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))
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( __armv7__ )
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)
262 #define BT_LARGE_FLOAT 1e30
266 #define BT_LARGE_FLOAT 1e18f
270 typedef __m128 btSimdFloat4;
273 #if defined (BT_USE_SSE)
278 static int btNanMask = 0x7F800001;
279 #define BT_NAN (*(float*)&btNanMask)
283 static int btInfinityMask = 0x7F800000;
284 #define BT_INFINITY (*(float*)&btInfinityMask)
287 inline __m128
operator + (
const __m128 A,
const __m128 B)
289 return _mm_add_ps(A, B);
292 inline __m128
operator - (
const __m128 A,
const __m128 B)
294 return _mm_sub_ps(A, B);
297 inline __m128
operator * (
const __m128 A,
const __m128 B)
299 return _mm_mul_ps(A, B);
302 #define btCastfTo128i(a) (_mm_castps_si128(a))
303 #define btCastfTo128d(a) (_mm_castps_pd(a))
304 #define btCastiTo128f(a) (_mm_castsi128_ps(a))
305 #define btCastdTo128f(a) (_mm_castpd_ps(a))
306 #define btCastdTo128i(a) (_mm_castpd_si128(a))
307 #define btAssign128(r0,r1,r2,r3) _mm_setr_ps(r0,r1,r2,r3)
311 #define btCastfTo128i(a) ((__m128i)(a))
312 #define btCastfTo128d(a) ((__m128d)(a))
313 #define btCastiTo128f(a) ((__m128) (a))
314 #define btCastdTo128f(a) ((__m128) (a))
315 #define btCastdTo128i(a) ((__m128i)(a))
316 #define btAssign128(r0,r1,r2,r3) (__m128){r0,r1,r2,r3}
317 #define BT_INFINITY INFINITY
320 #endif //BT_USE_SSE_IN_API
323 #include <arm_neon.h>
325 typedef float32x4_t btSimdFloat4;
326 #define BT_INFINITY INFINITY
328 #define btAssign128(r0,r1,r2,r3) (float32x4_t){r0,r1,r2,r3}
335 #define BT_DECLARE_ALIGNED_ALLOCATOR() \
336 SIMD_FORCE_INLINE void* operator new(size_t sizeInBytes) { return btAlignedAlloc(sizeInBytes,16); } \
337 SIMD_FORCE_INLINE void operator delete(void* ptr) { btAlignedFree(ptr); } \
338 SIMD_FORCE_INLINE void* operator new(size_t, void* ptr) { return ptr; } \
339 SIMD_FORCE_INLINE void operator delete(void*, void*) { } \
340 SIMD_FORCE_INLINE void* operator new[](size_t sizeInBytes) { return btAlignedAlloc(sizeInBytes,16); } \
341 SIMD_FORCE_INLINE void operator delete[](void* ptr) { btAlignedFree(ptr); } \
342 SIMD_FORCE_INLINE void* operator new[](size_t, void* ptr) { return ptr; } \
343 SIMD_FORCE_INLINE void operator delete[](void*, void*) { } \
347 #if defined(BT_USE_DOUBLE_PRECISION) || defined(BT_FORCE_DOUBLE_FUNCTIONS)
367 #ifdef USE_APPROXIMATION
369 unsigned long *tfptr = ((
unsigned long *)&tempf) + 1;
372 *tfptr = (0xbfcdd90a - *tfptr)>>1;
412 #define SIMD_2_PI btScalar(6.283185307179586232)
413 #define SIMD_PI (SIMD_2_PI * btScalar(0.5))
414 #define SIMD_HALF_PI (SIMD_2_PI * btScalar(0.25))
415 #define SIMD_RADS_PER_DEG (SIMD_2_PI / btScalar(360.0))
416 #define SIMD_DEGS_PER_RAD (btScalar(360.0) / SIMD_2_PI)
417 #define SIMDSQRT12 btScalar(0.7071067811865475244008443621048490)
419 #define btRecipSqrt(x) ((btScalar)(btScalar(1.0)/btSqrt(btScalar(x))))
422 #ifdef BT_USE_DOUBLE_PRECISION
423 #define SIMD_EPSILON DBL_EPSILON
424 #define SIMD_INFINITY DBL_MAX
426 #define SIMD_EPSILON FLT_EPSILON
427 #define SIMD_INFINITY FLT_MAX
437 btScalar r = (x - abs_y) / (x + abs_y);
438 angle = coeff_1 - coeff_1 * r;
440 btScalar r = (x + abs_y) / (abs_y - x);
441 angle = coeff_2 - coeff_1 * r;
443 return (y < 0.0f) ? -angle : angle;
449 return (((a) <= eps) && !((a) < -eps));
452 return (!((a) <= eps));
463 #define BT_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name
468 return a >= 0 ? b : c;
471 #define btFsels(a,b,c) (btScalar)btFsel(a,b,c)
477 const char *p = (
const char *) &i;
494 unsigned testNz = (unsigned)(((
int)condition | -(
int)condition) >> 31);
495 unsigned testEqz = ~testNz;
496 return ((valueIfConditionNonZero & testNz) | (valueIfConditionZero & testEqz));
500 unsigned testNz = (unsigned)(((
int)condition | -(
int)condition) >> 31);
501 unsigned testEqz = ~testNz;
502 return static_cast<int>((valueIfConditionNonZero & testNz) | (valueIfConditionZero & testEqz));
506 #ifdef BT_HAVE_NATIVE_FSEL
507 return (
float)
btFsel((
btScalar)condition -
btScalar(1.0f), valueIfConditionNonZero, valueIfConditionZero);
509 return (condition != 0) ? valueIfConditionNonZero : valueIfConditionZero;
524 return (((val & 0xff000000) >> 24) | ((val & 0x00ff0000) >> 8) | ((val & 0x0000ff00) << 8) | ((val & 0x000000ff) << 24));
529 return static_cast<unsigned short>(((val & 0xff00) >> 8) | ((val & 0x00ff) << 8));
551 unsigned char *dst = (
unsigned char *)&a;
552 unsigned char *src = (
unsigned char *)&d;
565 unsigned char *src = (
unsigned char *)&a;
566 unsigned char *dst = (
unsigned char *)&d;
580 unsigned char *src = (
unsigned char *)&d;
597 unsigned char *dst = (
unsigned char *)&d;
619 else if(angleInRadians >
SIMD_PI)
625 return angleInRadians;
649 struct btConvertPointerSizeT
657 btConvertPointerSizeT converter;
660 const size_t bit_mask = ~(alignment - 1);
661 converter.ptr = unalignedPtr;
662 converter.integer += alignment-1;
663 converter.integer &= bit_mask;
664 return converter.ptr;