Repository navigation
feat(libc): add C23 leading and trailing one counts - #12229
Conversation
Progress report (061cdb6 → d7986b1)📈 System libraries: 46.62% (+0.03%, +10 implemented functions) ✅ 10 implemented
Changed libraries (implemented exports)
|
MarcZX10
left a comment
There was a problem hiding this comment.
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.
|
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.
|
MarcZX10
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
What
Add the ten missing
stdc_leading_ones_{uc,us,ui,ul,ull}andstdc_trailing_ones_{uc,us,ui,ul,ull}libc exports. They count consecutive one bits from the most significant or least significant end using C++20std::countl_oneandstd::countr_one. Zero returns 0; an all-ones input returns 8, 16, 32, 64 or 64. The guestulargument 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(SHA256483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6), 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.stdc_leading_ones_ucGb7WaJE6NVY0x30440stdc_leading_ones_usxAkgpOJwa9k0x30450stdc_leading_ones_uin355wwngPkM0x30460stdc_leading_ones_ul+e7Kan3oiag0x30470stdc_leading_ones_ullkyMcGM6dDlk0x30480stdc_trailing_ones_ucai13B6znEco0x304e0stdc_trailing_ones_usexfJv2yF4-Q0x30500stdc_trailing_ones_uiL8ab0HIh9mY0x30510stdc_trailing_ones_ulrn7utXuD-Yk0x30520stdc_trailing_ones_ullRzigWMxfMMA0x30530No 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 main1829def9bf4a54a7df2449addfc2143016ed5b94. Published head:d7986b1fb6738b5971ac3c7b7e734207b81c414e, based on main6db75895fbcb425edb3edddedc17308582e5ff1d(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.
guest_one_runs_tests,guest_count_ones_testsandguest_integer_builtins_tests.ctest --test-dir build -R "^(guest_one_runs_(leading|trailing)_(uc|us|ui|ul|ull)|guest_count_ones_(uc|us|ui|ul|ull)|guest_integer_builtins|public_headers)$" -V --output-on-failurepasses 17/17 on both platforms on the runtime-tested head. Windows also rebuilt the NID-patched production libc used below.NotImplemented_nid_no_patch(__func__). Restoring production makes them pass with the same test executable; the negative, positive and final runtime-tested executable are byte-identical (SHA256805138cc256c58bf2d92d58250f44644692e876f3f10978bbfef297317d0f65c).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
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)