20 #ifdef BT_MANAGED_CODE
31 #define BT_BULLET_VERSION 282
38 #if defined(DEBUG) || defined (_DEBUG)
45 #if defined(__MINGW32__) || defined(__CYGWIN__) || (defined (_MSC_VER) && _MSC_VER < 1300)
47 #define SIMD_FORCE_INLINE inline
48 #define ATTRIBUTE_ALIGNED16(a) a
49 #define ATTRIBUTE_ALIGNED64(a) a
50 #define ATTRIBUTE_ALIGNED128(a) a
53 #pragma warning(disable : 4324) // disable padding warning
58 #define SIMD_FORCE_INLINE __forceinline
59 #define ATTRIBUTE_ALIGNED16(a) __declspec(align(16)) a
60 #define ATTRIBUTE_ALIGNED64(a) __declspec(align(64)) a
61 #define ATTRIBUTE_ALIGNED128(a) __declspec (align(128)) a
65 #include <ppcintrinsics.h>
66 #define BT_HAVE_NATIVE_FSEL
67 #define btFsel(a,b,c) __fsel((a),(b),(c))
70 #if (defined (_WIN32) && (_MSC_VER) && _MSC_VER >= 1400) && (!defined (BT_USE_DOUBLE_PRECISION))
72 #define BT_USE_SIMD_VECTOR3
85 #include <emmintrin.h>
95 #define btAssert(x) { if(!(x)){printf("Assert "__FILE__ ":%u ("#x")\n", __LINE__);__debugbreak(); }}
98 #define btAssert assert
104 #define btFullAssert(x)
106 #define btLikely(_c) _c
107 #define btUnlikely(_c) _c
111 #if defined (__CELLOS_LV2__)
112 #define SIMD_FORCE_INLINE inline __attribute__((always_inline))
113 #define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16)))
114 #define ATTRIBUTE_ALIGNED64(a) a __attribute__ ((aligned (64)))
115 #define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128)))
121 #include <spu_printf.h>
122 #define printf spu_printf
123 #define btAssert(x) {if(!(x)){printf("Assert "__FILE__ ":%u ("#x")\n", __LINE__);spu_hcmpeq(0,0);}}
125 #define btAssert assert
132 #define btFullAssert(x)
134 #define btLikely(_c) _c
135 #define btUnlikely(_c) _c
141 #define SIMD_FORCE_INLINE __inline
142 #define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16)))
143 #define ATTRIBUTE_ALIGNED64(a) a __attribute__ ((aligned (64)))
144 #define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128)))
149 #define btAssert assert
154 #define btFullAssert(x)
157 #define btLikely(_c) __builtin_expect((_c), 1)
158 #define btUnlikely(_c) __builtin_expect((_c), 0)
164 #if (defined (__APPLE__) && (!defined (BT_USE_DOUBLE_PRECISION)))
165 #if defined (__i386__) || defined (__x86_64__)
166 #define BT_USE_SIMD_VECTOR3
170 #define BT_USE_SSE_IN_API
173 #if defined (__SSE4_1__)
174 #include <smmintrin.h>
175 #elif defined (__SSSE3__)
176 #include <tmmintrin.h>
177 #elif defined (__SSE3__)
178 #include <pmmintrin.h>
180 #include <emmintrin.h>
183 #elif defined( __ARM_NEON__ )
185 #define BT_USE_NEON 1
186 #define BT_USE_SIMD_VECTOR3
188 #if defined BT_USE_NEON && defined (__clang__)
189 #include <arm_neon.h>
194 #define SIMD_FORCE_INLINE inline __attribute__ ((always_inline))
196 #define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16)))
197 #define ATTRIBUTE_ALIGNED64(a) a __attribute__ ((aligned (64)))
198 #define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128)))
203 #if defined(DEBUG) || defined (_DEBUG)
204 #if defined (__i386__) || defined (__x86_64__)
210 printf("Assert %s in line %d, file %s\n",#x, __LINE__, __FILE__);\
211 asm volatile ("int3");\
214 #else//defined (__i386__) || defined (__x86_64__)
215 #define btAssert assert
216 #endif//defined (__i386__) || defined (__x86_64__)
217 #else//defined(DEBUG) || defined (_DEBUG)
219 #endif//defined(DEBUG) || defined (_DEBUG)
222 #define btFullAssert(x)
223 #define btLikely(_c) _c
224 #define btUnlikely(_c) _c
228 #define SIMD_FORCE_INLINE inline
233 #define ATTRIBUTE_ALIGNED16(a) a
234 #define ATTRIBUTE_ALIGNED64(a) a
235 #define ATTRIBUTE_ALIGNED128(a) a
240 #if defined(DEBUG) || defined (_DEBUG)
241 #define btAssert assert
247 #define btFullAssert(x)
248 #define btLikely(_c) _c
249 #define btUnlikely(_c) _c
254 #endif //__CELLOS_LV2__
259 #if defined(BT_USE_DOUBLE_PRECISION)
263 #define BT_LARGE_FLOAT 1e30
268 #define BT_LARGE_FLOAT 1e18f
272 typedef __m128 btSimdFloat4;
275 #if defined (BT_USE_SSE)
280 static int btNanMask = 0x7F800001;
281 #define BT_NAN (*(float*)&btNanMask)
286 #define BT_INFINITY (*(float*)&btInfinityMask)
290 #ifndef BT_NO_SIMD_OPERATOR_OVERLOADS
291 inline __m128
operator + (
const __m128 A,
const __m128 B)
293 return _mm_add_ps(A, B);
296 inline __m128
operator - (
const __m128 A,
const __m128 B)
298 return _mm_sub_ps(A, B);
301 inline __m128
operator * (
const __m128 A,
const __m128 B)
303 return _mm_mul_ps(A, B);
305 #endif //BT_NO_SIMD_OPERATOR_OVERLOADS
307 #define btCastfTo128i(a) (_mm_castps_si128(a))
308 #define btCastfTo128d(a) (_mm_castps_pd(a))
309 #define btCastiTo128f(a) (_mm_castsi128_ps(a))
310 #define btCastdTo128f(a) (_mm_castpd_ps(a))
311 #define btCastdTo128i(a) (_mm_castpd_si128(a))
312 #define btAssign128(r0,r1,r2,r3) _mm_setr_ps(r0,r1,r2,r3)
316 #define btCastfTo128i(a) ((__m128i)(a))
317 #define btCastfTo128d(a) ((__m128d)(a))
318 #define btCastiTo128f(a) ((__m128) (a))
319 #define btCastdTo128f(a) ((__m128) (a))
320 #define btCastdTo128i(a) ((__m128i)(a))
321 #define btAssign128(r0,r1,r2,r3) (__m128){r0,r1,r2,r3}
322 #define BT_INFINITY INFINITY
328 #include <arm_neon.h>
330 typedef float32x4_t btSimdFloat4;
331 #define BT_INFINITY INFINITY
333 #define btAssign128(r0,r1,r2,r3) (float32x4_t){r0,r1,r2,r3}
338 #define BT_INFINITY (*(float*)&btInfinityMask)
345 #include <arm_neon.h>
347 typedef float32x4_t btSimdFloat4;
348 #define BT_INFINITY INFINITY
350 #define btAssign128(r0,r1,r2,r3) (float32x4_t){r0,r1,r2,r3}
357 #define BT_DECLARE_ALIGNED_ALLOCATOR() \
358 SIMD_FORCE_INLINE void* operator new(size_t sizeInBytes) { return btAlignedAlloc(sizeInBytes,16); } \
359 SIMD_FORCE_INLINE void operator delete(void* ptr) { btAlignedFree(ptr); } \
360 SIMD_FORCE_INLINE void* operator new(size_t, void* ptr) { return ptr; } \
361 SIMD_FORCE_INLINE void operator delete(void*, void*) { } \
362 SIMD_FORCE_INLINE void* operator new[](size_t sizeInBytes) { return btAlignedAlloc(sizeInBytes,16); } \
363 SIMD_FORCE_INLINE void operator delete[](void* ptr) { btAlignedFree(ptr); } \
364 SIMD_FORCE_INLINE void* operator new[](size_t, void* ptr) { return ptr; } \
365 SIMD_FORCE_INLINE void operator delete[](void*, void*) { } \
369 #if defined(BT_USE_DOUBLE_PRECISION) || defined(BT_FORCE_DOUBLE_FUNCTIONS)
389 #ifdef USE_APPROXIMATION
391 unsigned long *tfptr = ((
unsigned long *)&tempf) + 1;
394 *tfptr = (0xbfcdd90a - *tfptr)>>1;
434 #define SIMD_PI btScalar(3.1415926535897932384626433832795029)
435 #define SIMD_2_PI btScalar(2.0) * SIMD_PI
436 #define SIMD_HALF_PI (SIMD_PI * btScalar(0.5))
437 #define SIMD_RADS_PER_DEG (SIMD_2_PI / btScalar(360.0))
438 #define SIMD_DEGS_PER_RAD (btScalar(360.0) / SIMD_2_PI)
439 #define SIMDSQRT12 btScalar(0.7071067811865475244008443621048490)
441 #define btRecipSqrt(x) ((btScalar)(btScalar(1.0)/btSqrt(btScalar(x))))
442 #define btRecip(x) (btScalar(1.0)/btScalar(x))
444 #ifdef BT_USE_DOUBLE_PRECISION
445 #define SIMD_EPSILON DBL_EPSILON
446 #define SIMD_INFINITY DBL_MAX
448 #define SIMD_EPSILON FLT_EPSILON
449 #define SIMD_INFINITY FLT_MAX
459 btScalar r = (x - abs_y) / (x + abs_y);
460 angle = coeff_1 - coeff_1 * r;
462 btScalar r = (x + abs_y) / (abs_y - x);
463 angle = coeff_2 - coeff_1 * r;
465 return (y < 0.0f) ? -angle : angle;
471 return (((a) <= eps) && !((a) < -eps));
474 return (!((a) <= eps));
485 #define BT_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name
490 return a >= 0 ? b : c;
493 #define btFsels(a,b,c) (btScalar)btFsel(a,b,c)
499 const char *p = (
const char *) &i;
516 unsigned testNz = (unsigned)(((
int)condition | -(
int)condition) >> 31);
517 unsigned testEqz = ~testNz;
518 return ((valueIfConditionNonZero & testNz) | (valueIfConditionZero & testEqz));
522 unsigned testNz = (unsigned)(((
int)condition | -(
int)condition) >> 31);
523 unsigned testEqz = ~testNz;
524 return static_cast<int>((valueIfConditionNonZero & testNz) | (valueIfConditionZero & testEqz));
528 #ifdef BT_HAVE_NATIVE_FSEL
529 return (
float)
btFsel((
btScalar)condition -
btScalar(1.0f), valueIfConditionNonZero, valueIfConditionZero);
531 return (condition != 0) ? valueIfConditionNonZero : valueIfConditionZero;
546 return (((val & 0xff000000) >> 24) | ((val & 0x00ff0000) >> 8) | ((val & 0x0000ff00) << 8) | ((val & 0x000000ff) << 24));
551 return static_cast<unsigned short>(((val & 0xff00) >> 8) | ((val & 0x00ff) << 8));
573 unsigned char *dst = (
unsigned char *)&a;
574 unsigned char *src = (
unsigned char *)&d;
587 unsigned char *src = (
unsigned char *)&a;
588 unsigned char *dst = (
unsigned char *)&d;
602 unsigned char *src = (
unsigned char *)&d;
619 unsigned char *dst = (
unsigned char *)&d;
652 p0 = a[0]; q0 = b[0];
654 p1 = a[1]; q1 = b[1];
681 else if(angleInRadians >
SIMD_PI)
687 return angleInRadians;
713 struct btConvertPointerSizeT
721 btConvertPointerSizeT converter;
724 const size_t bit_mask = ~(alignment - 1);
725 converter.ptr = unalignedPtr;
726 converter.integer += alignment-1;
727 converter.integer &= bit_mask;
728 return converter.ptr;