[PR #2266] spirv_interp: handle GLSL IEEE edge domains, FMA sign/overflow, and OpFNegate NaNs #2270

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

📋 Pull Request Information

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

Base: main ← Head: fix/spirv-interp-ieee-safety


📝 Commits (1)

  • d1b1407 spirv_interp: handle GLSL IEEE edge domains, FMA sign/overflow, and OpFNegate NaNs

📊 Changes

2 files changed (+224 additions, -5 deletions)

View changed files

📝 tests/spirv_interp.py (+70 -5)
📝 tests/test_spirv_interp_signs.py (+154 -0)

📄 Description

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.py previously raised Python exceptions or lost IEEE-754 sign/payload bits on valid edge-case inputs:

  • Sqrt, InverseSqrt, Log2, Sin, Cos, Fract, and Exp2 called raw math.* / 2.0 ** x functions directly, raising ValueError or OverflowError on negative/zero/infinite/huge operands instead of returning IEEE-754 NaN, signed infinity, 0.0, or -0.0.
  • Fma converted Fraction sums unconditionally via float(...), losing -0.0 sign when -0.0 * c + (-0.0) summed to zero and raising OverflowError on overflowing binary64 results.
  • OpFNegate ran unary -v, stripping _F32 bit-pattern payloads (including signalling NaN bits) and failing on tuple vector operands.

This adds IEEE-754 domain/overflow/-0.0-safe evaluation in glsl(), preserves _F32 bit patterns and vector/f64 NaN signs in OpFNegate, and adds regression tests in tests/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)
  • Detached upstream/main baseline negative control: failed with the new tests before the fix
  • python -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, and git diff --cached --check

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/2266 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/spirv-interp-ieee-safety` --- ### 📝 Commits (1) - [`d1b1407`](https://github.com/ubiquitarianism/leonida/commit/d1b14075a48fcd598bb9b7d2e173a38ccd4db60e) spirv_interp: handle GLSL IEEE edge domains, FMA sign/overflow, and OpFNegate NaNs ### 📊 Changes **2 files changed** (+224 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `tests/spirv_interp.py` (+70 -5) 📝 `tests/test_spirv_interp_signs.py` (+154 -0) </details> ### 📄 Description 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.py` previously raised Python exceptions or lost IEEE-754 sign/payload bits on valid edge-case inputs: - `Sqrt`, `InverseSqrt`, `Log2`, `Sin`, `Cos`, `Fract`, and `Exp2` called raw `math.*` / `2.0 ** x` functions directly, raising `ValueError` or `OverflowError` on negative/zero/infinite/huge operands instead of returning IEEE-754 `NaN`, signed infinity, `0.0`, or `-0.0`. - `Fma` converted `Fraction` sums unconditionally via `float(...)`, losing `-0.0` sign when `-0.0 * c + (-0.0)` summed to zero and raising `OverflowError` on overflowing binary64 results. - `OpFNegate` ran unary `-v`, stripping `_F32` bit-pattern payloads (including signalling NaN bits) and failing on tuple vector operands. This adds IEEE-754 domain/overflow/`-0.0`-safe evaluation in `glsl()`, preserves `_F32` bit patterns and vector/f64 NaN signs in `OpFNegate`, and adds regression tests in `tests/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) - Detached `upstream/main` baseline negative control: failed with the new tests before the fix - `python -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`, and `git diff --cached --check` 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#2270
No description provided.