20 #ifdef BT_MANAGED_CODE
31 #define BT_BULLET_VERSION 281
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))
81 #include <emmintrin.h>
91 #define btAssert(x) { if(!(x)){printf("Assert "__FILE__ ":%u ("#x")\n", __LINE__);__debugbreak(); }}
94 #define btAssert assert
100 #define btFullAssert(x)
102 #define btLikely(_c) _c
103 #define btUnlikely(_c) _c
107 #if defined (__CELLOS_LV2__)
108 #define SIMD_FORCE_INLINE inline __attribute__((always_inline))
109 #define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16)))
110 #define ATTRIBUTE_ALIGNED64(a) a __attribute__ ((aligned (64)))
111 #define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128)))
117 #include <spu_printf.h>
118 #define printf spu_printf
119 #define btAssert(x) {if(!(x)){printf("Assert "__FILE__ ":%u ("#x")\n", __LINE__);spu_hcmpeq(0,0);}}
121 #define btAssert assert
128 #define btFullAssert(x)
130 #define btLikely(_c) _c
131 #define btUnlikely(_c) _c
137 #define SIMD_FORCE_INLINE __inline
138 #define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16)))
139 #define ATTRIBUTE_ALIGNED64(a) a __attribute__ ((aligned (64)))
140 #define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128)))
145 #define btAssert assert
150 #define btFullAssert(x)
153 #define btLikely(_c) __builtin_expect((_c), 1)
154 #define btUnlikely(_c) __builtin_expect((_c), 0)
160 #if (defined (__APPLE__) && (!defined (BT_USE_DOUBLE_PRECISION)))
161 #if defined (__i386__) || defined (__x86_64__)
165 #define BT_USE_SSE_IN_API
168 #if defined (__SSE4_1__)
169 #include <smmintrin.h>
170 #elif defined (__SSSE3__)
171 #include <tmmintrin.h>
172 #elif defined (__SSE3__)
173 #include <pmmintrin.h>
175 #include <emmintrin.h>
178 #elif defined( __armv7__ )
180 #define BT_USE_NEON 1
182 #if defined BT_USE_NEON && defined (__clang__)
183 #include <arm_neon.h>
188 #define SIMD_FORCE_INLINE inline __attribute__ ((always_inline))
189 #define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16)))
191 #define ATTRIBUTE_ALIGNED64(a) a __attribute__ ((aligned (64)))
192 #define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128)))
197 #if defined(DEBUG) || defined (_DEBUG)
198 #if defined (__i386__) || defined (__x86_64__)
204 printf("Assert %s in line %d, file %s\n",#x, __LINE__, __FILE__);\
205 asm volatile ("int3");\
208 #else//defined (__i386__) || defined (__x86_64__)
209 #define btAssert assert
210 #end//defined (__i386__) || defined (__x86_64__)
212 #else//defined(DEBUG) || defined (_DEBUG)
214 #endif//defined(DEBUG) || defined (_DEBUG)
217 #define btFullAssert(x)
218 #define btLikely(_c) _c
219 #define btUnlikely(_c) _c
223 #define SIMD_FORCE_INLINE inline
224 #define ATTRIBUTE_ALIGNED16(a) a
229 #define ATTRIBUTE_ALIGNED64(a) a
230 #define ATTRIBUTE_ALIGNED128(a) a
235 #if defined(DEBUG) || defined (_DEBUG)
236 #define btAssert assert
242 #define btFullAssert(x)
243 #define btLikely(_c) _c
244 #define btUnlikely(_c) _c
249 #endif //__CELLOS_LV2__
254 #if defined(BT_USE_DOUBLE_PRECISION)
257 #define BT_LARGE_FLOAT 1e30
261 #define BT_LARGE_FLOAT 1e18f
265 typedef __m128 btSimdFloat4;
268 #if defined BT_USE_SSE_IN_API && defined (BT_USE_SSE)
272 static int btNanMask = 0x7F800001;
273 #define BT_NAN (*(float*)&btNanMask)
277 static int btInfinityMask = 0x7F800000;
278 #define BT_INFINITY (*(float*)&btInfinityMask)
281 inline __m128
operator + (
const __m128 A,
const __m128 B)
283 return _mm_add_ps(A, B);
286 inline __m128
operator - (
const __m128 A,
const __m128 B)
288 return _mm_sub_ps(A, B);
291 inline __m128
operator * (
const __m128 A,
const __m128 B)
293 return _mm_mul_ps(A, B);
296 #define btCastfTo128i(a) (_mm_castps_si128(a))
297 #define btCastfTo128d(a) (_mm_castps_pd(a))
298 #define btCastiTo128f(a) (_mm_castsi128_ps(a))
299 #define btCastdTo128f(a) (_mm_castpd_ps(a))
300 #define btCastdTo128i(a) (_mm_castpd_si128(a))
301 #define btAssign128(r0,r1,r2,r3) _mm_setr_ps(r0,r1,r2,r3)
305 #define btCastfTo128i(a) ((__m128i)(a))
306 #define btCastfTo128d(a) ((__m128d)(a))
307 #define btCastiTo128f(a) ((__m128) (a))
308 #define btCastdTo128f(a) ((__m128) (a))
309 #define btCastdTo128i(a) ((__m128i)(a))
310 #define btAssign128(r0,r1,r2,r3) (__m128){r0,r1,r2,r3}
311 #define BT_INFINITY INFINITY
314 #endif //BT_USE_SSE_IN_API
317 #include <arm_neon.h>
319 typedef float32x4_t btSimdFloat4;
320 #define BT_INFINITY INFINITY
322 #define btAssign128(r0,r1,r2,r3) (float32x4_t){r0,r1,r2,r3}
329 #define BT_DECLARE_ALIGNED_ALLOCATOR() \
330 SIMD_FORCE_INLINE void* operator new(size_t sizeInBytes) { return btAlignedAlloc(sizeInBytes,16); } \
331 SIMD_FORCE_INLINE void operator delete(void* ptr) { btAlignedFree(ptr); } \
332 SIMD_FORCE_INLINE void* operator new(size_t, void* ptr) { return ptr; } \
333 SIMD_FORCE_INLINE void operator delete(void*, void*) { } \
334 SIMD_FORCE_INLINE void* operator new[](size_t sizeInBytes) { return btAlignedAlloc(sizeInBytes,16); } \
335 SIMD_FORCE_INLINE void operator delete[](void* ptr) { btAlignedFree(ptr); } \
336 SIMD_FORCE_INLINE void* operator new[](size_t, void* ptr) { return ptr; } \
337 SIMD_FORCE_INLINE void operator delete[](void*, void*) { } \
341 #if defined(BT_USE_DOUBLE_PRECISION) || defined(BT_FORCE_DOUBLE_FUNCTIONS)
361 #ifdef USE_APPROXIMATION
363 unsigned long *tfptr = ((
unsigned long *)&tempf) + 1;
366 *tfptr = (0xbfcdd90a - *tfptr)>>1;
406 #define SIMD_2_PI btScalar(6.283185307179586232)
407 #define SIMD_PI (SIMD_2_PI * btScalar(0.5))
408 #define SIMD_HALF_PI (SIMD_2_PI * btScalar(0.25))
409 #define SIMD_RADS_PER_DEG (SIMD_2_PI / btScalar(360.0))
410 #define SIMD_DEGS_PER_RAD (btScalar(360.0) / SIMD_2_PI)
411 #define SIMDSQRT12 btScalar(0.7071067811865475244008443621048490)
413 #define btRecipSqrt(x) ((btScalar)(btScalar(1.0)/btSqrt(btScalar(x))))
416 #ifdef BT_USE_DOUBLE_PRECISION
417 #define SIMD_EPSILON DBL_EPSILON
418 #define SIMD_INFINITY DBL_MAX
420 #define SIMD_EPSILON FLT_EPSILON
421 #define SIMD_INFINITY FLT_MAX
431 btScalar r = (x - abs_y) / (x + abs_y);
432 angle = coeff_1 - coeff_1 * r;
434 btScalar r = (x + abs_y) / (abs_y - x);
435 angle = coeff_2 - coeff_1 * r;
437 return (y < 0.0f) ? -angle : angle;
443 return (((a) <= eps) && !((a) < -eps));
446 return (!((a) <= eps));
457 #define BT_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name
462 return a >= 0 ? b : c;
465 #define btFsels(a,b,c) (btScalar)btFsel(a,b,c)
471 const char *p = (
const char *) &i;
488 unsigned testNz = (unsigned)(((
int)condition | -(
int)condition) >> 31);
489 unsigned testEqz = ~testNz;
490 return ((valueIfConditionNonZero & testNz) | (valueIfConditionZero & testEqz));
494 unsigned testNz = (unsigned)(((
int)condition | -(
int)condition) >> 31);
495 unsigned testEqz = ~testNz;
496 return static_cast<int>((valueIfConditionNonZero & testNz) | (valueIfConditionZero & testEqz));
500 #ifdef BT_HAVE_NATIVE_FSEL
501 return (
float)
btFsel((
btScalar)condition -
btScalar(1.0f), valueIfConditionNonZero, valueIfConditionZero);
503 return (condition != 0) ? valueIfConditionNonZero : valueIfConditionZero;
518 return (((val & 0xff000000) >> 24) | ((val & 0x00ff0000) >> 8) | ((val & 0x0000ff00) << 8) | ((val & 0x000000ff) << 24));
523 return static_cast<unsigned short>(((val & 0xff00) >> 8) | ((val & 0x00ff) << 8));
545 unsigned char *dst = (
unsigned char *)&a;
546 unsigned char *src = (
unsigned char *)&d;
559 unsigned char *src = (
unsigned char *)&a;
560 unsigned char *dst = (
unsigned char *)&d;
574 unsigned char *src = (
unsigned char *)&d;
591 unsigned char *dst = (
unsigned char *)&d;
613 else if(angleInRadians >
SIMD_PI)
619 return angleInRadians;
643 struct btConvertPointerSizeT
651 btConvertPointerSizeT converter;
654 const size_t bit_mask = ~(alignment - 1);
655 converter.ptr = unalignedPtr;
656 converter.integer += alignment-1;
657 converter.integer &= bit_mask;
658 return converter.ptr;