spirv_mini_interp: binary64 Sqrt/InverseSqrt stay binary64, and OpFAdd/OpFSub/OpFDiv run on doubles (TEST-MINI-INTERP-F64) #856
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!856
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/856/head"
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?
@qhukz13 on GitHub · 2026-11-24 14:40 UTC · original
qhukz13:cont/mini-interp-f64→main· +144 −3 · 2 files · 1 commits · merged 2026-11-24 15:50 UTCClaimed in the coordination issue as: TEST-MINI-INTERP-F64
What and why
tests/semantic/spirv_mini_interp.pymishandled binary64:SqrtandInverseSqrtrounded a double result to binary32: the translatedv_sqrt_f64of 2.0 gave0x3ff6a09e60000000instead of0x3ff6a09e667f3bcd, andv_rsq_f64likewise.OpFAdd,OpFSubandOpFDivon binary64 raisedUnsupportedConstruct(onlyOpFMulran), sov_add_f64andv_rcp_f64could not run in this interpreter at all.tests/spirv_interp.py, the other interpreter, had the matchingOpFDivgap (#746).Changes:
Sqrtismath.sqrt(correctly rounded). A doubleInverseSqrtis the newrsqrt_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_f64matched all 20,008).OpFAdd/OpFSub/OpFDivfollow the binary32 path's rules: a division by zero is still refused as undefined, and a NaN made from non-NaN operands goes throughieee_nan.OpFMulis unchanged.Tested
tests/semantic/test_mini_interp_f64.py(7 tests): translatesv_sqrt_f64,v_rsq_f64,v_rcp_f64andv_add_f64and checks the pair against Python's binary64 operations and, for the inverse root, a 60-digit decimal reference (not againstrsqrt_f64itself);rcpof zero stays refused. Againstmain'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 aretest_sopc_validationandtest_unary_f16_validation, which needspirv-as/spirv-valand those are not installed here.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) andtest_rdna2spirv_pixelinput,test_u16_high_half(pytest): OK.test_translate.pyskips 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
@abnalstlll-byte on GitHub · 2026-11-24 14:43 UTC · original · approved these changes
Audited and verified. Implements exact binary64 arithmetic in spirv_mini_interp.py for OpFAdd, OpFSub, OpFDiv, Sqrt, and single-rounded InverseSqrt (using
sqrt_f64 with rational arithmetic to avoid double rounding). Includes comprehensive numerical validation against high-precision Decimal in ests/semantic/test_mini_interp_f64.py. Clean-room compliant. Approved.
@abnalstlll-byte on GitHub · 2026-11-24 14:44 UTC · original · approved these changes
Clean-Room Audit & Math Verification — PR #856 (
TEST-MINI-INTERP-F64)Superb floating-point implementation and numerical precision verification.
Technical Verification
rsqrt_f64(x)correctly avoids double-rounding artifacts by scaling rational fraction4^p / xwith exact integer square root (math.isqrt) and ties-to-even rounding down to 53 bits.OpFAdd,OpFSub,OpFDiv, and GLSLSqrt/InverseSqrtfor binary64 operands inspirv_mini_interp.py.tests/semantic/test_mini_interp_f64.pyvalidates precision against 60-digitDecimalreference calculations, testing edge cases including subnormals, infinities, and signed zeros.Verdict: APPROVED