F16-UNARY-CASES-16BIT-MASKING-AND-REF-TESTS #2347

Merged
kirigayakazima merged 1 commit from upstream-pr/2347 into main 2026-11-28 15:12:04 +00:00
kirigayakazima commented 2026-11-26 14:24:45 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-26T14:24:45Z.


Claimed in the coordination issue as: F16-UNARY-CASES-16BIT-MASKING-AND-REF-TESTS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7194729737)

What and why

  • Mask inputs with h &= 0xFFFF at the entry of ref_rcp, ref_sqrt, ref_rsq, and ref_fract in tests/semantic/f16_unary_cases.py so upper bits in 32-bit test words do not leak past NaN checks (0x17E01 | 0x7E00) or bypass the +inf/-0 exact comparisons (0x17C00 triggering OverflowError in Fraction(...)).
  • Validate exact_sqrt_ratio(num, den, k=64) domain parameters up front (num >= 0, den > 0, k >= 0, rejecting booleans and non-integers with ValueError).
  • Add direct unit tests in tests/test_f16_unary_cases.py.

Tested

  • python -I tests/test_f16_unary_cases.py -v: 3 passed, 0 failed (detached upstream/main baseline with only the new test file fails: 9 failures, 3 errors across subtests).
  • Existing semantic f16 suites (test_valu_fract_f16, test_valu_pack_b32_f16, test_valu_rcp_f16, test_valu_rsq_f16, test_valu_sqrt_f16): 46 passed, 0 failed.
  • python -I tests/test_ci_registration.py: 16 passed.
  • python -I tests/test_text_write_line_endings.py: 3 passed.
  • python -I scripts/check_no_game_data.py, python -I -m compileall -q tests/semantic/f16_unary_cases.py tests/test_f16_unary_cases.py, and git diff --cached --check: passed.

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:5511780253 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2347). Originally posted by [kirigayakazima](https://github.com/kirigayakazima) on 2026-11-26T14:24:45Z. --- Claimed in the coordination issue as: F16-UNARY-CASES-16BIT-MASKING-AND-REF-TESTS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7194729737) ### What and why - Mask inputs with `h &= 0xFFFF` at the entry of `ref_rcp`, `ref_sqrt`, `ref_rsq`, and `ref_fract` in `tests/semantic/f16_unary_cases.py` so upper bits in 32-bit test words do not leak past NaN checks (`0x17E01 | 0x7E00`) or bypass the `+inf`/`-0` exact comparisons (`0x17C00` triggering `OverflowError` in `Fraction(...)`). - Validate `exact_sqrt_ratio(num, den, k=64)` domain parameters up front (`num >= 0`, `den > 0`, `k >= 0`, rejecting booleans and non-integers with `ValueError`). - Add direct unit tests in `tests/test_f16_unary_cases.py`. ### Tested - `python -I tests/test_f16_unary_cases.py -v`: 3 passed, 0 failed (detached `upstream/main` baseline with only the new test file fails: 9 failures, 3 errors across subtests). - Existing semantic f16 suites (`test_valu_fract_f16`, `test_valu_pack_b32_f16`, `test_valu_rcp_f16`, `test_valu_rsq_f16`, `test_valu_sqrt_f16`): 46 passed, 0 failed. - `python -I tests/test_ci_registration.py`: 16 passed. - `python -I tests/test_text_write_line_endings.py`: 3 passed. - `python -I scripts/check_no_game_data.py`, `python -I -m compileall -q tests/semantic/f16_unary_cases.py tests/test_f16_unary_cases.py`, and `git diff --cached --check`: passed. 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. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed.
wavehs commented 2026-11-26 18:35:12 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by wavehs on 2026-11-26T18:35:12Z.

Review: COMMENTED


macOS arm64 check of #2347 (F16-UNARY-CASES-16BIT-MASKING-AND-REF-TESTS). A test-harness change only: no translator, runtime or GPU code.

Tested head fe131376f with its diff applied to a copy of main bdbc7e923 (the branch is 82 commits behind; git apply and git merge-tree are clean).

Environment: Apple M3 Pro, arm64, macOS 27.2.1, CPython 3.15.2.

Result

  • python -I tests/test_f16_unary_cases.py: 3 tests, OK.
  • The five suites that share the harness: test_valu_fract_f16.py, test_valu_pack_b32_f16.py, test_valu_rcp_f16.py, test_valu_rsq_f16.py, test_valu_sqrt_f16.py - all OK.
  • Negative control (new test kept, tests/semantic/f16_unary_cases.py put back to main's): the failures and errors the description predicts - ref_rcp / ref_sqrt / ref_rsq on words with upper bits set (0x17E01, 0x17C00), and the exact_sqrt_ratio arguments (0, 0), (1, 0), (True, 1), (1, True), (1, 1, False) no longer raising. So both halves of the change are pinned.
  • python -I scripts/run_semantic_tests.py tests/semantic: 500 files / 6,367 tests / 0 failed, the same as main (the new test file is in tests/, not tests/semantic/).
  • GPU fixtures not run: nothing under runtime/, tools/rdna2spirv.py or scripts/run_gpu_tests.py changes, and the semantic f16 suites use spirv_mini_interp, not a device. This is a harness fix, not a shader-rule change.

Review

  • All four reference functions in the file (ref_rcp, ref_sqrt, ref_rsq, ref_fract) mask at entry, and the file has no other ref_* helper, so the sweep is complete.
  • Masking the reference does not weaken the translator tests: run() still seeds each source with hi=0x5A5A above the 16-bit word, so a translator that reads the wrong half still fails the comparison; the reference now models the same low-half read the hardware does.
  • exact_sqrt_ratio's callers pass Fraction.numerator / .denominator (Python ints), so rejecting bools and non-ints cannot break the existing suites; I checked the two call sites at f16_unary_cases.py:75,89.
  • The new exact_sqrt_ratio checks are the only place a ValueError is raised for a bad domain; no caller catches it, which is right for a test helper.

No functional issue found. The one thing I would carry into a follow-up is a short comment on run()'s hi=0x5A5A pointing at the masking rule, because the two only make sense together and a future edit could remove the seed padding without noticing.

No game files. AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6079044283 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2347#pullrequestreview-6079044283). Originally posted by [wavehs](https://github.com/wavehs) on 2026-11-26T18:35:12Z. **Review:** COMMENTED --- **macOS arm64 check of #2347** (F16-UNARY-CASES-16BIT-MASKING-AND-REF-TESTS). A test-harness change only: no translator, runtime or GPU code. Tested head `fe131376f` with its diff applied to a copy of `main` `bdbc7e923` (the branch is 82 commits behind; `git apply` and `git merge-tree` are clean). Environment: Apple M3 Pro, arm64, macOS 27.2.1, CPython 3.15.2. **Result** - `python -I tests/test_f16_unary_cases.py`: 3 tests, OK. - The five suites that share the harness: `test_valu_fract_f16.py`, `test_valu_pack_b32_f16.py`, `test_valu_rcp_f16.py`, `test_valu_rsq_f16.py`, `test_valu_sqrt_f16.py` - all OK. - Negative control (new test kept, `tests/semantic/f16_unary_cases.py` put back to `main`'s): the failures and errors the description predicts - `ref_rcp` / `ref_sqrt` / `ref_rsq` on words with upper bits set (`0x17E01`, `0x17C00`), and the `exact_sqrt_ratio` arguments `(0, 0)`, `(1, 0)`, `(True, 1)`, `(1, True)`, `(1, 1, False)` no longer raising. So both halves of the change are pinned. - `python -I scripts/run_semantic_tests.py tests/semantic`: 500 files / 6,367 tests / 0 failed, the same as `main` (the new test file is in `tests/`, not `tests/semantic/`). - GPU fixtures not run: nothing under `runtime/`, `tools/rdna2spirv.py` or `scripts/run_gpu_tests.py` changes, and the semantic f16 suites use `spirv_mini_interp`, not a device. This is a harness fix, not a shader-rule change. **Review** - All four reference functions in the file (`ref_rcp`, `ref_sqrt`, `ref_rsq`, `ref_fract`) mask at entry, and the file has no other `ref_*` helper, so the sweep is complete. - Masking the reference does not weaken the translator tests: `run()` still seeds each source with `hi=0x5A5A` above the 16-bit word, so a translator that reads the wrong half still fails the comparison; the reference now models the same low-half read the hardware does. - `exact_sqrt_ratio`'s callers pass `Fraction.numerator` / `.denominator` (Python ints), so rejecting bools and non-ints cannot break the existing suites; I checked the two call sites at `f16_unary_cases.py:75,89`. - The new `exact_sqrt_ratio` checks are the only place a `ValueError` is raised for a bad domain; no caller catches it, which is right for a test helper. No functional issue found. The one thing I would carry into a follow-up is a short comment on `run()`'s `hi=0x5A5A` pointing at the masking rule, because the two only make sense together and a future edit could remove the seed padding without noticing. No game files. AI-assisted.
lixonik commented 2026-11-26 20:43:14 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T20:43:14Z.

Review: COMMENTED


On Windows 11 with CPython 3.12.1, all three direct reference tests and all 46 related semantic tests passed across fract, pack_b32, rcp, rsq and sqrt.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6080301662 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2347#pullrequestreview-6080301662). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-26T20:43:14Z. **Review:** COMMENTED --- On Windows 11 with CPython 3.12.1, all three direct reference tests and all 46 related semantic tests passed across `fract`, `pack_b32`, `rcp`, `rsq` and `sqrt`. AI-assisted.
tiguan26 commented 2026-11-27 04:43:06 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-27T04:43:06Z.

Review: APPROVED


Approving fe131376f.

The f16_unary_cases helpers now mask their inputs to 16 bits and refuse non-integer or negative arguments. Since f16_unary_cases and f16_ref are references the translator tests compare against, I also ran every semantic test that imports either one on this batch: 208 passed (5,662 subtests).

Merged onto main d1dff7949 in one batch with 15 other tool PRs of this series (no conflicts), on Linux with Python 3.13. tests/test_f16_unary_cases.py: 3 passed (new). AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6083579993 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2347#pullrequestreview-6083579993). Originally posted by [tiguan26](https://github.com/tiguan26) on 2026-11-27T04:43:06Z. **Review:** APPROVED --- Approving fe131376f. The `f16_unary_cases` helpers now mask their inputs to 16 bits and refuse non-integer or negative arguments. Since `f16_unary_cases` and `f16_ref` are references the translator tests compare against, I also ran every semantic test that imports either one on this batch: 208 passed (5,662 subtests). Merged onto `main` `d1dff7949` in one batch with 15 other tool PRs of this series (no conflicts), on Linux with Python 3.13. `tests/test_f16_unary_cases.py`: 3 passed (new). AI-assisted (Claude Code, Claude Opus 5.5).
zmasi commented 2026-11-28 10:23:48 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T10:23:48Z.


#2347 | head fe131376f5 (merged cleanly with main 901b6c1bf) | python -I tests/test_f16_unary_cases.py && python -I scripts/run_semantic_tests.py -p "test_*f16*.py" tests/semantic | red on main: FAILED (failures=9, errors=3) (unmasked upper bits above bit 15 in ref_rcp/ref_sqrt/ref_rsq/ref_fract and unguarded exact_sqrt_ratio domain/bool inputs) | green on PR+main: 3 tests OK and 55 files, 575 tests, 0 files failed | Windows 11, Python 3.12.10 | AI-assisted: yes

Audited exact_sqrt_ratio and ref_rcp / ref_sqrt / ref_rsq / ref_fract in tests/semantic/f16_unary_cases.py plus tests/test_f16_unary_cases.py. Verified both standalone and merged together with #2303 (tests/semantic/f16_ref.py): 0 merge conflicts and all unit, semantic (575/575), tests/test_ci_registration.py (18 OK), tests/test_text_write_line_endings.py (3 OK), tests/test_runner_calls_all_tests.py (3 OK), and scripts/check_no_game_data.py checks pass.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7237869213 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2347#issuecomment-7237869213). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T10:23:48Z. --- #2347 | head fe131376f5bd01e38e9138148ea399e9421e8200 (merged cleanly with main 901b6c1bf) | `python -I tests/test_f16_unary_cases.py && python -I scripts/run_semantic_tests.py -p "test_*f16*.py" tests/semantic` | red on main: `FAILED (failures=9, errors=3)` (unmasked upper bits above bit 15 in `ref_rcp`/`ref_sqrt`/`ref_rsq`/`ref_fract` and unguarded `exact_sqrt_ratio` domain/bool inputs) | green on PR+main: `3 tests OK` and `55 files, 575 tests, 0 files failed` | Windows 11, Python 3.12.10 | AI-assisted: yes Audited `exact_sqrt_ratio` and `ref_rcp` / `ref_sqrt` / `ref_rsq` / `ref_fract` in `tests/semantic/f16_unary_cases.py` plus `tests/test_f16_unary_cases.py`. Verified both standalone and merged together with #2303 (`tests/semantic/f16_ref.py`): `0` merge conflicts and all unit, semantic (`575/575`), `tests/test_ci_registration.py` (`18 OK`), `tests/test_text_write_line_endings.py` (`3 OK`), `tests/test_runner_calls_all_tests.py` (`3 OK`), and `scripts/check_no_game_data.py` checks pass.
MoonEyes commented 2026-11-28 15:12:01 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T15:12:01Z.


Red/green: classified READY by oreo-lot3 (red on main b1619e0a3, green on head merged with main); head fe131376f5 unchanged since 2026-11-26, before that run.
Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure.
AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7241280898 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2347#issuecomment-7241280898). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T15:12:01Z. --- Red/green: classified READY by oreo-lot3 (red on main b1619e0a3, green on head merged with main); head fe131376f5bd unchanged since 2026-11-26, before that run. Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure. AI-assisted (Claude Code, Claude Opus 5.5)
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!2347
No description provided.