Skip to content

Translator: ds_cmpst_b32 (compare-and-store without return) - #814

Merged
ItsNotRexed merged 4 commits into
ItsNotRexed:mainfrom
LouisRiverstone:lds-cmpst-b32
Nov 22, 2026
Merged

ItsNotRexed merged 4 commits into
ItsNotRexed:mainfrom
LouisRiverstone:lds-cmpst-b32

Conversation

@LouisRiverstone

Copy link
Copy Markdown
Contributor

Depends on: #812 (LDS atomics in spirv_mini_interp.py), which depends on #592. Until they land, this PR's diff also shows their commits. My change is the last commit.

tools/rdna2spirv.py translates ds_cmpst_rtn_b32 but raises Unsupported on the non-returning ds_cmpst_b32. It isn't in the translated corpus, so this is future-proofing. Claimed in #634.

Change

  • tools/rdna2spirv.py: ds_cmpst_b32 vaddr, data0, data1 is the same OpAtomicCompareExchange as the _rtn_ form, M = (M == data0) ? data1 : M (RDNA2 ISA, DS_CMPST_B32). The old value is dropped. Only the operand positions differ, because there's no vdst.
  • tests/semantic/test_lds_atomics_values.py: one more test runs ds_cmpst_b32 as one invocation on the CPU. It covers a match, a mismatch and the sign-bit value, and checks that vdst stays untouched.

Tested

  • python -I -m unittest discover -s tests/semantic: all pass. With only the translator change reverted, the new test has 3 errors (Unsupported: ds_cmpst_b32).
  • python -m compileall -q tools tests passes. Not run on a GPU, and no game files used.

AI-assisted (Claude Code): it wrote the change and the test, and ran the checks listed above.

spirv_mini_interp ran 32-bit atomics on physical-storage-buffer pointers
only, so the LDS atomics the translator emits (ds_add/sub/min/max/and/or/xor,
ds_wrxchg_rtn_b32, ds_cmpst_rtn_b32) had no value test. With one invocation an
atomic is read-combine-write on any pointer, so it now also takes the
variable-element pointers OpLoad/OpStore use (Workgroup = LDS since ItsNotRexed#592,
Function); push constants stay read-only.

tests/semantic/test_lds_atomics_values.py runs compute listings as one
invocation and checks the returned and stored words against a plain-Python
model of each RDNA2 DS atomic.
ds_cmpst_b32 raised Unsupported while ds_cmpst_rtn_b32 was translated. It is
the same OpAtomicCompareExchange (M = (M == data0) ? data1 : M) with the old
value dropped; operands are vaddr, data0, data1.

tests/semantic/test_lds_atomics_values.py checks a match, a mismatch and
vdst left untouched.

@quackottu quackottu 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.

Tested dd301d3 on NVIDIA GeForce RTX 5070 (subgroup 32), driver 621.24, Windows 11 Pro (26300), Vulkan SDK 1.4.363.0, llvm-mc 21.1.8 (built with scripts/build_llvm_mc.ps1), scripts/run_gpu_tests.py:

  • native: 71/98 passed, 27 skipped (main 8df277f here: 64/91 passed, 27 skipped, all wave64 tests needing a 64-wide subgroup)
  • LEONIDA_W64_EMULATE=1: 98/98 passed (main here: 91/91)
  • python -m unittest discover -s tests/semantic: Ran 981 tests in 187.752s OK

@ItsNotRexed
ItsNotRexed merged commit 9c12c5b into ItsNotRexed:main Nov 22, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants