shader: lower s_nand_b64, s_nor_b64 and s_xnor_b64 in pixel_aot #394

Merged
denn0x merged 1 commit from upstream-pr/400 into main 2026-11-22 03:03:23 +00:00
denn0x commented 2026-11-22 00:21:23 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-22T00:21:23Z.


Change

This advances pixel_aot scalar ALU coverage with three gfx1013 SOP2 forms: s_nand_b64, s_nor_b64 and s_xnor_b64. They join the merged 64-bit SALU_BIT64 table next to s_andn2_b64 and s_orn2_b64, which is the shared interface. No open PR lists these forms (#257 is the 32-bit scalar ALU), and no prerequisite PR is needed. Until now check_controls rejected them only as forms that were not lowered yet.

  • Lowering: each form inverts the 64-bit AND, OR or XOR of its sources across the SGPR pair, and sets SCC when the result is nonzero, like the other SALU_BIT64 operations. Operand handling (pairs, inline constants, literals, pending loads) is the existing scalar_u64 path.

Tests

  • scalar64() draw: for each form, the register-pair result goes into the hash, and an SCC probe is observed through s_cmov_b64 of a distinct literal. That is needed because channel 3 exports only SCC bits 0–9. Each probe is tested in both SCC states:
    • s_nand_b64 -1, -1 is zero;
    • s_nor_b64 with -1 is zero;
    • s_xnor_b64 of the alternate pair with -1 is zero only in Set 2.
  • Reference: scalar64_reference models the three forms independently with Python integers.
  • New mutations, which must report pixel_mismatch: nand to and, nor to or, xnor to xor, and the nor probe's -1 operand replaced with 0.
  • Coverage: tests/form_coverage_check.py moves the three forms from rejected_forms to scalar64_forms for gfx1013 and RDNA 2. Other rejected neighbors (s_cselect_b64, s_bfe_u64, s_bfe_i64, saveexec) stay rejected.

Fixture fix this needed

The final fold of the 64-bit accumulator repeated x ^= x >> 30. That equals x ^ (x >> 60), so accumulator bits 30–59 never reached a pixel, although the comment said all 64 bits were folded. I checked this by flipping each input bit: the old fold ignores exactly bits 30–59, and the new one ignores none.

With the new mixing steps, the existing signed-right-shift mutation landed in those bits and escaped detection. The fold now computes acc ^ (acc >> 30) ^ (acc >> 60), with both shifts taken from the original value. All four existing mutations still report a mismatch.

Verification

Windows 11 build 26200, Windows SDK 10.0.26100.0, DXC 1.8.2502.11, D3D12 debug layer enabled. Hardware: AMD Radeon RX 9070 XT (vendor 1002, device 7550), driver 32.0.32015.7029. WARP: Microsoft Basic Render Driver 10.0.26100.9818. Commit 3f17959 on 4f6c39d.

tests/pixel_aot_check.py draw ... hardware: exit 0, every draw max_absolute_error=0, debug_errors=0 debug_warnings=0
tests/pixel_aot_check.py draw ... warp:     exit 0, every draw max_absolute_error=0, debug_errors=0 debug_warnings=0
tests/form_coverage_check.py: form coverage checks passed

Mutation check (local, reverted): removing the low-half inversion from the nand lowering in tools/pixel_aot.py fails the WARP draw with pixel_mismatch x=0 y=0.

Not run locally: tests/pixel_aot_check.py binary, because this machine has no LLVM with gfx1013. scalar64() is already in check_binary, so Ubuntu CI assembles and round-trips the new lines.

Checklist

  • This pull request covers one reviewable behavior. The fold fix is needed for its negative controls.
  • I included the exact command and result for every check I ran.
  • It includes negative controls: five program mutations and one translator mutation.
  • docs/experiments.md is updated.
  • No game files, dumps or binaries.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6536274146 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/400). Originally posted by [denn0x](https://github.com/denn0x) on 2026-11-22T00:21:23Z. --- ## Change This advances `pixel_aot` scalar ALU coverage with three gfx1013 SOP2 forms: `s_nand_b64`, `s_nor_b64` and `s_xnor_b64`. They join the merged 64-bit `SALU_BIT64` table next to `s_andn2_b64` and `s_orn2_b64`, which is the shared interface. No open PR lists these forms (#257 is the 32-bit scalar ALU), and no prerequisite PR is needed. Until now `check_controls` rejected them only as forms that were not lowered yet. - **Lowering:** each form inverts the 64-bit AND, OR or XOR of its sources across the SGPR pair, and sets SCC when the result is nonzero, like the other `SALU_BIT64` operations. Operand handling (pairs, inline constants, literals, pending loads) is the existing `scalar_u64` path. ## Tests - **`scalar64()` draw:** for each form, the register-pair result goes into the hash, and an SCC probe is observed through `s_cmov_b64` of a distinct literal. That is needed because channel 3 exports only SCC bits 0–9. Each probe is tested in both SCC states: - `s_nand_b64 -1, -1` is zero; - `s_nor_b64` with -1 is zero; - `s_xnor_b64` of the alternate pair with -1 is zero only in Set 2. - **Reference:** `scalar64_reference` models the three forms independently with Python integers. - **New mutations, which must report `pixel_mismatch`:** `nand` to `and`, `nor` to `or`, `xnor` to `xor`, and the `nor` probe's -1 operand replaced with 0. - **Coverage:** `tests/form_coverage_check.py` moves the three forms from `rejected_forms` to `scalar64_forms` for gfx1013 and RDNA 2. Other rejected neighbors (`s_cselect_b64`, `s_bfe_u64`, `s_bfe_i64`, `saveexec`) stay rejected. ### Fixture fix this needed The final fold of the 64-bit accumulator repeated `x ^= x >> 30`. That equals `x ^ (x >> 60)`, so accumulator bits 30–59 never reached a pixel, although the comment said all 64 bits were folded. I checked this by flipping each input bit: the old fold ignores exactly bits 30–59, and the new one ignores none. With the new mixing steps, the existing signed-right-shift mutation landed in those bits and escaped detection. The fold now computes `acc ^ (acc >> 30) ^ (acc >> 60)`, with both shifts taken from the original value. All four existing mutations still report a mismatch. ## Verification Windows 11 build 26200, Windows SDK 10.0.26100.0, DXC 1.8.2502.11, D3D12 debug layer enabled. Hardware: AMD Radeon RX 9070 XT (vendor 1002, device 7550), driver 32.0.32015.7029. WARP: Microsoft Basic Render Driver 10.0.26100.9818. Commit `3f17959` on `4f6c39d`. ```text tests/pixel_aot_check.py draw ... hardware: exit 0, every draw max_absolute_error=0, debug_errors=0 debug_warnings=0 tests/pixel_aot_check.py draw ... warp: exit 0, every draw max_absolute_error=0, debug_errors=0 debug_warnings=0 tests/form_coverage_check.py: form coverage checks passed ``` **Mutation check (local, reverted):** removing the low-half inversion from the `nand` lowering in `tools/pixel_aot.py` fails the WARP draw with `pixel_mismatch x=0 y=0`. Not run locally: `tests/pixel_aot_check.py binary`, because this machine has no LLVM with gfx1013. `scalar64()` is already in `check_binary`, so Ubuntu CI assembles and round-trips the new lines. ## Checklist - [x] This pull request covers one reviewable behavior. The fold fix is needed for its negative controls. - [x] I included the exact command and result for every check I ran. - [x] It includes negative controls: five program mutations and one translator mutation. - [x] `docs/experiments.md` is updated. - [x] No game files, dumps or binaries. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-24 06:42:51 +00:00
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
R0Y00/Xbox2Windows!394
No description provided.