cpp-migration: lower v_sad_u8, v_sad_hi_u8, v_sad_u16, v_sad_u32 and v_msad_u8 in the direct C++ compute path #2987

Closed
opened 2026-11-27 03:23:26 +00:00 by legacy-code-archaeologist · 1 comment
legacy-code-archaeologist commented 2026-11-27 03:23:26 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-27T03:23:26Z.


Target branch cpp-migration. Part of #2935 (instruction coverage: integer ALU). I am taking this; please say if you already have it locally and I will drop it.

Gap: the direct compute path refuses the five sum-of-absolute-differences operations that gfx2hlsl.py lowers: v_sad_u8, v_sad_hi_u8, v_sad_u16, v_sad_u32 and v_msad_u8. I compiled each through compile_dxil ... gfx1013-direct-cs@0 from cpp-migration 05438d65, as a VOP3 instruction on VGPRs in a source-built request. All five fail with direct DXIL lowering for <name>. I found them with the same per-opcode VOP3 probe as #2985.

Plan: use the gfx2hlsl.py helpers sad_u8, sad4_u8, sad_u16 and sad_u32, which match tools/pixel_aot.py.

  • v_sad_u8: the sum of the four unsigned byte differences, plus S2.
  • v_sad_hi_u8: that sum shifted left by 16, plus S2.
  • v_sad_u16: the two unsigned halfword differences, plus S2.
  • v_sad_u32: |S0 - S1| unsigned, plus S2.
  • v_msad_u8: like v_sad_u8, but skipping each byte whose S1 byte is zero.

All results wrap modulo 2^32. Source abs/neg and clamp are refused, as gfx2hlsl.py refuses the modifiers. The fixture is a source-built dispatch with per-lane operands against a CPU reference, plus mutated references: signed byte differences, msad without its mask, sad_hi without its shift, and S2 dropped.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6639288562 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2987). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-27T03:23:26Z. --- Target branch `cpp-migration`. Part of #2935 (instruction coverage: integer ALU). I am taking this; please say if you already have it locally and I will drop it. **Gap:** the direct compute path refuses the five sum-of-absolute-differences operations that `gfx2hlsl.py` lowers: `v_sad_u8`, `v_sad_hi_u8`, `v_sad_u16`, `v_sad_u32` and `v_msad_u8`. I compiled each through `compile_dxil ... gfx1013-direct-cs@0` from `cpp-migration` `05438d65`, as a VOP3 instruction on VGPRs in a source-built request. All five fail with `direct DXIL lowering for <name>`. I found them with the same per-opcode VOP3 probe as #2985. **Plan:** use the `gfx2hlsl.py` helpers `sad_u8`, `sad4_u8`, `sad_u16` and `sad_u32`, which match `tools/pixel_aot.py`. - `v_sad_u8`: the sum of the four unsigned byte differences, plus S2. - `v_sad_hi_u8`: that sum shifted left by 16, plus S2. - `v_sad_u16`: the two unsigned halfword differences, plus S2. - `v_sad_u32`: |S0 - S1| unsigned, plus S2. - `v_msad_u8`: like `v_sad_u8`, but skipping each byte whose S1 byte is zero. All results wrap modulo 2^32. Source abs/neg and clamp are refused, as `gfx2hlsl.py` refuses the modifiers. The fixture is a source-built dispatch with per-lane operands against a CPU reference, plus mutated references: signed byte differences, msad without its mask, sad_hi without its shift, and S2 dropped. AI-assisted.
MasterDomino commented 2026-11-27 03:47:15 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-27T03:47:15Z.


Completed by #2990, merged into cpp-migration as b69c111f. Merges into a non-default branch do not close issues automatically.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7209270957 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2987#issuecomment-7209270957). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-27T03:47:15Z. --- Completed by #2990, merged into `cpp-migration` as b69c111f. Merges into a non-default branch do not close issues automatically.
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
R0Y00/Xbox2Windows#2987
No description provided.