Skip to content

feat(libc): implement unsigned 32-bit minimum - #11295

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
Danigamer05:feat/libc-unsigned-min32
Oct 27, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
Danigamer05:feat/libc-unsigned-min32

Conversation

@Danigamer05

@Danigamer05 Danigamer05 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What

Add the missing libc export __std_min_4u (60rcqDrkUNY): read a nonempty range of unsigned 32-bit elements and return the minimum value. Reads use the existing memcpy helper, accepting unaligned ranges and leaving the input untouched. Declare the export once in the public Api.hpp; tests include that header. Null, empty, reversed and partial-element ranges call NotImplemented_nid_no_patch; their native failure behavior remains unimplemented and recorded in debt. Tests cover valid inputs without pinning those unsupported paths.

Contract evidence: the libc.prx bundled with PPSA03671 v01.001.005 exports this NID at RVA 0x62680, size 0x1a2; ELF SHA256 483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6. Reading the original confirms range pointers in rdi/rsi, 4-byte elements, unsigned minimum selection (vpminud at 0x626c0 and cmovb %ecx,%eax at 0x62815) and a value returned in eax. It has no calls or image-relative data references. The original function was also run directly from its isolated mapped load segments on this Windows host, without relocations, module initializers or other module exports. This is a host differential, not a console measurement. Microsoft STL's public implementation independently corroborates the unsigned 32-bit value-returning signature. The implementation is a generic scalar scan written from that contract.

Main and all 1,394 open PR heads were scanned for the name and raw NID before implementation: no matches. No third-party code, module bytes or title files are added. No current title dependency, title unblock or performance improvement is claimed.

Tested

Current-main synchronization (27 October 2026). Exact tested/published head: be750a1f384f784cfb5c99e5682359ac1c5bc778. Main base: cb45ae2ddf6e113a4619e8fed91fe7b9333c5c0f.

  • Rebased from ae84a8e11a1340e521176a83920f53fc691fadcb onto the two newer main commits. Main changed only the windows_crash_stack_words test regex in core/libs/prx/libc/CMakeLists.txt (fix(main): windows_crash_stack_words regex crossed by '~' in register dump #11633). The entire four-file contribution patch is byte-identical before and after the rebase; no implementation or regression assertion changed.
  • On this exact head, rebuilt libc and guest_vector_algorithms_tests in the existing full-project Release configurations. guest_vector_algorithms and public_headers pass 2/2 on Windows 11 / WinLibs GCC 15.2.0 and 2/2 on Ubuntu 24.04 WSL / GCC 13.3.0.
  • All seven synchronized helper PRs still merge cleanly in forward and reverse order, producing the same tree. Their new combined revision 7da0577e45f238c6bfa01a818bd7e27f727ebeff also builds and passes both focused tests on Windows and Ubuntu. This synchronization ran 32 focused checks in total across the seven individual heads and the combined head.
  • Conventions, whitespace and strict main-sync checks pass: one commit ahead and zero behind the main base above.
  • The combined production sources, headers and regression sources are byte-identical to the previous combined revision a27d73c1f43135378c54ed6477af71273135ec42; only the unrelated upstream CMake regex differs. The previous original-module differential, standalone-header and AddressSanitizer evidence below retains its stated revisions and was not rerun for this synchronization.
  • The full CTest suite and all 64 general standalone-header batches were not run. No console, title or GPU run and no performance claim.
Earlier implementation validation and provenance

Current-main refresh (27 October 2026). Exact tested/published head: ae84a8e11a1340e521176a83920f53fc691fadcb. Fetched main base: 74acfad65b3f0fd4eab653f3a3989d298fba1157.

  • Rebased from f237f5085cc5dd4881dae7231132c730a39fd792. The __std_min_4u production body is byte-identical to that head. Every existing main declaration and debt entry is preserved; the patch still changes only the implementation, public declaration, regression cases and debt entry. The unchanged debt bullet was moved away from the _Thrd_lt insertion in feat(libc): implement _Thrd_lt #10788, removing that documentation-only content conflict.
  • Windows 11 x64, WinLibs GCC 15.2.0, Release, full-project configuration: rebuilt production libc and guest_vector_algorithms_tests; ctest --test-dir build -R "^(guest_vector_algorithms|public_headers)$" -V --output-on-failure passed 2/2 on this exact head (19.66 s).
  • Ubuntu 24.04 under WSL, GCC 13.3.0 and CMake 3.28.3, Release, full-project configuration in a separate native Linux checkout: rebuilt production libc and the focused executable; the same checks passed 2/2 on this exact head (14.97 s). The runtime uses its existing memory-comparison fallback when asynchronous userfaultfd write watching is unavailable.
  • The same focused checks also pass on the unmodified main base on both platforms. All seven remaining vector-helper PRs (feat(libc): implement unsigned 64-bit maximum #10460, feat(libc): implement unsigned 32-bit minimum #11295, feat(libc): implement signed 64-bit minimum #11300, feat(libc): implement signed 64-bit maximum #11302, feat(libc): implement unsigned 32-bit maximum #11304, feat(libc): implement signed 32-bit minimum value helper #11309 and feat(libc): implement signed 32-bit maximum value helper #11333), together with feat(libc): implement unsigned 64-bit minimum #11289 already in main, merge without content conflicts. Merging the seven in forward and reverse order produces the same tree. That combined revision a27d73c1f43135378c54ed6477af71273135ec42 also builds and passes both focused checks on Windows and Ubuntu.
  • The current feat(libc): implement _Thrd_lt #10788 head 92db947130efc9e7e12c492683329f2ebc3e1996 merges cleanly with the main base, each individual helper and the seven-helper composition. This is a content-merge check for feat(libc): implement _Thrd_lt #10788; its implementation was not part of the combined runtime run.
  • Conventions, whitespace and tools/check_main_sync.py --base origin/main --head ae84a8e11a1340e521176a83920f53fc691fadcb --strict pass. The sync check is one ahead and zero behind the fetched main base above. Bundled dependencies use that base's pinned revisions; no contribution dependency was introduced.
  • public_headers audits unique declarations and umbrella coverage. Its current upstream 90-second timeout is unchanged. The full set of 64 standalone-header batches and the full CTest suite were not run; the targeted header checks below were added afterward.

Additional validation on 27 October 2026, combined revision a27d73c1f43135378c54ed6477af71273135ec42 (the same seven-helper composition described above):

  • The five standalone public libc headers (include/Api.hpp, include/exceptions/Runtime.hpp, include/exceptions/Unwind.hpp, include/SonyCrt.hpp, and libc.hpp), plus a compilation unit including all 368 library umbrellas together, pass with C++20 and -Werror on Windows/WinLibs GCC 15.2.0 and Ubuntu/GCC 13.3.0. Every header is included twice, and the existing checker also rejects third-party header dependencies: 6 compilation units per platform, all pass. This is targeted coverage, not the full 64-batch matrix.
  • A separate Ubuntu full-project configuration with ANYPS5_ENABLE_ASAN=ON, RelWithDebInfo, rebuilt libc and guest_vector_algorithms_tests. ASAN_OPTIONS=halt_on_error=1:detect_leaks=1 ctest --test-dir build-asan-libc-followup-20261027-a -R '^guest_vector_algorithms$' -V --output-on-failure passed 1/1, with no AddressSanitizer or LeakSanitizer finding.
  • These added checks ran on the combined revision, not on seven additional individual builds. The individual Windows/Ubuntu Release results above remain associated with their exact published heads.

The earlier differential and negative-control results below belong to their stated heads. The original-module differential was not rerun for this refresh. No console, title or GPU execution and no performance claim.

Earlier implementation validation and provenance

Current-main refresh (26 October 2026), exact published/tested head f237f5085cc5dd4881dae7231132c730a39fd792, main base bf77a9e9cba4b02c358779b35295176dd9cae164:

  • Rebased from c685175f955ff5067b52288ab8defd6cb3f67b2a onto the main base above. All existing main declarations and debt entries are retained. The __std_min_4u production function body is byte-identical to the previously reviewed head; the patch still changes only its implementation, public declaration, regression cases and debt entry.
  • Windows 11 x64, WinLibs GCC 15.2.0, Release, full-project configuration: rebuilt libc and guest_vector_algorithms_tests; ctest --test-dir build -R "^(guest_vector_algorithms|public_headers)$" -V --output-on-failure passed 2/2 on this exact head (19.56 s).
  • Ubuntu 24.04 under WSL, GCC 13.3.0 and CMake 3.28.3, Release, full-project configuration in a separate Linux checkout: rebuilt libc and the focused executable, and the same two tests passed 2/2 on this exact head (13.81 s). The runtime reports the existing unavailable asynchronous userfaultfd write-watch path and uses its memory-comparison fallback.
  • The two header audits ran separately after both platform builds completed, with the existing 30-second limit unchanged. public_headers is the unique-declaration and umbrella-coverage audit; standalone-header compilation batches and the full CTest suite were not run in this refresh.
  • tools/check_conventions.py --base origin/main, PR-diff whitespace checks and tools/check_main_sync.py --base origin/main --head f237f5085cc5dd4881dae7231132c730a39fd792 --strict pass. The sync check reports one commit ahead and zero behind the fetched main base above.
  • A trial merge of all six refreshed PRs together with independent feat(libc): implement unsigned 64-bit maximum #10460 and feat(libc): implement unsigned 64-bit minimum #11289 is clean. That composition was checked for content conflicts; the runtime results above are the individual PR runs.

The previous baseline, differential and negative-control evidence below belongs to the earlier heads stated there. The original-module comparison was not rerun for this rebase-only refresh, and no console measurement was made.

Earlier implementation validation and provenance

Base: e41113fd39c8528de37028a933eae49ca5f7ebd2. Tested/published head: c685175f955ff5067b52288ab8defd6cb3f67b2a.

  • Windows 11, AMD Ryzen 7 3700X, WinLibs MinGW-w64 GCC 15.2.0 r7, CMake 4.3.1, Release, bundled dependencies, BUILD_TESTING=ON, full-project configuration: built production libs, relinker and guest_vector_algorithms_tests.
  • The existing guest_vector_algorithms and public_headers pass on the initial unmodified main (898a7fe). Added regression cases cover single values, all pairs of eight unsigned edge values, unsigned/sign and 16/32-bit boundaries, 20 lengths through 257 elements, offsets 0–31, unchanged input/canaries, repeated minima, all-maximum ranges and a unique minimum at every position.
  • Before the final rebase, three independently rebuilt negative controls fail as expected (the implementation is unchanged): a signed comparison, truncation of later elements to 16 bits and skipping the last element. Exact sources and binaries were restored 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 (368 libraries, 12,224 exports); standalone-header compilation batches and the full CTest suite were not run.
  • Original / NID-patched production candidate / independent unsigned-minimum reference: 8,577 cases, zero mismatches, including lengths 1–257 at offsets 0–31, 256 guard-page cases, each bit position, zero/UINT32_MAX and every pair of eight edge values. Input ranges remain unchanged.
  • Ubuntu 24.04 under WSL2, GCC 13.3.0, CMake 3.28.3, Release, bundled dependencies: full-project configuration; production libc and the focused executable build. The same two tests pass on the final commit in a separate Linux checkout, clean for tested sources before and after the run. One header-audit attempt timed out at 30 s while Linux and Windows builds were running concurrently; after builds stopped it passed in 14.57 s with the original 30 s limit. The runtime reports unavailable asynchronous userfaultfd write protection and uses its memory-comparison fallback.
  • Conventions and PR-diff whitespace checks pass. No PS5 console, title, macOS or GPU execution; no performance claim.

Overlap: tools/pr_overlap.py --branch feat/libc-unsigned-min32 --repo boykopovar/AnyPS5 against 97d33464c5ae244079d0e36d27340fc4aac276a0 reports no confirmed overlap. Manually inspected all 39 stale shared-file patches against their merge bases: #5021, #5303, #6565, #6713, #7081, #7386, #7447, #7544, #7648, #7715, #8150, #8417, #9087, #9269, #9371, #9447, #9526, #9669, #9771, #9863, #9873, #9929, #10007, #10113, #10158, #10200, #10222, #10226, #10229, #10283, #10346, #10349, #10405, #10467, #10610, #10742, #10788, #10898, #10989. They change other debt entries; the public-header additions in #10742, #10788 and #10989 concern math, thread and versioned-filesystem exports. None changes this export or its neighboring vector declarations/debt entry. Those stale branches are not claimed merge-clean. Trial merges with our independent #10460 and #11289 both succeed without content conflicts; no dependency on either.

The final rebase onto e41113fd39c8528de37028a933eae49ca5f7ebd2 adds upstream strcoll, symbolic-link test and import-audit changes; it changes none of the four files in this patch. The contribution diff is byte-for-byte identical to the scanned revision, and both OS tests and the native differential were repeated on the published head.

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

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Progress report (e2d457b → be750a1)

📉 System libraries: 51.82% (-0.01%, +1 declared functions)

🆕 1 declared as stubs
Library Name
libc __std_min_4u_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libc 1395/1404 (99.36%) 1395/1405 (99.29%) -0.07 pp

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 docs/dev/debt/libc.md
PR 6713 docs/dev/debt/libc.md
PR 7081 docs/dev/debt/libc.md
PR 7386 docs/dev/debt/libc.md
PR 7447 docs/dev/debt/libc.md
PR 7648 docs/dev/debt/libc.md
PR 7715 docs/dev/debt/libc.md
PR 8150 docs/dev/debt/libc.md
PR 8937 core/libs/prx/libc/include/Api.hpp
docs/dev/debt/libc.md
PR 9371 docs/dev/debt/libc.md
PR 9447 docs/dev/debt/libc.md
PR 9526 docs/dev/debt/libc.md
PR 9929 docs/dev/debt/libc.md
PR 10324 core/libs/prx/libc/include/Api.hpp
docs/dev/debt/libc.md
PR 10433 docs/dev/debt/libc.md
PR 10620 docs/dev/debt/libc.md
PR 11332 docs/dev/debt/libc.md

@wachi35676

Copy link
Copy Markdown
Contributor

Windows run of head c685175f955f merged onto main 0f34ebb85, WinLibs GCC 15.2.0, Release. guest_vector_algorithms passes 2/2 with no warnings. I also merged this together with #11289 and #11300 onto main. All three merge cleanly in any order, including docs/dev/debt/libc.md, and the combined guest_vector_algorithms passes 3/3. So the three can land in any order.

AI-assisted: yes (Claude Code); results above were run on this machine.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unsigned scan and its boundary, alignment, preservation, and differential coverage look sound from the submitted diff. The branch is 158 commits behind current main; both Api.hpp and docs/dev/debt/libc.md changed after its merge base. The reported Windows/WSL and combined-helper runs are useful, but the contribution rules require branches to be based on and kept up to date with main. Please rebase onto current main and rerun the focused guest_vector_algorithms and public_headers checks on the resulting head before this is approved.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refreshed the exact-head sync check against current upstream/main 204c6747d0a1cbaf932def3dea0778810cc3935e: this head is 1 ahead / 255 behind. The merge preview is clean, but Api.hpp and docs/dev/debt/libc.md changed on main since this branch’s base (#9269, #10354 and #10608); preserve those declarations and entries. The reported Windows/WSL and combined-helper results remain useful but predate this current base. Please rebase and rerun guest_vector_algorithms and public_headers on the resulting exact head. No new function-specific defect found.

@Danigamer05
Danigamer05 force-pushed the feat/libc-unsigned-min32 branch 2 times, most recently from f237f50 to ae84a8e Compare October 26, 2026 23:43
@Danigamer05
Danigamer05 force-pushed the feat/libc-unsigned-min32 branch from ae84a8e to be750a1 Compare October 27, 2026 01:11
@adriadam10 adriadam10 self-assigned this Oct 27, 2026
@adriadam10
adriadam10 dismissed MarcZX10’s stale review October 27, 2026 08:16

Dismissing a stale review: the requested changes were addressed after it (new head) and the merge queue blocks on it. Please request changes again if anything is still open.

@adriadam10
adriadam10 merged commit 80b209d into boykopovar:main Oct 27, 2026
18 of 19 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the diff against __std_min_8u on main (same pattern, unsigned compare, unaligned reads, unsupported ranges throw and are recorded in debt) and the test: it pins edge pairs, offsets 0-31 and lengths up to 257, so a signed compare or a skipped last element would fail it. The earlier rebase requests are met by this head (1 ahead of main). merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants