f16_ref: preserve signed zero in to_f16/scale and mask 16-bit inputs #2303
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2303"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-26T13:15:24Z.
Claimed in the coordination issue as: F16-REF-NEGATIVE-ZERO-SIGN-AND-MASK-SAFETY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7193007298)
What and why
0x8000) into_f16()when passedfloat(-0.0)soscale(0x0000, -1.0)andscale(0x8000, 1.0)no longer collapse-0.0throughFraction(-0.0)into+0.0(0x0000).& 0xFFFF) consistently acrossis_nan(),same_f16(),ref_add(),ref_sub(),ref_mul(),ref_fma(),neg(),scale(), andclamp01()intests/semantic/f16_ref.py(so upper word bits cannot leak throughneg(),scale(),clamp01(), or break-0.0/same_f16()equality checks).tests/test_f16_ref.py.Tested
python -I tests/test_f16_ref.py -v: 3 passed, 0 failed (detachedupstream/mainbaseline with only the new test file fails with 3 failures).f16_ref-using semantic suites (test_alu_min3_max3_med3_16,test_alu_round,test_interp_guards,test_interp_p1lv_f16,test_valu_add_f16,test_valu_fma_f16,test_valu_mul_f16,test_valu_pk_add_f16,test_valu_pk_fma_f16,test_valu_pk_minmax_f16,test_valu_pk_mul_f16,test_valu_sub_f16,test_valu_subrev_f16): 162 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_ref.py tests/test_f16_ref.py, andgit diff --cached --check: passed.GPUs tested: n/a
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T17:57:39Z.
Review: COMMENTED
Windows 11: all three f16 reference tests passed, including signed zero and masking. No findings from these checks.
AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-27T04:41:29Z.
Review: APPROVED
Approving
95b1cb7dc.f16_refmasks every 16-bit input andto_f16keeps the sign of zero (-0.0 gives 0x8000). As for #2347, the semantic tests that importf16_reforf16_unary_casesall pass on this batch: 208 passed (5,662 subtests), so no expected value the translator tests rely on moved.Merged onto
maind1dff7949in one batch with 15 other tool PRs of this series (no conflicts), on Linux with Python 3.13.tests/test_f16_ref.py: 3 passed (new). AI-assisted (Claude Code, Claude Opus 5.5).Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T10:23:49Z.
#2303 | head
95b1cb7dc7(merged cleanly with main901b6c1bf) |python -I tests/test_f16_ref.py && python -I scripts/run_semantic_tests.py -p "test_*f16*.py" tests/semantic| red on main:FAILED (failures=3)(to_f16(-0.0)andscale(0x0000, -1.0)returning+00x0000instead of0x8000, andis_nan(0x17E00)returningFalse) | green on PR+main:3 tests OKand55 files, 575 tests, 0 files failed| Windows 11, Python 3.12.10 | AI-assisted: yesAudited
to_f16(math.copysign-0.0preservation beforeFraction(v)drops zero sign),scale, and 16-bit input masking acrossis_nan,same_f16,ref_add,ref_sub,ref_mul,ref_fma,neg, andclamp01intests/semantic/f16_ref.py. Verified both standalone and merged together with #2347 (tests/semantic/f16_unary_cases.py):0merge 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), andscripts/check_no_game_data.pychecks pass.Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T15:10:51Z.
Red/green: classified READY by oreo-lot3 (red on main
b1619e0a3, green on head merged with main); head95b1cb7dc7unchanged since 2026-11-26, before that run.Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main
d48a957bbin GitHub Actions: no new failure.AI-assisted (Claude Code, Claude Opus 5.5)