Shaders: s_bfe_u32 (SOP2 0x27) has no scalar hardware test #803

Open
opened 2026-11-26 04:13:59 +00:00 by github-bot · 6 comments
Owner

@⁠kss306 on GitHub · 2026-11-24 11:11 UTC · original

bfe_signed_and_unsigned_match_rdna2 in valu_tests.rs builds shaders for v_bfe_i32 (VOP3 0x149), v_bfe_u32 (VOP3 0x148) and s_bfe_i32 (SOP2 0x28). The scalar unsigned variant s_bfe_u32 (SOP2 0x27) is never tested, even though it is handled in the same match arm.

Implementation evidence

lower.rs, sop() at line 2638:

"s_bfe_u32" | "s_bfe_i32" => {
    // src1: offset in bits 0-4, width in bits 16-22.
    let (a, b) = (src32(self, 0)?, src32(self, 1)?);
    let (k16, k127) = (self.s.m.i32(16), self.s.m.i32(0x7F));
    let w = self.s.m.bin(c, Bin::LShr, b, k16);
    let w = self.s.m.bin(c, Bin::And, w, k127);
    (self.bfe(a, b, w, name == "s_bfe_i32"), None)
}

s_bfe_u32 passes signed=false to bfe(). The 7-bit width field (src1[22:16]) is unique to SOP2: a width of 32..127 means "return all bits from the shifted source", exercising the full = width >= 32 branch of bfe().

Missing test

valu_tests.rs, bfe_signed_and_unsigned_match_rdna2 (line 794), builds:

Variable Instruction Opcode Present
v_signed v_bfe_i32 VOP3 0x149 ✅
v_unsigned v_bfe_u32 VOP3 0x148 ✅
s_signed s_bfe_i32 SOP2 0x28 ✅
(absent) s_bfe_u32 SOP2 0x27 ❌

The signed scalar path exercises bfe(…, true) with the 7-bit width and the width >= 32 branch ([0x8000_0000, 4, 32, 0] → 0xf800_0000). The unsigned scalar equivalent (bfe(…, false) with the same 7-bit encoding, no sign extension) is not tested. The expected result for width=32 differs: 0x0800_0000 unsigned vs 0xf800_0000 signed.

Suggested test addition

Add a fourth shader s_unsigned to bfe_signed_and_unsigned_match_rdna2:

// s_bfe_u32 s6, s0, s1 (SOP2 opcode 0x27)
let s_unsigned = build_valu_cs(&[sop2(0x27, 6, 0, 1), vop1(0x001, 0, sgpr(6))]);

Then run the same s_in cases against it, plus the width=32 edge case:

let mut su_cases = unsigned_cases.to_vec();
// width=32: s_bfe_u32 7-bit width keeps all bits; no sign extension.
su_cases.push(([0x8000_0000, 4, 32, 0], 0x0800_0000));
let su_in: Vec<[u32; 4]> = su_cases
    .iter()
    .map(|&(inp, _)| [inp[0], (inp[1] & 31) | ((inp[2] & 0x7F) << 16), 0, 0])
    .collect();
run_cases(&s_unsigned, &su_in, |backend, i, inp, got| {
    let want = su_cases[i].1;
    assert_eq!(
        got, want,
        "{backend}: s_bfe_u32({:#010x}, {:#010x}) = {got:#010x}, want {want:#010x}",
        inp[0], inp[1],
    );
});

The key case that differs from the signed test: ([0x8000_0000, 4, 32, 0], 0x0800_0000) — width=32 on a 7-bit field extracts all bits from offset 4 without sign-extending bit 31.

No game data needed; the test skips when no SM 6.6 device is available and runs on WARP.

AI-assisted: found with Kiro (Claude) and independently confirmed by five separate analysis passes without cross-contamination; no hardware run, no game data.

**@⁠kss306** on GitHub · 2026-11-24 11:11 UTC · [original](https://github.com/Marvisak/VIctory/issues/803) `bfe_signed_and_unsigned_match_rdna2` in `valu_tests.rs` builds shaders for `v_bfe_i32` (VOP3 0x149), `v_bfe_u32` (VOP3 0x148) and `s_bfe_i32` (SOP2 0x28). The scalar unsigned variant `s_bfe_u32` (SOP2 0x27) is never tested, even though it is handled in the same `match` arm. ## Implementation evidence `lower.rs`, `sop()` at line 2638: ```rust "s_bfe_u32" | "s_bfe_i32" => { // src1: offset in bits 0-4, width in bits 16-22. let (a, b) = (src32(self, 0)?, src32(self, 1)?); let (k16, k127) = (self.s.m.i32(16), self.s.m.i32(0x7F)); let w = self.s.m.bin(c, Bin::LShr, b, k16); let w = self.s.m.bin(c, Bin::And, w, k127); (self.bfe(a, b, w, name == "s_bfe_i32"), None) } ``` `s_bfe_u32` passes `signed=false` to `bfe()`. The 7-bit width field (`src1[22:16]`) is unique to SOP2: a width of 32..127 means "return all bits from the shifted source", exercising the `full = width >= 32` branch of `bfe()`. ## Missing test `valu_tests.rs`, `bfe_signed_and_unsigned_match_rdna2` (line 794), builds: | Variable | Instruction | Opcode | Present | |---|---|---|---| | `v_signed` | `v_bfe_i32` | VOP3 0x149 | ✅ | | `v_unsigned` | `v_bfe_u32` | VOP3 0x148 | ✅ | | `s_signed` | `s_bfe_i32` | SOP2 0x28 | ✅ | | _(absent)_ | `s_bfe_u32` | SOP2 **0x27** | ❌ | The signed scalar path exercises `bfe(…, true)` with the 7-bit width and the `width >= 32` branch (`[0x8000_0000, 4, 32, 0] → 0xf800_0000`). The unsigned scalar equivalent (`bfe(…, false)` with the same 7-bit encoding, no sign extension) is not tested. The expected result for width=32 differs: `0x0800_0000` unsigned vs `0xf800_0000` signed. ## Suggested test addition Add a fourth shader `s_unsigned` to `bfe_signed_and_unsigned_match_rdna2`: ```rust // s_bfe_u32 s6, s0, s1 (SOP2 opcode 0x27) let s_unsigned = build_valu_cs(&[sop2(0x27, 6, 0, 1), vop1(0x001, 0, sgpr(6))]); ``` Then run the same `s_in` cases against it, plus the width=32 edge case: ```rust let mut su_cases = unsigned_cases.to_vec(); // width=32: s_bfe_u32 7-bit width keeps all bits; no sign extension. su_cases.push(([0x8000_0000, 4, 32, 0], 0x0800_0000)); let su_in: Vec<[u32; 4]> = su_cases .iter() .map(|&(inp, _)| [inp[0], (inp[1] & 31) | ((inp[2] & 0x7F) << 16), 0, 0]) .collect(); run_cases(&s_unsigned, &su_in, |backend, i, inp, got| { let want = su_cases[i].1; assert_eq!( got, want, "{backend}: s_bfe_u32({:#010x}, {:#010x}) = {got:#010x}, want {want:#010x}", inp[0], inp[1], ); }); ``` The key case that differs from the signed test: `([0x8000_0000, 4, 32, 0], 0x0800_0000)` — width=32 on a 7-bit field extracts all bits from offset 4 without sign-extending bit 31. No game data needed; the test skips when no SM 6.6 device is available and runs on WARP. **AI-assisted:** found with Kiro (Claude) and independently confirmed by five separate analysis passes without cross-contamination; no hardware run, no game data.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:13:59 +00:00
Author
Owner

@⁠Jxyden34 on GitHub · 2026-11-24 11:25 UTC · original

Tested fix for the missing scalar unsigned case: github.com/Jxyden34/VIctory@0c39a5f7b5. The targeted test passed on native Windows on hardware and WARP. It covers seven inputs, including width 32 with bit 31 set, where the unsigned result is 0x08000000. The commit can be cherry-picked.

**@⁠Jxyden34** on GitHub · 2026-11-24 11:25 UTC · [original](https://github.com/Marvisak/VIctory/issues/803#issuecomment-7130084138) Tested fix for the missing scalar unsigned case: https://github.com/Jxyden34/VIctory/commit/0c39a5f7b5a8b454ef26aa3e5e117906b0f3fd47. The targeted test passed on native Windows on hardware and WARP. It covers seven inputs, including width 32 with bit 31 set, where the unsigned result is 0x08000000. The commit can be cherry-picked.
Author
Owner

@⁠towiice on GitHub · 2026-11-24 12:17 UTC · original

Adding an NVIDIA Turing hardware verification data point (GTX 1650 SUPER, 4 GB VRAM, wave32, driver 610.88, Windows 11 26300, stable-x86_64-pc-windows-gnullvm):

  • Extended bfe_signed_and_unsigned_match_rdna2 with s_bfe_u32 (SOP2 0x27), including the 7-bit width=32 unsigned case (0x8000_0000, offset 4, width 32 -> 0x0800_0000), on https://github.com/towiice/VIctory/tree/test/valu-f32-class-and-s-bfe-u32 (commit fb441bf).
  • cargo +stable-x86_64-pc-windows-gnullvm test -p victory-shader --lib bfe_signed_and_unsigned_match_rdna2: 1 passed, 0 failed (3.74 s, both hardware GPU and WARP).
**@⁠towiice** on GitHub · 2026-11-24 12:17 UTC · [original](https://github.com/Marvisak/VIctory/issues/803#issuecomment-7131232714) Adding an NVIDIA Turing hardware verification data point (`GTX 1650 SUPER`, 4 GB VRAM, wave32, driver `610.88`, Windows 11 26300, `stable-x86_64-pc-windows-gnullvm`): - Extended `bfe_signed_and_unsigned_match_rdna2` with `s_bfe_u32` (SOP2 `0x27`), including the 7-bit width=32 unsigned case (`0x8000_0000`, offset 4, width 32 -> `0x0800_0000`), on https://github.com/towiice/VIctory/tree/test/valu-f32-class-and-s-bfe-u32 (commit `fb441bf`). - `cargo +stable-x86_64-pc-windows-gnullvm test -p victory-shader --lib bfe_signed_and_unsigned_match_rdna2`: **1 passed, 0 failed** (3.74 s, both hardware GPU and WARP).
Author
Owner

@⁠Altorru on GitHub · 2026-11-24 12:17 UTC · original

s_bfe_u32 (SOP2 0x27) is added to bfe_signed_and_unsigned_match_rdna2 with the shared 7-bit width field, the unsigned 0x0800_0000 width=32 case, and the same unsigned cases as the vector form. Implemented in fork PR Altorru/VIctory#1 (upstream PR creation is collaborator-only), commit bb3a37b. Windows CI passed: cargo test --workspace on https://github.com/Altorru/VIctory/actions/runs/45391712656, where the new test ran on WARP. No game data.

**@⁠Altorru** on GitHub · 2026-11-24 12:17 UTC · [original](https://github.com/Marvisak/VIctory/issues/803#issuecomment-7131241250) s_bfe_u32 (SOP2 0x27) is added to bfe_signed_and_unsigned_match_rdna2 with the shared 7-bit width field, the unsigned 0x0800_0000 width=32 case, and the same unsigned cases as the vector form. Implemented in fork PR Altorru/VIctory#1 (upstream PR creation is collaborator-only), commit bb3a37b. Windows CI passed: cargo test --workspace on https://github.com/Altorru/VIctory/actions/runs/45391712656, where the new test ran on WARP. No game data.
Author
Owner

@⁠Beeak on GitHub · 2026-11-24 13:14 UTC · original

Added a standalone synthetic scalar integration test for s_bfe_u32 (SOP2 0x027) in crates/victory-shader/tests/s_bfe_u32_test.rs (zero existing files modified), implemented in fork PR https://github.com/Beeak/VIctory/pull/1 (commit a1703c7, since upstream PR creation is collaborator-only).

Covers:

  • Zero-extension across bit 31 and inside 32 bits
  • 7-bit width masking (src1[22:16]): width = 0, 31, 32, 64, 127, and ignored upper bits (bits 31:23)
  • 5-bit offset masking (src1[4:0]): offsets >= 32 and ignored bits (15:5)

Verified locally on Windows (rustc 1.98.1):

  • cargo test -p victory-shader --features host --test s_bfe_u32_test: 2 passed, 0 failed (hardware GPU and WARP)
  • cargo test -p victory-shader -- --test-threads=1: 120 passed, 0 failed, 1 ignored (unit tests); 1 passed, 0 failed (s_bfe_u32_test)
  • cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings: clean
  • cargo xtask policy: 155 files ok

All input data is synthetic; no game data was used.

**@⁠Beeak** on GitHub · 2026-11-24 13:14 UTC · [original](https://github.com/Marvisak/VIctory/issues/803#issuecomment-7132542534) Added a standalone synthetic scalar integration test for `s_bfe_u32` (SOP2 `0x027`) in `crates/victory-shader/tests/s_bfe_u32_test.rs` (zero existing files modified), implemented in fork PR https://github.com/Beeak/VIctory/pull/1 (commit `a1703c7`, since upstream PR creation is collaborator-only). Covers: - Zero-extension across bit 31 and inside 32 bits - 7-bit width masking (`src1[22:16]`): `width = 0`, `31`, `32`, `64`, `127`, and ignored upper bits (`bits 31:23`) - 5-bit offset masking (`src1[4:0]`): offsets >= 32 and ignored bits (`15:5`) Verified locally on Windows (`rustc 1.98.1`): - `cargo test -p victory-shader --features host --test s_bfe_u32_test`: 2 passed, 0 failed (hardware GPU and WARP) - `cargo test -p victory-shader -- --test-threads=1`: 120 passed, 0 failed, 1 ignored (unit tests); 1 passed, 0 failed (`s_bfe_u32_test`) - `cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings`: clean - `cargo xtask policy`: 155 files ok All input data is synthetic; no game data was used.
Author
Owner

@⁠jules47800 on GitHub · 2026-11-25 01:25 UTC · original

Covered on main since 328eec1 (2026-11-24). scalar_probes() in crates/victory-shader/src/emit/semantics_tests.rs runs s_bfe_u32 (SOP2 0x27) as sop2_probe(0x27, fields, bfe_u). Its inputs cover offsets 0, 4, 16, 28, 31, 32 and widths 0, 1, 4, 16, 31, 32, 33, 0x7F over five sources, so the width ≥ 32 branch is included, and it checks SCC too. That's scalar_alu_matches_the_hardware, which passes on an RX 6600 XT and on WARP at 42363ab. This issue can be closed.

**@⁠jules47800** on GitHub · 2026-11-25 01:25 UTC · [original](https://github.com/Marvisak/VIctory/issues/803#issuecomment-7149526603) Covered on main since `328eec1` (2026-11-24). `scalar_probes()` in `crates/victory-shader/src/emit/semantics_tests.rs` runs `s_bfe_u32` (SOP2 0x27) as `sop2_probe(0x27, fields, bfe_u)`. Its inputs cover offsets 0, 4, 16, 28, 31, 32 and widths 0, 1, 4, 16, 31, 32, 33, 0x7F over five sources, so the width ≥ 32 branch is included, and it checks SCC too. That's `scalar_alu_matches_the_hardware`, which passes on an RX 6600 XT and on WARP at `42363ab`. This issue can be closed.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 03:53 UTC · original

Automated triage for the maintainers.

Fixed in main. Commit 328eec1 (2026-11-24) added scalar_probes() in crates/victory-shader/src/emit/semantics_tests.rs, which runs s_bfe_u32 (SOP2 0x27) as sop2_probe(0x27, ...). Its widths include 32, 33 and 0x7F, so the width >= 32 branch is covered. It runs on the hardware and WARP through scalar_alu_matches_the_hardware. That is the test this issue asks for.

This issue will be closed in 48 hours unless the reporter replies or a maintainer removes the triage: proposed close label.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 03:53 UTC · [original](https://github.com/Marvisak/VIctory/issues/803#issuecomment-7152341810) <!-- victory-issue-triage v1 verdict=proposed-close seen=2026-11-25T01:25:13Z at=2026-11-25T03:53:53Z --> Automated triage for the maintainers. Fixed in `main`. Commit 328eec1 (2026-11-24) added `scalar_probes()` in `crates/victory-shader/src/emit/semantics_tests.rs`, which runs `s_bfe_u32` (SOP2 0x27) as `sop2_probe(0x27, ...)`. Its widths include 32, 33 and 0x7F, so the `width >= 32` branch is covered. It runs on the hardware and WARP through `scalar_alu_matches_the_hardware`. That is the test this issue asks for. This issue will be closed in 48 hours unless the reporter replies or a maintainer removes the `triage: proposed close` label. --- _Generated by [Claude Code](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory#803
No description provided.