wave_diff: validate cross-lane/mask operands, EXEC=0 dsts, DS offsets, and immutability (WAVE-DIFF-REF-VALIDATION) #1809

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

@⁠ShotTechOp on GitHub · 2026-11-25 12:21 UTC · original
ShotTechOp:fix/wave-diff-ref-validation → main · +106 −11 · 2 files · 1 commits · open

Summary

Claimed in #1608 as WAVE-DIFF-REF-VALIDATION: #1608

Hardens tools/wave_diff.py (WaveRef) so malformed or unsupported cross-lane and whole-mask operands raise cf_ref.Unsupported instead of silently reading the low register, flipping sign bits, skipping destination validation under EXEC == 0, raising unhandled ValueError, or mutating the caller's parsed instruction dicts:

  1. Reject multi-dword VGPRs and abs/neg modifiers:
    • _vsrc() requires a single VGPR (n == 1) with no abs/neg modifiers across v_readlane_b32, v_readfirstlane_b32, ds_bpermute_b32, and v_permlane16/x16_b32.
    • _scalar_int_src(), _lane_sel(), _count_src(), and s_not_b32/b64 reject abs/neg modifiers and unexpected instruction modifiers.
  2. Validate VGPR destinations even when EXEC == 0 or referenced source lanes are off:
    • Calls _check_vgpr_dst() upfront in v_writelane_b32, ds_bpermute_b32, and v_permlane16/x16_b32 so invalid destinations (s6, v[2:3]) cannot slip through when no lanes write.
  3. Validate ds_bpermute_b32 offset: modifiers:
    • Rejects duplicate offset: modifiers, non-integer values (raises cf_ref.Unsupported instead of ValueError), and values outside the 16-bit unsigned DS offset range (0..65535).
  4. Do not mutate caller's info["insns"] in WaveRef.__init__:
    • Copies unencoded instruction dicts when assigning placeholder enc/pc instead of mutating caller-owned dicts in place.

Independent of #1780 (tools/cf_ref.py); zero PR dependencies.

Testing

Environment: Windows 11 x64, Python 3.12.10, CPU-only (no GPU or game files; based on 0d80bc5).

  • Negative control on unpatched main (0d80bc5):
    • python -m unittest tests.test_wave_diff.Reference -> FAILED (failures=24, errors=1)
  • After fix:
    • python -I tests/test_wave_diff.py -> 16/16 OK (including canaries and seeded wave32/wave64 fuzz runs)
    • python -m compileall -q tools/wave_diff.py tests/test_wave_diff.py -> exit 0
    • python -I scripts/check_no_game_data.py tools/wave_diff.py tests/test_wave_diff.py -> exit 0
    • git diff --check -> clean

AI-assisted: yes (Antigravity). Synthetic inputs only; no game data.

**@⁠ShotTechOp** on GitHub · 2026-11-25 12:21 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1809) `ShotTechOp:fix/wave-diff-ref-validation` → `main` · +106 −11 · 2 files · 1 commits · open ## Summary Claimed in #1608 as `WAVE-DIFF-REF-VALIDATION`: https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608 Hardens `tools/wave_diff.py` (`WaveRef`) so malformed or unsupported cross-lane and whole-mask operands raise `cf_ref.Unsupported` instead of silently reading the low register, flipping sign bits, skipping destination validation under `EXEC == 0`, raising unhandled `ValueError`, or mutating the caller's parsed instruction dicts: 1. **Reject multi-dword VGPRs and `abs`/`neg` modifiers**: - `_vsrc()` requires a single VGPR (`n == 1`) with no `abs`/`neg` modifiers across `v_readlane_b32`, `v_readfirstlane_b32`, `ds_bpermute_b32`, and `v_permlane16/x16_b32`. - `_scalar_int_src()`, `_lane_sel()`, `_count_src()`, and `s_not_b32/b64` reject `abs`/`neg` modifiers and unexpected instruction modifiers. 2. **Validate VGPR destinations even when `EXEC == 0` or referenced source lanes are off**: - Calls `_check_vgpr_dst()` upfront in `v_writelane_b32`, `ds_bpermute_b32`, and `v_permlane16/x16_b32` so invalid destinations (`s6`, `v[2:3]`) cannot slip through when no lanes write. 3. **Validate `ds_bpermute_b32` `offset:` modifiers**: - Rejects duplicate `offset:` modifiers, non-integer values (raises `cf_ref.Unsupported` instead of `ValueError`), and values outside the 16-bit unsigned DS offset range (`0..65535`). 4. **Do not mutate caller's `info["insns"]` in `WaveRef.__init__`**: - Copies unencoded instruction dicts when assigning placeholder `enc`/`pc` instead of mutating caller-owned dicts in place. Independent of `#1780` (`tools/cf_ref.py`); zero PR dependencies. ## Testing Environment: Windows 11 x64, Python 3.12.10, CPU-only (no GPU or game files; based on `0d80bc5`). - Negative control on unpatched `main` (`0d80bc5`): - `python -m unittest tests.test_wave_diff.Reference` -> `FAILED (failures=24, errors=1)` - After fix: - `python -I tests/test_wave_diff.py` -> 16/16 OK (including canaries and seeded wave32/wave64 fuzz runs) - `python -m compileall -q tools/wave_diff.py tests/test_wave_diff.py` -> exit 0 - `python -I scripts/check_no_game_data.py tools/wave_diff.py tests/test_wave_diff.py` -> exit 0 - `git diff --check` -> clean AI-assisted: yes (Antigravity). Synthetic inputs only; no game data.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:06:29 +00:00
Author
Owner

@⁠GeorgiyDemo on GitHub · 2026-11-25 12:49 UTC · original

Tested 30e5b8b93 on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against main 98c2f7777 (Python CPU reference; no GPU):

  • pytest 9.2.0 on tests/test_wave_diff.py: 16 passed, 25 subtests passed at this head.
  • The same file on main: 25 failed, 15 passed — the cross-lane/mask operand, EXEC=0 destination, DS-offset and immutability validation is not there.
  • Not run: hardware — wave_diff is the reference side.

AI-assisted; synthetic fixtures only, no game data.

**@⁠GeorgiyDemo** on GitHub · 2026-11-25 12:49 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1809#issuecomment-7162919287) Tested `30e5b8b93` on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against `main` `98c2f7777` (Python CPU reference; no GPU): - pytest 9.2.0 on `tests/test_wave_diff.py`: **16 passed, 25 subtests passed** at this head. - The same file on `main`: **25 failed**, 15 passed — the cross-lane/mask operand, EXEC=0 destination, DS-offset and immutability validation is not there. - Not run: hardware — `wave_diff` is the reference side. AI-assisted; synthetic fixtures only, no game data.
Author
Owner

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

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

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

  • PR: 16 passed. main: 12 passed. The new tests pass on Windows.

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

**@⁠DeadlyChirp** on GitHub · 2026-11-25 15:52 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1809#issuecomment-7167393595) Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main. `python -m pytest -q tests/test_wave_diff.py`: - PR: 16 passed. main: 12 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/1809/head:github-bot/gh-1809'
git switch 'github-bot/gh-1809'

Merge

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