feat(libc): add SSE2 paths for trivial search and min helpers #12717
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12717"
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 xdCloudy on 2026-10-29T04:44:07Z.
What
Add SSE2 implementations for ten existing libc trivial-algorithm helpers:
__std_find_trivial_{1,2,4}__std_find_trivial_unsized_{1,2}__std_count_trivial_{1,2,4}__std_min_element_{1,2}Preserve the guest ABI, scalar fallbacks, unaligned handling, scalar tails and first-minimum semantics.
This change provides additional SIMD implementations without changing the expected functional results.
Tested
Windows x86_64 / WinLibs GCC / CMake-Ninja Release:
guest_vector_algorithms: PASSguest_vector_algorithms_scalar: PASSThe forced-scalar target compiles the production implementation with
ANYPS5_LIBC_FORCE_SCALAR. Preprocessing confirms that the SIMD implementation is excluded.Independent differential testing reported 611,066 passing checks with zero correctness differences, covering randomized inputs, alignment, signedness, range boundaries, page-end buffers and unsized searches.
These results establish functional equivalence for the tested inputs, not performance benefits.
Performance evidence
Earlier standalone host microbenchmarks indicated improvements on selected large-array workloads.
However, those measurements were outside an AnyPS5 title and do not establish gameplay improvements.
No qualifying same-title, same-scene before/after performance traces are available.
Current status
The PR remains draft pending qualifying title-level evidence or an explicit maintainer decision to accept the correctness-validated implementation without a demonstrated title performance benefit.
No gameplay performance claim is made.
Checklist
Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-29T04:45:49Z.
Review: COMMENTED
The branch doesn't contain the change this PR describes. Checked on macOS (host-side only):
496f97a1c2has one commit,feat(libkernel_sys): implement getfsstat. It changes only libkernel_sys/libc path-alias files (7 files, +57/-6).VectorAlgorithms.cppandGuestVectorAlgorithms.cpparen't modified, and the PR head has no SSE2 code in the__std_find_trivial_*/__std_count_trivial_*/__std_min_element_*helpers.496f97a1c24f84c17bae952cbbfd4bdb38e2072dis also the head of your closed #12695, so the getfsstat branch seems to have been pushed toperf/libc-vector-algorithms-sse2-10by mistake.Export.cppL56 declaresextern "C" int PosixStatfs_nid_no_patch(...)and calls it at L469, butgit grep PosixStatfsfinds no definition anywhere in the head tree or on main52c09d567d.git merge-tree: Export.cpp, GuestKernelSys.cpp, debt/libkernel_sys.md).conventionsjob is the body template: it uses## What/Tested/Checklistwhere the template needs###headings. The diff itself passescheck_conventions.py --base upstream/mainlocally.Could you force-push the vector-algorithms commit to this branch and fix the headings? I'm happy to run a differential check of the ten helpers against the scalar versions once it's there.
Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-29T05:11:07Z.
Review: COMMENTED
Thanks for pushing the vector commit. I tested 7bd7edae5e on the host only (macOS 26, Apple clang, built
-arch x86_64so__SSE2__is on, ASan+UBSan,-fno-sanitize-recover=undefined). I did not run it on a PS5 or under Windows.Differential vs main. I linked
VectorAlgorithms.cppfrom this PR and from main52c09d567d(main's symbols renamed) into one binary. A seeded random harness then compared find / count / find_unsized / min_element (signed and unsigned) for element sizes 1/2/4/8. Inputs: lengths 0–599, start offsets 0–63 bytes (so unaligned starts are covered), random data or 4-value pools with 0, all-ones and the sign bit, and targets taken from the range or from the pool. For find_unsized, the target is always present at or after the start.Mutants. 13 mutants, each run against the PR test and against the differential:
/ sizeof, skipping the first-block scan in unsized, signed int8 min treated as unsigned, unsigned uint16 min treated as signed, sign-flip constant, returning the last minimum instead of the first.bits >> 1(16-bit) or>> 3(32-bit) inMatchPositions, becausecmpeqsets every byte of a lane together;< 64→< 16;>= 16→> 16; startingminValueatlanes[1]. All five give 0 differences.MinElementSse2(for (; current != end; ...) if (value < minValue) ...). The PR test still passes because element 35 is already the minimum before the tail. The differential catches it (19,746 differences). This 2-row addition kills it, and passes on this PR and on main:Other checks
git merge-treeagainst main52c09d567dis clean, andcheck_conventions --base upstream/main --headpasses.__std_min/maxrange-check lines in the same file plusdocs/dev/debt/libc.md). Whichever lands second needs a small rebase.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:54:37Z.
Review: COMMENTED
-O3, 2,000 calls per sample, outside AnyPS5. The project's rule for a speed claim istools/trace_digest.pysummaries ofmainand the change from the same machine and scene. Nothing shows these__std_find_trivial,__std_count_trivialor__std_min_elementhelpers appear in any title's trace at all, or at what sizes. Typicalstd::findover a short range is not 1 MiB, and for short inputs the SSE2 prologue and scalar tail can be slower than the loop they replace._mm_cvtsi128_si64and is guarded by__SSE2__ || _M_X64. Which configurations take the scalar path, and does the new test run on one of them? The description lists only Linux x86-64 GCC 13.3.Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-11-02T19:43:53Z.
Review: APPROVED
Reviewed
e0ca5fec4f379bb00b60e6a632c5a761a8400582againstd8b60b46ed425b117b6fae18900fe6ab81ed6661for correctness of the SSE2 implementation and scalar fallback. No correctness blocker found in the reviewed diff.Windows x64 / WinLibs GCC 15.2 UCRT Release: registered
guest_vector_algorithmsandguest_vector_algorithms_scalarboth pass (2/2). Preprocessing confirms the production SSE2 guard is selected normally and excluded withANYPS5_LIBC_FORCE_SCALAR; this is scalar-source testing on x86-64, not an ARM/Emscripten runtime result.An independent
-O3harness compiles the original base, current SSE2 source and forced-scalar source separately with distinct symbol names and the real guest ABI. All 611,066 checks pass, covering deterministic randomized values/lengths/byte offsets, long all-match counts, empty ranges, signed/unsigned minima and first-tie behavior, guarded page-end buffers, and byte/word unsized searches. Bounded operations are also checked against independently computed expected results. These are functional checks, not benchmark iterations or proof of a gameplay speedup. Diff whitespace passes.The revised correctness-only framing is reasonable. The PR description still says to keep it draft pending title traces, so that text should be aligned with the intended scope and maintainers' requirements. This review does not establish a title-level performance benefit or waive repository performance policy.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T08:49:30Z.
Review: COMMENTED
Reviewed — no blocking findings
The implementation and its added tests show no verified blocking defect; the PR’s title and description also make clear that title level performance benefits have not been demonstrated.
What I ran
Reviewed head
e0ca5fec4f379bb00b60e6a632c5a761a8400582. Read the prepared description, commit list, manifest, diff, and the changed implementation, test, and CMake sections throughrepo_read.py. No build or tests were run during this review.Results
files.jsonwas unavailable through the readerFindings
Blocking
None.
Non-blocking
None.
Not verified
The author reports Windows x86_64 test runs and differential checks in the PR description; these were not independently run or verified. The
files.jsoninventory was unavailable, so I could not confirm whether any changed files were excluded from the prepared bundle. The prepared manifest lists three changed files, and all three were inspected in relevant sections; I did not read their full text.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T13:24:54Z.
Review: COMMENTED
Built the focused checks against the existing Linux runtime.
GuestVectorAlgorithmspassed.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.