shader: lower v_mul_lo_i32 and v_mad_i64_i32 #82
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/uiliannn--VItoriaBr!82
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@lcg007xd-c on GitHub · 2026-11-25 22:07 UTC · original
lcg007xd-c:shader-signed-mul→main· +119 −1 · 2 files · 1 commits · openWhat 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
VOP3 0x16B and VOP3B 0x177 decoded but failed to translate ("v_mul_lo_i32 is not supported"): the signed counterparts of v_mul_lo_u32 and v_mad_u64_u32, which already lower. v_mul_lo_i32's low 32 bits are v_mul_lo_u32's. v_mad_i64_i32 is S0.i32 * S1.i32 + S2.i64 (AMD's RDNA2 ISA) with the product sign-extended; S2 is a signed 64-bit operand, so a 32-bit literal sign-extends. Its scalar carry-out is left unwritten, so a program that reads it is refused ("a lane mask from a carry") instead of reading a guess; compilers name null there. Co-Authored-By: Claude Opus 5.5 <[email protected]>View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.