Fix compile error in Visual Studio 2005 build: only enable SSE/SIMD intrinsics for btVector3 for Visual Studio 2008 and higher

This commit is contained in:
erwin.coumans
2012-12-07 18:16:04 +00:00
parent b4022e0f23
commit d54423f9c0
4 changed files with 35 additions and 27 deletions

View File

@@ -60,10 +60,10 @@ unsigned int btPolarDecomposition::decompose(const btMatrix3x3& a, btMatrix3x3&
break; break;
const btScalar gamma = btPow(h_norm / u_norm, 0.25f); const btScalar gamma = btPow(h_norm / u_norm, 0.25f);
const btScalar inv_gamma = 1.0 / gamma; const btScalar inv_gamma = btScalar(1.0) / gamma;
// Determine the delta to 'u' // Determine the delta to 'u'
const btMatrix3x3 delta = (u * (gamma - 2.0) + h.transpose() * inv_gamma) * 0.5; const btMatrix3x3 delta = (u * (gamma - btScalar(2.0)) + h.transpose() * inv_gamma) * btScalar(0.5);
// Update the matrices // Update the matrices
u += delta; u += delta;

View File

@@ -68,6 +68,10 @@ inline int btGetVersion()
#else #else
#if (defined (_WIN32) && (_MSC_VER) && _MSC_VER >= 1400) && (!defined (BT_USE_DOUBLE_PRECISION)) #if (defined (_WIN32) && (_MSC_VER) && _MSC_VER >= 1400) && (!defined (BT_USE_DOUBLE_PRECISION))
#if _MSC_VER>1400
#define BT_USE_SIMD_VECTOR3
#endif
#define BT_USE_SSE #define BT_USE_SSE
#ifdef BT_USE_SSE #ifdef BT_USE_SSE
//BT_USE_SSE_IN_API is disabled under Windows by default, because //BT_USE_SSE_IN_API is disabled under Windows by default, because
@@ -159,7 +163,8 @@ inline int btGetVersion()
#if (defined (__APPLE__) && (!defined (BT_USE_DOUBLE_PRECISION))) #if (defined (__APPLE__) && (!defined (BT_USE_DOUBLE_PRECISION)))
#if defined (__i386__) || defined (__x86_64__) #if defined (__i386__) || defined (__x86_64__)
#define BT_USE_SSE #define BT_USE_SIMD_VECTOR3
#define BT_USE_SSE
//BT_USE_SSE_IN_API is enabled on Mac OSX by default, because memory is automatically aligned on 16-byte boundaries //BT_USE_SSE_IN_API is enabled on Mac OSX by default, because memory is automatically aligned on 16-byte boundaries
//if apps run into issues, we will disable the next line //if apps run into issues, we will disable the next line
#define BT_USE_SSE_IN_API #define BT_USE_SSE_IN_API
@@ -178,7 +183,8 @@ inline int btGetVersion()
#elif defined( __armv7__ ) #elif defined( __armv7__ )
#ifdef __clang__ #ifdef __clang__
#define BT_USE_NEON 1 #define BT_USE_NEON 1
#define BT_USE_SIMD_VECTOR3
#if defined BT_USE_NEON && defined (__clang__) #if defined BT_USE_NEON && defined (__clang__)
#include <arm_neon.h> #include <arm_neon.h>
#endif//BT_USE_NEON #endif//BT_USE_NEON
@@ -264,7 +270,8 @@ typedef float btScalar;
typedef __m128 btSimdFloat4; typedef __m128 btSimdFloat4;
#endif//BT_USE_SSE #endif//BT_USE_SSE
#if defined BT_USE_SSE_IN_API && defined (BT_USE_SSE) #if defined (BT_USE_SSE)
//#if defined BT_USE_SSE_IN_API && defined (BT_USE_SSE)
#ifdef _WIN32 #ifdef _WIN32
#ifndef BT_NAN #ifndef BT_NAN

View File

@@ -19,10 +19,12 @@
#define BT_USE_SSE_IN_API #define BT_USE_SSE_IN_API
#endif #endif
#include "btVector3.h" #include "btVector3.h"
#if defined (BT_USE_SSE) || defined (BT_USE_NEON)
#if defined BT_USE_SIMD_VECTOR3
#ifdef __APPLE__ #ifdef __APPLE__
#include <stdint.h> #include <stdint.h>
typedef float float4 __attribute__ ((vector_size(16))); typedef float float4 __attribute__ ((vector_size(16)));

View File

@@ -229,7 +229,7 @@ public:
* @param v The other vector in the dot product */ * @param v The other vector in the dot product */
SIMD_FORCE_INLINE btScalar dot(const btVector3& v) const SIMD_FORCE_INLINE btScalar dot(const btVector3& v) const
{ {
#if defined(BT_USE_SSE_IN_API) && defined (BT_USE_SSE) #if defined BT_USE_SIMD_VECTOR3
__m128 vd = _mm_mul_ps(mVec128, v.mVec128); __m128 vd = _mm_mul_ps(mVec128, v.mVec128);
__m128 z = _mm_movehl_ps(vd, vd); __m128 z = _mm_movehl_ps(vd, vd);
__m128 y = _mm_shuffle_ps(vd, vd, 0x55); __m128 y = _mm_shuffle_ps(vd, vd, 0x55);
@@ -345,7 +345,8 @@ public:
/**@brief Return a vector will the absolute values of each element */ /**@brief Return a vector will the absolute values of each element */
SIMD_FORCE_INLINE btVector3 absolute() const SIMD_FORCE_INLINE btVector3 absolute() const
{ {
#if defined(BT_USE_SSE_IN_API) && defined (BT_USE_SSE)
#if defined BT_USE_SIMD_VECTOR3 && defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE)
return btVector3(_mm_and_ps(mVec128, btv3AbsfMask)); return btVector3(_mm_and_ps(mVec128, btv3AbsfMask));
#elif defined(BT_USE_NEON) #elif defined(BT_USE_NEON)
return btVector3(vabsq_f32(mVec128)); return btVector3(vabsq_f32(mVec128));
@@ -400,7 +401,7 @@ public:
SIMD_FORCE_INLINE btScalar triple(const btVector3& v1, const btVector3& v2) const SIMD_FORCE_INLINE btScalar triple(const btVector3& v1, const btVector3& v2) const
{ {
#if defined(BT_USE_SSE_IN_API) && defined (BT_USE_SSE) #if defined BT_USE_SIMD_VECTOR3 && defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE)
// cross: // cross:
__m128 T = _mm_shuffle_ps(v1.mVec128, v1.mVec128, BT_SHUFFLE(1, 2, 0, 3)); // (Y Z X 0) __m128 T = _mm_shuffle_ps(v1.mVec128, v1.mVec128, BT_SHUFFLE(1, 2, 0, 3)); // (Y Z X 0)
__m128 V = _mm_shuffle_ps(v2.mVec128, v2.mVec128, BT_SHUFFLE(1, 2, 0, 3)); // (Y Z X 0) __m128 V = _mm_shuffle_ps(v2.mVec128, v2.mVec128, BT_SHUFFLE(1, 2, 0, 3)); // (Y Z X 0)
@@ -632,7 +633,7 @@ public:
void getSkewSymmetricMatrix(btVector3* v0,btVector3* v1,btVector3* v2) const void getSkewSymmetricMatrix(btVector3* v0,btVector3* v1,btVector3* v2) const
{ {
#if defined(BT_USE_SSE_IN_API) && defined (BT_USE_SSE) #if defined BT_USE_SIMD_VECTOR3 && defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE)
__m128 V = _mm_and_ps(mVec128, btvFFF0fMask); __m128 V = _mm_and_ps(mVec128, btvFFF0fMask);
__m128 V0 = _mm_xor_ps(btvMzeroMask, V); __m128 V0 = _mm_xor_ps(btvMzeroMask, V);
@@ -702,7 +703,7 @@ public:
/* create a vector as btVector3( this->dot( btVector3 v0 ), this->dot( btVector3 v1), this->dot( btVector3 v2 )) */ /* create a vector as btVector3( this->dot( btVector3 v0 ), this->dot( btVector3 v1), this->dot( btVector3 v2 )) */
SIMD_FORCE_INLINE btVector3 dot3( const btVector3 &v0, const btVector3 &v1, const btVector3 &v2 ) const SIMD_FORCE_INLINE btVector3 dot3( const btVector3 &v0, const btVector3 &v1, const btVector3 &v2 ) const
{ {
#if defined(BT_USE_SSE_IN_API) && defined (BT_USE_SSE) #if defined BT_USE_SIMD_VECTOR3 && defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE)
__m128 a0 = _mm_mul_ps( v0.mVec128, this->mVec128 ); __m128 a0 = _mm_mul_ps( v0.mVec128, this->mVec128 );
__m128 a1 = _mm_mul_ps( v1.mVec128, this->mVec128 ); __m128 a1 = _mm_mul_ps( v1.mVec128, this->mVec128 );
@@ -768,7 +769,7 @@ operator*(const btVector3& v1, const btVector3& v2)
SIMD_FORCE_INLINE btVector3 SIMD_FORCE_INLINE btVector3
operator-(const btVector3& v1, const btVector3& v2) operator-(const btVector3& v1, const btVector3& v2)
{ {
#if (defined(BT_USE_SSE_IN_API) && defined(BT_USE_SSE)) #if defined BT_USE_SIMD_VECTOR3 && (defined(BT_USE_SSE_IN_API) && defined(BT_USE_SSE))
// without _mm_and_ps this code causes slowdown in Concave moving // without _mm_and_ps this code causes slowdown in Concave moving
__m128 r = _mm_sub_ps(v1.mVec128, v2.mVec128); __m128 r = _mm_sub_ps(v1.mVec128, v2.mVec128);
@@ -788,7 +789,7 @@ operator-(const btVector3& v1, const btVector3& v2)
SIMD_FORCE_INLINE btVector3 SIMD_FORCE_INLINE btVector3
operator-(const btVector3& v) operator-(const btVector3& v)
{ {
#if (defined(BT_USE_SSE_IN_API) && defined (BT_USE_SSE)) #if defined BT_USE_SIMD_VECTOR3 && (defined(BT_USE_SSE_IN_API) && defined (BT_USE_SSE))
__m128 r = _mm_xor_ps(v.mVec128, btvMzeroMask); __m128 r = _mm_xor_ps(v.mVec128, btvMzeroMask);
return btVector3(_mm_and_ps(r, btvFFF0fMask)); return btVector3(_mm_and_ps(r, btvFFF0fMask));
#elif defined(BT_USE_NEON) #elif defined(BT_USE_NEON)
@@ -842,7 +843,7 @@ operator/(const btVector3& v, const btScalar& s)
SIMD_FORCE_INLINE btVector3 SIMD_FORCE_INLINE btVector3
operator/(const btVector3& v1, const btVector3& v2) operator/(const btVector3& v1, const btVector3& v2)
{ {
#if (defined(BT_USE_SSE_IN_API)&& defined (BT_USE_SSE)) #if defined BT_USE_SIMD_VECTOR3 && (defined(BT_USE_SSE_IN_API)&& defined (BT_USE_SSE))
__m128 vec = _mm_div_ps(v1.mVec128, v2.mVec128); __m128 vec = _mm_div_ps(v1.mVec128, v2.mVec128);
vec = _mm_and_ps(vec, btvFFF0fMask); vec = _mm_and_ps(vec, btvFFF0fMask);
return btVector3(vec); return btVector3(vec);
@@ -948,7 +949,7 @@ SIMD_FORCE_INLINE btVector3 btVector3::rotate( const btVector3& wAxis, const btS
{ {
// wAxis must be a unit lenght vector // wAxis must be a unit lenght vector
#if defined(BT_USE_SSE_IN_API) && defined (BT_USE_SSE) #if defined BT_USE_SIMD_VECTOR3 && defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE)
__m128 O = _mm_mul_ps(wAxis.mVec128, mVec128); __m128 O = _mm_mul_ps(wAxis.mVec128, mVec128);
btScalar ssin = btSin( _angle ); btScalar ssin = btSin( _angle );
@@ -988,7 +989,7 @@ SIMD_FORCE_INLINE btVector3 btVector3::rotate( const btVector3& wAxis, const btS
SIMD_FORCE_INLINE long btVector3::maxDot( const btVector3 *array, long array_count, btScalar &dotOut ) const SIMD_FORCE_INLINE long btVector3::maxDot( const btVector3 *array, long array_count, btScalar &dotOut ) const
{ {
#if defined (BT_USE_SSE) || defined (BT_USE_NEON) #if defined BT_USE_SIMD_VECTOR3
#if defined _WIN32 || defined (BT_USE_SSE) #if defined _WIN32 || defined (BT_USE_SSE)
const long scalar_cutoff = 10; const long scalar_cutoff = 10;
long _maxdot_large( const float *array, const float *vec, unsigned long array_count, float *dotOut ); long _maxdot_large( const float *array, const float *vec, unsigned long array_count, float *dotOut );
@@ -996,10 +997,8 @@ SIMD_FORCE_INLINE long btVector3::maxDot( const btVector3 *array, long arra
const long scalar_cutoff = 4; const long scalar_cutoff = 4;
extern long (*_maxdot_large)( const float *array, const float *vec, unsigned long array_count, float *dotOut ); extern long (*_maxdot_large)( const float *array, const float *vec, unsigned long array_count, float *dotOut );
#endif #endif
if( array_count < scalar_cutoff ) if( array_count < scalar_cutoff )
#else #endif//BT_USE_SIMD_VECTOR3
#endif//BT_USE_SSE || BT_USE_NEON
{ {
btScalar maxDot = -SIMD_INFINITY; btScalar maxDot = -SIMD_INFINITY;
int i = 0; int i = 0;
@@ -1018,14 +1017,14 @@ SIMD_FORCE_INLINE long btVector3::maxDot( const btVector3 *array, long arra
dotOut = maxDot; dotOut = maxDot;
return ptIndex; return ptIndex;
} }
#if defined (BT_USE_SSE) || defined (BT_USE_NEON) #if defined BT_USE_SIMD_VECTOR3
return _maxdot_large( (float*) array, (float*) &m_floats[0], array_count, &dotOut ); return _maxdot_large( (float*) array, (float*) &m_floats[0], array_count, &dotOut );
#endif #endif//BT_USE_SIMD_VECTOR3
} }
SIMD_FORCE_INLINE long btVector3::minDot( const btVector3 *array, long array_count, btScalar &dotOut ) const SIMD_FORCE_INLINE long btVector3::minDot( const btVector3 *array, long array_count, btScalar &dotOut ) const
{ {
#if defined (BT_USE_SSE) || defined (BT_USE_NEON) #if defined BT_USE_SIMD_VECTOR3
#if defined BT_USE_SSE #if defined BT_USE_SSE
const long scalar_cutoff = 10; const long scalar_cutoff = 10;
long _mindot_large( const float *array, const float *vec, unsigned long array_count, float *dotOut ); long _mindot_large( const float *array, const float *vec, unsigned long array_count, float *dotOut );
@@ -1037,7 +1036,7 @@ SIMD_FORCE_INLINE long btVector3::minDot( const btVector3 *array, long arra
#endif #endif
if( array_count < scalar_cutoff ) if( array_count < scalar_cutoff )
#endif//BT_USE_SSE || BT_USE_NEON #endif//BT_USE_SIMD_VECTOR3
{ {
btScalar minDot = SIMD_INFINITY; btScalar minDot = SIMD_INFINITY;
int i = 0; int i = 0;
@@ -1058,9 +1057,9 @@ SIMD_FORCE_INLINE long btVector3::minDot( const btVector3 *array, long arra
return ptIndex; return ptIndex;
} }
#if defined (BT_USE_SSE) || defined (BT_USE_NEON) #if defined BT_USE_SIMD_VECTOR3
return _mindot_large( (float*) array, (float*) &m_floats[0], array_count, &dotOut ); return _mindot_large( (float*) array, (float*) &m_floats[0], array_count, &dotOut );
#endif #endif//BT_USE_SIMD_VECTOR3
} }
@@ -1098,7 +1097,7 @@ public:
SIMD_FORCE_INLINE btVector4 absolute4() const SIMD_FORCE_INLINE btVector4 absolute4() const
{ {
#if defined(BT_USE_SSE_IN_API) && defined (BT_USE_SSE) #if defined BT_USE_SIMD_VECTOR3 && defined(BT_USE_SSE_IN_API) && defined (BT_USE_SSE)
return btVector4(_mm_and_ps(mVec128, btvAbsfMask)); return btVector4(_mm_and_ps(mVec128, btvAbsfMask));
#elif defined(BT_USE_NEON) #elif defined(BT_USE_NEON)
return btVector4(vabsq_f32(mVec128)); return btVector4(vabsq_f32(mVec128));