wint_diff: model v_mbcnt/v_writelane operands and validate masks, pairs, op_sel, and arity (WINT-DIFF-REF-VALIDATION) #1913

Merged
leonida/mandy
ShotTechOp merged 1 commit from fix/wint-diff-ref-validation into main 2026-11-28 11:42:34 +00:00

Pull request successfully merged and closed

ShotTechOp commented 2026-11-25 15:40:04 +00:00

Claimed in #1608 as WINT-DIFF-REF-VALIDATION (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7167118909).

What and why

tools/wint_diff.py's whole-wave integer VALU reference interpreter had two semantic shortcuts and accepted malformed operands silently (or raised raw ValueError/KeyError/IndexError/TypeError instead of RefError):

  1. Full v_mbcnt_lo_u32_b32 / v_mbcnt_hi_u32_b32 semantics (step): previously hardcoded to write [min(lane, 32)] / [v0 + max(0, lane - 32)] unconditionally into v0, ignoring the destination VGPR, bitmask src0, addend src1, and EXEC. Both now compute popcount(src0 & mask_below_lane) + src1 into the named destination VGPR for active lanes only (cross-checked against rdna2spirv.py).
  2. v_writelane_b32 semantics (step): previously indexed v[args[0][1:]][int(args[2])] = st.sget(args[1]), rejecting inline constants (7), crashing on SGPR lane selectors (s5) or out-of-wave lane indices (32 in wave32), and accepting SGPR destinations. It now evaluates scalar/immediate src0 and src1, wraps lane selection mod st.wave, and validates a VGPR destination.
  3. Register, pair, wave-mask, op_sel, and arity validation (State, step):
    • s_mov_b32 now rejects VGPR destinations/sources and wave32 exec_hi.
    • State.mask / State.set_mask enforce wave-matching mask operands (sN/vcc_lo in wave32, s[N:N+1]/vcc in wave64) and consecutive pairs.
    • v_cmp_*/v_cmpx_* reject unknown compare predicates with RefError instead of KeyError.
    • CARRY requires 5 operands for _ci_ forms and 4 otherwise (previously a missing carry-in silently defaulted to 0).
    • MAD64 validates consecutive VGPR pairs v[N:N+1], OPS16 validates op_sel length (nsrc + 1), and all VGPR destinations reject non-VGPR tokens instead of stripping character 0.

Verification (Windows 11 x64, Python 3.12.10, no GPU / no game data)

Check Base (origin/main b0f3d39) This PR
python -I tests/test_wint_diff.py 29/29 OK 31/31 OK (incl. translator cross-check)
New regression tests against base tools/wint_diff.py (negative control) FAILED (23 failures, 10 errors) 2/2 OK
python -I tools/wint_diff.py --self-test pass pass
python -m compileall -q tools/wint_diff.py tests/test_wint_diff.py — pass
python -I scripts/check_no_game_data.py tools/wint_diff.py tests/test_wint_diff.py — pass
git diff --check — clean

AI-assisted: yes. Synthetic unit tests only; no game data, no GPU required.

Claimed in #1608 as `WINT-DIFF-REF-VALIDATION` (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7167118909). ### What and why `tools/wint_diff.py`'s whole-wave integer VALU reference interpreter had two semantic shortcuts and accepted malformed operands silently (or raised raw `ValueError`/`KeyError`/`IndexError`/`TypeError` instead of `RefError`): 1. **Full `v_mbcnt_lo_u32_b32` / `v_mbcnt_hi_u32_b32` semantics (`step`):** previously hardcoded to write `[min(lane, 32)]` / `[v0 + max(0, lane - 32)]` unconditionally into `v0`, ignoring the destination VGPR, bitmask `src0`, addend `src1`, and `EXEC`. Both now compute `popcount(src0 & mask_below_lane) + src1` into the named destination VGPR for active lanes only (cross-checked against `rdna2spirv.py`). 2. **`v_writelane_b32` semantics (`step`):** previously indexed `v[args[0][1:]][int(args[2])] = st.sget(args[1])`, rejecting inline constants (`7`), crashing on SGPR lane selectors (`s5`) or out-of-wave lane indices (`32` in wave32), and accepting SGPR destinations. It now evaluates scalar/immediate `src0` and `src1`, wraps lane selection mod `st.wave`, and validates a VGPR destination. 3. **Register, pair, wave-mask, `op_sel`, and arity validation (`State`, `step`):** - `s_mov_b32` now rejects VGPR destinations/sources and wave32 `exec_hi`. - `State.mask` / `State.set_mask` enforce wave-matching mask operands (`sN`/`vcc_lo` in wave32, `s[N:N+1]`/`vcc` in wave64) and consecutive pairs. - `v_cmp_*`/`v_cmpx_*` reject unknown compare predicates with `RefError` instead of `KeyError`. - `CARRY` requires 5 operands for `_ci_` forms and 4 otherwise (previously a missing carry-in silently defaulted to `0`). - `MAD64` validates consecutive VGPR pairs `v[N:N+1]`, `OPS16` validates `op_sel` length (`nsrc + 1`), and all VGPR destinations reject non-VGPR tokens instead of stripping character 0. ### Verification (Windows 11 x64, Python 3.12.10, no GPU / no game data) | Check | Base (`origin/main` `b0f3d39`) | This PR | |---|---|---| | `python -I tests/test_wint_diff.py` | 29/29 OK | **31/31 OK** (incl. translator cross-check) | | New regression tests against base `tools/wint_diff.py` (negative control) | **FAILED (23 failures, 10 errors)** | **2/2 OK** | | `python -I tools/wint_diff.py --self-test` | pass | **pass** | | `python -m compileall -q tools/wint_diff.py tests/test_wint_diff.py` | — | **pass** | | `python -I scripts/check_no_game_data.py tools/wint_diff.py tests/test_wint_diff.py` | — | **pass** | | `git diff --check` | — | **clean** | AI-assisted: yes. Synthetic unit tests only; no game data, no GPU required.
DeadlyChirp commented 2026-11-25 15:53:51 +00:00

Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main.

python -m pytest -q tests/test_wint_diff.py:

  • PR: 31 passed. main: 29 passed. The new tests pass on Windows.

(AI-assisted test run; output checked by hand.)

Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main. `python -m pytest -q tests/test_wint_diff.py`: - PR: 31 passed. main: 29 passed. The new tests pass on Windows. (AI-assisted test run; output checked by hand.)
sodove commented 2026-11-28 11:28:10 +00:00

#1913 | head 395bbc12a1b14b82cd47dc8c6ac418ebabc13190 | python3 -I tests/test_wint_diff.py -v | red: 31 run, 23 failures, 10 errors | green: 31 passed | Red → green

The reference-model tests exercise operand/EXEC handling, lane operations and validation, including hardware-oracle error paths. The test file passed in full after merging.

Copied the PR tests onto clean main 4a54aedcb6b66525e0c9f72a6ea10263337c9141 for the baseline, then merged that main into the recorded PR head and reran those files. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Unittest failure/error counts include subtests where applicable. AI-assisted with OpenAI Codex. Batch claim.

#1913 | head `395bbc12a1b14b82cd47dc8c6ac418ebabc13190` | `python3 -I tests/test_wint_diff.py -v` | red: 31 run, 23 failures, 10 errors | green: 31 passed | **Red → green** The reference-model tests exercise operand/EXEC handling, lane operations and validation, including hardware-oracle error paths. The test file passed in full after merging. Copied the PR tests onto clean main `4a54aedcb6b66525e0c9f72a6ea10263337c9141` for the baseline, then merged that main into the recorded PR head and reran those files. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Unittest failure/error counts include subtests where applicable. AI-assisted with OpenAI Codex. [Batch claim](https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7238450840).
DadaCap commented 2026-11-28 11:42:36 +00:00

Merged, thank you @ShotTechOp! This PR (wint_diff: model v_mbcnt/v_writelane operands and validate masks, pairs, op_sel, and arity (WINT-DIFF-REF-VALIDATION)) passed its own tests with main merged in during sodove's verification of this shader batch, so it went in with the batch.

AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

Merged, thank you @ShotTechOp! This PR (wint_diff: model v_mbcnt/v_writelane operands and validate masks, pairs, op_sel, and arity (WINT-DIFF-REF-VALIDATION)) passed its own tests with main merged in during sodove's verification of this shader batch, so it went in with the batch. AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.
Sign in to join this conversation.
No description provided.