diff options
author | Graham Madarasz <graham@lindenlab.com> | 2013-06-12 09:16:19 -0700 |
---|---|---|
committer | Graham Madarasz <graham@lindenlab.com> | 2013-06-12 09:16:19 -0700 |
commit | d2b253f1f6072beead770519849ad3b18a1a4359 (patch) | |
tree | c50dcc7ea602746d156e24a9127721a95f640007 /indra/llmath/llvector4a.inl | |
parent | 48324a93833cee8aca7559588ee5f2b4afa250fa (diff) |
Changes to protect against use of normalize3fast on degenerate vectors
Diffstat (limited to 'indra/llmath/llvector4a.inl')
-rwxr-xr-x | indra/llmath/llvector4a.inl | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/indra/llmath/llvector4a.inl b/indra/llmath/llvector4a.inl index 4589bac9fb..6860252a75 100755 --- a/indra/llmath/llvector4a.inl +++ b/indra/llmath/llvector4a.inl @@ -410,8 +410,26 @@ inline LLSimdScalar LLVector4a::normalize3withLength() // Note that this does not consider zero length vectors! inline void LLVector4a::normalize3fast() { - // find out about bad math before it takes two man-days to track down - llassert(isFinite3() && !equals3(getZero())); + LLVector4a lenSqrd; lenSqrd.setAllDot3( *this, *this ); + const LLQuad approxRsqrt = _mm_rsqrt_ps(lenSqrd.mQ); + mQ = _mm_mul_ps( mQ, approxRsqrt ); +} + +// Normalize this vector with respect to the x, y, and z components only. Accurate only to 10-12 bits of precision. W component is destroyed +// Note that this does not consider zero length vectors! +inline void LLVector4a::normalize3fast_checked(LLVector4a* default) +{ + // handle bogus inputs before NaNs are generated below + // + if (!isFinite3() || (dot3(*this).getF32() < F_APPROXIMATELY_ZERO)) + { + if (default) + *this = *default; + else + set(0,1,0,1); + + return; + } LLVector4a lenSqrd; lenSqrd.setAllDot3( *this, *this ); const LLQuad approxRsqrt = _mm_rsqrt_ps(lenSqrd.mQ); |