Shaders: set SCC from the carry of s_addc_u32 and s_subb_u32 #81

Manually merged
github merged 1 commit from gh-pr/81/head into gh-pr/81/base 2026-11-26 03:49:37 +00:00
Owner

@⁠tedin7 on GitHub · 2026-11-24 00:17 UTC · original
tedin7:vic-scalar-carry → main · +98 −30 · 1 files · 1 commits · merged 2026-11-24 00:36 UTC

What

s_addc_u32 and s_subb_u32 now set SCC to the carry (borrow) out, computed the way v_add_co_ci_u32 and v_sub_co_ci_u32 already compute theirs. The carry logic moves into one helper, add_sub_carry, which the scalar and vector paths share (the vector path's operations are unchanged).

Why

Both scalar instructions returned no carry, so SCC became Missing("the carry of a scalar operation"). Any 64-bit scalar add or subtract whose result feeds a branch or a select on SCC (s_add_u32 -> s_addc_u32 -> s_cselect_b32 / s_cbranch_scc1) could not be translated: the shader failed with Unsupported instead of becoming DXIL. The carry out of the high dword is a + b + cin >= 2^32 for add, and b + cin > a for subtract.

Tested

Linux x86_64, from the repository root:

  • cargo test -j4 -p victory-shader: 52 passed, 0 failed.
  • New test emit::lower::tests::a_scalar_carry_chain_reaches_the_select: lowers synthetic compute programs (s_add_u32 -> s_addc_u32 -> s_cselect_b32 -> branch, and s_sub_u32 -> s_subb_u32 -> s_cselect_b32 -> branch). Without the fix it fails with Unsupported { offset: 24, what: "the carry of a scalar operation" }; with it, it passes. Synthetic buffers only.
  • cargo clippy -j4 -p victory-shader --tests: nothing in lower.rs; the one warning (constant_color unused in emit/mod.rs) is already on main.
  • rustfmt --check --edition 2024 crates/victory-shader/src/emit/lower.rs: clean.
  • The carry formulas (add and subtract, with and without carry in) were also checked in a scratch program against 64-bit arithmetic over edge values (0, 1, 0x7fffffff, 0x80000000, 0xfffffffe, 0xffffffff).

Not run: the Windows runtime and any GPU. The test checks that the program now translates; it does not execute the emitted DXIL, so the carry value itself rests on the formula check above and on the vector path using the same logic.

**@⁠tedin7** on GitHub · 2026-11-24 00:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/81) `tedin7:vic-scalar-carry` → `main` · +98 −30 · 1 files · 1 commits · merged 2026-11-24 00:36 UTC ## What `s_addc_u32` and `s_subb_u32` now set SCC to the carry (borrow) out, computed the way `v_add_co_ci_u32` and `v_sub_co_ci_u32` already compute theirs. The carry logic moves into one helper, `add_sub_carry`, which the scalar and vector paths share (the vector path's operations are unchanged). ## Why Both scalar instructions returned no carry, so SCC became `Missing("the carry of a scalar operation")`. Any 64-bit scalar add or subtract whose result feeds a branch or a select on SCC (`s_add_u32` -> `s_addc_u32` -> `s_cselect_b32` / `s_cbranch_scc1`) could not be translated: the shader failed with `Unsupported` instead of becoming DXIL. The carry out of the high dword is `a + b + cin >= 2^32` for add, and `b + cin > a` for subtract. ## Tested Linux x86_64, from the repository root: - `cargo test -j4 -p victory-shader`: 52 passed, 0 failed. - New test `emit::lower::tests::a_scalar_carry_chain_reaches_the_select`: lowers synthetic compute programs (`s_add_u32` -> `s_addc_u32` -> `s_cselect_b32` -> branch, and `s_sub_u32` -> `s_subb_u32` -> `s_cselect_b32` -> branch). Without the fix it fails with `Unsupported { offset: 24, what: "the carry of a scalar operation" }`; with it, it passes. Synthetic buffers only. - `cargo clippy -j4 -p victory-shader --tests`: nothing in `lower.rs`; the one warning (`constant_color` unused in `emit/mod.rs`) is already on main. - `rustfmt --check --edition 2024 crates/victory-shader/src/emit/lower.rs`: clean. - The carry formulas (add and subtract, with and without carry in) were also checked in a scratch program against 64-bit arithmetic over edge values (0, 1, 0x7fffffff, 0x80000000, 0xfffffffe, 0xffffffff). Not run: the Windows runtime and any GPU. The test checks that the program now translates; it does not execute the emitted DXIL, so the carry value itself rests on the formula check above and on the vector path using the same logic.
Both returned no carry, so SCC was missing and a branch or select on a 64-bit scalar add or subtract failed to translate. They now share the carry logic of v_add_co_ci_u32 and v_sub_co_ci_u32.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:49:35 +00:00
github manually merged commit a2f5f4351d into gh-pr/81/base 2026-11-26 03:49:37 +00:00
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 00:23 UTC · original

Tested a2f5f43 stacked on #39 on Arch Linux x86_64, rustc 1.98.1: pass.

  • cargo test --workspace: 156 passed, 0 failed, 3 ignored; merge with #39 clean.
  • This PR adds tests (4 #[test] in the diff) and they are part of that run.
  • No game data used.

AI-assisted (DeepSeek V4.1 Flash coding agent).

**@⁠DaviTostes** on GitHub · 2026-11-24 00:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/81#issuecomment-7118015827) Tested `a2f5f43` stacked on **#39** on **Arch Linux x86_64, rustc 1.98.1**: **pass**. - `cargo test --workspace`: **156 passed, 0 failed, 3 ignored**; merge with #39 clean. - This PR adds tests (4 `#[test]` in the diff) and they are part of that run. - No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!81
No description provided.