tooling: print hwreg operands in disasm_rdna2 as LLVM 15 does #944

Merged
MasterDomino merged 1 commit from upstream-pr/951 into main 2026-11-23 18:49:19 +00:00
MasterDomino commented 2026-11-23 18:29:45 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-23T18:29:45Z.


Change

First step of #938: tools/disasm_rdna2.py now prints SOPK hwreg operands the way LLVM 15 does for gfx1013. Before, s_setreg_imm32_b32 came out as raw words (0x881, 0x3), while pixel_aot and tools/scan_unsupported_shaders.py match 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.

  • The hwreg operand. format_hwreg() decodes the register ID, offset and width from SIMM16. A whole-register field prints as hwreg(NAME); otherwise it prints hwreg(NAME, offset, width).
    • IDs without an LLVM 15 gfx1013 name keep a numeric fallback: hwreg(4), hwreg(63, 31, 1).
    • The name table is HWREG_NAMES.
  • The literal. format_literal32() prints the s_setreg_imm32_b32 literal as LLVM does: inline integers -16..64 and the inline float patterns symbolically (-1, 1.0, 0.15915494), and everything else in hex.
  • Two instructions get names. s_getreg_b32 and s_setreg_b32 (SOPK 0x12/0x13) are now named with the same operand format; they used to print as s_sopk_12/s_sopk_13. The translator still rejects both, as docs/experiments.md states. This PR changes only how they decode.
  • Unchanged: s_endpgm handling 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, the s_setreg_imm32_b32 golden case 341280ba41312111 used to expect the raw spelling s_setreg_imm32_b32 0x1234, 0x11213141. It now expects s_setreg_imm32_b32 hwreg(52, 8, 3), 0x11213141, which is LLVM 15.0.7's disassembly of the same bytes (checked with pixel_aot.disassemble, gfx1013). The instruction length and opcode assertions are unchanged.

Refs #938

Verification

Upstream main at 810acb0, Fedora 45 x86_64, Python 3.15.2, LLVM 15.0.7 (llvm15-15.0.7-17.fc45).

P=/usr/lib64/llvm15
LLVM_LIB=$P/lib/libLLVM-15.so LLVM_MC=$P/bin/llvm-mc LLVM_OBJCOPY=$P/bin/llvm-objcopy \
  python -B tests/rdna2_tools_check.py
python -B tests/rdna2_tools_check.py
  • With LLVM: Ran 78 tests … OK. Without LLVM: OK (skipped=2); the two skips are test_llvm_comparison and the new test_hwreg_llvm_round_trip.
  • The other checks: the 26 platform-independent checks from docs/non-windows-hosts.md and pe_package_preflight_check.py exit 0, and so do tests/pixel_aot_check.py binary and tests/ffx_dispatch_aot_check.py with LLVM 15.

New tests:

  • test_hwreg_llvm_round_trip (LLVM 15).
    • 14 s_setreg_imm32_b32 / s_getreg_b32 / s_setreg_b32 lines are assembled by llvm-mc. disasm_rdna2 must print exactly LLVM's text, and its text must re-assemble to the same bytes.
    • The fixture includes three one-field variants of 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 pass is_instruction_supported; the old raw spelling and the directed mode …, 1 don't.
  • test_binary_scan_reports_decoded_hwreg_writes_as_supported (pure Python, source-built scan case).
    • scan_directory_or_files runs on a .bin of 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).
    • A control .bin with the directed mode 1 reports exactly that one line as unsupported.

Negative control. With tools/disasm_rdna2.py reverted to 810acb0 and the new tests kept:

  • the round trip fails;
  • 22 failures in the spelling test: 17 encodings, 4 support checks, and the directed-mode spelling;
  • the corrected golden case fails;
  • the scan case reports (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 LLVMDisasmInstruction for 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.py with this change:

Measurement Before After
Unsupported instruction: s_setreg_imm32_b32 as the first translator rejection 2,249 records 0
Records with an s_setreg/s_getreg line marked unsupported 5,429 (12,220 lines) 10 (10 lines)

The 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 as s_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 past s_endpgm. Separately, KNOWN_RDNA2_BASE_OPCODES in the scanner doesn't list s_setreg_imm32_b32, s_setreg_b32 or s_getreg_b32; I left that unchanged.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed. (No capability or build requirement changed; docs/experiments.md's statement that s_setreg_b32/s_getreg_b32 stay unsupported still holds.)
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

🤖 Generated with Claude Code

https://claude.ai/code/session_01B48PpcRN2Er51keRf2DsS5

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6566121262 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/951). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-23T18:29:45Z. --- ## Change First step of #938: `tools/disasm_rdna2.py` now prints SOPK `hwreg` operands the way LLVM 15 does for gfx1013. Before, `s_setreg_imm32_b32` came out as raw words (`0x881, 0x3`), while `pixel_aot` and `tools/scan_unsupported_shaders.py` match 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. - **The `hwreg` operand.** `format_hwreg()` decodes the register ID, offset and width from SIMM16. A whole-register field prints as `hwreg(NAME)`; otherwise it prints `hwreg(NAME, offset, width)`. - IDs without an LLVM 15 gfx1013 name keep a numeric fallback: `hwreg(4)`, `hwreg(63, 31, 1)`. - The name table is `HWREG_NAMES`. - **The literal.** `format_literal32()` prints the `s_setreg_imm32_b32` literal as LLVM does: inline integers -16..64 and the inline float patterns symbolically (`-1`, `1.0`, `0.15915494`), and everything else in hex. - **Two instructions get names.** `s_getreg_b32` and `s_setreg_b32` (SOPK 0x12/0x13) are now named with the same operand format; they used to print as `s_sopk_12`/`s_sopk_13`. The translator still rejects both, as `docs/experiments.md` states. This PR changes only how they decode. - **Unchanged:** `s_endpgm` handling 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`, the `s_setreg_imm32_b32` golden case `341280ba41312111` used to expect the raw spelling `s_setreg_imm32_b32 0x1234, 0x11213141`. It now expects `s_setreg_imm32_b32 hwreg(52, 8, 3), 0x11213141`, which is LLVM 15.0.7's disassembly of the same bytes (checked with `pixel_aot.disassemble`, gfx1013). The instruction length and opcode assertions are unchanged. Refs #938 ## Verification Upstream `main` at `810acb0`, Fedora 45 x86_64, Python 3.15.2, LLVM 15.0.7 (`llvm15-15.0.7-17.fc45`). ```sh P=/usr/lib64/llvm15 LLVM_LIB=$P/lib/libLLVM-15.so LLVM_MC=$P/bin/llvm-mc LLVM_OBJCOPY=$P/bin/llvm-objcopy \ python -B tests/rdna2_tools_check.py python -B tests/rdna2_tools_check.py ``` - **With LLVM:** `Ran 78 tests … OK`. Without LLVM: `OK (skipped=2)`; the two skips are `test_llvm_comparison` and the new `test_hwreg_llvm_round_trip`. - **The other checks:** the 26 platform-independent checks from `docs/non-windows-hosts.md` and `pe_package_preflight_check.py` exit 0, and so do `tests/pixel_aot_check.py binary` and `tests/ffx_dispatch_aot_check.py` with LLVM 15. New tests: - **`test_hwreg_llvm_round_trip`** (LLVM 15). - 14 `s_setreg_imm32_b32` / `s_getreg_b32` / `s_setreg_b32` lines are assembled by `llvm-mc`. `disasm_rdna2` must print exactly LLVM's text, and its text must re-assemble to the same bytes. - The fixture includes three one-field variants of `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 pass `is_instruction_supported`; the old raw spelling and the directed mode `…, 1` don't. - **`test_binary_scan_reports_decoded_hwreg_writes_as_supported`** (pure Python, source-built scan case). - `scan_directory_or_files` runs on a `.bin` of 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)`. - A control `.bin` with the directed mode 1 reports exactly that one line as unsupported. **Negative control.** With `tools/disasm_rdna2.py` reverted to `810acb0` and the new tests kept: - the round trip fails; - 22 failures in the spelling test: 17 encodings, 4 support checks, and the directed-mode spelling; - the corrected golden case fails; - the scan case reports `(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 `LLVMDisasmInstruction` for 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.py` with this change: | Measurement | Before | After | |---|---|---| | `Unsupported instruction: s_setreg_imm32_b32` as the first translator rejection | 2,249 records | 0 | | Records with an `s_setreg`/`s_getreg` line marked unsupported | 5,429 (12,220 lines) | 10 (10 lines) | The 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 as `s_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 past `s_endpgm`. Separately, `KNOWN_RDNA2_BASE_OPCODES` in the scanner doesn't list `s_setreg_imm32_b32`, `s_setreg_b32` or `s_getreg_b32`; I left that unchanged. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. (No capability or build requirement changed; `docs/experiments.md`'s statement that `s_setreg_b32`/`s_getreg_b32` stay unsupported still holds.) - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01B48PpcRN2Er51keRf2DsS5
upstream-sync closed this pull request 2026-11-24 06:45:33 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!944
No description provided.