SSE2: Don't divide by zero when normalizing

--HG--
branch : sse2
hg/feature/sse2
kaetemi 11 years ago
parent 7867db4654
commit 5ec363a8a9

@ -182,7 +182,7 @@ inline float CVector::sqrnorm() const
inline float CVector::norm() const
{
#ifdef USE_SSE2
return sqrt(_mm_cvtss_f32(dotsplat(mm, mm)));
return sqrt(sqrnorm());
#else
return (float)sqrt(x*x + y*y + z*z);
#endif
@ -191,6 +191,7 @@ inline void CVector::normalize()
{
#ifdef USE_SSE2
__m128 normsplat = _mm_sqrt_ps(dotsplat(mm, mm));
if (_mm_cvtss_f32(normsplat))
mm = _mm_div_ps(mm, normsplat);
#else
float n=norm();
@ -203,6 +204,7 @@ inline CVector CVector::normed() const
#ifdef USE_SSE2
CVector res;
__m128 normsplat = _mm_sqrt_ps(dotsplat(mm, mm));
if (_mm_cvtss_f32(normsplat))
res.mm = _mm_div_ps(mm, normsplat);
return res;
#else

Loading…
Cancel
Save