xshader: lower fourteen ordinary VOP3 integer forms #95

Merged
JohnVonWells merged 1 commit from upstream-pr/95 into main 2026-11-24 22:05:57 +00:00
JohnVonWells commented 2026-11-24 22:01:08 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by JohnVonWells on 2026-11-24T22:01:08Z.


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

<!-- greyfinch-sync:brcly/TuxBox:issue:6592272325 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/95). Originally posted by [JohnVonWells](https://github.com/JohnVonWells) on 2026-11-24T22:01:08Z. --- 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
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
brcly/TuxBox!95
No description provided.