Shader div scale probe #1478

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

@⁠vsking2000 on GitHub · 2026-11-25 01:12 UTC · original
vsking2000:shader-div-scale-probe → main · +1569 −0 · 3 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/1478) `vsking2000:shader-div-scale-probe` → `main` · +1569 −0 · 3 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.
The translator refuses v_div_scale_f32/f64: the ISA text, the D = S0
pass-through LLVM's divide lowering relies on and the rule tinygrad's
RDNA3 emulator runs disagree at the edges, so the rule has to come from
a measurement. tools/div_scale_probe.py makes that one command on a
GFX10 GPU, built like tools/f64_omod_probe.py on tools/hw_oracle: raw
one-lane kernels, the five MODEs of that probe (game MODE first), wave32
and wave64.

Per width it runs 48 numerator/denominator pairs (special, denormal,
exponent gap 95/96/97 [767/768/769], denominators around 2^126 [2^1022],
quotients around 2^-126 [2^-1022], numerator fields 22/23/24
[52/53/54], ordinary) as the denominator and the numerator call, plus
10 S0 = S1 = S2 cases, each with VCC and with an SGPR mask destination
preset to all ones; 30 modifier rows; and LLVM's whole divide sequence
on every pair. Each row prints next to it what three candidate readings
predict (the newer ISA wording, the text with an f32-width reciprocal
test, tinygrad's emulator rule), so a run shows which one the hardware
follows. Not run on hardware; no rule goes into the contract table.

tests/test_div_scale_probe.py checks the matrix and its boundaries, the
candidates' known disagreements (including the 1.0 / 2^127 -> +inf
divide through the translator's measured v_div_fmas/v_div_fixup),
assembly with llvm-mc, and parsing and the CLI with a fake oracle.
docs/shader_validation.md documents the tool.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y7fbZYVY7EtLknWBZUfSLf
Review follow-ups for SHADER-DIV-SCALE-PROBE.

- D is written with a sentinel (no operand of the matrix and no candidate
  prediction equals it) before every v_div_scale of the plain and modifier
  kernels, so a D that is not written is reported (d_unwritten: summary line,
  --json field, --table marker) instead of reading as the previous row's value.
  The docstring and docs say that D = S0 where no branch assigns it is an
  assumption applied in every candidate, and name the emulator that initialises
  D differently.
- The f32 divide sequence omits LLVM's s_denorm_mode switch: the summary labels
  the f32 tallies of the MODEs that flush f32 denormals as not comparable with
  LLVM's lowering (llvm_comparable in the JSON), with a note.
- New pair 2^-60 [2^-284] over the smallest denormal: a gap below 96 [768], so
  the denormal-denominator branch is reached and not the gap branch. 49 pairs,
  108 rows per width.
- A run without --json ends with a line saying the summary is not the
  measurement. --json has mask_lo/mask_hi instead of the bare list; --table
  starts with a legend.
- isa_recip_width is described as the same text with the reciprocal classified
  in the operand's width; docstring and test references to a docs/design.md row
  that does not exist point at the docs/shader_validation.md section.
- tests: the preset and sentinel before every v_div_scale, the sequence against
  a hand-written table of LowerFDIV32/LowerFDIV64 and as a division on exact
  arithmetic, an unwritten D, the labels, the legend, a cr_ftz verdict.

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:24 +00:00
Author
Owner

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

Tested aea8ca596 on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against main 3ff2a2adc (new Python tool; no GPU):

  • LLVM_MC=/opt/homebrew/opt/llvm/bin/llvm-mc python3 -I tests/test_div_scale_probe.py: 36/36 OK at this head. Without LLVM_MC (Homebrew llvm is keg-only), test_kernels_assemble_when_llvm_mc_available skips with "llvm-mc not found".
  • On main there is no tools/div_scale_probe.py, so the test fails at import — new tool, no before/after to compare.
  • Not run: the probe against real hardware v_div_scale readings; only the unit tests.

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

**@⁠GeorgiyDemo** on GitHub · 2026-11-25 02:20 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1478#issuecomment-7150602419) Tested `aea8ca596` on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against `main` `3ff2a2adc` (new Python tool; no GPU): - `LLVM_MC=/opt/homebrew/opt/llvm/bin/llvm-mc python3 -I tests/test_div_scale_probe.py`: **36/36 OK** at this head. Without `LLVM_MC` (Homebrew llvm is keg-only), `test_kernels_assemble_when_llvm_mc_available` skips with "llvm-mc not found". - On `main` there is no `tools/div_scale_probe.py`, so the test fails at import — new tool, no before/after to compare. - Not run: the probe against real hardware `v_div_scale` readings; only the unit tests. AI-assisted; synthetic fixtures only, no game data.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

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