Shaders: lower v_mad_i64_i32; test the 64-bit integer vector operations against their definitions #635

Open
github-bot wants to merge 1 commit from github-bot/gh-635 into main AGit
Owner

@⁠Gruzzberry on GitHub · 2026-11-25 03:40 UTC · original
Gruzzberry:gz/int64-valu-isa → main · +136 −5 · 4 files · 1 commits · open

Summary

v_mad_u64_u32 is lowered; its signed sibling v_mad_i64_i32 (a signed 32 x 32 multiply plus a 64-bit addend, into a 64-bit result) is not, so a program using it is refused as Unsupported { what: "v_mad_i64_i32" } and its pipelines are dropped. This lowers it as the same operation on sign-extended factors, and adds a test of the 64-bit integer vector operations (the three 64-bit shifts and both multiply-adds) against the definitions in the RDNA2 instruction set document.

What is in it

  • crates/victory-shader/src/emit/lower.rs: a "v_mad_i64_i32" arm next to "v_mad_u64_u32": sign-extend both factors to 64 bits, multiply, add the 64-bit addend, write the two result dwords. The carry out is not modelled: the lane-mask value of the instruction's carry destination is Val::Missing("the carry of a signed multiply-add"), so a program that reads it is refused as for any lane mask read as data, and one that ignores it (the usual address computation) translates.
  • crates/victory-shader/src/emit/int64_tests.rs (new, registered in emit/mod.rs): two tests, one-thread compute shaders run twice (low dword of the result, then the high one) on the hardware adapter and WARP:
    • shifts_of_64_bits_use_the_low_six_bits_of_the_count: v_lshlrev_b64, v_lshrrev_b64, v_ashrrev_i64 with counts 0, 1, 31, 32, 33, 63, 64, 65 and 0xffffffc1 over 64 values built from the halves' sign and carry edges.
    • multiply_add_of_32_by_32_plus_64_matches_the_definition: v_mad_u64_u32 and v_mad_i64_i32 over eight values for each factor and four addends (0, 2^32-1, -1, and 2^63+1).
  • valu_tests.rs only gains pub(super) on five helpers the new module shares.

Before the lowering, multiply_add_of_32_by_32_plus_64_matches_the_definition stops at lower: Unsupported { offset: 36, what: "v_mad_i64_i32" }. With it, both operations and the three shifts agree with the definitions on WARP.

Does the title use it?

No: victory translate over the whole shader pack (26,148 programs, base 2119b0e) translates all of them and refuses none for this instruction. The change is coverage; the test is the main point. If you would rather have the test alone, drop the lower.rs hunk and the signed multiply-add half of the second test.

Tested

  • Machine: NVIDIA GeForce RTX 4070 12 GB, Intel i7-13700K, 64 GB, Windows 11 26200, Rust 1.98.1. Branch rebased on c96b4f2, one commit.
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean. Without --all-features it fails on c96b4f2 itself (placed_filler_twins in victory-gpu/src/resource.rs is never used); this change adds no warning.
  • cargo xtask policy: 170 files ok.
  • cargo test --workspace --locked on the RTX 4070 (default adapter, run directly): victory-shader 214 passed, 2 failed (emit::rect::tests::the_rectangle_stage_is_a_geometry_shader and rectangles_are_drawn_whole, the PSV0 validator issue of #61); every other crate passes. c96b4f2 without this change: 212 passed, the same 2 failed.
  • VICTORY_WARP=1 cargo test --workspace --locked (every GPU test on WARP): victory-shader 210 passed, 6 failed. The same 6 fail on c96b4f2 (208 passed): the two emit::rect ones, and ds_min_max_f32_order_floats_and_return_the_old_value, v_permlane16_and_x16_read_the_lanes_their_selectors_pick, whole_wave_f64_sum_and_cvt_f32_f64 and a_lane_mask_joined_with_a_number_is_read_as_the_number_it_is, which need a 32-lane device that VICTORY_WARP=1 takes away. No new failure.

Not tested

  • The carry out of v_mad_i64_i32 (not modelled; the RDNA2 document's wording for the signed form is not what I rely on).
  • 64-bit compares (open in #135) and the other 64-bit operations (v_add_co_u32 chains, f64).
  • AMD and Intel adapters.

AI use

Claude Code (Claude Sonnet 5.5) wrote the lowering and the tests and ran the checks above on my machine. The reference functions follow the RDNA2 instruction set document. Nothing is taken from the game.

🤖 Generated with Claude Code

🤖 Generated with Claude Code

**@⁠Gruzzberry** on GitHub · 2026-11-25 03:40 UTC · [original](https://github.com/fxceless/victory-fork/pull/635) `Gruzzberry:gz/int64-valu-isa` → `main` · +136 −5 · 4 files · 1 commits · open ## Summary `v_mad_u64_u32` is lowered; its signed sibling `v_mad_i64_i32` (a signed 32 x 32 multiply plus a 64-bit addend, into a 64-bit result) is not, so a program using it is refused as `Unsupported { what: "v_mad_i64_i32" }` and its pipelines are dropped. This lowers it as the same operation on sign-extended factors, and adds a test of the 64-bit integer vector operations (the three 64-bit shifts and both multiply-adds) against the definitions in the RDNA2 instruction set document. ## What is in it - `crates/victory-shader/src/emit/lower.rs`: a `"v_mad_i64_i32"` arm next to `"v_mad_u64_u32"`: sign-extend both factors to 64 bits, multiply, add the 64-bit addend, write the two result dwords. The carry out is not modelled: the lane-mask value of the instruction's carry destination is `Val::Missing("the carry of a signed multiply-add")`, so a program that reads it is refused as for any lane mask read as data, and one that ignores it (the usual address computation) translates. - `crates/victory-shader/src/emit/int64_tests.rs` (new, registered in `emit/mod.rs`): two tests, one-thread compute shaders run twice (low dword of the result, then the high one) on the hardware adapter and WARP: - `shifts_of_64_bits_use_the_low_six_bits_of_the_count`: `v_lshlrev_b64`, `v_lshrrev_b64`, `v_ashrrev_i64` with counts 0, 1, 31, 32, 33, 63, 64, 65 and `0xffffffc1` over 64 values built from the halves' sign and carry edges. - `multiply_add_of_32_by_32_plus_64_matches_the_definition`: `v_mad_u64_u32` and `v_mad_i64_i32` over eight values for each factor and four addends (0, 2^32-1, -1, and 2^63+1). - `valu_tests.rs` only gains `pub(super)` on five helpers the new module shares. Before the lowering, `multiply_add_of_32_by_32_plus_64_matches_the_definition` stops at `lower: Unsupported { offset: 36, what: "v_mad_i64_i32" }`. With it, both operations and the three shifts agree with the definitions on WARP. ## Does the title use it? No: `victory translate` over the whole shader pack (26,148 programs, base `2119b0e`) translates all of them and refuses none for this instruction. The change is coverage; the test is the main point. If you would rather have the test alone, drop the `lower.rs` hunk and the signed multiply-add half of the second test. ## Tested - Machine: NVIDIA GeForce RTX 4070 12 GB, Intel i7-13700K, 64 GB, Windows 11 26200, Rust 1.98.1. Branch rebased on `c96b4f2`, one commit. - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: clean. Without `--all-features` it fails on `c96b4f2` itself (`placed_filler_twins` in `victory-gpu/src/resource.rs` is never used); this change adds no warning. - `cargo xtask policy`: 170 files ok. - `cargo test --workspace --locked` on the RTX 4070 (default adapter, run directly): `victory-shader` 214 passed, 2 failed (`emit::rect::tests::the_rectangle_stage_is_a_geometry_shader` and `rectangles_are_drawn_whole`, the PSV0 validator issue of #61); every other crate passes. `c96b4f2` without this change: 212 passed, the same 2 failed. - `VICTORY_WARP=1 cargo test --workspace --locked` (every GPU test on WARP): `victory-shader` 210 passed, 6 failed. The same 6 fail on `c96b4f2` (208 passed): the two `emit::rect` ones, and `ds_min_max_f32_order_floats_and_return_the_old_value`, `v_permlane16_and_x16_read_the_lanes_their_selectors_pick`, `whole_wave_f64_sum_and_cvt_f32_f64` and `a_lane_mask_joined_with_a_number_is_read_as_the_number_it_is`, which need a 32-lane device that `VICTORY_WARP=1` takes away. No new failure. ## Not tested - The carry out of `v_mad_i64_i32` (not modelled; the RDNA2 document's wording for the signed form is not what I rely on). - 64-bit compares (open in #135) and the other 64-bit operations (`v_add_co_u32` chains, f64). - AMD and Intel adapters. ## AI use Claude Code (Claude Sonnet 5.5) wrote the lowering and the tests and ran the checks above on my machine. The reference functions follow the RDNA2 instruction set document. Nothing is taken from the game. 🤖 Generated with [Claude Code](https://claude.com/claude-code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
v_mad_i64_i32 (a signed 32 x 32 multiply plus a 64-bit addend into a 64-bit
result) had no lowering, so a program using it was refused as "unsupported"
and its pipelines were dropped, while its unsigned sibling v_mad_u64_u32 was
lowered. It is the same operation on sign-extended factors. The carry out is
not modelled: a program that reads it is refused as for any lane mask read
as data (the title's shader pack has no program with the instruction, so
none changes: a translate run over all 26148 programs refuses none for it).

The new test runs v_lshlrev_b64, v_lshrrev_b64, v_ashrrev_i64 (the count is
the low six bits of the first operand, including counts of 32 to 63 and
above 63) and v_mad_u64_u32 / v_mad_i64_i32 as one-thread compute shaders over
the sign and carry edges of the halves, comparing both dwords of the result
with the definition in Rust, on the hardware adapter and WARP. The two
multiply-adds and the shifts agree; before the lowering the signed
multiply-add stops the test at "Unsupported". valu_tests.rs only gains
pub(super) on the helpers the new module shares.

Assisted-by: Claude Code (Claude Sonnet 5.5)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:47:50 +00:00
Author
Owner

@⁠HAL9000RELOADED on GitHub · 2026-11-25 13:00 UTC · original

An AMD run of this PR's new tests. multiply_add_of_32_by_32_plus_64_matches_the_definition and shifts_of_64_bits_use_the_low_six_bits_of_the_count pass on a Radeon RX 7900 XTX (RDNA3), Windows 10 22H2, with the Agility SDK runtime from #402. They ran on the hardware device; WARP skips on this machine. Nothing else in the workspace regresses.

The setup, and the same run for eight related shader PRs, are in one table on #637: #637

**@⁠HAL9000RELOADED** on GitHub · 2026-11-25 13:00 UTC · [original](https://github.com/fxceless/victory-fork/pull/635#issuecomment-7163153570) An AMD run of this PR's new tests. `multiply_add_of_32_by_32_plus_64_matches_the_definition` and `shifts_of_64_bits_use_the_low_six_bits_of_the_count` pass on a Radeon RX 7900 XTX (RDNA3), Windows 10 22H2, with the Agility SDK runtime from #402. They ran on the hardware device; WARP skips on this machine. Nothing else in the workspace regresses. The setup, and the same run for eight related shader PRs, are in one table on #637: https://git.gtahub.st/github/fxceless--victory-fork/pulls/637
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/635/head:github-bot/gh-635'
git switch 'github-bot/gh-635'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-635'
git switch 'github-bot/gh-635'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-635'
git switch 'github-bot/gh-635'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-635'
git switch 'main'
git merge --squash 'github-bot/gh-635'
git switch 'main'
git merge --ff-only 'github-bot/gh-635'
git switch 'main'
git merge 'github-bot/gh-635'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.