feat(libc): implement unsigned 64-bit minimum #11289

Merged
Danigamer05 merged 1 commit from upstream-pr/11289 into main 2026-10-26 22:06:33 +00:00
Danigamer05 commented 2026-10-26 00:12:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Danigamer05 on 2026-10-26T00:12:31Z.


What

Add the missing libc export __std_min_8u (i8DeU1sI6I4). It reads a nonempty range of unsigned 64-bit elements and returns the minimum value, rather than a pointer. Reads use the existing memcpy helper, so the range need not be aligned; the input is left untouched. Null, empty, reversed or partial-element ranges call NotImplemented_nid_no_patch; their native failure behavior is not reproduced and remains in debt. The test does not assert those unsupported paths.

The contract comes from the libc.prx bundled with PPSA03671 v01.001.005: export RVA 0x62a30, size 0x2a4, ELF SHA256 483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6. Its implementation takes rdi/rsi range pointers, reads 8-byte elements, selects the unsigned smaller value (cmovb at 0x62cc6 in the scalar tail), and returns the value in rax. The isolated original function was also executed on this Windows host from its mapped load segments, using its image-relative constants without relocations, module initialization or other module exports. This is a host differential, not a console measurement. Microsoft STL's public implementation corroborates the unsigned value-returning signature.

Declare the export once in libc's public Api.hpp; tests use that header. No third-party code, module bytes or title files are added. No current title dependency or title unblock is claimed.

Tested

Base: acb900c194325b9ee8c23c10768a9a491454f0b2. Published/tested head: 94e88881d482031d47178adcbe87a58212d3a304.

  • Windows 11 build 26200, AMD Ryzen 7 3700X, WinLibs MinGW-w64 GCC 15.2.0 r7, CMake 4.3.1, Release, bundled dependencies, BUILD_TESTING=ON, ANYPS5_RELINKER_ONLY=OFF, SDL_CCACHE=OFF. Built production libs, relinker and guest_vector_algorithms_tests.
  • The original guest_vector_algorithms passes on the unmodified base. Added cases cover unsigned/sign and 32/64-bit boundaries, a single value, repeated minima, lengths around vector/tail boundaries, offsets 0–31, input/canary preservation, all-maximum ranges and a unique minimum at every position. All existing cases remain.
  • Three independently rebuilt negative controls fail as expected: signed comparison, truncating later elements to 32 bits, and skipping the last element. Restored exact sources and binaries afterward.
  • ctest --test-dir build -R "^(guest_vector_algorithms|public_headers)$" -V --output-on-failure: both pass on Windows. The public-header audit verifies unique declarations and umbrella coverage; this is not a claim that all standalone-header compilation batches or the full CTest suite ran.
  • Isolated original / NID-patched production candidate / unsigned-minimum reference: 8,609 cases, zero mismatches. This includes lengths 1–257 at offsets 0–31, 256 cases against inaccessible guard pages, every single-bit boundary, zero/UINT64_MAX, and all 64 pairs of eight unsigned edge values. Inputs remain unchanged. Repeated against the final production binary after restoration.
  • Ubuntu 24.04 under WSL2 (kernel 6.6.114.1), GCC 13.3.0, CMake 3.28.3, Release, bundled dependencies: full-project configuration, production libc and guest_vector_algorithms_tests build; the same CTest expression passes both tests. A separate Git checkout fixed to the published commit is clean for the tested sources before and after the run. The existing runtime reported unavailable asynchronous userfaultfd write protection and used its memory-comparison fallback.
  • Conventions and PR-diff whitespace checks pass. No console, title run, macOS, full CTest suite, GPU execution or performance claim.

Overlap: the required scan against acb900c194325b9ee8c23c10768a9a491454f0b2 reports no confirmed overlap. Manually inspected all 29 stale shared-file comparisons against their merge bases: #5021, #5303, #6713, #7081, #7386, #7447, #7544, #7648, #7715, #8150, #8417, #9269, #9371, #9447, #9526, #9669, #9771, #9863, #9873, #9929, #10007, #10113, #10226, #10405, #10467, #10610, #10742, #10788, #10898. Their changes touch other debt entries; #10742 adds _LCosh/_LSinh declarations and #10788 adds _Thrd_lt, away from this declaration. None changes this export or the adjacent vector-algorithm entry. Those stale branches are not claimed merge-clean. A trial merge-tree with #10460 (62c85f44a6a50b0ffb6ae72e7d6405c5a8c7769f, unsigned maximum) succeeds without content conflicts; the two exports are independent.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5010073598 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11289). Originally posted by [Danigamer05](https://github.com/Danigamer05) on 2026-10-26T00:12:31Z. --- ### What Add the missing libc export `__std_min_8u` (`i8DeU1sI6I4`). It reads a nonempty range of unsigned 64-bit elements and returns the minimum value, rather than a pointer. Reads use the existing `memcpy` helper, so the range need not be aligned; the input is left untouched. Null, empty, reversed or partial-element ranges call `NotImplemented_nid_no_patch`; their native failure behavior is not reproduced and remains in debt. The test does not assert those unsupported paths. The contract comes from the `libc.prx` bundled with PPSA03671 v01.001.005: export RVA `0x62a30`, size `0x2a4`, ELF SHA256 `483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6`. Its implementation takes `rdi`/`rsi` range pointers, reads 8-byte elements, selects the unsigned smaller value (`cmovb` at `0x62cc6` in the scalar tail), and returns the value in `rax`. The isolated original function was also executed on this Windows host from its mapped load segments, using its image-relative constants without relocations, module initialization or other module exports. This is a host differential, not a console measurement. [Microsoft STL's public implementation](https://github.com/microsoft/STL/blob/b6f01e438b68ee497f9c08313e49d12bb2f0d8e0/stl/src/vector_algorithms.cpp#L3914-L3916) corroborates the unsigned value-returning signature. Declare the export once in libc's public `Api.hpp`; tests use that header. No third-party code, module bytes or title files are added. No current title dependency or title unblock is claimed. ### Tested Base: `acb900c194325b9ee8c23c10768a9a491454f0b2`. Published/tested head: `94e88881d482031d47178adcbe87a58212d3a304`. - Windows 11 build 26200, AMD Ryzen 7 3700X, WinLibs MinGW-w64 GCC 15.2.0 r7, CMake 4.3.1, Release, bundled dependencies, `BUILD_TESTING=ON`, `ANYPS5_RELINKER_ONLY=OFF`, `SDL_CCACHE=OFF`. Built production `libs`, `relinker` and `guest_vector_algorithms_tests`. - The original `guest_vector_algorithms` passes on the unmodified base. Added cases cover unsigned/sign and 32/64-bit boundaries, a single value, repeated minima, lengths around vector/tail boundaries, offsets 0–31, input/canary preservation, all-maximum ranges and a unique minimum at every position. All existing cases remain. - Three independently rebuilt negative controls fail as expected: signed comparison, truncating later elements to 32 bits, and skipping the last element. Restored exact sources and binaries afterward. - `ctest --test-dir build -R "^(guest_vector_algorithms|public_headers)$" -V --output-on-failure`: both pass on Windows. The public-header audit verifies unique declarations and umbrella coverage; this is not a claim that all standalone-header compilation batches or the full CTest suite ran. - Isolated original / NID-patched production candidate / unsigned-minimum reference: 8,609 cases, zero mismatches. This includes lengths 1–257 at offsets 0–31, 256 cases against inaccessible guard pages, every single-bit boundary, zero/`UINT64_MAX`, and all 64 pairs of eight unsigned edge values. Inputs remain unchanged. Repeated against the final production binary after restoration. - Ubuntu 24.04 under WSL2 (kernel 6.6.114.1), GCC 13.3.0, CMake 3.28.3, Release, bundled dependencies: full-project configuration, production libc and `guest_vector_algorithms_tests` build; the same CTest expression passes both tests. A separate Git checkout fixed to the published commit is clean for the tested sources before and after the run. The existing runtime reported unavailable asynchronous userfaultfd write protection and used its memory-comparison fallback. - Conventions and PR-diff whitespace checks pass. No console, title run, macOS, full CTest suite, GPU execution or performance claim. Overlap: the required scan against `acb900c194325b9ee8c23c10768a9a491454f0b2` reports no confirmed overlap. Manually inspected all 29 stale shared-file comparisons against their merge bases: #5021, #5303, #6713, #7081, #7386, #7447, #7544, #7648, #7715, #8150, #8417, #9269, #9371, #9447, #9526, #9669, #9771, #9863, #9873, #9929, #10007, #10113, #10226, #10405, #10467, #10610, #10742, #10788, #10898. Their changes touch other debt entries; #10742 adds `_LCosh`/`_LSinh` declarations and #10788 adds `_Thrd_lt`, away from this declaration. None changes this export or the adjacent vector-algorithm entry. Those stale branches are not claimed merge-clean. A trial `merge-tree` with #10460 (`62c85f44a6a50b0ffb6ae72e7d6405c5a8c7769f`, unsigned maximum) succeeds without content conflicts; the two exports are independent. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes
MarcZX10 commented 2026-10-26 00:27:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T00:27:17Z.

Review: APPROVED


Re-reviewed exact head 94e88881d482031d47178adcbe87a58212d3a304. The unsigned 64-bit minimum implementation handles the nonempty range through the existing Read helper, including unaligned inputs; the added tests cover boundaries, random vectors, offsets, and guard/canary behavior. I found no concrete correctness issue in the diff.

The author reports Windows and WSL builds/differential tests (8,609 cases). Hosted conventions, eligibility, intake, labels, Ubuntu/macOS/Windows relinker, ASan, register-context, and write-watch checks pass. Full Linux and Windows product builds were path-skipped. I did not independently rerun the author’s local differential tests.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5646164291 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11289#pullrequestreview-5646164291). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T00:27:17Z. **Review:** APPROVED --- Re-reviewed exact head `94e88881d482031d47178adcbe87a58212d3a304`. The unsigned 64-bit minimum implementation handles the nonempty range through the existing `Read` helper, including unaligned inputs; the added tests cover boundaries, random vectors, offsets, and guard/canary behavior. I found no concrete correctness issue in the diff. The author reports Windows and WSL builds/differential tests (8,609 cases). Hosted conventions, eligibility, intake, labels, Ubuntu/macOS/Windows relinker, ASan, register-context, and write-watch checks pass. Full Linux and Windows product builds were path-skipped. I did not independently rerun the author’s local differential tests.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!11289
No description provided.