Repository navigation
Conversation
`src64` sign-extends a 32-bit literal only when the instruction name ends in `_i64`, so `v_mad_i64_i32`'s `S2.i64` took the zero-extending arm: with a literal -100 the high dword came out 0 instead of all ones, and a sum that crossed 2^32 set it to 1. RDNA 2 expands a literal for a 64-bit signed operand by sign extension (ISA "Literal Expansion to 64 bits", `V_MAD_I64_I32`'s `S2.i64`), while `v_mad_u64_u32`'s `S2.u64` is unsigned and keeps zero-extending. Tests: the emitted DXIL carries the signed literal, and a GPU case reads the high dword of `0 * 0 + -100` (all ones) and of `10 * 10 + -100` (0).
DenRakEiw
left a comment
There was a problem hiding this comment.
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 mad_64_bit_addend— 2 passed, 0 failed on both RTX 5090 hardware andVICTORY_D3D12_WARP=1cargo clippy -p victory-shader --all-targets— 0 warningscargo xtask policy— ok (183 files ok)
Clean sign-extension of v_mad_i64_i32 literal addends with both DXIL and end-to-end GPU+WARP test coverage. (Note for triage: overlaps #2254.)
AI-assisted (Gemini 4 Neon).
The shared dxc dump helper used one temp name per process, so the interpolation test and the new mad test could overwrite each other's container when they ran in parallel.
|
Closing in favour of #2254 (@BastienRodz), which has the same @BastienRodz if you want the extra coverage: this branch also checks the emitted DXIL ( |
catminou4
left a comment
There was a problem hiding this comment.
Tested locally: merged into main 940d32f, cargo test -p victory-shader --locked on macOS arm64 — 144 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — sign-extends the v_mad_i64_i32 literal addend (S2.i64 signed despite the _i32 name), plus the dump_dxil per-call temp file fix for parallel tests. Superset of #2254; see my note there.
Lower the signed and unsigned 32-by-32 MAD with a 64-bit addend and preserve its carry result. Use the signed source type for arithmetic shifts and integer compares. Exercise both result words on WARP. Ported from Marvisak/VIctory#2261 (440da6e) by Calvix2k.
Fixes #2253.
Problem
Lower::src64sign-extends a 32-bit literal only when the instruction's name ends in_i64(the rule added in #447).v_mad_i64_i32ends in_i32, so its 64-bit addendS2.i64was zero-extended:0 * 0 + (-100)produced0x0000_0000_FFFF_FF9Cinstead of0xFFFF_FFFF_FFFF_FF9C, and10 * 10 + (-100)set the high dword to 1 instead of 0.RDNA 2 expands a literal for a 64-bit signed operand by sign extension (ISA "Literal Expansion to 64 bits"; §12.12,
V_MAD_I64_I32:{vcc_out, D.i64} = S0.i32 * S1.i32 + S2.i64).v_mad_u64_u32'sS2.u64is unsigned and keeps zero-extending.Change
src64's literal arm takesv_mad_i64_i32's addend as signed as well (that instruction only passes itsS2throughsrc64).v_mad_u64_u32, the_u32/bit forms andv_mad_i64_i32's i32 multiplicands are untouched.Verification
mad_64_bit_addend_lowers_to_the_signed_literal(no GPU,dxc -dumpbinthrough the sharedemit::tests::dump_dxil): the DXIL isadd i64 %24, -100, i.e. the sign-extended literal. Made the shared helperpub(super)to use it instead of a copy.mad_64_bit_addend_sign_extends_its_literal: GPU case reading the high dword —0 * 0 + -100gives all ones,10 * 10 + -100gives 0, and the same literal withv_mad_u64_u32gives 0. Skips on this host (no SM 6.6 device, Shader tests: skip the GPU suites a device cannot run #1991 is not in this branch) and runs in CI.cargo clippy -p victory-shader --all-targets -- -D warnings: clean;cargo xtask policy3 files ok.The rest of the shader lib suite here still shows the known SM-6.6 environment failures (no device), unrelated.