tombox-xshader: fix SCC and 64-bit mask handling in s_lshl_b64, s_bfm_b64, s_addk_i32 #29

Closed
github-bot wants to merge 1 commit from gh-pr/29/head into gh-pr/29/base
Owner

@⁠artareias on GitHub · 2026-11-21 18:12 UTC · original
artareias:fix-salu-scc-bfm-addk → main · +29 −5 · 1 files · 64 commits · closed without merging

Problem

vop::basic::salu_basic (tests/exec_vop/basic.rs) fails with 55 cases on both a hardware adapter and WARP. 43 of them are three scalar ops in the HLSL emitter (crates/tombox-xshader/src/hlsl.rs):

Op What the emitter did Expected
s_lshl_b64 never updated SCC SCC = (result != 0), like the other SOP2 shifts
s_bfm_b64 produced only the low word, high word forced to 0 64-bit mask ((1 << S0[5:0]) - 1) << S1[5:0]
s_addk_i32 added the immediate, SCC untouched SCC = signed overflow of D + signext(SIMM16)

The oracles in tests/exec_vop/basic.rs already encode the expected behaviour, so no test change is needed.

Change

  • s_lshl_b64: set scc after writing both words (s_bfm_b64 and s_cselect_b64 still leave SCC alone).
  • s_bfm_b64: build the 64-bit mask from two words, then shift the pair left by S1[5:0].
  • s_addk_i32: compute D + imm into a temp, set SCC with the same overflow expression s_add_i32 already uses, then write D.

Testing

Windows 10 19045, MSVC 14.44, rustc 1.100.0, AMD Radeon RX 7600 (TOMBOX_EXEC_HW=1) and WARP:

  • salu_basic: 55 failing cases before, 12 after, on both adapters. All 43 s_lshl_b64 / s_bfm_b64 / s_addk_i32 cases pass.
  • Per-test run of all 61 exec tests on the RX 7600 before and after: no other test changes status.
  • cargo test -p tombox-xshader --lib --test synthetic --test opcodes: pass. (amp and fixtures fail on this base because they need local fixtures, see #13.)

Not changed

The remaining 12 salu_basic failures are all s_bfe_i32. The emitter's tb_bfe_i32 uses a 7-bit width ((b >> 16) & 127), while s_bfe_u32 in the same file and the test oracle use 5 bits (& 31). I could not tell which side matches hardware, so I left it. vop3_basic (55 failing cases: v_bfe_i32, v_fma_mix*) is a separate group.

🤖 Generated with Claude Code

**@⁠artareias** on GitHub · 2026-11-21 18:12 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/29) `artareias:fix-salu-scc-bfm-addk` → `main` · +29 −5 · 1 files · 64 commits · closed without merging ## Problem `vop::basic::salu_basic` (tests/exec_vop/basic.rs) fails with 55 cases on both a hardware adapter and WARP. 43 of them are three scalar ops in the HLSL emitter (`crates/tombox-xshader/src/hlsl.rs`): | Op | What the emitter did | Expected | |---|---|---| | `s_lshl_b64` | never updated SCC | `SCC = (result != 0)`, like the other SOP2 shifts | | `s_bfm_b64` | produced only the low word, high word forced to 0 | 64-bit mask `((1 << S0[5:0]) - 1) << S1[5:0]` | | `s_addk_i32` | added the immediate, SCC untouched | `SCC` = signed overflow of `D + signext(SIMM16)` | The oracles in `tests/exec_vop/basic.rs` already encode the expected behaviour, so no test change is needed. ## Change - `s_lshl_b64`: set `scc` after writing both words (`s_bfm_b64` and `s_cselect_b64` still leave SCC alone). - `s_bfm_b64`: build the 64-bit mask from two words, then shift the pair left by `S1[5:0]`. - `s_addk_i32`: compute `D + imm` into a temp, set SCC with the same overflow expression `s_add_i32` already uses, then write D. ## Testing Windows 10 19045, MSVC 14.44, rustc 1.100.0, AMD Radeon RX 7600 (`TOMBOX_EXEC_HW=1`) and WARP: - `salu_basic`: 55 failing cases before, 12 after, on both adapters. All 43 `s_lshl_b64` / `s_bfm_b64` / `s_addk_i32` cases pass. - Per-test run of all 61 `exec` tests on the RX 7600 before and after: no other test changes status. - `cargo test -p tombox-xshader --lib --test synthetic --test opcodes`: pass. (`amp` and `fixtures` fail on this base because they need local fixtures, see #13.) ## Not changed The remaining 12 `salu_basic` failures are all `s_bfe_i32`. The emitter's `tb_bfe_i32` uses a 7-bit width (`(b >> 16) & 127`), while `s_bfe_u32` in the same file and the test oracle use 5 bits (`& 31`). I could not tell which side matches hardware, so I left it. `vop3_basic` (55 failing cases: `v_bfe_i32`, `v_fma_mix*`) is a separate group. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
- s_lshl_b64 never updated SCC. SOP2 shifts set SCC = (result != 0), as the
  neighbouring s_ashr_i64/s_lshr_b64 path already does.
- s_bfm_b64 only produced the low word and zeroed the high word. It now builds
  the 64-bit mask ((1 << S0[5:0]) - 1) << S1[5:0] from two words. SCC is left
  untouched, as before.
- s_addk_i32 added the immediate without setting SCC. SCC is now the signed
  overflow of D + signext(SIMM16), using the same expression as s_add_i32.

The existing oracles in tests/exec_vop/basic.rs already encode this behaviour.

Verified with the exec tests (Windows 10 19045, MSVC 14.44, rustc 1.100.0):
vop::basic::salu_basic goes from 55 failing cases to 12 on both an AMD Radeon
RX 7600 (TOMBOX_EXEC_HW=1) and WARP. The remaining 12 are all s_bfe_i32 and
are not touched here. The full per-test exec run on the RX 7600 shows no other
change.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:07:46 +00:00
github-bot closed this pull request 2026-11-26 06:07:46 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 13:13 UTC · original

Main's history was rewritten, which auto-closed this PR (sorry for the noise). Already on main (64-bit s_bfm_b64, s_lshl_b64 SCC and s_addk_i32 overflow SCC). Thanks!

**@⁠omonkeyz** on GitHub · 2026-11-22 13:13 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/29#issuecomment-7079651650) Main's history was rewritten, which auto-closed this PR (sorry for the noise). Already on main (64-bit s_bfm_b64, s_lshl_b64 SCC and s_addk_i32 overflow SCC). Thanks!
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-21 18:12 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-21 18:12 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/29#pullrequestreview-6007209599) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.