feat(shader): implement v_div_scale_f64, v_div_fmas_f64 and v_div_fixup_f64 #474
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/474"
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?
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-03T17:39:43Z.
What
The f64 division ops threw "opcode not implemented". Found by the ISA coverage sweep:
v_div_scale_f64,v_div_fmas_f64,v_div_fixup_f64, the f64 version of the precise division macro compilers emit fora / b.Stacked on #447 and #264 (#446 is merged): it uses the f64 ops of #447 and the f32 versions from #264. Their
commits are included here unchanged, with only adjacent opcode lines resolved between them. Only the last commit is new.
Behaviour measured on HW
RDNA2 (Radeon 660M), 41152 results from two kernels (plain operands, then abs/neg modifiers and per-lane VCC). I wrote a Python model first, it matched every result, and then the C++:
v_div_scale_f64decides from the exponent fields only, like the f32 op (#264), with f64 constants: it scales by2^128 or 2^-128 and sets VCC for exponent differences >= 768 or <= -768, a denormal or huge (exponent >= 2045)
denominator and a numerator exponent <= 53. A NaN source is returned unchanged (signalling NaNs stay
signalling), and a zero numerator or denominator gives
0xfff8000000000000.v_div_fmas_f64with VCC set computes(S0 * S1 + S2) * 2^±128with a single rounding: 2^128 when the exponentof S2 is >= 1024, else 2^-128. Inf/NaN inputs and VCC clear give a plain fma. It reuses the exact fma emulation from
#446 (Dekker + TwoSum + round-to-odd), with the scale folded into its final rescale, so the result does not depend
on how the driver rounds
Fma.v_div_fixup_f64follows the ISA: NaN sources come back quieted, 0/0 and inf/inf give the default NaN, a NaNquotient with finite inputs becomes ±inf, and exponent differences below -1075 give a signed zero.
FPLdexp64), and so is NaN handling.Tested
F64DivisionandF64DivisionModifiers, 32 lanes each with expected values captured onhardware. Rows are picked greedily to cover input/result classes and exponent-difference ranges, and these are forced in: two
signalling NaN rows, each threshold and the value next to it (768, -768, 2045, 53, -1075), and rows where rounding
the fma first and then scaling gives a different result.
Another 6 random batches per kernel (384 hardware rows) also passed on RADV and lavapipe, outside the PR. As in #446,
denormal inputs and results are left out (lavapipe flushes f64 denormals).
no zero → NaN, VCC without the <= -768 case, neg ignored on div_scale; div_fmas as a plain fma, as an fma followed by ldexp
(double rounding), with the scale left out of the exact path, wrong direction threshold; div_fixup without NaN
quotient → inf, without quieting, without the invalid cases, underflow threshold off by one.
ctest: 151/152. The failure isagc_driver_pixel_helper_lanes(wave64 case) on thismachine's RADV, and it fails the same way on
mainwithout this change.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-03T17:40:13Z.
Progress report (
ebf29f8→063437c)📈 GPU shader instructions: 87.91% (+0.6%, +7 implemented instructions)
✅ 7 implemented
V_RCP_F64V_RSQ_F64V_SQRT_F64V_DIV_FIXUP_F64V_DIV_FMAS_F64V_DIV_SCALE_F64V_TRIG_PREOP_F64Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-04T10:07:42Z.
Rebased on current main: now carries the rebased #447 commit and both #264 commits (it had only the first one before, so the f32 NaN/s_denorm_mode fix of #264 is now included too), then this PR's commit. F64Division, F64DivisionModifiers, Division and F64Transcendental pass on RADV, local lavapipe and CI's lavapipe.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-04T20:36:25Z.
Rebased on current main: the only Windows failure was
guest_audio_in_no_device, fixed by #532. No other changes.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T23:09:20Z.
Thanks. I reviewed only the last commit (c7b0dd4); the #447 and #264 commits are patch-identical to those PRs, apart from context.
v_div_fixup_f64follows the ISA's priority order (numerator NaN, denominator NaN, 0/0 and inf/inf, x/0 and inf/y, x/inf and 0/y, underflow below -1075, then the sign-fixed quotient), plus the measured NaN quotient to inf rule. Taking NaNs and zeros on the bits avoids driver canonicalisation.v_div_scale_f64/v_div_fmas_f64mirror the f32 versions from #264 with the f64 thresholds you measured.negis kept on div_scale (VOP3B), and clamp/omod still throw.FusedMultiplyAddrefactor keeps plainv_fma_f64the same: with scale 0 the far branch now returnsc * 1.0instead of the rawcbits. That only differs for a denormalcon a driver that flushes f64 denormals, which the tests already leave out. The new [-2044, 2046] clamp only matters when the result overflows or underflows to zero anyway. The #446 f64 tests still pass with it.agc_driver_f64_divisionandagc_driver_f64_division_modifierspass on my machine at this head. On the commit below yours (#447 + #264 only) both fail with "VOP3 opcode is not implemented".What needs doing: #264 is merged now, so this branch conflicts with main in
RdnaOpcode.hpp,RdnaOpcode.cpp,RdnaVectorOpDecoder.cppandVectorInstructions.cpp. Once #447 is rebased and merged, could you rebase this onto main so only your commit is left? Also,supportsNativeVop3SourceModifiersclashes by one line with #498. None of my PPSA21564 shader dumps uses the f64 division ops, so it doesn't need a gate run.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T01:38:03Z.
Rebased on current main: #264's commits are now on main and dropped from this branch, which carries #447's rebased head plus the last commit (c7b0dd4 content unchanged apart from context: the f64 enum/classifier/VOP3 rows sit next to main's
v_div_*_f32ones).agc_driver_f64_division{,_modifiers}_testsandagc_driver_division_testspass on RADV and lavapipe, full ctest green on RADV apart from the knownagc_driver_pixel_helper_lanes.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T02:47:04Z.
Thanks, this now carries #447's rebased head (the same commit), and your own commit only changed in context.
One small overlap to know about: #563 changes the same line in
checkNativeVop3Modifiers(the clamp exception forv_mad_u64_u32/v_mad_i64_i32), so whichever of the two lands second needs a one-line rebase that keeps both exceptions:With that resolved,
agc_driver_f64_division,agc_driver_f64_division_modifiersandagc_driver_divisionpass here on the merged branch. PPSA21564 has no f64 division, so it doesn't need my PPSA21564 check. Ready to merge from my side after #447.