Skip to content

rdna2_decode: v_permlane16_b32 prints the two op_sel bits llvm-mc prints - #8044

Open
bobcatchris wants to merge 1 commit into
ItsNotRexed:mainfrom
bobcatchris:rdna2-permlane-opsel
Open

bobcatchris wants to merge 1 commit into
ItsNotRexed:mainfrom
bobcatchris:rdna2-permlane-opsel

Conversation

@bobcatchris

Copy link
Copy Markdown
Contributor

tests/test_rdna2_decode.py::test_parity_with_llvm_mc_on_shader_fixtures is red on main at runtime/test/shaders/cs_w32_permlane_fi.asm. The decoder printed four op_sel bits where LLVM prints two:

AssertionError: Lists differ: ['op_sel:[0,1,0,0]'] != ['op_sel:[0,1]']
 : cs_w32_permlane_fi.asm: v_permlane16_b32

Cause. tools/rdna2_decode.py printed every VOP3P op_sel as nsrc + 1 bits, the last one the destination selector. For v_permlane16_b32 / v_permlanex16_b32 the field holds only FI (bit 0) and BOUND_CTRL (bit 1): bits 2-3 are unused and there is no destination selector, which is exactly what llvm-mc prints — and what the fixture's own comment already says ("op_sel:[FI, BOUND_CTRL] (LLVM: llvm.amdgcn.permlane16 <bound_control> -> op_sel bits 0, 1)"). The decoder disagreed with the repo's documentation of its own fixture.

Fix. The exception is keyed on the two opcodes (0x377, 0x378); every other VOP3P form keeps the nsrc + 1 rule, so v_dot4_i32_i8's three-bit op_sel:[0,1,0] and the op_sel_hi handling are untouched. The comment above the code now states the exception and why.

Checks. python -I tests/test_rdna2_decode.py: the permlane fixture passes, and rdna2_decode's own VOP3P cases (test_vop3p_dot4_i8_with_opsel_that_llvm_mc_rejects, the op_sel/op_sel_hi source-modifier case) still pass. The suite still reports one failure — ps_sdwa_f16_const.asm, where llvm-mc encodes an f16 1.0 source in SDWA as a trailing literal word and the decoder reads the source field as an inline constant (f9a00a7ef2148500 vs f9a00a7eff148500003c0000). That one is pre-existing on main, is not touched here, and is the subject of #5013. I did not run anything on a GPU.

AI-assisted.

`tools/rdna2_decode.py` printed every VOP3P `op_sel` as `nsrc + 1` bits, appending the destination
selector. `v_permlane16_b32` and `v_permlanex16_b32` encode only FI (bit 0) and BOUND_CTRL (bit 1) there —
bits 2-3 are unused and there is no destination selector — and llvm-mc prints exactly those two bits.

The decoder therefore said `op_sel:[0,1,0,0]` where the checked-in LLVM disassembly (and the fixture comment in
`runtime/test/shaders/cs_w32_permlane_fi.asm`, which already spells out "op_sel:[FI, BOUND_CTRL]") says
`op_sel:[0,1]`, so `tests/test_rdna2_decode.py::test_parity_with_llvm_mc_on_shader_fixtures` failed on `main` at
that fixture.

The exception is keyed on the two opcodes (0x377, 0x378) and leaves every other VOP3P form on the `nsrc + 1` rule.

Parity test after the change: the permlane fixture passes. The one remaining failure is
`ps_sdwa_f16_const.asm`, where llvm-mc encodes an f16 `1.0` source in SDWA as a literal word and the decoder reads
the source field as an inline constant; that is untouched here and is the subject of ItsNotRexed#5013.

AI-assisted.
@SweatierKey

Copy link
Copy Markdown
Contributor

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

  • Cross-checked both v_permlane16_b32 (0x377) and v_permlanex16_b32 (0x378) across op_sel values 1, 2, 3 against llvm-mc -triple=amdgcn -mcpu=gfx1030 -disassemble: 6/6 exact match (op_sel:[1,0], [0,1], [1,1]).
  • tests/test_rdna2_decode.py: cs_w32_permlane_fi.asm now passes parity (the remaining single failure in test_parity_with_llvm_mc_on_shader_fixtures is the separate pre-existing ps_w64_a_discard.asm: exp null target vs special mismatch).
  • py_compile and git diff --check clean.

@rojasruiz

Copy link
Copy Markdown

Checked ecc3759 merged onto main dde82f2 on Linux 7.2.15, CPython 3.14, with llvm-mc 23.1.3 (Arch llvm). The v_permlane16_b32 op_sel difference is gone, but tests/test_rdna2_decode.py is still red with this llvm-mc. test_parity_with_llvm_mc_on_shader_fixtures now stops at the next difference:

AssertionError: Lists differ: [('target', 'null', False, False), ... != [('special', 'null', False, False), ...

That's exp's null target: LLVM 23 prints it as the null register (special), the decoder as a target. #6036 (same op_sel change) gives exactly the same result here. #4867 normalises that spelling (and the LLVM 21 SDWA re-encoding). Merged onto the same main, it is the one of the three that turns the file green with llvm-mc 23.1.3 (OK).

So with LLVM 23, this PR is needed but not sufficient on its own. And since #6036 is the same fix, one of the two can probably be closed.

AI-assisted (Claude Code).

@SquishyGithub

Copy link
Copy Markdown

Checked ecc375979 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:

So with LLVM 23.1.5 the parity test needs this PR (or #6036) and the exp null change to pass.

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