Skip to content

Commit cc3592e

Browse files
committed
SSE transform math: remove 2 unnecessary mask ops
In 2 cases we were forming a vector from (a.xyz, b.w) but it turns out the "junk" w component of a already contained the desired b.w value, so we can just use a is-is.
1 parent a324945 commit cc3592e

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/engine/qcommon/q_shared.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,8 @@ inline vec_t VectorNormalize2( const vec3_t v, vec3_t out )
12041204
__m128 sum2 = _mm_add_ps( sum1, sseSwizzle( sum1, ZWXY ) );
12051205
return sum2;
12061206
}
1207+
1208+
// returns 0 in w component if input w's are finite
12071209
inline __m128 sseCrossProduct( __m128 a, __m128 b ) {
12081210
__m128 a_yzx = sseSwizzle( a, YZXW );
12091211
__m128 b_yzx = sseSwizzle( b, YZXW );
@@ -1239,6 +1241,7 @@ inline vec_t VectorNormalize2( const vec3_t v, vec3_t out )
12391241
t = _mm_mul_ps( h, t );
12401242
return _mm_mul_ps( q, t );
12411243
}
1244+
// rotates (3-dimensional) vec. vec's w component is unchanged
12421245
inline __m128 sseQuatTransform( __m128 q, __m128 vec ) {
12431246
__m128 t, t2;
12441247
t = sseCrossProduct( q, vec );
@@ -1303,10 +1306,8 @@ inline vec_t VectorNormalize2( const vec3_t v, vec3_t out )
13031306
}
13041307
inline void TransAddRotationQuat( const quat_t quat, transform_t *t ) {
13051308
__m128 q = _mm_loadu_ps( quat );
1306-
__m128 transformed = sseQuatTransform( q, t->sseTransScale );
13071309
t->sseRot = sseQuatMul( q, t->sseRot );
1308-
t->sseTransScale = _mm_or_ps( _mm_and_ps( transformed, mask_XYZ0() ),
1309-
_mm_and_ps( t->sseTransScale, mask_000W() ) );
1310+
t->sseTransScale = sseQuatTransform( q, t->sseTransScale );
13101311
}
13111312
inline void TransInsScale( float factor, transform_t *t ) {
13121313
t->scale *= factor;
@@ -1337,8 +1338,6 @@ inline vec_t VectorNormalize2( const vec3_t v, vec3_t out )
13371338
__m128 bRot = b->sseRot;
13381339
__m128 bTS = b->sseTransScale;
13391340
__m128 tmp = sseQuatTransform( bRot, aTS );
1340-
tmp = _mm_or_ps( _mm_and_ps( tmp, mask_XYZ0() ),
1341-
_mm_and_ps( aTS, mask_000W() ) );
13421341
tmp = _mm_mul_ps( tmp, sseSwizzle( bTS, WWWW ) );
13431342
out->sseTransScale = _mm_add_ps( tmp, _mm_and_ps( bTS, mask_XYZ0() ) );
13441343
out->sseRot = sseQuatMul( bRot, aRot );

0 commit comments

Comments
 (0)