Recompiler rejects clamp on VOP3 v_add_nc_u32, v_sub_nc_u32 and the 16-bit add/sub ops #1897

Closed
opened 2026-10-08 22:57:53 +00:00 by fisherjoey · 0 comments
fisherjoey commented 2026-10-08 22:57:53 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-08T22:57:53Z.


A VOP3 clamp on unsigned 32-bit add/sub, or on any 16-bit integer add/sub, stops the recompile with ShaderRecompiler::Recompile: VOP3 source modifiers are not implemented. The affected ops are:

  • v_add_nc_u32, v_sub_nc_u32, v_subrev_nc_u32
  • v_add_nc_u16, v_sub_nc_u16, v_add_nc_i16, v_sub_nc_i16

LLVM emits these with clamp for saturating adds and subtracts on gfx10 (uadd.sat, usub.sat, and the i16/u16 forms), so they can appear in real shaders.

The signed 32-bit versions already work (v_add_nc_i32/v_sub_nc_i32 clamp, e144f43f). The u32 saturation is also already in vAddSubNcU32, added for the SDWA form in c5effd40. The VOP3 form is refused in the decoder because those three opcodes are missing from usesIntegerSaturateClamp. For the 16-bit ops, checkNativeVop3Modifiers rejects clamp, and integer16Binary doesn't saturate.

Hardware behaviour, measured with tools/hw-oracle on a Ryzen 5 7600X iGPU (gfx1036, RDNA2, wave32):

Op Result with clamp
v_add_nc_u32 saturates to 0xffffffff
v_sub_nc_u32, v_subrev_nc_u32 saturate to 0
v_add_nc_u16, v_sub_nc_u16 saturate to 0xffff / 0
v_add_nc_i16, v_sub_nc_i16 saturate to 0x7fff / 0x8000

Bits 31:16 of the 16-bit results were 0 in these runs.

Float settings: IEEE=0, DX10_CLAMP=1, denorm32=0, denorm16=3, round32=0, round16=0, fp16_overflow=0. A second run with IEEE=1, DX10_CLAMP=0, denorm 3/3, round toward zero and fp16_overflow=1 gave identical results.

Out of scope: the carry ops (v_add_co_u32, v_sub_co_u32, v_add_co_ci_u32, ...) with clamp still throw. LLVM only emits that form for gfx8. On the iGPU they saturate the result and still write the carry-out. I can do them separately if anyone needs them.

I have a fix with a test built from the measured rows, and I'll open the PR now: https://github.com/fisherjoey/AnyPS5/tree/fix/vop3-add-sub-clamp

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5770092336 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/1897). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-08T22:57:53Z. --- A VOP3 `clamp` on unsigned 32-bit add/sub, or on any 16-bit integer add/sub, stops the recompile with `ShaderRecompiler::Recompile: VOP3 source modifiers are not implemented`. The affected ops are: - `v_add_nc_u32`, `v_sub_nc_u32`, `v_subrev_nc_u32` - `v_add_nc_u16`, `v_sub_nc_u16`, `v_add_nc_i16`, `v_sub_nc_i16` LLVM emits these with `clamp` for saturating adds and subtracts on gfx10 (`uadd.sat`, `usub.sat`, and the i16/u16 forms), so they can appear in real shaders. The signed 32-bit versions already work (`v_add_nc_i32`/`v_sub_nc_i32` clamp, e144f43f). The u32 saturation is also already in `vAddSubNcU32`, added for the SDWA form in c5effd40. The VOP3 form is refused in the decoder because those three opcodes are missing from `usesIntegerSaturateClamp`. For the 16-bit ops, `checkNativeVop3Modifiers` rejects clamp, and `integer16Binary` doesn't saturate. Hardware behaviour, measured with `tools/hw-oracle` on a Ryzen 5 7600X iGPU (gfx1036, RDNA2, wave32): | Op | Result with clamp | | --- | --- | | `v_add_nc_u32` | saturates to `0xffffffff` | | `v_sub_nc_u32`, `v_subrev_nc_u32` | saturate to 0 | | `v_add_nc_u16`, `v_sub_nc_u16` | saturate to `0xffff` / 0 | | `v_add_nc_i16`, `v_sub_nc_i16` | saturate to `0x7fff` / `0x8000` | Bits 31:16 of the 16-bit results were 0 in these runs. Float settings: IEEE=0, DX10_CLAMP=1, denorm32=0, denorm16=3, round32=0, round16=0, fp16_overflow=0. A second run with IEEE=1, DX10_CLAMP=0, denorm 3/3, round toward zero and fp16_overflow=1 gave identical results. Out of scope: the carry ops (`v_add_co_u32`, `v_sub_co_u32`, `v_add_co_ci_u32`, ...) with clamp still throw. LLVM only emits that form for gfx8. On the iGPU they saturate the result and still write the carry-out. I can do them separately if anyone needs them. I have a fix with a test built from the measured rows, and I'll open the PR now: https://github.com/fisherjoey/AnyPS5/tree/fix/vop3-add-sub-clamp AI-assisted: yes
Sign in to join this conversation.
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
boykopovar/AnyPS5#1897
No description provided.