tooling: decode GFX10 VOPC/VOPCX SDWA instructions in disasm_rdna2 #973

Merged
Batushn merged 4 commits from upstream-pr/980 into main 2026-11-23 20:05:37 +00:00
Batushn commented 2026-11-23 19:39:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Batushn on 2026-11-23T19:39:42Z.


Summary

Refs #938 (step 3: VOPC SDWA decoding).

Previously, tools/disasm_rdna2.py recognized the 8-byte length of VOPC instructions with src0 == 249 (SDWA) but returned a placeholder vopc_sdwa / <unsupported SDWA> record instead of decoding the GFX10 VOP_SDWA9Be extension word.

This PR adds _decode_vopc_sdwa() in tools/disasm_rdna2.py to decode GFX10 wave32 VOPC (v_cmp_*_sdwa) and VOPCX (v_cmpx_*_sdwa) SDWA instructions in LLVM 15 syntax:

  • Decodes sdst / sdst_en (Inst{47:40}): vcc_lo when sdst_en == 0, scalar register via decode_s_reg(sdst) when sdst_en == 1, and omits destination for v_cmpx_*_sdwa (EmitDst = 0).
  • Decodes src0 (Inst{39:32} + src0_sgpr Inst{55}) and src1 (Inst{16:9} + src1_sgpr Inst{63}) as VGPR or scalar/special register.
  • Applies float (-, |...|, -|...|) vs integer (sext(...)) modifiers matching LLVM 15's VOPC_Profile / VOPC_Class_Profile rules (v_cmp_class_f32_sdwa / v_cmp_class_f16_sdwa use float modifiers on src0 and sext on src1).
  • Formats src0_sel (Inst{50:48}) and src1_sel (Inst{58:56}) over BYTE_0..BYTE_3, WORD_0..WORD_1, DWORD.
  • Preserves clean fallback (vopc_sdwa / <unsupported SDWA>) for 64-bit VOPC opcodes, unknown opcodes, or invalid sel == 7, and preserves vopc_truncated for truncated 4-byte prefixes.

Tests

  • Updated TestRdna2Disasm.test_vopc_opcode_table_synthetic_forms for the decoded v_cmpx_eq_f32_sdwa -v1, v2 src0_sel:DWORD src1_sel:DWORD fixture.
  • Added TestRdna2Disasm.test_vopc_sdwa_decoding with 34 independent GFX10 wave32 golden vectors from LLVM 15.0.7 (gfx10_asm_vopc_sdwa.s and gfx10_asm_vopcx.s), src1_sgpr=1, and negative/boundary controls (f64 fallback, invalid sel == 7, 4-byte truncation).
  • Added TestRdna2Disasm.test_vopc_sdwa_llvm_round_trip assembling and round-tripping 33 single-field VOPC/VOPCX SDWA variants through LLVM 15 llvm-mc + llvm-objcopy + libLLVM (runs in the Assemble and translate gfx1013 fixtures CI job).
  • Added TestRdna2Scanner.test_binary_scan_recognizes_vopc_sdwa verifying binary shader scans classify decoded v_cmp_lt_f32_sdwa (DWORD) as supported, decoded unlowered SDWA compares (v_cmp_gt_u32_sdwa with WORD_1 and v_cmpx_eq_f32_sdwa) as opcode_recognized_translator_rejected without <unsupported SDWA>, and unsupported 64-bit SDWA fallback as rejected.

Local verification

  • python -B tests/rdna2_tools_check.py: Ran 83 tests ? OK (skipped=3) (LLVM_LIB not installed locally; LLVM round-trip runs in CI).
  • Cross-checked disasm_rdna2 against all 1,712 wave32 vectors in LLVM 15.0.7 gfx10_asm_vopc_sdwa.s and all 1,504 vectors in gfx10_asm_vopcx.s (3,216 / 3,216 exact matches, 0 mismatches).
  • python -B -m py_compile tools/disasm_rdna2.py tests/rdna2_tools_check.py: exit 0.

Disclosure

  • AI-assisted: yes (implementation, golden-vector cross-check, and tests written with AI assistance and verified locally).
  • Clean-room synthetic inputs only; no retail binaries, shaders, keys, or logs.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6567335859 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/980). Originally posted by [Batushn](https://github.com/Batushn) on 2026-11-23T19:39:42Z. --- ## Summary Refs #938 (step 3: VOPC SDWA decoding). Previously, `tools/disasm_rdna2.py` recognized the 8-byte length of VOPC instructions with `src0 == 249` (SDWA) but returned a placeholder `vopc_sdwa` / `<unsupported SDWA>` record instead of decoding the GFX10 `VOP_SDWA9Be` extension word. This PR adds `_decode_vopc_sdwa()` in `tools/disasm_rdna2.py` to decode GFX10 wave32 `VOPC` (`v_cmp_*_sdwa`) and `VOPCX` (`v_cmpx_*_sdwa`) SDWA instructions in LLVM 15 syntax: - Decodes `sdst` / `sdst_en` (`Inst{47:40}`): `vcc_lo` when `sdst_en == 0`, scalar register via `decode_s_reg(sdst)` when `sdst_en == 1`, and omits destination for `v_cmpx_*_sdwa` (`EmitDst = 0`). - Decodes `src0` (`Inst{39:32}` + `src0_sgpr` `Inst{55}`) and `src1` (`Inst{16:9}` + `src1_sgpr` `Inst{63}`) as VGPR or scalar/special register. - Applies float (`-`, `|...|`, `-|...|`) vs integer (`sext(...)`) modifiers matching LLVM 15's `VOPC_Profile` / `VOPC_Class_Profile` rules (`v_cmp_class_f32_sdwa` / `v_cmp_class_f16_sdwa` use float modifiers on `src0` and `sext` on `src1`). - Formats `src0_sel` (`Inst{50:48}`) and `src1_sel` (`Inst{58:56}`) over `BYTE_0..BYTE_3`, `WORD_0..WORD_1`, `DWORD`. - Preserves clean fallback (`vopc_sdwa` / `<unsupported SDWA>`) for 64-bit VOPC opcodes, unknown opcodes, or invalid `sel == 7`, and preserves `vopc_truncated` for truncated 4-byte prefixes. ## Tests - Updated `TestRdna2Disasm.test_vopc_opcode_table_synthetic_forms` for the decoded `v_cmpx_eq_f32_sdwa -v1, v2 src0_sel:DWORD src1_sel:DWORD` fixture. - Added `TestRdna2Disasm.test_vopc_sdwa_decoding` with 34 independent GFX10 wave32 golden vectors from LLVM 15.0.7 (`gfx10_asm_vopc_sdwa.s` and `gfx10_asm_vopcx.s`), `src1_sgpr=1`, and negative/boundary controls (`f64` fallback, invalid `sel == 7`, 4-byte truncation). - Added `TestRdna2Disasm.test_vopc_sdwa_llvm_round_trip` assembling and round-tripping 33 single-field VOPC/VOPCX SDWA variants through LLVM 15 `llvm-mc` + `llvm-objcopy` + `libLLVM` (runs in the `Assemble and translate gfx1013 fixtures` CI job). - Added `TestRdna2Scanner.test_binary_scan_recognizes_vopc_sdwa` verifying binary shader scans classify decoded `v_cmp_lt_f32_sdwa` (DWORD) as supported, decoded unlowered SDWA compares (`v_cmp_gt_u32_sdwa` with `WORD_1` and `v_cmpx_eq_f32_sdwa`) as `opcode_recognized_translator_rejected` without `<unsupported SDWA>`, and unsupported 64-bit SDWA fallback as rejected. ## Local verification - `python -B tests/rdna2_tools_check.py`: `Ran 83 tests ? OK (skipped=3)` (`LLVM_LIB` not installed locally; LLVM round-trip runs in CI). - Cross-checked `disasm_rdna2` against all 1,712 wave32 vectors in LLVM 15.0.7 `gfx10_asm_vopc_sdwa.s` and all 1,504 vectors in `gfx10_asm_vopcx.s` (`3,216 / 3,216` exact matches, `0` mismatches). - `python -B -m py_compile tools/disasm_rdna2.py tests/rdna2_tools_check.py`: exit 0. ## Disclosure - AI-assisted: yes (implementation, golden-vector cross-check, and tests written with AI assistance and verified locally). - Clean-room synthetic inputs only; no retail binaries, shaders, keys, or logs.
upstream-sync closed this pull request 2026-11-24 06:45:41 +00:00
Leyukaka commented 2026-11-24 06:49:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-23T20:05:12Z.


Review from reading the diff against main (not built or run here).

Two cases in _decode_vopc_sdwa with the SGPR bit set:

  1. Only 249, 250 and 255 are refused. Codes 209-234 fall through decode_s_reg to its final return f"s{reg_id}", so for example f904887dd2868606 (v_cmp_gt_u32, src0 code 210) prints s210, which is not a register.
  2. A lone neg on an inline constant goes through _format_operand_modifiers and prints -0.5 (for example f904027cf0869606, v_cmp_lt_f32 with src0 0.5 and neg). The file already notes, near the interpolation decoder, that LLVM spells a lone negation of a numeric operand as neg(...); if LLVM accepts this operand, -0.5 would read as the constant -0.5 rather than neg(0.5).

I have not run LLVM 15 on these words, so the exact LLVM output is worth confirming. The round-trip list has only s1 and m0 as SGPR-bit sources, which is where both cases sit.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7112535663 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/980#issuecomment-7112535663). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-23T20:05:12Z. --- Review from reading the diff against `main` (not built or run here). Two cases in `_decode_vopc_sdwa` with the SGPR bit set: 1. Only 249, 250 and 255 are refused. Codes 209-234 fall through `decode_s_reg` to its final `return f"s{reg_id}"`, so for example `f904887dd2868606` (`v_cmp_gt_u32`, src0 code 210) prints `s210`, which is not a register. 2. A lone neg on an inline constant goes through `_format_operand_modifiers` and prints `-0.5` (for example `f904027cf0869606`, `v_cmp_lt_f32` with src0 0.5 and neg). The file already notes, near the interpolation decoder, that LLVM spells a lone negation of a numeric operand as `neg(...)`; if LLVM accepts this operand, `-0.5` would read as the constant -0.5 rather than `neg(0.5)`. I have not run LLVM 15 on these words, so the exact LLVM output is worth confirming. The round-trip list has only `s1` and `m0` as SGPR-bit sources, which is where both cases sit.
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!973
No description provided.