From 5ec363a8a921be49fde3e85c354bce3d2b1c88d0 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Fri, 13 Jun 2014 15:05:52 +0200 Subject: [PATCH] SSE2: Don't divide by zero when normalizing --HG-- branch : sse2 --- code/nel/include/nel/misc/vector_inline.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/code/nel/include/nel/misc/vector_inline.h b/code/nel/include/nel/misc/vector_inline.h index 270608af0..77d827c35 100644 --- a/code/nel/include/nel/misc/vector_inline.h +++ b/code/nel/include/nel/misc/vector_inline.h @@ -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,7 +191,8 @@ inline void CVector::normalize() { #ifdef USE_SSE2 __m128 normsplat = _mm_sqrt_ps(dotsplat(mm, mm)); - mm = _mm_div_ps(mm, normsplat); + if (_mm_cvtss_f32(normsplat)) + mm = _mm_div_ps(mm, normsplat); #else float n=norm(); if(n) @@ -203,7 +204,8 @@ inline CVector CVector::normed() const #ifdef USE_SSE2 CVector res; __m128 normsplat = _mm_sqrt_ps(dotsplat(mm, mm)); - res.mm = _mm_div_ps(mm, normsplat); + if (_mm_cvtss_f32(normsplat)) + res.mm = _mm_div_ps(mm, normsplat); return res; #else CVector ret;