DXIL: lower Lw::mul_hi to umul_wide and imul_wide #2172

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

@⁠O5-7 on GitHub · 2026-11-25 07:04 UTC · original
O5-7:dxil/mul-hi-wide → main · +84 −5 · 3 files · 1 commits · open

Lower RDNA2 32x32→high-32 multiplication (Lw::mul_hi) directly to DXIL dx.op.binaryWithTwoOuts.i32 (umul_wide, op 42, and imul_wide, op 41) instead of widening operands to i64, multiplying in 64 bits, shifting right by 32, and truncating back to i32.

This covers s_mul_hi_u32, s_mul_hi_i32, v_mul_hi_u32, v_mul_hi_i32, v_mul_hi_u32_u24, and v_mul_hi_i32_i24 and avoids unnecessary 64-bit integer operations and Feature::Int64Ops flags.

Part of #1269

What is in it

  • crates/xcl/src/gpu/dxil/lower.rs: replace Lw::mul_hi with if signed { self.s.imul_wide(a, b).0 } else { self.s.umul_wide(a, b).0 } (+1/-5 lines).
  • crates/xcl/src/gpu/dxil/core_tests.rs: add mul_hi_lowers_to_dxil_wide_mul verifying DXIL validation and disassembly emit dx.op.binaryWithTwoOuts.i32 opcodes 42 (UMul) and 41 (IMul) without mul i64 or sext i32.
  • crates/xcl/src/gpu/recomp/tests.rs: add gpu_mul_hi_edge_cases testing scalar and vector mul_hi (u32, i32, u24, i24 with dirty upper 8 bits and sign/boundary inputs) against 64-bit CPU reference.
  • Synthetic compute shader measurement (1 and 64 (V_MUL_HI_U32, V_MUL_HI_I32) pairs, wave32): n = 1 changes 2272 → 2348 bytes (first dx.types.twoi32 / binaryWithTwoOuts declarations); n = 64 drops 5748 → 5676 bytes (-72 bytes) and removes all i64 arithmetic.

Tested

  • Hardware & toolchain: NVIDIA GeForce RTX 5080 (driver 32.0.15.9579, wave32), AMD Ryzen 7 9700X, Windows 11 Pro 10.0.26100, rustc 1.100.0, DXC 1.8.2502.11 (XCL_DXC_DIR=D:\Windows Kits\10\bin\10.0.26100.0\x64), debug & release builds.
  • cargo test --workspace -- --test-threads=4: 1156 passed, 0 failed, 46 ignored (24 SKIPPED hardware-capability / policy checks: native wave64 unavailable on RTX 5080 and rejected direct-path f16 arithmetic), including mul_hi_lowers_to_dxil_wide_mul and gpu_mul_hi_edge_cases.
  • XCL_DIRECT_DXIL=1 targeted GPU parity runs on RTX 5080 (gpu_mul_hi_edge_cases, gpu_scalar_sext_mulhi_and_vector_i24_sub_co_ci_u64_shifts): both passed.

Regression run
main:

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1680 (PresentX 1680)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 13673 MB

PR:

xcl-smoke v1
commit: 01c4d2068185c915a2e742358f5f2c2067d0a6f5
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1685 (PresentX 1685)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13629 MB

Not tested

  • Native wave64 GPU execution (skipped automatically on wave32-only RTX 5080 hardware).
  • Running the title with XCL_DIRECT_DXIL=1 in the smoke.ps1 launch (because on unmerged main without PR #2101, D:\Windows Kits\... in XCL_DXC_DIR is intercepted by the {game} D-drive VFS mount inside the host process; XCL_DIRECT_DXIL=1 was verified in unit/GPU tests).

AI use

  • Antigravity (Gemini 4 Neon): updated Lw::mul_hi to emit umul_wide/imul_wide, added the disassembly and GPU edge-case tests, and ran the test suite and scripts/smoke.ps1 regression checks.
**@⁠O5-7** on GitHub · 2026-11-25 07:04 UTC · [original](https://github.com/xcl-dev/xcl/pull/2172) `O5-7:dxil/mul-hi-wide` → `main` · +84 −5 · 3 files · 1 commits · open Lower RDNA2 32x32→high-32 multiplication (`Lw::mul_hi`) directly to DXIL `dx.op.binaryWithTwoOuts.i32` (`umul_wide`, op 42, and `imul_wide`, op 41) instead of widening operands to `i64`, multiplying in 64 bits, shifting right by 32, and truncating back to `i32`. This covers `s_mul_hi_u32`, `s_mul_hi_i32`, `v_mul_hi_u32`, `v_mul_hi_i32`, `v_mul_hi_u32_u24`, and `v_mul_hi_i32_i24` and avoids unnecessary 64-bit integer operations and `Feature::Int64Ops` flags. Part of #1269 **What is in it** - `crates/xcl/src/gpu/dxil/lower.rs`: replace `Lw::mul_hi` with `if signed { self.s.imul_wide(a, b).0 } else { self.s.umul_wide(a, b).0 }` (+1/-5 lines). - `crates/xcl/src/gpu/dxil/core_tests.rs`: add `mul_hi_lowers_to_dxil_wide_mul` verifying DXIL validation and disassembly emit `dx.op.binaryWithTwoOuts.i32` opcodes 42 (`UMul`) and 41 (`IMul`) without `mul i64` or `sext i32`. - `crates/xcl/src/gpu/recomp/tests.rs`: add `gpu_mul_hi_edge_cases` testing scalar and vector `mul_hi` (`u32`, `i32`, `u24`, `i24` with dirty upper 8 bits and sign/boundary inputs) against 64-bit CPU reference. - Synthetic compute shader measurement (1 and 64 `(V_MUL_HI_U32, V_MUL_HI_I32)` pairs, wave32): `n = 1` changes `2272` → `2348` bytes (first `dx.types.twoi32` / `binaryWithTwoOuts` declarations); `n = 64` drops `5748` → `5676` bytes (`-72` bytes) and removes all `i64` arithmetic. **Tested** - Hardware & toolchain: NVIDIA GeForce RTX 5080 (driver `32.0.15.9579`, wave32), AMD Ryzen 7 9700X, Windows 11 Pro `10.0.26100`, `rustc 1.100.0`, DXC `1.8.2502.11` (`XCL_DXC_DIR=D:\Windows Kits\10\bin\10.0.26100.0\x64`), debug & release builds. - `cargo test --workspace -- --test-threads=4`: 1156 passed, 0 failed, 46 ignored (`24 SKIPPED` hardware-capability / policy checks: native wave64 unavailable on RTX 5080 and rejected direct-path `f16` arithmetic), including `mul_hi_lowers_to_dxil_wide_mul` and `gpu_mul_hi_edge_cases`. - `XCL_DIRECT_DXIL=1` targeted GPU parity runs on RTX 5080 (`gpu_mul_hi_edge_cases`, `gpu_scalar_sext_mulhi_and_vector_i24_sub_co_ci_u64_shifts`): both passed. **Regression run** main: ``` xcl-smoke v1 commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1680 (PresentX 1680) presents per 2 s (last 3): 60 61 60 device removals: 0 crashes: 0 peak commit: 13673 MB ``` PR: ``` xcl-smoke v1 commit: 01c4d2068185c915a2e742358f5f2c2067d0a6f5 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1685 (PresentX 1685) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 13629 MB ``` **Not tested** - Native wave64 GPU execution (skipped automatically on wave32-only RTX 5080 hardware). - Running the title with `XCL_DIRECT_DXIL=1` in the `smoke.ps1` launch (because on unmerged `main` without PR #2101, `D:\Windows Kits\...` in `XCL_DXC_DIR` is intercepted by the `{game}` D-drive VFS mount inside the host process; `XCL_DIRECT_DXIL=1` was verified in unit/GPU tests). **AI use** - Antigravity (Gemini 4 Neon): updated `Lw::mul_hi` to emit `umul_wide`/`imul_wide`, added the disassembly and GPU edge-case tests, and ran the test suite and `scripts/smoke.ps1` regression checks.
Replace the 64-bit extend/mul/shift/trunc expansion in Lw::mul_hi with
dx.op.binaryWithTwoOuts UMul (op 42) and IMul (op 41), extracting the
high dword directly and avoiding i64 ops and Feature::Int64Ops across
s_mul_hi_u32/i32, v_mul_hi_u32/i32, and v_mul_hi_u32_u24/i32_i24.

Part of #1269

Assisted-by: Antigravity (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:21:47 +00:00
Author
Owner

@⁠luckyteagirl on GitHub · 2026-11-25 07:12 UTC · original

Independent native Windows AMD check of exact PR head 3a599afdb71b1994ae09df4772a73c98d176bdf7. The PR description lists native wave64 as untested.

Tested

  • Windows 11 build 26200; Ryzen 9 5980HX; Radeon RX 6800M driver 30.0.13002.13003; Rust 1.99.0 MSVC; DXC/DXIL 1.9.2609.5; debug tests.
  • XCL_ADAPTER=6800M, XCL_REQUIRE_GPU=wave64, XCL_DIRECT_DXIL=1; cargo test --locked -p xcl --lib -j 2 gpu_mul_hi_edge_cases -- --test-threads=1 --show-output: 1 passed, 0 failed, 0 ignored, 0 SKIPPED. The fixture runs both wave64 and wave32 and checks scalar/vector signed and unsigned high-multiply cases, including 24-bit operands, against CPU reference values.
  • The same GPU command with XCL_DIRECT_DXIL=0: 1 passed, 0 failed, 0 ignored, 0 SKIPPED.
  • mul_hi_lowers_to_dxil_wide_mul on this head: 1 passed, 0 failed, 0 ignored (DXIL intrinsic validation/disassembly unit test).

This checks the focused GPU and DXIL tests. I did not run the full workspace suite or a paired title smoke on this PR. No claim about speed or title shader use follows from these tests.

AI-assisted checkout, testing, log verification, and report drafting with OpenAI Codex (GPT-6). No game data was used.

**@⁠luckyteagirl** on GitHub · 2026-11-25 07:12 UTC · [original](https://github.com/xcl-dev/xcl/pull/2172#issuecomment-7155597361) Independent native Windows AMD check of exact PR head `3a599afdb71b1994ae09df4772a73c98d176bdf7`. The PR description lists native wave64 as untested. **Tested** - Windows 11 build 26200; Ryzen 9 5980HX; Radeon RX 6800M driver `30.0.13002.13003`; Rust 1.99.0 MSVC; DXC/DXIL 1.9.2609.5; debug tests. - `XCL_ADAPTER=6800M`, `XCL_REQUIRE_GPU=wave64`, `XCL_DIRECT_DXIL=1`; `cargo test --locked -p xcl --lib -j 2 gpu_mul_hi_edge_cases -- --test-threads=1 --show-output`: **1 passed, 0 failed, 0 ignored, 0 SKIPPED**. The fixture runs both wave64 and wave32 and checks scalar/vector signed and unsigned high-multiply cases, including 24-bit operands, against CPU reference values. - The same GPU command with `XCL_DIRECT_DXIL=0`: **1 passed, 0 failed, 0 ignored, 0 SKIPPED**. - `mul_hi_lowers_to_dxil_wide_mul` on this head: **1 passed, 0 failed, 0 ignored** (DXIL intrinsic validation/disassembly unit test). This checks the focused GPU and DXIL tests. I did not run the full workspace suite or a paired title smoke on this PR. No claim about speed or title shader use follows from these tests. AI-assisted checkout, testing, log verification, and report drafting with OpenAI Codex (GPT-6). No game data was used.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 07:28 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 07:28 UTC · [original](https://github.com/xcl-dev/xcl/pull/2172#issuecomment-7155892905) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
Author
Owner

@⁠Toons29 on GitHub · 2026-11-25 12:05 UTC · original

Regression run of aeab3278 on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 568e7db7, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1566 (PresentX 1566)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14592 MB
xcl-smoke v1
commit: aeab32784f743a3308e995181f272e7605a974c2
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1629 (PresentX 1629)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14592 MB

Against the limits in CONTRIBUTING.md: 104 % of main's frames, 100 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; a script posted this right after the run, with both blocks exactly as printed.

**@⁠Toons29** on GitHub · 2026-11-25 12:05 UTC · [original](https://github.com/xcl-dev/xcl/pull/2172#issuecomment-7161915710) Regression run of `aeab3278` on the retail title, for this PR's **Regression run** section. Both blocks are from `scripts/smoke.ps1` as printed, not edited: `main` on `568e7db7`, this PR on its head commit with no uncommitted changes, same title and time. ``` xcl-smoke v1 commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb gpu: AMD Radeon RX 9070 title: 34df7c50 seconds: 60 exit: 0x0 frames shown: 1566 (PresentX 1566) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14592 MB ``` ``` xcl-smoke v1 commit: aeab32784f743a3308e995181f272e7605a974c2 gpu: AMD Radeon RX 9070 title: 34df7c50 seconds: 60 exit: 0x0 frames shown: 1629 (PresentX 1629) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14592 MB ``` Against the limits in CONTRIBUTING.md: 104 % of `main`'s frames, 100 % of its peak commit, no crash, no device removal. AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, `cargo build --release -p xcl`, 60 s, `XCL_NETWORK=0`. This is a regression check only: it does not show whether the run reaches the code this PR changes. AI use: Claude Code (Claude Opus 5.5) built both trees and ran `scripts/smoke.ps1`; a script posted this right after the run, with both blocks exactly as printed.
Author
Owner

@⁠raylitebull on GitHub · 2026-11-25 18:24 UTC · original

Code review on 8f131d4 (Lw::mul_hi -> umul_wide/imul_wide in lower.rs + disassembly & GPU edge-case tests): diff is clean and CI is green. Only item needed before merge: an exact-head 8f131d4 AMD GPU pass of gpu_mul_hi_edge_cases with XCL_DIRECT_DXIL=1 (previous RX 6800M run was on 3a599af and the RX 9070 smoke on eab327 leaves XCL_DIRECT_DXIL unset).

**@⁠raylitebull** on GitHub · 2026-11-25 18:24 UTC · [original](https://github.com/xcl-dev/xcl/pull/2172#issuecomment-7170873012) Code review on 8f131d4 (Lw::mul_hi -> umul_wide/imul_wide in lower.rs + disassembly & GPU edge-case tests): diff is clean and CI is green. Only item needed before merge: an exact-head 8f131d4 AMD GPU pass of gpu_mul_hi_edge_cases with XCL_DIRECT_DXIL=1 (previous RX 6800M run was on 3a599af and the RX 9070 smoke on eab327 leaves XCL_DIRECT_DXIL unset).
Author
Owner

@⁠O5-7 on GitHub · 2026-11-26 02:51 UTC · original · reviewed

Rebased onto main (b49be18) to resolve trailing conflicts in core_tests.rs and recomp/tests.rs (now at 01c4d20), and re-verified mul_hi (default + XCL_DIRECT_DXIL=1), workspace suite, and 60s smoke. Ready for an AMD XCL_DIRECT_DXIL=1 check on 01c4d20.

**@⁠O5-7** on GitHub · 2026-11-26 02:51 UTC · [original](https://github.com/xcl-dev/xcl/pull/2172#pullrequestreview-6067905106) · **reviewed** Rebased onto main (b49be18) to resolve trailing conflicts in core_tests.rs and recomp/tests.rs (now at 01c4d20), and re-verified mul_hi (default + XCL_DIRECT_DXIL=1), workspace suite, and 60s smoke. Ready for an AMD XCL_DIRECT_DXIL=1 check on 01c4d20.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 08:15 UTC · original

Re-verification on RTX 3060 Ti (Windows 11): still a merge conflict with current main on the new head — needs another rebase before it can be tested.

**@⁠DavidM1911** on GitHub · 2026-11-26 08:15 UTC · [original](https://github.com/xcl-dev/xcl/pull/2172#issuecomment-7186372244) Re-verification on RTX 3060 Ti (Windows 11): still a **merge conflict with current `main`** on the new head — needs another rebase before it can be tested.
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/2172/head:github-bot/gh-2172'
git switch 'github-bot/gh-2172'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2172'
git switch 'github-bot/gh-2172'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2172'
git switch 'github-bot/gh-2172'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2172'
git switch 'main'
git merge --squash 'github-bot/gh-2172'
git switch 'main'
git merge --ff-only 'github-bot/gh-2172'
git switch 'main'
git merge 'github-bot/gh-2172'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.