Skip to content

feat(libc): add C23 count-zeros exports - #12187

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

oneandonlydean merged 1 commit into
boykopovar:mainfrom
Danigamer05:feat/libc-stdc-count-zeros

Conversation

@Danigamer05

Copy link
Copy Markdown
Contributor

What

Add the five missing stdc_count_zeros_{uc,us,ui,ul,ull} libc exports. They return the number of zero bits in their unsigned argument as uint32_t, using the existing C++20 std::popcount support in IntegerBuiltins.cpp. For example, zero returns the type's width and an all-ones argument returns zero. The guest ul argument stays 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. The five functions are call-free leaves counting the complemented argument at its stated width. The signatures and zero-bit semantics also follow C23 draft N3220, section 7.18.11 and the LLVM libc stdbit declarations.

Export NID Input bits Original RVA
stdc_count_zeros_uc 5DURS5C7Ops 8 0x30760
stdc_count_zeros_us 4GzA8wMtal8 16 0x30770
stdc_count_zeros_ui TEzfCIqfppU 32 0x30780
stdc_count_zeros_ul d+GiccCjl9o 64 0x30790
stdc_count_zeros_ull 7njNPBGm1V4 64 0x307a0

The implementation is written from this contract. 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

Exact tested/published head: e5835d6866aa2303924a22eacdd5bd8e72a7ba00. Main base: cccdaa2734a71d27e6c907325c60fdf2d3baf0af (28 October 2026).

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 (cccdaa2 → e5835d6)

📈 System libraries: 46.58% (+0.02%, +5 implemented functions)

✅ 5 implemented
Library Name
libc stdc_count_zeros_uc_nid_postfix
libc stdc_count_zeros_ui_nid_postfix
libc stdc_count_zeros_ul_nid_postfix
libc stdc_count_zeros_ull_nid_postfix
libc stdc_count_zeros_us_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libc 1404/1417 (99.08%) 1409/1422 (99.09%) +0.00 pp

@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 7648 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 9677 docs/dev/debt/libc.md
PR 9775 core/libs/prx/libc/CMakeLists.txt
PR 9867 docs/dev/debt/libc.md
PR 9929 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 10113 docs/dev/debt/libc.md
PR 10222 docs/dev/debt/libc.md
PR 10226 docs/dev/debt/libc.md
PR 10229 docs/dev/debt/libc.md
PR 10234 docs/dev/debt/libc.md
PR 10245 docs/dev/debt/libc.md
PR 10247 docs/dev/debt/libc.md
PR 10250 docs/dev/debt/libc.md
PR 10253 docs/dev/debt/libc.md
PR 10265 docs/dev/debt/libc.md
PR 10315 docs/dev/debt/libc.md
PR 10317 docs/dev/debt/libc.md
PR 10321 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 10325 docs/dev/debt/libc.md
PR 10328 docs/dev/debt/libc.md
PR 10345 docs/dev/debt/libc.md
PR 10349 docs/dev/debt/libc.md
PR 10433 docs/dev/debt/libc.md
PR 10506 docs/dev/debt/libc.md
PR 10510 docs/dev/debt/libc.md
PR 10512 docs/dev/debt/libc.md
PR 10565 docs/dev/debt/libc.md
PR 10620 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 11664 core/libs/prx/libc/include/Api.hpp
docs/dev/debt/libc.md
PR 11831 core/libs/prx/libc/include/Api.hpp
docs/dev/debt/libc.md
PR 11850 docs/dev/debt/libc.md
PR 11870 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 12053 docs/dev/debt/libc.md
PR 12122 docs/dev/debt/libc.md

@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.

I reviewed exact head e5835d6866aa2303924a22eacdd5bd8e72a7ba00. The five zero-count functions use the correct fixed-width unsigned inputs, with ul explicitly 64-bit for the PS5 ABI on Windows; the bit-count complement formula returns the input width for zero and zero for all ones. I independently recomputed all five NIDs with tools/nid_names.py, and the public-header audit passes (368 libraries, 12,989 exports). Both changed C++ files pass local GCC C++20 syntax-only compilation; conventions and git diff --check pass, and the current-main merge preview is clean. I also checked the interaction with open #12193: it introduces distinct leading/trailing-zero symbols, and the two branches combine cleanly. The PR’s exact-head report documents focused Linux and Windows test runs plus 1,348,815 original-versus-production calls with zero mismatches; hosted policy, relinker, register-context, write-watch and Windows jobs pass. Linux full build and the full CTest suite were not run in this review. I found no blocker in this revision.

@oneandonlydean oneandonlydean self-assigned this Oct 28, 2026
@oneandonlydean
oneandonlydean merged commit 14a269c 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