Skip to content

feat(libc): add C23 count-ones exports - #11663

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

adriadam10 merged 1 commit into
boykopovar:mainfrom
Danigamer05:feat/libc-stdc-count-ones

Conversation

@Danigamer05

Copy link
Copy Markdown
Contributor

What

Implement the five missing stdc_count_ones_{uc,us,ui,ul,ull} libc exports using the existing C++20 std::popcount support in IntegerBuiltins.cpp. Each returns the number of set bits as uint32_t. Inputs are unsigned 8, 16, 32, 64 and 64 bits respectively; ul explicitly stays 64-bit on Windows to preserve the guest LP64 ABI. Each export has one public declaration, and each width has its own regression test.

Contract evidence is the libc.prx bundled with PPSA03671 v01.001.005 (SHA256 483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6), supplemented by C23 draft N3220, section 7.18.12 and the LLVM libc stdbit signatures.

Export NID Input bits Original RVA
stdc_count_ones_uc VV9JOsHi9f0 8 0x307b0
stdc_count_ones_us gnkfi6EgH+A 16 0x307c0
stdc_count_ones_ui lCm3HL3DTMk 32 0x307d0
stdc_count_ones_ul nz-w4D57ff0 64 0x307e0
stdc_count_ones_ull 2HLlqICSbCA 64 0x307f0

The first three original functions count the bits of the zero-extended argument in edi; the last two count the 64-bit argument in rdi. All five are call-free leaves returning that count. They were also executed directly on a Windows host as described below. No console measurement is claimed; this gap is recorded beside the integer builtins in docs/dev/debt/libc.md. No original binary, byte dump, third-party source, investigation notes or logs are committed.

Tested

Runtime-tested head: a32936391b6d43cf702324b2870106682b2607b7, based on main e2d457be345d62842ec929ca08680bb1286c6830. Published head: 218e9c7e4e5be8f45246ea159707e3f22344adab, based on main 27ad7244d22153ebfd576e04e3c4d63e0b92264b (27 October 2026).

After those runtime tests, main received graphics-only updates in AGC, AGCDriver and the shader recompiler. The branch was rebased onto the newer base and its debt entry moved to avoid documentation conflicts. All libc production sources, declarations, CMake registration and regression sources are byte-identical to the runtime-tested head; no libc path changed between the two main bases. The runtime and native differential results below belong to the stated tested head. Conventions, whitespace, strict synchronization and the final overlap comparison were checked again on the published head.

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

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 (27ad724 → 218e9c7)

📈 System libraries: 51.84% (+0.01%, +5 implemented functions)

✅ 5 implemented
Library Name
libc stdc_count_ones_uc_nid_postfix
libc stdc_count_ones_ui_nid_postfix
libc stdc_count_ones_ul_nid_postfix
libc stdc_count_ones_ull_nid_postfix
libc stdc_count_ones_us_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libc 1395/1404 (99.36%) 1400/1409 (99.36%) +0.00 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.

Reviewed exact head 218e9c7e4e5be8f45246ea159707e3f22344adab. The five declarations, std::popcount implementations and per-width CTest registration are consistent, including the explicit 64-bit ul guest ABI on Windows. The regression tests use an independent shift reference, exhaustive 8/16-bit inputs, edge patterns and deterministic wider inputs; the debt note accurately says console behavior is not measured. I verified the changed test and implementation translation units with c++ -std=c++20 -fsyntax-only (using the PR header for its new declarations), and git diff --check plus conventions pass. Hosted eligibility, conventions, intake, labels, report, Ubuntu/Windows relinker, ASan and Ubuntu register-context checks pass. macOS jobs are still queued; Linux/Windows product jobs were skipped by path policy. The PR reports separate Windows and Ubuntu runtime/differential testing on its stated tested head; I did not rerun those full tests locally.

@github-actions

github-actions Bot commented Oct 27, 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 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 10324 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/include/Api.hpp
docs/dev/debt/libc.md
PR 10349 docs/dev/debt/libc.md
PR 10433 docs/dev/debt/libc.md
PR 10620 docs/dev/debt/libc.md
PR 11332 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 11848 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 11872 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/include/Api.hpp
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

@adriadam10 adriadam10 self-assigned this Oct 27, 2026
@adriadam10
adriadam10 merged commit 439d03d into boykopovar:main Oct 28, 2026
18 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the five NIDs against tools/nid_names.py, the std::popcount bodies (8/16/32/64/64-bit inputs, uint32_t result, ul 64-bit on Windows), the per-width ctest registration and the independent-reference tests (exhaustive 8/16-bit, edge and random wider inputs), and the debt entry; merged.

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