xshader: lower fourteen ordinary VOP3 integer forms #95

Manually merged
github merged 1 commit from gh-pr/95/head into gh-pr/95/base 2026-11-26 06:30:49 +00:00
Owner

@⁠JohnVonWells on GitHub · 2026-11-24 22:01 UTC · original
xshader/ordinary-integer-vop3 → main · +2250 −5 · 6 files · 1 commits · merged 2026-11-24 22:05 UTC

A synthetic sweep over the decoder's ALU opcode table (one instruction with ordinary register operands per opcode, no shader inputs) showed about 95 decodable instructions the translator refuses as unsupported vector op. This PR takes the group with exact integer semantics, which is the easiest to verify:

Kind Instructions
16-bit, writes one destination half v_add_nc_i16, v_sub_nc_i16, v_mad_u16, v_mad_i16, v_min3_u16, v_max3_u16, v_med3_u16, v_min3_i16, v_max3_i16, v_med3_i16
32-bit result v_add_nc_i32, v_sub_nc_i32, v_mad_u32_u16, v_mad_i32_i16

Lowering

  • The 16-bit forms reuse the existing int16 half-select path: op_sel picks the source halves, and op_sel bit 3 picks the destination half. The other half is preserved, as for the existing newer 16-bit forms.
  • Without clamp, the signed add, subtract and multiply-add produce the same bits as the unsigned forms. min3/max3/med3 compare sign-extended halves for _i16.
  • The 32-bit forms are in a new small int32 module. v_mad_u32_u16/v_mad_i32_i16 accept op_sel on the two multiplicands only.
  • Conservative scope: VGPR sources only, compute shaders only. Clamp (saturation), abs, neg and the other op_sel bits are refused, like the existing newer 16-bit forms.

Verification

  • Unit tests decode the LLVM gfx1030 words and check accepted forms, half selection and every refusal.
  • tools/check_ordinary_integer_gpu.py assembles every legal op_sel combination with llvm-mc -mcpu=gfx1030. The result register aliases one source, so destination-half preservation is tested too. The script runs the translated shaders through DXC/DXV and stock Proton, then compares all 384 readback words per dispatch, including the inputs and guard words, with a Python model. Hand-computed values for that model are in tests/test_ordinary_integer_gpu.py.
  • Result on an AMD Radeon RX 6950 XT (1002:73a5, RADV): 154 selector combinations, 2,464 results, 8,448 GPU words, zero mismatches. The receipt is evidence/ordinary-integer-vop3-control.json.
  • The emitter from 5cee10f refuses all 22 test shaders (--baseline). For each instruction, the clamp form and an SGPR-source form are refused.
  • Negative control: I rebuilt the emitter with the signed min3/max3/med3 comparing unsigned. The check then failed at the first v_min3_i16 case, exactly on the inputs with bit 15 set.
  • Unchanged: all 124 shader-compiler tests and all 184 Python tests pass.

Not included: v_cvt_pk_u16_u32 and v_cvt_pk_i16_i32 were refused in the same sweep. I could not independently confirm their saturation behaviour (LLVM does not constant-fold llvm.amdgcn.cvt.pk.*), so they remain refused.

AI-assisted.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NhDbTJdTcjebsL5u7pwFoY

**@⁠JohnVonWells** on GitHub · 2026-11-24 22:01 UTC · [original](https://github.com/brcly/TuxBox/pull/95) `xshader/ordinary-integer-vop3` → `main` · +2250 −5 · 6 files · 1 commits · merged 2026-11-24 22:05 UTC A synthetic sweep over the decoder's ALU opcode table (one instruction with ordinary register operands per opcode, no shader inputs) showed about 95 decodable instructions the translator refuses as `unsupported vector op`. This PR takes the group with exact integer semantics, which is the easiest to verify: | Kind | Instructions | |---|---| | 16-bit, writes one destination half | `v_add_nc_i16`, `v_sub_nc_i16`, `v_mad_u16`, `v_mad_i16`, `v_min3_u16`, `v_max3_u16`, `v_med3_u16`, `v_min3_i16`, `v_max3_i16`, `v_med3_i16` | | 32-bit result | `v_add_nc_i32`, `v_sub_nc_i32`, `v_mad_u32_u16`, `v_mad_i32_i16` | **Lowering** - The 16-bit forms reuse the existing `int16` half-select path: op_sel picks the source halves, and op_sel bit 3 picks the destination half. The other half is preserved, as for the existing newer 16-bit forms. - Without clamp, the signed add, subtract and multiply-add produce the same bits as the unsigned forms. `min3`/`max3`/`med3` compare sign-extended halves for `_i16`. - The 32-bit forms are in a new small `int32` module. `v_mad_u32_u16`/`v_mad_i32_i16` accept op_sel on the two multiplicands only. - **Conservative scope:** VGPR sources only, compute shaders only. Clamp (saturation), abs, neg and the other op_sel bits are refused, like the existing newer 16-bit forms. **Verification** - Unit tests decode the LLVM gfx1030 words and check accepted forms, half selection and every refusal. - `tools/check_ordinary_integer_gpu.py` assembles every legal op_sel combination with `llvm-mc -mcpu=gfx1030`. The result register aliases one source, so destination-half preservation is tested too. The script runs the translated shaders through DXC/DXV and stock Proton, then compares all 384 readback words per dispatch, including the inputs and guard words, with a Python model. Hand-computed values for that model are in `tests/test_ordinary_integer_gpu.py`. - **Result on an AMD Radeon RX 6950 XT** (`1002:73a5`, RADV): 154 selector combinations, 2,464 results, 8,448 GPU words, zero mismatches. The receipt is `evidence/ordinary-integer-vop3-control.json`. - The emitter from `5cee10f` refuses all 22 test shaders (`--baseline`). For each instruction, the clamp form and an SGPR-source form are refused. - **Negative control:** I rebuilt the emitter with the signed `min3`/`max3`/`med3` comparing unsigned. The check then failed at the first `v_min3_i16` case, exactly on the inputs with bit 15 set. - Unchanged: all 124 shader-compiler tests and all 184 Python tests pass. **Not included:** `v_cvt_pk_u16_u32` and `v_cvt_pk_i16_i32` were refused in the same sweep. I could not independently confirm their saturation behaviour (LLVM does not constant-fold `llvm.amdgcn.cvt.pk.*`), so they remain refused. AI-assisted. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01NhDbTJdTcjebsL5u7pwFoY
A synthetic sweep of the decoder's ALU opcode table found these decoded
but refused as "unsupported vector op":

- 16-bit, writing one destination half and preserving the other:
  v_add_nc_i16, v_sub_nc_i16, v_mad_u16, v_mad_i16, v_min3/max3/med3
  in _u16 and _i16
- 32-bit result: v_add_nc_i32, v_sub_nc_i32, v_mad_u32_u16,
  v_mad_i32_i16

The 16-bit forms reuse the existing int16 half-select lowering. Like the
other newer forms they accept VGPR sources only, in compute shaders
only, and refuse clamp, abs and neg. Without clamp, the signed add,
subtract and multiply-add produce the same bits as the unsigned forms.

tools/check_ordinary_integer_gpu.py assembles every source and
destination op_sel combination with LLVM (gfx1030), runs the translated
shaders on a GPU and compares each word with a Python model.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NhDbTJdTcjebsL5u7pwFoY
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:30:47 +00:00
github manually merged commit db6a4bf799 into gh-pr/95/base 2026-11-26 06:30:49 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.