tooling: decode GFX10 VOPC/VOPCX SDWA instructions in disasm_rdna2 #973
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/980"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by Batushn on 2026-11-23T19:39:42Z.
Summary
Refs #938 (step 3: VOPC SDWA decoding).
Previously,
tools/disasm_rdna2.pyrecognized the 8-byte length of VOPC instructions withsrc0 == 249(SDWA) but returned a placeholdervopc_sdwa/<unsupported SDWA>record instead of decoding the GFX10VOP_SDWA9Beextension word.This PR adds
_decode_vopc_sdwa()intools/disasm_rdna2.pyto decode GFX10 wave32VOPC(v_cmp_*_sdwa) andVOPCX(v_cmpx_*_sdwa) SDWA instructions in LLVM 15 syntax:sdst/sdst_en(Inst{47:40}):vcc_lowhensdst_en == 0, scalar register viadecode_s_reg(sdst)whensdst_en == 1, and omits destination forv_cmpx_*_sdwa(EmitDst = 0).src0(Inst{39:32}+src0_sgprInst{55}) andsrc1(Inst{16:9}+src1_sgprInst{63}) as VGPR or scalar/special register.-,|...|,-|...|) vs integer (sext(...)) modifiers matching LLVM 15'sVOPC_Profile/VOPC_Class_Profilerules (v_cmp_class_f32_sdwa/v_cmp_class_f16_sdwause float modifiers onsrc0andsextonsrc1).src0_sel(Inst{50:48}) andsrc1_sel(Inst{58:56}) overBYTE_0..BYTE_3,WORD_0..WORD_1,DWORD.vopc_sdwa/<unsupported SDWA>) for 64-bit VOPC opcodes, unknown opcodes, or invalidsel == 7, and preservesvopc_truncatedfor truncated 4-byte prefixes.Tests
TestRdna2Disasm.test_vopc_opcode_table_synthetic_formsfor the decodedv_cmpx_eq_f32_sdwa -v1, v2 src0_sel:DWORD src1_sel:DWORDfixture.TestRdna2Disasm.test_vopc_sdwa_decodingwith 34 independent GFX10 wave32 golden vectors from LLVM 15.0.7 (gfx10_asm_vopc_sdwa.sandgfx10_asm_vopcx.s),src1_sgpr=1, and negative/boundary controls (f64fallback, invalidsel == 7, 4-byte truncation).TestRdna2Disasm.test_vopc_sdwa_llvm_round_tripassembling and round-tripping 33 single-field VOPC/VOPCX SDWA variants through LLVM 15llvm-mc+llvm-objcopy+libLLVM(runs in theAssemble and translate gfx1013 fixturesCI job).TestRdna2Scanner.test_binary_scan_recognizes_vopc_sdwaverifying binary shader scans classify decodedv_cmp_lt_f32_sdwa(DWORD) as supported, decoded unlowered SDWA compares (v_cmp_gt_u32_sdwawithWORD_1andv_cmpx_eq_f32_sdwa) asopcode_recognized_translator_rejectedwithout<unsupported SDWA>, and unsupported 64-bit SDWA fallback as rejected.Local verification
python -B tests/rdna2_tools_check.py:Ran 83 tests ? OK (skipped=3)(LLVM_LIBnot installed locally; LLVM round-trip runs in CI).disasm_rdna2against all 1,712 wave32 vectors in LLVM 15.0.7gfx10_asm_vopc_sdwa.sand all 1,504 vectors ingfx10_asm_vopcx.s(3,216 / 3,216exact matches,0mismatches).python -B -m py_compile tools/disasm_rdna2.py tests/rdna2_tools_check.py: exit 0.Disclosure
Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-23T20:05:12Z.
Review from reading the diff against
main(not built or run here).Two cases in
_decode_vopc_sdwawith the SGPR bit set:decode_s_regto its finalreturn f"s{reg_id}", so for examplef904887dd2868606(v_cmp_gt_u32, src0 code 210) printss210, which is not a register._format_operand_modifiersand prints-0.5(for examplef904027cf0869606,v_cmp_lt_f32with src0 0.5 and neg). The file already notes, near the interpolation decoder, that LLVM spells a lone negation of a numeric operand asneg(...); if LLVM accepts this operand,-0.5would read as the constant -0.5 rather thanneg(0.5).I have not run LLVM 15 on these words, so the exact LLVM output is worth confirming. The round-trip list has only
s1andm0as SGPR-bit sources, which is where both cases sit.