shader: set the SCC of s_lshl<n>_add_u32 from the 64-bit overflow #86

Manually merged
github merged 2 commits from github-bot/gh-86 into main 2026-11-26 15:06:16 +00:00 AGit
Owner

@⁠Olima34 on GitHub · 2026-11-26 13:52 UTC · original
Olima34:fix/shader-lshl-add-scc → main · +56 −2 · 3 files · 2 commits · merged 2026-11-26 15:01 UTC

What this changes

ir::writes_scc lists s_lshl1_add_u32..s_lshl4_add_u32 as writing SCC, but their arm returned no carry, so SCC fell to the default result != 0: s_lshl1_add_u32 1, 2 gave 4 with SCC 1 instead of 0, and s_lshl4_add_u32 0x10000000, 0 gave 0 with SCC 0 instead of 1. A following s_addc_u32 for a high dword would read a wrong carry; the title forms heap addresses with s_lshl4_add_u32.

RDNA2 ISA reference, section 12.1 (SOP2 46-49): D.u = (S0.u << N) + S1.u; SCC = ((S0.u << N) + S1.u) >= 0x100000000, and the RDNA3 manual writes the sum out in 64 bits, so bits shifted out of S0 count. SCC is now the 32-bit add's carry (add_sub_carry) or S0 >> (32 - N) != 0. Mesa ACO ignores the bits shifted out (it fuses s_lshl + s_add_u32 even when SCC is read); the manual is followed, and docs/native-host.md says so. The signed-overflow SCC of s_add_i32/s_sub_i32 is left for another PR.

Tests: Windows value probes in scalar_probes() for the four opcodes over the edge pairs plus 1<<1 + 2, 0x80000000<<1, 0x7FFFFFFF<<1 + 2, 0x3FFFFFFF<<2, 0x10000000<<4, 0x0FFFFFFF<<4 + 0x10 and -1<<3 + -1, with the inputs the old SCC got wrong tagged and checked by scalar_shift_adds_set_scc_from_the_overflow.

How it was tested

  • cargo test -p victory-shader (the value probes run only in the Windows CI)
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings, also with --all-features
  • arm64 cargo test --workspace and cargo xtask policy
  • Ran the game: not done, no copy of it here

Checklist

  • No game files, game code, disassembly listings or SDK files are included
  • Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md
  • New diagnostics are behind a VICTORY_* variable and documented (none added)
**@⁠Olima34** on GitHub · 2026-11-26 13:52 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/86) `Olima34:fix/shader-lshl-add-scc` → `main` · +56 −2 · 3 files · 2 commits · merged 2026-11-26 15:01 UTC ## What this changes `ir::writes_scc` lists `s_lshl1_add_u32`..`s_lshl4_add_u32` as writing SCC, but their arm returned no carry, so SCC fell to the default `result != 0`: `s_lshl1_add_u32 1, 2` gave 4 with SCC 1 instead of 0, and `s_lshl4_add_u32 0x10000000, 0` gave 0 with SCC 0 instead of 1. A following `s_addc_u32` for a high dword would read a wrong carry; the title forms heap addresses with `s_lshl4_add_u32`. RDNA2 ISA reference, section 12.1 (SOP2 46-49): `D.u = (S0.u << N) + S1.u; SCC = ((S0.u << N) + S1.u) >= 0x100000000`, and the RDNA3 manual writes the sum out in 64 bits, so bits shifted out of S0 count. SCC is now the 32-bit add's carry (`add_sub_carry`) or `S0 >> (32 - N) != 0`. Mesa ACO ignores the bits shifted out (it fuses `s_lshl` + `s_add_u32` even when SCC is read); the manual is followed, and docs/native-host.md says so. The signed-overflow SCC of `s_add_i32`/`s_sub_i32` is left for another PR. Tests: Windows value probes in `scalar_probes()` for the four opcodes over the edge pairs plus `1<<1 + 2`, `0x80000000<<1`, `0x7FFFFFFF<<1 + 2`, `0x3FFFFFFF<<2`, `0x10000000<<4`, `0x0FFFFFFF<<4 + 0x10` and `-1<<3 + -1`, with the inputs the old SCC got wrong tagged and checked by `scalar_shift_adds_set_scc_from_the_overflow`. ## How it was tested - [x] `cargo test -p victory-shader` (the value probes run only in the Windows CI) - [x] `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings`, also with `--all-features` - [x] arm64 `cargo test --workspace` and `cargo xtask policy` - [ ] Ran the game: not done, no copy of it here ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included - [x] Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md - [x] New diagnostics are behind a `VICTORY_*` variable and documented (none added)
ir::writes_scc lists s_lshl1_add_u32..s_lshl4_add_u32 as writing SCC,
but their arm returned no carry, so SCC fell to the default
`result != 0`: s_lshl1_add_u32 1, 2 gave 4 with SCC 1 instead of 0.

RDNA2 ISA, section 12.1 (SOP2 46-49): D.u = (S0.u << N) + S1.u and
SCC = ((S0.u << N) + S1.u) >= 0x100000000; the RDNA3 manual writes the
sum out in 64 bits, so bits shifted out of S0 count. SCC is now the
32-bit add's carry (add_sub_carry) or S0 >> (32 - N) != 0. Mesa ACO
ignores the bits shifted out (it fuses s_lshl and s_add_u32 even when
SCC is read); the manual is followed here.

Tests: Windows value probes in semantics_tests.rs scalar_probes() for
the four opcodes over the edge pairs plus the cases 1<<1 + 2, 0x80000000
<< 1, 0x7FFFFFFF << 1 + 2, 0x3FFFFFFF << 2, 0x10000000 << 4,
0x0FFFFFFF << 4 + 0x10 and -1 << 3 + -1, with the inputs the old SCC
got wrong tagged and run by scalar_shift_adds_set_scc_from_the_overflow.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:45:37 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 14:54 UTC · original · approved these changes

Looks right against the ISA (SCC from the 64-bit sum), thanks for documenting the ACO difference.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 14:54 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/86#pullrequestreview-6076250329) · **approved these changes** Looks right against the ISA (SCC from the 64-bit sum), thanks for documenting the ACO difference.
github manually merged commit 09a733226e into main 2026-11-26 15:06:16 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.