disasm_rdna2: format 64-bit SOP1 and SOP2 operands as register pairs #682

Merged
Holastor merged 1 commit from upstream-pr/688 into main 2026-11-22 23:01:36 +00:00
Holastor commented 2026-11-22 20:21:14 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-22T20:21:14Z.


Summary

Addresses review feedback on #688 by addressing the root cause in tools/disasm_rdna2.py rather than loosening operand syntax in the shader translator and scanner:

  • In RDNA 2 / GFX1013 Wave32, 64-bit scalar operations (SOP1, SOP2) operate on 64-bit scalar quantities. While EXEC is a 32-bit register in Wave32 mode, SGPR operands are register pairs (s[N:N+1]), matching standard LLVM assembly syntax (llvm-mc -triple=amdgcn--amdpal -mcpu=gfx1013).
  • Previously, tools/disasm_rdna2.py formatted SOP1 and SOP2 operands using decode_s_reg() instead of decode_s_reg64(), emitting single register names (e.g. s2 instead of s[2:3]) for 64-bit instructions (s_mov_b64, s_not_b64, s_and_b64, etc.).
  • Update decode_instruction() in tools/disasm_rdna2.py to use decode_s_reg64() for 64-bit SOP1 and SOP2 instructions, keeping single registers for 32-bit shift counts/bitfield offsets (s_lshl_b64, s_lshr_b64, s_ashr_b64, s_bfe_u64, s_bfe_i64, s_bfm_b64).
  • Add 0x0b: ("s_cselect_b64", "Scalar conditional select 64-bit") to SOP2_OPS.
  • Update tests/rdna2_tools_check.py with golden vectors for 64-bit SOP1/SOP2 pair formatting (s_mov_b64 s[2:3], s[0:1], s_not_b64, s_and_b64, s_lshl_b64, s_wqm_b64).
  • Reverts all changes to tools/pixel_aot.py, tools/pixel_cb_read.py, and tools/scan_unsupported_shaders.py, avoiding non-LLVM syntax, scanner-translator disparity, and conflicts with #700.

Verification

python -B tests/rdna2_tools_check.py
python -B tests/pixel_aot_check.py
python -B tests/docs_links_check.py
python -B tests/bidi_controls_check.py
python -B tests/pso_readiness_check.py
python -B tests/dxil_retarget_check.py
  • tests/rdna2_tools_check.py: 54 passed (1 capability skip for local LLVM_LIB).
  • tests/pixel_aot_check.py: Passed.
  • tests/docs_links_check.py: Checked 10 Markdown files and 134 links, all passed.
  • tests/bidi_controls_check.py: Checked 601 tracked files, all passed.
  • tests/pso_readiness_check.py: Passed.
  • tests/dxil_retarget_check.py: Passed.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6547305255 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/688). Originally posted by [Holastor](https://github.com/Holastor) on 2026-11-22T20:21:14Z. --- ## Summary Addresses review feedback on #688 by addressing the root cause in `tools/disasm_rdna2.py` rather than loosening operand syntax in the shader translator and scanner: - In RDNA 2 / GFX1013 Wave32, 64-bit scalar operations (SOP1, SOP2) operate on 64-bit scalar quantities. While EXEC is a 32-bit register in Wave32 mode, SGPR operands are register pairs (`s[N:N+1]`), matching standard LLVM assembly syntax (`llvm-mc -triple=amdgcn--amdpal -mcpu=gfx1013`). - Previously, `tools/disasm_rdna2.py` formatted SOP1 and SOP2 operands using `decode_s_reg()` instead of `decode_s_reg64()`, emitting single register names (e.g. `s2` instead of `s[2:3]`) for 64-bit instructions (`s_mov_b64`, `s_not_b64`, `s_and_b64`, etc.). - Update `decode_instruction()` in `tools/disasm_rdna2.py` to use `decode_s_reg64()` for 64-bit SOP1 and SOP2 instructions, keeping single registers for 32-bit shift counts/bitfield offsets (`s_lshl_b64`, `s_lshr_b64`, `s_ashr_b64`, `s_bfe_u64`, `s_bfe_i64`, `s_bfm_b64`). - Add `0x0b: ("s_cselect_b64", "Scalar conditional select 64-bit")` to `SOP2_OPS`. - Update `tests/rdna2_tools_check.py` with golden vectors for 64-bit SOP1/SOP2 pair formatting (`s_mov_b64 s[2:3], s[0:1]`, `s_not_b64`, `s_and_b64`, `s_lshl_b64`, `s_wqm_b64`). - Reverts all changes to `tools/pixel_aot.py`, `tools/pixel_cb_read.py`, and `tools/scan_unsupported_shaders.py`, avoiding non-LLVM syntax, scanner-translator disparity, and conflicts with #700. ## Verification ```powershell python -B tests/rdna2_tools_check.py python -B tests/pixel_aot_check.py python -B tests/docs_links_check.py python -B tests/bidi_controls_check.py python -B tests/pso_readiness_check.py python -B tests/dxil_retarget_check.py ``` - `tests/rdna2_tools_check.py`: 54 passed (1 capability skip for local `LLVM_LIB`). - `tests/pixel_aot_check.py`: Passed. - `tests/docs_links_check.py`: Checked 10 Markdown files and 134 links, all passed. - `tests/bidi_controls_check.py`: Checked 601 tracked files, all passed. - `tests/pso_readiness_check.py`: Passed. - `tests/dxil_retarget_check.py`: Passed.
upstream-sync closed this pull request 2026-11-24 06:44:20 +00:00
MatyEjsr commented 2026-11-24 06:48:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MatyEjsr on 2026-11-22T21:51:41Z.


Verdict: Request changes (reviewed head dac105cbd407531ed963da998a4ff3aa8ca8106d, compared against main 4c3b573).

Verification

Environment: Windows 11 x64, Python 3.12.10, and WSL Arch llvm-mc 23.1.5 (-triple=amdgcn--amdpal -mcpu=gfx1013). Zero-GPU review (no WARP or hardware draw executed).

Commands and results on dac105c:

  • python -B tests/pixel_aot_check.py: passed (exit 0).
  • python -B tests/rdna2_tools_check.py: 53 passed, 1 skipped (test_llvm_comparison, skipped because LLVM_LIB is not set on Windows).
  • python -B tests/docs_links_check.py and python -B tests/bidi_controls_check.py: both passed.
  • git merge-tree --write-tree main dac105c: clean against 4c3b573 (exit 0); conflicts with #700 (git merge-tree exit 1).

Issues to address

  1. Root cause is tools/disasm_rdna2.py formatting, not Wave32 / gfx1013 assembly syntax:

    • Verified with llvm-mc -triple=amdgcn--amdpal -mcpu=gfx1013 -show-encoding: single-SGPR operands on 64-bit SALU ops are rejected (s_mov_b64 s0, s2, s_and_b64 s0, s2, s4, s_lshl_b64 s0, s2, 4, s_bfe_u64 s0, s2, s4 all fail with error: invalid operand for instruction), whereas s[0:1], s[2:3] assembles and disassembles cleanly.
    • Single-SGPR formatting on 64-bit SOP1/SOP2 ops (s_mov_b64 s2, s0) comes from tools/disasm_rdna2.py calling decode_s_reg instead of decode_s_reg64 (unlike SOPC/VOPC, which already use decode_s_reg64). Fixing disasm_rdna2.py to emit s[N:N+1] for 64-bit SOP1/SOP2 instructions addresses the root cause without introducing non-LLVM syntax into pixel_aot.py, pixel_cb_read.py, and scan_unsupported_shaders.py.
  2. Scanner vs. translator disagreement and missing opcode recognition (tools/scan_unsupported_shaders.py):

    • SCALAR64_DST and SCALAR64_SOURCE allow s\d+ without checking even alignment or the 0..104 bound, so is_instruction_supported() returns True for inputs that pixel_aot.py rejects:
      • s_mov_b64 s45, s46, s_mov_b64 s44, s45, s_mov_b64 s106, s44
      • s_and_b64 s45, s44, s46, s_and_b64 s44, s45, s46
      • s_bfe_u64 s45, s44, s46, s_bfm_b64 s45, 4, 8
    • s_bfe_[ui]64 is added to SUPPORTED_INSTRUCTIONS_REGEX, making is_instruction_supported("s_bfe_u64 s44, s44, s46") == True, while s_bfe_u64 and s_bfe_i64 are missing from KNOWN_RDNA2_BASE_OPCODES (is_opcode_recognized() == False).
  3. tools/pixel_cb_read.py leaks unrelated #684 changes and has incomplete/unvalidated 64-bit write tracking:

    • Lines 59–62 include unrelated #684 exec_lo / s_wqm_b32 exec, exec / s_and_b32 exec, ... changes (mixing a separate PR into this one).
    • if op.endswith(("_b64", "_i64", "_u64")) and re.fullmatch(r"s\d+", dest): return range(n, n + 2) skips even-alignment and range checks (scalar_writes("s_mov_b64 s45, s46") == range(45, 47), scalar_writes("s_mov_b64 s105, s46") == range(105, 107)).
    • Only s_not_b64, s_brev_b64, and s_cmov_b64 were added to the opcode list; other 64-bit SALU ops widened in pixel_aot.py (s_and_b64, s_or_b64, s_cselect_b64, s_lshl_b64, s_bfm_b64, s_bfe_u64) still return None from scalar_writes().
  4. Conflict and contradiction with #700, plus no runtime draw coverage for general s_mov_b64:

    • Directly conflicts with and contradicts #700's negative controls on single-SGPR s_bfe_*64 / s_bfm_b64.
    • The new general s_mov_b64 lowering in pixel_aot.py is only checked statically in check_controls(), with no observable draw test.

AI-assisted review (local Python and llvm-mc checks executed locally).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7086369086 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/688#issuecomment-7086369086). Originally posted by [MatyEjsr](https://github.com/MatyEjsr) on 2026-11-22T21:51:41Z. --- **Verdict: Request changes** (reviewed head `dac105cbd407531ed963da998a4ff3aa8ca8106d`, compared against `main` `4c3b573`). ### Verification Environment: Windows 11 x64, Python 3.12.10, and WSL Arch `llvm-mc` 23.1.5 (`-triple=amdgcn--amdpal -mcpu=gfx1013`). Zero-GPU review (no WARP or hardware draw executed). Commands and results on `dac105c`: - `python -B tests/pixel_aot_check.py`: passed (exit 0). - `python -B tests/rdna2_tools_check.py`: **53 passed, 1 skipped** (`test_llvm_comparison`, skipped because `LLVM_LIB` is not set on Windows). - `python -B tests/docs_links_check.py` and `python -B tests/bidi_controls_check.py`: both passed. - `git merge-tree --write-tree main dac105c`: clean against `4c3b573` (exit 0); **conflicts with #700** (`git merge-tree` exit 1). ### Issues to address 1. **Root cause is `tools/disasm_rdna2.py` formatting, not Wave32 / `gfx1013` assembly syntax:** - Verified with `llvm-mc -triple=amdgcn--amdpal -mcpu=gfx1013 -show-encoding`: single-SGPR operands on 64-bit SALU ops are rejected (`s_mov_b64 s0, s2`, `s_and_b64 s0, s2, s4`, `s_lshl_b64 s0, s2, 4`, `s_bfe_u64 s0, s2, s4` all fail with `error: invalid operand for instruction`), whereas `s[0:1], s[2:3]` assembles and disassembles cleanly. - Single-SGPR formatting on 64-bit SOP1/SOP2 ops (`s_mov_b64 s2, s0`) comes from `tools/disasm_rdna2.py` calling `decode_s_reg` instead of `decode_s_reg64` (unlike SOPC/VOPC, which already use `decode_s_reg64`). Fixing `disasm_rdna2.py` to emit `s[N:N+1]` for 64-bit SOP1/SOP2 instructions addresses the root cause without introducing non-LLVM syntax into `pixel_aot.py`, `pixel_cb_read.py`, and `scan_unsupported_shaders.py`. 2. **Scanner vs. translator disagreement and missing opcode recognition (`tools/scan_unsupported_shaders.py`):** - `SCALAR64_DST` and `SCALAR64_SOURCE` allow `s\d+` without checking even alignment or the `0..104` bound, so `is_instruction_supported()` returns `True` for inputs that `pixel_aot.py` rejects: - `s_mov_b64 s45, s46`, `s_mov_b64 s44, s45`, `s_mov_b64 s106, s44` - `s_and_b64 s45, s44, s46`, `s_and_b64 s44, s45, s46` - `s_bfe_u64 s45, s44, s46`, `s_bfm_b64 s45, 4, 8` - `s_bfe_[ui]64` is added to `SUPPORTED_INSTRUCTIONS_REGEX`, making `is_instruction_supported("s_bfe_u64 s44, s44, s46") == True`, while `s_bfe_u64` and `s_bfe_i64` are missing from `KNOWN_RDNA2_BASE_OPCODES` (`is_opcode_recognized() == False`). 3. **`tools/pixel_cb_read.py` leaks unrelated #684 changes and has incomplete/unvalidated 64-bit write tracking:** - Lines 59–62 include unrelated `#684` `exec_lo` / `s_wqm_b32 exec, exec` / `s_and_b32 exec, ...` changes (mixing a separate PR into this one). - `if op.endswith(("_b64", "_i64", "_u64")) and re.fullmatch(r"s\d+", dest): return range(n, n + 2)` skips even-alignment and range checks (`scalar_writes("s_mov_b64 s45, s46") == range(45, 47)`, `scalar_writes("s_mov_b64 s105, s46") == range(105, 107)`). - Only `s_not_b64`, `s_brev_b64`, and `s_cmov_b64` were added to the opcode list; other 64-bit SALU ops widened in `pixel_aot.py` (`s_and_b64`, `s_or_b64`, `s_cselect_b64`, `s_lshl_b64`, `s_bfm_b64`, `s_bfe_u64`) still return `None` from `scalar_writes()`. 4. **Conflict and contradiction with #700, plus no runtime draw coverage for general `s_mov_b64`:** - Directly conflicts with and contradicts #700's negative controls on single-SGPR `s_bfe_*64` / `s_bfm_b64`. - The new general `s_mov_b64` lowering in `pixel_aot.py` is only checked statically in `check_controls()`, with no observable draw test. *AI-assisted review (local Python and `llvm-mc` checks executed locally).*
Holastor commented 2026-11-24 06:48:49 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-22T22:21:37Z.


Thanks for the thorough review and for pinpointing the root cause, @MatyEjsr! You're completely right: llvm-mc strictly requires s[N:N+1] pairs for 64-bit SALU operations in amdgcn--amdpal -mcpu=gfx1013, and the single-SGPR syntax was an artifact of tools/disasm_rdna2.py formatting with decode_s_reg() instead of decode_s_reg64().

We have updated this PR to fix the root cause cleanly:

  1. tools/disasm_rdna2.py:
    • Updated 64-bit SOP1 decoding to use decode_s_reg64() for sdst and ssrc0.
    • Updated 64-bit SOP2 decoding to use decode_s_reg64() for sdst, ssrc0 (except s_bfm_b64), and ssrc1 (except 32-bit shift/bfe operands s_lshl_b64, s_lshr_b64, s_ashr_b64, s_bfe_u64, s_bfe_i64, s_bfm_b64).
    • Added s_cselect_b64 (opcode 0x0b) to SOP2_OPS.
  2. Reverted all changes to tools/pixel_aot.py, tools/pixel_cb_read.py, and tools/scan_unsupported_shaders.py:
    • Preserves strict adherence to standard LLVM assembly syntax.
    • Eliminates scanner-translator divergence and eliminates any conflict with #700.
  3. Tests (tests/rdna2_tools_check.py):
    • Updated the golden vectors from s_mov_b64 s2, s0 to s_mov_b64 s[2:3], s[0:1].
    • Added golden test cases for s_not_b64 s[2:3], s[0:1], s_and_b64 s[0:1], s[2:3], s[4:5], s_lshl_b64 s[0:1], s[2:3], s4, s_mov_b64 s[50:51], exec, s_wqm_b64 exec, exec, and s_and_b64 exec, exec, s[50:51].

All test suites pass locally (tests/rdna2_tools_check.py, tests/pixel_aot_check.py, tests/docs_links_check.py, tests/bidi_controls_check.py, tests/pso_readiness_check.py, tests/dxil_retarget_check.py).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7086756108 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/688#issuecomment-7086756108). Originally posted by [Holastor](https://github.com/Holastor) on 2026-11-22T22:21:37Z. --- Thanks for the thorough review and for pinpointing the root cause, @MatyEjsr! You're completely right: `llvm-mc` strictly requires `s[N:N+1]` pairs for 64-bit SALU operations in `amdgcn--amdpal -mcpu=gfx1013`, and the single-SGPR syntax was an artifact of `tools/disasm_rdna2.py` formatting with `decode_s_reg()` instead of `decode_s_reg64()`. We have updated this PR to fix the root cause cleanly: 1. **`tools/disasm_rdna2.py`**: - Updated 64-bit SOP1 decoding to use `decode_s_reg64()` for `sdst` and `ssrc0`. - Updated 64-bit SOP2 decoding to use `decode_s_reg64()` for `sdst`, `ssrc0` (except `s_bfm_b64`), and `ssrc1` (except 32-bit shift/bfe operands `s_lshl_b64`, `s_lshr_b64`, `s_ashr_b64`, `s_bfe_u64`, `s_bfe_i64`, `s_bfm_b64`). - Added `s_cselect_b64` (opcode `0x0b`) to `SOP2_OPS`. 2. **Reverted all changes to `tools/pixel_aot.py`, `tools/pixel_cb_read.py`, and `tools/scan_unsupported_shaders.py`**: - Preserves strict adherence to standard LLVM assembly syntax. - Eliminates scanner-translator divergence and eliminates any conflict with #700. 3. **Tests (`tests/rdna2_tools_check.py`)**: - Updated the golden vectors from `s_mov_b64 s2, s0` to `s_mov_b64 s[2:3], s[0:1]`. - Added golden test cases for `s_not_b64 s[2:3], s[0:1]`, `s_and_b64 s[0:1], s[2:3], s[4:5]`, `s_lshl_b64 s[0:1], s[2:3], s4`, `s_mov_b64 s[50:51], exec`, `s_wqm_b64 exec, exec`, and `s_and_b64 exec, exec, s[50:51]`. All test suites pass locally (`tests/rdna2_tools_check.py`, `tests/pixel_aot_check.py`, `tests/docs_links_check.py`, `tests/bidi_controls_check.py`, `tests/pso_readiness_check.py`, `tests/dxil_retarget_check.py`).
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!682
No description provided.