feat(shader): decode and implement ds_condxchg32_rtn_b64 #1372
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1372"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by pandather on 2026-10-08T00:46:27Z.
What
Decodes and implements
ds_condxchg32_rtn_b64(DS opcode 0x7E) — the last DS instruction intools/rdna_isa.txtthat the decoder did not recognize and that no open pull request covers. Shader instructions: 1139/1166 -> 1140/1166.amdgpu_isa_rdna2.xml) — VDST is a B64 pair, ADDR a B32, DATA0 a B64 pair, plus implicit DSMEM — read from the fields every other DS instruction uses;gdsbit 17 is kept ininstruction.gds. Classified as a DS atomic likeds_wrxchg_rtn_b64.data & 0x7FFFFFFF— bit31 is a write-enable flag. Seven oracle cases cover every write-enable combination (both halves, low only, high only, neither), bit31-only and bit30-only immediates, and the mask edges (0xFFFFFFFF,0x80000000,0x00000001as data). A second conditional exchange fed back from LDS confirms the returned value is the state before each write.SharedAtomicCondxchg64IR opcode lowered through the same locked 64-bit LDS path asds_cmpswap_b64(SharedAtomic64, workgroup spinlock viaLockedLdsUpdatewhen analysis requires it), so the read-modify-write is atomic across the wave. The GDS variant throws "64-bit GDS atomics are not supported", consistent with every other 64-bit DS atomic.Sources:
amdgpu_isa_rdna2.xml, DS_CONDXCHG32_RTN_B64, opcode 126 = 0x7E) cross-checked byte-for-byte against LLVM's assembler for gfx1031. The words in the tests areclang --target=amdgcn-amd-amdhsa -mcpu=gfx1031encodings (ds_condxchg32_rtn_b64 v[16:17], v8, v[6:7]->D9F80000 10000608, gds variant ->D9FA0000 ...).tools/hw-oracle); not derived from documentation. The ISA guide describes the same conditional exchange; the measurements pin down the bit31 write-enable and the mask.Tested
Windows 11, NVIDIA Blackwell desktop GPU (driver 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7):
agc_ds_condxchg32_decode,agc_driver_ds_condxchg32_b64and the full suite report100% tests passed out of 406. Conventions check (tools/check_conventions.py) passes.agc_ds_condxchg32_decode: decodes three LLVM-encoded programs (plain,offset:255,gds) and checks opcode, length, operands, offset and gds flag.agc_driver_ds_condxchg32_b64: runs two chained conditional exchanges on the GPU through the recompiler and SPIR-V backend with 32 lanes whose data halves drive every write-enable combination, and checks all eight output dwords per lane against the measured semantics; also checks that the GDS variant is rejected.Not tested: no title or homebrew (LLVM emits this instruction only from explicit assembly, never from intrinsics). Concurrent contention on one LDS address from several lanes is not exercised; the workgroup lock makes the pair access atomic with respect to the other 64-bit LDS atomics, which are not ordered against concurrent 32-bit accesses (TechnicalDebt).
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T10:59:56Z.
Closing as a duplicate: #1198 implemented
ds_condxchg32_rtn_b64and is already onmain. Thanks for the hardware measurements. If they show something #1198 gets wrong, please open a fix againstmain.Pull request closed