mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-09-23 14:53:13 +08:00
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.
This commit is contained in:
parent
aba3998278
commit
6cf0ab5e99
@ -3297,42 +3297,8 @@ template<> EIGEN_STRONG_INLINE Packet4ui psqrt(const Packet4ui& a) {
|
|||||||
return res;
|
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<Packet4f>((std::numeric_limits<float>::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<Packet2f>((std::numeric_limits<float>::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 Packet4f psqrt(const Packet4f& _x){return vsqrtq_f32(_x);}
|
||||||
template<> EIGEN_STRONG_INLINE Packet2f psqrt(const Packet2f& _x){return vsqrt_f32(_x); }
|
template<> EIGEN_STRONG_INLINE Packet2f psqrt(const Packet2f& _x){return vsqrt_f32(_x); }
|
||||||
#endif
|
|
||||||
|
|
||||||
//---------- bfloat16 ----------
|
//---------- bfloat16 ----------
|
||||||
// TODO: Add support for native armv8.6-a bfloat16_t
|
// TODO: Add support for native armv8.6-a bfloat16_t
|
||||||
|
Loading…
x
Reference in New Issue
Block a user