Skip to content

feat(libc): add C23 leading and trailing zero counts - #12193

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
Danigamer05:feat/libc-stdc-zero-runs
Oct 28, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
Danigamer05:feat/libc-stdc-zero-runs

Conversation

@Danigamer05

Copy link
Copy Markdown
Contributor

What

Add the ten missing stdc_leading_zeros_{uc,us,ui,ul,ull} and stdc_trailing_zeros_{uc,us,ui,ul,ull} libc exports. They return the zero-bit run before the highest set bit or after the lowest set bit, using C++20 std::countl_zero and std::countr_zero. Zero returns the argument's width: 8, 16, 32, 64 or 64. The guest ul argument is explicitly 64-bit on Windows. Each export has one public declaration and its own regression case.

Contract evidence is PPSA03671 v01.001.005's bundled libc.prx (SHA256 483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6), read from disassembly and run directly on a Windows host. All ten functions are call-free leaves. The signatures and semantics also follow C23 draft N3220, sections 7.18.3 and 7.18.5 and the LLVM libc stdbit declarations.

Export NID Input bits Original RVA
stdc_leading_zeros_uc GEWnLZqp9Hk 8 0x303f0
stdc_leading_zeros_us 7FB0t5y2r6A 16 0x30400
stdc_leading_zeros_ui pkc1bZWixqw 32 0x30410
stdc_leading_zeros_ul bJLACmBx3bI 64 0x30420
stdc_leading_zeros_ull UO464WICdrU 64 0x30430
stdc_trailing_zeros_uc chy93WuEyPw 8 0x30490
stdc_trailing_zeros_us xRF+BzlARZo 16 0x304a0
stdc_trailing_zeros_ui XS0cqoqWgNY 32 0x304b0
stdc_trailing_zeros_ul jMnJyLF8kPk 64 0x304c0
stdc_trailing_zeros_ull jqsveb-7TE4 64 0x304d0

No original binary, byte dump, third-party source, investigation notes or logs are committed. The remaining console-verification gap is recorded in libc's debt file.

Tested

Runtime-tested head: dc3999b2747bf068c0e229b0281cfc903dafaa0e, based on main 61924d4637aaaeab35bc7ba3e4d3156f9ebd025d. Published head: 504111f10c8bc83a8a9ae36a85bdd03c124528b5, based on main 19f71094a71751d5026bc2452452bb539979b463 (28 October 2026).

After the runtime tests, main received other libraries' implementation changes, regression tests, documentation and the import-audit tool update. All libc production sources, headers, CMake and the focused regression sources are byte-identical between the runtime-tested and published heads. The runtime and native-comparison results below belong to the stated tested head. Conventions, whitespace, strict main synchronization and the overlap comparison were checked on the published head.

The full CTest suite, all standalone-header compilation batches, macOS, console, title and GPU execution were not tested. No performance or title-unblock claim.

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

@github-actions

Copy link
Copy Markdown

Progress report (09d952f → 504111f)

📈 System libraries: 46.6% (+0.04%, +10 implemented functions)

✅ 10 implemented
Library Name
libc stdc_leading_zeros_uc_nid_postfix
libc stdc_leading_zeros_ui_nid_postfix
libc stdc_leading_zeros_ul_nid_postfix
libc stdc_leading_zeros_ull_nid_postfix
libc stdc_leading_zeros_us_nid_postfix
libc stdc_trailing_zeros_uc_nid_postfix
libc stdc_trailing_zeros_ui_nid_postfix
libc stdc_trailing_zeros_ul_nid_postfix
libc stdc_trailing_zeros_ull_nid_postfix
libc stdc_trailing_zeros_us_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libc 1404/1417 (99.08%) 1414/1427 (99.09%) +0.01 pp

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent exact-head review of 504111f10c8bc83a8a9ae36a85bdd03c124528b5: the ten exports use the correct width-specific C++20 operations, zero-input widths and ul 64-bit PS5 ABI; all ten NIDs independently match tools/nid_names.py. The public-header audit passes (368 libraries, 12,994 exports), conventions and diff checks pass, the merge preview against current main is clean, and both changed C++ files pass GCC 12 C++20 syntax-only compilation. The official overlap scan found no confirmed duplicate or code-line overlap; its 39 historical-branch warnings are confined to shared/conflicted files. I checked the warned PR diffs for these ten names; #5021 exceeds GitHub’s 300-file diff limit, but its paginated changed-file list and relevant CMake/debt hunks do not touch the new declarations or implementations. Author-reported exhaustive fixed-width/random tests and original-binary comparisons are detailed in the PR. Hosted policy checks, Linux/Windows/macOS relinker and register-context jobs, and macOS write-watch jobs pass; the full Windows build is still pending, while Linux full build is skipped by path selection. I found no code blocker in the review completed so far; I’m leaving this as a comment until the Windows build finishes.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The full Windows build has now completed successfully on the same reviewed head 504111f10c8bc83a8a9ae36a85bdd03c124528b5; the earlier Linux/macOS relinker, register-context, write-watch, and policy checks also passed. My exact-head review found no code blocker, and the independent NID, public-header, convention, syntax, merge-preview, and overlap checks are recorded in my earlier review comment. Linux full build was skipped by path selection. I approve this revision.

@github-actions

github-actions Bot commented Oct 28, 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 5021 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 6085 core/libs/prx/libc/CMakeLists.txt
PR 6713 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 7081 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 7386 docs/dev/debt/libc.md
PR 7447 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 7715 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 8150 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 8937 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/include/Api.hpp
docs/dev/debt/libc.md
PR 9371 docs/dev/debt/libc.md
PR 9447 docs/dev/debt/libc.md
PR 9526 docs/dev/debt/libc.md
PR 9688 docs/dev/debt/libc.md
PR 9775 core/libs/prx/libc/CMakeLists.txt
PR 9929 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 10253 docs/dev/debt/libc.md
PR 10324 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/include/Api.hpp
docs/dev/debt/libc.md
PR 10433 docs/dev/debt/libc.md
PR 10620 docs/dev/debt/libc.md
PR 11270 docs/dev/debt/libc.md
PR 11332 docs/dev/debt/libc.md
PR 11625 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 11849 docs/dev/debt/libc.md
PR 11872 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/include/Api.hpp
docs/dev/debt/libc.md
PR 11892 docs/dev/debt/libc.md
PR 11969 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/include/Api.hpp
docs/dev/debt/libc.md
PR 12397 docs/dev/debt/libc.md
PR 12598 docs/dev/debt/libc.md
PR 12605 docs/dev/debt/libc.md

@MarcZX10 MarcZX10 mentioned this pull request Oct 28, 2026
12 tasks done
@oneandonlydean oneandonlydean self-assigned this Oct 28, 2026
@oneandonlydean
oneandonlydean merged commit 34ae0d5 into boykopovar:main Oct 28, 2026
18 checks passed
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.

3 participants