28#define BT_BULLET_VERSION 287
48 #define BT_NOT_EMPTY_FILE_CAT_II(p, res) res
49 #define BT_NOT_EMPTY_FILE_CAT_I(a, b) BT_NOT_EMPTY_FILE_CAT_II(~, a ## b)
50 #define BT_NOT_EMPTY_FILE_CAT(a, b) BT_NOT_EMPTY_FILE_CAT_I(a, b)
51 #define BT_NOT_EMPTY_FILE namespace { char BT_NOT_EMPTY_FILE_CAT(NoEmptyFileDummy, __COUNTER__); }
53 #define BT_NOT_EMPTY_FILE
59#if defined(DEBUG) || defined (_DEBUG)
64 #if defined(__MINGW32__) || defined(__CYGWIN__) || (defined (_MSC_VER) && _MSC_VER < 1300)
65 #define SIMD_FORCE_INLINE inline
66 #define ATTRIBUTE_ALIGNED16(a) a
67 #define ATTRIBUTE_ALIGNED64(a) a
68 #define ATTRIBUTE_ALIGNED128(a) a
70 #define SIMD_FORCE_INLINE __forceinline
71 #define ATTRIBUTE_ALIGNED16(a) __declspec() a
72 #define ATTRIBUTE_ALIGNED64(a) __declspec() a
73 #define ATTRIBUTE_ALIGNED128(a) __declspec () a
76 #pragma warning(disable : 4324)
78 #pragma warning(disable:4996)
81 #define SIMD_FORCE_INLINE __forceinline
82 #define ATTRIBUTE_ALIGNED16(a) __declspec(align(16)) a
83 #define ATTRIBUTE_ALIGNED64(a) __declspec(align(64)) a
84 #define ATTRIBUTE_ALIGNED128(a) __declspec (align(128)) a
88 #include <ppcintrinsics.h>
89 #define BT_HAVE_NATIVE_FSEL
90 #define btFsel(a,b,c) __fsel((a),(b),(c))
95#elif (defined (_WIN32) && (_MSC_VER) && _MSC_VER >= 1400) && (!defined (BT_USE_DOUBLE_PRECISION))
97 #define BT_USE_SIMD_VECTOR3
103#if (_MSC_FULL_VER >= 170050727)
104 #define BT_ALLOW_SSE4
115 #include <emmintrin.h>
125 #define btAssert(x) { if(!(x)){printf("Assert "__FILE__ ":%u (%s)\n", __LINE__, #x);__debugbreak(); }}
128 #define btAssert assert
134 #define btFullAssert(x)
136 #define btLikely(_c) _c
137 #define btUnlikely(_c) _c
141 #if defined (__CELLOS_LV2__)
142 #define SIMD_FORCE_INLINE inline __attribute__((always_inline))
143 #define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16)))
144 #define ATTRIBUTE_ALIGNED64(a) a __attribute__ ((aligned (64)))
145 #define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128)))
151 #include <spu_printf.h>
152 #define printf spu_printf
153 #define btAssert(x) {if(!(x)){printf("Assert "__FILE__ ":%u ("#x")\n", __LINE__);spu_hcmpeq(0,0);}}
155 #define btAssert assert
162 #define btFullAssert(x)
164 #define btLikely(_c) _c
165 #define btUnlikely(_c) _c
171 #define SIMD_FORCE_INLINE __inline
172 #define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16)))
173 #define ATTRIBUTE_ALIGNED64(a) a __attribute__ ((aligned (64)))
174 #define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128)))
179 #define btAssert assert
184 #define btFullAssert(x)
187 #define btLikely(_c) __builtin_expect((_c), 1)
188 #define btUnlikely(_c) __builtin_expect((_c), 0)
194 #if (defined (__APPLE__) && (!defined (BT_USE_DOUBLE_PRECISION)))
195 #if defined (__i386__) || defined (__x86_64__)
196 #define BT_USE_SIMD_VECTOR3
200 #define BT_USE_SSE_IN_API
203 #if defined (__SSE4_1__)
204 #include <smmintrin.h>
205 #elif defined (__SSSE3__)
206 #include <tmmintrin.h>
207 #elif defined (__SSE3__)
208 #include <pmmintrin.h>
210 #include <emmintrin.h>
213 #elif defined( __ARM_NEON__ )
215 #define BT_USE_NEON 1
216 #define BT_USE_SIMD_VECTOR3
218 #if defined BT_USE_NEON && defined (__clang__)
219 #include <arm_neon.h>
224 #define SIMD_FORCE_INLINE inline __attribute__ ((always_inline))
226 #define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16)))
227 #define ATTRIBUTE_ALIGNED64(a) a __attribute__ ((aligned (64)))
228 #define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128)))
233 #if defined(DEBUG) || defined (_DEBUG)
234 #if defined (__i386__) || defined (__x86_64__)
240 printf("Assert %s in line %d, file %s\n",#x, __LINE__, __FILE__);\
241 asm volatile ("int3");\
245 #define btAssert assert
252 #define btFullAssert(x)
253 #define btLikely(_c) _c
254 #define btUnlikely(_c) _c
258 #define SIMD_FORCE_INLINE inline
263 #define ATTRIBUTE_ALIGNED16(a) a
264 #define ATTRIBUTE_ALIGNED64(a) a
265 #define ATTRIBUTE_ALIGNED128(a) a
270 #if defined(DEBUG) || defined (_DEBUG)
271 #define btAssert assert
277 #define btFullAssert(x)
278 #define btLikely(_c) _c
279 #define btUnlikely(_c) _c
287#if defined(BT_USE_DOUBLE_PRECISION)
290 #define BT_LARGE_FLOAT 1e30
294 #define BT_LARGE_FLOAT 1e18f
298 typedef __m128 btSimdFloat4;
301#if defined(BT_USE_SSE)
306 static int btNanMask = 0x7F800001;
307 #define BT_NAN (*(float *)&btNanMask)
312 #define BT_INFINITY (*(float *)&btInfinityMask)
322 #ifndef BT_NO_SIMD_OPERATOR_OVERLOADS
323 inline __m128
operator+(
const __m128 A,
const __m128 B)
325 return _mm_add_ps(A, B);
328 inline __m128
operator-(
const __m128 A,
const __m128 B)
330 return _mm_sub_ps(A, B);
333 inline __m128
operator*(
const __m128 A,
const __m128 B)
335 return _mm_mul_ps(A, B);
339 #define btCastfTo128i(a) (_mm_castps_si128(a))
340 #define btCastfTo128d(a) (_mm_castps_pd(a))
341 #define btCastiTo128f(a) (_mm_castsi128_ps(a))
342 #define btCastdTo128f(a) (_mm_castpd_ps(a))
343 #define btCastdTo128i(a) (_mm_castpd_si128(a))
344 #define btAssign128(r0, r1, r2, r3) _mm_setr_ps(r0, r1, r2, r3)
348 #define btCastfTo128i(a) ((__m128i)(a))
349 #define btCastfTo128d(a) ((__m128d)(a))
350 #define btCastiTo128f(a) ((__m128)(a))
351 #define btCastdTo128f(a) ((__m128)(a))
352 #define btCastdTo128i(a) ((__m128i)(a))
353 #define btAssign128(r0, r1, r2, r3) \
354 (__m128) { r0, r1, r2, r3 }
355 #define BT_INFINITY INFINITY
361 #include <arm_neon.h>
363 typedef float32x4_t btSimdFloat4;
364 #define BT_INFINITY INFINITY
366 #define btAssign128(r0, r1, r2, r3) \
367 (float32x4_t) { r0, r1, r2, r3 }
383 #define BT_INFINITY (btInfinityMask.mask)
394 #include <arm_neon.h>
396 typedef float32x4_t btSimdFloat4;
397 #define BT_INFINITY INFINITY
399 #define btAssign128(r0, r1, r2, r3) \
400 (float32x4_t) { r0, r1, r2, r3 }
403#define BT_DECLARE_ALIGNED_ALLOCATOR() \
404 SIMD_FORCE_INLINE void *operator new(size_t sizeInBytes) { return btAlignedAlloc(sizeInBytes, 16); } \
405 SIMD_FORCE_INLINE void operator delete(void *ptr) { btAlignedFree(ptr); } \
406 SIMD_FORCE_INLINE void *operator new(size_t, void *ptr) { return ptr; } \
407 SIMD_FORCE_INLINE void operator delete(void *, void *) {} \
408 SIMD_FORCE_INLINE void *operator new[](size_t sizeInBytes) { return btAlignedAlloc(sizeInBytes, 16); } \
409 SIMD_FORCE_INLINE void operator delete[](void *ptr) { btAlignedFree(ptr); } \
410 SIMD_FORCE_INLINE void *operator new[](size_t, void *ptr) { return ptr; } \
411 SIMD_FORCE_INLINE void operator delete[](void *, void *) {}
413#if defined(BT_USE_DOUBLE_PRECISION) || defined(BT_FORCE_DOUBLE_FUNCTIONS)
446 #ifdef USE_APPROXIMATION
448 float xhalf = 0.5f * y;
450 i = 0x5f375a86 - (i >> 1);
452 y = y * (1.5f - xhalf * y * y);
453 y = y * (1.5f - xhalf * y * y);
454 y = y * (1.5f - xhalf * y * y);
459 unsigned long *tfptr = ((
unsigned long *)&tempf) + 1;
461 *tfptr = (0xbfcdd90a - *tfptr) >> 1;
464 x = (
btScalar(1.5) * x) - (x * x) * (x * z);
465 x = (
btScalar(1.5) * x) - (x * x) * (x * z);
466 x = (
btScalar(1.5) * x) - (x * x) * (x * z);
467 x = (
btScalar(1.5) * x) - (x * x) * (x * z);
468 x = (
btScalar(1.5) * x) - (x * x) * (x * z);
504#define SIMD_PI btScalar(3.1415926535897932384626433832795029)
505#define SIMD_2_PI (btScalar(2.0) * SIMD_PI)
506#define SIMD_HALF_PI (SIMD_PI * btScalar(0.5))
507#define SIMD_RADS_PER_DEG (SIMD_2_PI / btScalar(360.0))
508#define SIMD_DEGS_PER_RAD (btScalar(360.0) / SIMD_2_PI)
509#define SIMDSQRT12 btScalar(0.7071067811865475244008443621048490)
510#define btRecipSqrt(x) ((btScalar)(btScalar(1.0) / btSqrt(btScalar(x))))
511#define btRecip(x) (btScalar(1.0) / btScalar(x))
513#ifdef BT_USE_DOUBLE_PRECISION
514 #define SIMD_EPSILON DBL_EPSILON
515 #define SIMD_INFINITY DBL_MAX
521 #define SIMD_EPSILON FLT_EPSILON
522 #define SIMD_INFINITY FLT_MAX
539 btScalar r = (x - abs_y) / (x + abs_y);
540 angle = coeff_1 - coeff_1 * r;
544 btScalar r = (x + abs_y) / (abs_y - x);
545 angle = coeff_2 - coeff_1 * r;
547 return (y < 0.0f) ? -angle : angle;
554 return (((a) <= eps) && !((a) < -eps));
558 return (!((a) <= eps));
569#define BT_DECLARE_HANDLE(name) \
570 typedef struct name##__ \
578 return a >= 0 ? b : c;
581#define btFsels(a, b, c) (btScalar) btFsel(a, b, c)
586 const char *p = (
const char *)&i;
601 unsigned testNz = (unsigned)(((
int)condition | -(
int)condition) >> 31);
602 unsigned testEqz = ~testNz;
603 return ((valueIfConditionNonZero & testNz) | (valueIfConditionZero & testEqz));
607 unsigned testNz = (unsigned)(((
int)condition | -(
int)condition) >> 31);
608 unsigned testEqz = ~testNz;
609 return static_cast<int>((valueIfConditionNonZero & testNz) | (valueIfConditionZero & testEqz));
613#ifdef BT_HAVE_NATIVE_FSEL
614 return (
float)
btFsel((
btScalar)condition -
btScalar(1.0f), valueIfConditionNonZero, valueIfConditionZero);
616 return (condition != 0) ? valueIfConditionNonZero : valueIfConditionZero;
631 return (((val & 0xff000000) >> 24) | ((val & 0x00ff0000) >> 8) | ((val & 0x0000ff00) << 8) | ((val & 0x000000ff) << 24));
636 return static_cast<unsigned short>(((val & 0xff00) >> 8) | ((val & 0x00ff) << 8));
658 unsigned char *dst = (
unsigned char *)&a;
659 unsigned char *src = (
unsigned char *)&d;
672 unsigned char *src = (
unsigned char *)&a;
673 unsigned char *dst = (
unsigned char *)&d;
686 unsigned char *src = (
unsigned char *)&d;
702 unsigned char *dst = (
unsigned char *)&d;
766 else if (angleInRadians >
SIMD_PI)
772 return angleInRadians;
794 struct btConvertPointerSizeT
801 btConvertPointerSizeT converter;
803 const size_t bit_mask = ~(alignment - 1);
804 converter.ptr = unalignedPtr;
805 converter.integer += alignment - 1;
806 converter.integer &= bit_mask;
807 return converter.ptr;
btMatrix3x3 operator*(const btMatrix3x3 &m, const btScalar &k)
btMatrix3x3 operator+(const btMatrix3x3 &m1, const btMatrix3x3 &m2)
btMatrix3x3 operator-(const btMatrix3x3 &m1, const btMatrix3x3 &m2)
#define SIMD_RADS_PER_DEG
unsigned int btSwapEndianFloat(float d)
btSwapFloat uses using char pointers to swap the endianness
btScalar btPow(btScalar x, btScalar y)
btScalar btNormalizeAngle(btScalar angleInRadians)
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
unsigned btSelect(unsigned condition, unsigned valueIfConditionNonZero, unsigned valueIfConditionZero)
btSelect avoids branches, which makes performance much better for consoles like Playstation 3 and XBo...
void btSetZero(T *a, int n)
bool btMachineIsLittleEndian()
#define SIMD_DEGS_PER_RAD
btScalar btSqrt(btScalar y)
float btUnswapEndianFloat(unsigned int a)
void btSwapEndianDouble(double d, unsigned char *dst)
int btIsNegative(btScalar x)
btScalar btDegrees(btScalar x)
btScalar btAtan2(btScalar x, btScalar y)
static btInfMaskConverter btInfinityMask
btScalar btSin(btScalar x)
btScalar btFabs(btScalar x)
btScalar btTan(btScalar x)
#define SIMD_FORCE_INLINE
btScalar btExp(btScalar x)
bool btEqual(btScalar a, btScalar eps)
unsigned btSwapEndian(unsigned val)
btScalar btFmod(btScalar x, btScalar y)
T * btAlignPointer(T *unalignedPtr, size_t alignment)
align a pointer to the provided alignment, upwards
btScalar btCos(btScalar x)
bool btGreaterEqual(btScalar a, btScalar eps)
btScalar btLog(btScalar x)
double btUnswapEndianDouble(const unsigned char *src)
btScalar btRadians(btScalar x)
#define BT_BULLET_VERSION
btScalar btAtan2Fast(btScalar y, btScalar x)
btScalar btFsel(btScalar a, btScalar b, btScalar c)
btScalar btAtan(btScalar x)
btScalar btAcos(btScalar x)
btScalar btLargeDot(const btScalar *a, const btScalar *b, int n)
btScalar btAsin(btScalar x)
bool btFuzzyZero(btScalar x)
static T sum(const btAlignedObjectArray< T > &items)
btInfMaskConverter(int _mask=0x7F800000)
rudimentary class to provide type info
btTypedObject(int objectType)
int getObjectType() const