Skip to content

rdna2_decode: decode the gfx101x SMEM stores, scratch ops, atomics and s_atc_probe* - #7421

Open
hmodymac8-droid wants to merge 2 commits into
ItsNotRexed:mainfrom
hmodymac8-droid:fix/rdna2-decode-smem-gfx101
Open

hmodymac8-droid wants to merge 2 commits into
ItsNotRexed:mainfrom
hmodymac8-droid:fix/rdna2-decode-smem-gfx101

Conversation

@hmodymac8-droid

Copy link
Copy Markdown

What changed and why

rdna2_isa_tables.SMEM is the RDNA2 (gfx103x) XML set, but rdna2_decode's default target is gfx1013.
On gfx1013, llvm-mc 23.1.6 also decodes these, and rdna2_decode reported every one of them as invalid words:

  • s_store_dword*, s_scratch_load_dword*, s_scratch_store_dword*, s_buffer_store_dword*
  • s_atomic_* and s_buffer_atomic_*, including _x2 and cmpswap at the doubled width
  • s_dcache_discard*

They go in a new SMEM_GFX101 table that the decoder uses only when mcpu is gfx101x, so a gfx1030 listing still refuses them, as llvm-mc does.
s_atc_probe and s_atc_probe_buffer (0x26, 0x27) exist on both targets. Their SDATA field is the probe-mode immediate (s_atc_probe 4, s[2:3], 16).

Found by decoding every opcode of every encoding with both rdna2_decode and llvm-mc and comparing.

Claim: #7231 (new item).

Test

  • Four random words per SMEM opcode, on gfx1013 and gfx1030, against llvm-mc: every word llvm-mc decodes now decodes to the same instruction and operands.
  • Two differences remain; both already exist on main and are out of scope here:
    • immediate offsets print in decimal where llvm-mc prints hex, as s_load_dword already does;
    • a negative SMEM buffer offset prints unsigned, as s_buffer_load already does.
  • python -I -m unittest tests.test_rdna2_decode: OK. The new test_gfx101_smem_stores_atomics_and_probes fails on main.
  • tests/test_shader_ir.py, tests/test_shader_disasm.py: OK.

GPU and driver

No GPU needed.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

…d s_atc_probe*

rdna2_isa_tables.SMEM is the RDNA2 (gfx103x) XML set, but rdna2_decode's
default target is gfx1013, where llvm-mc 23.1.6 also decodes s_store_dword*,
s_scratch_load/store_dword*, s_buffer_store_dword*, s_atomic_* and
s_buffer_atomic_* (and _x2, cmpswap with the doubled width) and
s_dcache_discard*. rdna2_decode reported each of them as invalid words.
They go in a new SMEM_GFX101 table that the decoder consults only when mcpu
is gfx101x, so a gfx1030 listing still refuses them as llvm-mc does.
s_atc_probe and s_atc_probe_buffer (0x26, 0x27) exist on both targets; their
SDATA field is the probe-mode immediate (`s_atc_probe 4, s[2:3], 16`).

Checked four random words per SMEM opcode on gfx1013 and gfx1030 against
llvm-mc: every word llvm-mc decodes now decodes to the same instruction and
operands. What still differs is pre-existing and out of scope: immediate
offsets print in decimal where llvm-mc prints hex (as s_load_dword already
does on main), and a negative SMEM buffer offset prints unsigned (as
s_buffer_load does on main).

tests/test_rdna2_decode.py: test_gfx101_smem_stores_atomics_and_probes
(fails on main); the file: OK.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@SweatierKey

Copy link
Copy Markdown
Contributor

Independent CPU review at 5f65cf774 (Linux, Python 3.13.5, llvm-mc 18.1.3, no GPU or game files): pass.

  • Cross-checked all 68 new/updated SMEM opcodes (66 in SMEM_GFX101 + s_atc_probe / s_atc_probe_buffer in SMEM) against llvm-mc -triple=amdgcn -disassemble on both -mcpu=gfx1013 and -mcpu=gfx1030: 68/68 exact match on mnemonic, operand widths, PROBE immediate, and gfx1013-only vs gfx1030 acceptance (differing only in 16 vs 0x10 offset formatting in LLVM 18).
  • tests/test_rdna2_decode.py: 16/17 passed — the new test_gfx101_smem_stores_atomics_and_probes passes cleanly; the single failure (cs_w32_permlane_fi.asm op_sel:[0,1,0,0] vs op_sel:[0,1]) is pre-existing on main.
  • py_compile and git diff --check clean.

@AsgerCode

Copy link
Copy Markdown

Tested 5f65cf7 on Windows 11 (NTFS), Python 3.12.10 (CPU only, no GPU, no game files): fail, one more gfx101x-only SMEM opcode is still reported as invalid (s_dcache_wb, 0x21). Everything the PR adds matches LLVM.

What I ran:

  • python -I tests/test_rdna2_decode.py: 17 tests, OK (1 skipped: no llvm-mc on this machine).
  • Negative control (merge-base rdna2_decode.py + rdna2_isa_tables.py): test_gfx101_smem_stores_atomics_and_probes fails in all 8 subtests (('', 2) instead of the instruction).
  • Other users of the decoder: tests/test_shader_disasm.py 29 OK, tests/test_shader_ir.py 39 OK, tests/test_fssm_crosscheck.py 6 OK, tests/semantic/test_printed_encoding.py 7 OK, tests/semantic/test_image_sample_bias_nonps.py 7 OK (2 skipped).
  • Merge with current main (775287b, 27 commits ahead): clean, and main has not changed these 3 files.

Independent reference: llvm-mc is not installed here, and the local LLVM 22.1.1 (clang, llvm-objdump) has no AMDGPU target. So I used LLVM's own llvm-mc test vectors instead: llvm/test/MC/Disassembler/AMDGPU/gfx10_smem.txt (llvm-project main, 425 words with FileCheck-ed llvm-mc output, gfx1010), plus the opcodes in SMInstructions.td and the feature sets in GCNFeatures.td. I compared after converting hex numbers to decimal on both sides.

decoder target match invalid mismatch
merge base gfx1013 176 249 0
this PR gfx1013 (wave32 and wave64) 424 1 (s_dcache_wb) 0
this PR gfx1010 424 1 (s_dcache_wb) 0
this PR gfx1030 182 243 (all the gfx101x-only ops) 0

The 248 vectors for the new opcodes include glc (74), dlc (66), soffset + offset: (14), null (6), vcc and m0 operands. A script compared the tables with the gfx10 defm/def lines in SMInstructions.td: all 66 SMEM_GFX101 opcodes and 0x26/0x27 match, and s_dcache_wb (0x21) is the only gfx10 SMEM opcode that is in neither table. I also hand-assembled 11 words from the SMEM_Real_gfx10 bit layout (ttmp sdata and sbase, an m0 soffset, a negative non-buffer offset, glc + dlc on _x2 atomics, a nonzero sdata field on s_dcache_discard_x2, and bit 15 set). All of them gave the expected fields.

The bug: s_dcache_wb is SMEM_Real_gfx10<0x021, S_DCACHE_WB> with OtherPredicates = [HasScalarStores]. FeatureScalarStores is in FeatureISAVersion10_1_Common (so gfx1013 has it) and is not in FeatureISAVersion10_3_0. LLVM's vector 0x00,0x00,0x84,0xf4,0x00,0x00,0x00,0x00 decodes as s_dcache_wb on gfx1010. With this PR, disasm_bytes(bytes.fromhex("000084f400000000"), mcpu="gfx1013") still returns ('', 2). This is the same kind of gap the PR fixes, and the description says every opcode was compared. Fix: add 0x21: ('s_dcache_wb', ()), to SMEM_GFX101, and add one subtest.

Nits, none blocking:

  1. The probe mode prints in hex from 100: s_atc_probe 0x64, s[2:3], 16 and 0x7f for 127, because the imm formatter in _format_operand uses hex for values of 100 or more. In LLVM, $sdata of SM_Probe_Pseudo is an i8imm (OPERAND_UNKNOWN), and AMDGPUInstPrinter prints that with formatDec, so llvm-mc should print 127. I read this in the source but could not run llvm-mc. A {"k": "raw", "t": str(sdata)} operand would keep it decimal.

Overlap: open #6237 ("tests: add schema and decoder-contract invariant tests for rdna2_isa_tables") merges cleanly with this PR, but its tests/test_rdna2_isa_tables.py fails 3 tests on this PR's tables. They pass on main. The failures: 'PROBE' is not in VALID_OPERAND_NAMES, and SMEM_GFX101 is not in ENCODING_OPCODE_BITS. Whichever lands second must add both. This PR also has adjacent-insertion conflicts in tests/test_rdna2_decode.py with #7369, #7337, #7260 and #7300.

Not cross-checked: gfx1013 itself (the LLVM vectors are gfx1010; I relied on the shared FeatureISAVersion10_1_Common feature set), gfx1030 rejection against an LLVM vector, and probe values other than 0, 1 and 7 against LLVM output.

AI-assisted (Claude Code).

…nts as llvm-mc does

Review on ItsNotRexed#7421 (AsgerCode): s_dcache_wb (0x21, no operands) is gfx101x-only
like the rest and was still invalid; llvm-mc 23.1.6 decodes its vector
000084f400000000 on gfx1013 and refuses it on gfx1030. Added to
SMEM_GFX101.

The probe mode is printed as llvm-mc 23.1.6 prints it: decimal up to 64,
hex from 65 (all 128 values of s_atc_probe and s_atc_probe_buffer checked).
The table now uses the plain SDATA field for it and the decoder keys on the
name, so no new operand name enters rdna2_isa_tables (ItsNotRexed#6237 checks them).

The test moves next to test_mubuf_mtbuf_mimg_global_ds_exp_vintrp, apart
from the other open rdna2_decode PRs' tests, and gains the 64/0x41 probe
cases and s_dcache_wb.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hmodymac8-droid

Copy link
Copy Markdown
Author

Thanks @SweatierKey and @AsgerCode, both checks are very helpful. Pushed fc959a5:

tests/test_rdna2_decode.py, tests/test_shader_ir.py, tests/test_shader_disasm.py: OK. AI-assisted (Claude Code).

hmodymac8-droid added a commit to hmodymac8-droid/Leonida that referenced this pull request Nov 23, 2026
…codes

Review on ItsNotRexed#7337 (AsgerCode): the 31 *_src2_* entries sat in the shared DS
table, so gfx1030 decoded them too, where llvm-mc 23.1.6 refuses them (and
LLVM's gfx1030_err.s lists them as unsupported). They move to DS_GFX101,
which the decoder reads only when mcpu is gfx101x, as ItsNotRexed#7421 does for its
SMEM ops; the test checks gfx1030 and gfx1036 refuse ds_add_src2_u32.

The condxchg32 and read2 test words had a nonzero unused DATA1 field, which
llvm-mc refuses; they now use the words llvm-mc decodes to the expected
text, so every row of the test is llvm-mc's output.

Every DS word this PR changes against main, over all 256 opcodes, four
operand/offset patterns and gfx1013/gfx1030/gfx1036: either it now matches
llvm-mc, or llvm-mc refuses that word for a nonzero unused field, which
main ignores as well. The tables' docstring names DS_GFX101.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@YordiLorenzo

Copy link
Copy Markdown

Tested fc959a5 on Linux, Python 3.14.4, llvm-mc 21.1.8: pass

  • python -I tests/test_rdna2_decode.py: the new test passes. The one failure is the permlane16 op_sel parity, as on main
  • Every SMEM opcode, one aligned word each, against llvm-mc 21: on gfx1013 all 86 words it decodes give the same instruction (offsets compared as numbers), and nothing it refuses decodes. On gfx1030, 18 of 18, and the new gfx101x ops are refused there as they should be. s_atc_probe with mode 65 prints 0x41 as llvm-mc does

One leftover, same on main and not from this PR: s_get_waveid_in_workgroup (0x2a) still decodes on gfx1030, where llvm-mc refuses it.

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.

4 participants