feat(libSceLibcInternal): implement signed and 16-bit integer extrema and minmax #15657

Merged
HilalElusive merged 6 commits from upstream-pr/15657 into main 2026-11-09 12:04:28 +00:00
HilalElusive commented 2026-11-04 00:31:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by HilalElusive on 2026-11-04T00:31:25Z.


What

Implement 14 integer helpers of the vectorized STL algorithms in libSceLibcInternal, replacing their parameterless throwing placeholders in RecoveredInventory.cpp:

  • __std_min_1i, __std_max_1i, __std_min_2i, __std_max_2i, __std_min_2u, __std_max_2u return the smallest or largest element of a nonempty half-open range.
  • __std_minmax_1i, _1u, _2i, _2u, _4i, _4u, _8i, _8u return both as a {min, max} pair by value.
    The signatures, value results and result struct layouts follow Microsoft STL's vector_algorithms.cpp and __msvc_minmax.hpp, the same source whose 4- and 8-byte __std_min/__std_max forms libc already exports from VectorAlgorithms.cpp (there checked against a title's bundled libc.prx). The range checks match those libc exports: null, empty, reversed and partial-element ranges throw through NotImplemented_nid_no_patch, since the source reads an element of any range it is given. Reads are unaligned and comparisons scalar; no SIMD equivalence or speed is claimed.

The new code is in its own IntegerExtrema.cpp, so it does not collide with the VectorAlgorithms.cpp that #15581 adds. The placeholder count in the debt entry drops from 40 to 26, and the gap is recorded under Functional in docs/dev/debt/libSceLibcInternal.md.

Overlap: no open PR implements these 14 exports (pr_overlap.py reports no shared exports). The remaining textual conflicts are:

  • #15460 (__std_min_1u, __std_max_1u), #15577 (__std_bitset_to_string_1, _2) and #15581 (the f and d forms) remove other declarations from the same RecoveredInventory.cpp/.hpp and edit the same debt count line; #15577 also adds its source next to RecoveredInventory.cpp in CMakeLists.txt. Whichever lands later rebases; the conflicts are the count, adjacent deleted lines and that one CMake line.
  • #14212 adds a blank line between every debt entry, so it conflicts with any new entry.

Tested

Ubuntu 24.04 x86-64, GCC 13.3.0, Release full configure with BUILD_TESTING=ON; no title.

  • New guest_libc_internal_integer_extrema: every pair of edge values (type min, min+1, -1, 0, 1, max-1, max, the sign boundary) and singletons; random ranges of 1 to 257 elements at every byte offset up to the element size, compared with std::min_element/std::max_element/std::minmax_element, with an extremum forced at the start, middle and end, and the input checked unchanged; null, empty, reversed and partial-element ranges throw a std::runtime_error naming the export. Four deliberate faults (inverted comparison, skipped elements, wrong initial value, missing partial-element check) each made it fail.
  • guest_libc_internal_pad, public_headers and all 65 public_headers_compile_* batches pass.
  • nm -D on libSceLibcInternal.prx lists the 14 exports.
  • python3 tools/check_conventions.py --base upstream/main passes.
  • python3 tools/pr_overlap.py --branch feat/libc-internal-integer-extrema (1821 open pull requests) found no shared exports and conflicting lines only with #15460, #15577 and #15581. It could not compare seven pull requests that conflict with main (#5021, #13486, #13778, #13782, #14212, #14401, #14837), so I merged this branch with each of them and with every other open pull request touching these files using git merge-tree. Only #14212 conflicts with this branch's lines, as described above.

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:5146736054 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15657). Originally posted by [HilalElusive](https://github.com/HilalElusive) on 2026-11-04T00:31:25Z. --- ### What Implement 14 integer helpers of the vectorized STL algorithms in `libSceLibcInternal`, replacing their parameterless throwing placeholders in `RecoveredInventory.cpp`: - `__std_min_1i`, `__std_max_1i`, `__std_min_2i`, `__std_max_2i`, `__std_min_2u`, `__std_max_2u` return the smallest or largest element of a nonempty half-open range. - `__std_minmax_1i`, `_1u`, `_2i`, `_2u`, `_4i`, `_4u`, `_8i`, `_8u` return both as a `{min, max}` pair by value. The signatures, value results and result struct layouts follow Microsoft STL's [`vector_algorithms.cpp`](https://github.com/microsoft/STL/blob/e1ed302683e5e822f663fbb0f44cee7e9ddc6af0/stl/src/vector_algorithms.cpp#L3865-L3975) and [`__msvc_minmax.hpp`](https://github.com/microsoft/STL/blob/e1ed302683e5e822f663fbb0f44cee7e9ddc6af0/stl/inc/__msvc_minmax.hpp#L25-L63), the same source whose 4- and 8-byte `__std_min`/`__std_max` forms `libc` already exports from `VectorAlgorithms.cpp` (there checked against a title's bundled `libc.prx`). The range checks match those `libc` exports: null, empty, reversed and partial-element ranges throw through `NotImplemented_nid_no_patch`, since the source reads an element of any range it is given. Reads are unaligned and comparisons scalar; no SIMD equivalence or speed is claimed. The new code is in its own `IntegerExtrema.cpp`, so it does not collide with the `VectorAlgorithms.cpp` that #15581 adds. The placeholder count in the debt entry drops from 40 to 26, and the gap is recorded under Functional in `docs/dev/debt/libSceLibcInternal.md`. Overlap: no open PR implements these 14 exports (`pr_overlap.py` reports no shared exports). The remaining textual conflicts are: - #15460 (`__std_min_1u`, `__std_max_1u`), #15577 (`__std_bitset_to_string_1`, `_2`) and #15581 (the `f` and `d` forms) remove other declarations from the same `RecoveredInventory.cpp`/`.hpp` and edit the same debt count line; #15577 also adds its source next to `RecoveredInventory.cpp` in `CMakeLists.txt`. Whichever lands later rebases; the conflicts are the count, adjacent deleted lines and that one CMake line. - #14212 adds a blank line between every debt entry, so it conflicts with any new entry. ### Tested Ubuntu 24.04 x86-64, GCC 13.3.0, Release full configure with `BUILD_TESTING=ON`; no title. - New `guest_libc_internal_integer_extrema`: every pair of edge values (type min, min+1, -1, 0, 1, max-1, max, the sign boundary) and singletons; random ranges of 1 to 257 elements at every byte offset up to the element size, compared with `std::min_element`/`std::max_element`/`std::minmax_element`, with an extremum forced at the start, middle and end, and the input checked unchanged; null, empty, reversed and partial-element ranges throw a `std::runtime_error` naming the export. Four deliberate faults (inverted comparison, skipped elements, wrong initial value, missing partial-element check) each made it fail. - `guest_libc_internal_pad`, `public_headers` and all 65 `public_headers_compile_*` batches pass. - `nm -D` on `libSceLibcInternal.prx` lists the 14 exports. - `python3 tools/check_conventions.py --base upstream/main` passes. - `python3 tools/pr_overlap.py --branch feat/libc-internal-integer-extrema` (1821 open pull requests) found no shared exports and conflicting lines only with #15460, #15577 and #15581. It could not compare seven pull requests that conflict with `main` (#5021, #13486, #13778, #13782, #14212, #14401, #14837), so I merged this branch with each of them and with every other open pull request touching these files using `git merge-tree`. Only #14212 conflicts with this branch's lines, as described above. ### 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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
BunnyFl commented 2026-11-04 01:41:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-04T01:41:29Z.

Review: APPROVED


@HilalElusive thanks. The 14 helpers are also defined in firmware 13.42's system libSceLibcInternal.sprx (sha256 a01795ab49df639dd40abd6194956ada062244826824ce486c9acab227bf5285): each name's NID (from __std_min_1i XxFnGBq9gO4 to __std_minmax_8u sS4cYWO4yXw) is a defined .text export there (objdump -T), 14 of 14.

I also ran those firmware exports under an emulator, with imports stubbed, not measured on a console. On ranges of 1 to 3 elements at unaligned addresses, every value the firmware returned (rax, plus rdx for the 8-byte pairs) matched the plain minimum and maximum, which is what this PR returns. For longer ranges the firmware takes vector paths that the emulator can't run reliably: it stopped on invalid instructions in four exports and gave results that weren't plain min/max in others. So I'm not drawing anything from those runs, either for or against this PR, and they don't confirm the longer ranges.

What I ran: head b34b0b5f09 (it fast-forwards onto main 1c8c0efc8c), Windows 11, WinLibs GCC, Release:

  • guest_libc_internal_integer_extrema, guest_libc_internal_pad and public_headers pass (3 of 3);
  • mutation, value < result.minimum changed to value > result.minimum in IntegerExtrema.cpp: guest_libc_internal_integer_extrema fails;
  • tools/check_conventions.py --base upstream/main on the head: all checks passed;
  • tools/pr_overlap.py --branch: the same result as in your description. Only #15460, #15577 and #15581 share lines, and the same seven PRs that conflict with main couldn't be compared.

Approving.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5762021112 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15657#pullrequestreview-5762021112). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-04T01:41:29Z. **Review:** APPROVED --- @HilalElusive thanks. The 14 helpers are also defined in firmware 13.42's system `libSceLibcInternal.sprx` (sha256 `a01795ab49df639dd40abd6194956ada062244826824ce486c9acab227bf5285`): each name's NID (from `__std_min_1i` `XxFnGBq9gO4` to `__std_minmax_8u` `sS4cYWO4yXw`) is a defined `.text` export there (`objdump -T`), 14 of 14. I also ran those firmware exports under an emulator, with imports stubbed, not measured on a console. On ranges of 1 to 3 elements at unaligned addresses, every value the firmware returned (`rax`, plus `rdx` for the 8-byte pairs) matched the plain minimum and maximum, which is what this PR returns. For longer ranges the firmware takes vector paths that the emulator can't run reliably: it stopped on invalid instructions in four exports and gave results that weren't plain min/max in others. So I'm not drawing anything from those runs, either for or against this PR, and they don't confirm the longer ranges. **What I ran:** head `b34b0b5f09` (it fast-forwards onto `main` `1c8c0efc8c`), Windows 11, WinLibs GCC, Release: - `guest_libc_internal_integer_extrema`, `guest_libc_internal_pad` and `public_headers` pass (3 of 3); - mutation, `value < result.minimum` changed to `value > result.minimum` in `IntegerExtrema.cpp`: `guest_libc_internal_integer_extrema` fails; - `tools/check_conventions.py --base upstream/main` on the head: all checks passed; - `tools/pr_overlap.py --branch`: the same result as in your description. Only #15460, #15577 and #15581 share lines, and the same seven PRs that conflict with `main` couldn't be compared. Approving.
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!15657
No description provided.