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

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

📋 Pull Request Information

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

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


📝 Commits (1)

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

📊 Changes

2 files changed (+106 additions, -11 deletions)

View changed files

📝 tests/test_wave_diff.py (+53 -0)
📝 tools/wave_diff.py (+53 -11)

📄 Description

Summary

Claimed in #1608 as WAVE-DIFF-REF-VALIDATION: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7162135689

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.


🔄 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/1809 **Author:** [@ShotTechOp](https://github.com/ShotTechOp) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/wave-diff-ref-validation` --- ### 📝 Commits (1) - [`30e5b8b`](https://github.com/ubiquitarianism/leonida/commit/30e5b8b932365a86ceba7915142fe584e25bbdb0) wave_diff: validate cross-lane/mask operands, EXEC=0 dsts, DS offsets, and immutability (WAVE-DIFF-REF-VALIDATION) ### 📊 Changes **2 files changed** (+106 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_wave_diff.py` (+53 -0) 📝 `tools/wave_diff.py` (+53 -11) </details> ### 📄 Description ## Summary Claimed in #1608 as `WAVE-DIFF-REF-VALIDATION`: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7162135689 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. --- <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#1822
No description provided.