Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- inline __m128 SSE_SIMDTestNormalizeFast( float * RESTRICT vOut, float * RESTRICT vIn )
- {
- // load as a SIMD vector
- const __m128 vec = _mm_loadu_ps(vIn);
- // compute a dot product by computing the square, and
- // then rotating the vector and adding, so that the
- // dot ends up in the low term (used by the scalar ops)
- __m128 dot = _mm_mul_ps( vec, vec );
- // rotate x under y and add together
- __m128 rotated = _mm_shuffle_ps( dot, dot, _MM_SHUFFLE( 0,3,2,1 ) ); // YZWX ( shuffle macro is high to low word )
- dot = _mm_add_ss( dot, rotated ); // x^2 + y^2 in the low word
- rotated = _mm_shuffle_ps( rotated, rotated, _MM_SHUFFLE( 0,3,2,1 ) ); // ZWXY
- dot = _mm_add_ss( dot, rotated ); // x^2 + y^2 + z^2 in the low word
- __m128 recipsqrt = SSERSqrtNR( dot ); // contains reciprocal square root in low term
- recipsqrt = _mm_shuffle_ps( recipsqrt, recipsqrt, _MM_SHUFFLE( 0, 0, 0, 0 ) ); // broadcast low term to all words
- // multiply 1/sqrt(dotproduct) against all vector components, and write back
- const __m128 normalized = _mm_mul_ps( vec, recipsqrt );
- _mm_storeu_ps(vOut, normalized);
- return _mm_mul_ss( dot , recipsqrt );
- }
Advertisement
Add Comment
Please, Sign In to add comment