Repository navigation
Shaders: lower v_mad_u64_u32 and v_mad_i64_i32 - #171
n-romanovich wants to merge 1 commit into
Conversation
|
Tested
No game data used. |
|
The unsigned form looks right. For #163 lowers the same two opcodes ( Static review, not built or run. |
d9c8525 to
a5af45f
Compare
|
Thanks for the review, @Sunkiller-qc! Addressed in
|
|
A note from comparing this with #163, which lowers the same two instructions: the 64-bit results agree, but the carry-out of
With the operands sign-extended to 65 bits, bit 64 is the unsigned carry out of bit 63 xor the signs of the product and the addend. The two differ when both addends are negative and the add does not overflow, e.g. I have not run this on hardware; the above is from the documents only. No game data used. |
|
Thanks, @r4tedx! This was updated in |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
RDNA2 hardware measurement of both instructions, including the carry-out discussed above: the current head ( Setup. AMD Radeon iGPU of a Ryzen 7 9800X3D, gfx1036 (RDNA2), AMD driver 32.0.21042.62, Windows 11 Pro 26200. Hand-written instructions in a HIP kernel (assembled by the AMD driver's amd_comgr). RDNA2 desktop silicon, not the console's. No game data. 748 operand sets: all combinations of
Both of your examples set the flag on the hardware: AI use: Claude Code (Claude Opus 5.5) wrote the probes, ran them on the GPU above and drafted this comment; the numbers come from the hardware run. |
catminou4
left a comment
There was a problem hiding this comment.
Merges cleanly with current main (8e79c80); cargo test -p victory-shader --locked on macOS arm64 / rustc 1.98.1 → 71 passed / 0 failed (1 ignored, Windows execution).
The lowering looks right: both v_mad_u64_u32 and v_mad_i64_i32 sign/zero-extend the 32-bit operands to i64 (can't overflow on the multiply), detect carry-out as sum < prod unsigned, and for the signed form XOR in the sign disagreement of prod/acc — the standard mad carry. Clamped forms are refused, the carry goes to lane_bits, and other writes are marked as lane-mask reads. The new valu_mad64_executes_on_gpu test is Windows-gated (validator + host execution), so CI covers it; I can't run it here.
One note: the victory-gpu/src/host.rs hunk (mod tests → mod batch) is already on main — it merges as a no-op, so the PR's real content is just the shader lowering + test.
|
Tested head Merged onto current There's no text conflict, so GitHub still shows the PR as mergeable, but merging it as it is would break With
AI-assisted (Claude Code). |
|
Merged onto Checked with CI's steps (both clippy runs with |
|
Thanks for testing and pointing this out, @alexdeliu! Merged latest main and updated resource::track in the test to pass Some(&st) per 6638098. Verified with cargo clippy --all-targets --locked -- -D warnings and re-ran the GPU test — both compile cleanly and pass with 0 warnings. |
|
@n-romanovich rechecked |
|
Automated triage for the maintainers. Recommended for a maintainer's look. The verdict hasn't changed. The new head is a rebase onto current A small optional addition: the two signed cases in CI: passing. Generated by Claude Code |
|
@Marvisak, thanks for the review. In 6b5e0b4, I removed the redundant flags::INT64 assignment (as src64 already sets it) and updated the PR description to reflect the 65-bit carry rule. |
953f4da to
25d8524
Compare
25d8524 to
d1d21f9
Compare
|
Verification on Windows 10 19045 (RX 7800 XT), your head
On the carry, I checked the formula rather than only the test: for the signed form One thing worth a line in the PR body, if you agree: the previous code only wrote the carry for the unsigned form, so this changes |
Summary
emit::lowerpreviously loweredv_mad_u64_u32andv_mad_i64_i32incrates/victory-shader/src/emit/lower.rs, but only emitted the carry-out lane mask (SDST) for the unsigned form, causing shaders that readv_mad_i64_i32'sSDSTto be refused.This PR adds signed carry-out for
v_mad_i64_i32as bit 64 of the exact 65-bit result, refusesclampon both instructions, and adds a GPU execution test.Changes
crates/victory-shader/src/emit/lower.rs(v_mad_u64_u32|v_mad_i64_i32):v.clampwithErr("a clamped integer operation").sum = prod + accand unsigned carryucarry = sum < prod(equivalent tosum < acc).v_mad_i64_i32(signed == true), derive the signed carry-out (bit 64 of the exact 65-bit signed result) asucarry ^ (prod < 0) ^ (acc < 0)and writecarrytoself.lane_bitsforv.carryon both signed and unsigned forms.crates/victory-shader/src/emit/mod.rs(emit::tests::valu_mad64_executes_on_gpu):v_mad_u64_u32andv_mad_i64_i32carry-out across-3 * 5 + 0,-3 * 5 + 25, and-15 + i64::MIN, as well asv.clamprefusal.Verification
cargo test -p victory-shader --locked -- mad64:1 passed; 0 failed(emit::tests::valu_mad64_executes_on_gpu ... ok).