shader: set the SCC of s_add_i32, s_sub_i32 and s_addk_i32 to the signed overflow #93

Manually merged
github merged 1 commit from github-bot/gh-93 into main 2026-11-26 15:06:16 +00:00 AGit
Owner

@⁠Olima34 on GitHub · 2026-11-26 14:29 UTC · original
Olima34:fix/shader-signed-add-scc → main · +94 −7 · 3 files · 2 commits · merged 2026-11-26 15:05 UTC

What this changes

The SCC of s_add_i32, s_sub_i32 and s_addk_i32 was Val::Missing, so a shader that reads it (a select or a branch on it) was refused. It is now the signed overflow, as the RDNA2 ISA reference gives it (SOP2 2 and 3, SOPK 15): S0[31] == S1[31] && S0[31] != D[31] for the adds (tmp[31] == SIMM16[15] && tmp[31] != D[31] for s_addk_i32, tmp the old D) and S0[31] != S1[31] && S0[31] != D[31] for the subtraction, computed as the sign of (a ^ r) & (b ^ r) and (a ^ b) & (a ^ r).

Tests: a_signed_overflow_reaches_the_select translates a select and a branch on each instruction's SCC (refused on main), and Windows value probes check the overflow cases (0x7FFFFFFF + 1, 0x80000000 + -1, -1 + 1, 0x80000000 - 1, 0 - 0x80000000, 0 - 1, and s_addk_i32 with 0x7FFF, 0xFFFF, 0x8000).

How it was tested

  • cargo test -p victory-shader and arm64 cargo test --workspace (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
  • 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 14:29 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/93) `Olima34:fix/shader-signed-add-scc` → `main` · +94 −7 · 3 files · 2 commits · merged 2026-11-26 15:05 UTC ## What this changes The SCC of `s_add_i32`, `s_sub_i32` and `s_addk_i32` was `Val::Missing`, so a shader that reads it (a select or a branch on it) was refused. It is now the signed overflow, as the RDNA2 ISA reference gives it (SOP2 2 and 3, SOPK 15): `S0[31] == S1[31] && S0[31] != D[31]` for the adds (`tmp[31] == SIMM16[15] && tmp[31] != D[31]` for `s_addk_i32`, `tmp` the old D) and `S0[31] != S1[31] && S0[31] != D[31]` for the subtraction, computed as the sign of `(a ^ r) & (b ^ r)` and `(a ^ b) & (a ^ r)`. Tests: `a_signed_overflow_reaches_the_select` translates a select and a branch on each instruction's SCC (refused on `main`), and Windows value probes check the overflow cases (`0x7FFFFFFF + 1`, `0x80000000 + -1`, `-1 + 1`, `0x80000000 - 1`, `0 - 0x80000000`, `0 - 1`, and `s_addk_i32` with `0x7FFF`, `0xFFFF`, `0x8000`). ## How it was tested - [x] `cargo test -p victory-shader` and arm64 `cargo test --workspace` (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] `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)
Their SCC was Val::Missing, so a shader that read it was refused with
"the carry of a scalar operation".

RDNA2 ISA reference guide, SOP2 opcodes 2 and 3 and SOPK opcode 15:
- s_add_i32: SCC = S0[31] == S1[31] && S0[31] != D[31]
- s_sub_i32: SCC = S0[31] != S1[31] && S0[31] != D[31]
- s_addk_i32: SCC = tmp[31] == SIMM16[15] && tmp[31] != D[31], tmp the
  old D and the constant sign-extended
computed as the sign of (a ^ r) & (b ^ r) for the adds and of
(a ^ b) & (a ^ r) for the subtraction.

Tests: a translation test (a select and a branch on each SCC) that is
refused without the change, and Windows value probes in
semantics_tests.rs: s_add_i32 and s_sub_i32 with their SCC over the edge
pairs plus 0x7FFFFFFF + 1, 0x80000000 + -1, -1 + 1, 0x80000000 - 1,
0 - 0x80000000 and 0 - 1, and s_addk_i32 with constants 0, 1, 0x7FFF,
0x8000 and 0xFFFF over the edge values.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:45:49 +00:00
Author
Owner

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

The signed-overflow formulas match the ISA and the lowering test fails on main. Thanks.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 14:54 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/93#pullrequestreview-6076251158) · **approved these changes** The signed-overflow formulas match the ISA and the lowering test fails on main. Thanks.
github manually merged commit fb5861df37 into main 2026-11-26 15:06:16 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.