28#define BT_BULLET_VERSION 324
37 #ifdef BT_USE_DOUBLE_PRECISION
57#define BT_NOT_EMPTY_FILE_CAT_II(p, res) res
58#define BT_NOT_EMPTY_FILE_CAT_I(a, b) BT_NOT_EMPTY_FILE_CAT_II(~, a##b)
59#define BT_NOT_EMPTY_FILE_CAT(a, b) BT_NOT_EMPTY_FILE_CAT_I(a, b)
60#define BT_NOT_EMPTY_FILE \
63 char BT_NOT_EMPTY_FILE_CAT(NoEmptyFileDummy, __COUNTER__); \
66#define BT_NOT_EMPTY_FILE
71#if defined(DEBUG) || defined (_DEBUG)
77 #define SIMD_FORCE_INLINE __inline__ __attribute__((always_inline))
78 #define ATTRIBUTE_ALIGNED16(a) a __attribute__((aligned(16)))
79 #define ATTRIBUTE_ALIGNED64(a) a __attribute__((aligned(64)))
80 #define ATTRIBUTE_ALIGNED128(a) a __attribute__((aligned(128)))
81 #elif ( defined(_MSC_VER) && _MSC_VER < 1300 )
82 #define SIMD_FORCE_INLINE inline
83 #define ATTRIBUTE_ALIGNED16(a) a
84 #define ATTRIBUTE_ALIGNED64(a) a
85 #define ATTRIBUTE_ALIGNED128(a) a
87 #define SIMD_FORCE_INLINE __forceinline
88 #define ATTRIBUTE_ALIGNED16(a) __declspec() a
89 #define ATTRIBUTE_ALIGNED64(a) __declspec() a
90 #define ATTRIBUTE_ALIGNED128(a) __declspec () a
93 #pragma warning(disable : 4324)
95 #pragma warning(disable:4996)
98 #define SIMD_FORCE_INLINE __forceinline
99 #define ATTRIBUTE_ALIGNED16(a) __declspec(align(16)) a
100 #define ATTRIBUTE_ALIGNED64(a) __declspec(align(64)) a
101 #define ATTRIBUTE_ALIGNED128(a) __declspec (align(128)) a
103 #define BT_USE_VMX128
105 #include <ppcintrinsics.h>
106 #define BT_HAVE_NATIVE_FSEL
107 #define btFsel(a,b,c) __fsel((a),(b),(c))
110#if defined (_M_ARM) || defined (_M_ARM64)
112#elif (defined (_WIN32) && (_MSC_VER) && _MSC_VER >= 1400) && (!defined (BT_USE_DOUBLE_PRECISION))
115#define __BT_DISABLE_SSE__
117#ifndef __BT_DISABLE_SSE__
119 #define BT_USE_SIMD_VECTOR3
125#if (_MSC_FULL_VER >= 170050727)
126 #define BT_ALLOW_SSE4
137 #include <emmintrin.h>
147 #define btAssert(x) { if(!(x)){printf("Assert " __FILE__ ":%u (%s)\n", __LINE__, #x);__debugbreak(); }}
150 #define btAssert assert
156 #define btFullAssert(x)
158 #define btLikely(_c) _c
159 #define btUnlikely(_c) _c
163 #if defined (__CELLOS_LV2__)
164 #define SIMD_FORCE_INLINE inline __attribute__((always_inline))
165 #define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16)))
166 #define ATTRIBUTE_ALIGNED64(a) a __attribute__ ((aligned (64)))
167 #define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128)))
173 #include <spu_printf.h>
174 #define printf spu_printf
175 #define btAssert(x) {if(!(x)){printf("Assert " __FILE__ ":%u ("#x")\n", __LINE__);spu_hcmpeq(0,0);}}
177 #define btAssert assert
184 #define btFullAssert(x)
186 #define btLikely(_c) _c
187 #define btUnlikely(_c) _c
193 #define SIMD_FORCE_INLINE __inline
194 #define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16)))
195 #define ATTRIBUTE_ALIGNED64(a) a __attribute__ ((aligned (64)))
196 #define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128)))
201 #define btAssert assert
206 #define btFullAssert(x)
209 #define btLikely(_c) __builtin_expect((_c), 1)
210 #define btUnlikely(_c) __builtin_expect((_c), 0)
216 #if (defined (__APPLE__) && (!defined (BT_USE_DOUBLE_PRECISION)))
217 #if defined (__i386__) || defined (__x86_64__)
218 #define BT_USE_SIMD_VECTOR3
222 #define BT_USE_SSE_IN_API
225 #if defined (__SSE4_1__)
226 #include <smmintrin.h>
227 #elif defined (__SSSE3__)
228 #include <tmmintrin.h>
229 #elif defined (__SSE3__)
230 #include <pmmintrin.h>
232 #include <emmintrin.h>
235 #elif defined( __ARM_NEON__ )
237 #define BT_USE_NEON 1
238 #define BT_USE_SIMD_VECTOR3
240 #if defined BT_USE_NEON && defined (__clang__)
241 #include <arm_neon.h>
246 #define SIMD_FORCE_INLINE inline __attribute__ ((always_inline))
248 #define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16)))
249 #define ATTRIBUTE_ALIGNED64(a) a __attribute__ ((aligned (64)))
250 #define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128)))
255 #if defined(DEBUG) || defined (_DEBUG)
256 #if defined (__i386__) || defined (__x86_64__)
262 printf("Assert %s in line %d, file %s\n",#x, __LINE__, __FILE__);\
263 asm volatile ("int3");\
267 #define btAssert assert
274 #define btFullAssert(x)
275 #define btLikely(_c) _c
276 #define btUnlikely(_c) _c
280 #define SIMD_FORCE_INLINE inline
285 #define ATTRIBUTE_ALIGNED16(a) a
286 #define ATTRIBUTE_ALIGNED64(a) a
287 #define ATTRIBUTE_ALIGNED128(a) a
292 #if defined(DEBUG) || defined (_DEBUG)
293 #define btAssert assert
299 #define btFullAssert(x)
300 #define btLikely(_c) _c
301 #define btUnlikely(_c) _c
309#if defined(BT_USE_DOUBLE_PRECISION)
312 #define BT_LARGE_FLOAT 1e30
316 #define BT_LARGE_FLOAT 1e18f
320 typedef __m128 btSimdFloat4;
323#if defined(BT_USE_SSE)
328 static int btNanMask = 0x7F800001;
329 #define BT_NAN (*(float *)&btNanMask)
334 #define BT_INFINITY (*(float *)&btInfinityMask)
344 #ifndef BT_NO_SIMD_OPERATOR_OVERLOADS
345 inline __m128
operator+(
const __m128 A,
const __m128 B)
347 return _mm_add_ps(A, B);
350 inline __m128
operator-(
const __m128 A,
const __m128 B)
352 return _mm_sub_ps(A, B);
355 inline __m128
operator*(
const __m128 A,
const __m128 B)
357 return _mm_mul_ps(A, B);
361 #define btCastfTo128i(a) (_mm_castps_si128(a))
362 #define btCastfTo128d(a) (_mm_castps_pd(a))
363 #define btCastiTo128f(a) (_mm_castsi128_ps(a))
364 #define btCastdTo128f(a) (_mm_castpd_ps(a))
365 #define btCastdTo128i(a) (_mm_castpd_si128(a))
366 #define btAssign128(r0, r1, r2, r3) _mm_setr_ps(r0, r1, r2, r3)
370 #define btCastfTo128i(a) ((__m128i)(a))
371 #define btCastfTo128d(a) ((__m128d)(a))
372 #define btCastiTo128f(a) ((__m128)(a))
373 #define btCastdTo128f(a) ((__m128)(a))
374 #define btCastdTo128i(a) ((__m128i)(a))
375 #define btAssign128(r0, r1, r2, r3) \
376 (__m128) { r0, r1, r2, r3 }
377 #define BT_INFINITY INFINITY
383 #include <arm_neon.h>
385 typedef float32x4_t btSimdFloat4;
386 #define BT_INFINITY INFINITY
388 #define btAssign128(r0, r1, r2, r3) \
389 (float32x4_t) { r0, r1, r2, r3 }
405 #define BT_INFINITY (btInfinityMask.mask)
416 #include <arm_neon.h>
418 typedef float32x4_t btSimdFloat4;
419 #define BT_INFINITY INFINITY
421 #define btAssign128(r0, r1, r2, r3) \
422 (float32x4_t) { r0, r1, r2, r3 }
425#define BT_DECLARE_ALIGNED_ALLOCATOR() \
426 SIMD_FORCE_INLINE void *operator new(size_t sizeInBytes) { return btAlignedAlloc(sizeInBytes, 16); } \
427 SIMD_FORCE_INLINE void operator delete(void *ptr) { btAlignedFree(ptr); } \
428 SIMD_FORCE_INLINE void *operator new(size_t, void *ptr) { return ptr; } \
429 SIMD_FORCE_INLINE void operator delete(void *, void *) {} \
430 SIMD_FORCE_INLINE void *operator new[](size_t sizeInBytes) { return btAlignedAlloc(sizeInBytes, 16); } \
431 SIMD_FORCE_INLINE void operator delete[](void *ptr) { btAlignedFree(ptr); } \
432 SIMD_FORCE_INLINE void *operator new[](size_t, void *ptr) { return ptr; } \
433 SIMD_FORCE_INLINE void operator delete[](void *, void *) {}
435#if defined(BT_USE_DOUBLE_PRECISION) || defined(BT_FORCE_DOUBLE_FUNCTIONS)
468 #ifdef USE_APPROXIMATION
470 float xhalf = 0.5f * y;
472 i = 0x5f375a86 - (i >> 1);
474 y = y * (1.5f - xhalf * y * y);
475 y = y * (1.5f - xhalf * y * y);
476 y = y * (1.5f - xhalf * y * y);
481 unsigned long *tfptr = ((
unsigned long *)&tempf) + 1;
483 *tfptr = (0xbfcdd90a - *tfptr) >> 1;
486 x = (
btScalar(1.5) * x) - (x * x) * (x * z);
487 x = (
btScalar(1.5) * x) - (x * x) * (x * z);
488 x = (
btScalar(1.5) * x) - (x * x) * (x * z);
489 x = (
btScalar(1.5) * x) - (x * x) * (x * z);
490 x = (
btScalar(1.5) * x) - (x * x) * (x * z);
526#define SIMD_PI btScalar(3.1415926535897932384626433832795029)
527#define SIMD_2_PI (btScalar(2.0) * SIMD_PI)
528#define SIMD_HALF_PI (SIMD_PI * btScalar(0.5))
529#define SIMD_RADS_PER_DEG (SIMD_2_PI / btScalar(360.0))
530#define SIMD_DEGS_PER_RAD (btScalar(360.0) / SIMD_2_PI)
531#define SIMDSQRT12 btScalar(0.7071067811865475244008443621048490)
532#define btRecipSqrt(x) ((btScalar)(btScalar(1.0) / btSqrt(btScalar(x))))
533#define btRecip(x) (btScalar(1.0) / btScalar(x))
535#ifdef BT_USE_DOUBLE_PRECISION
536 #define SIMD_EPSILON DBL_EPSILON
537 #define SIMD_INFINITY DBL_MAX
543 #define SIMD_EPSILON FLT_EPSILON
544 #define SIMD_INFINITY FLT_MAX
561 btScalar r = (x - abs_y) / (x + abs_y);
562 angle = coeff_1 - coeff_1 * r;
566 btScalar r = (x + abs_y) / (abs_y - x);
567 angle = coeff_2 - coeff_1 * r;
569 return (y < 0.0f) ? -angle : angle;
576 return (((a) <=
eps) && !((a) < -
eps));
580 return (!((a) <=
eps));
591#define BT_DECLARE_HANDLE(name) \
592 typedef struct name##__ \
600 return a >= 0 ? b : c;
603#define btFsels(a, b, c) (btScalar) btFsel(a, b, c)
608 const char *p = (
const char *)&i;
623 unsigned testNz = (unsigned)(((
int)condition | -(
int)condition) >> 31);
624 unsigned testEqz = ~testNz;
625 return ((valueIfConditionNonZero & testNz) | (valueIfConditionZero & testEqz));
629 unsigned testNz = (unsigned)(((
int)condition | -(
int)condition) >> 31);
630 unsigned testEqz = ~testNz;
631 return static_cast<int>((valueIfConditionNonZero & testNz) | (valueIfConditionZero & testEqz));
635#ifdef BT_HAVE_NATIVE_FSEL
636 return (
float)
btFsel((
btScalar)condition -
btScalar(1.0f), valueIfConditionNonZero, valueIfConditionZero);
638 return (condition != 0) ? valueIfConditionNonZero : valueIfConditionZero;
653 return (((val & 0xff000000) >> 24) | ((val & 0x00ff0000) >> 8) | ((val & 0x0000ff00) << 8) | ((val & 0x000000ff) << 24));
658 return static_cast<unsigned short>(((val & 0xff00) >> 8) | ((val & 0x00ff) << 8));
680 unsigned char *dst = (
unsigned char *)&a;
681 unsigned char *src = (
unsigned char *)&d;
694 unsigned char *src = (
unsigned char *)&a;
695 unsigned char *dst = (
unsigned char *)&d;
708 unsigned char *src = (
unsigned char *)&d;
724 unsigned char *dst = (
unsigned char *)&d;
788 else if (angleInRadians >
SIMD_PI)
794 return angleInRadians;
816 struct btConvertPointerSizeT
823 btConvertPointerSizeT converter;
825 const size_t bit_mask = ~(alignment - 1);
826 converter.ptr = unalignedPtr;
827 converter.integer += alignment - 1;
828 converter.integer &= bit_mask;
829 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
int btIsDoublePrecision()
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