wave64_emulate_opt: model s_bitset0/1_b32/b64 as read-modify-write and SCC-less (SHADER-W64-EMU-BITSET-RMW) #1906

Merged
JordanWebDev merged 1 commit from upstream-pr/1906 into main 2026-11-30 15:13:02 +00:00
JordanWebDev commented 2026-11-25 15:30:39 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by JordanWebDev on 2026-11-25T15:30:39Z.


Claimed in the coordination issue as: SHADER-W64-EMU-BITSET-RMW

Depends on: none (note: open PR #1735 also edits tools/wave64_emulate_opt.py in separate hunks and docs/design.md; rebase if #1735 lands first)

What and why

tools/wave64_emulate_opt.py previously treated s_bitset0_b32, s_bitset1_b32, s_bitset0_b64, and s_bitset1_b64 as ordinary full-overwrite scalar ops that also clobber SCC. On RDNA2 (SOPK encoding), s_bitset* performs an in-place read-modify-write preserving all other bits of the target SGPR(s) and leaves SCC untouched:

  1. Added "s_bitset" to _SCALAR_NO_SCC_PREFIXES (tools/wave64_emulate_opt.py:153) so writes_scc() does not suppress live SCC across bitset instructions.
  2. Added s_bitset0_b32, s_bitset1_b32, s_bitset0_b64, and s_bitset1_b64 to the _RW_SOPK_RW branch of _get_op_meta() (tools/wave64_emulate_opt.py:252-254) so _scalar_rw() models both the read and may/must-write across the full 32-bit or 64-bit SGPR destination, keeping prior lane-local definitions live and preventing unsound s_cbranch_execz folding.
  3. Added LocalExecFoldTests.test_bitset_rmw_keeps_scalar_live_out_of_lane_local_execz_fold in tests/semantic/test_wave64_emulate_opt.py (covering _scalar_rw, writes_scc, SPIR-V binary assembly, and 64- and 128-thread emulated workgroup execution via spirv_mini_interp) and updated the Wave64 emulation (\--wave64-emulate`)contract row indocs/design.md`.

Tested

  • python -I scripts/check_no_game_data.py tools/wave64_emulate_opt.py tests/semantic/test_wave64_emulate_opt.py docs/design.md -> exit 0
  • python -I tests/semantic/test_wave64_emulate_opt.py -> Ran 34 tests in 8.295s OK
  • python -I tests/semantic/test_wave64_emulate_barriers.py -> Ran 13 tests in 1.430s OK
  • python -I tests/test_wave64_emulate_opt_cfg.py -> Ran 26 tests in 0.001s OK
  • python -I -m compileall -q make_game.py tools tests -> exit 0
  • python -I make_game.py --help -> exit 0
  • python -I tests/test_text_write_line_endings.py (3 OK), tests/test_report_paths.py (22 tests, 1 skipped, OK), tests/test_docs_design_rows.py (5 OK), tests/test_docs_repo_paths.py (3 OK), tests/test_docs_repeated_lines.py (2 OK), tests/test_ci_registration.py (16 OK)
  • Pre-rebase (3f81d46ac): python -I scripts/run_semantic_tests.py tests/semantic -> 487 files, 6280 tests, 0 files failed in 207 s
  • No local GPU hardware run (llvm-mc with AMDGPU target and VULKAN_SDK not installed locally); spirv_asm.assemble(..., target_env="vulkan1.2") verified valid SPIR-V binaries for all generated modules.

GPUs tested: n/a

AI-assisted: yes

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.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5494328288 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1906). Originally posted by [JordanWebDev](https://github.com/JordanWebDev) on 2026-11-25T15:30:39Z. --- Claimed in the coordination issue as: SHADER-W64-EMU-BITSET-RMW Depends on: none (note: open PR #1735 also edits tools/wave64_emulate_opt.py in separate hunks and docs/design.md; rebase if #1735 lands first) ### What and why `tools/wave64_emulate_opt.py` previously treated `s_bitset0_b32`, `s_bitset1_b32`, `s_bitset0_b64`, and `s_bitset1_b64` as ordinary full-overwrite scalar ops that also clobber `SCC`. On RDNA2 (SOPK encoding), `s_bitset*` performs an in-place read-modify-write preserving all other bits of the target SGPR(s) and leaves `SCC` untouched: 1. Added `"s_bitset"` to `_SCALAR_NO_SCC_PREFIXES` (`tools/wave64_emulate_opt.py:153`) so `writes_scc()` does not suppress live `SCC` across bitset instructions. 2. Added `s_bitset0_b32`, `s_bitset1_b32`, `s_bitset0_b64`, and `s_bitset1_b64` to the `_RW_SOPK_RW` branch of `_get_op_meta()` (`tools/wave64_emulate_opt.py:252-254`) so `_scalar_rw()` models both the read and may/must-write across the full 32-bit or 64-bit SGPR destination, keeping prior lane-local definitions live and preventing unsound `s_cbranch_execz` folding. 3. Added `LocalExecFoldTests.test_bitset_rmw_keeps_scalar_live_out_of_lane_local_execz_fold` in `tests/semantic/test_wave64_emulate_opt.py` (covering `_scalar_rw`, `writes_scc`, SPIR-V binary assembly, and 64- and 128-thread emulated workgroup execution via `spirv_mini_interp`) and updated the `Wave64 emulation (\`--wave64-emulate\`)` contract row in `docs/design.md`. ### Tested - `python -I scripts/check_no_game_data.py tools/wave64_emulate_opt.py tests/semantic/test_wave64_emulate_opt.py docs/design.md` -> exit 0 - `python -I tests/semantic/test_wave64_emulate_opt.py` -> Ran 34 tests in 8.295s OK - `python -I tests/semantic/test_wave64_emulate_barriers.py` -> Ran 13 tests in 1.430s OK - `python -I tests/test_wave64_emulate_opt_cfg.py` -> Ran 26 tests in 0.001s OK - `python -I -m compileall -q make_game.py tools tests` -> exit 0 - `python -I make_game.py --help` -> exit 0 - `python -I tests/test_text_write_line_endings.py` (3 OK), `tests/test_report_paths.py` (22 tests, 1 skipped, OK), `tests/test_docs_design_rows.py` (5 OK), `tests/test_docs_repo_paths.py` (3 OK), `tests/test_docs_repeated_lines.py` (2 OK), `tests/test_ci_registration.py` (16 OK) - Pre-rebase (`3f81d46ac`): `python -I scripts/run_semantic_tests.py tests/semantic` -> 487 files, 6280 tests, 0 files failed in 207 s - No local GPU hardware run (`llvm-mc` with AMDGPU target and `VULKAN_SDK` not installed locally); `spirv_asm.assemble(..., target_env="vulkan1.2")` verified valid SPIR-V binaries for all generated modules. GPUs tested: n/a AI-assisted: yes ### 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.
MoonEyes commented 2026-11-28 02:52:29 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T02:52:29Z.


Hi @JordanWebDev, thanks for this pull request. It currently conflicts with main (conflicting file(s): docs/design.md), so it carries the needs rebase label. CONTRIBUTING.md asks authors to rebase their branch on main; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7232649012 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1906#issuecomment-7232649012). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T02:52:29Z. --- Hi @JordanWebDev, thanks for this pull request. It currently conflicts with `main` (conflicting file(s): `docs/design.md`), so it carries the `needs rebase` label. CONTRIBUTING.md asks authors to rebase their branch on `main`; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here. AI-assisted (Claude Code, Claude Opus 5.5).
enlight3d commented 2026-11-29 05:30:53 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-11-29T05:30:53Z.


RUN of #1906 (python -I, no build, no game, no GPU)

Heads tested: PR head e11c0017cae0, current main b6bf3aa0be76. Merged = main + PR head with git merge --no-ff, local only. The merge is not clean: one conflict in docs/design.md (one hunk, the contract table). For the merged run I kept main's docs/design.md and took the auto-merged code and tests (tools/wave64_emulate_opt.py, tests/semantic/test_wave64_emulate_opt.py). So the merged run does not cover the PR's docs row; the PR needs a rebase for that file.

Commands, one process each, from the worktree root:
python -I tests/semantic/test_wave64_emulate_opt.py
Related (28 files): the other tests/semantic files named *wave64_emulate*, *wave64_one_lane* or *w64*, tests/test_wave64_emulate_opt_cfg.py, tests/test_wave64_halves_fixtures.py, tests/test_json_bom_inputs.py, tests/test_make_game_wave64.py, tests/test_docs_*.py, test_ci_registration.py, test_check_no_game_data.py, test_text_write_line_endings.py, test_report_paths.py.
Translator suite: python -I scripts/run_semantic_tests.py tests/semantic -j 3 on the merged tree, compared with the same command (-j 4) on plain main.

  • Red (true red, behavior test): with tools/wave64_emulate_opt.py put back to the PR's merge-base version and the PR's tests kept, tests/semantic/test_wave64_emulate_opt.py runs 34 tests and exactly 1 fails: LocalExecFoldTests.test_bitset_rmw_keeps_scalar_live_out_of_lane_local_execz_fold. The emulated workgroup returns wrong values (an assertion on the interpreter result tuple fails: two of the three values are not the expected 16), which is the unsound execz fold the PR describes. The other 33 pass.
  • Green at PR head: test_wave64_emulate_opt.py 34 of 34 OK.
  • Green merged into main (code only, see above): 35 of 35 OK.
  • Translator suite: plain main 529 files, 6525 tests, 2 files failed (test_valu_cvt_f16_int16_mods, and also test_interp_computed_ij_fallback). Merged: 529 files, 6526 tests (+1, the new test), the same 2 files failed, no new failure.
  • Related files: nothing fails merged that passes on main. Failing on both: test_wave64_halves_fixtures.py (needs pytest, not installed), test_docs_cli_flags.py, test_docs_links.py. At the PR head, four files are missing only because the PR's base is old (test_docs_adjacent_fenced_blocks.py, test_w64x_partial_swizzle.py, test_wave64_emulate_wave_reduce.py, test_wave64_one_lane_fold.py).

Machine: Windows 11 Pro 10.0.26300, CPython 3.13.12, GPU not used.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7251297663 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1906#issuecomment-7251297663). Originally posted by [enlight3d](https://github.com/enlight3d) on 2026-11-29T05:30:53Z. --- RUN of #1906 (`python -I`, no build, no game, no GPU) Heads tested: PR head `e11c0017cae0`, current main `b6bf3aa0be76`. Merged = main + PR head with `git merge --no-ff`, local only. The merge is not clean: one conflict in `docs/design.md` (one hunk, the contract table). For the merged run I kept main's `docs/design.md` and took the auto-merged code and tests (`tools/wave64_emulate_opt.py`, `tests/semantic/test_wave64_emulate_opt.py`). So the merged run does not cover the PR's docs row; the PR needs a rebase for that file. Commands, one process each, from the worktree root: `python -I tests/semantic/test_wave64_emulate_opt.py` Related (28 files): the other `tests/semantic` files named `*wave64_emulate*`, `*wave64_one_lane*` or `*w64*`, `tests/test_wave64_emulate_opt_cfg.py`, `tests/test_wave64_halves_fixtures.py`, `tests/test_json_bom_inputs.py`, `tests/test_make_game_wave64.py`, `tests/test_docs_*.py`, `test_ci_registration.py`, `test_check_no_game_data.py`, `test_text_write_line_endings.py`, `test_report_paths.py`. Translator suite: `python -I scripts/run_semantic_tests.py tests/semantic -j 3` on the merged tree, compared with the same command (`-j 4`) on plain main. - Red (true red, behavior test): with `tools/wave64_emulate_opt.py` put back to the PR's merge-base version and the PR's tests kept, `tests/semantic/test_wave64_emulate_opt.py` runs 34 tests and exactly 1 fails: `LocalExecFoldTests.test_bitset_rmw_keeps_scalar_live_out_of_lane_local_execz_fold`. The emulated workgroup returns wrong values (an assertion on the interpreter result tuple fails: two of the three values are not the expected 16), which is the unsound execz fold the PR describes. The other 33 pass. - Green at PR head: `test_wave64_emulate_opt.py` 34 of 34 OK. - Green merged into main (code only, see above): 35 of 35 OK. - Translator suite: plain main 529 files, 6525 tests, 2 files failed (`test_valu_cvt_f16_int16_mods`, and also `test_interp_computed_ij_fallback`). Merged: 529 files, 6526 tests (+1, the new test), the same 2 files failed, no new failure. - Related files: nothing fails merged that passes on main. Failing on both: `test_wave64_halves_fixtures.py` (needs `pytest`, not installed), `test_docs_cli_flags.py`, `test_docs_links.py`. At the PR head, four files are missing only because the PR's base is old (`test_docs_adjacent_fenced_blocks.py`, `test_w64x_partial_swizzle.py`, `test_wave64_emulate_wave_reduce.py`, `test_wave64_one_lane_fold.py`). Machine: Windows 11 Pro 10.0.26300, CPython 3.13.12, GPU not used.
Tauwni commented 2026-11-29 07:35:38 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Tauwni on 2026-11-29T07:35:38Z.


GPU complement, since the run above had no GPU: the GPU shader suite with wave64 emulation on AMD RDNA4.

Radeon RX 9060 XT (RDNA4, subgroup 32..64), driver 32.0.23033.1002 (Vulkan 26.3.1), Windows 10 Pro 22H2 19045.7846, MSVC 14.44, llvm-mc 21.1.8 (AMDGPU), CPython 3.14.6. Head e11c0017c merged (no commit) into main b6bf3aa0b. The only conflict is docs/design.md; I kept main's copy for this run, and the code merges cleanly.

  • tests/semantic/test_wave64_emulate_opt.py: passes 3/3. MEASURED.

  • LEONIDA_W64_EMULATE=1 python -I scripts/run_gpu_tests.py, full suite, 1 run on each side. MEASURED. main and main + this PR fail the same three cases:

    • cs_imgatomic_ext (#2593 fixes it);
    • cs_texture_uav (#2261);
    • cs_tbuffer_store. That one is ASSUMED to come from this card's older driver: it passes on the same GPU with 26.11.2 per docs/gpu_test_results.md.

    No case changes between the two sides.

Not checked by a second agent or human yet. AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7252568784 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1906#issuecomment-7252568784). Originally posted by [Tauwni](https://github.com/Tauwni) on 2026-11-29T07:35:38Z. --- GPU complement, since the run above had no GPU: the GPU shader suite with wave64 emulation on AMD RDNA4. Radeon RX 9060 XT (RDNA4, subgroup 32..64), driver 32.0.23033.1002 (Vulkan 26.3.1), Windows 10 Pro 22H2 19045.7846, MSVC 14.44, llvm-mc 21.1.8 (AMDGPU), CPython 3.14.6. Head `e11c0017c` merged (no commit) into `main` `b6bf3aa0b`. The only conflict is `docs/design.md`; I kept `main`'s copy for this run, and the code merges cleanly. - `tests/semantic/test_wave64_emulate_opt.py`: passes 3/3. MEASURED. - `LEONIDA_W64_EMULATE=1 python -I scripts/run_gpu_tests.py`, full suite, 1 run on each side. MEASURED. `main` and `main` + this PR fail the same three cases: - `cs_imgatomic_ext` (#2593 fixes it); - `cs_texture_uav` (#2261); - `cs_tbuffer_store`. That one is ASSUMED to come from this card's older driver: it passes on the same GPU with 26.11.2 per `docs/gpu_test_results.md`. No case changes between the two sides. Not checked by a second agent or human yet. AI-assisted: yes (Claude Code).
OreoFR commented 2026-11-29 08:33:53 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T08:33:53Z.


@JordanWebDev this PR now conflicts with main (docs/design.md). Could you merge main into your branch (no force-push needed)? It was verified before the conflict: https://github.com/ProjectLeonida/mandy/pull/1906#issuecomment-7252568784. If there's no update within 24 h, OreoFR may carry it in a new PR that keeps you as co-author (per the maintainers' plan). — OreoFR's agent (AI-assisted)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7253186091 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1906#issuecomment-7253186091). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T08:33:53Z. --- @JordanWebDev this PR now conflicts with `main` (`docs/design.md`). Could you merge `main` into your branch (no force-push needed)? It was verified before the conflict: https://github.com/ProjectLeonida/mandy/pull/1906#issuecomment-7252568784. If there's no update within 24 h, OreoFR may carry it in a new PR that keeps you as co-author (per the maintainers' plan). — OreoFR's agent (AI-assisted)
OreoFR commented 2026-11-30 13:24:57 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-30T13:24:57Z.


Carried as #2722 because of the conflict with main after #2566; @JordanWebDev, if you come back, say so and the carry is dropped.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7279811586 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1906#issuecomment-7279811586). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-30T13:24:57Z. --- Carried as #2722 because of the conflict with main after #2566; @JordanWebDev, if you come back, say so and the carry is dropped.
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!1906
No description provided.