Repository navigation
rdna2_decode: name VOP2 0x06 / VOP3 0x106 / 0x140 legacy MAC/MAD ops for the shader target (BUILD-806) - #4928
bobcatchris wants to merge 4 commits into
Conversation
|
Tested 17dc102 on Windows 11 with CPython 3.14.7, CPU only. The Python CLI emits the target-specific instruction name. I put
The existing listing allocation cost is tracked separately in #4932. AI-assisted. |
The decoder's tables carry the GFX10.3 names, but one encoding has two names depending on the target: GFX10.1 (the console, gfx1013) spells the legacy multiply-accumulate ops without the fused prefix. llvm-mc prints v_mac_legacy_f32 where the tables say v_fmac_legacy_f32 (VOP2 0x06, VOP3 0x106) and v_mad_legacy_f32 where they say v_fma_legacy_f32 (VOP3 0x140). Thread the target through decode_bytes() and disasm_bytes() (default gfx1013), name those three opcodes per target, and pass shader_disasm's --mcpu to its Python backend.
17dc102 to
36a94fa
Compare
whattheflop
left a comment
There was a problem hiding this comment.
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.
|
Tested
Synthetic encodings only, no game data. AI-assisted (Claude Code). |
|
Tested 36a94fa on Ubuntu 24.04 (linux-dev-01; Python decoder tests, no GPU used) with LLVM_MC=llvm-mc-21, so the llvm-mc parity test ran instead of skipping.
AI-assisted. |
The new target parameter accepted anything: `--backend python --mcpu gfx1100` (the Python tools need no llvm-mc, so nothing else rejected it) decoded RDNA2 tables and reported the shader "clean", with the GFX10.3 opcode names for a GFX11 target. decode_bytes() now raises for a target outside gfx101*/gfx103*, and the CLI stops with exit 2 before it reads a shader.
|
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). |
`gfx101`/`gfx103` prefixes let near-misses through, and llvm-mc accepts gfx1014 and gfx1037 as CPU names without complaint, so nothing else rejects them either: `--backend python --mcpu gfx1037` exited 0 on main and would still have been accepted with a prefix. The guard now lists the parts the tables describe (gfx1010-1013, gfx1030-1036) and names them in the error.
A listing is only reusable for the target it was written for, but the check was "non-empty file", so `--mcpu gfx1030 --skip-existing` kept a listing disassembled as gfx1013 and reported it as reused, even though opcode 0x140 has a different mnemonic there. Match the target recorded in the listing header.
|
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.
Negative control: with Read the diff: no verified issue. |
BUILD-806: the pure-Python decoder (#2038) names the legacy MAC/MAD ops with the GFX10.3 mnemonic whatever target the listing is for, and had no target parameter at all. For the console's gfx1013 code that is the wrong name: those opcodes are the ones GFX10.1 spells without the fused prefix.
Repro on
main(3faac557), one encoding eachllvm-mc(ROCm 5.7's, LLVM 15) on the same bytes, per target:-mcpu=gfx1013(the console)-mcpu=gfx103001 05 00 0c(VOP20x06)v_mac_legacy_f32_e32 v0, v1, v2v_fmac_legacy_f32_e32 v0, v1, v200 80 06 d5 01 05 02 00(VOP30x106, clamp)v_mac_legacy_f32 v0, v1, v2 clampv_fmac_legacy_f32 v0, v1, v2 clamp00 00 40 d5 01 05 0e 04(VOP30x140)v_mad_legacy_f32 v0, v1, v2, v3v_fma_legacy_f32 v0, v1, v2, v3This is the GFX10.1/10.3 opcode row in
docs/design.md: the tables intools/rdna2_isa_tables.pycarry only the GFX10.3 spelling, so console code was printed as fused MAC/MAD.Change
_decode_one,decode_bytes()anddisasm_bytes()take the target (mcpu, defaultgfx1013, since the console is the project's target).TARGET_DEPENDENT_NAMESmap plustarget_name()names the three affected opcodes for the target: VOP20x06and VOP30x106→v_mac_legacy_f32, VOP30x140→v_mad_legacy_f32ongfx101*. Applying it before the VOP2 path appends_e32/_dpp/_sdwaand the VOP3 path appends_e64keeps every form in step.shader_disasm.disasm()passes its existing--mcputo the Python backend instead of dropping it (thellvm-mcbackend already used it).After the change:
gfx1013/gfx1010→v_mac_legacy_f32_e32,v_mac_legacy_f32_e64 … clamp,v_mad_legacy_f32;gfx1030→v_fmac_legacy_f32_e32,v_fmac_legacy_f32_e64 … clamp,v_fma_legacy_f32; default (gfx1013) → the GFX10.1 names.The target is also validated
A target parameter that accepts values the tables do not describe is the same defect in another form: the Python backend needs no
llvm-mc, so nothing rejected a target at all. Onmain,shader_disasm.py <fssm> --backend python --mcpu gfx1100exits 0 and reports{'clean': 1}— RDNA2 tables, GFX11 target, GFX10.3 names — anddisasm(raw, "gfx1100", backend="python")returnsv_fma_legacy_f32.decode_bytes()now raises for any target outside an explicit list of the parts the tables describe —gfx1010-gfx1013(GFX10.1; the console isgfx1013) andgfx1030-gfx1036(GFX10.3) — and the CLI stops with exit 2 before it reads a shader. The list is explicit rather than agfx101/gfx103prefix because a prefix lets near-misses through:llvm-mcacceptsgfx1037andgfx1014as CPU names without complaint, andmainalso accepts both with the Python backend.--backend llvm-mcis unchanged, since therellvm-mcitself decides which targets exist.Tests
tests/test_rdna2_decode.pygainstest_legacy_mac_mad_mnemonics_follow_the_target: for all three encodings above it decodes as gfx1013, gfx1010 and gfx1030, asserting the expected mnemonic and that the other target's one is absent, then checks the default and thatshader_disasm.disasm(..., "gfx1030", backend="python")passes its target through.tests/test_shader_disasm.pygainstest_python_backend_rejects_a_target_its_tables_do_not_cover: the CLI with--backend pythonexits 2 forgfx1100,gfx9999,rdna2, the bare prefixesgfx101/gfx103and the near-missesgfx1014/gfx1037, each message naming the rejected value and the accepted list, and a validgfx1013run still writes its listing. The decoder test checks the same near-misses (plusgfx1030x,GFX1013," gfx1013") through the API, then asserts every listed target is accepted and gets the right GFX10.1/GFX10.3 mnemonic.--skip-existingkeeps a listing only for its own targetSame defect, third form: the reuse check was "non-empty file", so the target recorded in the listing was ignored. On
main, disassembling with--mcpu gfx1013and then running--mcpu gfx1030 --skip-existingreports{'reused': 1}and leaves thegfx1013header — while those two targets disagree on VOP30x140(v_mad_legacy_f32vsv_fma_legacy_f32), so the kept listing is wrong for the run it was reused by. The check now parses the target from the listing's own header (; name code …, <mcpu>, N invalid words) and reuses only a match; a listing without a header is rebuilt.test_skip_existing_only_reuses_listings_for_the_same_targetcovers it end to end:gfx1013listing →gfx1030 --skip-existingre-disassembles (clean: 1, header nowgfx1030) → the same command again reuses (reused: 1). The oldertest_skip_existing_only_reuses_published_nonempty_listingsnow writes the header a real listing has.python -I tests/test_rdna2_decode.py: 11 tests, 1 failure — the failure istest_parity_with_llvm_mc_on_shader_fixtures, which fails identically on unmodifiedmainin this checkout: ROCm 5.7'sllvm-mcis LLVM 15 and encodes one SDWA fixture differently (8 vs 12 bytes forps_sdwa_f16_const.asm), which the repo's CI builds with LLVM 21. The two new tests pass on their own (Ran 2 tests … OK).python -I tests/test_shader_disasm.py: 22 tests OK.test_rdna2spirv_decode.pyandtest_rdna2spirv_merge.py: OK (they consume the module's default target).Control on
main's decoder: itsdisasm_bytes()has no target parameter at all (TypeErrorwithmcpu=), and its default output for these bytes is the GFX10.3 name for all three — the value the test asserts against.Scope
tools/rdna2_decode.py,tools/shader_disasm.pyand the decoder's test file. Hand-built instruction words; the test needs no LLVM, no GPU and no game files.AI-assisted.