ei_psqrt fix for zero input

This commit is contained in:
Hauke Heibel 2010-04-01 15:10:52 +02:00
parent 1b3f7f2fee
commit 9d6afdeb22

View File

@ -370,7 +370,11 @@ static EIGEN_DONT_INLINE EIGEN_UNUSED Packet4f ei_pcos(Packet4f x)
static EIGEN_UNUSED Packet4f ei_psqrt(Packet4f _x) static EIGEN_UNUSED Packet4f ei_psqrt(Packet4f _x)
{ {
Packet4f half = ei_pmul(_x, ei_pset1(.5f)); Packet4f half = ei_pmul(_x, ei_pset1(.5f));
Packet4f x = _mm_rsqrt_ps(_x);
/* select only the inverse sqrt of non-zero inputs */
Packet4f non_zero_mask = _mm_cmpgt_ps(_x, ei_pset1(std::numeric_limits<float>::epsilon()));
Packet4f x = _mm_and_ps(non_zero_mask, _mm_rsqrt_ps(_x));
x = ei_pmul(x, ei_psub(ei_pset1(1.5f), ei_pmul(half, ei_pmul(x,x)))); x = ei_pmul(x, ei_psub(ei_pset1(1.5f), ei_pmul(half, ei_pmul(x,x))));
return ei_pmul(_x,x); return ei_pmul(_x,x);
} }