refactor(libc): call atomic_signal_fence from _Atomic_signal_fence #10569

Closed
MarcZX10 wants to merge 2 commits from upstream-pr/10569 into main
MarcZX10 commented 2026-10-24 10:21:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T10:21:55Z.


What

Makes _Atomic_signal_fence_nid_postfix call std::atomic_signal_fence for valid memory orders, as the Microsoft STL body at pinned commit b6f01e438b68ee497f9c08313e49d12bb2f0d8e0 does; invalid integer orders are ignored. There is no observable behaviour change. The export is an out-of-line function, so the call boundary is what gives a guest its ordering, and the compiled body is a ret either way (reported on the PR from a Windows build with objdump). The test now calls the export with every order from relaxed through sequentially consistent instead of only sequentially consistent; it passes on main's body too and is a smoke check, not a regression test for a behaviour. PS5 behavior is not directly verified.

Tested

Debian Linux, GCC 12.2.0: compiled DinkumwareAtomics.cpp with GuestDinkumwareAtomics.cpp using C++20, -O2 and pthreads, then ran the focused test successfully. The test invokes every memory order value from relaxed through sequentially consistent. objdump of the wrapper showed no hardware fence instruction. python3 tools/check_conventions.py --base upstream/main and git diff --check passed. The full project build, Windows, and PS5 hardware were not tested.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4994571038 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10569). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T10:21:55Z. --- ### What Makes `_Atomic_signal_fence_nid_postfix` call `std::atomic_signal_fence` for valid memory orders, as the Microsoft STL body at pinned commit [`b6f01e438b68ee497f9c08313e49d12bb2f0d8e0`](https://github.com/microsoft/STL/blob/b6f01e438b68ee497f9c08313e49d12bb2f0d8e0/stl/inc/atomic) does; invalid integer orders are ignored. **There is no observable behaviour change.** The export is an out-of-line function, so the call boundary is what gives a guest its ordering, and the compiled body is a `ret` either way (reported on the PR from a Windows build with `objdump`). The test now calls the export with every order from relaxed through sequentially consistent instead of only sequentially consistent; it passes on `main`'s body too and is a smoke check, not a regression test for a behaviour. PS5 behavior is not directly verified. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Debian Linux, GCC 12.2.0: compiled `DinkumwareAtomics.cpp` with `GuestDinkumwareAtomics.cpp` using C++20, `-O2` and pthreads, then ran the focused test successfully. The test invokes every memory order value from relaxed through sequentially consistent. `objdump` of the wrapper showed no hardware fence instruction. `python3 tools/check_conventions.py --base upstream/main` and `git diff --check` passed. The full project build, Windows, and PS5 hardware were not tested. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
harisibrar1 commented 2026-10-24 12:28:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T12:28:37Z.

Review: COMMENTED


Checked against main 87666fc5d6 and Microsoft STL b6f01e43 (stl/inc/atomic):

  • Main already has _Atomic_signal_fence_nid_postfix as an empty function (DinkumwareAtomics.cpp:146, from ec3fe412db), and I think that body is already correct. A signal fence is only a compiler barrier, and when the guest calls an out-of-line libc.prx export, the call itself is that barrier: the guest's compiler can't move escaping memory accesses across an opaque call. Inside the callee there are no loads or stores for std::atomic_signal_fence to order, so I'd expect the new body to compile to the same bare ret as main. I didn't compile it to confirm, but your objdump finding no fence instruction is consistent with that.
  • The new test loop calls each order but checks nothing, so it would pass against main as well.
  • docs/dev/debt/libc.md already covers this file in the "Dinkumware atomics" entry under Unknown function info (line 33). The new Functional bullet duplicates it and says the function "orders compiler operations", which the callee can't do by itself. If a note is wanted, one sentence in the existing entry saying _Atomic_signal_fence is a no-op because the call is the compiler barrier seems more accurate than a separate item.
  • Unless I'm missing an observable difference, this could probably be closed as already covered by main.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638236599 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10569#pullrequestreview-5638236599). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-24T12:28:37Z. **Review:** COMMENTED --- Checked against main 87666fc5d6 and Microsoft STL b6f01e43 (`stl/inc/atomic`): - Main already has `_Atomic_signal_fence_nid_postfix` as an empty function (DinkumwareAtomics.cpp:146, from ec3fe412db), and I think that body is already correct. A signal fence is only a compiler barrier, and when the guest calls an out-of-line libc.prx export, the call itself is that barrier: the guest's compiler can't move escaping memory accesses across an opaque call. Inside the callee there are no loads or stores for `std::atomic_signal_fence` to order, so I'd expect the new body to compile to the same bare `ret` as main. I didn't compile it to confirm, but your objdump finding no fence instruction is consistent with that. - The new test loop calls each order but checks nothing, so it would pass against main as well. - `docs/dev/debt/libc.md` already covers this file in the "Dinkumware atomics" entry under Unknown function info (line 33). The new Functional bullet duplicates it and says the function "orders compiler operations", which the callee can't do by itself. If a note is wanted, one sentence in the existing entry saying `_Atomic_signal_fence` is a no-op because the call is the compiler barrier seems more accurate than a separate item. - Unless I'm missing an observable difference, this could probably be closed as already covered by main. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
gabichuuuuu commented 2026-11-10 11:12:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-10T11:12:04Z.

Review: COMMENTED


Read 66685d4028 against main.

Correctness. _Atomic_signal_fence_nid_postfix in core/libs/prx/libc/src/DinkumwareAtomics.cpp now calls std::atomic_signal_fence(static_cast<std::memory_order>(order)) when IsValidOrder(order) holds (0 to 5, which match the std::memory_order enumerators). A signal fence is only a compiler barrier, and inside an out-of-line function with no surrounding memory accesses it compiles to nothing, so the export behaves exactly as main's empty body for every input, valid or not. The PR body says this plainly; the change is correct and harmless.

Test. The loop over orders 0 to 5 in CheckFlagsAndFences (core/libs/tests/GuestDinkumwareAtomics.cpp) passes on main too, as the body states; there is no observable behaviour for a test to pin, so this is a smoke call, not a regression test.

Debt. The new libc.md entry records no gap: it describes an implementation detail of a no-op whose result is the same as before. Since docs/dev/debt is for known gaps, consider dropping it, or reduce it to the one open point (PS5 behaviour not verified) if that is worth tracking at all.

Non-blocking. #include <atomic> is appended after <cstring>, out of the alphabetical order of the other standard headers in that block.

Not run here; this is from reading the code.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5840901793 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10569#pullrequestreview-5840901793). Originally posted by [gabichuuuuu](https://github.com/gabichuuuuu) on 2026-11-10T11:12:04Z. **Review:** COMMENTED --- Read `66685d4028` against `main`. **Correctness.** `_Atomic_signal_fence_nid_postfix` in `core/libs/prx/libc/src/DinkumwareAtomics.cpp` now calls `std::atomic_signal_fence(static_cast<std::memory_order>(order))` when `IsValidOrder(order)` holds (0 to 5, which match the `std::memory_order` enumerators). A signal fence is only a compiler barrier, and inside an out-of-line function with no surrounding memory accesses it compiles to nothing, so the export behaves exactly as `main`'s empty body for every input, valid or not. The PR body says this plainly; the change is correct and harmless. **Test.** The loop over orders 0 to 5 in `CheckFlagsAndFences` (`core/libs/tests/GuestDinkumwareAtomics.cpp`) passes on `main` too, as the body states; there is no observable behaviour for a test to pin, so this is a smoke call, not a regression test. **Debt.** The new `libc.md` entry records no gap: it describes an implementation detail of a no-op whose result is the same as before. Since `docs/dev/debt` is for known gaps, consider dropping it, or reduce it to the one open point (PS5 behaviour not verified) if that is worth tracking at all. **Non-blocking.** `#include <atomic>` is appended after `<cstring>`, out of the alphabetical order of the other standard headers in that block. Not run here; this is from reading the code. AI-assisted: yes.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!10569
No description provided.