Repository navigation
feat(shader): implement v_div_scale_f64, v_div_fmas_f64 and v_div_fixup_f64 - #474
Conversation
cf54fa2 to
ca03ff7
Compare
|
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. |
ca03ff7 to
c7b0dd4
Compare
|
Rebased on current main: the only Windows failure was |
|
Thanks. I reviewed only the last commit (c7b0dd4); the #447 and #264 commits are patch-identical to those PRs, apart from context.
What needs doing: #264 is merged now, so this branch conflicts with main in |
Decode and translate the remaining unary f64 transcendentals and v_trig_preop_f64. On RDNA2 hardware v_rcp_f64, v_rsq_f64 and v_sqrt_f64 are approximations (relative error up to ~2^-24.3 over 8209 inputs; sqrt(1.0) is not even exact), so they are emitted as exact double operations and the test compares against the hardware value with a 2^-23 tolerance. Special cases are exact and selected on bits: NaN inputs are quieted (RADV keeps signaling NaN on FDiv), negative inputs give the default NaN 0xfff8000000000000, rsq(-0) = -inf, sqrt(-0) = -0. v_trig_preop_f64 matches the hardware bit for bit on 24627 results plus a sweep of the table tail: the 2/PI table is 1184 bits (bits below b17 read as zero), shift = 53 * S1[4:0] + max(exp - 1077, 0), +128 scale for exp >= 1968, omod ignored. The 53-bit window is read from a private u32 table and scaled in two exact steps so only the final multiply rounds. Stacked on the f64 infrastructure of boykopovar#446. Co-Authored-By: Claude <noreply@anthropic.com>
…up_f64 These make up the precise f64 division macro compilers emit for a / b. Like the f32 ops, the rules were measured on an RDNA2 GPU (41152 rows, model matches all of them): - div_scale decides from the exponent fields only: 2^128 or 2^-128 scaling and VCC for differences >= 768 or <= -768, a denormal or huge (>= 2045) denominator and a numerator exponent <= 53; a NaN source is passed through unchanged and a zero input gives 0xfff8000000000000. - div_fmas scales by 2^128 when the exponent of S2 is >= 1024, else 2^-128, before the single rounding, so it reuses the exact fma emulation with the scale folded into its final rescale. - div_fixup follows the ISA: NaN sources are quieted, a NaN quotient with finite inputs becomes +-inf, exponent differences below -1075 give a signed zero. Co-Authored-By: Claude <noreply@anthropic.com>
c7b0dd4 to
063437c
Compare
|
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 |
|
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 if ((clamp != 0u && !isVop3BMadU64Opcode(opcode)) || omod != 0u || (neg != 0u && !floatCompare && opcode != RdnaOpcode::VDivScaleF32 && opcode != RdnaOpcode::VDivScaleF64)) {With that resolved, |
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 (feat(shader): implement v_div_scale/fmas/fixup_f32 and s_denorm_mode (f32 division macro) #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
feat(shader): implement basic f64 VALU ops #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 feat(shader): implement basic f64 VALU ops #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)