[PR #2347] F16-UNARY-CASES-16BIT-MASKING-AND-REF-TESTS #2351

Open
opened 2026-11-26 21:20:56 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2347
Author: @kirigayakazima
Created: 11/26/2026
Status: 🔄 Open

Base: main ← Head: fix/f16-unary-cases-mask-safety


📝 Commits (1)

  • fe13137 F16-UNARY-CASES-16BIT-MASKING-AND-REF-TESTS

📊 Changes

2 files changed (+103 additions, -0 deletions)

View changed files

📝 tests/semantic/f16_unary_cases.py (+10 -0)
➕ tests/test_f16_unary_cases.py (+93 -0)

📄 Description

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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/2347 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/f16-unary-cases-mask-safety` --- ### 📝 Commits (1) - [`fe13137`](https://github.com/ubiquitarianism/leonida/commit/fe131376f5bd01e38e9138148ea399e9421e8200) F16-UNARY-CASES-16BIT-MASKING-AND-REF-TESTS ### 📊 Changes **2 files changed** (+103 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `tests/semantic/f16_unary_cases.py` (+10 -0) ➕ `tests/test_f16_unary_cases.py` (+93 -0) </details> ### 📄 Description 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#2351
No description provided.