startup: lower 16-bit integer VOPC compares in gfx2hlsl (Part of #1723) #2361

Merged
legacy-code-archaeologist merged 1 commit from upstream-pr/2369 into main 2026-11-25 14:27:23 +00:00
legacy-code-archaeologist commented 2026-11-25 13:54:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-25T13:54:56Z.


Change

tools/startup/gfx2hlsl.py now lowers the 16-bit integer VOPC compares v_cmp_{lt,eq,le,gt,ne,ge}_{i16,u16} and v_cmpx_{lt,eq,le,gt,ne,ge}_{i16,u16} in the _e32 and _e64 encodings (48 forms). Before this change every one of them was refused as an unknown instruction. Part of #1723 (claimed in https://github.com/R0Y00/Xbox2Windows/issues/1723#issuecomment-7161903409).

  • Each source is bits 15:0 of the operand, compared as S0.i16 / S0.u16 (AMD RDNA 2 ISA guide). An i16 register reads as asint(x << 16u) >> 16u, a u16 register as x & 0xffffu. LLVM 15 selects v_cmp_lt_i16_e32 on whole VGPRs for icmp slt i16 of truncated values, which matches this reading.
  • Sources: a VGPR, an SGPR, an inline integer from -16 to 64, or a literal up to 0xffff.
  • Destinations (vcc, an SGPR lane mask, or EXEC for v_cmpx) use the existing 32-bit integer compare path unchanged.
  • Refused: inline float constants (they are binary16 on 16-bit operands), wider literals, register ranges, vcc/exec/m0 as a source, op_sel, clamp, the NEG/ABS bits of the _e64 form (checked in the raw word, since the disassembler prints NEG on inline 1 as -1), and the SDWA forms (tools/pixel_aot.py keeps its own lowering of those).

Shared interface: none. No open PR adds these forms to gfx2hlsl; I checked the + lines of every open PR that touches tools/startup/gfx2hlsl.py.

Verification

All runs: 43608f2e plus this commit, Windows 11 10.0.26100, debug layer unavailable.

Check Result
cmake --build --preset dev 279/279, exit 0
ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_' -j 2 119/119 passed
ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_cmp16_' -V (default hardware = NVIDIA Quadro M1000M, driver 32.0.15.7371) 3/3 passed
same with XBOX2WINDOWS_ADAPTER=Intel (Intel HD Graphics 530, driver 31.0.101.2111) 3/3 passed
same with XBOX2WINDOWS_ADAPTER=Quadro 3/3 passed
WARP (Microsoft Basic Render Driver 10.0.26100.8972), inside the runs above passed
python -B tests/startup_gfx2hlsl_cmp16_check.py binary <llvm-mc> <llvm-objcopy> PASS (see note)
tests/startup_gfx2hlsl_vopc_sdwa_check.py, form_coverage_check.py, docs_links_check.py, bidi_controls_check.py, rdna2_tools_check.py all exit 0 (rdna2_tools: OK, 19 skipped, same as before the change)

Binary mode note: the official LLVM 15.0.7 Windows build ships no llvm-mc. Locally a wrapper passed the llvm-mc arguments to that build's integrated assembler (clang -cc1as), and its llvm-objcopy extracted .text. The CI LLVM 15 job runs the same mode with llvm-mc-15 / llvm-objcopy-15; that run has not happened yet.

Negative control: the new test file on 417a101c without the translator change stops at the first translated case with Unsupported: v_cmp_eq_i16 (exit 1). In draw mode, two mutated lowerings (i16 read zero-extended, u16 read as the whole word) must each fail against the reference and match their own image. A separate mutation run over the lowering detected 9 of 9 mutations; that scratch script is not part of the PR.

Not covered: no gfx1013 hardware run; the draws check the translated HLSL on desktop adapters against a reference written from the ISA meaning.

Evidence and follow-up

Fixtures are source-built: synthetic VOPC words, checked against LLVM 15 encodings, and three source-built pixel programs (a v_cmpx_le_i16_e32 kill, a v_cmpx_gt_u16_e64 kill, and all six relations of the i16/u16 e32 and e64 forms folded into mask words). No game data.

Design review note: the design went through four rounds of independent critic and readiness review. The last critic round still had two open points (mutant image definition, the s0 that the disassembler prints for an _e64 v_cmpx); I chose to proceed at that point, and both are addressed in the implementation (image(how) per-pixel reference, and a control that writes s0, runs v_cmpx_le_i16_e64 and reads s0 back).

Possible follow-ups (not in this PR, to keep one behavior):

  • destinations() returns ops[0] for every non-s_cmp instruction, so a v_cmpx_*_e64 marks its printed s0, and an _e32 v_cmpx with an SGPR src0 marks that SGPR, as written. This only loses constant/uniform proofs (no wrong value found), and it applies to the 32-bit forms too. A branch test (a v_cmpx in a skipped branch, then a read of s0) would pin it.
  • The destinations() docstring says "Compares write none", which does not match the code above; best fixed together with the item before.
  • Not pinned by a control yet: a 16-bit compare on a VGPR whose high half is unknown after an odd-dmask d16 image load (accepted, since only bits 15:0 are read), and a 16-bit compare inside a branch or exec-masked region (same join path as the i32 forms).
  • Several sibling draw checks (vopc_sdwa, dpp_*, f32_lg, ...) exit 77 on the first capability skip before reporting earlier failures; this PR fixes that only in the new check.

docs: new section "Startup translator: 16-bit integer compares" in docs/experiments.md; AGENTS.md lists the check; CI runs the no-argument mode on Linux and the binary mode in the LLVM 15 job.

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.

This change was AI-assisted (Claude Code), with independent read-only reviews before commit.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6606096216 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2369). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-25T13:54:56Z. --- ## Change `tools/startup/gfx2hlsl.py` now lowers the 16-bit integer VOPC compares `v_cmp_{lt,eq,le,gt,ne,ge}_{i16,u16}` and `v_cmpx_{lt,eq,le,gt,ne,ge}_{i16,u16}` in the `_e32` and `_e64` encodings (48 forms). Before this change every one of them was refused as an unknown instruction. Part of #1723 (claimed in https://github.com/R0Y00/Xbox2Windows/issues/1723#issuecomment-7161903409). - Each source is bits 15:0 of the operand, compared as `S0.i16` / `S0.u16` (AMD RDNA 2 ISA guide). An i16 register reads as `asint(x << 16u) >> 16u`, a u16 register as `x & 0xffffu`. LLVM 15 selects `v_cmp_lt_i16_e32` on whole VGPRs for `icmp slt i16` of truncated values, which matches this reading. - Sources: a VGPR, an SGPR, an inline integer from -16 to 64, or a literal up to `0xffff`. - Destinations (`vcc`, an SGPR lane mask, or EXEC for `v_cmpx`) use the existing 32-bit integer compare path unchanged. - Refused: inline float constants (they are binary16 on 16-bit operands), wider literals, register ranges, `vcc`/`exec`/`m0` as a source, `op_sel`, `clamp`, the NEG/ABS bits of the `_e64` form (checked in the raw word, since the disassembler prints NEG on inline 1 as `-1`), and the SDWA forms (`tools/pixel_aot.py` keeps its own lowering of those). Shared interface: none. No open PR adds these forms to gfx2hlsl; I checked the `+` lines of every open PR that touches `tools/startup/gfx2hlsl.py`. ## Verification All runs: `43608f2e` plus this commit, Windows 11 10.0.26100, debug layer unavailable. | Check | Result | |---|---| | `cmake --build --preset dev` | 279/279, exit 0 | | `ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_' -j 2` | 119/119 passed | | `ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_cmp16_' -V` (default hardware = NVIDIA Quadro M1000M, driver 32.0.15.7371) | 3/3 passed | | same with `XBOX2WINDOWS_ADAPTER=Intel` (Intel HD Graphics 530, driver 31.0.101.2111) | 3/3 passed | | same with `XBOX2WINDOWS_ADAPTER=Quadro` | 3/3 passed | | WARP (Microsoft Basic Render Driver 10.0.26100.8972), inside the runs above | passed | | `python -B tests/startup_gfx2hlsl_cmp16_check.py binary <llvm-mc> <llvm-objcopy>` | PASS (see note) | | `tests/startup_gfx2hlsl_vopc_sdwa_check.py`, `form_coverage_check.py`, `docs_links_check.py`, `bidi_controls_check.py`, `rdna2_tools_check.py` | all exit 0 (rdna2_tools: OK, 19 skipped, same as before the change) | Binary mode note: the official LLVM 15.0.7 Windows build ships no `llvm-mc`. Locally a wrapper passed the `llvm-mc` arguments to that build's integrated assembler (`clang -cc1as`), and its `llvm-objcopy` extracted `.text`. The CI LLVM 15 job runs the same mode with `llvm-mc-15` / `llvm-objcopy-15`; that run has not happened yet. Negative control: the new test file on `417a101c` without the translator change stops at the first translated case with `Unsupported: v_cmp_eq_i16` (exit 1). In draw mode, two mutated lowerings (i16 read zero-extended, u16 read as the whole word) must each fail against the reference and match their own image. A separate mutation run over the lowering detected 9 of 9 mutations; that scratch script is not part of the PR. Not covered: no gfx1013 hardware run; the draws check the translated HLSL on desktop adapters against a reference written from the ISA meaning. ## Evidence and follow-up Fixtures are source-built: synthetic VOPC words, checked against LLVM 15 encodings, and three source-built pixel programs (a `v_cmpx_le_i16_e32` kill, a `v_cmpx_gt_u16_e64` kill, and all six relations of the i16/u16 e32 and e64 forms folded into mask words). No game data. Design review note: the design went through four rounds of independent critic and readiness review. The last critic round still had two open points (mutant image definition, the `s0` that the disassembler prints for an `_e64` `v_cmpx`); I chose to proceed at that point, and both are addressed in the implementation (`image(how)` per-pixel reference, and a control that writes `s0`, runs `v_cmpx_le_i16_e64` and reads `s0` back). Possible follow-ups (not in this PR, to keep one behavior): - `destinations()` returns `ops[0]` for every non-`s_cmp` instruction, so a `v_cmpx_*_e64` marks its printed `s0`, and an `_e32` `v_cmpx` with an SGPR `src0` marks that SGPR, as written. This only loses constant/uniform proofs (no wrong value found), and it applies to the 32-bit forms too. A branch test (a `v_cmpx` in a skipped branch, then a read of `s0`) would pin it. - The `destinations()` docstring says "Compares write none", which does not match the code above; best fixed together with the item before. - Not pinned by a control yet: a 16-bit compare on a VGPR whose high half is unknown after an odd-dmask d16 image load (accepted, since only bits 15:0 are read), and a 16-bit compare inside a branch or exec-masked region (same join path as the i32 forms). - Several sibling draw checks (`vopc_sdwa`, `dpp_*`, `f32_lg`, ...) exit 77 on the first capability skip before reporting earlier failures; this PR fixes that only in the new check. docs: new section "Startup translator: 16-bit integer compares" in `docs/experiments.md`; `AGENTS.md` lists the check; CI runs the no-argument mode on Linux and the binary mode in the LLVM 15 job. ## 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. This change was AI-assisted (Claude Code), with independent read-only reviews before commit. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
tedin7 commented 2026-11-25 14:05:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T13:57:40Z.

Review: COMMENTED


Review of head 5c937b2851f9c8a86951d76a073d4e8d83a9eb88 (comment only, no approval).

Result: no P1, no P2.

What I checked:

  • tools/startup/gfx2hlsl.py: _low16_source reads an i16 register as asint(x << 16u) >> 16u and a u16 register as x & 0xffffu. Both match the RDNA 2 S0.i16 / S0.u16 meaning (bits 15:0 only). Inline integers -16..64 and literals up to 0xffff fold to the right signed or unsigned constant. Float inline constants, wider literals, register ranges, vcc/exec/m0, and SDWA are refused.
  • check_encoding: the NEG/ABS test on the raw VOP3 words (word0 & 0x700, word1 & 0xe0000000) is the right place, because the printed -1 is ambiguous with inline 1 plus NEG.
  • The six relations only (no f/t on 16-bit in gfx10) are enforced before the table lookup. The 32-bit destination and EXEC path is reused unchanged.
  • Sibling wiring is complete: CMakeLists.txt (controls + warp + hardware), windows.yml (both lists), AGENTS.md, docs/experiments.md.
  • Title and body are neutral, with a Part of #1723 line and a Verification block.

Commands run locally in a worktree of this head:

  • python3 -B tests/startup_gfx2hlsl_cmp16_check.py -> PASS (controls, 71 refusals).
  • python3 tests/docs_links_check.py -> Checked 19 Markdown files and 460 links.
  • python3 tests/bidi_controls_check.py -> Checked 1646 ... no bidirectional controls.
  • git diff --check origin/main...HEAD -> clean.
  • Mutation 1: make the i16 read zero-extended -> test fails (AssertionError: ('K', 'no sext', 0)).
  • Mutation 2: widen the literal limit to 0x1ffff -> test reports FAIL in the refusals section.
  • Both mutations reverted; tree clean.

Not run:

  • The binary mode (needs llvm-mc-15, not installed here).
  • The draw mode and a Windows VM run. At review time the Windows CI jobs were still pending. The PR body reports WARP and hardware draws passed. The Windows CI result should be green before merging.

Nit (not blocking): none.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6058939874 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2369#pullrequestreview-6058939874). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T13:57:40Z. **Review:** COMMENTED --- Review of head `5c937b2851f9c8a86951d76a073d4e8d83a9eb88` (comment only, no approval). **Result: no P1, no P2.** What I checked: - `tools/startup/gfx2hlsl.py`: `_low16_source` reads an i16 register as `asint(x << 16u) >> 16u` and a u16 register as `x & 0xffffu`. Both match the RDNA 2 `S0.i16` / `S0.u16` meaning (bits 15:0 only). Inline integers -16..64 and literals up to `0xffff` fold to the right signed or unsigned constant. Float inline constants, wider literals, register ranges, `vcc`/`exec`/`m0`, and SDWA are refused. - `check_encoding`: the NEG/ABS test on the raw VOP3 words (`word0 & 0x700`, `word1 & 0xe0000000`) is the right place, because the printed `-1` is ambiguous with inline 1 plus NEG. - The six relations only (no `f`/`t` on 16-bit in gfx10) are enforced before the table lookup. The 32-bit destination and EXEC path is reused unchanged. - Sibling wiring is complete: `CMakeLists.txt` (controls + warp + hardware), `windows.yml` (both lists), `AGENTS.md`, `docs/experiments.md`. - Title and body are neutral, with a `Part of #1723` line and a `Verification` block. Commands run locally in a worktree of this head: - `python3 -B tests/startup_gfx2hlsl_cmp16_check.py` -> `PASS` (controls, 71 refusals). - `python3 tests/docs_links_check.py` -> `Checked 19 Markdown files and 460 links.` - `python3 tests/bidi_controls_check.py` -> `Checked 1646 ... no bidirectional controls.` - `git diff --check origin/main...HEAD` -> clean. - Mutation 1: make the i16 read zero-extended -> test fails (`AssertionError: ('K', 'no sext', 0)`). - Mutation 2: widen the literal limit to `0x1ffff` -> test reports `FAIL` in the refusals section. - Both mutations reverted; tree clean. Not run: - The `binary` mode (needs `llvm-mc-15`, not installed here). - The `draw` mode and a Windows VM run. At review time the Windows CI jobs were still pending. The PR body reports WARP and hardware draws passed. The Windows CI result should be green before merging. Nit (not blocking): none. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 15:01:47 +00:00
RavenCurseBurg commented 2026-11-25 15:01:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T14:25:54Z.


I reproduced the follow-up you listed for the sibling draw checks. On current main, a recorded comparison failure followed by renderer exit 77 returns 77 in the VOPC SDWA and DPP family. I’m taking the test-harness follow-up separately: verify the ordering in each affected accumulator, preserve an ordinary capability skip, and add a regression check.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7165267447 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2369#issuecomment-7165267447). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-25T14:25:54Z. --- I reproduced the follow-up you listed for the sibling draw checks. On current main, a recorded comparison failure followed by renderer exit 77 returns 77 in the VOPC SDWA and DPP family. I’m taking the test-harness follow-up separately: verify the ordering in each affected accumulator, preserve an ordinary capability skip, and add a regression check.
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!2361
No description provided.