Repository navigation
Shaders: v_mad_i64_i32 sign-extends a negative literal addend - #2380
Open
Melow-code wants to merge 1 commit into
Open
Melow-code wants to merge 1 commit into
Melow-code wants to merge 1 commit into
Conversation
The addend (src2) of v_mad_i64_i32 is S2.i64 (RDNA 2 ISA section 12.12), so its 32-bit literal is sign-extended to 64 bits (section 6.2.1). The existing guard in src64 matched only names that end in _i64, and v_mad_i64_i32 ends in _i32 (the multiplied inputs), so the literal fell to the zero-extending arm. With src2 = -100, 0 * 0 + src2 gave 0x00000000_ffffff9c instead of -100. The guard now also matches v_mad_i64_i32 when the operand is src2 (k == 2). v_mad_u64_u32 keeps its zero-extending arm unchanged. Fixes Marvisak#2253. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
DenRakEiw
approved these changes
Nov 25, 2026
DenRakEiw
left a comment
There was a problem hiding this comment.
Verified against origin/main (940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:
- Sign-extending negative 32-bit literal addends for
v_mad_i64_i32is clean and passesdxil.dllvalidation (note: overlaps in scope with#2254). cargo test -p victory-shader emit::lower::tests: 22/22 passed on RTX 5090, 22/22 passed on WARP (includingv_mad_i64_i32_sign_extends_a_negative_literal_addend).cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.cargo xtask policy: 183 files ok.
AI-assisted (Gemini 4 Neon).
catminou4
approved these changes
Nov 25, 2026
catminou4
left a comment
Contributor
There was a problem hiding this comment.
Tested locally: merged into main 940d32f, cargo test -p victory-shader --locked on macOS arm64 — 145 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — third PR fixing v_mad_i64_i32 literal sign-extension (after #2254 and #2261), but the most precise of the three: the k == 2 condition restricts sign-extension to the addend (src2, S2.i64) instead of any operand of the instruction. All three conflict on the same lower.rs lines — if only one survives, I'd pick this one.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The addend (src2) of
v_mad_i64_i32isS2.i64(RDNA 2 ISA §12.12), so its 32-bit literal is sign-extended to 64 bits (§6.2.1). The existing guard insrc64matched only names that end in_i64, andv_mad_i64_i32ends in_i32(the multiplied inputs), so the literal fell to the zero-extending arm. Withsrc2 = -100,0 * 0 + src2gave0x00000000_ffffff9cinstead of-100.The guard now also matches
v_mad_i64_i32when the operand is src2 (k == 2).v_mad_u64_u32keeps its zero-extending arm unchanged.Verification
cargo test -p victory-shader --libon Linux: 145 passed, 0 failed, 2 ignored.v_mad_i64_i32_sign_extends_a_negative_literal_addend(VOP3B with literal -100 as the addend).Fixes #2253.
🤖 Generated with Claude Code
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com