feat(libc): implement reverse trivial element searches #15098
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15098"
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 Danigamer05 on 2026-11-02T16:10:12Z.
What
Implement libc's
__std_find_last_trivial_1/2/4/8(NIDseaLVyLMql6I,-ciYO9tOTVQ,fPGFDSCERGM,akVoBLxgReY). Given a valid half-open range and a value of the corresponding unsigned width, return the last equal element, or the supplied end pointer if absent. Reads support unaligned elements and leave input and errno unchanged. Equal endpoints return without accessing memory, including null and inaccessible endpoints. Malformed reversed, partial-element or nonempty null-ended ranges throw; their native faults or nontermination are not reproduced.The ABI and behavior come from the bundled
libc.prxin PPSA03671 v01.001.005, SHA-256483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6, at RVAs0x658D0,0x659B0,0x65A90,0x65B70. These leaf exports have no calls or RIP-relative data accesses. The implementation uses a scalar element search and the existing unaligned read helper; no SIMD code or original bytes are copied.#13273 originally declared the same four names as throwing inventory placeholders in
libSceLibcInternal, where an import from that library would have been resolved before this libc implementation. Its author removed them inbb4d312e54ddfb0b5e7471271d37ff7cd3afe767after we agreed on the order in that PR, so the two changes no longer share exports.Tested
Windows x86-64, WinLibs GCC 15.2.0, Release,
BUILD_TESTING=ON, main5e85609d0b0152d14ae34d708d3237005ed311ca. Exact tested commit:9527343a948295e74bc6787a90ab7865ead17770.The change was first tested on main
0cc3899f6992e86d217a623abc6990feb2ce27b3at480c7de6c93d7e0c30a3e439e1f8085bc6e19f48, including the negative control below, then rebased onto the main above without conflicts; the diff of the change is the same apart from context lines. All 18 selected CTests and all 1,703,708 differential vectors were run again at the tested commit and pass.guest_find_last_trivial_testsand the neighboringguest_vector_algorithms_tests.guest_vector_algorithmsandpublic_headers. Cases cover empty/inaccessible ranges, every matching position, duplicate matches, absent values, all 8/16-bit values, high bits and deterministic wider values, 32 byte alignments, unchanged inputs/errno and read-only pages between inaccessible guards. The longest new test took 0.99 seconds locally.NotImplemented_nid_no_patch, where the original faults or does not terminate;tools/progress.pycounts any export that can reach that call as a stub. Every valid range is implemented. On main,__std_max_4i/4u/8i/8uand__std_min_4i/4u/8i/8uuse the same kind of guard and are counted the same way.git diff --checkpass.tools/pr_overlap.pyread 1,747 open PRs at the tested commit and reports no confirmed overlap. #13273 no longer shares exports. It keeps exit 2 for 58 branches that already conflict with main (#5021, #5303, #6819, #7081, #7386, #7447, #7715, #8150, #8965, #9087, #9340, #9371, #9447, #9526, #9929, #10113, #10226, #10245, #10250, #10253, #10265, #10274, #10325, #10328, #10345, #10349, #10405, #10506, #10510, #10512, #10565, #10987, #11260, #11262, #11266, #11332, #11632, #11634, #11724, #11726, #11831, #11907, #12122, #12397, #12514, #12560, #12574, #12593, #12622, #12627, #12682, #12688, #12700, #12965, #13119, #13390, #13804, #14212). None of their added lines against their merge base contains the four names or NIDs. Merging each with this branch and with main usinggit merge-treegives the same conflict blocks, and no conflict block contains this change.Not tested: Linux, macOS, another SDK, a game, GPU or console. No speed or game compatibility claim. No original module, extracted bytes, oracle, report or log is committed or uploaded.
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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T16:43:22Z.
Review: APPROVED
Cross-checked against firmware 13.42's system
libSceLibcInternal.sprx(sha256a01795ab49df639dd40abd6194956ada062244826824ce486c9acab227bf5285). All four NIDs are exported there as leaf functions at0x40dd0,0x40eb0,0x40f90and0x41070. The 1-byte form, for example, is a backwardvpcmpeqbscan in 32-byte, then 16-byte, blocks, with a finalcmp rdi, rcxagainst the start (read from disassembly only, not measured on a console). That matches a last-match search that returns the end pointer when nothing matches. The scalar implementation computes the same result.Build and test on Windows (WinLibs GCC,
BUILD_TESTING=ON), PR merged into currentmain: all 16guest_find_last_trivial_*tests pass. Onmainthe exports don't exist.