tombox-xshader: v_div_scale_f64 and the f64 div ops under MODE as RDNA2 does #391
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
library
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/omonkeyz--xbox-emulator!391
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-391"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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_f64at every MODE, andv_div_fixup_f64/v_div_fmas_f64under 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_f64doesn't follow the documented pseudo-codeThe 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_f64uses to undo the scaling, so a full f64 division can come out off by 2^±64 when it's wrong. Withd/nexponent fieldsed/en, silicon does this:dornzero0xfff8000000000000(−qNaN, not +qNaN)abs(en − ed) ≥ 768en − ed ≥ 768x == d?x·2¹²⁸:xddenormalx·2¹²⁸ed ≥ 2045anden − ed ≤ −768x == d?x·2⁻¹²⁸:xed ≥ 2045x·2⁻¹²⁸en − ed ≤ −768x == d?x:x·2¹²⁸en ≤ 53x·2¹²⁸xWhere this departs from the documented rule:
Both "tiny" tests use exponent fields, not exact values.
ed ≥ 2045:d = 2¹⁰²²counts, though1/dis exactly normal.en − ed ≤ −768. That also sets VCC for quotients like2⁻⁷⁹⁰, 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
xother thand. The documented rule scales onlyx == n.On the 2⁻¹²⁸ paths, an
xwith 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
xisdorn. 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_f64under f64 denormal flushThe MODE path flushed every f64 operand and result of both ops. gfx1036 flushes:
v_div_fixup_f64: only thedandnoperands. The quotient operand and the result keep denormals;fixup(2⁻¹⁰⁷⁴, −1, 1)gives0x8000000000000001.v_div_fmas_f64: only the result. Its inputs aren't flushed.fmas(2⁻¹⁰⁷⁴, −1, 2⁻¹⁰²²)gives0, the flushed0x000fffffffffffff. The translator flushed the input2⁻¹⁰⁷⁴first and returned2⁻¹⁰²².Tests
f64_div_scale_edge_cases_as_rdna2: 6 gfx1036 vectors, including the inf and denormal results on the 2⁻¹²⁸ path.f64_div_fixup_and_fmas_under_f64_flush_as_rdna2: 4 gfx1036 vectors under f64 flush set bys_setreg.div_scalereference model inexec_vop/mod.rsfollows the table above, and its operand table gains 6 rows that exercise the changed branches.src/changediv_scale_and_fixup_f64rowstests/exec.rstests/exec.rsdiv_f64, 118 cases)isa_sweeptarget, WARPWARP_KNOWNdeviations only)v_div_*mnemonic differs any more (16 / 44 / 45 differ in total, down from 17 / 45 / 46)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
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.