Skip to content

feat(libc): add C23 leading and trailing one counts - #12229

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

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

Conversation

@Danigamer05

Copy link
Copy Markdown
Contributor

What

Add the ten missing stdc_leading_ones_{uc,us,ui,ul,ull} and stdc_trailing_ones_{uc,us,ui,ul,ull} libc exports. They count consecutive one bits from the most significant or least significant end using C++20 std::countl_one and std::countr_one. Zero returns 0; an all-ones input returns 8, 16, 32, 64 or 64. The guest ul argument is explicitly 64-bit on Windows. Each export has one public declaration and a separate 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 counting the corresponding zero run in the width-limited complement. The signatures and semantics also follow C23 draft N3220, sections 7.18.4 and 7.18.6 and the LLVM libc stdbit declarations.

Export NID Input bits Original RVA
stdc_leading_ones_uc Gb7WaJE6NVY 8 0x30440
stdc_leading_ones_us xAkgpOJwa9k 16 0x30450
stdc_leading_ones_ui n355wwngPkM 32 0x30460
stdc_leading_ones_ul +e7Kan3oiag 64 0x30470
stdc_leading_ones_ull kyMcGM6dDlk 64 0x30480
stdc_trailing_ones_uc ai13B6znEco 8 0x304e0
stdc_trailing_ones_us exfJv2yF4-Q 16 0x30500
stdc_trailing_ones_ui L8ab0HIh9mY 32 0x30510
stdc_trailing_ones_ul rn7utXuD-Yk 64 0x30520
stdc_trailing_ones_ull RzigWMxfMMA 64 0x30530

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: 1d64984245b43ccb6a13162fd748a44058c4d4e7, based on main 1829def9bf4a54a7df2449addfc2143016ed5b94. Published head: d7986b1fb6738b5971ac3c7b7e734207b81c414e, based on main 6db75895fbcb425edb3edddedc17308582e5ff1d (28 October 2026).

After runtime testing, main received AGC changes and other libraries' regression tests. 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 (061cdb6 → d7986b1)

📈 System libraries: 46.62% (+0.03%, +10 implemented functions)

✅ 10 implemented
Library Name
libc stdc_leading_ones_uc_nid_postfix
libc stdc_leading_ones_ui_nid_postfix
libc stdc_leading_ones_ul_nid_postfix
libc stdc_leading_ones_ull_nid_postfix
libc stdc_leading_ones_us_nid_postfix
libc stdc_trailing_ones_uc_nid_postfix
libc stdc_trailing_ones_ui_nid_postfix
libc stdc_trailing_ones_ul_nid_postfix
libc stdc_trailing_ones_ull_nid_postfix
libc stdc_trailing_ones_us_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libc 1410/1423 (99.09%) 1420/1433 (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.

I reviewed the implementation and regression coverage. The ten functions use width-correct unsigned arguments and C++20 countl_one/countr_one; the test includes exhaustive 8/16-bit inputs, boundary and complement cases, deterministic wider-input coverage, and errno preservation. The description also distinguishes the host comparison from console verification and records that remaining gap. On the exact head, conventions, whitespace, the Linux/Debug and Linux/Release register-context jobs, Ubuntu relinker and relinker ASan passed; Windows, Windows relinker, and macOS jobs remain in progress, while full Linux is skipped. The author reports focused runtime/reference checks on Windows and Ubuntu WSL.

I’m requesting an update to current main before approval as required by CONTRIBUTING. The branch is 19 commits behind 7fe69e276fc4e000ccb2a360ea8faeb3d7fcc137; those changes do not overlap this PR and the merge preview is clean. Please rebase/update and rerun the affected checks on the resulting head. I found no functional issue in the implementation as reviewed.

@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 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 ten definitions use the correct width-specific unsigned types, and countl_one/countr_one match the described semantics. The focused host tests, original-versus-production comparisons, overlap analysis, and hosted checks are extensive; I found no functional defect in the reviewed diff. The published branch is based on 6db75895, while current main is 0c5401dc (43 commits ahead). CONTRIBUTING requires branches to be based on current main; please update the branch and rerun the focused libc cases and conventions check on that head before approval.

@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 new exports use width-specific unsigned arguments and C++20 countl_one/countr_one, matching the described C23 operations; the Windows unsigned long ABI is explicitly fixed to 64 bits. Tests include zero, all ones, boundaries and reference-count comparisons, and the ABI evidence is identified as title libc.prx disassembly/runtime results. Current registration, Windows, and cross-platform relinker checks pass. No blocking issue found.

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