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

Open
github-bot wants to merge 1 commit from github-bot/gh-1913 into main AGit
Owner

@⁠ShotTechOp on GitHub · 2026-11-25 15:40 UTC · original
ShotTechOp:fix/wint-diff-ref-validation → main · +226 −38 · 2 files · 1 commits · open

Claimed in #1608 as WINT-DIFF-REF-VALIDATION (#1608).

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.

**@⁠ShotTechOp** on GitHub · 2026-11-25 15:40 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1913) `ShotTechOp:fix/wint-diff-ref-validation` → `main` · +226 −38 · 2 files · 1 commits · open Claimed in #1608 as `WINT-DIFF-REF-VALIDATION` (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608). ### 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:10:57 +00:00
Author
Owner

@⁠DeadlyChirp on GitHub · 2026-11-25 15:53 UTC · original

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.)

**@⁠DeadlyChirp** on GitHub · 2026-11-25 15:53 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1913#issuecomment-7167409522) 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.)
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1913/head:github-bot/gh-1913'
git switch 'github-bot/gh-1913'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1913'
git switch 'github-bot/gh-1913'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1913'
git switch 'github-bot/gh-1913'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1913'
git switch 'main'
git merge --squash 'github-bot/gh-1913'
git switch 'main'
git merge --ff-only 'github-bot/gh-1913'
git switch 'main'
git merge 'github-bot/gh-1913'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.