Skip to content

ATOMS.INC / ATOMS.DEC are a compare-and-swap loop; ATOMS.CAS gives the old value - #1413

Closed
Copak731 wants to merge 1 commit into
seedds:mainfrom
Copak731:shared-atomics
Closed

Copak731 wants to merge 1 commit into
seedds:mainfrom
Copak731:shared-atomics

Conversation

@Copak731

@Copak731 Copak731 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

What and why

  • ATOMS.INC / ATOMS.DEC (operations 3 and 4, CUDA's atomicInc / atomicDec): AAtoms hands them to EmitAtomicOp, which has no case for them; it logs "Invalid atomic operation" and gives the constant 0, with no access to shared memory. They are now a compare-and-swap loop (INC: old >= b ? 0 : old + 1; DEC: old == 0 || old > b ? b : old - 1), Rd the old value.
  • ATOMS.CAS's result. AAtomsCas gave every compare-and-swap CAST.SPIN's 1 / 0. nvdisasm names the forms by bit 87: clear is CAS (CUDA's atomicCAS, PTX atom.cas: Rd the old value); set is CAST, and CAST.SPIN with bit 88 too. CAST and CAST.SPIN keep 1 / 0, so Fire Emblem Fortune's Weave's retry loop is unchanged.

Reference entry: docs/reference/shaders.md, "ATOMS.INC / ATOMS.DEC, and ATOMS.CAS's result".

Checked

  • Tests: DMSH_TEST_XLATE=<translator> python3 dm/gfx/tests/test_dmsh_ampere_alu.py, new SharedAtomics (3, all fail on main). All test_dmsh_*.py pass.
  • GPU cross-check: 400 LDS / STS / ATOMS / ATOMS.CAS from the corpus, each as a one-thread compute shader (inputs and outputs through an NVN2 storage buffer, LDC.64 c[0][0x10] then LDG.E / STG.E; only the 16-byte block the access touches is set and compared), production options, MSL 2.3: 84 mismatches on main, all INC, DEC and CAS, to none; the same on encodings from real compiled code (CUDA sm_80 / sm_75 binaries). Everything else (LDS of every size, STS, ADD / MIN / MAX / AND / OR / XOR / EXCH) already matched.
  • Devices and OS: MacBook, Apple M5, macOS 26.6.2, Xcode 27.2.
  • Games run: none (no game files were used).

Docs

  • The finding is in its docs/reference/shaders.md entry, and python3 dm/tools/docs_symptoms.py was run (the symptom index)
  • No game files, keys or data extracted from a game in the change or the attachments

🤖 Generated with Claude Code

…e old value

AAtoms handed operations 3 and 4 to EmitAtomicOp, which has no case for them
(the constant 0, no access). AAtomsCas gave every compare-and-swap CAST.SPIN's
1 / 0; nvdisasm names three forms by bit 87, and a plain CAS (bit 87 clear)
gives the old value. CAST and CAST.SPIN keep 1 / 0.

New SharedAtomics tests in test_dmsh_ampere_alu.py (three fail on main). A
GPU cross-check of 400 shared accesses as one-thread compute shaders with the
production options: 84 mismatches (INC, DEC, CAS) to none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests) docs Documentation labels Nov 5, 2026
fpedrolucas95 pushed a commit to fpedrolucas95/nxnative that referenced this pull request Nov 6, 2026
…are-and-swap loop; ATOMS.CAS gives the old value
fpedrolucas95 pushed a commit to fpedrolucas95/nxnative that referenced this pull request Nov 6, 2026
…, seedds#1410, seedds#1411, seedds#1412, seedds#1413, seedds#1414, seedds#1329 on top of main's translator fixes): chain c9cf9613657e

Publishes Ryujinx.Graphics.Shader, Ryujinx.Common, Spv.Generator and dmsh_xlate (osx-arm64, framework-dependent, the universal launcher kept) from the merged source; the
PRs' own binaries were built without this tree's translator changes (float atomic adds, F2IP, the growing raw pool table). The lock and dmsh_chain.h are written again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
seedds added a commit that referenced this pull request Nov 7, 2026
…s the old value: shared-memory counters move as on Ampere (chain 1ddb83a9817a, PR #1413)

AAtoms handed operations 3 and 4 (CUDA's atomicInc / atomicDec) to EmitAtomicOp, which has no case for them: it logged "Invalid atomic operation" and gave the constant 0, with no access to shared memory. They are now the compare-and-swap loop ATOMG's INC / DEC already are on main (INC: old >= b ? 0 : old + 1; DEC: old == 0 || old > b ? b : old - 1), Rd the old value. AAtomsCas gave every compare-and-swap CAST.SPIN's 1 / 0; nvdisasm names the forms by bit 87: clear is CAS (atomicCAS, Rd the old value), set is CAST, with bit 88 CAST.SPIN, which keep 1 / 0, so Fire Emblem Fortune's Weave's retry loop is unchanged.

Checked: test_dmsh_ampere_alu SharedAtomics (3 tests, all fail on the translator before) and the 21 translator test files (test_dmsh_pairs' two NameErrors as before), test_nsp_chain, test_xlate_anycpu, test_docs. The author's GPU cross-check: 400 LDS / STS / ATOMS / ATOMS.CAS from the corpus as one-thread compute shaders, 84 mismatches on main (all INC, DEC and CAS) to none, the same on encodings from CUDA sm_80 / sm_75 binaries. No game is known to depend on it. Regression: one Ocarina of Time run on the chain that ends this batch.

Co-authored-by: Copak731 <224629733+Copak731@users.noreply.github.com>
@seedds

seedds commented Nov 7, 2026

Copy link
Copy Markdown
Owner

Landed as 1a410e6 with you as co-author (SharedAtomics fails before, passes after; main already had ATOMG's INC / DEC). Thank you.

@seedds seedds closed this Nov 7, 2026
Aznracer pushed a commit to Aznracer/Mighty-Green-Kokiri-Kid that referenced this pull request Nov 8, 2026
…s the old value: shared-memory counters move as on Ampere (chain 1ddb83a9817a, PR seedds#1413)
Know-It-All-Brother pushed a commit to Know-It-All-Brother/nxnative that referenced this pull request Nov 9, 2026
…s the old value: shared-memory counters move as on Ampere (chain 1ddb83a9817a, PR seedds#1413)

AAtoms handed operations 3 and 4 (CUDA's atomicInc / atomicDec) to EmitAtomicOp, which has no case for them: it logged "Invalid atomic operation" and gave the constant 0, with no access to shared memory. They are now the compare-and-swap loop ATOMG's INC / DEC already are on main (INC: old >= b ? 0 : old + 1; DEC: old == 0 || old > b ? b : old - 1), Rd the old value. AAtomsCas gave every compare-and-swap CAST.SPIN's 1 / 0; nvdisasm names the forms by bit 87: clear is CAS (atomicCAS, Rd the old value), set is CAST, with bit 88 CAST.SPIN, which keep 1 / 0, so Fire Emblem Fortune's Weave's retry loop is unchanged.

Checked: test_dmsh_ampere_alu SharedAtomics (3 tests, all fail on the translator before) and the 21 translator test files (test_dmsh_pairs' two NameErrors as before), test_nsp_chain, test_xlate_anycpu, test_docs. The author's GPU cross-check: 400 LDS / STS / ATOMS / ATOMS.CAS from the corpus as one-thread compute shaders, 84 mismatches on main (all INC, DEC and CAS) to none, the same on encodings from CUDA sm_80 / sm_75 binaries. No game is known to depend on it. Regression: one Ocarina of Time run on the chain that ends this batch.

Co-authored-by: Copak731 <224629733+Copak731@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants