tombox-xshader: v_div_scale_f64 and the f64 div ops under MODE as RDNA2 does #391

Open
github-bot wants to merge 1 commit from github-bot/gh-391 into main AGit
Owner

@⁠SchmashinPrunes on GitHub · 2026-11-25 20:56 UTC · original
SchmashinPrunes:f64-div-mode-rdna2 → main · +72 −15 · 4 files · 1 commits · open

@⁠omonkeyz, this fixes v_div_scale_f64 at every MODE, and v_div_fixup_f64 / v_div_fmas_f64 under f64 denormal flush. It came out of the translator-vs-gfx1036 comparison from #387, plus four small targeted runs on the same iGPU.

1. v_div_scale_f64 doesn't follow the documented pseudo-code

The translator (and the exec reference model) implemented AMD's documented rule. gfx1036 disagreed on 210 of the 1,024 recorded lanes at the default MODE, mostly on VCC. VCC is what v_div_fmas_f64 uses to undo the scaling, so a full f64 division can come out off by 2^±64 when it's wrong. With d/n exponent fields ed/en, silicon does this:

condition result VCC
d or n zero 0xfff8000000000000 (−qNaN, not +qNaN) abs(en − ed) ≥ 768
en − ed ≥ 768 x == d ? x·2¹²⁸ : x 1
d denormal x·2¹²⁸ 0
ed ≥ 2045 and en − ed ≤ −768 x == d ? x·2⁻¹²⁸ : x 1
ed ≥ 2045 x·2⁻¹²⁸ 0
en − ed ≤ −768 x == d ? x : x·2¹²⁸ 1
en ≤ 53 x·2¹²⁸ 0
otherwise x 0

Where this departs from the documented rule:

  • Both "tiny" tests use exponent fields, not exact values.

    • "1/d is denormal" is ed ≥ 2045: d = 2¹⁰²² counts, though 1/d is exactly normal.
    • "n/d is denormal" is en − ed ≤ −768. That also sets VCC for quotients like 2⁻⁷⁹⁰, which are far from denormal.
  • VCC for a zero operand depends on the same exponent difference, in either direction.

  • The tiny-quotient case scales any x other than d. The documented rule scales only x == n.

  • On the 2⁻¹²⁸ paths, an x with exponent field ≤ 116 (denormals included) gives ±inf instead of underflowing. Fields 117 and up give the correctly rounded, possibly denormal, result. Zero, inf and NaN pass through unchanged.

    This can't happen inside a real division sequence, where x is d or n. I measured it so the model is exact.

The rule matches all 1,024 recorded lanes in each of the three MODEs where f64 denormals are enabled (0xf0, 0xc0, and 0xf0 with IEEE). Under f64 flush, the MODE path's existing operand and result flush covers the rest.

2. v_div_fixup_f64 / v_div_fmas_f64 under f64 denormal flush

The MODE path flushed every f64 operand and result of both ops. gfx1036 flushes:

  • v_div_fixup_f64: only the d and n operands. The quotient operand and the result keep denormals; fixup(2⁻¹⁰⁷⁴, −1, 1) gives 0x8000000000000001.
  • v_div_fmas_f64: only the result. Its inputs aren't flushed. fmas(2⁻¹⁰⁷⁴, −1, 2⁻¹⁰²²) gives 0, the flushed 0x000fffffffffffff. The translator flushed the input 2⁻¹⁰⁷⁴ first and returned 2⁻¹⁰²².

Tests

  • New f64_div_scale_edge_cases_as_rdna2: 6 gfx1036 vectors, including the inf and denormal results on the 2⁻¹²⁸ path.
  • New f64_div_fixup_and_fmas_under_f64_flush_as_rdna2: 4 gfx1036 vectors under f64 flush set by s_setreg.
  • The div_scale reference model in exec_vop/mod.rs follows the table above, and its operand table gains 6 rows that exercise the changed branches.
run result
WARP, without the src/ change the new tests fail (3 + 3 cases), plus 19 of the div_scale_and_fixup_f64 rows
WARP, tests/exec.rs 191/191
Radeon RX 9060 XT, tests/exec.rs 191/191
full f64 division sequences (div_f64, 118 cases) unchanged, passing on both hosts
isa_sweep target, WARP ok (existing WARP_KNOWN deviations only)
translator vs gfx1036, initial MODE 0xf0 / 0x30 / 0x00, RX 9060 XT no v_div_* mnemonic differs any more (16 / 44 / 45 differ in total, down from 17 / 45 / 46)
same, WARP only v_div_fmas_f64, which is WARP's existing f64 fma deviation (WARP_KNOWN)

The PR gate is clean. No game or console files are involved.

🤖 Generated with Claude Code

**@⁠SchmashinPrunes** on GitHub · 2026-11-25 20:56 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/391) `SchmashinPrunes:f64-div-mode-rdna2` → `main` · +72 −15 · 4 files · 1 commits · open @⁠omonkeyz, this fixes `v_div_scale_f64` at every MODE, and `v_div_fixup_f64` / `v_div_fmas_f64` under f64 denormal flush. It came out of the translator-vs-gfx1036 comparison from #387, plus four small targeted runs on the same iGPU. ### 1. `v_div_scale_f64` doesn't follow the documented pseudo-code The translator (and the exec reference model) implemented AMD's documented rule. gfx1036 disagreed on 210 of the 1,024 recorded lanes at the default MODE, mostly on VCC. VCC is what `v_div_fmas_f64` uses to undo the scaling, so a full f64 division can come out off by 2^±64 when it's wrong. With `d`/`n` exponent fields `ed`/`en`, silicon does this: | condition | result | VCC | |---|---|---| | `d` or `n` zero | `0xfff8000000000000` (−qNaN, not +qNaN) | `abs(en − ed) ≥ 768` | | `en − ed ≥ 768` | `x == d` ? `x·2¹²⁸` : `x` | 1 | | `d` denormal | `x·2¹²⁸` | 0 | | `ed ≥ 2045` and `en − ed ≤ −768` | `x == d` ? `x·2⁻¹²⁸` : `x` | 1 | | `ed ≥ 2045` | `x·2⁻¹²⁸` | 0 | | `en − ed ≤ −768` | `x == d` ? `x` : `x·2¹²⁸` | 1 | | `en ≤ 53` | `x·2¹²⁸` | 0 | | otherwise | `x` | 0 | Where this departs from the documented rule: - **Both "tiny" tests use exponent fields, not exact values.** - "1/d is denormal" is `ed ≥ 2045`: `d = 2¹⁰²²` counts, though `1/d` is exactly normal. - "n/d is denormal" is `en − ed ≤ −768`. That also sets VCC for quotients like `2⁻⁷⁹⁰`, which are far from denormal. - **VCC for a zero operand** depends on the same exponent difference, in either direction. - **The tiny-quotient case** scales any `x` other than `d`. The documented rule scales only `x == n`. - **On the 2⁻¹²⁸ paths,** an `x` with exponent field ≤ 116 (denormals included) gives **±inf** instead of underflowing. Fields 117 and up give the correctly rounded, possibly denormal, result. Zero, inf and NaN pass through unchanged. This can't happen inside a real division sequence, where `x` is `d` or `n`. I measured it so the model is exact. The rule matches all 1,024 recorded lanes in each of the three MODEs where f64 denormals are enabled (0xf0, 0xc0, and 0xf0 with IEEE). Under f64 flush, the MODE path's existing operand and result flush covers the rest. ### 2. `v_div_fixup_f64` / `v_div_fmas_f64` under f64 denormal flush The MODE path flushed every f64 operand and result of both ops. gfx1036 flushes: - `v_div_fixup_f64`: only the `d` and `n` operands. The quotient operand and the result keep denormals; `fixup(2⁻¹⁰⁷⁴, −1, 1)` gives `0x8000000000000001`. - `v_div_fmas_f64`: only the result. Its inputs aren't flushed. `fmas(2⁻¹⁰⁷⁴, −1, 2⁻¹⁰²²)` gives `0`, the flushed `0x000fffffffffffff`. The translator flushed the input `2⁻¹⁰⁷⁴` first and returned `2⁻¹⁰²²`. ### Tests - New `f64_div_scale_edge_cases_as_rdna2`: 6 gfx1036 vectors, including the inf and denormal results on the 2⁻¹²⁸ path. - New `f64_div_fixup_and_fmas_under_f64_flush_as_rdna2`: 4 gfx1036 vectors under f64 flush set by `s_setreg`. - The `div_scale` reference model in `exec_vop/mod.rs` follows the table above, and its operand table gains 6 rows that exercise the changed branches. | run | result | |---|---| | WARP, without the `src/` change | the new tests fail (3 + 3 cases), plus 19 of the `div_scale_and_fixup_f64` rows | | WARP, `tests/exec.rs` | 191/191 | | Radeon RX 9060 XT, `tests/exec.rs` | 191/191 | | full f64 division sequences (`div_f64`, 118 cases) | unchanged, passing on both hosts | | `isa_sweep` target, WARP | ok (existing `WARP_KNOWN` deviations only) | | translator vs gfx1036, initial MODE 0xf0 / 0x30 / 0x00, RX 9060 XT | no `v_div_*` mnemonic differs any more (16 / 44 / 45 differ in total, down from 17 / 45 / 46) | | same, WARP | only `v_div_fmas_f64`, which is WARP's existing f64 fma deviation (`WARP_KNOWN`) | The PR gate is clean. No game or console files are involved. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
v_div_scale_f64 followed the documented pseudo-code, which gfx1036 does
not: VCC is set when the exponent fields differ by 768 or more in either
direction, "quotient tiny" is that test (en - ed <= -768) and scales x
unless x is the denominator, "1/d tiny" is ed >= 2045, a zero operand
gives -qNaN, and on the 2^-128 path an x with exponent field <= 116
becomes infinity. Fitted to and checked against all 1,024 recorded
gfx1036 lanes in each of the three MODEs with f64 denormals enabled.

Under f64 denormal flush, v_div_fixup_f64 no longer flushes its quotient
operand or its result, and v_div_fmas_f64 no longer flushes its inputs;
gfx1036 flushes only the d and n operands of fixup and the fmas result.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:21:14 +00:00
This pull request can be merged automatically.
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/391/head:github-bot/gh-391'
git switch 'github-bot/gh-391'

Merge

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