pk16_diff: generate the packed high-half constant read by default #2560

Merged
jjjj2244 merged 4 commits from upstream-pr/2560 into main 2026-11-28 23:47:00 +00:00
jjjj2244 commented 2026-11-28 04:47:42 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by jjjj2244 on 2026-11-28T04:47:42Z.


Claimed in the coordination issue as: TOOL-PK16-CONST-HI (claim)

What and why

tools/pk16_diff.py still listed pk-const-hi in KNOWN_DIVERGENCES: "a constant in a packed add/sub/mul_lo/min/max/mad source whose high half op_sel or op_sel_hi reads: the translator raises Unsupported". That stopped being true on 2026-11-22. A constant source is its 32-bit dword and op_sel/op_sel_hi index that dword, high half included (measured on gfx1036, docs/design.md, "Packed 16-bit integer ops").

Because the entry existed, the generator refused to put a constant anywhere its high half would be read, so the form was never fuzzed by default. Three things already in the tree contradicted the entry:

  • tests/test_pk16_diff.py::test_a_wrong_translation_is_caught runs v_pk_add_u16 v1, v2, 1 op_sel_hi:[1,0] through d.check() and asserts the translator matches;
  • test_constants_are_their_32_bit_value asserts the reference's high-half read: v_pk_add_u16 v1, 0x12345678, 0 is 0x12345678;
  • docs/shader_validation.md records 2,300 --oracle hw programs on gfx1036 with the --known forms included matching the model.

So the entry was stale, and it cost coverage of a measured form. This removes it, lets a constant go in any packed source, and corrects the two documents that still said the translator rejects the form.

  • tools/pk16_diff.py: KNOWN_DIVERGENCES = {}; a constant is allowed in every packed source; PK_SHIFTS removed (its only use was that gate); docstring updated.
  • tests/test_pk16_diff.py: test_known_divergences_are_left_out_by_default replaced by test_the_high_half_constant_read_is_not_left_out and test_generated_high_half_constant_reads_match_the_translator.
  • docs/design.md: the packed 16-bit row said a constant's high half "is not measured ... raises Unsupported"; it is measured and handled.
  • docs/shader_validation.md: the same claim in the pk16_diff section.

KNOWN_DIVERGENCES and the --known flag are kept (empty) rather than removed, so --known and the tests that use it keep working; #1654 touches the same mechanism and would otherwise conflict.

Tested

Windows 11 (build 26300), Python 3.13, no GPU. The two new tests fail on main's tools/pk16_diff.py and pass with this branch:

# tests only, against main's tools/pk16_diff.py
python -I tests/test_pk16_diff.py            -> FAILED (failures=2)
# with the whole change
python -I tests/test_pk16_diff.py            -> Ran 17 tests, OK
python -I tools/pk16_diff.py --programs 2000 --seed 11 --max-ops 8
                                             -> 2000 pass, 0 mismatch, 0 skipped
python -I tools/pk16_diff.py --known --programs 800 --seed 5
                                             -> 800 pass, 0 mismatch, 0 skipped
python -I tools/pk16_diff.py --known --programs 1500 --seed 9   (on main, before the change)
                                             -> 1500 pass, 0 mismatch, 0 skipped

The last run is why the entry is removed rather than kept: with the known forms enabled, main already agreed with the reference on the form over 1,500 programs, with no skips. The whole standalone unit suite was run on the branch and compared with main (520 of 554 run standalone, the same 6 environment-dependent failures on both).

No hardware run: this changes a fuzzer's generator and two documents, not the translator, so there is nothing new to measure on a GPU. The hardware evidence behind the rule is the one already recorded: gfx1036 in docs/design.md, and the 2,300 --oracle hw programs in docs/shader_validation.md.

Branch is based on ef8fbf0; main has moved to b1619e0 since, and those commits touch only runtime/src/cpu_emulation.h and runtime/test/cpu_emulation_test.cpp, so GitHub reports this merges cleanly.

GPUs tested: n/a (no GPU test in this change)

AI-assisted: yes — written by a coding agent (OpenCode; DeepSeek V4.1 Flash) working under this account.

Checklist

  • Based on main and merges cleanly (GitHub: "Able to merge").
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption.
  • No new translator rule (the rule was already measured and is in docs/design.md; only the row's stale text is corrected).
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5536774668 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2560). Originally posted by [jjjj2244](https://github.com/jjjj2244) on 2026-11-28T04:47:42Z. --- Claimed in the coordination issue as: `TOOL-PK16-CONST-HI` ([claim](https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7234107376)) ### What and why `tools/pk16_diff.py` still listed `pk-const-hi` in `KNOWN_DIVERGENCES`: "a constant in a packed add/sub/mul_lo/min/max/mad source whose high half op_sel or op_sel_hi reads: the translator raises Unsupported". That stopped being true on 2026-11-22. A constant source is its 32-bit dword and `op_sel`/`op_sel_hi` index that dword, high half included (measured on gfx1036, `docs/design.md`, "Packed 16-bit integer ops"). Because the entry existed, the generator refused to put a constant anywhere its high half would be read, so the form was never fuzzed by default. Three things already in the tree contradicted the entry: - `tests/test_pk16_diff.py::test_a_wrong_translation_is_caught` runs `v_pk_add_u16 v1, v2, 1 op_sel_hi:[1,0]` through `d.check()` and asserts the translator matches; - `test_constants_are_their_32_bit_value` asserts the reference's high-half read: `v_pk_add_u16 v1, 0x12345678, 0` is `0x12345678`; - `docs/shader_validation.md` records 2,300 `--oracle hw` programs on gfx1036 with the `--known` forms included matching the model. So the entry was stale, and it cost coverage of a measured form. This removes it, lets a constant go in any packed source, and corrects the two documents that still said the translator rejects the form. - `tools/pk16_diff.py`: `KNOWN_DIVERGENCES = {}`; a constant is allowed in every packed source; `PK_SHIFTS` removed (its only use was that gate); docstring updated. - `tests/test_pk16_diff.py`: `test_known_divergences_are_left_out_by_default` replaced by `test_the_high_half_constant_read_is_not_left_out` and `test_generated_high_half_constant_reads_match_the_translator`. - `docs/design.md`: the packed 16-bit row said a constant's high half "is **not measured** ... raises `Unsupported`"; it is measured and handled. - `docs/shader_validation.md`: the same claim in the `pk16_diff` section. `KNOWN_DIVERGENCES` and the `--known` flag are kept (empty) rather than removed, so `--known` and the tests that use it keep working; #1654 touches the same mechanism and would otherwise conflict. ### Tested Windows 11 (build 26300), Python 3.13, no GPU. The two new tests fail on `main`'s `tools/pk16_diff.py` and pass with this branch: ``` # tests only, against main's tools/pk16_diff.py python -I tests/test_pk16_diff.py -> FAILED (failures=2) # with the whole change python -I tests/test_pk16_diff.py -> Ran 17 tests, OK python -I tools/pk16_diff.py --programs 2000 --seed 11 --max-ops 8 -> 2000 pass, 0 mismatch, 0 skipped python -I tools/pk16_diff.py --known --programs 800 --seed 5 -> 800 pass, 0 mismatch, 0 skipped python -I tools/pk16_diff.py --known --programs 1500 --seed 9 (on main, before the change) -> 1500 pass, 0 mismatch, 0 skipped ``` The last run is why the entry is removed rather than kept: with the known forms enabled, main already agreed with the reference on the form over 1,500 programs, with no skips. The whole standalone unit suite was run on the branch and compared with `main` (520 of 554 run standalone, the same 6 environment-dependent failures on both). No hardware run: this changes a fuzzer's generator and two documents, not the translator, so there is nothing new to measure on a GPU. The hardware evidence behind the rule is the one already recorded: gfx1036 in `docs/design.md`, and the 2,300 `--oracle hw` programs in `docs/shader_validation.md`. Branch is based on `ef8fbf0`; `main` has moved to `b1619e0` since, and those commits touch only `runtime/src/cpu_emulation.h` and `runtime/test/cpu_emulation_test.cpp`, so GitHub reports this merges cleanly. GPUs tested: n/a (no GPU test in this change) AI-assisted: yes — written by a coding agent (OpenCode; DeepSeek V4.1 Flash) working under this account. ### Checklist - [x] Based on `main` and merges cleanly (GitHub: "Able to merge"). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption. - [x] No new translator rule (the rule was already measured and is in `docs/design.md`; only the row's stale text is corrected).
kirigayakazima commented 2026-11-28 05:35:01 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-28T05:35:01Z.


#2560 | head 0ab5ccd213d819f7c588fb4db2de944f42440283 | python -I tests/test_pk16_diff.py | red: FAILED (failures=2, AssertionError) | green: 17/17 OK (2.072s) | full suite: 513/521 stdlib passed, 0 new failures vs main 8994000b08 | Windows 11, Python 3.14.7, no game files | AI-assisted: yes, Antigravity (Gemini)

Details:

  • Red (PR test tests/test_pk16_diff.py on upstream/main 8994000b08): Ran 17 tests in 10.834s — FAILED (failures=2) (AssertionError: 0 not greater than or equal to 5 in test_generated_high_half_constant_reads_match_the_translator and AssertionError: {'pk-const-hi': ...} != {} in test_the_high_half_constant_read_is_not_left_out).
  • Green (merged with upstream/main 8994000b08): Ran 17 tests in 2.072s — OK.
  • Repo checks: scripts/check_no_game_data.py -> 0; python -m compileall -q tools scripts tests -> 0; node --test tests/test_viewer_streaming.cjs -> 0; standalone stdlib tests/test_*.py -> 513/521 passed (33 skipped pytest/helper files; 0 new failures vs 8994000b08, same 8 pre-existing Windows/docs/timeout failures: test_docs_cli_flags.py, test_docs_env_vars.py, test_docs_python_deps.py, test_docs_repo_paths.py, test_make_game_preflight.py, test_progress_dashboard.py, test_semantic_mutants.py, test_tool_stdout_encoding.py).
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7234758136 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2560#issuecomment-7234758136). Originally posted by [kirigayakazima](https://github.com/kirigayakazima) on 2026-11-28T05:35:01Z. --- `#2560 | head 0ab5ccd213d819f7c588fb4db2de944f42440283 | python -I tests/test_pk16_diff.py | red: FAILED (failures=2, AssertionError) | green: 17/17 OK (2.072s) | full suite: 513/521 stdlib passed, 0 new failures vs main 8994000b08 | Windows 11, Python 3.14.7, no game files | AI-assisted: yes, Antigravity (Gemini)` Details: - **Red** (PR test `tests/test_pk16_diff.py` on `upstream/main` `8994000b08`): `Ran 17 tests in 10.834s — FAILED (failures=2)` (`AssertionError: 0 not greater than or equal to 5` in `test_generated_high_half_constant_reads_match_the_translator` and `AssertionError: {'pk-const-hi': ...} != {}` in `test_the_high_half_constant_read_is_not_left_out`). - **Green** (merged with `upstream/main` `8994000b08`): `Ran 17 tests in 2.072s — OK`. - **Repo checks**: `scripts/check_no_game_data.py` -> `0`; `python -m compileall -q tools scripts tests` -> `0`; `node --test tests/test_viewer_streaming.cjs` -> `0`; standalone stdlib `tests/test_*.py` -> `513/521 passed` (`33` skipped pytest/helper files; `0` new failures vs `8994000b08`, same 8 pre-existing Windows/docs/timeout failures: `test_docs_cli_flags.py`, `test_docs_env_vars.py`, `test_docs_python_deps.py`, `test_docs_repo_paths.py`, `test_make_game_preflight.py`, `test_progress_dashboard.py`, `test_semantic_mutants.py`, `test_tool_stdout_encoding.py`).
lixonik commented 2026-11-28 09:20:43 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-28T09:20:43Z.

Review: APPROVED


Reviewed the diff and tested merged onto main (493867366).

Clearing the stale pk-const-hi entry from KNOWN_DIVERGENCES while keeping --known intact, updating the generator/tests, and aligning docs/design.md and docs/shader_validation.md is clean and matches the current translator behaviour.

Tests run

  • python -I tests/test_pk16_diff.py: 17/17 passed (12.73 s).
  • python -I tools/pk16_diff.py --programs 500 --seed 11 --max-ops 8: 500 pass, 0 mismatch, 0 skipped.

AI-assisted (Antigravity, Gemini).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6096941252 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2560#pullrequestreview-6096941252). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-28T09:20:43Z. **Review:** APPROVED --- Reviewed the diff and tested merged onto `main` (`493867366`). Clearing the stale `pk-const-hi` entry from `KNOWN_DIVERGENCES` while keeping `--known` intact, updating the generator/tests, and aligning `docs/design.md` and `docs/shader_validation.md` is clean and matches the current translator behaviour. ### Tests run - `python -I tests/test_pk16_diff.py`: **17/17 passed** (12.73 s). - `python -I tools/pk16_diff.py --programs 500 --seed 11 --max-ops 8`: **500 pass, 0 mismatch, 0 skipped**. AI-assisted (Antigravity, Gemini).
zmasi commented 2026-11-28 13:01:06 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T13:01:06Z.


#2560 | head 0ab5ccd213d819f7c588fb4db2de944f42440283 (merged cleanly onto main d48a957bb9988afce424552a3c0c8d01ef12320f) | Windows 11 (10.0.26200), CPython 3.12.10, llvm-mc (gfx1013), spirv-val (1.4.363.1), NVIDIA GeForce RTX 3090 (Vulkan 1.4.341, driver 610.88, subgroup 32..32, LEONIDA_VK_VALIDATION=1)

  • Red on main (d48a957bb9988afce424552a3c0c8d01ef12320f): tests/test_pk16_diff.py fails on main (KNOWN_DIVERGENCES retains 'pk-const-hi', leaving packed high-half constant reads out of default generation).
  • Green on PR + main:
    • python -I tests/test_pk16_diff.py -v: pass (OK).
    • python -I tools/pk16_diff.py --programs 200 --seed 7: 200/200 pass (0 mismatches, 0 skipped).
    • Live RTX 3090 Vulkan GPU check (vk_compute_test, LEONIDA_VK_VALIDATION=1, spirv-val clean): assembled and executed 10 generated pk16_diff programs containing non-shift packed high-half constant reads (op_sel / op_sel_hi indexing bits [31:16] of inline/literal constants) -> 10/10 GPU 4-word outputs match pk16_diff.reference bit-for-bit (0 Khronos validation errors).
    • scripts/check_no_game_data.py, test_docs_encoding.py, and test_text_write_line_endings.py: pass (0 CRLF).

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7239629425 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2560#issuecomment-7239629425). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T13:01:06Z. --- #2560 | head `0ab5ccd213d819f7c588fb4db2de944f42440283` (merged cleanly onto `main` `d48a957bb9988afce424552a3c0c8d01ef12320f`) | Windows 11 (`10.0.26200`), CPython `3.12.10`, `llvm-mc` (`gfx1013`), `spirv-val` (`1.4.363.1`), NVIDIA GeForce RTX 3090 (Vulkan `1.4.341`, driver `610.88`, `subgroup 32..32`, `LEONIDA_VK_VALIDATION=1`) - **Red on `main` (`d48a957bb9988afce424552a3c0c8d01ef12320f`)**: `tests/test_pk16_diff.py` fails on `main` (`KNOWN_DIVERGENCES` retains `'pk-const-hi'`, leaving packed high-half constant reads out of default generation). - **Green on `PR + main`**: - `python -I tests/test_pk16_diff.py -v`: pass (`OK`). - `python -I tools/pk16_diff.py --programs 200 --seed 7`: `200/200` pass (`0` mismatches, `0` skipped). - Live RTX 3090 Vulkan GPU check (`vk_compute_test`, `LEONIDA_VK_VALIDATION=1`, `spirv-val` clean): assembled and executed `10` generated `pk16_diff` programs containing non-shift packed high-half constant reads (`op_sel` / `op_sel_hi` indexing bits `[31:16]` of inline/literal constants) -> `10/10` GPU 4-word outputs match `pk16_diff.reference` bit-for-bit (`0` Khronos validation errors). - `scripts/check_no_game_data.py`, `test_docs_encoding.py`, and `test_text_write_line_endings.py`: pass (`0` CRLF). AI-assisted.
TheGeogeo commented 2026-11-28 23:37:54 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-28T23:37:54Z.


Tested 0ab5ccd21 merged (no commit) with main aa918e5d9: Python 3.12.4, Windows 11 10.0.26300, CPU only. check_no_game_data.py is clean.

  • Green: tests/test_pk16_diff.py, 21 tests pass. On main, its 20 tests pass.
  • Red: with tools/pk16_diff.py back to main, 2 tests fail (the pk-const-hi case is missing).

No blocker from my side.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7247559458 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2560#issuecomment-7247559458). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-28T23:37:54Z. --- Tested `0ab5ccd21` merged (no commit) with `main` `aa918e5d9`: Python 3.12.4, Windows 11 10.0.26300, CPU only. `check_no_game_data.py` is clean. - Green: `tests/test_pk16_diff.py`, 21 tests pass. On `main`, its 20 tests pass. - Red: with `tools/pk16_diff.py` back to `main`, 2 tests fail (the `pk-const-hi` case is missing). No blocker from my side. AI-assisted (Claude Code).
MoonEyes commented 2026-11-28 23:47:02 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T23:47:02Z.


Merged after TheGeogeo's red/green check (check) (Windows, Python tests, no GPU needed) and a local re-check here. Merged after local re-verification: this PR merged onto main e1d87a4a4 without conflict, and its test file(s) (tests/test_pk16_diff.py) pass there. Earlier today the same tests failed on main without the PR (red/green) and a bundle with other open PRs showed no new failures. check_no_game_data.py is clean. Windows 11, Python 3.14; no GPU needed for these tests.

AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7247660579 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2560#issuecomment-7247660579). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T23:47:02Z. --- Merged after **TheGeogeo**'s red/green check ([check](https://github.com/ProjectLeonida/mandy/pull/2560#issuecomment-7247559458)) (Windows, Python tests, no GPU needed) and a local re-check here. Merged after local re-verification: this PR merged onto `main` e1d87a4a4 without conflict, and its test file(s) (`tests/test_pk16_diff.py`) pass there. Earlier today the same tests failed on `main` without the PR (red/green) and a bundle with other open PRs showed no new failures. `check_no_game_data.py` is clean. Windows 11, Python 3.14; no GPU needed for these tests. _AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes._
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!2560
No description provided.