shader: lower v_mul_lo_i32 and v_mad_i64_i32 #82
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/82"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from uiliannn/VItoriaBr. Originally posted by lcg007xd-c on 2026-11-25T22:07:45Z.
What is broken
v_mul_lo_i32(VOP3 0x16B) andv_mad_i64_i32(VOP3B 0x177) decode, but a program using either fails to translate withv_mul_lo_i32 is not supported(orv_mad_i64_i32 …). They are the signed counterparts ofv_mul_lo_u32andv_mad_u64_u32, which already lower. I found them by translating a one-instruction program for every VOP3 opcode the decoder names. LLVM emitsv_mad_i64_i32for 32×32→64 signed multiplies, so it appears in any 64-bit index math on signed values.Semantics (AMD's RDNA2 ISA, §12.12, opcodes 363 and 375)
v_mul_lo_i32:D.i = S0.i * S1.i, low 32 bits. These are the same bits asv_mul_lo_u32.v_mad_i64_i32:{vcc_out, D.i64} = S0.i32 * S1.i32 + S2.i64. The product is sign-extended, and S2 is a signed 64-bit operand.The change (
emit/lower.rs)v_mul_lo_i32: joinsv_mul_lo_u32's arm ininteger.v_mad_i64_i32(invalu_op): the operands are sign-extended to i64, multiplied, and added to S2. The result is written to the VGPR pair._i64forms.src64's name test (ends_with("_i64")) does not matchv_mad_i64_i32, so this arm does it.a lane mask from a carry is not supported) rather than given a guess. Compilers putnullthere.Tests
emit::lower::tests::signed_multiplies_translate(every host):nulland to an SGPR pair nobody reads;v_mad_i64_i32's carry-out is refused with a carry message, while the same read ofv_mad_u64_u32's still translates.Without the
lower.rschange it fails:v_mul_lo_i32 [d56b0000, 00020501]: GFX10 code at 0x24: v_mul_lo_i32 is not supported.valu_tests::signed_multiplies_match_rdna2(Windows/GPU):v_mul_lo_i32on −3×7 and 0x10001².v_mad_i64_i32is checked on both result dwords: −1×5,i32::MIN²= 2⁶²,i32::MAX×−1 + 10, and 3×4 +0xFFFFFFFFcarrying into the high dword.CPU run: I ran these on Linux through the CPU harness of #62, which runs the emitted DXIL with LLVM's
lli. I compared against Rust'swrapping_mul/wrapping_addon all 81 pairs of 9 edge values, times 5 accumulators forv_mad_i64_i32, on both dwords. I also checked a literal−2accumulator (sign-extended:1·1 − 2 = 0xFFFFFFFF_FFFFFFFF). All match.Run here (Linux, Rust 1.98.1):
cargo test -p victory-shader --lib --locked: 188 passed, 0 failed, 2 ignored.CARGO_FEATURE_PURE=1 cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings: clean.Not run here: the GPU case, since I have no Windows machine.
🤖 Generated with Claude Code
Imported from uiliannn/VItoriaBr. Originally posted by lmouz823-lang on 2026-11-28T08:26:20Z.
I can take native Windows signed-multiply validation at exact head
f4242ab1cd48428ac3f2cdf5bd42f840247ad30c. I will run the existing translation/refusal and GPU regressions, then add focused fixed-expectation coverage for signed literal accumulators and result-dword boundaries. The signed carry-read refusal and unsigned control will remain part of acceptance. A targeted negative control, fresh restored-source runs, SDK validation evidence and explicit skipped/native AMD/game scope will accompany the result. AI-assisted with Codex.Imported from uiliannn/VItoriaBr. Originally posted by lmouz823-lang on 2026-11-28T08:54:20Z.
Windows validation of
f4242abI checked head
f4242ab1cd48428ac3f2cdf5bd42f840247ad30cagainst base081a89d2e5767beb38c94e2f4adc7eeca0ad69dband prepared a small additional regression test.Environment and execution
x86_64-pc-windows-msvc, release profile, locked dependencies.VICTORY_STRICT_TESTS=1, explicitVICTORY_DXILpointing to Windows SDK 10.0.26100.0 x64dxil.dll, file version 1.8.2502.11. A temporary diagnostic run recorded successful validator load, validation, and container-hash checks for all 3 original and 4 added shader modules. The submitted patch contains the regression test.emit::lower::tests::signed_multiplies_translateemit::valu_tests::signed_multiplies_match_rdna2emit::valu_tests::signed_mad_wraps_and_sign_extends_literal_accumulatorsEach command used
cargo test --release --locked -p victory-shader --lib <exact-name> -- --exact --nocapture --test-threads=1. Each selected exactly one test. No selected final case reported a skip.The existing translation test continues to accept null and unread signed carry destinations, refuse a read of signed MAD carry-out, and accept the unsigned MAD carry-read control.
Additional coverage and negative control
The attached 55-line test adds fixed expected bit patterns for signed 64-bit wraparound, register accumulator sign boundaries, and literal
0xFFFFFFFEsign extension. It reads both destination dwords through v[5:6], preserving v1..v4 inputs. Register cases account for2 dwords × 6 inputs × 2 backends = 24dispatches, and literal cases for2 × 4 × 2 = 16.The result-dword calculations follow signed 32-bit multiplication and a signed 64-bit accumulator. The i64 literal conversion is also documented as sign extension from 32 bits. AMD RDNA2 ISA, V_MAD_I64_I32, LLVM AMDGPU integer operand conversion
For a targeted negative control, I temporarily changed only the signed MAD literal accumulator conversion from
i64::from(l as i32)toi64::from(l). The original GPU test still passed on both adapters. The added test failed on NVIDIA at literal-2, input[1, 1, 0, 0], high result dword, with actual0x00000000and expected0xFFFFFFFFand cargo exit 101. This establishes that the added coverage detects that specific regression. The deliberate failure stopped later negative cases and the WARP negative run.I then restored
lower.rsbyte-for-byte, removed diagnostic logging, cleaned only the isolatedvictory-shaderrelease outputs, and rebuilt the final test binary in 1m41s. All three final exact tests above passed after that real rebuild.Static checks and scope
--all-targets -- -D warnings, the 195-file asset policy check, andgit diff --checkpassed.The patch was prepared with AI assistance and checked locally. Patch SHA-256
d3f8cd7a50d44f9fe2efc307f7779d931c792425b5e44385afd56f55768da994.Complete regression-test patch
Pull request closed