Skip to content

feat(libc): implement the 16-byte __sync builtins and __atomic_is_lock_free - #6331

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
hypermoist:feat/libc-generic-atomics
Oct 18, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
hypermoist:feat/libc-generic-atomics

Conversation

@hypermoist

Copy link
Copy Markdown
Contributor

What

Implements the libatomic-style exports of the system libc.prx that AnyPS5 did not have, in a new src/AtomicBuiltins.cpp:

  • __sync_fetch_and_add_16, __sync_fetch_and_sub_16, __sync_fetch_and_and_16, __sync_fetch_and_or_16, __sync_fetch_and_xor_16, __sync_lock_test_and_set_16: a lock cmpxchg16b loop returning the previous value, as on the console (GNU inline asm, so no -mcx16/libatomic is needed on either host)
  • __atomic_is_lock_free(size, ptr): sizes 0 and 1 are lock-free, 2/4/8/16 when ptr is aligned to the size, anything else is not (the console's jump table)
  • __atomic_load, __atomic_store, __atomic_exchange, __atomic_compare_exchange: in the libc.prx bundled with PPSA08427 each of these is a single ud2, so a call traps on the console; they throw here, recorded in docs/dev/debt/libc.md

Tested

Linux (CachyOS, GCC Release build, plus a clang -Wall -Wextra syntax check): new guest_atomic_builtins test (each operation, the lock-free table, the traps, and two threads racing __sync_fetch_and_add_16 across the 64-bit carry) passes. tools/check_conventions.py passes; tools/pr_overlap.py --branch reports no overlap.

Differential test against the console: the PPSA08427 libc.prx was mapped into a Linux process and __atomic_is_lock_free (sizes 0-39, 64 alignments) and each 16-byte operation (100,000 random operand pairs) were run side by side with this implementation; returned values and memory agree everywhere.

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
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

https://claude.ai/code/session_01Q8tinbP1MUpUaDsbNWnGnu

…k_free

__sync_fetch_and_{add,sub,and,or,xor}_16 and __sync_lock_test_and_set_16 are
cmpxchg16b loops returning the previous value, and __atomic_is_lock_free
answers by size and alignment, as in the libc.prx bundled with PPSA08427. Its
generic __atomic_load/store/exchange/compare_exchange are a ud2, so they throw.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q8tinbP1MUpUaDsbNWnGnu
@github-actions

Copy link
Copy Markdown

Progress report (b3f9f89 → 6d2708a)

📈 System libraries: 88.75% (+0.04%, +11 implemented functions)

✅ 11 implemented
Library Name
libc __atomic_compare_exchange_nid_postfix
libc __atomic_exchange_nid_postfix
libc __atomic_is_lock_free_nid_postfix
libc __atomic_load_nid_postfix
libc __atomic_store_nid_postfix
libc __sync_fetch_and_add_16_nid_postfix
libc __sync_fetch_and_and_16_nid_postfix
libc __sync_fetch_and_or_16_nid_postfix
libc __sync_fetch_and_sub_16_nid_postfix
libc __sync_fetch_and_xor_16_nid_postfix
libc __sync_lock_test_and_set_16_nid_postfix

This was referenced Oct 15, 2026
@github-actions

github-actions Bot commented Oct 15, 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 3987 docs/dev/debt/libc.md
PR 5021 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 5303 docs/dev/debt/libc.md
PR 6044 core/libs/prx/libc/CMakeLists.txt
PR 6226 docs/dev/debt/libc.md
PR 6565 docs/dev/debt/libc.md
PR 7039 docs/dev/debt/libc.md
PR 7081 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 7084 core/libs/prx/libc/CMakeLists.txt
PR 7201 core/libs/prx/libc/CMakeLists.txt
PR 7332 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md

@adriadam10 adriadam10 self-assigned this Oct 18, 2026
@adriadam10
adriadam10 merged commit 0f12173 into boykopovar:main Oct 18, 2026
13 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.

2 participants