tombox-xshader: fix v_bfe_i32 when offset + width reaches past bit 31 #33

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

@⁠artareias on GitHub · 2026-11-21 18:31 UTC · original
artareias:fix-v-bfe-i32-wide-field → main · +4 −2 · 1 files · 68 commits · closed without merging

Problem

v_bfe_i32 extracted the field with (a << ((32 - w - o) & 31)) >> (32 - w). When w + o > 32 the left-shift count wraps through the & 31 mask. Example: a = 1, o = 31, w = 31 shifts left by 2 instead of 0, so the emitter returns 2 where the field is 0.

vop::basic::vop3_basic shows this as 18 failing v_bfe_i32 cases (on both a hardware adapter and WARP).

Change

When w + o >= 32 the field already reaches the sign bit, so the arithmetic shift asint(a) >> o alone sign-fills it. The shift pair is kept for w + o < 32, where both shift counts are in 1..31. This is the same split the existing tb_bfe_i32 helper (used by s_bfe_i32) already makes. Width 0 still returns 0.

Reference: RDNA 2 ISA guide, VOP3 V_BFE_I32 (p. 177): offset is S1[4:0], width is S2[4:0].

Testing

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

before after
vop3_basic failing cases (RX 7600) 55 37
vop3_basic failing cases (WARP) 55 37
v_bfe_i32 failing cases 18 0

The 37 left are v_fma_mixhi_f16 (36) and v_fma_mix_f32 (1), a separate issue. I ran all 61 exec tests one at a time on the RX 7600 before and after: no other test changes status.

🤖 Generated with Claude Code

**@⁠artareias** on GitHub · 2026-11-21 18:31 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/33) `artareias:fix-v-bfe-i32-wide-field` → `main` · +4 −2 · 1 files · 68 commits · closed without merging ## Problem `v_bfe_i32` extracted the field with `(a << ((32 - w - o) & 31)) >> (32 - w)`. When `w + o > 32` the left-shift count wraps through the `& 31` mask. Example: `a = 1, o = 31, w = 31` shifts left by 2 instead of 0, so the emitter returns 2 where the field is 0. `vop::basic::vop3_basic` shows this as 18 failing `v_bfe_i32` cases (on both a hardware adapter and WARP). ## Change When `w + o >= 32` the field already reaches the sign bit, so the arithmetic shift `asint(a) >> o` alone sign-fills it. The shift pair is kept for `w + o < 32`, where both shift counts are in 1..31. This is the same split the existing `tb_bfe_i32` helper (used by `s_bfe_i32`) already makes. Width 0 still returns 0. Reference: RDNA 2 ISA guide, VOP3 `V_BFE_I32` (p. 177): offset is `S1[4:0]`, width is `S2[4:0]`. ## Testing Windows 10 19045, MSVC 14.44, rustc 1.100.0, AMD Radeon RX 7600 (`TOMBOX_EXEC_HW=1`) and WARP: | | before | after | |---|---|---| | `vop3_basic` failing cases (RX 7600) | 55 | 37 | | `vop3_basic` failing cases (WARP) | 55 | 37 | | `v_bfe_i32` failing cases | 18 | 0 | The 37 left are `v_fma_mixhi_f16` (36) and `v_fma_mix_f32` (1), a separate issue. I ran all 61 `exec` tests one at a time on the RX 7600 before and after: no other test changes status. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The emitter extracted the field with (a << ((32 - w - o) & 31)) >> (32 - w).
When w + o > 32 the left-shift count wraps through the & 31 mask (for example
a = 1, o = 31, w = 31 shifts left by 2 instead of 0) and the result is wrong.

When w + o >= 32 the field already reaches the sign bit, so the arithmetic
shift a >> o alone sign-fills it; use that. The shift pair is kept for
w + o < 32, where both shift counts are in 1..31. This mirrors the existing
tb_bfe_i32 helper used for s_bfe_i32. Width 0 still returns 0.

RDNA 2 ISA guide, VOP3 V_BFE_I32 (p. 177): offset is S1[4:0], width is S2[4:0].

Verified: vop::basic::vop3_basic goes from 55 to 37 failing cases on both an
AMD Radeon RX 7600 and WARP; all 18 v_bfe_i32 cases pass. A per-test run of all
61 exec tests 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:55 +00:00
github-bot closed this pull request 2026-11-26 06:07:55 +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 (v_bfe_i32 goes through tb_bfe_i32). Thanks!

**@⁠omonkeyz** on GitHub · 2026-11-22 13:13 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/33#issuecomment-7079651335) Main's history was rewritten, which auto-closed this PR (sorry for the noise). Already on main (v_bfe_i32 goes through tb_bfe_i32). Thanks!
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-21 18:31 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:31 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/33#pullrequestreview-6007284181) · **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.