[PR #746] [MERGED] tests: the f64 rcp/rsq/sqrt/cvt oracle files check the translator, and spirv_interp divides doubles as doubles (TEST-F64-ORACLES-TRANSLATE) #784

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

📋 Pull Request Information

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

Base: main ← Head: cont/f64-oracles-translate


📝 Commits (1)

  • ee4dfb0 tests: the f64 rcp/rsq/sqrt/cvt oracle files check the translator, and spirv_interp divides doubles as doubles (TEST-F64-ORACLES-TRANSLATE)

📊 Changes

7 files changed (+189 additions, -5 deletions)

View changed files

➕ tests/semantic/f64_translate.py (+43 -0)
📝 tests/semantic/test_valu_cvt_f32_f64.py (+33 -0)
📝 tests/semantic/test_valu_rcp_f64.py (+34 -0)
📝 tests/semantic/test_valu_rsq_f64.py (+34 -0)
📝 tests/semantic/test_valu_sqrt_f64.py (+35 -0)
📝 tests/spirv_interp.py (+10 -1)
📝 tests/test_semantic_translator_use.py (+0 -4)

📄 Description

Claimed in the coordination issue as: TEST-F64-ORACLES-TRANSLATE

What and why

tests/semantic/test_valu_{rcp,rsq,sqrt}_f64.py and test_valu_cvt_f32_f64.py were private oracles, exempted in tests/test_semantic_translator_use.py ("should translate a listing"): nothing in them ran the translator. tools/semantic_mutants.py --op v_rcp_f64 (and rsq, sqrt, cvt_f32_f64) showed it: swapping the high and low word of the f64 source in the shared f64() helper (rdna2spirv.py line 8487) failed none of the four files.

  • Each file gets a TranslatorMatchesOracle class: the instruction is translated (tests/semantic/f64_translate.py), run in tests/spirv_interp.py, and its word checked against the file's own oracle. Inputs are the ones whose SPIR-V result is defined (docs/design.md rows for these ops): no NaN; no zero divisor for rcp, nothing below zero for the roots, no binary32 subnormal or overflow for cvt. Both signs, subnormals, infinities, neg/abs and clamp are covered.
  • The four exemptions are removed from tests/test_semantic_translator_use.py.

Doing this found a bug in tests/spirv_interp.py: its F64 table had no OpFDiv, so a binary64 division fell through to the binary32 table. The translated v_rcp_f64 of 3.0 gave 0x3fd5555560000000 instead of 0x3fd5555555555555, and of 1e300 gave 0. OpFDiv is added to F64 (x / 0 as the binary32 one does), and OpFConvert is added (binary64 to binary32 rounds to nearest even, binary32 to binary64 is exact).

The oracles are correctly rounded, which matches the translator's contract (GLSL Sqrt/InverseSqrt, OpFDiv). RDNA2's own v_sqrt_f64 is not correctly rounded (docs/design.md), and none of the four ops occurs in the game listings, so this checks the translation against its documented contract, not against hardware.

Tested

  • The four files: OK under python -m unittest discover -s tests/semantic -p ... and as python -I scripts. Against main's spirv_interp.py the new classes fail (rcp: 19 failures; cvt: 34 errors, no OpFConvert).
  • python -I tests/test_semantic_translator_use.py: OK without the four exemptions.
  • semantic_mutants --op v_rcp_f64 / v_rsq_f64 / v_sqrt_f64 / v_cvt_f32_f64 with the matching file: the line-8487 hi -> lo mutant is now caught by each (survived all four before). The four survivors left are v_add_f64 code in the same shared branch (lines 8508, 8516), which test_valu_add_f64.py covers.
  • Other spirv_interp users: the tests/semantic files pass, and the five pytest files (test_f16_hw_words, test_f16_op_sel_values, test_mode_round, test_u16_high_half, test_values) pass, 330 tests.
  • tests/test_text_write_line_endings.py, tests/test_ci_registration.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/746 **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/f64-oracles-translate` --- ### 📝 Commits (1) - [`ee4dfb0`](https://github.com/ubiquitarianism/leonida/commit/ee4dfb04c7de6a6a8858b0d8ef9b43f8c9c3b91e) tests: the f64 rcp/rsq/sqrt/cvt oracle files check the translator, and spirv_interp divides doubles as doubles (TEST-F64-ORACLES-TRANSLATE) ### 📊 Changes **7 files changed** (+189 additions, -5 deletions) <details> <summary>View changed files</summary> ➕ `tests/semantic/f64_translate.py` (+43 -0) 📝 `tests/semantic/test_valu_cvt_f32_f64.py` (+33 -0) 📝 `tests/semantic/test_valu_rcp_f64.py` (+34 -0) 📝 `tests/semantic/test_valu_rsq_f64.py` (+34 -0) 📝 `tests/semantic/test_valu_sqrt_f64.py` (+35 -0) 📝 `tests/spirv_interp.py` (+10 -1) 📝 `tests/test_semantic_translator_use.py` (+0 -4) </details> ### 📄 Description Claimed in the coordination issue as: TEST-F64-ORACLES-TRANSLATE ### What and why `tests/semantic/test_valu_{rcp,rsq,sqrt}_f64.py` and `test_valu_cvt_f32_f64.py` were private oracles, exempted in `tests/test_semantic_translator_use.py` ("should translate a listing"): nothing in them ran the translator. `tools/semantic_mutants.py --op v_rcp_f64` (and rsq, sqrt, cvt_f32_f64) showed it: swapping the high and low word of the f64 source in the shared `f64()` helper (`rdna2spirv.py` line 8487) failed none of the four files. - Each file gets a `TranslatorMatchesOracle` class: the instruction is translated (`tests/semantic/f64_translate.py`), run in `tests/spirv_interp.py`, and its word checked against the file's own oracle. Inputs are the ones whose SPIR-V result is defined (docs/design.md rows for these ops): no NaN; no zero divisor for rcp, nothing below zero for the roots, no binary32 subnormal or overflow for cvt. Both signs, subnormals, infinities, neg/abs and clamp are covered. - The four exemptions are removed from `tests/test_semantic_translator_use.py`. Doing this found a bug in `tests/spirv_interp.py`: its `F64` table had no `OpFDiv`, so a binary64 division fell through to the binary32 table. The translated `v_rcp_f64` of 3.0 gave `0x3fd5555560000000` instead of `0x3fd5555555555555`, and of 1e300 gave 0. `OpFDiv` is added to `F64` (x / 0 as the binary32 one does), and `OpFConvert` is added (binary64 to binary32 rounds to nearest even, binary32 to binary64 is exact). The oracles are correctly rounded, which matches the translator's contract (GLSL `Sqrt`/`InverseSqrt`, `OpFDiv`). RDNA2's own `v_sqrt_f64` is not correctly rounded (docs/design.md), and none of the four ops occurs in the game listings, so this checks the translation against its documented contract, not against hardware. ### Tested - The four files: OK under `python -m unittest discover -s tests/semantic -p ...` and as `python -I` scripts. Against `main`'s `spirv_interp.py` the new classes fail (rcp: 19 failures; cvt: 34 errors, no `OpFConvert`). - `python -I tests/test_semantic_translator_use.py`: OK without the four exemptions. - `semantic_mutants --op v_rcp_f64 / v_rsq_f64 / v_sqrt_f64 / v_cvt_f32_f64` with the matching file: the line-8487 hi -> lo mutant is now caught by each (survived all four before). The four survivors left are `v_add_f64` code in the same shared branch (lines 8508, 8516), which `test_valu_add_f64.py` covers. - Other `spirv_interp` users: the `tests/semantic` files pass, and the five pytest files (`test_f16_hw_words`, `test_f16_op_sel_values`, `test_mode_round`, `test_u16_high_half`, `test_values`) pass, 330 tests. - `tests/test_text_write_line_endings.py`, `tests/test_ci_registration.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:02 +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#784
No description provided.