Shaders: sign-extend the v_mad_i64_i32 literal addend #2261
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2261
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2261/head"
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?
@Calvix2k on GitHub · 2026-11-25 09:17 UTC · original
Calvix2k:codex/shader-mad-i64-literal-2253→main· +54 −4 · 3 files · 2 commits · closed without mergingFixes #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, #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.
@Calvix2k on GitHub · 2026-11-25 09:40 UTC · original
Closing in favour of #2254 (@BastienRodz), which has the same
src64change and is already verified on hardware (GTX 1050 via Agility, @kotekompotek) and integrated with #171 (@Dathinel). Two PRs for one arm only splits the review; nothing here is lost.@BastienRodz if you want the extra coverage: this branch also checks the emitted DXIL (
add i64 %x, -100, so the sign extension is visible without a GPU) and reads the high dword of0 * 0 + -100and10 * 10 + -100with the unsigned form as a control. Both are incodex/shader-mad-i64-literal-2253if you would rather fold them in than have them disappear; otherwise your test plus the hardware runs are enough.Pull request closed