rdna2spirv: a lane mask read as a number is the wave's mask word (SHADER-MASK-AS-DATA) #1043

Open
github-bot wants to merge 3 commits from github-bot/gh-1043 into main AGit
Owner

@⁠thesubtleties on GitHub · 2026-11-24 17:08 UTC · original
thesubtleties:mask-as-data → main · +307 −18 · 10 files · 3 commits · open

Claimed in the coordination issue as: SHADER-MASK-AS-DATA

What and why

A lane mask is one word for the wave on hardware; the translator keeps each lane's own 0 / ~0. An op that read the mask as a number therefore got a different wrong value per lane, with no error: with mask 0x3ff, s_add_u32 d, mask, 1 was 0 or 1 and v_mov_b32 v, mask was 0 or ~0 (crosslane_fuzz.py "maskdata", the old #293). s_bcnt / s_ff / s_flbit already rebuild the word. This does the same for:

  • 32-bit integer SALU and VALU ops (lane_masks.NUMBER_READERS);
  • v_mov_b32 of a mask, when no v_readfirstlane_b32 or vector bitwise op reads that value as a mask. Each copy is followed forward, through VGPR-to-VGPR copies (second commit).

The emulation planner counts such an op as an exchange, it never joins an active run, and wave32_pixel_scan.py counts it as mask_word.

Partial on purpose. Not covered: the values excluded above (the v_mov / v_or3 / v_readfirstlane idiom needs each lane's own bit), compares, SDWA and DPP, and 16-bit, float and 64-bit ops.

Three existing tests changed: test_salu_movrels_lane_mask, test_scselect_b64_data and test_salu64_bitwise_data read a mask back with v_mov_b32 and expected the lane's own 0 / ~0; they now expect the mask word.

Tested

Measured on base 82a2aabc, then rebased; the semantic suite and the touched tests were rerun after the rebase.

  • New tests/semantic/test_mask_as_data.py (wave32, native wave64, partial EXEC, the through-a-VGPR idiom, emulated translation): fails on main, passes here.
  • run_semantic_tests.py: 0 files failed.
  • crosslane_fuzz.py, hard mismatches, main -> this PR; no program fails here that passed on main:
Run main first commit now
wave32 native, seed 880505 (300), 3080 and gfx1036 20 10 0
wave32 native, seed 991201 (250), 3080 13 7 4
wave32 native, seed 991202 (250), 3080 and gfx1036 21 16 4
wave64 emulated --ext, seed 880606 (300), 3080 and gfx1036 6 6 1
wave64 native --ext, seed 880707 (300), gfx1036 7 6 3

The 880xxx main rows were run on 98a977b4. With --no-maskdata there are no hard mismatches there on main. Correction: the first version of this text said the remaining mismatches were v_readfirstlane reads. Minimizing them showed most came from a plain VGPR-to-VGPR copy that the first commit counted as a mask read; the second commit fixes that. What is left on wave32 seeds 991201, 991202 and 993301 (11 mismatches, plus 4 programs with a hypothesis op) is now minimized on the 3080: every reduction contains a v_mov_b32 of a mask into a VGPR that a v_readfirstlane_b32 or a vector bitwise op then reads, the idiom this PR leaves alone. The shortest is v_cmp_ne_u32_e32 vcc_lo, 9, v6 / v_mov_b32_e32 v2, vcc_lo / v_readfirstlane_b32 s8, v2. The wave64 leftovers (seed 880606 emulated on the 3080, seed 880707 native on gfx1036) minimize to the same idiom. Caveat: two hard reductions stayed at 14 and 17 lines, where the pattern is present but not shown to be the cause, and the six programs with a hypothesis op (4 wave32, 2 wave64 native) are not explained.

  • cf_diff.py: 2,000 programs on the second commit (wave32 and wave64), 0 mismatches.
  • run_gpu_tests.py: per-test results identical to main: 3080 201/252, 3080 emulated 233/252, gfx1036 234/252, gfx1036 emulated 234/252; only the two known tfe fixtures fail (#31). Rerun on the second commit.
  • Not done: no RDNA2 measurement, no corpus run (I don't have the game), so translated / valid counts before and after, how many shaders change, and the cost of the extra subgroup ops are unknown. A corpus run by someone with a copy would be very useful before merging.

GPUs tested: NVIDIA RTX 3080 (620.73.04) and AMD RDNA2 iGPU gfx1036 (RADV, Mesa 26.3.1), CachyOS Linux 7.3.5

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.
**@⁠thesubtleties** on GitHub · 2026-11-24 17:08 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1043) `thesubtleties:mask-as-data` → `main` · +307 −18 · 10 files · 3 commits · open Claimed in the coordination issue as: SHADER-MASK-AS-DATA ### What and why A lane mask is one word for the wave on hardware; the translator keeps each lane's own 0 / ~0. An op that read the mask as a number therefore got a different wrong value per lane, with no error: with mask `0x3ff`, `s_add_u32 d, mask, 1` was 0 or 1 and `v_mov_b32 v, mask` was 0 or ~0 (`crosslane_fuzz.py` "maskdata", the old #293). `s_bcnt` / `s_ff` / `s_flbit` already rebuild the word. This does the same for: - 32-bit integer SALU and VALU ops (`lane_masks.NUMBER_READERS`); - `v_mov_b32` of a mask, when no `v_readfirstlane_b32` or vector bitwise op reads that value as a mask. Each copy is followed forward, through VGPR-to-VGPR copies (second commit). The emulation planner counts such an op as an exchange, it never joins an active run, and `wave32_pixel_scan.py` counts it as `mask_word`. **Partial on purpose.** Not covered: the values excluded above (the v_mov / v_or3 / v_readfirstlane idiom needs each lane's own bit), compares, SDWA and DPP, and 16-bit, float and 64-bit ops. Three existing tests changed: `test_salu_movrels_lane_mask`, `test_scselect_b64_data` and `test_salu64_bitwise_data` read a mask back with `v_mov_b32` and expected the lane's own 0 / ~0; they now expect the mask word. ### Tested Measured on base `82a2aabc`, then rebased; the semantic suite and the touched tests were rerun after the rebase. - New `tests/semantic/test_mask_as_data.py` (wave32, native wave64, partial EXEC, the through-a-VGPR idiom, emulated translation): fails on `main`, passes here. - `run_semantic_tests.py`: 0 files failed. - `crosslane_fuzz.py`, hard mismatches, main -> this PR; no program fails here that passed on main: | Run | main | first commit | now | |---|---|---|---| | wave32 native, seed 880505 (300), 3080 and gfx1036 | 20 | 10 | **0** | | wave32 native, seed 991201 (250), 3080 | 13 | 7 | **4** | | wave32 native, seed 991202 (250), 3080 and gfx1036 | 21 | 16 | **4** | | wave64 emulated `--ext`, seed 880606 (300), 3080 and gfx1036 | 6 | 6 | **1** | | wave64 native `--ext`, seed 880707 (300), gfx1036 | 7 | 6 | **3** | The 880xxx main rows were run on `98a977b4`. With `--no-maskdata` there are no hard mismatches there on main. **Correction:** the first version of this text said the remaining mismatches were `v_readfirstlane` reads. Minimizing them showed most came from a plain VGPR-to-VGPR copy that the first commit counted as a mask read; the second commit fixes that. What is left on wave32 seeds 991201, 991202 and 993301 (11 mismatches, plus 4 programs with a hypothesis op) is now minimized on the 3080: every reduction contains a `v_mov_b32` of a mask into a VGPR that a `v_readfirstlane_b32` or a vector bitwise op then reads, the idiom this PR leaves alone. The shortest is `v_cmp_ne_u32_e32 vcc_lo, 9, v6` / `v_mov_b32_e32 v2, vcc_lo` / `v_readfirstlane_b32 s8, v2`. The wave64 leftovers (seed 880606 emulated on the 3080, seed 880707 native on gfx1036) minimize to the same idiom. Caveat: two hard reductions stayed at 14 and 17 lines, where the pattern is present but not shown to be the cause, and the six programs with a hypothesis op (4 wave32, 2 wave64 native) are not explained. - `cf_diff.py`: 2,000 programs on the second commit (wave32 and wave64), 0 mismatches. - `run_gpu_tests.py`: per-test results identical to main: 3080 201/252, 3080 emulated 233/252, gfx1036 234/252, gfx1036 emulated 234/252; only the two known tfe fixtures fail (#31). Rerun on the second commit. - Not done: no RDNA2 measurement, no corpus run (I don't have the game), so translated / valid counts before and after, how many shaders change, and the cost of the extra subgroup ops are unknown. A corpus run by someone with a copy would be very useful before merging. GPUs tested: NVIDIA RTX 3080 (620.73.04) and AMD RDNA2 iGPU gfx1036 (RADV, Mesa 26.3.1), CachyOS Linux 7.3.5 AI-assisted: yes (Claude Code) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:34:57 +00:00
Author
Owner

@⁠morodirule on GitHub · 2026-11-24 17:10 UTC · original

Independent Linux check (stdlib only, no game/GPU): all four files pass on head 02d62939f — test_mask_as_data 9/9, test_salu64_bitwise_data 11/11, test_salu_movrels_lane_mask 3/3, test_scselect_b64_data 12/12. Same files against the unmodified tools fail 172+9+32+2 respectively, so the tests fully exercise the change. Not claiming; review evidence.

**@⁠morodirule** on GitHub · 2026-11-24 17:10 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1043#issuecomment-7138799568) Independent Linux check (stdlib only, no game/GPU): all four files pass on head 02d62939f — test_mask_as_data 9/9, test_salu64_bitwise_data 11/11, test_salu_movrels_lane_mask 3/3, test_scselect_b64_data 12/12. Same files against the unmodified tools fail 172+9+32+2 respectively, so the tests fully exercise the change. Not claiming; review evidence.
Author
Owner

@⁠KernelSmoker on GitHub · 2026-11-24 17:24 UTC · original · approved these changes

Verified on exact head 02d62939f6 (base 96e1e22261). Focused tests pass: new mask-as-data 9/9; updated SALU64, MOVRELS and SCSELECT regressions 11/11, 3/3 and 12/12; lane-mask, planner and pixel-scan unit suites also pass (including wave64 emulation 31/31). One additional SPIR-V validation test skipped because spirv-as/spirv-val are absent. The full semantic run covered 471 files / 6,174 tests; only test_sopc_validation and test_unary_f16_validation failed, both because those executables are missing, so I do not report the full suite as green. Changed-file no-game-data/diff checks and merge-tree pass. The added docs/design.md contract entry is present. CPU semantic validation only; no local GPU or game-data run.

**@⁠KernelSmoker** on GitHub · 2026-11-24 17:24 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1043#pullrequestreview-6044133340) · **approved these changes** Verified on exact head 02d62939f62b5ed8d6a8835ed3f3030b4f843ae8 (base 96e1e222614898097e363c74cda966a048920f78). Focused tests pass: new mask-as-data 9/9; updated SALU64, MOVRELS and SCSELECT regressions 11/11, 3/3 and 12/12; lane-mask, planner and pixel-scan unit suites also pass (including wave64 emulation 31/31). One additional SPIR-V validation test skipped because `spirv-as`/`spirv-val` are absent. The full semantic run covered 471 files / 6,174 tests; only `test_sopc_validation` and `test_unary_f16_validation` failed, both because those executables are missing, so I do not report the full suite as green. Changed-file no-game-data/diff checks and merge-tree pass. The added `docs/design.md` contract entry is present. CPU semantic validation only; no local GPU or game-data run.
Author
Owner

@⁠thesubtleties on GitHub · 2026-11-24 17:28 UTC · original

Thanks @⁠morodirule and @⁠KernelSmoker. I pushed a second commit, so your checks cover 02d62939f and not the new head. It changes only how lane_masks.number_moves decides which v_mov_b32 copies are read as numbers: a VGPR-to-VGPR copy no longer counts as a mask read. Wave32 fuzz mismatches go from 10 to 0 (seed 880505). My earlier explanation of those 10 was wrong, and the description is corrected. AI-assisted (Claude Code).

**@⁠thesubtleties** on GitHub · 2026-11-24 17:28 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1043#issuecomment-7139241839) Thanks @⁠morodirule and @⁠KernelSmoker. I pushed a second commit, so your checks cover `02d62939f` and not the new head. It changes only how `lane_masks.number_moves` decides which `v_mov_b32` copies are read as numbers: a VGPR-to-VGPR copy no longer counts as a mask read. Wave32 fuzz mismatches go from 10 to 0 (seed 880505). My earlier explanation of those 10 was wrong, and the description is corrected. AI-assisted (Claude Code).
Author
Owner

@⁠Sangonapou on GitHub · 2026-11-24 18:24 UTC · original

Tested 68b964e4 on NVIDIA GeForce RTX 3080 Ti Laptop (Ampere, subgroup 32..32), NVIDIA 621.24, Vulkan 1.4.357, Windows 11 Pro (build 26300): pass, and a GPU before/after with crosslane_fuzz

Runtime built with scripts\build_runtime.ps1 (MSVC 19.51; this PR changes no runtime file); llvm-mc 23.1.6, SPIRV-Tools 2026.4. No game files.

crosslane_fuzz.py --wave both --modes both --programs 300 --seed 20261123 (the same vk_compute_test), on this PR's base d4de3a7d and at this head. "Flagged" = programs reported as mismatch, including the hypothesis-op ones; every flagged program in both columns contains maskdata:

variant base: wave32 native / wave64 emulated mismatch (+hyp) flagged this PR flagged
plain 6 (+2) / 10 (+9) 27 1 (+0) / 6 (+1) 8
--dpp 6 (+3) / 10 (+6) 25 2 (+1) / 1 (+3) 7
--ext 6 (+2) / 3 (+6) 17 1 (+0) / 0 (+1) 2
total 69 17

The base counts are identical to a run of the same seed on main 867d922f the day before, so the drop is this change. 0 rejected and 0 harness errors in all runs. Still flagged at this head (seed 20261123, reproducible with --show):

  • plain: cs_xl32_2026173083373, cs_xl64_2026173083374, …396, …450, …524, …564, …632, …660
  • --dpp: cs_xl32_2026173083409, …425, …639, cs_xl64_2026173083512, …528, …580, …642
  • --ext: cs_xl32_2026173083373, cs_xl64_2026173083562

Also at this head: test_mask_as_data.py 13 OK, test_salu64_bitwise_data.py 11 OK, test_salu_movrels_lane_mask.py 3 OK, test_scselect_b64_data.py 12 OK (unittest discover). GPU suite: 261 shaders, 261 translated, 261 pass spirv-val; native 201/252, emulated 233/252; the only failures are cs_imgload_tfe / cs_imgload_d16_tfe, as on main on this card (#892).

**@⁠Sangonapou** on GitHub · 2026-11-24 18:24 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1043#issuecomment-7140611397) Tested 68b964e4 on NVIDIA GeForce RTX 3080 Ti Laptop (Ampere, subgroup 32..32), NVIDIA 621.24, Vulkan 1.4.357, Windows 11 Pro (build 26300): pass, and a GPU before/after with `crosslane_fuzz` Runtime built with `scripts\build_runtime.ps1` (MSVC 19.51; this PR changes no runtime file); `llvm-mc` 23.1.6, SPIRV-Tools 2026.4. No game files. **`crosslane_fuzz.py --wave both --modes both --programs 300 --seed 20261123`** (the same `vk_compute_test`), on this PR's base `d4de3a7d` and at this head. "Flagged" = programs reported as `mismatch`, including the hypothesis-op ones; every flagged program in both columns contains `maskdata`: | variant | base: wave32 native / wave64 emulated mismatch (+hyp) | flagged | this PR | flagged | |---|---|---|---|---| | plain | 6 (+2) / 10 (+9) | 27 | 1 (+0) / 6 (+1) | 8 | | `--dpp` | 6 (+3) / 10 (+6) | 25 | 2 (+1) / 1 (+3) | 7 | | `--ext` | 6 (+2) / 3 (+6) | 17 | 1 (+0) / 0 (+1) | 2 | | total | | **69** | | **17** | The base counts are identical to a run of the same seed on `main` `867d922f` the day before, so the drop is this change. 0 rejected and 0 harness errors in all runs. Still flagged at this head (seed 20261123, reproducible with `--show`): - plain: `cs_xl32_2026173083373`, `cs_xl64_2026173083374`, `…396`, `…450`, `…524`, `…564`, `…632`, `…660` - `--dpp`: `cs_xl32_2026173083409`, `…425`, `…639`, `cs_xl64_2026173083512`, `…528`, `…580`, `…642` - `--ext`: `cs_xl32_2026173083373`, `cs_xl64_2026173083562` **Also at this head:** `test_mask_as_data.py` 13 OK, `test_salu64_bitwise_data.py` 11 OK, `test_salu_movrels_lane_mask.py` 3 OK, `test_scselect_b64_data.py` 12 OK (`unittest discover`). GPU suite: 261 shaders, 261 translated, 261 pass spirv-val; native 201/252, emulated 233/252; the only failures are `cs_imgload_tfe` / `cs_imgload_d16_tfe`, as on `main` on this card (#892).
Author
Owner

@⁠thesubtleties on GitHub · 2026-11-24 18:54 UTC · original

More evidence on head 68b964e42; no code change.

tools/wave_diff.py --masks-as-data (CPU only, seed 551117, 2,000 programs per wave size), main 3aa97542 against this branch:

main this PR
wave32 104 mismatches 17
wave64 112 mismatches 11

The first remaining failure in each is a v_mov_b32 of a mask followed by a v_readfirstlane_b32 of that VGPR, the idiom this PR leaves alone. I did not check the other 26 one by one (that tool has no minimizer).

The wave64 crosslane_fuzz.py leftovers from the description are minimized now (seed 880606 emulated on the 3080, seed 880707 native on gfx1036): all 4 contain the same idiom, the shortest being v_cmp_ge_u32_e64 vcc, v6, v1 / v_mov_b32_e32 v5, vcc_hi / v_readfirstlane_b32 s8, v5. The description is updated to say so.

Not tested: the game corpus and RDNA2 console hardware. AI-assisted (Claude Code)

**@⁠thesubtleties** on GitHub · 2026-11-24 18:54 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1043#issuecomment-7141308380) More evidence on head `68b964e42`; no code change. `tools/wave_diff.py --masks-as-data` (CPU only, seed 551117, 2,000 programs per wave size), main `3aa97542` against this branch: | | main | this PR | |---|---|---| | wave32 | 104 mismatches | 17 | | wave64 | 112 mismatches | 11 | The first remaining failure in each is a `v_mov_b32` of a mask followed by a `v_readfirstlane_b32` of that VGPR, the idiom this PR leaves alone. I did not check the other 26 one by one (that tool has no minimizer). The wave64 `crosslane_fuzz.py` leftovers from the description are minimized now (seed 880606 emulated on the 3080, seed 880707 native on gfx1036): all 4 contain the same idiom, the shortest being `v_cmp_ge_u32_e64 vcc, v6, v1` / `v_mov_b32_e32 v5, vcc_hi` / `v_readfirstlane_b32 s8, v5`. The description is updated to say so. Not tested: the game corpus and RDNA2 console hardware. AI-assisted (Claude Code)
Author
Owner

@⁠MynFriend on GitHub · 2026-11-24 19:53 UTC · original · edited 2026-11-24 19:57 UTC

Tested 68b964e42 on an RTX 3080 with --wave64-emulate. A synthetic loop counting four set bits should return 4 in every lane. GPU readback returned 32 in four lanes and 2 in the other 60. A local change that converts the lane mask to a scalar word before entering the loop returned 4 in all 64 lanes. Both modules passed Vulkan 1.2 validation. AI-assisted test, no game files used.

Local translator change. On entry to the scalar bit-scan loop, s8 represents the low half of a per-lane mask. On the back edge, s_mov_b32 s8, s14 carries an ordinary scalar after clearing one bit. The analysis drops the mask classification at the join. The first s_ff1_i32_b32 then sees a different value across lanes. The local fix gathers the low 32 predicate bits into one uniform word at the entry zero-test, while the source is still known to be a mask (Gen.lane_mask_word). It stores that word in the SGPR and treats the register as scalar on both outgoing paths and at the loop header. The fix was tested on an experimental translator branch with single-wave, 64-thread compute groups.

Reproduce on the PR head with Python only

From the repo root at 68b964e42, run the following Python. Each of the 64 output words should be 4. The interpreter prints Counter({2: 60, 32: 4}), matching the RTX 3080 readback.

from collections import Counter
from pathlib import Path
import sys

sys.path.insert(0, str(Path("tests/semantic").resolve()))
import test_wave64_emulate_opt as t

insns = [
    ('v_cmp_lt_u32_e64 s[8:9], v0, 4', 8),
    ('s_and_b64 s[8:9], s[8:9], exec', 4),
    ('s_mov_b32 s20, 0', 4),
    ('s_cmp_lg_i32 s8, 0', 4),
    ('s_cbranch_scc0 8', 4),
    ('s_ff1_i32_b32 s12, s8', 4),
    ('s_lshl_b32 s12, 1, s12', 4),
    ('s_xor_b32 s14, s12, s8', 4),
    ('s_add_u32 s20, s20, 1', 4),
    ('s_cmp_eq_i32 s8, s12', 4),
    ('s_cbranch_scc1 2', 4),
    ('s_mov_b32 s8, s14', 4),
    ('s_branch 65528', 4),
    ('v_mov_b32_e32 v6, s20', 4),
    ('v_lshlrev_b32_e32 v1, 2, v0', 4),
    ('buffer_store_dword v6, v1, s[0:3], 0 offen', 8),
    ('s_endpgm', 4),
]
asm, _ = t._translate_encoded("cs_lowword_bitloop", insns, (64, 1, 1), emulate=True)
mem, _ = t.run_emulated_workgroup(asm, (64, 1, 1), push_constants=t.VSHARP + [0] * 28)
print(Counter(mem[4*i] for i in range(64)))

For the GPU check, the same asm was assembled with spirv-as --target-env vulkan1.2 and validated with spirv-val --target-env vulkan1.2. The module was run with vk_compute_test scan.spv 1 inspect and VKC_DUMP set to an output file. All 64 little-endian uint32 values in the dump were counted.

**@⁠MynFriend** on GitHub · 2026-11-24 19:53 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1043#issuecomment-7142747023) · edited 2026-11-24 19:57 UTC Tested `68b964e42` on an RTX 3080 with `--wave64-emulate`. A synthetic loop counting four set bits should return 4 in every lane. GPU readback returned 32 in four lanes and 2 in the other 60. A local change that converts the lane mask to a scalar word before entering the loop returned 4 in all 64 lanes. Both modules passed Vulkan 1.2 validation. AI-assisted test, no game files used. **Local translator change.** On entry to the scalar bit-scan loop, `s8` represents the low half of a per-lane mask. On the back edge, `s_mov_b32 s8, s14` carries an ordinary scalar after clearing one bit. The analysis drops the mask classification at the join. The first `s_ff1_i32_b32` then sees a different value across lanes. The local fix gathers the low 32 predicate bits into one uniform word at the entry zero-test, while the source is still known to be a mask (`Gen.lane_mask_word`). It stores that word in the SGPR and treats the register as scalar on both outgoing paths and at the loop header. The fix was tested on an experimental translator branch with single-wave, 64-thread compute groups. <details> <summary>Reproduce on the PR head with Python only</summary> From the repo root at `68b964e42`, run the following Python. Each of the 64 output words should be 4. The interpreter prints `Counter({2: 60, 32: 4})`, matching the RTX 3080 readback. ```python from collections import Counter from pathlib import Path import sys sys.path.insert(0, str(Path("tests/semantic").resolve())) import test_wave64_emulate_opt as t insns = [ ('v_cmp_lt_u32_e64 s[8:9], v0, 4', 8), ('s_and_b64 s[8:9], s[8:9], exec', 4), ('s_mov_b32 s20, 0', 4), ('s_cmp_lg_i32 s8, 0', 4), ('s_cbranch_scc0 8', 4), ('s_ff1_i32_b32 s12, s8', 4), ('s_lshl_b32 s12, 1, s12', 4), ('s_xor_b32 s14, s12, s8', 4), ('s_add_u32 s20, s20, 1', 4), ('s_cmp_eq_i32 s8, s12', 4), ('s_cbranch_scc1 2', 4), ('s_mov_b32 s8, s14', 4), ('s_branch 65528', 4), ('v_mov_b32_e32 v6, s20', 4), ('v_lshlrev_b32_e32 v1, 2, v0', 4), ('buffer_store_dword v6, v1, s[0:3], 0 offen', 8), ('s_endpgm', 4), ] asm, _ = t._translate_encoded("cs_lowword_bitloop", insns, (64, 1, 1), emulate=True) mem, _ = t.run_emulated_workgroup(asm, (64, 1, 1), push_constants=t.VSHARP + [0] * 28) print(Counter(mem[4*i] for i in range(64))) ``` For the GPU check, the same `asm` was assembled with `spirv-as --target-env vulkan1.2` and validated with `spirv-val --target-env vulkan1.2`. The module was run with `vk_compute_test scan.spv 1 inspect` and `VKC_DUMP` set to an output file. All 64 little-endian uint32 values in the dump were counted. </details>
Author
Owner

@⁠thesubtleties on GitHub · 2026-11-24 22:35 UTC · original

Thanks @⁠MynFriend, I reproduced this in the CPU interpreters at 68b964e42: wave64 native and emulated, and a wave32 version. Main 82a2aabc gives the same wrong values, so it isn't a regression, but this PR doesn't fix it. It's a mask meeting plain data at a join, where the analysis drops the mask.

While checking I found a straight-line relative: s_xor_b32 of a mask and plain data reads one lane's bit. I have a local prototype for that second case only (semantic suite clean, no GPU run yet). If you'd like to send your entry-test fix as its own PR, please do; I won't start on the loop case.

CPU only. AI-assisted (Claude Code)

**@⁠thesubtleties** on GitHub · 2026-11-24 22:35 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1043#issuecomment-7146411116) Thanks @⁠MynFriend, I reproduced this in the CPU interpreters at `68b964e42`: wave64 native and emulated, and a wave32 version. Main `82a2aabc` gives the same wrong values, so it isn't a regression, but this PR doesn't fix it. It's a mask meeting plain data at a join, where the analysis drops the mask. While checking I found a straight-line relative: `s_xor_b32` of a mask and plain data reads one lane's bit. I have a local prototype for that second case only (semantic suite clean, no GPU run yet). If you'd like to send your entry-test fix as its own PR, please do; I won't start on the loop case. CPU only. AI-assisted (Claude Code)
Author
Owner

@⁠thesubtleties on GitHub · 2026-11-24 23:50 UTC · original

Native RDNA2 (gfx1036, tools/hw_oracle): all 21 programs left over in the description (15 hard, 6 with a hypothesis op) match the fuzzer's model, so those are translator bugs, not model errors. Four short versions of the idiom also match. The cause is still shown only for the short reductions.

GPU suite on this head: the only failures are the two tfe fixtures fixed by #892. AI-assisted (Claude Code)

**@⁠thesubtleties** on GitHub · 2026-11-24 23:50 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1043#issuecomment-7147849512) Native RDNA2 (gfx1036, `tools/hw_oracle`): all 21 programs left over in the description (15 hard, 6 with a hypothesis op) match the fuzzer's model, so those are translator bugs, not model errors. Four short versions of the idiom also match. The cause is still shown only for the short reductions. GPU suite on this head: the only failures are the two `tfe` fixtures fixed by #892. AI-assisted (Claude Code)
Author
Owner

@⁠thesubtleties on GitHub · 2026-11-25 04:03 UTC · original

Rebased by merging main bfef489c; two conflicts, both independent additions. test_slot67_operand_forms loses an expectedFailure that this fixes.

Semantic suite: 488 files / 6,292 tests, 0 failed. GPU suite on the 3080 and gfx1036, native and emulated: per-test identical to main. Earlier approvals cover older heads. #1397 overlaps; I commented there. AI-assisted (Claude Code)

**@⁠thesubtleties** on GitHub · 2026-11-25 04:03 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1043#issuecomment-7152483243) Rebased by merging main `bfef489c`; two conflicts, both independent additions. `test_slot67_operand_forms` loses an `expectedFailure` that this fixes. Semantic suite: 488 files / 6,292 tests, 0 failed. GPU suite on the 3080 and gfx1036, native and emulated: per-test identical to main. Earlier approvals cover older heads. #1397 overlaps; I commented there. AI-assisted (Claude Code)
Author
Owner

@⁠ammonium231 on GitHub · 2026-11-26 01:56 UTC · original

RTX 3090 / 621.40, crosslane fuzz with maskdata, seed 309700: mismatches go 56+29 -> 12+9 (w32+w64) with this PR. Remaining are still mask-as-data, e.g. cs_xl32_30970929176 (native, group 50):

minimized repro
v_cmp_gt_u32_e64 s18, v7, v7
s_mov_b32 exec_lo, 0x110c5
v_mov_b32_e32 v6, s18
v_readfirstlane_b32 s14, v6

s14: expected 0x00000000; threads 0-31 got 0xfffeef3a, threads 32-49 got 0x0002ef3a.

**@⁠ammonium231** on GitHub · 2026-11-26 01:56 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1043#issuecomment-7180295082) RTX 3090 / 621.40, crosslane fuzz with maskdata, seed 309700: mismatches go 56+29 -> 12+9 (w32+w64) with this PR. Remaining are still mask-as-data, e.g. cs_xl32_30970929176 (native, group 50): <details> <summary>minimized repro</summary> ```asm v_cmp_gt_u32_e64 s18, v7, v7 s_mov_b32 exec_lo, 0x110c5 v_mov_b32_e32 v6, s18 v_readfirstlane_b32 s14, v6 ``` s14: expected 0x00000000; threads 0-31 got 0xfffeef3a, threads 32-49 got 0x0002ef3a. </details>
Author
Owner

@⁠ammonium231 on GitHub · 2026-11-26 08:15 UTC · original

Fix for the remaining mismatches: https://github.com/ubiquitarianism/leonida/compare/thesubtleties:mask-as-data...ammonium231:fix-1043-number-moves (on top of this PR, 4 files, +123/-10). number_moves dropped a plain v_mov of a mask when a later v_readfirstlane / v_and read the copy, so inactive lanes leaked into the mask. RTX 3090 fuzz, 2000 programs/seed, --dpp --ext: 309700 984/12/4 + 989/9/2 -> 1000/1000 both waves; held-out 309900 (36 failing) and 310100 (29 failing) -> 0, no new failures. Semantic suite 6296/0.

**@⁠ammonium231** on GitHub · 2026-11-26 08:15 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1043#issuecomment-7186377437) Fix for the remaining mismatches: https://github.com/ubiquitarianism/leonida/compare/thesubtleties:mask-as-data...ammonium231:fix-1043-number-moves (on top of this PR, 4 files, +123/-10). number_moves dropped a plain v_mov of a mask when a later v_readfirstlane / v_and read the copy, so inactive lanes leaked into the mask. RTX 3090 fuzz, 2000 programs/seed, --dpp --ext: 309700 984/12/4 + 989/9/2 -> 1000/1000 both waves; held-out 309900 (36 failing) and 310100 (29 failing) -> 0, no new failures. Semantic suite 6296/0.
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/1043/head:github-bot/gh-1043'
git switch 'github-bot/gh-1043'

Merge

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