feat(libSceLibcInternal): implement signed and 16-bit integer extrema and minmax #15657
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15657"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 inRecoveredInventory.cpp:__std_min_1i,__std_max_1i,__std_min_2i,__std_max_2i,__std_min_2u,__std_max_2ureturn the smallest or largest element of a nonempty half-open range.__std_minmax_1i,_1u,_2i,_2u,_4i,_4u,_8i,_8ureturn both as a{min, max}pair by value.The signatures, value results and result struct layouts follow Microsoft STL's
vector_algorithms.cppand__msvc_minmax.hpp, the same source whose 4- and 8-byte__std_min/__std_maxformslibcalready exports fromVectorAlgorithms.cpp(there checked against a title's bundledlibc.prx). The range checks match thoselibcexports: null, empty, reversed and partial-element ranges throw throughNotImplemented_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 theVectorAlgorithms.cppthat #15581 adds. The placeholder count in the debt entry drops from 40 to 26, and the gap is recorded under Functional indocs/dev/debt/libSceLibcInternal.md.Overlap: no open PR implements these 14 exports (
pr_overlap.pyreports no shared exports). The remaining textual conflicts are:__std_min_1u,__std_max_1u), #15577 (__std_bitset_to_string_1,_2) and #15581 (thefanddforms) remove other declarations from the sameRecoveredInventory.cpp/.hppand edit the same debt count line; #15577 also adds its source next toRecoveredInventory.cppinCMakeLists.txt. Whichever lands later rebases; the conflicts are the count, adjacent deleted lines and that one CMake line.Tested
Ubuntu 24.04 x86-64, GCC 13.3.0, Release full configure with
BUILD_TESTING=ON; no title.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 withstd::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 astd::runtime_errornaming 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_headersand all 65public_headers_compile_*batches pass.nm -DonlibSceLibcInternal.prxlists the 14 exports.python3 tools/check_conventions.py --base upstream/mainpasses.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 withmain(#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 usinggit merge-tree. Only #14212 conflicts with this branch's lines, as described above.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)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(sha256a01795ab49df639dd40abd6194956ada062244826824ce486c9acab227bf5285): each name's NID (from__std_min_1iXxFnGBq9gO4to__std_minmax_8usS4cYWO4yXw) is a defined.textexport 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, plusrdxfor 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 ontomain1c8c0efc8c), Windows 11, WinLibs GCC, Release:guest_libc_internal_integer_extrema,guest_libc_internal_padandpublic_headerspass (3 of 3);value < result.minimumchanged tovalue > result.minimuminIntegerExtrema.cpp:guest_libc_internal_integer_extremafails;tools/check_conventions.py --base upstream/mainon 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 withmaincouldn't be compared.Approving.