shader: cover four scalar leading-bit scan lowerings #687

Manually merged
github merged 2 commits from gh-pr/687/head into gh-pr/687/base 2026-11-26 22:11:43 +00:00
Owner

@⁠Leyukaka on GitHub · 2026-11-22 20:02 UTC · original
Leyukaka:flbit-controls → main · +7 −4 · 1 files · 2 commits · merged 2026-11-22 23:01 UTC

Change

This closes four coverage gaps in the scalar leading-bit scan lowering of tools/pixel_aot.py (s_flbit_i32_b32, s_flbit_i32, s_flbit_i32_b64, s_flbit_i32_i64). Each was a one-line mutation that passed every WARP test on main. Only tests/pixel_aot_check.py changes (13 added, 2 changed lines); the translator does not.

New input Mutation it covers
s_flbit_i32 of 0x40000000 (result 1) signed 32-bit scan also normalizes on bit 30
s_flbit_i32_b32 of 0x00010000 (result 15) unsigned scan masks bit 16
s_flbit_i32_i64 with high word 0x40000000 (result 1) signed 64-bit scan also normalizes on bit 62
a second draw that sets SCC to false before each scan of a zero pair a scan that finds no bit writes SCC

s_flbit does not write SCC, so after s_cmp_lg_u32 of two zero words both b64 and i64 scans must return 0xffffffff with SCC still false. The new rows are prepended, so the existing mismatch control still reuses its last case.

Not covered: a 32-bit hex literal used as the 64-bit source. The translator zero-extends it (except for s_ashr_i64). I have not checked that against hardware, so this PR does not fix that behavior in a test.

Verification

On bb6ba2f (branch on 5748b02), Windows 11 build 26300.9974, MSVC 14.44.35207, Python 3.14, WARP:

ctest --preset dev --no-tests=error -j 4

All 297 tests pass.

Each mutation was applied to tools/pixel_aot.py one at a time, and all WARP tests were run. On main, all of them passed for each mutation. A control that changed the 64-bit result (63u to 62u) was caught by pixel_aot_predicate_rounding_warp, so the run does detect a broken translator. On this branch, each of the four mutations fails pixel_aot_predicate_rounding_warp.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed. (No capability changed.)
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

**@⁠Leyukaka** on GitHub · 2026-11-22 20:02 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/687) `Leyukaka:flbit-controls` → `main` · +7 −4 · 1 files · 2 commits · merged 2026-11-22 23:01 UTC ## Change This closes four coverage gaps in the scalar leading-bit scan lowering of `tools/pixel_aot.py` (`s_flbit_i32_b32`, `s_flbit_i32`, `s_flbit_i32_b64`, `s_flbit_i32_i64`). Each was a one-line mutation that passed every WARP test on `main`. Only `tests/pixel_aot_check.py` changes (13 added, 2 changed lines); the translator does not. | New input | Mutation it covers | |---|---| | `s_flbit_i32` of `0x40000000` (result 1) | signed 32-bit scan also normalizes on bit 30 | | `s_flbit_i32_b32` of `0x00010000` (result 15) | unsigned scan masks bit 16 | | `s_flbit_i32_i64` with high word `0x40000000` (result 1) | signed 64-bit scan also normalizes on bit 62 | | a second draw that sets SCC to false before each scan of a zero pair | a scan that finds no bit writes SCC | `s_flbit` does not write SCC, so after `s_cmp_lg_u32` of two zero words both `b64` and `i64` scans must return `0xffffffff` with SCC still false. The new rows are prepended, so the existing mismatch control still reuses its last case. Not covered: a 32-bit hex literal used as the 64-bit source. The translator zero-extends it (except for `s_ashr_i64`). I have not checked that against hardware, so this PR does not fix that behavior in a test. ## Verification On `bb6ba2f` (branch on `5748b02`), Windows 11 build 26300.9974, MSVC 14.44.35207, Python 3.14, WARP: ```text ctest --preset dev --no-tests=error -j 4 ``` All 297 tests pass. Each mutation was applied to `tools/pixel_aot.py` one at a time, and all WARP tests were run. On `main`, all of them passed for each mutation. A control that changed the 64-bit result (`63u` to `62u`) was caught by `pixel_aot_predicate_rounding_warp`, so the run does detect a broken translator. On this branch, each of the four mutations fails `pixel_aot_predicate_rounding_warp`. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [ ] I updated README/docs when a capability or build requirement changed. (No capability changed.) - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted.
The leading-bit draw gains s_flbit_i32 on 0x40000000, s_flbit_i32_b32
on 0x00010000 and s_flbit_i32_i64 on a high word of 0x40000000, plus a
draw that seeds SCC false before each scan of a zero pair, since
s_flbit does not write SCC. Each covers a pixel_aot mutation that passed
every WARP test before.
The leading-bit program now seeds SCC with s_cmp_lg_u32, so every row
in both widths expects SCC = (lo != hi) after the scans. The zero pair
that finds no bit keeps the false seed in the 32-bit and 64-bit paths,
and the separate SCC draw and its compile are gone.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:11:43 +00:00
github manually merged commit 08f8307293 into gh-pr/687/base 2026-11-26 22:11:43 +00:00
Author
Owner

@⁠thepatrickworld on GitHub · 2026-11-22 20:52 UTC · original · edited 2026-11-22 21:28 UTC

Verification: #687 shader: cover four scalar leading-bit scan lowerings

Head bb6ba2f7, merged with main. One file, tests/pixel_aot_check.py, +13/−2. No translator
change: coverage only.

What it adds

Three rows to check_scalar_leading_bit_draw:

  • 32-bit 0x40000000 — the top bit is clear, the second one set;
  • 32-bit 0x00010000 — a single bit near the middle;
  • 64-bit (0, 0x40000000) — the only set bit sits at bit 62, so the scan has to cross into the high
    word and skip its top bit.

Plus a separate case that seeds SCC false with s_cmp_lg_u32 before scanning a zero pair, to check
that s_flbit does not write SCC.

Environment

Windows 11 25H2 build 26200.9711, MSVC 19.44.35230, DXC 1.9.2602.17, RX 9070 XT (RDNA4), driver
32.0.32029.2010.

Commands and output

ctest --preset dev --no-tests=error -R "^pixel_aot_"
100% tests passed out of 22

Negative control: I removed the inversion from the ffbh helper (31u - firstbithigh(x) became
firstbithigh(x)) and re-ran ^pixel_aot_hardware$:

0% tests passed, 1 tests failed out of 1

The reserve

The SCC case is not tautological, but its scope is narrower than the comment suggests.

For 32 bits the fixture already had this exact case: (0, 1) gives word = 0 with SCC seeded false
by s_cmp_eq_u32 s44, s45 (0 == 1 is false), and the expected result is false. The 64-bit path had
nothing: there (0, 1) gives word = 0x1_00000000, and (0, 0) seeds SCC true. So an
implementation modelling SCC = (source == 0) passed the 64-bit path before this PR.

What the case actually pins down is that model. Slim, but real. Against the ISA: S_FLBIT_I32_*
documents only the destination, with no SCC line, unlike S_ABS_I32 whose entry says "SCC=1 if result
is non-zero". The translator's table (l. 849-850) and its 64-bit path (l. 1654-1666) both leave SCC
alone, which is consistent.

It still says nothing about hardware: it compares the translator against itself. And one row cannot
test the write order if SCC and the destination were both written.

The new 64-bit scan row is the strongest of the three: it is the first case where the top bit of the
high word is zero while a lower bit is set, which is what a naive "scan the high word from the top"
gets wrong.

What I would add

The SCC block pays a compile_shader plus a draw for one line. Parameterise the seed
(scalar_leading_bit_values(width, seed="eq"|"lg")) and add the row to the existing case, in 32 bits
as well: the two translator paths are distinct — the SCALAR table for b32, a dedicated block for
b64 — so covering both is not redundant, and it removes a compilation.

What this does not prove

  • Nothing about the s_flbit_i32 signed variant beyond what the existing rows covered.
  • Nothing about the order in which SCC and the destination are written, if both are written.
  • Helper-lane behaviour is untouched by this PR.

Merge note: this head, #679 and #683 branch from the same blob (11f47701) on the same file. Their hunks are disjoint, so no conflict today, but each will need a rebase after the first one lands.

AI-assisted; runs executed locally.

**@⁠thepatrickworld** on GitHub · 2026-11-22 20:52 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/687#issuecomment-7085617914) · edited 2026-11-22 21:28 UTC **Verification: #687 `shader: cover four scalar leading-bit scan lowerings`** Head `bb6ba2f7`, merged with `main`. One file, `tests/pixel_aot_check.py`, +13/−2. No translator change: coverage only. ### What it adds Three rows to `check_scalar_leading_bit_draw`: - 32-bit `0x40000000` — the top bit is clear, the second one set; - 32-bit `0x00010000` — a single bit near the middle; - 64-bit `(0, 0x40000000)` — the only set bit sits at bit 62, so the scan has to cross into the high word and skip its top bit. Plus a separate case that seeds SCC false with `s_cmp_lg_u32` before scanning a zero pair, to check that `s_flbit` does not write SCC. ### Environment Windows 11 25H2 build 26200.9711, MSVC 19.44.35230, DXC 1.9.2602.17, RX 9070 XT (RDNA4), driver 32.0.32029.2010. ### Commands and output ``` ctest --preset dev --no-tests=error -R "^pixel_aot_" 100% tests passed out of 22 ``` Negative control: I removed the inversion from the `ffbh` helper (`31u - firstbithigh(x)` became `firstbithigh(x)`) and re-ran `^pixel_aot_hardware$`: ``` 0% tests passed, 1 tests failed out of 1 ``` ### The reserve The SCC case is not tautological, but its scope is narrower than the comment suggests. For 32 bits the fixture already had this exact case: `(0, 1)` gives `word = 0` with SCC seeded false by `s_cmp_eq_u32 s44, s45` (`0 == 1` is false), and the expected result is false. The 64-bit path had nothing: there `(0, 1)` gives `word = 0x1_00000000`, and `(0, 0)` seeds SCC true. So an implementation modelling `SCC = (source == 0)` passed the 64-bit path before this PR. What the case actually pins down is that model. Slim, but real. Against the ISA: `S_FLBIT_I32_*` documents only the destination, with no SCC line, unlike `S_ABS_I32` whose entry says "SCC=1 if result is non-zero". The translator's table (l. 849-850) and its 64-bit path (l. 1654-1666) both leave SCC alone, which is consistent. It still says nothing about hardware: it compares the translator against itself. And one row cannot test the write order if SCC and the destination were both written. The new 64-bit scan row is the strongest of the three: it is the first case where the top bit of the high word is zero while a lower bit is set, which is what a naive "scan the high word from the top" gets wrong. ### What I would add The SCC block pays a `compile_shader` plus a draw for one line. Parameterise the seed (`scalar_leading_bit_values(width, seed="eq"|"lg")`) and add the row to the existing case, in 32 bits as well: the two translator paths are distinct — the SCALAR table for `b32`, a dedicated block for `b64` — so covering both is not redundant, and it removes a compilation. ### What this does not prove - Nothing about the `s_flbit_i32` signed variant beyond what the existing rows covered. - Nothing about the order in which SCC and the destination are written, if both are written. - Helper-lane behaviour is untouched by this PR. Merge note: this head, #679 and #683 branch from the same blob (`11f47701`) on the same file. Their hunks are disjoint, so no conflict today, but each will need a rebase after the first one lands. _AI-assisted; runs executed locally._
Author
Owner

@⁠Leyukaka on GitHub · 2026-11-22 21:04 UTC · original

Thanks for the run on RDNA4, and for checking the ISA entry.

Agreed on the scope: the 32-bit path already had a zero source with SCC seeded false ((0, 1)), and the 64-bit path did not. The new case rules out an SCC = (source == 0) model on the 64-bit path. It does not show more than that, and it compares the translator against its own reference, not hardware.

Folding the seed into scalar_leading_bit_values would save one compile, though the row would still need its draw. I kept a separate draw so the existing rows stay unchanged; I can fold it in, with the row in both widths, if that is preferred.

AI-assisted.

**@⁠Leyukaka** on GitHub · 2026-11-22 21:04 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/687#issuecomment-7085771134) Thanks for the run on RDNA4, and for checking the ISA entry. Agreed on the scope: the 32-bit path already had a zero source with SCC seeded false (`(0, 1)`), and the 64-bit path did not. The new case rules out an `SCC = (source == 0)` model on the 64-bit path. It does not show more than that, and it compares the translator against its own reference, not hardware. Folding the seed into `scalar_leading_bit_values` would save one compile, though the row would still need its draw. I kept a separate draw so the existing rows stay unchanged; I can fold it in, with the row in both widths, if that is preferred. AI-assisted.
Author
Owner

@⁠thepatrickworld on GitHub · 2026-11-22 21:57 UTC · original

Yes — fold it in, with the row in both widths. The two translator paths are distinct (the SCALAR table for b32, the dedicated block for b64), so the 32-bit row is not redundant even though (0, 1) already seeds false there, and dropping one compile_shader is worth it.

Thanks for stating the reference-vs-hardware limit plainly instead of dressing it up; that is the right way to describe what the case pins down.

AI-assisted.

**@⁠thepatrickworld** on GitHub · 2026-11-22 21:57 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/687#issuecomment-7086444401) Yes — fold it in, with the row in both widths. The two translator paths are distinct (the SCALAR table for `b32`, the dedicated block for `b64`), so the 32-bit row is not redundant even though `(0, 1)` already seeds false there, and dropping one `compile_shader` is worth it. Thanks for stating the reference-vs-hardware limit plainly instead of dressing it up; that is the right way to describe what the case pins down. _AI-assisted._
Author
Owner

@⁠Leyukaka on GitHub · 2026-11-22 22:48 UTC · original

Folded in 08f8307. The leading-bit program now seeds SCC with s_cmp_lg_u32, so every row in both widths expects SCC = lo != hi after the scans. The (0, 0) row, which finds no bit, keeps the false seed through s_flbit_i32_b32/s_flbit_i32 and s_flbit_i32_b64/s_flbit_i32_i64. The separate SCC draw and its compile are removed.

The mutation that sets SCC when the 64-bit scan finds no bit still fails pixel_aot_predicate_rounding_warp. ctest --preset dev --no-tests=error -j 4: 304 of 304 pass on WARP. The branch is rebased on current main.

AI-assisted.

**@⁠Leyukaka** on GitHub · 2026-11-22 22:48 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/687#issuecomment-7087099150) Folded in 08f8307. The leading-bit program now seeds SCC with `s_cmp_lg_u32`, so every row in both widths expects SCC = `lo != hi` after the scans. The `(0, 0)` row, which finds no bit, keeps the false seed through `s_flbit_i32_b32`/`s_flbit_i32` and `s_flbit_i32_b64`/`s_flbit_i32_i64`. The separate SCC draw and its compile are removed. The mutation that sets SCC when the 64-bit scan finds no bit still fails `pixel_aot_predicate_rounding_warp`. `ctest --preset dev --no-tests=error -j 4`: 304 of 304 pass on WARP. The branch is rebased on current `main`. AI-assisted.
This discussion has been locked. Commenting is limited to contributors.
No description provided.