Skip to content

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

Open
O5-7 wants to merge 1 commit into
xcl-dev:mainfrom
O5-7:dxil/mul-hi-wide
Open

O5-7 wants to merge 1 commit into
xcl-dev:mainfrom
O5-7:dxil/mul-hi-wide

Conversation

@O5-7

@O5-7 O5-7 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

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: cbc296ab65a2661a61e3e2da109134bcd5319f60
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1686 (PresentX 1686)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14083 MB

PR:

xcl-smoke v1
commit: 3a599afdb71b1994ae09df4772a73c98d176bdf7
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1687 (PresentX 1687)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14076 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 VFS: exempt xcl.exe and host tool dirs from console drive mounts #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.

@luckyteagirl

Copy link
Copy Markdown
Contributor

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.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

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 xcl-dev#1269

Assisted-by: Antigravity (Gemini 4 Neon)
@Toons29

Toons29 commented Nov 25, 2026

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants