[PR #1231] rdna2spirv: model the measured special results of v_rcp/v_rsq/v_sqrt/v_log_f32 (SHADER-F32-SPECIAL-RESULTS) #1263

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1231
Author: @Sangonapou
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: f32-special-results


📝 Commits (2)

  • 1c31b57 rdna2spirv: model the measured special results of v_rcp/v_rsq/v_sqrt/v_log_f32
  • bd96a74 tests: f32_fuzz and rcp_iflag checks follow the modelled special results

📊 Changes

9 files changed (+155 additions, -62 deletions)

View changed files

📝 docs/design.md (+2 -2)
📝 tests/semantic/test_alu_rcp.py (+20 -21)
📝 tests/semantic/test_alu_rcp_f32.py (+5 -4)
📝 tests/semantic/test_valu_f32_transcendentals.py (+34 -9)
📝 tests/semantic/test_valu_rcp_fdiv.py (+9 -9)
📝 tests/semantic/test_valu_trig_f32.py (+8 -10)
📝 tests/test_f32_fuzz.py (+11 -2)
📝 tests/test_rcp_iflag_mods.py (+18 -1)
📝 tools/rdna2spirv.py (+48 -4)

📄 Description

Claimed in the coordination issue as: SHADER-F32-SPECIAL-RESULTS (claim)

What and why

docs/design.md ("Denormal flush and special results") lists RDNA2's measured special results as not modelled: v_rcp_f32/v_rcp_iflag_f32(±0) = ±inf, v_rsq_f32(-0) = -inf, v_sqrt_f32(-0) = -0, v_log_f32(±0) = -inf, and v_sqrt/v_rsq/v_log of a negative value = 0xffc00000. The translator emitted OpFDiv %f1 x and GLSL.std.450 Sqrt/InverseSqrt/Log2, which SPIR-V leaves undefined for exactly those inputs, so the result was whatever the driver returned. These ops occur 1.17M times in 76% of the corpus (counts in that row).

Gen.f32_special_results (used by the F1 path and v_rcp_iflag_f32): a special operand reaches the op as 1.0 and the hardware word is selected afterwards, the same technique the f16 forms already use. Every other operand, NaNs included, reaches the op unchanged, so its result is as before. v_rsq_f32(+0) = +inf (IEEE). Denormal handling is unchanged (separate question). The design.md row and the "Still open" list are updated.

Tested

  • GPU readback (tools/vk_fuzz_run, one wave32 lane, opaque operands), 22 cases (16 special inputs across the five ops plus 6 regular ones): base 15/22, this branch 22/22 match the RDNA2 words. On the base, NVIDIA returns 0x7fffffff for every sqrt/rsq/log of a negative value where RDNA2 gives 0xffc00000; ±0 cases already matched there by luck of the driver.
  • tools/f32_fuzz.py --programs 500 --seed 20261124: base 463 match / 0 mismatch / 17 undefined in SPIR-V / 20 skipped → this branch 480 match / 0 mismatch / 0 undefined / 20 skipped.
  • python -I scripts/run_semantic_tests.py tests/semantic: 470 files, 6169 tests; the only failures were the five tests that asserted the old undefined behaviour (test_alu_rcp, test_valu_f32_transcendentals, test_alu_rcp_f32, test_valu_rcp_fdiv, test_valu_trig_f32), now updated to the hardware words (plus a regular-input check); all pass.
  • python -m compileall, scripts/check_no_game_data.py on every changed file: clean.

GPUs tested: NVIDIA GeForce RTX 3080 Ti Laptop (Ampere, subgroup 32), driver 621.24, Vulkan 1.4.357, Windows 11 Pro build 26300
AI-assisted: yes (Claude Code)

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.

🤖 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/1231 **Author:** [@Sangonapou](https://github.com/Sangonapou) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `f32-special-results` --- ### 📝 Commits (2) - [`1c31b57`](https://github.com/ubiquitarianism/leonida/commit/1c31b575b4fb2932f0626142aa4a2703a8455541) rdna2spirv: model the measured special results of v_rcp/v_rsq/v_sqrt/v_log_f32 - [`bd96a74`](https://github.com/ubiquitarianism/leonida/commit/bd96a7474f044c855da4f38ce834e86b32b9800e) tests: f32_fuzz and rcp_iflag checks follow the modelled special results ### 📊 Changes **9 files changed** (+155 additions, -62 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+2 -2) 📝 `tests/semantic/test_alu_rcp.py` (+20 -21) 📝 `tests/semantic/test_alu_rcp_f32.py` (+5 -4) 📝 `tests/semantic/test_valu_f32_transcendentals.py` (+34 -9) 📝 `tests/semantic/test_valu_rcp_fdiv.py` (+9 -9) 📝 `tests/semantic/test_valu_trig_f32.py` (+8 -10) 📝 `tests/test_f32_fuzz.py` (+11 -2) 📝 `tests/test_rcp_iflag_mods.py` (+18 -1) 📝 `tools/rdna2spirv.py` (+48 -4) </details> ### 📄 Description Claimed in the coordination issue as: SHADER-F32-SPECIAL-RESULTS ([claim](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7143040476)) ### What and why `docs/design.md` ("Denormal flush and special results") lists RDNA2's measured special results as **not modelled**: `v_rcp_f32`/`v_rcp_iflag_f32(±0)` = ±inf, `v_rsq_f32(-0)` = -inf, `v_sqrt_f32(-0)` = -0, `v_log_f32(±0)` = -inf, and `v_sqrt`/`v_rsq`/`v_log` of a negative value = `0xffc00000`. The translator emitted `OpFDiv %f1 x` and `GLSL.std.450 Sqrt`/`InverseSqrt`/`Log2`, which SPIR-V leaves undefined for exactly those inputs, so the result was whatever the driver returned. These ops occur 1.17M times in 76% of the corpus (counts in that row). `Gen.f32_special_results` (used by the `F1` path and `v_rcp_iflag_f32`): a special operand reaches the op as 1.0 and the hardware word is selected afterwards, the same technique the f16 forms already use. Every other operand, NaNs included, reaches the op unchanged, so its result is as before. `v_rsq_f32(+0)` = +inf (IEEE). Denormal handling is unchanged (separate question). The design.md row and the "Still open" list are updated. ### Tested - **GPU readback** (`tools/vk_fuzz_run`, one wave32 lane, opaque operands), 22 cases (16 special inputs across the five ops plus 6 regular ones): **base 15/22, this branch 22/22** match the RDNA2 words. On the base, NVIDIA returns `0x7fffffff` for every sqrt/rsq/log of a negative value where RDNA2 gives `0xffc00000`; ±0 cases already matched there by luck of the driver. - `tools/f32_fuzz.py --programs 500 --seed 20261124`: base 463 match / 0 mismatch / **17 undefined in SPIR-V** / 20 skipped → this branch 480 match / 0 mismatch / **0 undefined** / 20 skipped. - `python -I scripts/run_semantic_tests.py tests/semantic`: 470 files, 6169 tests; the only failures were the five tests that asserted the old undefined behaviour (`test_alu_rcp`, `test_valu_f32_transcendentals`, `test_alu_rcp_f32`, `test_valu_rcp_fdiv`, `test_valu_trig_f32`), now updated to the hardware words (plus a regular-input check); all pass. - `python -m compileall`, `scripts/check_no_game_data.py` on every changed file: clean. GPUs tested: NVIDIA GeForce RTX 3080 Ti Laptop (Ampere, subgroup 32), driver 621.24, Vulkan 1.4.357, Windows 11 Pro build 26300 AI-assisted: yes (Claude Code) ### 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. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. 🤖 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>
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#1263
No description provided.