[PR #856] [MERGED] spirv_mini_interp: binary64 Sqrt/InverseSqrt stay binary64, and OpFAdd/OpFSub/OpFDiv run on doubles (TEST-MINI-INTERP-F64) #894

Closed
opened 2026-11-26 20:19:24 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/856
Author: @qhukz13
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/24/2026
Merged by: @ubiquitarianism

Base: main ← Head: cont/mini-interp-f64


📝 Commits (1)

  • adc2569 spirv_mini_interp: binary64 Sqrt/InverseSqrt stay binary64, and OpFAdd/OpFSub/OpFDiv run on doubles (TEST-MINI-INTERP-F64)

📊 Changes

2 files changed (+144 additions, -3 deletions)

View changed files

📝 tests/semantic/spirv_mini_interp.py (+32 -3)
➕ tests/semantic/test_mini_interp_f64.py (+112 -0)

📄 Description

Claimed in the coordination issue as: TEST-MINI-INTERP-F64

What and why

tests/semantic/spirv_mini_interp.py mishandled binary64:

  • GLSL.std.450 Sqrt and InverseSqrt rounded a double result to binary32: the translated v_sqrt_f64 of 2.0 gave 0x3ff6a09e60000000 instead of 0x3ff6a09e667f3bcd, and v_rsq_f64 likewise.
  • OpFAdd, OpFSub and OpFDiv on binary64 raised UnsupportedConstruct (only OpFMul ran), so v_add_f64 and v_rcp_f64 could not run in this interpreter at all.

tests/spirv_interp.py, the other interpreter, had the matching OpFDiv gap (#746).

Changes:

  • A double Sqrt is math.sqrt (correctly rounded). A double InverseSqrt is the new rsqrt_f64, rounded once from the exact value through an integer square root: 1.0 / math.sqrt(x) rounds twice and misses by an ulp on about a quarter of random doubles (5,219 of 20,008, checked against a 90-digit decimal; rsqrt_f64 matched all 20,008).
  • Binary64 OpFAdd/OpFSub/OpFDiv follow the binary32 path's rules: a division by zero is still refused as undefined, and a NaN made from non-NaN operands goes through ieee_nan. OpFMul is unchanged.

Tested

  • New tests/semantic/test_mini_interp_f64.py (7 tests): translates v_sqrt_f64, v_rsq_f64, v_rcp_f64 and v_add_f64 and checks the pair against Python's binary64 operations and, for the inverse root, a 60-digit decimal reference (not against rsqrt_f64 itself); rcp of zero stays refused. Against main's interpreter it gives 2 failures and 14 errors.
  • python -I scripts/run_semantic_tests.py tests/semantic: 466 files, 6,115 tests; the only failures are test_sopc_validation and test_unary_f16_validation, which need spirv-as/spirv-val and those are not installed here.
  • The top-level users of spirv_mini_interp: test_fma_mix_probe, test_image_query_translate, test_rdna2_decode, test_spirv_interp_bits, test_spirv_interp_f64_glsl, test_shader_diff_exit, test_wave_diff (stdlib) and test_rdna2spirv_pixelinput, test_u16_high_half (pytest): OK. test_translate.py skips without llvm-mc.
  • tests/test_semantic_translator_use.py, tests/test_text_write_line_endings.py, scripts/check_no_game_data.py, compileall: OK.

Linux, CPU only; no GPU, no game files.

AI-assisted (Claude Code).

🤖 Generated with Claude Code


🔄 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/856 **Author:** [@qhukz13](https://github.com/qhukz13) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/24/2026 **Merged by:** [@ubiquitarianism](https://github.com/ubiquitarianism) **Base:** `main` ← **Head:** `cont/mini-interp-f64` --- ### 📝 Commits (1) - [`adc2569`](https://github.com/ubiquitarianism/leonida/commit/adc25699fdd6ae0bc33f7c535ebb6f8ad117eac8) spirv_mini_interp: binary64 Sqrt/InverseSqrt stay binary64, and OpFAdd/OpFSub/OpFDiv run on doubles (TEST-MINI-INTERP-F64) ### 📊 Changes **2 files changed** (+144 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `tests/semantic/spirv_mini_interp.py` (+32 -3) ➕ `tests/semantic/test_mini_interp_f64.py` (+112 -0) </details> ### 📄 Description Claimed in the coordination issue as: TEST-MINI-INTERP-F64 ### What and why `tests/semantic/spirv_mini_interp.py` mishandled binary64: - GLSL.std.450 `Sqrt` and `InverseSqrt` rounded a double result to binary32: the translated `v_sqrt_f64` of 2.0 gave `0x3ff6a09e60000000` instead of `0x3ff6a09e667f3bcd`, and `v_rsq_f64` likewise. - `OpFAdd`, `OpFSub` and `OpFDiv` on binary64 raised `UnsupportedConstruct` (only `OpFMul` ran), so `v_add_f64` and `v_rcp_f64` could not run in this interpreter at all. `tests/spirv_interp.py`, the other interpreter, had the matching `OpFDiv` gap (#746). Changes: - A double `Sqrt` is `math.sqrt` (correctly rounded). A double `InverseSqrt` is the new `rsqrt_f64`, rounded once from the exact value through an integer square root: `1.0 / math.sqrt(x)` rounds twice and misses by an ulp on about a quarter of random doubles (5,219 of 20,008, checked against a 90-digit decimal; `rsqrt_f64` matched all 20,008). - Binary64 `OpFAdd`/`OpFSub`/`OpFDiv` follow the binary32 path's rules: a division by zero is still refused as undefined, and a NaN made from non-NaN operands goes through `ieee_nan`. `OpFMul` is unchanged. ### Tested - New `tests/semantic/test_mini_interp_f64.py` (7 tests): translates `v_sqrt_f64`, `v_rsq_f64`, `v_rcp_f64` and `v_add_f64` and checks the pair against Python's binary64 operations and, for the inverse root, a 60-digit decimal reference (not against `rsqrt_f64` itself); `rcp` of zero stays refused. Against `main`'s interpreter it gives 2 failures and 14 errors. - `python -I scripts/run_semantic_tests.py tests/semantic`: 466 files, 6,115 tests; the only failures are `test_sopc_validation` and `test_unary_f16_validation`, which need `spirv-as`/`spirv-val` and those are not installed here. - The top-level users of `spirv_mini_interp`: `test_fma_mix_probe`, `test_image_query_translate`, `test_rdna2_decode`, `test_spirv_interp_bits`, `test_spirv_interp_f64_glsl`, `test_shader_diff_exit`, `test_wave_diff` (stdlib) and `test_rdna2spirv_pixelinput`, `test_u16_high_half` (pytest): OK. `test_translate.py` skips without llvm-mc. - `tests/test_semantic_translator_use.py`, `tests/test_text_write_line_endings.py`, `scripts/check_no_game_data.py`, `compileall`: OK. Linux, CPU only; no GPU, no game files. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:19:24 +01:00
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#894
No description provided.