Skip to content

rdna2_decode: name the legacy MAC/MAD ops for the shader target - #4928

Open
bobcatchris wants to merge 1 commit into
ItsNotRexed:mainfrom
bobcatchris:fix/decoder-vop3-140-target
Open

bobcatchris wants to merge 1 commit into
ItsNotRexed:mainfrom
bobcatchris:fix/decoder-vop3-140-target

Conversation

@bobcatchris

@bobcatchris bobcatchris commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

GFX10.1 (the console is gfx1013) spells the legacy multiply-add ops without the fused "fma/fmac" prefix. llvm-mc prints both names from the same bytes — v_mac_legacy_f32 for gfx1013, v_fmac_legacy_f32 for gfx1030 — and the ISA tables carry the GFX10.3 spellings, so the decoder named GFX10.1 code as GFX10.3.

decode_bytes() / disasm_bytes() / _decode_one() take mcpu (default gfx1013, the console) and pick the name per target:

bytes gfx1013 gfx1030
01 05 00 0c (VOP2 0x06) v_mac_legacy_f32_e32 v0, v1, v2 v_fmac_legacy_f32_e32 v0, v1, v2
00 80 06 d5 01 05 02 00 (VOP3 0x106) v_mac_legacy_f32_e64 v0, v1, v2 clamp v_fmac_legacy_f32_e64 v0, v1, v2 clamp
00 00 40 d5 01 05 0e 04 (VOP3 0x140) v_mad_legacy_f32 v0, v1, v2, v3 v_fma_legacy_f32 v0, v1, v2, v3

VOP3 0x140 reached main separately as dfcbd362b; this keeps it through the same table instead of a special case and adds the two VOP2 0x06 / VOP3 0x106 byte patterns, which main still names v_fmac_*.

The tables cover GFX10.1 and GFX10.3 only, so decode_bytes() refuses anything else with ValueError and shader_disasm --mcpu exits 2, rather than naming code the tables were not built from. An explicit list (RDNA2_TARGETS: gfx1010-gfx1013, gfx1030-gfx1036), not a gfx101/gfx103 prefix — llvm-mc takes an unknown name such as gfx1037 without complaint, so a prefix would let near-misses through. target_name() applies the same gate, so a direct call with gfx1014 keeps the GFX10.3 spelling too.

shader_disasm passes its --mcpu to the Python backend, and --skip-existing reuses a listing only for the target it was written for: --mcpu gfx1030 no longer keeps a listing disassembled as gfx1013, where 0x140 has a different name.

Verification (Windows 11, CPython 3.12, CPU only, no GPU, no game files):

  • python -I tests/test_rdna2_decode.py → 17 tests, one failure: test_parity_with_llvm_mc_on_shader_fixtures, which fails identically on main in this checkout (cs_w32_permlane_fi.asm op_sel, LLVM 15). Not introduced here.
  • python -I tests/test_shader_disasm.py → 31 OK; test_rdna2spirv_decode.py 26 OK; test_rdna2spirv_merge.py 30 OK.
  • Red-on-main control at 1cc6e3c1, same three byte patterns: gfx1013 prints v_fmac_legacy_f32_e32, v_fmac_legacy_f32_e64 … clamp, and --mcpu gfx1100 decodes without complaint ({'clean': 1} from the CLI). On this head they print v_mac_legacy_f32_e32, v_mac_legacy_f32_e64 … clamp, and gfx1100 / gfx101 / gfx1037 / gfx1030x return exit 2.

Rebased onto 1cc6e3c1 with main's newer fma_mix neg/abs and image-atomic changes kept, and squashed from four commits into one; the earlier head was 200a4c3f.

AI-assisted.

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 17dc102 on Windows 11 with CPython 3.14.7, CPU only. The Python CLI emits the target-specific instruction name.

I put 000040d501050e04000081bf at offset 0x128 in a synthetic FSSM fixture. I ran py -3.14 -I tools/shader_disasm.py probe.fssm --backend python --mcpu gfx1013 --jobs 1 --out gfx1013, then repeated with gfx1030 and a separate output folder. Both runs report one clean shader. The first listing has v_mad_legacy_f32. The second has v_fma_legacy_f32. The operand registers and encoded bytes match.

py -3.14 -I tests/test_rdna2_decode.py reports 9 passes and one skip (llvm-mc parity). All 20 tests in py -3.14 -I tests/test_shader_disasm.py pass. On merge base d974c88, the new decoder test fails because the function rejects the mcpu argument.

The existing listing allocation cost is tracked separately in #4932.

AI-assisted.

@bobcatchris
bobcatchris force-pushed the fix/decoder-vop3-140-target branch from 17dc102 to 36a94fa Compare November 23, 2026 06:33
@bobcatchris bobcatchris changed the title rdna2_decode: name VOP3 0x140 for the shader target (BUILD-806) rdna2_decode: name VOP2 0x06 / VOP3 0x106 / 0x140 legacy MAC/MAD ops for the shader target (BUILD-806) Nov 23, 2026

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

Independent Windows CPU follow-up on the updated head, AI-assisted, with uv CPython 3.12.13 and WSL LLVM 21.1.8. For VOP2 0x06 and VOP3 0x106, the Python backend matched LLVM's target-specific names, operands, suffixes and the VOP3 clamp. Default gfx1013 matched explicit gfx1013.

Both unclamped gfx1013 MAC forms and 0x140 lowered to separate multiply and add with NoContraction and returned zero on the rounding canary. The VOP3 clamp returned 1.0 for 2×3+4 and 0.75 for 0.5×0.5+0.5, confirming that the old destination serves as the addend. With gfx1030 both backends decode the fused names, and the translator still reports the known unsupported fused lowering (see #3188). The ordinary f32 add control matched on both targets. Synthetic inputs only.

@rhtnxe

rhtnxe commented Nov 23, 2026

Copy link
Copy Markdown

Tested 36a94faa merged into main 3faac557 (clean merge) on macOS 27.2.1 arm64 (Apple M4), CPython 3.15.2, with llvm-mc 23.1.6 (Homebrew LLVM): pass. An independent check of the LLVM 15 table in the description on a current LLVM.

  • python -I tests/test_rdna2_decode.py: 10 tests OK (1 skipped), including test_legacy_mac_mad_mnemonics_follow_the_target; main: 9 OK (1 skipped). python -I tests/test_shader_disasm.py: 20 OK on both.
  • The three encodings through llvm-mc -triple=amdgcn--amdpal -mattr=+wavefrontsize32 -disassemble and through this PR's disasm_bytes(..., mcpu=...), for gfx1010, gfx1013, gfx1030 and gfx1036: all 12 lines match, operands included.
bytes gfx1010 / gfx1013 gfx1030 / gfx1036
01 05 00 0c v_mac_legacy_f32_e32 v0, v1, v2 v_fmac_legacy_f32_e32 v0, v1, v2
00 80 06 d5 01 05 02 00 v_mac_legacy_f32_e64 v0, v1, v2 clamp v_fmac_legacy_f32_e64 v0, v1, v2 clamp
00 00 40 d5 01 05 0e 04 v_mad_legacy_f32 v0, v1, v2, v3 v_fma_legacy_f32 v0, v1, v2, v3
  • With no mcpu, disasm_bytes gives v_mad_legacy_f32 v0, v1, v2, v3 (the gfx1013 default).

Synthetic encodings only, no game data. AI-assisted (Claude Code).

@gertify

gertify commented Nov 23, 2026 •

Copy link
Copy Markdown

Tested 36a94fa on Ubuntu 24.04 (Python decoder tests, no GPU used) with LLVM_MC=llvm-mc-21, so the llvm-mc parity test ran instead of skipping.

  • test_legacy_mac_mad_mnemonics_follow_the_target (new): ok.
  • With mcpu=gfx1030 the three encodings decode as: 0105000c -> v_fmac_legacy_f32_e32 v0, v1, v2; 008006d501050200 -> v_fmac_legacy_f32_e64 v0, v1, v2 clamp; 000040d501050e04 -> v_fma_legacy_f32 v0, v1, v2, v3.
  • test_parity_with_llvm_mc_on_shader_fixtures fails on runtime/test/shaders/ps_sdwa_f16_const.asm: 'f9a00a7ef2148500' != 'f9a00a7eff148500003c0000'. Same failure with the same bytes on main 3faac55 on the same machine (Ran 9 tests, FAILED (failures=1)), so it is not from this PR. Since llvm-mc-21 shows it too, the parity failure does not come only from an older LLVM.
  • Without LLVM_MC: Ran 10 tests, OK (skipped=1).

AI-assisted.

@memorypressure

Copy link
Copy Markdown

Verified merged with main 3faac55: the new target-sensitive mnemonic test passes and test_shader_disasm stays green. The single failure in tests/test_rdna2_decode.py is the known exp-null parity red that reproduces identically on plain main (re-confirmed at the same ps_w64_a_discard.asm case; fix pending in #4697, see #4421) — unrelated to this change. mcpu threading is backward compatible and shader_disasm's python backend now matches its llvm-mc backend per target. CI pending. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@kapitche

Copy link
Copy Markdown
Contributor

Tested 200a4c3 merged with main 3faac55 (clean merge) on Ubuntu (WSL2) / CPython 3.12.16 and Windows 11 / CPython 3.13.1 with llvm-mc 23.1.6: pass.

  • Linux (no llvm-mc, so the parity test skips): tests/test_rdna2_decode.py 11 run, 10 pass, 0 fail, 1 skipped; tests/test_shader_disasm.py 22 run, 22 pass.
  • Windows (LLVM_MC set, parity test runs): tests/test_rdna2_decode.py 11 run, 10 pass, 1 fail; tests/test_shader_disasm.py 22 run, 22 pass. The one failure is test_parity_with_llvm_mc_on_shader_fixtures, an exp-null operand mismatch (target vs special); I ran that test alone on plain main 3faac55 on the same machine and it fails identically, so it is the known red on main and not from this PR.

Negative control: with tools/rdna2_decode.py and tools/shader_disasm.py taken from main and the PR's tests kept, 4 new tests fail (2 in test_rdna2_decode.py, errors since mcpu is not accepted; 2 in test_shader_disasm.py); restored, they pass.

Read the diff: no verified issue.

@King1565

Copy link
Copy Markdown

Tested 200a4c3 on Linux, Python 3.13 (CPU only, no GPU, no game files): pass

Ran

  • tests/test_rdna2_decode.py 11 tests and tests/test_shader_disasm.py 22 tests on head: all pass except test_parity_with_llvm_mc_on_shader_fixtures, which fails the same way on main 3faac55 with my LLVM 18.1.3. With the PR's test files copied onto main: the 4 new tests fail (2 errors in test_rdna2_decode, 2 failures in test_shader_disasm, including the --skip-existing target check).
  • llvm-mc (LLVM 18.1.3) against disasm_bytes(..., mcpu=t) for VOP2 0x06, VOP3 0x106 (clamp) and VOP3 0x140 on every target in RDNA2_TARGETS: 33/33 mnemonics match. gfx101x gives v_mac_legacy_f32_e32 / v_mac_legacy_f32_e64 / v_mad_legacy_f32, and gfx103x gives the fused names.
  • decode_bytes(..., mcpu="gfx1100") raises the new ValueError. Merges cleanly with main. compileall and git diff --check are clean.

Read
No defect found. The new gfx1013 default is safe downstream: rdna2spirv.py:7993 already translates v_mac_legacy_f32 (with D as the addend) and v_mad_legacy_f32. This also covers what I flagged on #5285 (VOP2 0x06 / VOP3 0x106).

AI-assisted (Claude Code).


Generated by Claude Code

@Atomic258

Copy link
Copy Markdown
Contributor

Tested 200a4c3 on Windows Server 2022, CPython 3.13.12: pass

  • python -I tests/test_shader_disasm.py -> OK; python -I tests/test_rdna2_decode.py still OK

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

GFX10.1 (the console is gfx1013) spells the legacy multiply-add ops without the fused
"fma/fmac" prefix. `llvm-mc` prints both names from the same bytes, e.g. `v_mac_legacy_f32`
for gfx1013 and `v_fmac_legacy_f32` for gfx1030, and the ISA tables carry the GFX10.3
spellings, so decode_bytes() and disasm_bytes() take `mcpu` and pick the name:

* VOP2 0x06 and VOP3 0x106/0x140 follow the target; the listing for gfx1013 says
  `v_mac_legacy_f32_e32`, `v_mac_legacy_f32_e64` and `v_mad_legacy_f32`, gfx1030 says
  `v_fmac_legacy_f32_e32`, `v_fmac_legacy_f32_e64` and `v_fma_legacy_f32`.
  VOP3 0x140 already landed on main as dfcbd36; this keeps it through the same table
  instead of a special case, and adds the two VOP2/VOP3 0x106 byte patterns.
* The tables cover GFX10.1 and GFX10.3 only, so an explicit target list refuses anything
  else with ValueError instead of naming code the tables were not built from. An explicit
  list, not a `gfx101`/`gfx103` prefix: `llvm-mc` takes an unknown name like `gfx1037`
  without complaint, so a prefix would let near-misses through.
* `shader_disasm --mcpu` reaches the Python backend and exits 2 for an unsupported target,
  and `--skip-existing` reuses a listing only for the target it was written for: `--mcpu
  gfx1030` no longer keeps a listing disassembled as gfx1013.

Verified locally (Windows 11, CPython 3.12): tests/test_rdna2_decode.py 17 tests with one
failure, the pre-existing test_parity_with_llvm_mc_on_shader_fixtures mismatch that fails
identically on main in this checkout (cs_w32_permlane_fi.asm op_sel, LLVM 15); the other
tests/ suites are test_shader_disasm 31 OK, test_rdna2spirv_decode 26 OK,
test_rdna2spirv_merge 30 OK.

Red on main 1cc6e3c, same three byte patterns: gfx1013 prints `v_fmac_legacy_f32_e32`,
`v_fmac_legacy_f32_e64 ... clamp`, and `--mcpu gfx1100` decodes without complaint. On this
branch they print `v_mac_legacy_f32_e32`, `v_mac_legacy_f32_e64 ... clamp`, and gfx1100,
gfx101, gfx1037 and gfx1030x raise. CPU only; no GPU, no game files.
@bobcatchris
bobcatchris force-pushed the fix/decoder-vop3-140-target branch from 200a4c3 to 1d16b2a Compare November 23, 2026 15:00
@bobcatchris bobcatchris changed the title rdna2_decode: name VOP2 0x06 / VOP3 0x106 / 0x140 legacy MAC/MAD ops for the shader target (BUILD-806) rdna2_decode: name the legacy MAC/MAD ops for the shader target Nov 23, 2026
@bobcatchris

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (1cc6e3c1) and squashed to one commit, now head 1d16b2a8. If you measured the earlier head 200a4c3f, the diff is smaller: main keeps its newer fma_mix neg/abs handling, image-atomic dmask change and _iter_insns() split untouched.

Two things changed in scope, both because of what landed meanwhile:

  • VOP3 0x140 is already on main as dfcbd362b ("Decode VOP3 legacy MAD/FMA according to the shader target"), a gfx101 prefix special case in _decode_one(). This PR keeps that result through TARGET_DEPENDENT_NAMES / target_name() instead of a special case, so the three legacy ops share one table.
  • VOP2 0x06 and VOP3 0x106 were not covered by it. On main 1cc6e3c1 those bytes still decode as v_fmac_legacy_f32_e32 / v_fmac_legacy_f32_e64 … clamp for mcpu=gfx1013; this head gives v_mac_legacy_f32_e32 / v_mac_legacy_f32_e64 … clamp, with v_fmac_* still correct for gfx1030.

Still here from the earlier review: the explicit RDNA2_TARGETS list (gfx1010-gfx1013, gfx1030-gfx1036) refuses gfx1100, gfx101, gfx1037, gfx1030x and " gfx1013", and target_name() now applies the same gate so a direct call with gfx1014 keeps the GFX10.3 spelling; --skip-existing only reuses a listing for its own target.

One fix came out of the rebase itself: main's disasm_bytes() streams through _iter_insns() and so bypassed decode_bytes()'s guard — python -I tests/test_rdna2_decode.py caught it (ValueError not raised: gfx1100). Both entry points now call require_supported_target(), and the streaming test that asserts each instruction is formatted before the next is decoded still passes.

python -I tests/test_rdna2_decode.py → 17 tests, one failure, test_parity_with_llvm_mc_on_shader_fixtures, which fails identically on main in this checkout (cs_w32_permlane_fi.asm op_sel, LLVM 15). test_shader_disasm 31 OK; test_rdna2spirv_decode 26 OK; test_rdna2spirv_merge 30 OK.

Not tested: per-target parity against a newer LLVM. This machine's llvm-mc is ROCm 5.7 (LLVM 15), which also accepts any -mcpu name, so the byte patterns above come from llvm-mc on hand-picked encodings, not a corpus sweep.

AI-assisted.

@bobcatchris

Copy link
Copy Markdown
Contributor Author

Independent macOS code read and test run at head 1d16b2a (Apple M2, llvm-mc 21.1.8, Python 3.13.18). The decoder now names legacy MAC/MAD ops for the shader target, with synthetic disassembly and decoder tests covering the new cases. pytest -q tests/test_rdna2_decode.py: 16 passed, 467 subtests passed, 1 failed — the failure is the known test_parity_with_llvm_mc_on_shader_fixtures TEST-1010 case (SDWA inline constant materialised by llvm-mc 21), which fails identically on current main and is covered by #5013, so it is not caused by this PR. No new issue found; no game data.

AI-assisted.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 1d16b2a merged with main 8575d36 on Linux (WSL2), CPython 3.12.16: pass
Merge is clean. Ran with -I: tests/test_rdna2_decode.py (18 tests, 1 skipped: the llvm-mc parity test, llvm-mc is not installed on this box), tests/test_shader_disasm.py (31), test_shader_profile.py, test_wave64_graphics_scan.py, test_rdna2spirv_cli.py, test_first_light.py (4 skipped), semantic/test_printed_encoding.py: all OK.
Negative control: reverting tools/rdna2_decode.py and tools/shader_disasm.py to main makes test_rdna2_decode.py fail 2 tests and test_shader_disasm.py fail 2 tests, so the new tests discriminate.
Not checked here: llvm-mc output parity for the renamed v_mac_legacy_f32 / v_mad_legacy_f32. No other open PR found for the same change.

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