disasm_rdna2: decode 64-bit VOP3A and VOP3B instructions #570
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/576"
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 Holastor on 2026-11-22T13:25:31Z.
Description
This PR implements decoding of 64-bit RDNA 2 (GFX1013) vector ALU instructions (
VOP3AandVOP3B, prefix0xd4000000) intools/disasm_rdna2.pyand synchronizes native VOP3 opcodes intools/scan_unsupported_shaders.py.Background & Root Cause
In the RDNA 2 ISA, 64-bit vector instructions share prefix
(w0 & 0xfc000000) == 0xd4000000(bits[31:26] == 0b110101). Previously,disasm_rdna2.pylacked a decoder for this encoding, causing all 64-bit VOP3 instructions to fall through into.long(consuming only 4 bytes instead of 8 or 12).This desynchronized the instruction stream across thousands of shaders: the second dword (
w1) had bit 31 as 0, which was then falsely decoded as a 32-bit VOP2 instruction (producing ~1.8 million phantomv_vop2_00,v_vop2_02,v_vop2_20instances and ~3 million.long 0xd5...instances in scanning).Summary of Changes
tools/disasm_rdna2.py:VOP3_NATIVE_OPStable (117 native VOP3A and VOP3B opcodes from Table 83 and Table 85 of the RDNA 2 ISA manual).VOP3A / VOP3Bdecoder checking(w0 & 0xfc000000) == 0xd4000000:op = (w0 >> 16) & 0x3ff(10 bits).op < 0x100: VOPC comparisons in VOP3 (e.g.v_cmp_*_e64, destination scalar registerdecode_s_reg(vdst), 2 sources).0x100 <= op < 0x140: VOP2 instructions in VOP3 (e.g.v_add_f32_e64,v_cndmask_b32_e64with 3 sources, 2-source vector arithmetic).0x180 <= op < 0x200: VOP1 instructions in VOP3 (e.g.v_mov_b32_e64,v_cvt_*_e64, 1 source).0x270 <= op < 0x274: VINTRP parameter interpolation in VOP3 (v_interp_*_e64).op in VOP3_NATIVE_OPS: Native 3-source and 2-source VOP3A/VOP3B forms.v_add_co_u32,v_sub_co_u32,v_subrev_co_u32,v_add_co_ci_u32,v_sub_co_ci_u32,v_subrev_co_ci_u32,v_div_scale_f32,v_div_scale_f64,v_mad_u64_u32,v_mad_i64_i32).sdst = (w0 >> 8) & 0x7f(decode_s_reg(sdst)).src0 == 255,src1 == 255, orsrc2 == 255.vop3_truncatedif incomplete.abs(|src|),neg(-src), and combined (-|src|).clamp(w0[15]),omod(mul:2,mul:4,div:2), andop_sel(op_sel:[s0,s1,s2]).tools/scan_unsupported_shaders.py:KNOWN_RDNA2_BASE_OPCODESso thatis_opcode_recognized()andclassify_isa_category()identify them as validVOP / VALU (Vector ALU - VOP1/VOP2/VOP3).tests/rdna2_tools_check.py:test_golden_vectors:v_fma_f32 v0, v1, v2, v3(00004bd501050e04)v_mul_f32_e64 v12, v12, 1.0 clamp(0c8008d50ce50100)v_cmp_lt_f32_e64 s0, -s44, -v18(000001d42c240260)v_cndmask_b32_e64 v14, 0, 1.0, s0(0e0001d580e40100)v_add_co_u32 v1, s0, v2, v3(01000fd702070200)v_fma_f32 v5, v1, 0x3f800000, v2(05004bd501ff09040000803f)v_add_f32_e64 v3, |v1|, v2 mul:2(030103d501050208)v_cmp_lt_i16_e64 s52, s44, v18 op_sel:[1,0,0](340889d42c240200)test_vop3_opcode_table_synthetic_forms:test_vop3_distinguishes_non_default_modifiers:abs,neg,clamp,omod, andop_selall produce distinct, non-colliding disassembled strings for identical register operands.s_endpgmintest_literal_operands_keep_stream_aligned.bad_hexchecks.fixture_instructionsintest_llvm_comparison.Verification
Commit under test:
ee49597Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T14:35:11Z.
I checked
97a9eaeagainst LLVM's GFX10 byte cases.fe0064d501050202currently printsv_add_f64 v254, v1, v2; LLVM printsv_add_f64 v[254:255], v[1:2], v[2:3]. The destination and source widths also vary independently for conversions and mixed-width VOP3B forms. Please add opcode-specific operand widths and independent checks for those forms, or keep those forms explicitly undecoded while consuming the right instruction length. Include a followings_endpgmin the byte-stream check. The VOP3 work can proceed separately from MUBUF/MTBUF and FLAT. LLVM GFX10 disassembler casesImported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-22T15:00:58Z.
@R0Y00 Updated in 7daf2e4:
v_add_f64,v_mul_f64,v_fma_f64, etc.): vector register pairsv[N:N+1]and scalar register pairss[N:N+1].v_cvt_f64_i32,v_cvt_f64_u32,v_cvt_f64_f32) format 64-bit destinations and 32-bit sources; 64-to-32 bit (v_cvt_i32_f64,v_cvt_u32_f64,v_cvt_f32_f64,v_frexp_exp_i32_f64) format 32-bit destinations and 64-bit sources (both in_e32and_e64).v_lshlrev_b64,v_lshrrev_b64,v_ashrrev_i64) format 32-bit shift count and 64-bit input/output;v_ldexp_f64formats 64-bit float and 32-bit exponent.v_mad_u64_u32/v_mad_i64_i32format 64-bitvdst, scalarsdst, 32-bitsrc0/src1, and 64-bitsrc2;v_div_scale_f64formats 64-bitvdst, scalarsdst, and 64-bit sources.fe0064d501050202->v_add_f64 v[254:255], v[1:2], v[2:3]).test_vop3_operand_widths_and_stream_alignmentwith mixed-width instructions, 12-byte literal, and trailings_endpgm.KNOWN_RDNA2_BASE_OPCODESwith 64-bit conversion and math opcodes.main.Imported from R0Y00/Xbox2Windows. Originally posted by alexander-src on 2026-11-22T15:11:50Z.
Ran a 10-bit VOP3 differential sweep (
0x000..0x3ff) on7daf2e4against LLVM 23.1.4 (libLLVM.so,gfx1013) on Linux x64. All five local Python suites pass (rdna2_tools_check.py,pso_readiness_check.py,form_coverage_check.py,docs_links_check.py,bidi_controls_check.py), and 247 validgfx1013VOP3 opcodes match LLVM output exactly. The sweep flagged 23 decoded opcodes that still disagree with LLVM:VOP1-in-VOP3 slots with swapped mnemonics or widths:
0x180(000080d502091a04): LLVM printsv_nop, PR printsv_nop v0, v2.0x1ab(0000abd502091a04): LLVM printsv_rcp_iflag_f32_e64 v0, v2, PR printsv_fract_f64_e64 v[0:1], v[2:3].0x1af(0000afd502091a04): LLVM printsv_rcp_f64_e64 v[0:1], v[2:3], PR printsv_rndne_f64_e64 v[0:1], v[2:3].0x1b1(0000b1d502091a04): LLVM printsv_rsq_f64_e64 v[0:1], v[2:3], PR printsv_rcp_f64_e64 v[0:1], v[2:3].0x1b4(0000b4d502091a04): LLVM printsv_sqrt_f64_e64 v[0:1], v[2:3], PR printsv_frexp_mant_f32_e64 v0, v2.0x1b9(0000b9d502091a04): LLVM printsv_ffbh_u32_e64 v0, v2, PR printsv_sqrt_f64_e64 v[0:1], v[2:3].0x1ba(0000bad502091a04): LLVM printsv_ffbl_b32_e64 v0, v2, PR printsv_frexp_exp_i32_f64_e64 v0, v[2:3].0x1bb(0000bbd502091a04): LLVM printsv_ffbh_i32_e64 v0, v2, PR printsv_frexp_mant_f64_e64 v[0:1], v[2:3].VOP3A / VOP3B mnemonics, arities, and register classes:
0x128,0x129,0x12a: LLVM printsv_add_co_ci_u32_e64,v_sub_co_ci_u32_e64,v_subrev_co_ci_u32_e64; PR drops the_e64suffix.0x140(000040d502091a04): LLVM printsv_mad_legacy_f32, PR printsv_fma_legacy_f32.0x150(000050d502091a04):v_mullit_f32takes three sources (v0, v2, v4, v6); PR prints two (v0, v2, v4).0x172(v_qsad_pk_u16_u8),0x173(v_mqsad_pk_u16_u8), and0x175(v_mqsad_u32_u8) need multi-dword register ranges (v[0:1]/v[0:3],v[2:3],v[6:7]/v[6:9]) rather than single 32-bit registers.0x342,0x343,0x35a(v_interp_p1ll_f16,v_interp_p1lv_f16,v_interp_p2_f16) encodeattrandhighfields instead of plain VGPR operands.0x360(v_readlane_b32) writes a scalar destination (s0, notv0), and0x361/0x377/0x378(v_writelane_b32,v_permlane16_b32,v_permlanex16_b32) take scalar lane-selector operands.Fixing the VOP1 table slots and either correcting the remaining multi-dword/special forms or leaving them explicitly undecoded (as @R0Y00 suggested) should get the VOP3 sweep clean against LLVM.
AI-assisted: yes (automated LLVM 23 differential check on Linux x64, reviewed before posting).
Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-22T15:33:38Z.
Updated in 8b9e629 to resolve all 23 discrepancies flagged by the LLVM 23.1.4 (gfx1013) differential sweep:
VOP1-in-VOP3 slot fixes:
0x180:v_nopin VOP3 now correctly formats asv_nopwithout operands (arity 0).VOP1_OPS:0x2b(0x1ab):v_rcp_iflag_f32_e64 v0, v20x2f(0x1af):v_rcp_f64_e64 v[0:1], v[2:3]0x31(0x1b1):v_rsq_f64_e64 v[0:1], v[2:3]0x34(0x1b4):v_sqrt_f64_e64 v[0:1], v[2:3]0x39(0x1b9):v_ffbh_u32_e64 v0, v20x3a(0x1ba):v_ffbl_b32_e64 v0, v20x3b(0x1bb):v_ffbh_i32_e64 v0, v2VOP3A / VOP3B opcode mnemonics & arities:
0x128, 0x129, 0x12a: Kept the_e64suffix (v_add_co_ci_u32_e64,v_sub_co_ci_u32_e64,v_subrev_co_ci_u32_e64).0x140: Corrected mnemonic fromv_fma_legacy_f32tov_mad_legacy_f32.0x150:v_mullit_f32now takes 3 sources (v0, v2, v4, v6).Special / Non-standard register forms left explicitly undecoded:
v_vop3_<op>):0x172 (v_qsad_pk_u16_u8),0x173 (v_mqsad_pk_u16_u8),0x175 (v_mqsad_u32_u8)(multi-dword quads)0x342 (v_interp_p1ll_f16),0x343 (v_interp_p1lv_f16),0x35a (v_interp_p2_f16)(attr/high fields)0x360 (v_readlane_b32),0x361 (v_writelane_b32),0x377 (v_permlane16_b32),0x378 (v_permlanex16_b32)(scalar destination & lane selectors)Independent checks & stream tests:
000080d502091a04,0000abd502091a04,0000afd502091a04,0000b1d502091a04,0000b4d502091a04,0000b9d502091a04,0000bad502091a04,0000bbd502091a04,000040d502091a04,000050d502091a04,010028d502060000) totest_golden_vectors.test_vop3_operand_widths_and_stream_alignmentto verify mixed-width forms, 0-source VOP3v_nop, 3-sourcev_mullit_f32, and explicitly undecoded 8-byte instructions followed bys_endpgm.Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-22T18:15:02Z.
@R0Y00 Rebased onto
main(commit5fc014d), cleanly resolving the merge conflicts with #579 and #580