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

Open
opened 2026-11-26 21:19:25 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1913
Author: @ShotTechOp
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/wint-diff-ref-validation


📝 Commits (1)

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

📊 Changes

2 files changed (+226 additions, -38 deletions)

View changed files

📝 tests/test_wint_diff.py (+77 -0)
📝 tools/wint_diff.py (+149 -38)

📄 Description

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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1913 **Author:** [@ShotTechOp](https://github.com/ShotTechOp) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/wint-diff-ref-validation` --- ### 📝 Commits (1) - [`395bbc1`](https://github.com/ubiquitarianism/leonida/commit/395bbc12a1b14b82cd47dc8c6ac418ebabc13190) wint_diff: model v_mbcnt/v_writelane operands and validate masks, pairs, op_sel, and arity (WINT-DIFF-REF-VALIDATION) ### 📊 Changes **2 files changed** (+226 additions, -38 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_wint_diff.py` (+77 -0) 📝 `tools/wint_diff.py` (+149 -38) </details> ### 📄 Description 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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
starred/leonida#1922
No description provided.