Skip to content

feat(libc): implement the __std vectorized algorithm helpers - #6339

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
hypermoist:feat/libc-std-vector-algorithms
Oct 19, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
hypermoist:feat/libc-std-vector-algorithms

Conversation

@hypermoist

@hypermoist hypermoist commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What

Implements the 33 MSVC-STL-style vectorized algorithm helpers that the system libc.prx exports and AnyPS5 did not have, in a new src/VectorAlgorithms.cpp:

  • __std_find_trivial_N, __std_find_trivial_unsized_N, __std_count_trivial_N
  • __std_min_element_N, __std_max_element_N, __std_minmax_element_N ((first, last, bool signed); first minimum, first maximum, and for minmax the first minimum and last maximum, returned as two pointers)
  • __std_reverse_trivially_swappable_N, __std_reverse_copy_trivially_copyable_N
  • __std_swap_ranges_trivially_swappable_noalias (declared void, as in MSVC's STL; the console leaves an unrelated value in rax)

for N = 1, 2, 4, 8, as scalar loops.

The console's __std_find_trivial_unsized_N has a quirk that is reproduced: when nothing matches between first and the end of its 32-byte-aligned block, it rescans that whole block without masking, so it can return a match up to 31 bytes before first. Recorded in docs/dev/debt/libc.md.

Tested

Linux (CachyOS, GCC Release build, plus a clang -Wall -Wextra syntax check): new guest_vector_algorithms test passes. tools/check_conventions.py passes; tools/pr_overlap.py --branch reports no line overlap.

Differential test against the console: the PPSA08427 libc.prx was mapped into a Linux process and every helper was run side by side with this implementation on 30,000 random arrays per element size (lengths 0-100, element-aligned start offsets, small value ranges so ties are frequent, both signedness flags), plus 30,000 random swap_ranges calls; returned pointers, counts and memory agree everywhere.

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
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

https://claude.ai/code/session_01Q8tinbP1MUpUaDsbNWnGnu

__std_find_trivial(_unsized), __std_count_trivial, __std_min/max/minmax_element,
__std_reverse_trivially_swappable, __std_reverse_copy_trivially_copyable and
__std_swap_ranges_trivially_swappable_noalias for 1-, 2-, 4- and 8-byte
elements, matching the libc.prx bundled with PPSA08427 including the rescan of
the first aligned block in the unsized find.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q8tinbP1MUpUaDsbNWnGnu
@github-actions

Copy link
Copy Markdown

Progress report (f7a90d6 → 6103a3e)

📈 System libraries: 88.8% (+0.1%, +33 implemented functions)

✅ 33 implemented
Library Name
libc __std_count_trivial_1_nid_postfix
libc __std_count_trivial_2_nid_postfix
libc __std_count_trivial_4_nid_postfix
libc __std_count_trivial_8_nid_postfix
libc __std_find_trivial_1_nid_postfix
libc __std_find_trivial_2_nid_postfix
libc __std_find_trivial_4_nid_postfix
libc __std_find_trivial_8_nid_postfix
libc __std_find_trivial_unsized_1_nid_postfix
libc __std_find_trivial_unsized_2_nid_postfix
libc __std_find_trivial_unsized_4_nid_postfix
libc __std_find_trivial_unsized_8_nid_postfix
libc __std_max_element_1_nid_postfix
libc __std_max_element_2_nid_postfix
libc __std_max_element_4_nid_postfix
libc __std_max_element_8_nid_postfix
libc __std_min_element_1_nid_postfix
libc __std_min_element_2_nid_postfix
libc __std_min_element_4_nid_postfix
libc __std_min_element_8_nid_postfix
libc __std_minmax_element_1_nid_postfix
libc __std_minmax_element_2_nid_postfix
libc __std_minmax_element_4_nid_postfix
libc __std_minmax_element_8_nid_postfix
libc __std_reverse_copy_trivially_copyable_1_nid_postfix
libc __std_reverse_copy_trivially_copyable_2_nid_postfix
libc __std_reverse_copy_trivially_copyable_4_nid_postfix
libc __std_reverse_copy_trivially_copyable_8_nid_postfix
libc __std_reverse_trivially_swappable_1_nid_postfix
libc __std_reverse_trivially_swappable_2_nid_postfix
libc __std_reverse_trivially_swappable_4_nid_postfix
libc __std_reverse_trivially_swappable_8_nid_postfix
libc __std_swap_ranges_trivially_swappable_noalias_nid_postfix

This was referenced Oct 15, 2026
@github-actions

github-actions Bot commented Oct 15, 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 3987 docs/dev/debt/libc.md
PR 5021 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 5303 docs/dev/debt/libc.md
PR 6044 core/libs/prx/libc/CMakeLists.txt
PR 6226 docs/dev/debt/libc.md
PR 6565 docs/dev/debt/libc.md
PR 7039 docs/dev/debt/libc.md
PR 7081 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 7084 core/libs/prx/libc/CMakeLists.txt
PR 7201 core/libs/prx/libc/CMakeLists.txt

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.

2 participants