spirv_interp: handle GLSL IEEE edge domains, FMA sign/overflow, and OpFNegate NaNs #2266
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!2266
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/spirv-interp-ieee-safety"
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?
Pull request successfully merged and closed
Claimed in the coordination issue as: SPIRV-INTERP-IEEE-DOMAIN-OVERFLOW-FMA-AND-BITCAST-SIGN (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7191180874)
What and why
tests/spirv_interp.pypreviously raised Python exceptions or lost IEEE-754 sign/payload bits on valid edge-case inputs:Sqrt,InverseSqrt,Log2,Sin,Cos,Fract, andExp2called rawmath.*/2.0 ** xfunctions directly, raisingValueErrororOverflowErroron negative/zero/infinite/huge operands instead of returning IEEE-754NaN, signed infinity,0.0, or-0.0.FmaconvertedFractionsums unconditionally viafloat(...), losing-0.0sign when-0.0 * c + (-0.0)summed to zero and raisingOverflowErroron overflowing binary64 results.OpFNegateran unary-v, stripping_F32bit-pattern payloads (including signalling NaN bits) and failing on tuple vector operands.This adds IEEE-754 domain/overflow/
-0.0-safe evaluation inglsl(), preserves_F32bit patterns and vector/f64 NaN signs inOpFNegate, and adds regression tests intests/test_spirv_interp_signs.py.Tested
python -I tests/test_spirv_interp_signs.py -v(11 passed)python -I tests/test_spirv_interp_bits.py -v(5 passed)python -I tests/test_spirv_interp_f64_glsl.py -v(6 passed)upstream/mainbaseline negative control: failed with the new tests before the fixpython -I tests/test_ci_registration.py,python -I tests/test_text_write_line_endings.py,python -I scripts/check_no_game_data.py,python -I -m compileall -q, andgit diff --cached --checkGPUs 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.Verified on main a73a57e1 (Ubuntu 24.04 x86-64, Python 3.13, no GPU). Merges cleanly. With this PR, python -I tests/test_spirv_interp_signs.py: 11 tests OK. The PR's test file against main's interpreter: 1 failure and 2 errors, so the new tests fail on main and pass with the change. compileall clean.
AI-assisted: yes (Claude Code)
Approving d1b14075a.
spirv_interpis what many translator tests compute expected values with, so beyond its own tests I ran every test that imports it on this batch: 781 passed (main: 770, the difference being this PR's tests), so the IEEE edge cases (sqrt/rsqrt/log2 of negatives and zeros, exp2 overflow, trig of infinities, an exact-zero FMA's sign) and the NaN-preserving negate move no existing result.Merged onto
maind1dff7949in one batch with 22 other tool PRs of this series (no conflicts), on Linux with Python 3.13.tests/test_spirv_interp_signs.py: 11 passed (main: 8). AI-assisted (Claude Code, Claude Opus 5.5).#2266 | head d1b14075a48fcd598bb9b7d2e173a38ccd4db60e (merged cleanly with main 6c7f79343) |
python -I tests/test_spirv_interp_signs.py| red on main:FAILED (failures=1, errors=2)(ValueError: math domain erroronSqrt(-1),TypeErroron vectorOpFNegate, andFma(-0.0, 1.0, -0.0)returning+0.0instead of-0.00x80000000) | green on PR+main:11 tests OK| Windows 11, Python 3.12.10 | AI-assisted: yesAudited
_fneg(preserving_F32sNaN/qNaN payload bits and tuple vectors),_ieee_sqrt/_ieee_rsqrt/_ieee_log2/_ieee_exp2/_ieee_trig,Fract(+-inf) -> NaN, andFmaexact-zero sign (-0.0whena*bandcare both negative zero) +f64OverflowError -> +-infhandling intests/spirv_interp.py. Also passedtests/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.py.Red/green:
pytest tests/test_spirv_interp_signs.pyfails on main (3 failed, 8 passed, 3 subtests passed) and passes on head d1b14075a48f merged with main (11 passed, 3 subtests passed).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)