Shader trig preop #1476

Open
github-bot wants to merge 2 commits from github-bot/gh-1476 into main AGit
Owner

@⁠vsking2000 on GitHub · 2026-11-25 01:12 UTC · original
vsking2000:shader-trig-preop → main · +511 −1 · 4 files · 2 commits · open

Claimed in the coordination issue as:

Depends on:

Fixes:

What and why

Tested

GPUs tested:

AI-assisted:

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.
**@⁠vsking2000** on GitHub · 2026-11-25 01:12 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1476) `vsking2000:shader-trig-preop` → `main` · +511 −1 · 4 files · 2 commits · open Claimed in the coordination issue as: <!-- the item ID from the open "Coordinating who works on what" issue, for example TEST-17, or a link to your claim --> Depends on: <!-- #N for every pull request this one builds on or conflicts with (the coordination issue's Commands section, AGENTS.md); delete the line if it builds on none and conflicts with none --> Fixes: <!-- #N for each issue this closes (GitHub closes it on merge); delete the line if it closes none --> ### What and why <!-- What this changes and the problem it solves. --> ### Tested <!-- What you ran and on which GPU and driver (CONTRIBUTING.md). For the shader translator: how many shaders translate and pass spirv-val, before and after. --> GPUs tested: <!-- vendor, model, driver and OS of each GPU the GPU tests ran on, or n/a --> AI-assisted: <!-- yes or no (AGENTS.md asks a coding agent to say so) --> ### 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.
v_trig_preop_f64 was refused by name. It now translates when S1 is an
integer constant with S1[4:0] <= 2, following the ISA pseudocode: the 53
fraction bits of 2/pi after the first shift = 53 * S1[4:0] (+ exponent(S0)
- 1077 above 1077), times 2^(-53 - shift), times 2^128 more from an
exponent field of 1968. Only the exponent field of S0 is read.

The result is built with 32-bit integer ops only: the 2/pi words live in a
Private constant array derived exactly from integer bounds on pi, the
window is read from three words, normalised and packed into the exponent
and mantissa fields. In the translated domain every result is a normal
double, so nothing is rounded.

Refused: a register or float S1 and S1[4:0] >= 3, where LLVM's constant
folding (0 from a shift of 1120) and the ISA text's 1201-bit constant
disagree; clamp and omod (unmeasured). tools/shader_ir.py flags hex
literal sources of the op as f64 literals. docs/design.md records the
sources of each part and what is unmeasured.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y7fbZYVY7EtLknWBZUfSLf
docs/design.md: tinygrad's TestTrigPreop is described as what it is: it runs on
tinygrad's emulator unless USE_HW=1, the emulator implements the same
pseudocode and the comparison is a tolerance, so it is a third derivation of
the same window, not hardware evidence. LLVM's constant-folding test
(llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll, the
trig_preop_constfold* functions) is added as the bit-exact external source,
described as compile-time folds, not measurements; the translator reproduces
all 22 of them with S1[4:0] <= 2. The tinygrad pseudocode file is named without
an upstream path, which was not confirmed. "Not measured on any hardware" stays.

tests/semantic/test_trig_preop_f64.py (21 tests, was 16): LLVM's 22 in-domain
fold words as literals with their S0 bits and S1; S1 = 65; a destination equal
to S0 and one overlapping it; two uses in one program.

tools/rdna2spirv.py: comment and docstring only. The result's exponent field
is 26..1022 over the translated domain (not "1 .. 1150"), and the Machin error
bound is (terms + 2) units, as the code has it. No arithmetic changes.

AI-assisted.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y7fbZYVY7EtLknWBZUfSLf
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:53:19 +00:00
Author
Owner

@⁠GeorgiyDemo on GitHub · 2026-11-25 02:20 UTC · original

Tested 78b87beb9 on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against main 3ff2a2adc (translator-only PR; binaries from the build at 66d4f5aa3):

  • python3 -m unittest test_trig_preop_f64 (from tests/semantic): OK at this head. The same file on main fails 4 + 35 errors.
  • GPU: --filter ps_f64 SKIPs on both MoltenVK 1.4.2 and KosmicKrisp (Mesa 26.3.1): ps_f64_mods and ps_f64_round report "uses Float64 and the device has no shaderFloat64". Apple GPUs cannot run f64 shaders, so the GPU side of this change is untestable on this machine.
  • Not run: GPU execution of the new trig-preop form; no .asm fixture for it, and no f64 device — the semantic suite is the evidence.

AI-assisted; synthetic fixtures only, no game data.

**@⁠GeorgiyDemo** on GitHub · 2026-11-25 02:20 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1476#issuecomment-7150602874) Tested `78b87beb9` on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against `main` `3ff2a2adc` (translator-only PR; binaries from the build at `66d4f5aa3`): - `python3 -m unittest test_trig_preop_f64` (from `tests/semantic`): **OK** at this head. The same file on `main` fails **4 + 35 errors**. - GPU: `--filter ps_f64` **SKIPs on both MoltenVK 1.4.2 and KosmicKrisp** (Mesa 26.3.1): `ps_f64_mods` and `ps_f64_round` report "uses Float64 and the device has no shaderFloat64". Apple GPUs cannot run f64 shaders, so the GPU side of this change is untestable on this machine. - Not run: GPU execution of the new trig-preop form; no `.asm` fixture for it, and no f64 device — the semantic suite is the evidence. AI-assisted; synthetic fixtures only, no game data.
This pull request has changes conflicting with the target branch.
  • tools/rdna2spirv.py
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1476/head:github-bot/gh-1476'
git switch 'github-bot/gh-1476'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1476'
git switch 'github-bot/gh-1476'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1476'
git switch 'github-bot/gh-1476'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1476'
git switch 'main'
git merge --squash 'github-bot/gh-1476'
git switch 'main'
git merge --ff-only 'github-bot/gh-1476'
git switch 'main'
git merge 'github-bot/gh-1476'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.