[PR #1063] [MERGED] tests, rdna2spirv: GPU readback for frexp and ldexp, and their neg/abs sources move the sign bit (GPU-FREXP-LDEXP, SHADER-FREXP-LDEXP-SIGN-MODS) #1102

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1063
Author: @milk4sale
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/25/2026
Merged by: @aslan2142

Base: main ← Head: gpu-test/frexp-ldexp


📝 Commits (8)

  • 355c8c9 tests: GPU readback for the binary64 roundings, v_trunc_f64, v_ceil_f64, v_rndne_f64 and v_floor_f64 (GPU-ROUND-F64)
  • 5f063e5 tests, rdna2spirv: GPU readback for frexp and ldexp, and their neg/abs sources move the sign bit (GPU-FREXP-LDEXP, SHADER-FREXP-LDEXP-SIGN-MODS)
  • 60c2ed9 tests: cs_w32_round_f64 allows llvmpipe's float path for Trunc and RoundEven (GPU-ROUND-F64)
  • eba94cb Merge gpu-test/round-f64 into gpu-test/frexp-ldexp: cs_w32_round_f64's llvmpipe allowance
  • e040dce Merge main into gpu-test/round-f64
  • 2eb49b1 Merge main into gpu-test/frexp-ldexp
  • 69935f8 Merge main into gpu-test/round-f64
  • 5431c75 Merge gpu-test/round-f64 into gpu-test/frexp-ldexp: main 6558d5318, with #1012 merged

📊 Changes

11 files changed (+1071 additions, -8 deletions)

View changed files

📝 docs/design.md (+3 -3)
📝 docs/testing.md (+58 -0)
📝 runtime/test/shaders/check.py (+264 -2)
➕ runtime/test/shaders/cs_w32_frexp_ldexp.asm (+44 -0)
➕ runtime/test/shaders/cs_w32_round_f64.asm (+56 -0)
📝 scripts/run_gpu_tests.py (+10 -0)
📝 tests/semantic/test_alu_frexp_ldexp.py (+60 -0)
➕ tests/test_gpu_frexp_ldexp.py (+236 -0)
➕ tests/test_gpu_round_f64.py (+319 -0)
📝 tests/test_shader_checks.py (+18 -2)
📝 tools/rdna2spirv.py (+3 -1)

📄 Description

Claimed in the coordination issue as: GPU-FREXP-LDEXP (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7139072105), SHADER-FREXP-LDEXP-SIGN-MODS (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7139171475)

Depends on: #1034, which depends on #1012 (this branch is one commit on top of them. All three add a memory-fed fixture next to cs_w32_shift64 and touch the same lines of check.py, run_gpu_tests.py and tests/test_shader_checks.py; the last commit is the one to review. It does not touch what #1047 changes.)

What and why

v_frexp_mant_f32, v_frexp_exp_i32_f32, v_ldexp_f32, v_frexp_mant_f64 and v_frexp_exp_i32_f64 are lowered with integer ops on the float's words. They are CPU-checked and measured natively on gfx1036, but no fixture in runtime/test/shaders ran any of the five.

The fixture. cs_w32_frexp_ldexp is memory-fed, like cs_w32_shift64 (#590): check.py seeds 64 records of a binary32 value, an ldexp exponent and a binary64 value, and each thread loads one at run time. They cover normals, the clamp of the exponent at ±512 and beyond, results that overflow to an infinity and that fall below the smallest normal, binary32 denormals (read as zero), 24 binary64 subnormals (single fraction bits on both sides of the dword boundary, and patterns with several), zeros, infinities and NaNs. A thread stores the five results, v_frexp_mant_f32 with a neg source, and v_ldexp_f32 with an abs source run with the odd threads turned off. The expected words come from an oracle written from the rows of docs/design.md; tests/test_gpu_frexp_ldexp.py checks it against math.frexp and math.ldexp wherever those agree with the hardware, and checks the assembly, the readback and the runner verdicts without a GPU. Both runners compare all 768 heap words.

What it found, and the fix (the finding linked above). On an RTX 4070 Ti six of the 512 result words were wrong: every NaN source under a neg or abs modifier came back as 0x7fffffff, the driver's default NaN, where the hardware returns the source with its sign bit moved. The binary32 branch read its source with Gen.src_u, which applies the modifiers as FAbs and OpFNegate, and Vulkan lets a driver return any NaN from those. The three ops only move bits, and Gen.src_u_sign_mods exists for that case (the min/max family uses it), so the branch now reads its source through it: one line of tools/rdna2spirv.py. SourceModifierBitsTests in tests/semantic/test_alu_frexp_ldexp.py checks that the modifiers are emitted as sign-bit ops and that a NaN, a denormal, a zero and an infinity under them give the hardware's word. The fixture cannot pass on NVIDIA without that line, which is why both are in one pull request; this corrects the "no translator change" of my first claim.

The two rows of docs/design.md name the fixture, and the binary32 one the rule.

Tested

At this head, llvm-mc 23.1.4, SPIRV-Tools v2026.4:

  • python -I scripts/run_gpu_tests.py --build runtime/build --filter cs_w32_frexp_ldexp --require-pass: PASS ("768 words exact") on the RTX 4070 Ti natively and with LEONIDA_W64_EMULATE=1, and on llvmpipe. With the one line put back, word 419 fails on the 4070 Ti ("expected 0xffc00000, got 0x7fffffff"; six words differ in all) and llvmpipe still passes.
  • Rules broken one at a time, fixture rebuilt, on both devices; each failed at the word the oracle predicts: the mantissa given the exponent field 127 (word 0) or, for binary64, 1023 (word 5), the exponent subtracting 127 (word 1), v_ldexp_f32 without its clamp (word 258) or overflowing to the largest finite value (word 106), a binary32 denormal not read as zero (word 352), the binary64 subnormal exponent off by one in the low or in the high dword (words 134 and 150), the fixture without its v_cmpx (word 15).
  • python -m unittest discover -s tests/semantic -p test_alu_frexp_ldexp.py: 15 tests. With tools/rdna2spirv.py put back to the commit below, test_the_modifiers_are_not_float_instructions fails for all eight modifier forms. The interpreter negates on the bits whichever way the module does it, so the value tests hold with both lowerings; the instruction check and the GPU run are what tell them apart.
  • Whole translator suite, python -I scripts/run_semantic_tests.py tests/semantic -j 8: 470 files, 6,169 tests, 0 files failed.
  • Corpus: none of the 25,734 disassembly listings in my work folder contains a frexp or ldexp op, so no game shader's translation changes.
  • git merge-tree against main 32950551e and against #1047's head: clean; the three-way result of this branch, #1047 and main passes the tests below as well.
  • tests/test_gpu_frexp_ldexp.py (11 tests), tests/test_shader_checks.py (87), tests/test_run_gpu_tests.py (64), tests/test_gpu_round_f64.py, tests/test_gpu_cmp_f64.py, tests/test_semantic_translator_use.py, tests/test_docs_design_rows.py, tests/test_docs_links.py, tests/test_docs_repo_paths.py, tests/test_text_write_line_endings.py: OK. python -m compileall -q make_game.py tools tests and scripts/check_no_game_data.py on the changed files: OK.

Not run: the whole GPU suite at this head (it ran clean on main 32950551e for #1059, and this adds one fixture and changes three ops no other fixture uses); llvm-mc 19; Windows; AMD hardware. The binary16 forms and v_ldexp_f64 are not in the fixture. The hardware's words are the rows' gfx1036 measurements, which this does not repeat.

Merge of #1034's 60c2ed910 (eba94cbe8). The red linux-gpu-tools here was not this fixture: cs_w32_frexp_ldexp passed in that run, and #1034's cs_w32_round_f64, which is in this stack, failed on a runner without AVX-512, where llvmpipe computes Trunc and RoundEven of a double with its float code (details in #1034). #1034 now carries an allowance for llvmpipe, merged here without conflict. On the merge: --filter cs_w32_ gives 15 of 23 passed and 8 skipped on llvmpipe (Mesa 26.2.6), natively and under GALLIUM_OVERRIDE_CPU_CAPS=avx, and 23 of 23 on the RTX 4070 Ti; tests/test_gpu_frexp_ldexp.py, tests/test_gpu_round_f64.py, tests/test_shader_checks.py and tests/test_run_gpu_tests.py pass, also on the tree merged with main 4a50cafc7.

GPUs tested: NVIDIA GeForce RTX 4070 Ti, driver 620.70.06, Linux (CachyOS, kernel 7.3.3); Mesa llvmpipe 26.2.6 (LLVM 23.1.4), same machine

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/1063 **Author:** [@milk4sale](https://github.com/milk4sale) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/25/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `gpu-test/frexp-ldexp` --- ### 📝 Commits (8) - [`355c8c9`](https://github.com/ubiquitarianism/leonida/commit/355c8c9c2da01a9898df5061d266ca1f5567cdc9) tests: GPU readback for the binary64 roundings, v_trunc_f64, v_ceil_f64, v_rndne_f64 and v_floor_f64 (GPU-ROUND-F64) - [`5f063e5`](https://github.com/ubiquitarianism/leonida/commit/5f063e5812f9b12f5c2063c1b552fd975ae9e5e9) tests, rdna2spirv: GPU readback for frexp and ldexp, and their neg/abs sources move the sign bit (GPU-FREXP-LDEXP, SHADER-FREXP-LDEXP-SIGN-MODS) - [`60c2ed9`](https://github.com/ubiquitarianism/leonida/commit/60c2ed910b90aef3cf5af1df2366a28a25afbe64) tests: cs_w32_round_f64 allows llvmpipe's float path for Trunc and RoundEven (GPU-ROUND-F64) - [`eba94cb`](https://github.com/ubiquitarianism/leonida/commit/eba94cbe893de58b059a4ded35c498fea32a32d0) Merge gpu-test/round-f64 into gpu-test/frexp-ldexp: cs_w32_round_f64's llvmpipe allowance - [`e040dce`](https://github.com/ubiquitarianism/leonida/commit/e040dce1f09d42f21a8fed75668c53c0d49fb57a) Merge main into gpu-test/round-f64 - [`2eb49b1`](https://github.com/ubiquitarianism/leonida/commit/2eb49b1a6fdbba711a5567613297a735503a6fcb) Merge main into gpu-test/frexp-ldexp - [`69935f8`](https://github.com/ubiquitarianism/leonida/commit/69935f84ee8d670626594c3c5e4a171b2e20fcf0) Merge main into gpu-test/round-f64 - [`5431c75`](https://github.com/ubiquitarianism/leonida/commit/5431c75a6f7d7cd083b15524d8afe27ab461f28e) Merge gpu-test/round-f64 into gpu-test/frexp-ldexp: main 6558d5318, with #1012 merged ### 📊 Changes **11 files changed** (+1071 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+3 -3) 📝 `docs/testing.md` (+58 -0) 📝 `runtime/test/shaders/check.py` (+264 -2) ➕ `runtime/test/shaders/cs_w32_frexp_ldexp.asm` (+44 -0) ➕ `runtime/test/shaders/cs_w32_round_f64.asm` (+56 -0) 📝 `scripts/run_gpu_tests.py` (+10 -0) 📝 `tests/semantic/test_alu_frexp_ldexp.py` (+60 -0) ➕ `tests/test_gpu_frexp_ldexp.py` (+236 -0) ➕ `tests/test_gpu_round_f64.py` (+319 -0) 📝 `tests/test_shader_checks.py` (+18 -2) 📝 `tools/rdna2spirv.py` (+3 -1) </details> ### 📄 Description Claimed in the coordination issue as: GPU-FREXP-LDEXP (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7139072105), SHADER-FREXP-LDEXP-SIGN-MODS (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7139171475) Depends on: #1034, which depends on #1012 (this branch is one commit on top of them. All three add a memory-fed fixture next to `cs_w32_shift64` and touch the same lines of `check.py`, `run_gpu_tests.py` and `tests/test_shader_checks.py`; the last commit is the one to review. It does not touch what #1047 changes.) ### What and why `v_frexp_mant_f32`, `v_frexp_exp_i32_f32`, `v_ldexp_f32`, `v_frexp_mant_f64` and `v_frexp_exp_i32_f64` are lowered with integer ops on the float's words. They are CPU-checked and measured natively on gfx1036, but no fixture in `runtime/test/shaders` ran any of the five. **The fixture.** `cs_w32_frexp_ldexp` is memory-fed, like `cs_w32_shift64` (#590): `check.py` seeds 64 records of a binary32 value, an `ldexp` exponent and a binary64 value, and each thread loads one at run time. They cover normals, the clamp of the exponent at ±512 and beyond, results that overflow to an infinity and that fall below the smallest normal, binary32 denormals (read as zero), 24 binary64 subnormals (single fraction bits on both sides of the dword boundary, and patterns with several), zeros, infinities and NaNs. A thread stores the five results, `v_frexp_mant_f32` with a `neg` source, and `v_ldexp_f32` with an `abs` source run with the odd threads turned off. The expected words come from an oracle written from the rows of `docs/design.md`; `tests/test_gpu_frexp_ldexp.py` checks it against `math.frexp` and `math.ldexp` wherever those agree with the hardware, and checks the assembly, the readback and the runner verdicts without a GPU. Both runners compare all 768 heap words. **What it found, and the fix** (the finding linked above). On an RTX 4070 Ti six of the 512 result words were wrong: every NaN source under a `neg` or `abs` modifier came back as `0x7fffffff`, the driver's default NaN, where the hardware returns the source with its sign bit moved. The binary32 branch read its source with `Gen.src_u`, which applies the modifiers as `FAbs` and `OpFNegate`, and Vulkan lets a driver return any NaN from those. The three ops only move bits, and `Gen.src_u_sign_mods` exists for that case (the min/max family uses it), so the branch now reads its source through it: one line of `tools/rdna2spirv.py`. `SourceModifierBitsTests` in `tests/semantic/test_alu_frexp_ldexp.py` checks that the modifiers are emitted as sign-bit ops and that a NaN, a denormal, a zero and an infinity under them give the hardware's word. The fixture cannot pass on NVIDIA without that line, which is why both are in one pull request; this corrects the "no translator change" of my first claim. The two rows of `docs/design.md` name the fixture, and the binary32 one the rule. ### Tested At this head, llvm-mc 23.1.4, SPIRV-Tools v2026.4: - `python -I scripts/run_gpu_tests.py --build runtime/build --filter cs_w32_frexp_ldexp --require-pass`: PASS ("768 words exact") on the RTX 4070 Ti natively and with `LEONIDA_W64_EMULATE=1`, and on llvmpipe. With the one line put back, word 419 fails on the 4070 Ti ("expected 0xffc00000, got 0x7fffffff"; six words differ in all) and llvmpipe still passes. - Rules broken one at a time, fixture rebuilt, on both devices; each failed at the word the oracle predicts: the mantissa given the exponent field 127 (word 0) or, for binary64, 1023 (word 5), the exponent subtracting 127 (word 1), `v_ldexp_f32` without its clamp (word 258) or overflowing to the largest finite value (word 106), a binary32 denormal not read as zero (word 352), the binary64 subnormal exponent off by one in the low or in the high dword (words 134 and 150), the fixture without its `v_cmpx` (word 15). - `python -m unittest discover -s tests/semantic -p test_alu_frexp_ldexp.py`: 15 tests. With `tools/rdna2spirv.py` put back to the commit below, `test_the_modifiers_are_not_float_instructions` fails for all eight modifier forms. The interpreter negates on the bits whichever way the module does it, so the value tests hold with both lowerings; the instruction check and the GPU run are what tell them apart. - Whole translator suite, `python -I scripts/run_semantic_tests.py tests/semantic -j 8`: 470 files, 6,169 tests, 0 files failed. - Corpus: none of the 25,734 disassembly listings in my work folder contains a frexp or ldexp op, so no game shader's translation changes. - `git merge-tree` against `main` `32950551e` and against #1047's head: clean; the three-way result of this branch, #1047 and `main` passes the tests below as well. - `tests/test_gpu_frexp_ldexp.py` (11 tests), `tests/test_shader_checks.py` (87), `tests/test_run_gpu_tests.py` (64), `tests/test_gpu_round_f64.py`, `tests/test_gpu_cmp_f64.py`, `tests/test_semantic_translator_use.py`, `tests/test_docs_design_rows.py`, `tests/test_docs_links.py`, `tests/test_docs_repo_paths.py`, `tests/test_text_write_line_endings.py`: OK. `python -m compileall -q make_game.py tools tests` and `scripts/check_no_game_data.py` on the changed files: OK. Not run: the whole GPU suite at this head (it ran clean on `main` `32950551e` for #1059, and this adds one fixture and changes three ops no other fixture uses); llvm-mc 19; Windows; AMD hardware. The binary16 forms and `v_ldexp_f64` are not in the fixture. The hardware's words are the rows' gfx1036 measurements, which this does not repeat. **Merge of #1034's `60c2ed910` (`eba94cbe8`).** The red `linux-gpu-tools` here was not this fixture: `cs_w32_frexp_ldexp` passed in that run, and #1034's `cs_w32_round_f64`, which is in this stack, failed on a runner without AVX-512, where llvmpipe computes `Trunc` and `RoundEven` of a double with its float code (details in #1034). #1034 now carries an allowance for llvmpipe, merged here without conflict. On the merge: `--filter cs_w32_` gives 15 of 23 passed and 8 skipped on llvmpipe (Mesa 26.2.6), natively and under `GALLIUM_OVERRIDE_CPU_CAPS=avx`, and 23 of 23 on the RTX 4070 Ti; `tests/test_gpu_frexp_ldexp.py`, `tests/test_gpu_round_f64.py`, `tests/test_shader_checks.py` and `tests/test_run_gpu_tests.py` pass, also on the tree merged with `main` 4a50cafc7. GPUs tested: NVIDIA GeForce RTX 4070 Ti, driver 620.70.06, Linux (CachyOS, kernel 7.3.3); Mesa llvmpipe 26.2.6 (LLVM 23.1.4), same machine 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>
4ld0 2026-11-26 20:20:05 +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#1102
No description provided.