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

Closed
artareias wants to merge 0 commits from upstream-pr/38 into main
artareias commented 2026-11-21 18:52:38 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by artareias on 2026-11-21T18:52:38Z.


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

<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:6532999671 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/38). Originally posted by [artareias](https://github.com/artareias) on 2026-11-21T18:52:38Z. --- ## 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)
copilot-pull-request-reviewer[bot] commented 2026-11-21 18:52:47 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-21T18:52:47Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:review:6007405427 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/38#pullrequestreview-6007405427). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-21T18:52:47Z. **Review:** COMMENTED --- 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.
omonkeyz commented 2026-11-22 13:13:05 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-22T13:13:05Z.


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!

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7079650958 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/38#issuecomment-7079650958). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-22T13:13:05Z. --- 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!

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
omonkeyz/xbox-emulator!38
No description provided.