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

Open
github-bot wants to merge 1 commit from github-bot/gh-2347 into main AGit
Owner

@⁠kirigayakazima on GitHub · 2026-11-26 14:24 UTC · original
kirigayakazima:fix/f16-unary-cases-mask-safety → main · +103 −0 · 2 files · 1 commits · open

Claimed in the coordination issue as: F16-UNARY-CASES-16BIT-MASKING-AND-REF-TESTS (#1608)

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.
**@⁠kirigayakazima** on GitHub · 2026-11-26 14:24 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2347) `kirigayakazima:fix/f16-unary-cases-mask-safety` → `main` · +103 −0 · 2 files · 1 commits · open Claimed in the coordination issue as: F16-UNARY-CASES-16BIT-MASKING-AND-REF-TESTS (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:29:21 +00:00
Author
Owner

@⁠wavehs on GitHub · 2026-11-26 18:35 UTC · original · reviewed

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.

**@⁠wavehs** on GitHub · 2026-11-26 18:35 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2347#pullrequestreview-6079044283) · **reviewed** **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.
Author
Owner

@⁠lixonik on GitHub · 2026-11-26 20:43 UTC · original · reviewed

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.

**@⁠lixonik** on GitHub · 2026-11-26 20:43 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2347#pullrequestreview-6080301662) · **reviewed** 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.
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-27 04:43 UTC · original · approved these changes

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).

**@⁠tiguan26** on GitHub · 2026-11-27 04:43 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2347#pullrequestreview-6083579993) · **approved these changes** 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).
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/2347/head:github-bot/gh-2347'
git switch 'github-bot/gh-2347'

Merge

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