tombox-xshader: s_bfe_u32 field width is 7 bits; add a scalar oracle in the test #38

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

@⁠artareias on GitHub · 2026-11-21 18:52 UTC · original
artareias:fix-s-bfe-7bit-width → main · +21 −3 · 2 files · 69 commits · closed without merging

Problem

vop::basic::salu_basic fails 12 s_bfe_i32 cases. The RDNA 2 ISA guide (S_BFE_U32 / S_BFE_I32, p. 113) puts the field offset in S1[4:0] and the field width in S1[22:16], which is 7 bits. In this repo:

  • the s_bfe_i32 emitter (tb_bfe_i32) already reads a 7-bit width;
  • the s_bfe_u32 emitter masks the width with & 31 (5 bits);
  • the test oracle masks the width to 5 bits for both scalar ops.

The vector V_BFE_* ops are different (offset S1[4:0], width S2[4:0], p. 177), so the existing 5-bit helper is right for them.

Change

  • hlsl.rs: s_bfe_u32 reads the width as (S1 >> 16) & 127.
  • tests/exec_vop/basic.rs: new sbfe() oracle for the scalar ops (7-bit width). bfe() stays as is for the vector ops.

An inference to review

For a width of 32 or more, the manual's (1 << width) - 1 is not defined in 32-bit arithmetic. The emitter and the new oracle both treat it as a full mask, with sign extension from bit 31 for s_bfe_i32. This is my reading, not something the manual states. Since the emitter and the oracle were written together, they agree by construction, so this case is not independent evidence. If you know the hardware behaviour for widths 32..127, it is a one-line change in both places.

Testing

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

before after
salu_basic s_bfe_i32 failing cases (RX 7600) 12 0
salu_basic s_bfe_i32 failing cases (WARP) 12 0

The 43 other salu_basic cases (s_lshl_b64, s_bfm_b64, s_addk_i32) are fixed separately in #29. Per-test run of all 61 exec tests on the RX 7600 before and after: no other test changes status.

🤖 Generated with Claude Code

**@⁠artareias** on GitHub · 2026-11-21 18:52 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/38) `artareias:fix-s-bfe-7bit-width` → `main` · +21 −3 · 2 files · 69 commits · closed without merging ## Problem `vop::basic::salu_basic` fails 12 `s_bfe_i32` cases. The RDNA 2 ISA guide (`S_BFE_U32` / `S_BFE_I32`, p. 113) puts the field offset in `S1[4:0]` and the field **width in `S1[22:16]`, which is 7 bits**. In this repo: - the `s_bfe_i32` emitter (`tb_bfe_i32`) already reads a 7-bit width; - the `s_bfe_u32` emitter masks the width with `& 31` (5 bits); - the test oracle masks the width to 5 bits for both scalar ops. The vector `V_BFE_*` ops are different (offset `S1[4:0]`, width `S2[4:0]`, p. 177), so the existing 5-bit helper is right for them. ## Change - `hlsl.rs`: `s_bfe_u32` reads the width as `(S1 >> 16) & 127`. - `tests/exec_vop/basic.rs`: new `sbfe()` oracle for the scalar ops (7-bit width). `bfe()` stays as is for the vector ops. ## An inference to review For a width of 32 or more, the manual's `(1 << width) - 1` is not defined in 32-bit arithmetic. The emitter and the new oracle both treat it as a full mask, with sign extension from bit 31 for `s_bfe_i32`. This is my reading, not something the manual states. Since the emitter and the oracle were written together, they agree by construction, so this case is not independent evidence. If you know the hardware behaviour for widths 32..127, it is a one-line change in both places. ## Testing Windows 10 19045, MSVC 14.44, rustc 1.100.0, AMD Radeon RX 7600 (`TOMBOX_EXEC_HW=1`) and WARP: | | before | after | |---|---|---| | `salu_basic` `s_bfe_i32` failing cases (RX 7600) | 12 | 0 | | `salu_basic` `s_bfe_i32` failing cases (WARP) | 12 | 0 | The 43 other `salu_basic` cases (`s_lshl_b64`, `s_bfm_b64`, `s_addk_i32`) are fixed separately in #29. Per-test run of all 61 `exec` tests on the RX 7600 before and after: no other test changes status. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The RDNA 2 ISA guide (S_BFE_U32 / S_BFE_I32, p. 113) puts the offset in S1[4:0]
and the width in S1[22:16], which is 7 bits. The emitter's s_bfe_i32 already
used 7 bits (tb_bfe_i32), but s_bfe_u32 masked the width with & 31, and the
test oracle masked it to 5 bits for both. The vector V_BFE_* ops are different:
offset S1[4:0] and width S2[4:0] (p. 177).

- Emitter: s_bfe_u32 reads the width as (S1 >> 16) & 127.
- Test: add sbfe() for the scalar ops and keep bfe() (5-bit fields) for the
  vector ops.

For a width of 32 or more the manual's `(1 << width) - 1` is not defined in
32-bit arithmetic. Both the emitter and the oracle treat it as a full mask, with
sign extension from bit 31 for s_bfe_i32. That is an inference, not something the
manual states.

Verified: vop::basic::salu_basic loses all 12 s_bfe_i32 failing cases on both an
AMD Radeon RX 7600 and WARP. 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:08:07 +00:00
github-bot closed this pull request 2026-11-26 06:08:07 +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 (same s_bfe_u32 expression and test), so nothing is left to apply. Thanks!

**@⁠omonkeyz** on GitHub · 2026-11-22 13:13 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/38#issuecomment-7079650958) Main's history was rewritten, which auto-closed this PR (sorry for the noise). Already on main (same s_bfe_u32 expression and test), so nothing is left to apply. Thanks!
Author
Owner

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