Skip to content

rdna2_decode: v_permlane16/x16_b32 op_sel is two bits, not four - #6036

Open
abilliontokens wants to merge 1 commit into
ItsNotRexed:mainfrom
abilliontokens:sf/rdna2-decode-permlane-opsel
Open

abilliontokens wants to merge 1 commit into
ItsNotRexed:mainfrom
abilliontokens:sf/rdna2-decode-permlane-opsel

Conversation

@abilliontokens

Copy link
Copy Markdown
Contributor

What

tools/rdna2_decode.py printed VOP3 v_permlane16_b32 / v_permlanex16_b32 op_sel with the generic VOP3 width — op_sel:[s0,s1,s2,dst] (4 bits) — while llvm-mc prints op_sel:[s0,s1] (2 bits). These two ops carry only FI and BOUND_CTRL in op_sel[1:0] (docs/design.md SHADER-74; rdna2spirv reads them via opsel_bits(mods, 2)), so the extra two bits were noise that broke decode parity.

Example on runtime/test/shaders/cs_w32_permlane_fi.asm:

decoder:  v_permlane16_b32 v11, v2, s4, s5 op_sel:[0,1,0,0]
llvm-mc:  v_permlane16_b32 v11, v2, s4, s5 op_sel:[0,1]

Fix

Emit 2 op_sel bits for opcodes 0x377/0x378 (v_permlane16_b32, v_permlanex16_b32); all other VOP3/VOPC ops keep the existing nsrc/nsrc+1 rule. New unit test test_vop3_permlane_opsel_is_two_bits covers both ops, both op_sel values, and the no-modifier case, using encodings assembled with llvm-mc -mcpu=gfx1013.

Verification (Windows 11, python 3.12, LLVM 23.1.0 at C:/Users/james/AppData/Local/Leonida/llvm-mc)

  • Fail before: new test on main 561b65a8 → 4 subtests FAIL (op_sel:[0,1,0,0] vs [0,1]).
  • Pass after: python -I tests/test_rdna2_decode.py → the permlane parity failure is gone; cs_w32_permlane_fi.asm now matches llvm-mc on every instruction.
  • The suite still reports one unrelated pre-existing failure, ps_sdwa_f16_const.asm (llvm-mc's assembler/disassembler disagree on an SDWA literal word) — that defect is already covered by open PR rdna2_decode parity: skip llvm-mc's SDWA inline-constant disassembly quirk #5013 and is untouched here.

AI-assisted (omp orchestrator). Item claimed in the coordination thread (#5934 comment 7101670067). No game data.

VOP3 v_permlane16_b32 and v_permlanex16_b32 carry only FI and BOUND_CTRL
in op_sel[1:0] (docs/design.md SHADER-74; rdna2spirv reads them via
opsel_bits(mods, 2)). The decoder printed the generic VOP3 shape
[s0,s1,s2,dst], e.g. op_sel:[0,1,0,0], while llvm-mc prints op_sel:[0,1].
Emit two bits for opcodes 0x377/0x378 so decode_bytes matches llvm-mc.

Verified: new unit test fails on main (4 subtests, op_sel:[0,1,0,0] vs
[0,1]) and passes with the fix; tests/test_rdna2_decode.py parity vs
llvm-mc 23.1.0 now passes cs_w32_permlane_fi.asm (the remaining
ps_sdwa_f16_const.asm failure is the known llvm-mc disasm quirk
covered by open PR ItsNotRexed#5013).
@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

One decoder parity case remains at 726f2283. When the two permlane flags are zero and only bit 2 or 3 of the generic VOP3 selector is set, LLVM prints no modifier. The PR prints op_sel:[0,0]. This is a text and IR difference. I did not observe a change in GPU behavior.

For example, run these commands from the checkout root with LLVM 21.1.8 and CPython 3.14.7:

'0x0a 0x20 0x77 0xd7 0x02 0x09 0x14 0x00' | llvm-mc -triple=amdgcn -mcpu=gfx1013 --disassemble
py -3.14 -I -c "import sys; sys.path.insert(0,'tools'); import rdna2_decode as d; print(d.decode_bytes(bytes.fromhex('0a2077d702091400'))['insns'][0]['mods'])"

LLVM prints v_permlane16_b32 v10, v2, s4, s5 without a diagnostic. The merge-base decoder at 561b65a8 gives ['op_sel:[0,0,1,0]']. The PR gives ['op_sel:[0,0]']. For parity, mask the selector to two bits for these two opcodes before testing whether to emit the modifier.

I checked both opcodes with selector values 0, 1, 2, 3, 4 and 8. The first four agree with LLVM. Values 4 and 8 give the difference above on both opcodes. With LLVM_MC set, py -3.14 -I tests/test_rdna2_decode.py passes 14 of 15 tests. The fixture test fails at ps_sdwa_f16_const.asm, as described in the PR.

AI-assisted.

@Kev-Ball

Copy link
Copy Markdown

Checked the retail reach of both the fix and the remaining synthetic parity case at 726f2283. Across 26,503 LLVM listings from Xbox 1.0.2.1, I found 9,021 decoded permlane instructions in 2,293 shaders, all v_permlanex16_b32. Of these, 362 had an explicit LLVM selector and 8,659 had none.

I decoded the recorded instruction bytes with the parent and PR decoder and compared each instruction to the corresponding LLVM listing, ignoring whitespace. The parent disagreed on 362 instructions, all in the selector. The PR agreed on all 9,021, including every instance where LLVM omitted the selector. Thus the still-open op_sel:[0,0] formatting case in the synthetic check above had no observed instance in these decoded retail instructions. The non-X variant remains covered by the synthetic tests.

CPU only, CachyOS, AI-assisted. Only counts are included.

@neoisg8

neoisg8 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Independent CPU verification on Windows 11 (Python 3.14.0a4, head 726f22831, base main 561b65a83b):

  • Clean diff & compile: git diff --check origin/main...HEAD and python -m compileall -q tools/rdna2_decode.py tests/test_rdna2_decode.py pass cleanly.
  • Suite passes: python -I tests/test_rdna2_decode.py -v passes 14/14 unit tests (1 llvm-mc integration test skipped as expected when llvm-mc is not installed on path).
  • Negative control reproduced on unpatched main:
    • Running test_vop3_permlane_opsel_is_two_bits on unpatched main failed on 4 subtests:
      AssertionError: Lists differ: ['op_sel:[0,1,0,0]'] != ['op_sel:[0,1]']
      AssertionError: Lists differ: ['op_sel:[1,0,0,0]'] != ['op_sel:[1,0]']
      
  • RDNA2 ISA & translator alignment: Restricting nbits = 2 for opcodes 0x377 (v_permlane16_b32) and 0x378 (v_permlanex16_b32) matches RDNA2 ISA encoding (FI bit 0, BOUND_CTRL bit 1) and aligns with rdna2spirv (opsel_bits(mods, 2)).

Clean fix and ready to land.

AI-assisted.

@VibeClauding

Copy link
Copy Markdown

Tested 726f2283 on Windows 11, Python 3.12, llvm-mc 23.1.6 (conda-forge) and 21.1.8: pass.

A full decoder-vs-llvm-mc scan of every runtime/test/shaders/*.asm (the parity test's loop, listing every mismatch instead of stopping at the first), llvm-mc 23.1.6:

On 21.1.8 the only remaining difference is ps_sdwa_f16_const (llvm-mc 21's SDWA inline-constant re-encoding, #5013). The ps_sdwa failure on your LLVM probably hid the exp null one, since the test stops at the first failing fixture.

@autowert66

Copy link
Copy Markdown

Tested 726f2283 on macOS 27.2.1, Apple M1 Max, Homebrew LLVM 23.1.6 (python -I tests/test_rdna2_decode.py): the change replicates cleanly on a second platform and toolchain.

  • test_vop3_permlane_opsel_is_two_bits: ok — both ops, both op_sel values and the no-modifier case, with encodings assembled by llvm-mc 23.1.6.
  • Fixture parity: on main 561b65a83 this toolchain fails exactly at the PR's target — cs_w32_permlane_fi.asm: v_permlane16_b32, decoder op_sel:[0,1,0,0] against llvm-mc's op_sel:[0,1]. At the head the permlane parity failure is gone and the fixture matches llvm-mc on every instruction, as in the PR's Windows run.
  • One difference vs the PR's own log, worth knowing rather than acting on here: the documented pre-existing ps_sdwa_f16_const failure does not reproduce on LLVM 23.1.6 — that gap looks 23.1.0-specific. Instead, once permlane parity is fixed, the test surfaces a different pre-existing gap that main also has but masks by failing earlier: ps_w64_a_discard.asm: exp, where llvm-mc 23.1.6 prints the first operand as special and the decoder prints target. Same failure on main here (it stops at permlane first), so it is a decode-parity item against newer llvm-mc, unrelated to this change.

AI-assisted (OpenCode / DeepSeek V4.1 Flash + GLM-5.3): the agent ran the suite sandboxed on the toolchain above.

@Mortify7612

Copy link
Copy Markdown

Tested 726f2283 merged onto main 56e607ac (clean) on Linux (Debian 12, Python 3.12, llvm-mc 23.1.6): the v_permlane16_b32 parity failure on cs_w32_permlane_fi.asm is gone (main: op_sel:[0,1,0,0] vs op_sel:[0,1]). The parity test now stops at the next case, ps_w64_a_discard.asm: exp null (a fixture main added in cc4231d3), which #4697 fixes. With both, test_parity_with_llvm_mc_on_shader_fixtures passes here. tests/test_rdna2_decode.py otherwise: 15 passed. AI-assisted (Claude Code).

@ne1i

ne1i commented Nov 23, 2026

Copy link
Copy Markdown

Tested 726f2283 on Linux, CPython 3.14, CPU only, synthetic inputs, merged onto main dde82f27, installed llvm-mc LLVM 23.1.5: improves tests/test_rdna2_decode.py but does not turn it green here

Independent check (not the author). Run by an AI agent (DeepSeek V4.1 Flash) and re-run by the orchestrating session (Claude Code) before posting; claimed in #8047.

@SquishyGithub

Copy link
Copy Markdown

Checked 726f22831 merged into main dde82f27e with llvm-mc 23.1.5 (Fedora 45, Linux, Python 3.15.2; CPU only): the permlane mismatch is fixed.

pytest tests/test_rdna2_decode.py:

#8044 fixes the same mismatch for v_permlane16_b32; this PR also covers v_permlanex16_b32.

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.

9 participants