Lower v_xor3_b32 in the startup gfx2hlsl translator #2090

Merged
Ybucaille merged 1 commit from upstream-pr/2097 into main 2026-11-25 00:54:23 +00:00
Ybucaille commented 2026-11-25 00:14:06 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ybucaille on 2026-11-25T00:14:06Z.


Item I of #2023.

Summary

v_xor3_b32 vD, a, b, c (RDNA 2 VOP3, D = S0 ^ S1 ^ S2) is added to the three-source integer table in tools/startup/gfx2hlsl.py, next to v_or3_b32. It lowers to a ^ b ^ c. Source modifiers, clamp, op_sel and a wrong operand count stay refused.

Semantics source

LLVM 15 AMDGPU VOP3 definition and the RDNA 2 ISA reference: D.u = S0.u ^ S1.u ^ S2.u. Same semantics as the compute lowering in #1573.

Fixture and controls

tests/startup_gfx2hlsl_bit_alu_check.py gains v_xor3_b32 (existing CMake and windows.yml wiring already runs it, including the WARP and hardware draws):

  • Source-built pixel fixture, words recorded from llvm-mc (no retail bytes).
  • 729 grid inputs against an independent reference written as x ^ y ^ z.
  • Three draw sets where the three sources differ in every byte (0x13579bdf, 0x2468ace0, 0xfedcba98 and rotations), plus zero, all ones and a repeated source.
  • Negative control: a mutation that drops the third operand must read src0 ^ src1, in the evaluator and in the draw.
  • Refusal controls: clamp, -v, |v|, op_sel, two or five operands.

Repro

python -B tests/startup_gfx2hlsl_bit_alu_check.py
python -B tests/startup_gfx2hlsl_bit_alu_check.py binary llvm-mc-15

Results (Linux)

  • Controls pass, including v_xor3_b32: 729 inputs match and the mutation controls.
  • On origin/main the check stops with Unsupported: v_xor3_b32.
  • With the lowering changed to {0} ^ {1}, the check fails on 729 inputs match the reference.
  • The xor3 body, prologue, export and vertex words match /usr/bin/llvm-mc (version 23.1.5).
  • All tests/startup_gfx2hlsl_*_check.py and tests/startup_translator_check.py pass (no-argument mode), tests/docs_links_check.py passes, git diff --check is clean.

Not run

  • The D3D12 WARP and hardware draws (startup_gfx2hlsl_bit_alu_warp / _hardware) do not run on Linux.
  • binary as a whole with llvm-mc 23 fails on the existing v_bcnt_u32_b32 words (unrelated, the CI uses llvm-mc 15); not run with llvm-mc 15.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6594122772 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2097). Originally posted by [Ybucaille](https://github.com/Ybucaille) on 2026-11-25T00:14:06Z. --- Item I of #2023. ## Summary `v_xor3_b32 vD, a, b, c` (RDNA 2 VOP3, `D = S0 ^ S1 ^ S2`) is added to the three-source integer table in `tools/startup/gfx2hlsl.py`, next to `v_or3_b32`. It lowers to `a ^ b ^ c`. Source modifiers, `clamp`, `op_sel` and a wrong operand count stay refused. ## Semantics source LLVM 15 AMDGPU VOP3 definition and the RDNA 2 ISA reference: `D.u = S0.u ^ S1.u ^ S2.u`. Same semantics as the compute lowering in #1573. ## Fixture and controls `tests/startup_gfx2hlsl_bit_alu_check.py` gains `v_xor3_b32` (existing CMake and `windows.yml` wiring already runs it, including the WARP and hardware draws): - Source-built pixel fixture, words recorded from llvm-mc (no retail bytes). - 729 grid inputs against an independent reference written as `x ^ y ^ z`. - Three draw sets where the three sources differ in every byte (`0x13579bdf`, `0x2468ace0`, `0xfedcba98` and rotations), plus zero, all ones and a repeated source. - Negative control: a mutation that drops the third operand must read `src0 ^ src1`, in the evaluator and in the draw. - Refusal controls: `clamp`, `-v`, `|v|`, `op_sel`, two or five operands. ## Repro ``` python -B tests/startup_gfx2hlsl_bit_alu_check.py python -B tests/startup_gfx2hlsl_bit_alu_check.py binary llvm-mc-15 ``` ## Results (Linux) - Controls pass, including `v_xor3_b32: 729 inputs match` and the mutation controls. - On `origin/main` the check stops with `Unsupported: v_xor3_b32`. - With the lowering changed to `{0} ^ {1}`, the check fails on `729 inputs match the reference`. - The xor3 body, prologue, export and vertex words match `/usr/bin/llvm-mc` (version 23.1.5). - All `tests/startup_gfx2hlsl_*_check.py` and `tests/startup_translator_check.py` pass (no-argument mode), `tests/docs_links_check.py` passes, `git diff --check` is clean. ## Not run - The D3D12 WARP and hardware draws (`startup_gfx2hlsl_bit_alu_warp` / `_hardware`) do not run on Linux. - `binary` as a whole with llvm-mc 23 fails on the existing `v_bcnt_u32_b32` words (unrelated, the CI uses llvm-mc 15); not run with llvm-mc 15. AI-assisted.
upstream-sync closed this pull request 2026-11-25 01:01:39 +00:00
ChazY11 commented 2026-11-25 01:02:06 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T00:34:11Z.


Four mutations on the new table row, all caught — and the arity entry is the one that matters most

out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_bit_alu_check.py
the same forms without a modifier or operand error translate: ok
modifiers refused: ok
wrong operand count refused: ok                                exit 0
mutation of the v_xor3_b32 row result
the expression copied from v_or3_b32 (a | b | c) caught
only the first two sources XORed ((a ^ b), third dropped) caught
arity 3 → 2 caught
second term made an AND ((a ^ b) & c) caught

The third is the one I would call load-bearing. v_xor3_b32 is a three-source VOP3 with a N field on RDNA 2, so a row that declares arity 3 lets
v_xor3_b32 v5, v1, v2 (two sources) reach the emit path with a missing operand instead of being refused — and the table is the only place that says how
many sources an opcode takes. Your fixture catches it, which means the count is pinned rather than implied by the expression's shape.

One thing I checked because it is what my own open PR is about

#2104 sweeps every op_* handler with operand shapes no decoder produces and fails if a handler answers with anything other than Unsupported. Against
this branch, v_xor3_b32 behaves, because the table-driven emit refuses a count mismatch before indexing. So this PR adds a handler that is compliant with
that ratchet rather than one more PENDING entry — which is the direction the list should move.

A note on the docs/experiments.md line

The one-line change there is the part a later reader will use to decide whether v_xor3_b32 is covered, so it is worth making it say the same thing the
fixture does: which forms are accepted, and that modifiers are refused. Right now it follows the surrounding style of naming the opcode only. Not a
blocker — just the cheapest place to record it.

What the fixture does not establish

That the emitted a ^ b ^ c matches the ISA's three-source XOR on a device. The parity of a three-input XOR is the same under any association, so the risk
here is lower than for med3, but the operand order is still taken on trust from the disassembly, not measured.

AI-assisted; the check and the four mutations were run locally on Windows 11 build 26300.9974.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7148647895 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2097#issuecomment-7148647895). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-25T00:34:11Z. --- ## Four mutations on the new table row, all caught — and the arity entry is the one that matters most ```powershell out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_bit_alu_check.py the same forms without a modifier or operand error translate: ok modifiers refused: ok wrong operand count refused: ok exit 0 ``` | mutation of the `v_xor3_b32` row | result | |---|---| | the expression copied from `v_or3_b32` (`a \| b \| c`) | **caught** | | only the first two sources XORed (`(a ^ b)`, third dropped) | **caught** | | arity `3` → `2` | **caught** | | second term made an AND (`(a ^ b) & c`) | **caught** | The third is the one I would call load-bearing. `v_xor3_b32` is a three-source VOP3 with a `N` field on RDNA 2, so a row that declares arity 3 lets `v_xor3_b32 v5, v1, v2` (two sources) reach the emit path with a missing operand instead of being refused — and the table is the only place that says how many sources an opcode takes. Your fixture catches it, which means the count is pinned rather than implied by the expression's shape. ## One thing I checked because it is what my own open PR is about `#2104` sweeps every `op_*` handler with operand shapes no decoder produces and fails if a handler answers with anything other than `Unsupported`. Against this branch, `v_xor3_b32` behaves, because the table-driven emit refuses a count mismatch before indexing. So this PR adds a handler that is compliant with that ratchet rather than one more `PENDING` entry — which is the direction the list should move. ## A note on the `docs/experiments.md` line The one-line change there is the part a later reader will use to decide whether `v_xor3_b32` is covered, so it is worth making it say the same thing the fixture does: which forms are accepted, and that modifiers are refused. Right now it follows the surrounding style of naming the opcode only. Not a blocker — just the cheapest place to record it. ## What the fixture does not establish That the emitted `a ^ b ^ c` matches the ISA's three-source XOR on a device. The parity of a three-input XOR is the same under any association, so the risk here is lower than for `med3`, but the operand order is still taken on trust from the disassembly, not measured. AI-assisted; the check and the four mutations were run locally on Windows 11 build 26300.9974.
Its3rr0rsWRLD commented 2026-11-25 01:02:07 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Its3rr0rsWRLD on 2026-11-25T00:39:35Z.


Windows run of the requested draws for #2097, tested at head 09238b61aaf61d5203b3aa2e638ba782197bf7cc.

Environment

  • Windows 11 26H2, build 26300.9974
  • Hardware adapter: NVIDIA GeForce RTX 4070 Ti, driver 32.0.16.1088
  • WARP: Microsoft Basic Render Driver, d3d10warp.dll 10.0.26100.9818
  • dev preset, MSVC; built only offscreen_check and the tests' dependencies

Command

ctest --preset dev --no-tests=error -R "^startup_(gfx2hlsl_bit_alu|vertex_fetch_formats)_(controls|warp|hardware)$" --output-on-failure

Results: 6/6 passed

Test Result
startup_gfx2hlsl_bit_alu_controls pass
startup_gfx2hlsl_bit_alu_warp pass
startup_gfx2hlsl_bit_alu_hardware pass
startup_vertex_fetch_formats_controls pass
startup_vertex_fetch_formats_warp pass
startup_vertex_fetch_formats_hardware pass

Run by Claude (AI-assisted).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7148742422 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2097#issuecomment-7148742422). Originally posted by [Its3rr0rsWRLD](https://github.com/Its3rr0rsWRLD) on 2026-11-25T00:39:35Z. --- Windows run of the requested draws for #2097, tested at head `09238b61aaf61d5203b3aa2e638ba782197bf7cc`. **Environment** - Windows 11 26H2, build 26300.9974 - Hardware adapter: NVIDIA GeForce RTX 4070 Ti, driver 32.0.16.1088 - WARP: Microsoft Basic Render Driver, d3d10warp.dll 10.0.26100.9818 - `dev` preset, MSVC; built only `offscreen_check` and the tests' dependencies **Command** ``` ctest --preset dev --no-tests=error -R "^startup_(gfx2hlsl_bit_alu|vertex_fetch_formats)_(controls|warp|hardware)$" --output-on-failure ``` **Results: 6/6 passed** | Test | Result | |---|---| | `startup_gfx2hlsl_bit_alu_controls` | pass | | `startup_gfx2hlsl_bit_alu_warp` | pass | | `startup_gfx2hlsl_bit_alu_hardware` | pass | | `startup_vertex_fetch_formats_controls` | pass | | `startup_vertex_fetch_formats_warp` | pass | | `startup_vertex_fetch_formats_hardware` | pass | Run by Claude (AI-assisted).
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!2090
No description provided.