tooling: decode GFX10 VOP1 and VOP2 SDWA instructions #1179

Merged
Batushn merged 2 commits from upstream-pr/1186 into main 2026-11-24 03:38:53 +00:00
Batushn commented 2026-11-24 02:59:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Batushn on 2026-11-24T02:59:29Z.


Change

Decode GFX10 8-byte VOP1 and VOP2 SDWA (src0=249) forms in tools/disasm_rdna2.py instead of returning <unsupported SDWA> placeholders.

  • Added _decode_vop1_sdwa (VOP_SDWA9Ae): handles v_nop restricted SDWA form, scalar/VGPR src0 (src0_sel, sext/abs/neg), dst_sel, dst_unused (UNUSED_PAD/UNUSED_SEXT/UNUSED_PRESERVE), clamp, omod (mul:2, mul:4, div:2), and rejects 64-bit / non-SDWA VOP1 ops, invalid selectors, scalar codes forbidden on v_movrel*, and LLVM 15 unsupported scalar codes (209-234, 249, 250, 255).
  • Added _decode_vop2_sdwa (VOP_SDWA9Ae / VOP_SDWA9Be for carry ops v_add_co_ci_u32, v_sub_co_ci_u32, v_subrev_co_ci_u32, v_cndmask_b32): handles two-operand src0/src1 selectors & modifiers (including v_ldexp_f16 int src1 and v_cvt_pkrtz_f16_f32 float src0/src1), carry-in vcc_lo on SDWA9Be, and rejects unsupported VOP2 opcodes (0x02, 0x06, 0x0d, 0x1f..0x21, 0x2b..0x2d, 0x36..0x38, 0x3c) and invalid fields.
  • Shared float modifier helper _format_sdwa_float_modifiers with _decode_vopc_sdwa.

Verification

Commit 89e00bf (based on main 063df2c):

  • python -B tests/rdna2_tools_check.py: Ran 112 tests in 2.616s — OK (skipped=11) (the 11 skips are tests gated on LLVM_LIB, which is not configured in this local environment).
  • python -B tests/shader_census_check.py: passed (7/7).
  • python -B tests/shader_corpus_report_check.py: passed (8/8).
  • python -B tests/shader_probe_check.py: passed.
  • python -B tests/docs_links_check.py: passed (253 links checked).
  • python -B tests/bidi_controls_check.py: passed (948 files checked).

Evidence and follow-up

  • Test inputs in tests/rdna2_tools_check.py are synthetic little-endian instruction words cross-checked against LLVM 15 (VOPInstructions.td, VOP1Instructions.td, VOP2Instructions.td).
  • Includes negative controls verifying rejection of unsupported VOP1/VOP2 SDWA opcodes, invalid dst_sel/src_sel/omod fields, SGPR on v_movrel*, and non-zero reserved/fixed control bits.
  • CI with LLVM_LIB configured will also exercise the 11 LLVM-cross-check tests.

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.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted: yes

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6573615848 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1186). Originally posted by [Batushn](https://github.com/Batushn) on 2026-11-24T02:59:29Z. --- ## Change Decode GFX10 8-byte `VOP1` and `VOP2` `SDWA` (`src0=249`) forms in `tools/disasm_rdna2.py` instead of returning `<unsupported SDWA>` placeholders. - Added `_decode_vop1_sdwa` (`VOP_SDWA9Ae`): handles `v_nop` restricted SDWA form, scalar/VGPR `src0` (`src0_sel`, `sext`/`abs`/`neg`), `dst_sel`, `dst_unused` (`UNUSED_PAD`/`UNUSED_SEXT`/`UNUSED_PRESERVE`), `clamp`, `omod` (`mul:2`, `mul:4`, `div:2`), and rejects 64-bit / non-SDWA `VOP1` ops, invalid selectors, scalar codes forbidden on `v_movrel*`, and LLVM 15 unsupported scalar codes (`209-234`, `249`, `250`, `255`). - Added `_decode_vop2_sdwa` (`VOP_SDWA9Ae` / `VOP_SDWA9Be` for carry ops `v_add_co_ci_u32`, `v_sub_co_ci_u32`, `v_subrev_co_ci_u32`, `v_cndmask_b32`): handles two-operand `src0`/`src1` selectors & modifiers (including `v_ldexp_f16` int `src1` and `v_cvt_pkrtz_f16_f32` float `src0`/`src1`), carry-in `vcc_lo` on `SDWA9Be`, and rejects unsupported VOP2 opcodes (`0x02`, `0x06`, `0x0d`, `0x1f`..`0x21`, `0x2b`..`0x2d`, `0x36`..`0x38`, `0x3c`) and invalid fields. - Shared float modifier helper `_format_sdwa_float_modifiers` with `_decode_vopc_sdwa`. ## Verification Commit `89e00bf` (based on `main` `063df2c`): - `python -B tests/rdna2_tools_check.py`: `Ran 112 tests in 2.616s — OK (skipped=11)` (the 11 skips are tests gated on `LLVM_LIB`, which is not configured in this local environment). - `python -B tests/shader_census_check.py`: passed (7/7). - `python -B tests/shader_corpus_report_check.py`: passed (8/8). - `python -B tests/shader_probe_check.py`: passed. - `python -B tests/docs_links_check.py`: passed (253 links checked). - `python -B tests/bidi_controls_check.py`: passed (948 files checked). ## Evidence and follow-up - Test inputs in `tests/rdna2_tools_check.py` are synthetic little-endian instruction words cross-checked against LLVM 15 (`VOPInstructions.td`, `VOP1Instructions.td`, `VOP2Instructions.td`). - Includes negative controls verifying rejection of unsupported `VOP1`/`VOP2` SDWA opcodes, invalid `dst_sel`/`src_sel`/`omod` fields, SGPR on `v_movrel*`, and non-zero reserved/fixed control bits. - CI with `LLVM_LIB` configured will also exercise the 11 LLVM-cross-check tests. ## 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. - [ ] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted: yes
upstream-sync closed this pull request 2026-11-24 06:46:46 +00:00
tedin7 commented 2026-11-24 06:46:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T03:03:58Z.

Review: COMMENTED


Technical review on Linux (Windows build/tests were not executed locally).

Checks run (Linux, commit 89e00bf8)

  • python3 tests/rdna2_tools_check.py: Ran 112 tests in 2.273s — OK (skipped=11) (without LLVM_LIB).
  • python3 -B tests/shader_census_check.py: Ran 7 tests in 0.419s — OK.
  • python3 -B tests/shader_corpus_report_check.py: Ran 8 tests in 0.639s — OK.
  • python3 -B tests/docs_links_check.py and python3 -B tests/bidi_controls_check.py: passed.
  • python3 -B tests/shader_probe_check.py: failed with ModuleNotFoundError: No module named 'pefile' in this environment.
  • LLVM_LIB=/usr/lib/llvm-19/lib/libLLVM-19.so LLVM_MC=/usr/bin/llvm-mc-19 LLVM_OBJCOPY=/usr/bin/llvm-objcopy-19 python3 -B tests/rdna2_tools_check.py -k "vop1_vop2" -v: failed in test_vop1_vop2_sdwa_llvm_round_trip (see findings).

Findings

  1. Undefined helper in tests/rdna2_tools_check.py (test_vop1_vop2_sdwa_llvm_round_trip):
    Line 1472 calls resolve_llvm_assembler_tools(), which is not defined in tests/rdna2_tools_check.py (existing tests use resolve_tool("LLVM_MC", ...) and resolve_tool("LLVM_OBJCOPY", ...)). When LLVM_LIB is set, the test raises NameError: name 'resolve_llvm_assembler_tools' is not defined.
  2. LLVM 19 mismatch on f9040a02c106860e (v_cndmask_b32_sdwa ... sext(v2)):
    Both libLLVM-19.so (Unknown instruction at byte 0) and llvm-mc-19 (error: not a valid operand on sext(v2)) reject sext(v2) on v_cndmask_b32_sdwa, and libLLVM-19.so accepts v_movrels_b32_sdwa / v_movrelsd_b32_sdwa with s2 (f986007e02068600, f988007e02068600). Please verify against LLVM 15 once resolve_llvm_assembler_tools() is fixed.

Decoder logic (_decode_vop1_sdwa, _decode_vop2_sdwa, 0xF9 dispatch, v_nop mask, dst_sel/dst_unused/src*_sel, omod/clamp/sext/abs/neg, vcc_lo on carry ops/v_cndmask_b32, and scanner sync in test_binary_scan_recognizes_vop1_vop2_sdwa) is otherwise clean and title-neutral.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6033053960 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1186#pullrequestreview-6033053960). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T03:03:58Z. **Review:** COMMENTED --- Technical review on Linux (Windows build/tests were **not** executed locally). ### Checks run (Linux, commit `89e00bf8`) - `python3 tests/rdna2_tools_check.py`: `Ran 112 tests in 2.273s — OK (skipped=11)` (without `LLVM_LIB`). - `python3 -B tests/shader_census_check.py`: `Ran 7 tests in 0.419s — OK`. - `python3 -B tests/shader_corpus_report_check.py`: `Ran 8 tests in 0.639s — OK`. - `python3 -B tests/docs_links_check.py` and `python3 -B tests/bidi_controls_check.py`: passed. - `python3 -B tests/shader_probe_check.py`: failed with `ModuleNotFoundError: No module named 'pefile'` in this environment. - `LLVM_LIB=/usr/lib/llvm-19/lib/libLLVM-19.so LLVM_MC=/usr/bin/llvm-mc-19 LLVM_OBJCOPY=/usr/bin/llvm-objcopy-19 python3 -B tests/rdna2_tools_check.py -k "vop1_vop2" -v`: failed in `test_vop1_vop2_sdwa_llvm_round_trip` (see findings). ### Findings 1. **Undefined helper in `tests/rdna2_tools_check.py` (`test_vop1_vop2_sdwa_llvm_round_trip`)**: Line 1472 calls `resolve_llvm_assembler_tools()`, which is not defined in `tests/rdna2_tools_check.py` (existing tests use `resolve_tool("LLVM_MC", ...)` and `resolve_tool("LLVM_OBJCOPY", ...)`). When `LLVM_LIB` is set, the test raises `NameError: name 'resolve_llvm_assembler_tools' is not defined`. 2. **LLVM 19 mismatch on `f9040a02c106860e` (`v_cndmask_b32_sdwa ... sext(v2)`)**: Both `libLLVM-19.so` (`Unknown instruction at byte 0`) and `llvm-mc-19` (`error: not a valid operand` on `sext(v2)`) reject `sext(v2)` on `v_cndmask_b32_sdwa`, and `libLLVM-19.so` accepts `v_movrels_b32_sdwa` / `v_movrelsd_b32_sdwa` with `s2` (`f986007e02068600`, `f988007e02068600`). Please verify against LLVM 15 once `resolve_llvm_assembler_tools()` is fixed. Decoder logic (`_decode_vop1_sdwa`, `_decode_vop2_sdwa`, `0xF9` dispatch, `v_nop` mask, `dst_sel`/`dst_unused`/`src*_sel`, `omod`/`clamp`/`sext`/`abs`/`neg`, `vcc_lo` on carry ops/`v_cndmask_b32`, and scanner sync in `test_binary_scan_recognizes_vop1_vop2_sdwa`) is otherwise clean and title-neutral.
tedin7 commented 2026-11-24 06:46:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T03:40:54Z.

Review: COMMENTED


Retest on Linux at commit 832abf98 (Windows build/tests were not executed locally).

Checks run (Linux, commit 832abf98)

  • /root/.local/share/x2w-rev-venv/bin/python -B tests/rdna2_tools_check.py: Ran 112 tests in 2.607s — OK (skipped=11) (without LLVM_LIB).
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/rdna2_tools_check.py -k "vop1_vop2" -v: Ran 4 tests — OK (skipped=2) (without LLVM_LIB).
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/shader_probe_check.py, tests/form_coverage_check.py, tests/shader_census_check.py (7/7), tests/shader_corpus_report_check.py (8/8), tests/docs_links_check.py, tests/bidi_controls_check.py: all passed.
  • LLVM_LIB=/usr/lib/llvm-19/lib/libLLVM-19.so LLVM_MC=/usr/bin/llvm-mc-19 LLVM_OBJCOPY=/usr/bin/llvm-objcopy-19 /root/.local/share/x2w-rev-venv/bin/python -B tests/rdna2_tools_check.py -k "vop1_vop2" -v: Ran 4 tests — FAILED (errors=2) in test_vop1_vop2_sdwa_llvm_round_trip (see below).

Retest status against previous review (89e00bf8)

  1. Fixed — resolve_llvm_assembler_tools() NameError: test_vop1_vop2_sdwa_llvm_round_trip now uses resolve_tool("LLVM_MC", ...) and resolve_tool("LLVM_OBJCOPY", ...), so the assembler/objcopy lookup no longer raises NameError.
  2. Remaining LLVM 19 mismatch on f9040a02c106860e (v_cndmask_b32_sdwa v5, -1, sext(v2), vcc_lo ...): Under LLVM 19, libLLVM-19.so still raises ValueError: Unknown instruction at byte 0 on f9040a02c106860e, and llvm-mc-19 rejects sext(v2) with error: not a valid operand. All other 28 vectors in VOP1_VOP2_SDWA_DECODED assemble with llvm-mc-19 and disassemble with libLLVM-19.so (per AGENTS.md, CI runs LLVM 15, which remains authoritative for this vector).
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6033310187 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1186#pullrequestreview-6033310187). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T03:40:54Z. **Review:** COMMENTED --- Retest on Linux at commit `832abf98` (Windows build/tests were **not** executed locally). ### Checks run (Linux, commit `832abf98`) - `/root/.local/share/x2w-rev-venv/bin/python -B tests/rdna2_tools_check.py`: `Ran 112 tests in 2.607s — OK (skipped=11)` (without `LLVM_LIB`). - `/root/.local/share/x2w-rev-venv/bin/python -B tests/rdna2_tools_check.py -k "vop1_vop2" -v`: `Ran 4 tests — OK (skipped=2)` (without `LLVM_LIB`). - `/root/.local/share/x2w-rev-venv/bin/python -B tests/shader_probe_check.py`, `tests/form_coverage_check.py`, `tests/shader_census_check.py` (`7/7`), `tests/shader_corpus_report_check.py` (`8/8`), `tests/docs_links_check.py`, `tests/bidi_controls_check.py`: all passed. - `LLVM_LIB=/usr/lib/llvm-19/lib/libLLVM-19.so LLVM_MC=/usr/bin/llvm-mc-19 LLVM_OBJCOPY=/usr/bin/llvm-objcopy-19 /root/.local/share/x2w-rev-venv/bin/python -B tests/rdna2_tools_check.py -k "vop1_vop2" -v`: `Ran 4 tests — FAILED (errors=2)` in `test_vop1_vop2_sdwa_llvm_round_trip` (see below). ### Retest status against previous review (`89e00bf8`) 1. **Fixed — `resolve_llvm_assembler_tools()` `NameError`**: `test_vop1_vop2_sdwa_llvm_round_trip` now uses `resolve_tool("LLVM_MC", ...)` and `resolve_tool("LLVM_OBJCOPY", ...)`, so the assembler/objcopy lookup no longer raises `NameError`. 2. **Remaining LLVM 19 mismatch on `f9040a02c106860e` (`v_cndmask_b32_sdwa v5, -1, sext(v2), vcc_lo ...`)**: Under LLVM 19, `libLLVM-19.so` still raises `ValueError: Unknown instruction at byte 0` on `f9040a02c106860e`, and `llvm-mc-19` rejects `sext(v2)` with `error: not a valid operand`. All other 28 vectors in `VOP1_VOP2_SDWA_DECODED` assemble with `llvm-mc-19` and disassemble with `libLLVM-19.so` (per `AGENTS.md`, CI runs LLVM 15, which remains authoritative for this vector).
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!1179
No description provided.