Skip to content

feat(libc): implement signed 32-bit minimum value helper - #11309

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
Danigamer05:feat/libc-signed-min32
Oct 28, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
Danigamer05:feat/libc-signed-min32

Conversation

@Danigamer05

@Danigamer05 Danigamer05 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What

Implement libc's __std_min_4i (lpMzqv5j5HY) for nonempty ranges of signed 32-bit integers. Return the minimum value, allow unaligned input, and leave the range unchanged. Null, empty, reversed and partial-element ranges call NotImplemented_nid_no_patch; the remaining native failure behavior is recorded in libc's debt file. The implementation is a generic scalar reduction using the existing unaligned read helper.

Contract evidence: the user's own PPSA03671 v01.001.005 bundled libc.prx, ELF SHA256 483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6, dynamic export lpMzqv5j5HY, RVA 0x624d0, size 0x1a2. The entry uses rdi/rsi as the range bounds; 0x624f3 reads one 32-bit value, 0x62510 uses vpminsd, and the scalar tail at 0x62663/0x62665 selects with signed cmovl. The result reaches ret at 0x62671 in eax. Complete 16-byte blocks are bounded by the rounded-down byte length, and the remaining reads advance by four to the exclusive end. The function has no stores or calls. Empty input has no separate result path and enters a read. This is disassembly and direct execution on a host, not a console measurement; no original initializer or other original export was executed.

The two-pointer signature and int32_t result are also corroborated by Microsoft STL at b6f01e438b68ee497f9c08313e49d12bb2f0d8e0. The implementation was written from the module's contract, without copying its SIMD structure. No game files, binary bytes, dumps or keys are included.

Tested

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

  • Rebased from e2f17a9aa59d7400457f980289615fd84eee2294 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: e2f17a9aa59d7400457f980289615fd84eee2294. Fetched main base: 74acfad65b3f0fd4eab653f3a3989d298fba1157.

  • Rebased from ab2c0faa2ac1c6ea372cef0a9111fdbfd31fa70c. The __std_min_4i 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.
  • 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.69 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.66 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 e2f17a9aa59d7400457f980289615fd84eee2294 --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 ab2c0faa2ac1c6ea372cef0a9111fdbfd31fa70c, main base bf77a9e9cba4b02c358779b35295176dd9cae164:

  • Rebased from 937e9625661a38b25cdad0f97875d9fb86e96f79 onto the main base above. All existing main declarations and debt entries are retained. The __std_min_4i 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 (18.88 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.83 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 ab2c0faa2ac1c6ea372cef0a9111fdbfd31fa70c --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
  • Windows x64, Release, WinLibs GCC 15.2.0: built libs, relinker and guest_vector_algorithms_tests; guest_vector_algorithms and public_headers passed on the baseline and the change, and again after rebasing onto current main.
  • Ubuntu 24.04 in WSL, GCC 13.3 and CMake 3.28.3: configured the full project in a separate Linux checkout, built libc and guest_vector_algorithms_tests, and passed the same two tests on the baseline and the final change. WSL reports the existing asynchronous userfaultfd write-watch fallback to memory comparison; this is a host test, not a console measurement.
  • Regression assertions cover singleton and pairwise signed boundaries, negative values, INT32_MIN/INT32_MAX, deterministic random data, 20 lengths from 1 through 257, all 32 byte offsets, repeated values, the minimum at every position, and unchanged inputs and canaries. Unsupported-input throws are not pinned by tests.
  • On Windows, 41,796 direct comparisons of the isolated original function, the NID-patched production libc and an independent signed reference passed, including 256 guard-page cases. Original module initialization was never run.
  • Negative controls deliberately changed the production comparison to unsigned, truncated subsequent reads to 16 bits, or skipped the last element; the regression test rejected all three. Sources and affected binaries were restored exactly and their SHA256 hashes checked before rerunning the tests and direct comparison.
  • The combined libc helpers from feat(libc): implement unsigned 64-bit maximum #10460, feat(libc): implement unsigned 64-bit minimum #11289, feat(libc): implement unsigned 32-bit minimum #11295, feat(libc): implement signed 64-bit minimum #11300, feat(libc): implement signed 64-bit maximum #11302 and feat(libc): implement unsigned 32-bit maximum #11304 merge without conflicts and pass guest_vector_algorithms and public_headers together on Ubuntu. They remain independent contributions.
  • tools/check_conventions.py --base origin/main passed. tools/pr_overlap.py --branch feat/libc-signed-min32 found no confirmed line, export or new-file overlap after relocating only the additions. Shared-file patches from PRs already conflicting with main were checked separately: their existing per-file conflict blocks are unchanged by this patch.

Investigation scripts, evidence and logs remain outside the repository. No title bring-up or performance improvement is claimed.

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 → 762556e)

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

🆕 1 declared as stubs
Library Name
libc __std_min_4i_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 9677 docs/dev/debt/libc.md
PR 9867 docs/dev/debt/libc.md
PR 9929 docs/dev/debt/libc.md
PR 10113 docs/dev/debt/libc.md
PR 10222 docs/dev/debt/libc.md
PR 10226 docs/dev/debt/libc.md
PR 10229 docs/dev/debt/libc.md
PR 10245 docs/dev/debt/libc.md
PR 10247 docs/dev/debt/libc.md
PR 10250 docs/dev/debt/libc.md
PR 10253 docs/dev/debt/libc.md
PR 10265 docs/dev/debt/libc.md
PR 10324 core/libs/prx/libc/include/Api.hpp
docs/dev/debt/libc.md
PR 10349 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
PR 11664 core/libs/prx/libc/include/Api.hpp
docs/dev/debt/libc.md
PR 11831 core/libs/prx/libc/include/Api.hpp
docs/dev/debt/libc.md
PR 11848 core/libs/prx/libc/include/Api.hpp
docs/dev/debt/libc.md
PR 11850 docs/dev/debt/libc.md
PR 11870 docs/dev/debt/libc.md
PR 12053 docs/dev/debt/libc.md
PR 12122 docs/dev/debt/libc.md

@wachi35676

Copy link
Copy Markdown
Contributor

Windows run of head 937e9625661a merged onto main 14eb2cda22d2, WinLibs GCC 15.2.0, Release. guest_vector_algorithms passes 2/2 with no warnings. I also merged all six open __std_min_*/__std_max_* PRs (#11289, #11295, #11300, #11302, #11304, #11309) onto that main. They merge without conflicts, each export is defined once, and the combined guest_vector_algorithms passes 3/3, so the order they land in doesn't matter.

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.

Reviewed the new export signature, byte-range validation and reduction loop against the stated disassembly evidence. For the supported nonempty 4-byte-aligned span, the first read initializes the result, each subsequent read uses the existing unaligned-safe helper, and the signed comparison preserves INT32_MIN/negative ordering without modifying the input. Null, empty, reversed and partial-element ranges are explicitly outside the established contract and route to the project’s unimplemented path with that gap recorded in libc debt. The focused Windows/WSL differential, boundary/unaligned/canary tests and negative controls are extensive; hosted relinker/ASan, public-header and policy checks pass, while full Linux/Windows product jobs were skipped by path policy. No blocking issue found.

@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 exact implementation remains sound on the reviewed head, and the reported Windows/WSL differential, boundary and negative-control evidence is strong. I refreshed branch sync against current upstream/main 204c6747d0a1cbaf932def3dea0778810cc3935e: this head is 1 ahead / 178 behind. The merge preview is clean; docs/dev/debt/libc.md is the only touched PR path changed on main since the base, and the new debt entries merge cleanly. This request is for the repository branch rule to keep PRs current, not a newly found implementation defect. Please rebase, preserve the debt entry, and rerun guest_vector_algorithms and public_headers on the resulting exact head.

@Danigamer05
Danigamer05 force-pushed the feat/libc-signed-min32 branch from e2f17a9 to 762556e Compare October 27, 2026 01:11
@oneandonlydean
oneandonlydean merged commit 5ab8acf into boykopovar:main Oct 28, 2026
18 of 19 checks passed
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