Skip to content

feat(libc): implement the remaining Dinkumware _Atomic helpers - #6334

Open
hypermoist wants to merge 1 commit into
boykopovar:mainfrom
hypermoist:feat/libc-dinkumware-atomics
Open

hypermoist wants to merge 1 commit into
boykopovar:mainfrom
hypermoist:feat/libc-dinkumware-atomics

Conversation

@hypermoist

Copy link
Copy Markdown

What

Implements the 48 Dinkumware _Atomic_* helpers of the system libc.prx that AnyPS5 did not have (it already had _Atomic_fetch_add_4, _Atomic_fetch_sub_4, _Atomic_compare_exchange_weak_4 and _Atomic_load_4), in a new src/DinkumwareAtomics.cpp:

  • typed 1/2/4/8-byte _Atomic_store_N, _Atomic_load_N, _Atomic_exchange_N, _Atomic_compare_exchange_{strong,weak}_N, _Atomic_fetch_{add,sub,and,or,xor}_N (the sizes missing upstream)
  • _Atomic_is_lock_free_{1,2,4,8}, _Atomic_flag_test_and_set, _Atomic_flag_clear, _Atomic_thread_fence, _Atomic_signal_fence
  • the generic _Atomic_copy, _Atomic_exchange, _Atomic_compare_exchange_strong and _Atomic_compare_exchange_weak, which take a byte spinlock flag and a size, lock the flag, memcmp/copy the bytes and unlock, as on the console

Every operation is sequentially consistent whatever memory order it is given, never weaker than the console. The libc.prx bundled with PPSA08427 has observable quirks for unusual orders, which are reproduced: _Atomic_load_8 returns 0 for release, acq_rel or an invalid order, and the 8-byte exchange and fetch operations return 0 without touching memory for an order above memory_order_seq_cst. Recorded in docs/dev/debt/libc.md.

Tested

Linux (CachyOS, GCC Release build, plus a clang -Wall -Wextra syntax check): new guest_dinkumware_atomics test (each family, the order quirks, the flag, the generic functions, and two threads updating a 24-byte object through the locked compare-exchange) passes, as does guest_libc_threads. tools/check_conventions.py passes; tools/pr_overlap.py --branch reports no line overlap.

Differential test against the console: the PPSA08427 libc.prx was mapped into a Linux process and every function here was run side by side with this implementation on random values with every memory order from 0 to 7 (stores only with valid orders, since the console's store falls off its jump table otherwise), and the generic functions on sizes 1 to 40 with equal and unequal expected values; return values, targets, expected buffers and lock flags 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

The 1-, 2- and 8-byte loads, stores, exchanges, compare-exchanges and fetch
operations, _Atomic_is_lock_free_N, the flag and fence functions and the
lock-based generic _Atomic_copy, _Atomic_exchange and _Atomic_compare_exchange_*,
matching the libc.prx bundled with PPSA08427 including its handling of
invalid memory orders.

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 (34454bd → c0cf6e5)

📈 System libraries: 88.86% (+0.15%, +48 implemented functions)

✅ 48 implemented
Library Name
libc _Atomic_compare_exchange_strong_1_nid_postfix
libc _Atomic_compare_exchange_strong_2_nid_postfix
libc _Atomic_compare_exchange_strong_4_nid_postfix
libc _Atomic_compare_exchange_strong_8_nid_postfix
libc _Atomic_compare_exchange_strong_nid_postfix
libc _Atomic_compare_exchange_weak_1_nid_postfix
libc _Atomic_compare_exchange_weak_2_nid_postfix
libc _Atomic_compare_exchange_weak_8_nid_postfix
libc _Atomic_compare_exchange_weak_nid_postfix
libc _Atomic_copy_nid_postfix
libc _Atomic_exchange_1_nid_postfix
libc _Atomic_exchange_2_nid_postfix
libc _Atomic_exchange_4_nid_postfix
libc _Atomic_exchange_8_nid_postfix
libc _Atomic_exchange_nid_postfix
libc _Atomic_fetch_add_1_nid_postfix
libc _Atomic_fetch_add_2_nid_postfix
libc _Atomic_fetch_add_8_nid_postfix
libc _Atomic_fetch_and_1_nid_postfix
libc _Atomic_fetch_and_2_nid_postfix
libc _Atomic_fetch_and_4_nid_postfix
libc _Atomic_fetch_and_8_nid_postfix
libc _Atomic_fetch_or_1_nid_postfix
libc _Atomic_fetch_or_2_nid_postfix
libc _Atomic_fetch_or_4_nid_postfix
libc _Atomic_fetch_or_8_nid_postfix
libc _Atomic_fetch_sub_1_nid_postfix
libc _Atomic_fetch_sub_2_nid_postfix
libc _Atomic_fetch_sub_8_nid_postfix
libc _Atomic_fetch_xor_1_nid_postfix
libc _Atomic_fetch_xor_2_nid_postfix
libc _Atomic_fetch_xor_4_nid_postfix
libc _Atomic_fetch_xor_8_nid_postfix
libc _Atomic_flag_clear_nid_postfix
libc _Atomic_flag_test_and_set_nid_postfix
libc _Atomic_is_lock_free_1_nid_postfix
libc _Atomic_is_lock_free_2_nid_postfix
libc _Atomic_is_lock_free_4_nid_postfix
libc _Atomic_is_lock_free_8_nid_postfix
libc _Atomic_load_1_nid_postfix
libc _Atomic_load_2_nid_postfix
libc _Atomic_load_8_nid_postfix
libc _Atomic_signal_fence_nid_postfix
libc _Atomic_store_1_nid_postfix
libc _Atomic_store_2_nid_postfix
libc _Atomic_store_4_nid_postfix
libc _Atomic_store_8_nid_postfix
libc _Atomic_thread_fence_nid_postfix
⚪ 5 behaviourally empty (constant return or throw)
Library Name
libc _Atomic_is_lock_free_1_nid_postfix
libc _Atomic_is_lock_free_2_nid_postfix
libc _Atomic_is_lock_free_4_nid_postfix
libc _Atomic_is_lock_free_8_nid_postfix
libc _Atomic_signal_fence_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 3965 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 3987 docs/dev/debt/libc.md
PR 4627 core/libs/prx/libc/CMakeLists.txt
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 6079 core/libs/prx/libc/CMakeLists.txt
PR 6084 core/libs/prx/libc/CMakeLists.txt
PR 6085 core/libs/prx/libc/CMakeLists.txt
PR 6086 core/libs/prx/libc/CMakeLists.txt
PR 6144 docs/dev/debt/libc.md
PR 6226 docs/dev/debt/libc.md
PR 6469 docs/dev/debt/libc.md
PR 6541 docs/dev/debt/libc.md
PR 6565 docs/dev/debt/libc.md
PR 6610 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 6686 docs/dev/debt/libc.md
PR 6707 docs/dev/debt/libc.md
PR 6713 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 6819 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 6842 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 6851 core/libs/prx/libc/CMakeLists.txt
PR 6916 docs/dev/debt/libc.md
PR 6975 docs/dev/debt/libc.md
PR 6985 core/libs/prx/libc/CMakeLists.txt
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
PR 7386 docs/dev/debt/libc.md
PR 7411 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 7417 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 7447 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 7470 core/libs/prx/libc/CMakeLists.txt
PR 7473 docs/dev/debt/libc.md
PR 7506 docs/dev/debt/libc.md
PR 7525 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 7529 docs/dev/debt/libc.md
PR 7544 docs/dev/debt/libc.md
PR 7545 docs/dev/debt/libc.md
PR 7546 docs/dev/debt/libc.md
PR 7634 docs/dev/debt/libc.md
PR 7648 docs/dev/debt/libc.md

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build docs libc needs rebase Conflicts with main, rebase needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant