Shaders: lower mul_hi without INT64 #2146

Closed
scoresby13 wants to merge 1 commit from upstream-pr/2148 into main
scoresby13 commented 2026-11-25 06:09:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by scoresby13 on 2026-11-25T06:09:27Z.


Summary

Lowers Lower::mul_hi (s_mul_hi_u32, s_mul_hi_i32, v_mul_hi_u32, v_mul_hi_i32, v_mul_hi_u32_u24, v_mul_hi_i32_i24) in victory-shader using pure 32-bit DXIL operations instead of 64-bit integer multiplication, removing flags::INT64 (SFI0 bit 0x8000 / Int64ShaderOps) from shaders that use 32-bit/24-bit high-multiply instructions.

Claimed on #1633.

Details

  • Splits each 32-bit factor into 16-bit halves and computes the exact unsigned 32-bit high dword via 16x16 partial products without intermediate unsigned overflow (Hacker's Delight 8-2).
  • When signed is true, applies sign-bit masks (a >>s 31) & b and (b >>s 31) & a subtracted from the unsigned high word to produce the exact signed high dword.
  • Leaves all six s_mul_hi_*, v_mul_hi_*, and v_mul_hi_*_24 callers on mul_hi without requiring Int64ShaderOps.
  • Adds CPU-only SFI0 validation (emit::lower::tests::mul_hi_needs_no_int64) and GPU/WARP tests (emit::valu_tests::mul_hi_matches_rdna2_without_int64) covering all 144 ordered pairs of 12 edge-case 32-bit values across all 6 instructions.

Testing

  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings (passed)
  • cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings (passed)
  • cargo xtask policy (asset policy: 182 files ok)
  • cargo test -p victory-shader --locked mul_hi -- --nocapture (2 passed, 0 failed)
  • cargo test -p victory-shader --locked the_24_bit_multiplies_lower_both_halves -- --nocapture (1 passed, 0 failed)

No game data was used. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6598390230 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2148). Originally posted by [scoresby13](https://github.com/scoresby13) on 2026-11-25T06:09:27Z. --- ## Summary Lowers `Lower::mul_hi` (`s_mul_hi_u32`, `s_mul_hi_i32`, `v_mul_hi_u32`, `v_mul_hi_i32`, `v_mul_hi_u32_u24`, `v_mul_hi_i32_i24`) in `victory-shader` using pure 32-bit DXIL operations instead of 64-bit integer multiplication, removing `flags::INT64` (`SFI0` bit `0x8000` / `Int64ShaderOps`) from shaders that use 32-bit/24-bit high-multiply instructions. Claimed on #1633. ## Details - Splits each 32-bit factor into 16-bit halves and computes the exact unsigned 32-bit high dword via `16x16` partial products without intermediate unsigned overflow (Hacker's Delight 8-2). - When `signed` is true, applies sign-bit masks `(a >>s 31) & b` and `(b >>s 31) & a` subtracted from the unsigned high word to produce the exact signed high dword. - Leaves all six `s_mul_hi_*`, `v_mul_hi_*`, and `v_mul_hi_*_24` callers on `mul_hi` without requiring `Int64ShaderOps`. - Adds CPU-only `SFI0` validation (`emit::lower::tests::mul_hi_needs_no_int64`) and GPU/WARP tests (`emit::valu_tests::mul_hi_matches_rdna2_without_int64`) covering all 144 ordered pairs of 12 edge-case 32-bit values across all 6 instructions. ## Testing - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` (passed) - `cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings` (passed) - `cargo xtask policy` (`asset policy: 182 files ok`) - `cargo test -p victory-shader --locked mul_hi -- --nocapture` (2 passed, 0 failed) - `cargo test -p victory-shader --locked the_24_bit_multiplies_lower_both_halves -- --nocapture` (1 passed, 0 failed) No game data was used. AI-assisted.
DenRakEiw commented 2026-11-25 07:02:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T06:24:00Z.

Review: APPROVED


Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, with dxil.dll validator):

  • cargo test -p victory-shader --lib mul_hi_ — 2 passed, 0 failed on both RTX 5090 hardware and VICTORY_D3D12_WARP=1 (mul_hi_needs_no_int64 and mul_hi_matches_rdna2_without_int64)
  • cargo clippy -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean pure-32-bit mul_hi lowering without INT64, thoroughly verified end-to-end on hardware and WARP. Looks great.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6052794118 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2148#pullrequestreview-6052794118). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T06:24:00Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, with `dxil.dll` validator): - `cargo test -p victory-shader --lib mul_hi_` — **2 passed, 0 failed** on both RTX 5090 hardware and `VICTORY_D3D12_WARP=1` (`mul_hi_needs_no_int64` and `mul_hi_matches_rdna2_without_int64`) - `cargo clippy -p victory-shader --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean pure-32-bit `mul_hi` lowering without `INT64`, thoroughly verified end-to-end on hardware and WARP. Looks great. AI-assisted (Gemini 4 Neon).
catminou4 commented 2026-11-25 07:02:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T06:49:53Z.

Review: APPROVED


Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, cargo test -p victory-shader --locked.

145 passed / 0 failed / 2 ignored. mul_hi lowered without INT64 — multiply-high in 32-bit DXIL; part of the no-INT64 lowering cluster (#2104/#2133/#2063).

<!-- greyfinch-sync:Marvisak/VIctory:review:6053075661 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2148#pullrequestreview-6053075661). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T06:49:53Z. **Review:** APPROVED --- Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, `cargo test -p victory-shader --locked`. 145 passed / 0 failed / 2 ignored. mul_hi lowered without INT64 — multiply-high in 32-bit DXIL; part of the no-INT64 lowering cluster (#2104/#2133/#2063).
sinan-cmyk commented 2026-11-25 09:06:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T08:20:23Z.


Offline measurement on a retail dump

Result: no count change against main.

I merged head 8c9e7eba onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7156903317 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2148#issuecomment-7156903317). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T08:20:23Z. --- ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head 8c9e7eba onto `main` 940d32f (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 23,918 on `main`, 23,918 with this PR. No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Marvisak commented 2026-11-25 12:03:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T11:24:13Z.


Automated triage for the maintainers.

Needs work. The arithmetic is right. What the PR is missing is a reason to make the change.

What I checked: Lower::mul_hi (crates/victory-shader/src/emit/lower.rs) now builds the high dword from four 16×16 partial products. The steps match Hacker's Delight mulhu, and no intermediate overflows 32 bits. The signed result subtracts (a >> 31) & b and (b >> 31) & a, which is the standard mulhs correction. The 24-bit callers still sign- or zero-extend before the call. mul_hi_matches_rdna2_without_int64 compares all 144 pairs of edge values on the GPU against a 64-bit reference, which is a real check.

Why it isn't mergeable as is:

  • No host benefits that we know of. Main never checks Int64ShaderOps on the host (crates/victory-gpu/src/host.rs checks only the 64-bit atomic caps), and every SM 6.6 GPU VIctory targets exposes it. The offline measurement on the thread found no change in validated programs (23,918 before and after).
  • It costs instructions. One native 64-bit multiply becomes about 20 32-bit operations, in instructions that show up in address and hash math.
  • Programs keep INT64 anyway. It is still set by src64, the s_lshl_b64/s_lshr_b64/s_ashr_i64 path and the 64-bit atomics, so many programs will declare it regardless.

What would change the verdict: a host or driver that refuses Int64ShaderOps and so fails on these programs today, or a measured gain (for example programs that no longer declare INT64 at all, with a host that cares). CI: passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7160999795 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2148#issuecomment-7160999795). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T11:24:13Z. --- <!-- victory-triage v1 head=8c9e7eba491d049f9ab6c83a92a2e42edd7b5f0d verdict=needs-work at=2026-11-25T11:24:12Z --> Automated triage for the maintainers. **Needs work.** The arithmetic is right. What the PR is missing is a reason to make the change. What I checked: `Lower::mul_hi` (`crates/victory-shader/src/emit/lower.rs`) now builds the high dword from four 16×16 partial products. The steps match Hacker's Delight `mulhu`, and no intermediate overflows 32 bits. The signed result subtracts `(a >> 31) & b` and `(b >> 31) & a`, which is the standard `mulhs` correction. The 24-bit callers still sign- or zero-extend before the call. `mul_hi_matches_rdna2_without_int64` compares all 144 pairs of edge values on the GPU against a 64-bit reference, which is a real check. Why it isn't mergeable as is: - **No host benefits that we know of.** Main never checks `Int64ShaderOps` on the host (`crates/victory-gpu/src/host.rs` checks only the 64-bit atomic caps), and every SM 6.6 GPU VIctory targets exposes it. The offline measurement on the thread found no change in validated programs (23,918 before and after). - **It costs instructions.** One native 64-bit multiply becomes about 20 32-bit operations, in instructions that show up in address and hash math. - **Programs keep `INT64` anyway.** It is still set by `src64`, the `s_lshl_b64`/`s_lshr_b64`/`s_ashr_i64` path and the 64-bit atomics, so many programs will declare it regardless. What would change the verdict: a host or driver that refuses `Int64ShaderOps` and so fails on these programs today, or a measured gain (for example programs that no longer declare `INT64` at all, with a host that cares). CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
steven-seagull27 commented 2026-11-26 04:06:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-26T03:27:16Z.


@scoresby13 I measured the partial-product cost raised in triage using your 8c9e7eba merged onto main 63bcca43. On the RTX 5080 and built-in WARP, all six forms on your branch matched the CPU reference for 32,768 input pairs each (196,608/196,608 high dwords per device).

On the RTX, a chain of 64 dependent v_mul_hi_u32 operations per lane took 6.18–6.21 µs with your lowering, 4.13 µs on main, and 4.16 µs using #3007's DXIL intrinsic. A signed 24-bit chain gave 7.62–7.68, 5.66–5.70, and 4.90–4.93 µs respectively. These are medians from two independent runs with the three variants interleaved. The intrinsic keeps your INT64-removal goal and was faster than the partial products on both measured shaders. Fixtures, method and results on #3007.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7181733066 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2148#issuecomment-7181733066). Originally posted by [steven-seagull27](https://github.com/steven-seagull27) on 2026-11-26T03:27:16Z. --- @scoresby13 I measured the partial-product cost raised in triage using your `8c9e7eba` merged onto main `63bcca43`. On the RTX 5080 and built-in WARP, all six forms on your branch matched the CPU reference for 32,768 input pairs each (196,608/196,608 high dwords per device). On the RTX, a chain of 64 dependent `v_mul_hi_u32` operations per lane took 6.18–6.21 µs with your lowering, 4.13 µs on main, and 4.16 µs using #3007's DXIL intrinsic. A signed 24-bit chain gave 7.62–7.68, 5.66–5.70, and 4.90–4.93 µs respectively. These are medians from two independent runs with the three variants interleaved. The intrinsic keeps your INT64-removal goal and was faster than the partial products on both measured shaders. [Fixtures, method and results on #3007](https://github.com/Marvisak/VIctory/pull/3007#issuecomment-7181729656).
upstream-sync closed this pull request 2026-11-26 08:02:19 +00:00
scoresby13 commented 2026-11-26 08:03:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by scoresby13 on 2026-11-26T07:08:42Z.


Thank you @steven-seagull27 for the RTX 5080 benchmark and @Ingenioeren for #3007! Since #3007 (Shaders: lower the 32-bit mul_hi forms to one UMul/IMul) drops SFI0 INT64 using DXIL's native UMul/IMul intrinsic directly and runs faster without the 16x16 partial-product overhead, I'm closing this PR in favor of #3007.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7185142560 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2148#issuecomment-7185142560). Originally posted by [scoresby13](https://github.com/scoresby13) on 2026-11-26T07:08:42Z. --- Thank you @steven-seagull27 for the RTX 5080 benchmark and @Ingenioeren for #3007! Since #3007 (`Shaders: lower the 32-bit mul_hi forms to one UMul/IMul`) drops `SFI0` `INT64` using DXIL's native `UMul`/`IMul` intrinsic directly and runs faster without the 16x16 partial-product overhead, I'm closing this PR in favor of #3007. AI-assisted.

Pull request closed

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
Marvisak/VIctory!2146
No description provided.