feat(shader): implement v_rcp/rsq/sqrt_f64 and v_trig_preop_f64 #447
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/447"
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-03T08:07:28Z.
What
The rest of the unary f64 VALU ops threw "opcode not implemented". Found by the ISA coverage sweep:
v_rcp_f64,v_rsq_f64,v_sqrt_f64.v_trig_preop_f64.Builds on the f64 IR/backend infrastructure of #446 (merged). The
v_div_scale/fmas/fixup_f64ops are left for a later PR because they share structure with #264.Behaviour measured on RDNA2 hardware (Radeon 660M, 8209 inputs, Python model first, then the C++):
v_rcp_f64,v_rsq_f64andv_sqrt_f64are approximations on hardware: relative error up to ~2^-24.3, andsqrt(1.0)returns0x3ff0000004000000. Real code refines them with Newton steps, so they are emitted as exactdouble ops (
1/x,Sqrt,1/Sqrt) and the test compares normal results with a 2^-23 tolerance.FDiv), any negative input to rsq/sqrt (incl. -inf) gives the default NaN0xfff8000000000000,rcp(±0) = ±inf,rcp(±inf) = ±0,rsq(±0) = ±inf,rsq(+inf) = +0,sqrt(-0) = -0.v_trig_preop_f64matches the hardware bit for bit (24627 results + a sweep over the end of the table):shift = 53 * S1[4:0] + max(exp(S0) - 1077, 0), result = 53-bit window of 2/π at that shift scaled by2^(-53 - shift), +128 when
exp(S0) >= 1968. The hardware table is 1184 bits: bits below b17 of the 1201-bitvalue in the ISA doc read as zero (only visible in denormal results). omod is ignored, like every f64 op (#446).
u32[40]table and scaled in two exact steps, so only the last multiply rounds.Tested
F64Transcendental, 32 lanes with expected values captured on hardware: rcp, rsq, sqrt,trig_preop with a VGPR / inline S1 and with abs/neg + omod, rcp with clamp, sqrt of
-|x|. Rows were pickedgreedily to cover input/result classes, exponent ranges (>1077, >=1968) and two forced signalling NaN rows.
outside the PR. As in #446, denormal inputs and results are left out (lavapipe flushes f64 denormals).
unsigned zero in rsq, no +128 for large exponents, no exponent shift, wrong low word, no aligned-shift case.
ctest: 147/148. 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-03T08:07:53Z.
Progress report (
ebf29f8→4f901b9)📈 GPU shader instructions: 87.65% (+0.34%, +4 implemented instructions)
✅ 4 implemented
V_RCP_F64V_RSQ_F64V_SQRT_F64V_TRIG_PREOP_F64Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-04T10:05:12Z.
Rebased on current main now that #446 is merged: the branch is a single commit on top of main (no conflicts in it). F64Transcendental passes on RADV, local lavapipe and CI's lavapipe (Mesa 25.2.8). Description no longer says stacked.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T23:09:18Z.
Thanks. I went through this against the ISA and it checks out:
v_rcp_f64,v_rsq_f64andv_sqrt_f64as VOP1 0x2f, 0x31 and 0x34, andv_trig_preop_f64as VOP3 0x174, as in the tables.TwoOverPitable: I computed 2/pi independently (Machin, integer arithmetic) and the first 37 words match, with zeros after that, which is your 1184-bit hardware table.v_trig_preop_f64: a Python model of the ISA formula (shift = 53 * S1[4:0] + max(exp - 1077, 0), a 53-bit window of 2/pi, scale 2^(-53 - shift), +128 when exp >= 1968) reproduces all 96 trig_preop cells of the test, including the inline-S1 and-|x| mul:2columns (omod ignored). The two-step exact scaling leaves one rounding, as you say.rsq(-0) = -inf,sqrt(-0) = -0,rsq(+inf) = +0. The 2^-23 tolerance on normal results is reasonable for an approximate op, and emitting exact doubles is fine since real code refines them anyway.agc_driver_f64_transcendentalpasses on my machine (in a batch with this PR's commit); with only the test file on main's code it fails with "VOP1 opcode is not implemented".One thing before it can go in: #264 was just merged, and this branch now conflicts with main in
RdnaOpcode.hpp,RdnaOpcode.cppandRdnaVectorOpDecoder.cpp(both add opcodes at the same spots). It also has a one-line clash with #498 insupportsNativeVop3SourceModifiers(keep bothVLdexpF16andVTrigPreopF64). Could you rebase it? After that it's good to merge from my side. None of my PPSA21564 shader dumps uses these four ops.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T01:37:00Z.
Rebased on current main (after #264): the conflicts were adjacent enum, classifier and VOP3 table lines next to the
v_div_*_f32ones, kept both sides. Commit otherwise unchanged;agc_driver_f64_transcendental_testspasses 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:03Z.
Thanks, the rebase only moves the enum, classifier and VOP3 rows next to main's
v_div_*_f32ones; the code is the same as before.agc_driver_f64_transcendentalpasses here on the merged branch. PPSA21564 has no f64 transcendentals, so this doesn't need my PPSA21564 check. Ready to merge from my side.