Shaders: SCC of s_min, s_max and s_lshl1-4_add_u32 as the ISA sets it #168

Open
Dufftwt wants to merge 1 commit from upstream-pr/168 into main
Dufftwt commented 2026-11-24 01:03:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dufftwt on 2026-11-24T01:03:32Z.


What's wrong

On the console GPU, many scalar instructions also set a 1-bit flag, SCC, which later instructions can test. s_cselect picks between two values on it, and s_cbranch_scc0/1 branches on it. ir.rs correctly marks these instructions as writing SCC:

  • s_min_i32, s_min_u32, s_max_i32, s_max_u32
  • s_lshl1_add_u32, s_lshl2_add_u32, s_lshl3_add_u32, s_lshl4_add_u32

Their lowering in lower.rs doesn't say what SCC becomes, so it falls back to the generic rule "SCC = result is not zero". The ISA defines SCC differently for these instructions:

instruction SCC on the hardware SCC today
s_min_* 1 if src0 is the value chosen (src0 < src1) result ≠ 0
s_max_* 1 if src0 is the value chosen (src0 > src1) result ≠ 0
s_lshlN_add_u32 1 if (src0 << N) + src1 overflows 32 bits result ≠ 0

For s_lshlN_add_u32, the overflow includes bits shifted out of src0. The RDNA3 reference writes the pseudocode with a 64-bit intermediate.

Examples of what goes wrong today:

s_min_u32 s0, 5, 3         -> picks 3 (src1)  -> SCC should be 0, we give 1
s_lshl1_add_u32 s0, 1, -2  -> 2 + 0xFFFFFFFE = 0 with a carry -> SCC should be 1, we give 0
s_lshl1_add_u32 s0, 1, -3  -> 0xFFFFFFFF, no carry            -> SCC should be 0, we give 1

Any s_cselect or s_cbranch_scc* that reads SCC after one of these takes the wrong side. Compilers don't often read SCC after these instructions (LLVM never does), but it is legal ISA, and the translated code should behave like the hardware when a shader does.

What the fix does

Two small changes in lower.rs, in the same style as the existing carry handling of s_add_u32 / s_addc_u32:

  • min/max: the comparison that already picks the result is now also returned as SCC.
  • lshlN_add: SCC is "src0 had bits shifted out" OR "the add wrapped around" (result < src0 << N, unsigned).

How it behaves after the fix

  • SCC after these 8 instructions matches the hardware, so selects and branches on it go the right way.
  • The values they write to their destination register are unchanged.

Tests

There are two new tests in valu_tests.rs, using the synthetic-shader harness from #37. Each test runs the instruction on two inputs, reads SCC back with s_cselect_b32 s13, 1, 0, and stores it:

  • s_min_and_s_max_set_scc_when_src0_is_chosen: all four min/max forms, with src0 chosen, src1 chosen, and equal inputs.
  • s_lshl_add_sets_scc_on_unsigned_overflow: s_lshl1_add_u32 and s_lshl4_add_u32, with no overflow, overflow through the add, and overflow through the shift.

I ran cargo test -p victory-shader on GitHub's windows-latest with Rust 1.98.1 from rust-toolchain.toml. There's no GPU there, so the harness runs the shaders on WARP. Results:

  • This PR: both new tests pass; the shader crate has 71 passed and 0 failed.

  • The new tests alone on main: both fail. SCC is 1 where the hardware gives 0 (left: 1, right: 0), because the result is non-zero.

  • With --test-threads=4, the test process sometimes crashes on that runner (STATUS_ACCESS_VIOLATION) before reporting the GPU tests. Unmodified main does this too: it crashed in 3 of 3 runs. So the numbers above come from --test-threads=1 runs, which are clean.

  • I tested only the shader crate: cargo test --workspace doesn't build on main right now, because of a duplicate mod tests in victory-gpu/src/host.rs, which #129 fixes.

Not tested: a real GPU, or a title's shaders that use these instructions.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6572208610 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/168). Originally posted by [Dufftwt](https://github.com/Dufftwt) on 2026-11-24T01:03:32Z. --- ## What's wrong On the console GPU, many scalar instructions also set a 1-bit flag, SCC, which later instructions can test. `s_cselect` picks between two values on it, and `s_cbranch_scc0/1` branches on it. `ir.rs` correctly marks these instructions as writing SCC: - `s_min_i32`, `s_min_u32`, `s_max_i32`, `s_max_u32` - `s_lshl1_add_u32`, `s_lshl2_add_u32`, `s_lshl3_add_u32`, `s_lshl4_add_u32` Their lowering in `lower.rs` doesn't say *what* SCC becomes, so it falls back to the generic rule "SCC = result is not zero". The ISA defines SCC differently for these instructions: | instruction | SCC on the hardware | SCC today | |---|---|---| | `s_min_*` | 1 if **src0** is the value chosen (`src0 < src1`) | result ≠ 0 | | `s_max_*` | 1 if **src0** is the value chosen (`src0 > src1`) | result ≠ 0 | | `s_lshlN_add_u32` | 1 if `(src0 << N) + src1` **overflows 32 bits** | result ≠ 0 | For `s_lshlN_add_u32`, the overflow includes bits shifted out of src0. The RDNA3 reference writes the pseudocode with a 64-bit intermediate. Examples of what goes wrong today: ``` s_min_u32 s0, 5, 3 -> picks 3 (src1) -> SCC should be 0, we give 1 s_lshl1_add_u32 s0, 1, -2 -> 2 + 0xFFFFFFFE = 0 with a carry -> SCC should be 1, we give 0 s_lshl1_add_u32 s0, 1, -3 -> 0xFFFFFFFF, no carry -> SCC should be 0, we give 1 ``` Any `s_cselect` or `s_cbranch_scc*` that reads SCC after one of these takes the wrong side. Compilers don't often read SCC after these instructions (LLVM never does), but it is legal ISA, and the translated code should behave like the hardware when a shader does. ## What the fix does Two small changes in `lower.rs`, in the same style as the existing carry handling of `s_add_u32` / `s_addc_u32`: - **min/max:** the comparison that already picks the result is now also returned as SCC. - **lshlN_add:** SCC is "src0 had bits shifted out" OR "the add wrapped around" (`result < src0 << N`, unsigned). ## How it behaves after the fix - SCC after these 8 instructions matches the hardware, so selects and branches on it go the right way. - The values they write to their destination register are unchanged. ## Tests There are two new tests in `valu_tests.rs`, using the synthetic-shader harness from #37. Each test runs the instruction on two inputs, reads SCC back with `s_cselect_b32 s13, 1, 0`, and stores it: - `s_min_and_s_max_set_scc_when_src0_is_chosen`: all four min/max forms, with src0 chosen, src1 chosen, and equal inputs. - `s_lshl_add_sets_scc_on_unsigned_overflow`: `s_lshl1_add_u32` and `s_lshl4_add_u32`, with no overflow, overflow through the add, and overflow through the shift. I ran `cargo test -p victory-shader` on GitHub's `windows-latest` with Rust 1.98.1 from `rust-toolchain.toml`. There's no GPU there, so the harness runs the shaders on WARP. Results: - **This PR:** both new tests pass; the shader crate has 71 passed and 0 failed. - **The new tests alone on `main`:** both fail. SCC is 1 where the hardware gives 0 (`left: 1, right: 0`), because the result is non-zero. - With `--test-threads=4`, the test process sometimes crashes on that runner (`STATUS_ACCESS_VIOLATION`) before reporting the GPU tests. Unmodified `main` does this too: it crashed in 3 of 3 runs. So the numbers above come from `--test-threads=1` runs, which are clean. - I tested only the shader crate: `cargo test --workspace` doesn't build on `main` right now, because of a duplicate `mod tests` in `victory-gpu/src/host.rs`, which #129 fixes. **Not tested:** a real GPU, or a title's shaders that use these instructions.
catminou4 commented 2026-11-24 06:45:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T06:45:19Z.

Review: COMMENTED


Verified locally on macOS 26 arm64, rustc 1.98.1 (aarch64-apple-darwin) at head ae8967c:

  • cargo test -p victory-shader --locked: compiles clean, all ungated tests pass (no regressions vs main's 56).

Scope note: valu_tests/image_tests in victory-shader are #[cfg(all(test, windows))] — they need the Windows host backend (D3D12/dxil.dll), so they did not run here. What I verified is compilation on macOS plus all ungated tests. For this PR that means the new SCC checks in valu_tests.rs still needs a Windows run before merge — I can't execute it on this machine. The lowering changes themselves compile everywhere.

<!-- greyfinch-sync:Marvisak/VIctory:review:6034816694 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/168#pullrequestreview-6034816694). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T06:45:19Z. **Review:** COMMENTED --- Verified locally on macOS 26 arm64, rustc 1.98.1 (aarch64-apple-darwin) at head ae8967c: - `cargo test -p victory-shader --locked`: compiles clean, all ungated tests pass (no regressions vs main's 56). Scope note: `valu_tests`/`image_tests` in victory-shader are `#[cfg(all(test, windows))]` — they need the Windows host backend (D3D12/dxil.dll), so they did **not** run here. What I verified is compilation on macOS plus all ungated tests. For this PR that means the new SCC checks in `valu_tests.rs` still needs a Windows run before merge — I can't execute it on this machine. The lowering changes themselves compile everywhere.
DaviTostes commented 2026-11-24 06:54:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T01:19:31Z.


Tested ae8967c on Arch Linux x86_64, rustc 1.98.1: pass.

  • cargo test -p victory-shader: 56 passed, 0 failed (2 test binaries), including the 2 tests this PR adds.
  • The full workspace still needs #112 for the victory-gpu E0425.

No game data used.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118987575 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/168#issuecomment-7118987575). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T01:19:31Z. --- Tested `ae8967c` on **Arch Linux x86_64, rustc 1.98.1**: **pass**. - `cargo test -p victory-shader`: **56 passed, 0 failed** (2 test binaries), including the 2 tests this PR adds. - The full workspace still needs #112 for the `victory-gpu` E0425. No game data used.
upipibi commented 2026-11-24 06:56:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-24T05:33:22Z.


Independent check of this PR (head ae8967c, merged onto main d2a4bae; it merges cleanly). I found nothing wrong.

Against the RDNA2 ISA (30-November-2020), 12.1 "SOP2 Instructions"

  • s_min_i32 / s_min_u32 (opcodes 6, 7; pp. 102-103): SCC = (S0.i < S1.i) / SCC = (S0.u < S1.u). s_max_i32 / s_max_u32 (opcodes 8, 9): SCC = (S0.i > S1.i) / SCC = (S0.u > S1.u). The comparisons are strict, so equal operands give SCC = 0. lower.rs:2616-2623 returns the same strict compare (IULT/SLT/IUGT/SGT) that already picks the result, so result and SCC cannot disagree. Correct.
  • s_lshl1..4_add_u32 (opcodes 46-49; pp. 105-106): SCC = (((S0.u << N) + S1.u) >= 0x100000000ULL ? 1 : 0). The 64-bit constant means bits shifted out of S0 count; the RDNA3 reference spells that out (tmp = (64'U(S0.u) << 1U) + 64'U(S1.u)). lower.rs:2599-2611 computes (a >> (32 - N)) != 0 || (t + b) <u t, which equals the 64-bit test for N = 1..4 (the shift amount 32 - N is 28..31, never 32). Correct.

The PR's tests. Their expected values match the ISA formulas by hand; they are not taken from the code. What they leave out, none of which fails:

  • the unsigned forms are only tested with small values (3, 5, 4), so a signed predicate in s_min_u32 / s_max_u32 would pass them; one case with bit 31 set, e.g. s_min_u32(0x80000000, 1) -> SCC 0, would pin that;
  • no INT_MIN / INT_MAX for the signed forms; equal operands only as (4, 4);
  • s_min_u32(0, 1): result 0 and SCC 1, the one min case where the old "result != 0" rule gives 0 instead of 1;
  • s_lshl2_add_u32 and s_lshl3_add_u32 are not run at all;
  • no case with both a shifted-out bit and an add carry, and no add-only carry that leaves a zero result (s_lshl1_add_u32(0x40000000, 0x80000000));
  • SCC is only read through s_cselect_b32, not through s_cbranch_scc0/1, and never with the destination over src0.

Run on hardware. cargo test -p victory-shader -- --test-threads=1, NVIDIA RTX 3070, driver 616.56, Windows 11, Rust 1.98.1, dxil.dll from the Windows SDK 10.0.26100 loaded (so modules are validated), hardware and WARP:

  • this PR on main: 71 passed, 0 failed (69 on main plus the PR's two).
  • with three extra local tests covering the list above: 74 passed, 0 failed. They run 57 SCC cases over all eight opcodes, each read three ways (s_cselect_b32; destination = src0; s_cbranch_scc0), plus one destination-value check per opcode. Among them: s_min_i32(0x80000000, 0x7fffffff) -> 1, s_max_i32(0x80000000, 0x80000000) -> 0, s_max_u32(0xffffffff, 0) -> 1, s_lshl2_add_u32(0x80000000, 0) -> 1 (shifted out only, result 0), s_lshl3_add_u32(0x10000000, 0x80000000) -> 1 (add carry only, result 0), s_lshl4_add_u32(0x08000000, 0x7fffffff) -> 0.

Not checked: AMD hardware (the expected values are the ISA's; an NVIDIA run shows only that the translated DXIL computes them), literal-constant operands, a title's shaders.

Suggestion, optional: add one bit-31 case to each unsigned form and run s_lshl2/s_lshl3 once. I can send the cases if useful.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123057807 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/168#issuecomment-7123057807). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-24T05:33:22Z. --- Independent check of this PR (head `ae8967c`, merged onto `main` `d2a4bae`; it merges cleanly). I found nothing wrong. **Against the RDNA2 ISA (30-November-2020), 12.1 "SOP2 Instructions"** - `s_min_i32` / `s_min_u32` (opcodes 6, 7; pp. 102-103): `SCC = (S0.i < S1.i)` / `SCC = (S0.u < S1.u)`. `s_max_i32` / `s_max_u32` (opcodes 8, 9): `SCC = (S0.i > S1.i)` / `SCC = (S0.u > S1.u)`. The comparisons are strict, so equal operands give SCC = 0. `lower.rs:2616-2623` returns the same strict compare (`IULT`/`SLT`/`IUGT`/`SGT`) that already picks the result, so result and SCC cannot disagree. Correct. - `s_lshl1..4_add_u32` (opcodes 46-49; pp. 105-106): `SCC = (((S0.u << N) + S1.u) >= 0x100000000ULL ? 1 : 0)`. The 64-bit constant means bits shifted out of S0 count; the RDNA3 reference spells that out (`tmp = (64'U(S0.u) << 1U) + 64'U(S1.u)`). `lower.rs:2599-2611` computes `(a >> (32 - N)) != 0 || (t + b) <u t`, which equals the 64-bit test for N = 1..4 (the shift amount 32 - N is 28..31, never 32). Correct. **The PR's tests.** Their expected values match the ISA formulas by hand; they are not taken from the code. What they leave out, none of which fails: - the unsigned forms are only tested with small values (3, 5, 4), so a signed predicate in `s_min_u32` / `s_max_u32` would pass them; one case with bit 31 set, e.g. `s_min_u32(0x80000000, 1)` -> SCC 0, would pin that; - no `INT_MIN` / `INT_MAX` for the signed forms; equal operands only as (4, 4); - `s_min_u32(0, 1)`: result 0 and SCC 1, the one min case where the old "result != 0" rule gives 0 instead of 1; - `s_lshl2_add_u32` and `s_lshl3_add_u32` are not run at all; - no case with both a shifted-out bit and an add carry, and no add-only carry that leaves a zero result (`s_lshl1_add_u32(0x40000000, 0x80000000)`); - SCC is only read through `s_cselect_b32`, not through `s_cbranch_scc0/1`, and never with the destination over src0. **Run on hardware.** `cargo test -p victory-shader -- --test-threads=1`, NVIDIA RTX 3070, driver 616.56, Windows 11, Rust 1.98.1, `dxil.dll` from the Windows SDK 10.0.26100 loaded (so modules are validated), hardware and WARP: - this PR on `main`: **71 passed, 0 failed** (69 on `main` plus the PR's two). - with three extra local tests covering the list above: **74 passed, 0 failed**. They run 57 SCC cases over all eight opcodes, each read three ways (`s_cselect_b32`; destination = src0; `s_cbranch_scc0`), plus one destination-value check per opcode. Among them: `s_min_i32(0x80000000, 0x7fffffff)` -> 1, `s_max_i32(0x80000000, 0x80000000)` -> 0, `s_max_u32(0xffffffff, 0)` -> 1, `s_lshl2_add_u32(0x80000000, 0)` -> 1 (shifted out only, result 0), `s_lshl3_add_u32(0x10000000, 0x80000000)` -> 1 (add carry only, result 0), `s_lshl4_add_u32(0x08000000, 0x7fffffff)` -> 0. Not checked: AMD hardware (the expected values are the ISA's; an NVIDIA run shows only that the translated DXIL computes them), literal-constant operands, a title's shaders. Suggestion, optional: add one bit-31 case to each unsigned form and run `s_lshl2`/`s_lshl3` once. I can send the cases if useful. AI-assisted (Claude Code).
Lyrnc commented 2026-11-24 06:56:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Lyrnc on 2026-11-24T06:26:42Z.


RDNA2 hardware measurement of the SCC rules in the table: all match, including the shifted-out bits for s_lshlN_add_u32.

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. 141 operand pairs: all pairs of 0, 1, 2, 0x7fffffff, 0x80000000, 0xffffffff, 0x40000000, 0xc0000000, 0x12345678, plus 60 random. SCC was read with s_cselect right after each instruction.

SCC rule match
s_min_i32 / s_min_u32 src0 < src1 (signed / unsigned) 141/141 each
s_max_i32 / s_max_u32 src0 > src1 141/141 each
s_lshl1..4_add_u32 (src0 << N) + src1 >= 2^32 in 64 bits 141/141 each
(alternative: carry of the 32-bit add only) 108, 85, 81, 76 of 141

For example, s_lshl1_add_u32 0x80000000, 0 gives result 0 with SCC = 1: the shifted-out bit counts. s_lshl2_add_u32 0x7fffffff, 0 gives 0xfffffffc with SCC = 1. The results themselves match too.

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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123939392 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/168#issuecomment-7123939392). Originally posted by [Lyrnc](https://github.com/Lyrnc) on 2026-11-24T06:26:42Z. --- RDNA2 hardware measurement of the SCC rules in the table: **all match**, including the shifted-out bits for `s_lshlN_add_u32`. **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. 141 operand pairs: all pairs of `0, 1, 2, 0x7fffffff, 0x80000000, 0xffffffff, 0x40000000, 0xc0000000, 0x12345678`, plus 60 random. SCC was read with `s_cselect` right after each instruction. | | SCC rule | match | |---|---|---| | `s_min_i32` / `s_min_u32` | src0 < src1 (signed / unsigned) | 141/141 each | | `s_max_i32` / `s_max_u32` | src0 > src1 | 141/141 each | | `s_lshl1..4_add_u32` | `(src0 << N) + src1 >= 2^32` in 64 bits | 141/141 each | | (alternative: carry of the 32-bit add only) | | 108, 85, 81, 76 of 141 | For example, `s_lshl1_add_u32 0x80000000, 0` gives result 0 with **SCC = 1**: the shifted-out bit counts. `s_lshl2_add_u32 0x7fffffff, 0` gives `0xfffffffc` with SCC = 1. The results themselves match too. 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.
Damasque commented 2026-11-24 06:56:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Damasque on 2026-11-24T06:40:00Z.


Both new SCC tests passed at ae8967c on an AMD Radeon RX 6700 XT (driver 32.0.21045.29003, Windows, Rust 1.98.1). I ran each test individually and verified the dispatch device by D3D12 adapter LUID. The RX 6700 XT completed all 12 min/max cases and all 7 shift/add cases. The separate WARP passes also passed, with no hardware skips or fallback.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7124167351 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/168#issuecomment-7124167351). Originally posted by [Damasque](https://github.com/Damasque) on 2026-11-24T06:40:00Z. --- Both new SCC tests passed at ae8967c on an AMD Radeon RX 6700 XT (driver 32.0.21045.29003, Windows, Rust 1.98.1). I ran each test individually and verified the dispatch device by D3D12 adapter LUID. The RX 6700 XT completed all 12 min/max cases and all 7 shift/add cases. The separate WARP passes also passed, with no hardware skips or fallback.
tjthebigbearcat-hub commented 2026-11-24 21:55:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by tjthebigbearcat-hub on 2026-11-24T21:55:04Z.

Review: APPROVED


Verified this independently on Windows (hardware D3D12 adapter and WARP) on top of current main (ffe310e).

Results

  • cargo test --workspace --locked: passes, including s_min_and_s_max_set_scc_when_src0_is_chosen and s_lshl_add_sets_scc_on_unsigned_overflow (victory-shader: 122 passed, 1 ignored).
  • cargo clippy --workspace --all-targets --locked -- -D warnings: 0 warnings.
  • Independent ISA sweep (tested locally, not part of this PR diff): For all eight instructions (s_{min,max}_{i32,u32}, s_lshl{1,2,3,4}_add_u32), compared both result and SCC against RDNA 2 ISA reference models across 265 input pairs each (a 15×15 edge grid around 0, ±1, 2^28–2^31, and 0xFFFFFFFx, plus 40 random pairs) on both adapters: 0 mismatches. On main, the same sweep fails for all eight since SCC falls through to result != 0.

Code

  • min/max: SCC uses the select's own comparison, so equal operands give SCC = 0 (src1 chosen), matching the ISA.
  • lshlN_add: (src0 >> (32 − n)) != 0 || r < t covers both overflow paths, and with n in 1..=4 the shift is never 32 bits.

Why it matters: Beyond s_cselect / s_cbranch_scc, the s_lshlN_add_u32 carry feeds s_addc_u32 during 64-bit address calculation (base + (idx << n)). With the old result != 0, the high dword picks up a spurious +1 whenever the low result is non-zero, shifting addresses off by 4 GiB silently.

Nit (optional): The in-tree test covers s_lshl1 and s_lshl4 but not s_lshl2/s_lshl3 (they share the exact same code path and passed the sweep above, so extra cases are purely for completeness).

LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:review:6048026538 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/168#pullrequestreview-6048026538). Originally posted by [tjthebigbearcat-hub](https://github.com/tjthebigbearcat-hub) on 2026-11-24T21:55:04Z. **Review:** APPROVED --- Verified this independently on Windows (hardware D3D12 adapter and WARP) on top of current `main` (`ffe310e`). ### Results - `cargo test --workspace --locked`: passes, including `s_min_and_s_max_set_scc_when_src0_is_chosen` and `s_lshl_add_sets_scc_on_unsigned_overflow` (`victory-shader`: 122 passed, 1 ignored). - `cargo clippy --workspace --all-targets --locked -- -D warnings`: **0 warnings**. - **Independent ISA sweep (tested locally, not part of this PR diff):** For all eight instructions (`s_{min,max}_{i32,u32}`, `s_lshl{1,2,3,4}_add_u32`), compared both result and `SCC` against RDNA 2 ISA reference models across **265 input pairs each** (a 15×15 edge grid around `0`, `±1`, `2^28–2^31`, and `0xFFFFFFFx`, plus 40 random pairs) on both adapters: **0 mismatches**. On `main`, the same sweep fails for all eight since `SCC` falls through to `result != 0`. ### Code - **min/max:** `SCC` uses the select's own comparison, so equal operands give `SCC = 0` (`src1` chosen), matching the ISA. - **lshlN_add:** `(src0 >> (32 − n)) != 0 || r < t` covers both overflow paths, and with `n` in `1..=4` the shift is never 32 bits. **Why it matters:** Beyond `s_cselect` / `s_cbranch_scc`, the `s_lshlN_add_u32` carry feeds `s_addc_u32` during 64-bit address calculation (`base + (idx << n)`). With the old `result != 0`, the high dword picks up a spurious `+1` whenever the low result is non-zero, shifting addresses off by 4 GiB silently. *Nit (optional):* The in-tree test covers `s_lshl1` and `s_lshl4` but not `s_lshl2`/`s_lshl3` (they share the exact same code path and passed the sweep above, so extra cases are purely for completeness). LGTM.
Marvisak commented 2026-11-25 01:07:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:19:38Z.


Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-shader/src/emit/lower.rs, crates/victory-shader/src/emit/valu_tests.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148392361 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/168#issuecomment-7148392361). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:19:38Z. --- <!-- victory-triage v1 head=9483b1a962613cf91d30ac2a2d491657ed08f5c9 verdict=needs-rebase at=2026-11-25T00:13:20Z --> Automated triage for the maintainers. **Needs rebase.** This PR does not merge cleanly into current `main` (ac2525d). Conflicting files: `crates/victory-shader/src/emit/lower.rs`, `crates/victory-shader/src/emit/valu_tests.rs`. The content has not been reviewed yet; it will be once the branch is rebased onto `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/168:upstream-pr/168'
git switch 'upstream-pr/168'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/168'
git switch 'upstream-pr/168'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/168'
git switch 'upstream-pr/168'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/168'
git switch 'main'
git merge --squash 'upstream-pr/168'
git switch 'main'
git merge --ff-only 'upstream-pr/168'
git switch 'main'
git merge 'upstream-pr/168'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!168
No description provided.