docs: close the s_bfe width blocker from the ISA pseudocode and LLVM folding #178

Closed
iseaprojects wants to merge 1 commit from upstream-pr/178 into main
iseaprojects commented 2026-11-22 18:24:44 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by iseaprojects on 2026-11-22T18:24:44Z.


Library / area: docs/BLOCKERS.md (RDNA2 instructions held at yellow). No code change.

Exports changed (exports.txt rows): none

Source of the behaviour: the blocker asked for one of two external references; both agree with the translator as it stands:

  • AMD RDNA ISA, 25 September 2020, 12.1 SOP2, p. 110: D.u = (S0.u >> S1.u[4:0]) & ((1 << S1.u[22:16]) - 1). The width field is 7 bits, so width 0 clears the result and width 32 masks all 32 bits, leaving the shift alone.
  • LLVM AMDGPUISelLowering.cpp, constantFoldBFE: when Width + Offset >= 32 it returns Src0 >> Offset with no mask, and only masks the narrower field. SIISelLowering.cpp, knownBitsForSBFE, treats a width of 32 or more as ill-formed.

hlsl.rs already lowers that rule: s_bfe_u32 shifts when width >= 32, tb_bfe_i32 shifts when width + offset >= 32, and s_bfe_*64 clamp the width to 64. tests/isa_sweep/ops_s.rs covers widths 0, 1, 31, 32, 33, 63, 64, 65 and 127 with lane offsets, plus 0xffffffff (offset 31, width 127).

This entry is the only change: the note is replaced with the closure and its evidence. Nothing else in the section is touched; v_cvt_norm stays open because the ISA says only "supports rounding" for the (snorm)/(unorm) casts and does not settle .5 ties.

Tests (Windows 11, GTX 1650, debug):

  • TOMBOX_SWEEP_FILTER=s_bfe cargo test -p tombox-xshader --test isa_sweep isa_sweep (WARP): s_bfe_u32, s_bfe_i32, s_bfe_u64, s_bfe_i64 PASS, 11 cases and 11264 lanes each.

  • TOMBOX_EXEC_HW=1 cargo test -p tombox-xshader --test isa_sweep isa_sweep (GTX 1650): 541 mnemonics, 541 pass, 0 fail, 0 known WARP deviations, 94 compiles, 15.1 s.

  • No game or console files and no binaries included

  • No fake success; the two still-unconfirmed items in that section keep their notes

<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:6546041123 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/178). Originally posted by [iseaprojects](https://github.com/iseaprojects) on 2026-11-22T18:24:44Z. --- **Library / area:** `docs/BLOCKERS.md` (RDNA2 instructions held at yellow). No code change. **Exports changed (exports.txt rows):** none **Source of the behaviour:** the blocker asked for one of two external references; both agree with the translator as it stands: - AMD RDNA ISA, 25 September 2020, 12.1 SOP2, p. 110: `D.u = (S0.u >> S1.u[4:0]) & ((1 << S1.u[22:16]) - 1)`. The width field is 7 bits, so width 0 clears the result and width 32 masks all 32 bits, leaving the shift alone. - LLVM `AMDGPUISelLowering.cpp`, `constantFoldBFE`: when `Width + Offset >= 32` it returns `Src0 >> Offset` with no mask, and only masks the narrower field. `SIISelLowering.cpp`, `knownBitsForSBFE`, treats a width of 32 or more as ill-formed. `hlsl.rs` already lowers that rule: `s_bfe_u32` shifts when `width >= 32`, `tb_bfe_i32` shifts when `width + offset >= 32`, and `s_bfe_*64` clamp the width to 64. `tests/isa_sweep/ops_s.rs` covers widths 0, 1, 31, 32, 33, 63, 64, 65 and 127 with lane offsets, plus `0xffffffff` (offset 31, width 127). This entry is the only change: the note is replaced with the closure and its evidence. Nothing else in the section is touched; `v_cvt_norm` stays open because the ISA says only "supports rounding" for the `(snorm)`/`(unorm)` casts and does not settle .5 ties. Tests (Windows 11, GTX 1650, debug): - `TOMBOX_SWEEP_FILTER=s_bfe cargo test -p tombox-xshader --test isa_sweep isa_sweep` (WARP): `s_bfe_u32`, `s_bfe_i32`, `s_bfe_u64`, `s_bfe_i64` PASS, 11 cases and 11264 lanes each. - `TOMBOX_EXEC_HW=1 cargo test -p tombox-xshader --test isa_sweep isa_sweep` (GTX 1650): 541 mnemonics, 541 pass, 0 fail, 0 known WARP deviations, 94 compiles, 15.1 s. - [x] No game or console files and no binaries included - [x] No fake success; the two still-unconfirmed items in that section keep their notes
omonkeyz commented 2026-11-22 18:28:16 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-22T18:28:16Z.


Applied in 01a7018 (merged in 6ef1fea) with your authorship kept, thanks. I checked it against hlsl.rs on main: s_bfe_u32 shifts without masking when the width is 32 or more, tb_bfe_i32 shifts when width + offset is 32 or more, and width 0 gives 0. So the entry now matches the code.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7083626398 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/178#issuecomment-7083626398). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-22T18:28:16Z. --- Applied in 01a7018 (merged in 6ef1fea) with your authorship kept, thanks. I checked it against hlsl.rs on main: `s_bfe_u32` shifts without masking when the width is 32 or more, `tb_bfe_i32` shifts when width + offset is 32 or more, and width 0 gives 0. So the entry now matches the code.

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!178
No description provided.