From 6cf0ab5e99c27cb7b128e55991fbad5a7d234c8e Mon Sep 17 00:00:00 2001 From: Antonio Sanchez Date: Tue, 23 Feb 2021 19:48:46 -0800 Subject: Disable fast psqrt for NEON. Accuracy is too poor - requires at least two Newton iterations, but then it is no longer significantly faster than `vsqrt`. Fixes #2094. --- Eigen/src/Core/arch/NEON/PacketMath.h | 34 ---------------------------------- 1 file changed, 34 deletions(-) (limited to 'Eigen/src/Core/arch/NEON/PacketMath.h') diff --git a/Eigen/src/Core/arch/NEON/PacketMath.h b/Eigen/src/Core/arch/NEON/PacketMath.h index 2e06befc2..b2170e9f7 100644 --- a/Eigen/src/Core/arch/NEON/PacketMath.h +++ b/Eigen/src/Core/arch/NEON/PacketMath.h @@ -3297,42 +3297,8 @@ template<> EIGEN_STRONG_INLINE Packet4ui psqrt(const Packet4ui& a) { return res; } -#if EIGEN_FAST_MATH - -/* Functions for sqrt support packet2f/packet4f.*/ -// The EIGEN_FAST_MATH version uses the vrsqrte_f32 approximation and one step -// of Newton's method, at a cost of 1-2 bits of precision as opposed to the -// exact solution. It does not handle +inf, or denormalized numbers correctly. -// The main advantage of this approach is not just speed, but also the fact that -// it can be inlined and pipelined with other computations, further reducing its -// effective latency. This is similar to Quake3's fast inverse square root. -// For more details see: http://www.beyond3d.com/content/articles/8/ -template<> EIGEN_STRONG_INLINE Packet4f psqrt(const Packet4f& _x){ - Packet4ui denormal_mask = vandq_u32(vcgeq_f32(_x, vdupq_n_f32(0.0f)), - vcltq_f32(_x, pset1((std::numeric_limits::min)()))); - // Compute approximate reciprocal sqrt. - Packet4f x = vrsqrteq_f32(_x); - // Do one Newton's iteration for 1/sqrt(x). - x = vmulq_f32(vrsqrtsq_f32(vmulq_f32(_x, x), x), x); - // Flush results for denormals to zero. - return vreinterpretq_f32_u32(vbicq_u32(vreinterpretq_u32_f32(pmul(_x, x)), denormal_mask)); -} - -template<> EIGEN_STRONG_INLINE Packet2f psqrt(const Packet2f& _x) { - Packet2ui denormal_mask = vand_u32(vcge_f32(_x, vdup_n_f32(0.0f)), - vclt_f32(_x, pset1((std::numeric_limits::min)()))); - // Compute approximate reciprocal sqrt. - Packet2f x = vrsqrte_f32(_x); - // Do one Newton's iteration for 1/sqrt(x). - x = vmul_f32(vrsqrts_f32(vmul_f32(_x, x), x), x); - // Flush results for denormals to zero. - return vreinterpret_f32_u32(vbic_u32(vreinterpret_u32_f32(pmul(_x, x)), denormal_mask)); -} - -#else template<> EIGEN_STRONG_INLINE Packet4f psqrt(const Packet4f& _x){return vsqrtq_f32(_x);} template<> EIGEN_STRONG_INLINE Packet2f psqrt(const Packet2f& _x){return vsqrt_f32(_x); } -#endif //---------- bfloat16 ---------- // TODO: Add support for native armv8.6-a bfloat16_t -- cgit v1.2.3