shader: decode 9-bit VOP SRC0 operands correctly in disasm_rdna2 #242

Merged
Vonsek merged 1 commit from upstream-pr/245 into main 2026-11-21 19:14:31 +00:00
Vonsek commented 2026-11-21 19:09:46 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T19:09:46Z.


Change

Fix 9-bit VOP SRC0 operand decoding in tools/disasm_rdna2.py (decode_v_reg).

Per the AMD RDNA 2 / GFX10 ISA, a 9-bit VOP1/VOP2 SRC0 field encodes:

  • 0..255: SGPRs, special scalar registers (vcc_lo, exec_lo, m0, null), inline constants (0..64, -1..-16, 0.5..-4.0), and 255 (32-bit literal);
  • 256..511: VGPRs v0..v255 (reg_id - 256).

Previously, decode_v_reg had these two halves swapped (<= 255 decoded as v{reg_id} and >= 256 passed to decode_s_reg(reg_id - 256)), causing e.g. v_mov_b32_e32 v0, v1 (0103007e) to disassemble as v_mov_b32_e32 v0, s1 and v_mov_b32_e32 v2, 1.0 (f202047e) to disassemble as v_mov_b32_e32 v2, v242.

tests/rdna2_tools_check.py adds:

  • VOP1 (v_mov_b32_e32) and VOP2 (v_add_f32_e32) golden vectors covering VGPR (v1), SGPR (s1), and inline constants (1.0, 0.5, 0);
  • v_mov_b32_e32 VGPR/SGPR/inline-constant instructions to test_llvm_comparison with full assembly operand checks against LLVM 15 (llvm-mc -mcpu=gfx1013 / libLLVM) in CI.

Verification

Tested on Windows 11 x64, Python 3.12.10, at commit 644aa51:

  • Before the fix in tools/disasm_rdna2.py, rdna2_tools_check fails on the first VOP1 golden vector:
    ctest --preset dev --no-tests=error -R '^rdna2_tools_check$' -V
    AssertionError: 'v_mov_b32_e32 v0, s1' != 'v_mov_b32_e32 v0, v1' : Mismatched assembly for 0103007e
    1/1 Test #97: rdna2_tools_check ................***Failed    0.75 sec
    
  • After the fix:
    ctest --preset dev --no-tests=error -R '^rdna2_tools_check$' -V
    Ran 17 tests in 0.499s
    OK (skipped=1)
    1/1 Test #97: rdna2_tools_check ................   Passed    0.65 sec
    
    (test_llvm_comparison is skipped locally because LLVM_LIB is not installed on this Windows host; it runs in the Ubuntu Assemble and translate gfx1013 fixtures CI job.)

Evidence and follow-up

All test vectors are original synthetic encodings and llvm-mc source instructions.

This PR fixes only 9-bit SRC0 decoding (decode_v_reg). Separate follow-up: several opcodes in VOP2_OPS in tools/disasm_rdna2.py also need to be aligned with GFX10/RDNA 2 opcode numbers and verified against LLVM 15.

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.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6533203970 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/245). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T19:09:46Z. --- ## Change Fix 9-bit VOP `SRC0` operand decoding in `tools/disasm_rdna2.py` (`decode_v_reg`). Per the AMD RDNA 2 / GFX10 ISA, a 9-bit VOP1/VOP2 `SRC0` field encodes: - `0..255`: SGPRs, special scalar registers (`vcc_lo`, `exec_lo`, `m0`, `null`), inline constants (`0..64`, `-1..-16`, `0.5..-4.0`), and `255` (32-bit literal); - `256..511`: VGPRs `v0..v255` (`reg_id - 256`). Previously, `decode_v_reg` had these two halves swapped (`<= 255` decoded as `v{reg_id}` and `>= 256` passed to `decode_s_reg(reg_id - 256)`), causing e.g. `v_mov_b32_e32 v0, v1` (`0103007e`) to disassemble as `v_mov_b32_e32 v0, s1` and `v_mov_b32_e32 v2, 1.0` (`f202047e`) to disassemble as `v_mov_b32_e32 v2, v242`. `tests/rdna2_tools_check.py` adds: - VOP1 (`v_mov_b32_e32`) and VOP2 (`v_add_f32_e32`) golden vectors covering VGPR (`v1`), SGPR (`s1`), and inline constants (`1.0`, `0.5`, `0`); - `v_mov_b32_e32` VGPR/SGPR/inline-constant instructions to `test_llvm_comparison` with full assembly operand checks against LLVM 15 (`llvm-mc -mcpu=gfx1013` / `libLLVM`) in CI. ## Verification Tested on Windows 11 x64, Python 3.12.10, at commit `644aa51`: - Before the fix in `tools/disasm_rdna2.py`, `rdna2_tools_check` fails on the first VOP1 golden vector: ```text ctest --preset dev --no-tests=error -R '^rdna2_tools_check$' -V AssertionError: 'v_mov_b32_e32 v0, s1' != 'v_mov_b32_e32 v0, v1' : Mismatched assembly for 0103007e 1/1 Test #97: rdna2_tools_check ................***Failed 0.75 sec ``` - After the fix: ```text ctest --preset dev --no-tests=error -R '^rdna2_tools_check$' -V Ran 17 tests in 0.499s OK (skipped=1) 1/1 Test #97: rdna2_tools_check ................ Passed 0.65 sec ``` (`test_llvm_comparison` is skipped locally because `LLVM_LIB` is not installed on this Windows host; it runs in the Ubuntu `Assemble and translate gfx1013 fixtures` CI job.) ## Evidence and follow-up All test vectors are original synthetic encodings and `llvm-mc` source instructions. This PR fixes only 9-bit `SRC0` decoding (`decode_v_reg`). Separate follow-up: several opcodes in `VOP2_OPS` in `tools/disasm_rdna2.py` also need to be aligned with GFX10/RDNA 2 opcode numbers and verified against LLVM 15. ## 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. - [x] I did not include game files, dumps, distribution links or secrets.
upstream-sync closed this pull request 2026-11-24 06:42:00 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 06:42:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T19:15:17Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 644aa51cca

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6007614670 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/245#pullrequestreview-6007614670). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T19:15:17Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `644aa51cca` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". </details>
chatgpt-codex-connector[bot commented 2026-11-24 06:47:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T19:12:02Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T19:15:19.086338Z 644aa51 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7067839547 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/245#issuecomment-7067839547). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T19:12:02Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"644aa51cca3a8b67691060754562b83f70b3c0e3","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-21T19:15:19.086338Z">2026-11-21T19:15:19.086338Z</relative-time> | `644aa51` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
chatgpt-codex-connector[bot commented 2026-11-24 06:50:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T19:15:17Z.

Code review location: tests/rdna2_tools_check.py; line 130

@@ -118,6 +118,16 @@ def test_golden_vectors(self):
             ("000182be", "s_mov_b64", "s_mov_b64 s2, s0"),
             ("00008080", "s_sub_u32", "s_sub_u32 s0, s0, s0"),
             ("0000027e", "v_nop", "v_nop"),
+            # VOP1 9-bit SRC0: 0..255 scalar/constant, 256..511 VGPR
+            ("0103007e", "v_mov_b32_e32", "v_mov_b32_e32 v0, v1"),
+            ("0102007e", "v_mov_b32_e32", "v_mov_b32_e32 v0, s1"),
+            ("f202047e", "v_mov_b32_e32", "v_mov_b32_e32 v2, 1.0"),
+            ("f002067e", "v_mov_b32_e32", "v_mov_b32_e32 v3, 0.5"),
+            ("8002087e", "v_mov_b32_e32", "v_mov_b32_e32 v4, 0"),
+            # VOP2 9-bit SRC0 (VGPR vs SGPR vs inline constant)
+            ("01050602", "v_add_f32_e32", "v_add_f32_e32 v3, v1, v2"),
+            ("01040602", "v_add_f32_e32", "v_add_f32_e32 v3, s1, v2"),
+            ("f0040602", "v_add_f32_e32", "v_add_f32_e32 v3, 0.5, v2"),

P2 Badge Keep incorrect VOP2 opcodes out of new golden expectations

For the repository’s gfx1013 target, these three vectors encode v_cndmask_b32_e32, not v_add_f32_e32. Local LLVM 20 decodes 01050602 as v_cndmask_b32_e32 v3, v1, v2, vcc_lo, while the stated addition assembles to 01050606. Although the opcode-table defect predates this patch, these new full-assembly assertions make that defect a required test result and reject ISA-correct output. The LLVM comparison still passes because its new cases cover only VOP1. Isolate the SRC0 assertions from the deferred opcode-table defect, or use independently verified VOP2 expectations.

AGENTS.md reference: AGENTS.md:L41-L41

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4654532921 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/245#discussion_r4654532921). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T19:15:17Z. **Code review location:** `tests/rdna2_tools_check.py`; line 130 ~~~~diff @@ -118,6 +118,16 @@ def test_golden_vectors(self): ("000182be", "s_mov_b64", "s_mov_b64 s2, s0"), ("00008080", "s_sub_u32", "s_sub_u32 s0, s0, s0"), ("0000027e", "v_nop", "v_nop"), + # VOP1 9-bit SRC0: 0..255 scalar/constant, 256..511 VGPR + ("0103007e", "v_mov_b32_e32", "v_mov_b32_e32 v0, v1"), + ("0102007e", "v_mov_b32_e32", "v_mov_b32_e32 v0, s1"), + ("f202047e", "v_mov_b32_e32", "v_mov_b32_e32 v2, 1.0"), + ("f002067e", "v_mov_b32_e32", "v_mov_b32_e32 v3, 0.5"), + ("8002087e", "v_mov_b32_e32", "v_mov_b32_e32 v4, 0"), + # VOP2 9-bit SRC0 (VGPR vs SGPR vs inline constant) + ("01050602", "v_add_f32_e32", "v_add_f32_e32 v3, v1, v2"), + ("01040602", "v_add_f32_e32", "v_add_f32_e32 v3, s1, v2"), + ("f0040602", "v_add_f32_e32", "v_add_f32_e32 v3, 0.5, v2"), ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Keep incorrect VOP2 opcodes out of new golden expectations** For the repository’s `gfx1013` target, these three vectors encode `v_cndmask_b32_e32`, not `v_add_f32_e32`. Local LLVM 20 decodes `01050602` as `v_cndmask_b32_e32 v3, v1, v2, vcc_lo`, while the stated addition assembles to `01050606`. Although the opcode-table defect predates this patch, these new full-assembly assertions make that defect a required test result and reject ISA-correct output. The LLVM comparison still passes because its new cases cover only VOP1. Isolate the SRC0 assertions from the deferred opcode-table defect, or use independently verified VOP2 expectations. AGENTS.md reference: [AGENTS.md:L41-L41](https://github.com/R0Y00/Xbox2Windows/blob/644aa51cca3a8b67691060754562b83f70b3c0e3/AGENTS.md#L41-L41) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
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!242
No description provided.