diff --git a/src/BulletCollision/CollisionShapes/btBoxShape.h b/src/BulletCollision/CollisionShapes/btBoxShape.h index bc42f146c..b1cf32f4c 100644 --- a/src/BulletCollision/CollisionShapes/btBoxShape.h +++ b/src/BulletCollision/CollisionShapes/btBoxShape.h @@ -37,15 +37,11 @@ public: virtual btVector3 localGetSupportingVertex(const btVector3& vec) const { - btVector3 halfExtents = getHalfExtents(); - btVector3 supVertex; - supVertex = btPoint3(vec.x() < btScalar(0.0) ? -halfExtents.x() : halfExtents.x(), - vec.y() < btScalar(0.0) ? -halfExtents.y() : halfExtents.y(), - vec.z() < btScalar(0.0) ? -halfExtents.z() : halfExtents.z()); - - return supVertex; + return btVector3(btFsels(vec.x(), halfExtents.x(), -halfExtents.x()), + btFsels(vec.y(), halfExtents.y(), -halfExtents.y()), + btFsels(vec.z(), halfExtents.z(), -halfExtents.z())); } virtual inline btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const @@ -54,9 +50,9 @@ public: btVector3 margin(getMargin(),getMargin(),getMargin()); halfExtents -= margin; - return btVector3(vec.x() < btScalar(0.0) ? -halfExtents.x() : halfExtents.x(), - vec.y() < btScalar(0.0) ? -halfExtents.y() : halfExtents.y(), - vec.z() < btScalar(0.0) ? -halfExtents.z() : halfExtents.z()); + return btVector3(btFsels(vec.x(), halfExtents.x(), -halfExtents.x()), + btFsels(vec.y(), halfExtents.y(), -halfExtents.y()), + btFsels(vec.z(), halfExtents.z(), -halfExtents.z())); } virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const @@ -69,9 +65,9 @@ public: for (int i=0;i m_x) - m_x = other.m_x; - - if (other.m_y > m_y) - m_y = other.m_y; - - if (other.m_z > m_z) - m_z = other.m_z; - - if (other.m_unusedW > m_unusedW) - m_unusedW = other.m_unusedW; + btSetMax(m_x, other.m_x); + btSetMax(m_y, other.m_y); + btSetMax(m_z, other.m_z); + btSetMax(m_unusedW, other.m_unusedW); } SIMD_FORCE_INLINE void setMin(const btQuadWord& other) { - if (other.m_x < m_x) - m_x = other.m_x; - - if (other.m_y < m_y) - m_y = other.m_y; - - if (other.m_z < m_z) - m_z = other.m_z; - - if (other.m_unusedW < m_unusedW) - m_unusedW = other.m_unusedW; + btSetMin(m_x, other.m_x); + btSetMin(m_y, other.m_y); + btSetMin(m_z, other.m_z); + btSetMin(m_unusedW, other.m_unusedW); } diff --git a/src/LinearMath/btScalar.h b/src/LinearMath/btScalar.h index 01ad93e78..5664dc89e 100644 --- a/src/LinearMath/btScalar.h +++ b/src/LinearMath/btScalar.h @@ -37,6 +37,10 @@ subject to the following restrictions: #define ATTRIBUTE_ALIGNED16(a) __declspec(align(16)) a #ifdef _XBOX #define BT_USE_VMX128 + + #include + #define BT_HAVE_NATIVE_FSEL + #define btFsel(a,b,c) __fsel((a),(b),(c)) #else #define BT_USE_SSE #endif @@ -177,5 +181,12 @@ SIMD_FORCE_INLINE btScalar btDegrees(btScalar x) { return x * SIMD_DEGS_PER_RAD; #define BT_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name +#ifndef btFsel +SIMD_FORCE_INLINE btScalar btFsel(btScalar a, btScalar b, btScalar c) +{ + return a >= 0 ? b : c; +} +#endif +#define btFsels(a,b,c) (btScalar)btFsel(a,b,c) #endif //SIMD___SCALAR_H diff --git a/src/LinearMath/btSimdMinMax.h b/src/LinearMath/btSimdMinMax.h index 75e83f3c5..a220aad54 100644 --- a/src/LinearMath/btSimdMinMax.h +++ b/src/LinearMath/btSimdMinMax.h @@ -38,4 +38,39 @@ SIMD_FORCE_INLINE void btSetMax(T& a, const T& b) { if (a < b) a = b; } +// Specialize on float/double for platforms that have btFsel natively +#ifdef BT_HAVE_NATIVE_FSEL +SIMD_FORCE_INLINE float btMin( float a, float b) { + return (float)btFsel((a-b), b, a); +} + +SIMD_FORCE_INLINE float btMax( float a, float b) { + return (float)btFsel((a-b), a, b); +} + +SIMD_FORCE_INLINE void btSetMin(float& a, float b) { + a = (float)btFsel((a-b), b, a); +} + +SIMD_FORCE_INLINE void btSetMax(float& a, float b) { + a = (float)btFsel((a-b), a, b); +} + +SIMD_FORCE_INLINE double btMin( double a, double b) { + return btFsel((a-b), b, a); +} + +SIMD_FORCE_INLINE double btMax( double a, double b) { + return btFsel((a-b), a, b); +} + +SIMD_FORCE_INLINE void btSetMin(double& a, double b) { + a = btFsel((a-b), b, a); +} + +SIMD_FORCE_INLINE void btSetMax(double& a, double b) { + a = btFsel((a-b), a, b); +} +#endif + #endif