tooling: print hwreg operands in disasm_rdna2 as LLVM 15 does #944
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/951"
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 MasterDomino on 2026-11-23T18:29:45Z.
Change
First step of #938:
tools/disasm_rdna2.pynow prints SOPKhwregoperands the way LLVM 15 does for gfx1013. Before,s_setreg_imm32_b32came out as raw words (0x881, 0x3), whilepixel_aotandtools/scan_unsupported_shaders.pymatch LLVM's spelling (hwreg(HW_REG_MODE, 2, 2), 3). So the scan reported the MODE rounding and FLAT_SCRATCH writes that the translator accepts as unsupported.hwregoperand.format_hwreg()decodes the register ID, offset and width from SIMM16. A whole-register field prints ashwreg(NAME); otherwise it printshwreg(NAME, offset, width).hwreg(4),hwreg(63, 31, 1).HWREG_NAMES.format_literal32()prints thes_setreg_imm32_b32literal as LLVM does: inline integers -16..64 and the inline float patterns symbolically (-1,1.0,0.15915494), and everything else in hex.s_getreg_b32ands_setreg_b32(SOPK 0x12/0x13) are now named with the same operand format; they used to print ass_sopk_12/s_sopk_13. The translator still rejects both, asdocs/experiments.mdstates. This PR changes only how they decode.s_endpgmhandling and instruction boundaries. Bounded decoding and the other spellings from #938 are left for separate PRs, as asked.One existing expectation changed. In
test_second_dword_forms_keep_the_stream_aligned, thes_setreg_imm32_b32golden case341280ba41312111used to expect the raw spellings_setreg_imm32_b32 0x1234, 0x11213141. It now expectss_setreg_imm32_b32 hwreg(52, 8, 3), 0x11213141, which is LLVM 15.0.7's disassembly of the same bytes (checked withpixel_aot.disassemble, gfx1013). The instruction length and opcode assertions are unchanged.Refs #938
Verification
Upstream
mainat810acb0, Fedora 45 x86_64, Python 3.15.2, LLVM 15.0.7 (llvm15-15.0.7-17.fc45).Ran 78 tests … OK. Without LLVM:OK (skipped=2); the two skips aretest_llvm_comparisonand the newtest_hwreg_llvm_round_trip.docs/non-windows-hosts.mdandpe_package_preflight_check.pyexit 0, and so dotests/pixel_aot_check.py binaryandtests/ffx_dispatch_aot_check.pywith LLVM 15.New tests:
test_hwreg_llvm_round_trip(LLVM 15).s_setreg_imm32_b32/s_getreg_b32/s_setreg_b32lines are assembled byllvm-mc.disasm_rdna2must print exactly LLVM's text, and its text must re-assemble to the same bytes.hwreg(HW_REG_MODE, 2, 2): register (HW_REG_STATUS, 2, 2), offset (MODE, 3, 2) and width (MODE, 2, 3). It also includes unequal offset/width pairs (TRAPSTS, 1, 5,HW_ID1, 8, 4,GPR_ALLOC, 6, 9) and both numeric fallbacks. A swapped or dropped field changes the bytes.test_hwreg_operands_use_llvm_spelling(pure Python). 17 encodings with LLVM 15's text as the expected value, including the literal edge cases -16,0xffffffef, 64,0x41,0x80000000, 1.0, 0.15915494 and -4.0. The decoded MODE and FLAT_SCRATCH lines passis_instruction_supported; the old raw spelling and the directed mode…, 1don't.test_binary_scan_reports_decoded_hwreg_writes_as_supported(pure Python, source-built scan case).scan_directory_or_filesruns on a.binof llvm-mc output: MODE[3:2] = 3, FLAT_SCR_LO, FLAT_SCR_HI, MODE[3:2] = 0,s_endpgm. Expected:(total, supported, unsupported) = (5, 5, 0)..binwith the directed mode 1 reports exactly that one line as unsupported.Negative control. With
tools/disasm_rdna2.pyreverted to810acb0and the new tests kept:(5, 1, 4)instead of(5, 5, 0).That is
FAILED (failures=25)in total. Restoring the change passes all of them.Exhaustive comparison (local, not part of the suite). The decoder's text matches LLVM 15's
LLVMDisasmInstructionfor gfx1013 on 196,882 instructions with no mismatch. That covers all 65,536 SIMM16 values for each of the three opcodes, with assorted SGPRs and 266 literal values (inline integer and float boundaries plus 200 random words), and 44 special-SGPR cases.No Windows, D3D12 or GPU step is affected.
Evidence and follow-up
Effect on one local input (the 12,101 PS records counted in #711 and #932; aggregates only),
tools/scan_unsupported_shaders.pywith this change:Unsupported instruction: s_setreg_imm32_b32as the first translator rejections_setreg/s_getregline marked unsupportedThe remaining 10 are
s_setreg_b32 hwreg(HW_REG_POPS_PACKER, 0, 3), s1, an SGPR-sourced write the translator doesn't support. It used to print ass_sopk_13. The 2,249 records now stop at their next rejection, so this makes the scan accurate; it doesn't make more shaders translate.Not in this PR: the other spellings listed in #938 (
v_interp_*_f16, SDWA VOPC,image_atomic_*,v_add_co_ci_u32_e32) and decoding pasts_endpgm. Separately,KNOWN_RDNA2_BASE_OPCODESin the scanner doesn't lists_setreg_imm32_b32,s_setreg_b32ors_getreg_b32; I left that unchanged.Checklist
docs/experiments.md's statement thats_setreg_b32/s_getreg_b32stay unsupported still holds.)AI-assisted.
🤖 Generated with Claude Code
https://claude.ai/code/session_01B48PpcRN2Er51keRf2DsS5