Shaders: saturate clamped 24-bit multiply and multiply-add #2926

Open
github-bot wants to merge 1 commit from github-bot/gh-2926 into main AGit
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-26 00:16 UTC · original
andrewpozdnakov7-jpg:codex2/mul24-clamp → main · +151 −33 · 3 files · 1 commits · open

Summary

Lower the clamp forms of v_mul_i32_i24, v_mul_u32_u24, v_mad_i32_i24, and v_mad_u32_u24. Saturate the complete product or multiply-add to the signed or unsigned 32-bit range. The unclamped forms still wrap.

Only the clamped path computes a high word. Splitting each 24-bit operand into 16 low bits and 8 high bits keeps each partial product and intermediate sum in i32. For MAD, the carry and sign extension from the addend complete the high word before saturation. This needs only 32-bit DXIL integer operations. The forms are listed with clamp in the GFX1030 assembly reference, and integer saturation is described in section 6.5 of the RDNA 2 ISA.

Verification

  • On 63bcca4, the same fixture is refused at v_mul_i32_i24 with integer output modifiers. On the patch, all 96 signed/unsigned MUL/MAD input and mode combinations match an exact wide-integer reference on app-local WARP SM 6.6 with DXIL validation.
  • The controls cover high operand bits, positive and negative saturation, a MAD addend bringing a wide signed product back into range, unsigned carry out, and unclamped wrapping.
  • A separate arithmetic cross-check of 1,061,572 edge and fixed-seed pairs matched the exact high word and saturated result.
  • 36 VALU, 34 semantics (1 ignored), and 33 lowerer tests passed on WARP. Strict shader Clippy in both feature configurations and the staged asset policy (192 files) passed.
**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-26 00:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/2926) `andrewpozdnakov7-jpg:codex2/mul24-clamp` → `main` · +151 −33 · 3 files · 1 commits · open ### Summary Lower the `clamp` forms of `v_mul_i32_i24`, `v_mul_u32_u24`, `v_mad_i32_i24`, and `v_mad_u32_u24`. Saturate the complete product or multiply-add to the signed or unsigned 32-bit range. The unclamped forms still wrap. Only the clamped path computes a high word. Splitting each 24-bit operand into 16 low bits and 8 high bits keeps each partial product and intermediate sum in i32. For MAD, the carry and sign extension from the addend complete the high word before saturation. This needs only 32-bit DXIL integer operations. The forms are listed with `clamp` in the [GFX1030 assembly reference](https://rocmdocs.amd.com/projects/llvm-project/en/latest/LLVM/llvm/html/AMDGPU/AMDGPUAsmGFX1030.html), and integer saturation is described in section 6.5 of the [RDNA 2 ISA](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf). ### Verification - On `63bcca4`, the same fixture is refused at `v_mul_i32_i24` with `integer output modifiers`. On the patch, all 96 signed/unsigned MUL/MAD input and mode combinations match an exact wide-integer reference on app-local WARP SM 6.6 with DXIL validation. - The controls cover high operand bits, positive and negative saturation, a MAD addend bringing a wide signed product back into range, unsigned carry out, and unclamped wrapping. - A separate arithmetic cross-check of 1,061,572 edge and fixed-seed pairs matched the exact high word and saturated result. - 36 VALU, 34 semantics (1 ignored), and 33 lowerer tests passed on WARP. Strict shader Clippy in both feature configurations and the staged asset policy (192 files) passed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:17:40 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 04:24 UTC · original

Automated triage for the maintainers.

Merge candidate. Adds the clamp forms of v_mul_{i,u}32_{i,u}24 and v_mad_{i,u}32_{i,u}24, which main refused in write_i, in emit/lower/mul24.rs, leaving the unclamped forms unchanged. clamp_mul24 checks out: the 16/8-bit split keeps partial products within 32 bits, middle_hi floors correctly for signed forms, the MAD carry and addend sign extension give the exact high word, and saturation is right. The test compares against an exact i64 reference, and the RDNA2 ISA integer-clamp rule is cited.

CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 04:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/2926#issuecomment-7182561689) <!-- victory-triage v1 head=3b60f1bd966bcb0f6908f294ade763e832a7e27d verdict=merge-candidate at=2026-11-26T04:23:56Z --> Automated triage for the maintainers. **Merge candidate.** Adds the `clamp` forms of `v_mul_{i,u}32_{i,u}24` and `v_mad_{i,u}32_{i,u}24`, which main refused in `write_i`, in `emit/lower/mul24.rs`, leaving the unclamped forms unchanged. `clamp_mul24` checks out: the 16/8-bit split keeps partial products within 32 bits, `middle_hi` floors correctly for signed forms, the MAD carry and addend sign extension give the exact high word, and saturation is right. The test compares against an exact i64 reference, and the RDNA2 ISA integer-clamp rule is cited. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2926/head:github-bot/gh-2926'
git switch 'github-bot/gh-2926'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2926'
git switch 'github-bot/gh-2926'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2926'
git switch 'github-bot/gh-2926'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2926'
git switch 'main'
git merge --squash 'github-bot/gh-2926'
git switch 'main'
git merge --ff-only 'github-bot/gh-2926'
git switch 'main'
git merge 'github-bot/gh-2926'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2926
No description provided.