Changeset 8351 for code/trunk/src/external/bullet/LinearMath/btScalar.h
- Timestamp:
- Apr 28, 2011, 7:15:14 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/external/bullet/LinearMath/btScalar.h
r5781 r8351 1 1 /* 2 Copyright (c) 2003-200 6 Gino van den Bergen / Erwin Coumans http://continuousphysics.com/Bullet/2 Copyright (c) 2003-2009 Erwin Coumans http://bullet.googlecode.com 3 3 4 4 This software is provided 'as-is', without any express or implied warranty. … … 18 18 #define SIMD___SCALAR_H 19 19 20 #ifdef BT_MANAGED_CODE 21 //Aligned data types not supported in managed code 22 #pragma unmanaged 23 #endif 24 25 20 26 #include <math.h> 21 22 27 #include <stdlib.h>//size_t for MSVC 6.0 23 24 28 #include <cstdlib> 25 29 #include <cfloat> 26 30 #include <float.h> 27 31 28 #define BT_BULLET_VERSION 274 32 /* SVN $Revision$ on $Date$ from http://bullet.googlecode.com*/ 33 #define BT_BULLET_VERSION 277 29 34 30 35 inline int btGetVersion() … … 38 43 39 44 40 #ifdef WIN3245 #ifdef _WIN32 41 46 42 47 #if defined(__MINGW32__) || defined(__CYGWIN__) || (defined (_MSC_VER) && _MSC_VER < 1300) … … 44 49 #define SIMD_FORCE_INLINE inline 45 50 #define ATTRIBUTE_ALIGNED16(a) a 51 #define ATTRIBUTE_ALIGNED64(a) a 46 52 #define ATTRIBUTE_ALIGNED128(a) a 47 53 #else … … 54 60 #define SIMD_FORCE_INLINE __forceinline 55 61 #define ATTRIBUTE_ALIGNED16(a) __declspec(align(16)) a 62 #define ATTRIBUTE_ALIGNED64(a) __declspec(align(64)) a 56 63 #define ATTRIBUTE_ALIGNED128(a) __declspec (align(128)) a 57 64 #ifdef _XBOX … … 63 70 #else 64 71 65 #if (defined ( WIN32) && (_MSC_VER) && _MSC_VER >= 1400) && (!defined (BT_USE_DOUBLE_PRECISION))72 #if (defined (_WIN32) && (_MSC_VER) && _MSC_VER >= 1400) && (!defined (BT_USE_DOUBLE_PRECISION)) 66 73 #define BT_USE_SSE 67 74 #include <emmintrin.h> … … 87 94 88 95 #if defined (__CELLOS_LV2__) 89 #define SIMD_FORCE_INLINE inline 96 #define SIMD_FORCE_INLINE inline __attribute__((always_inline)) 90 97 #define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16))) 98 #define ATTRIBUTE_ALIGNED64(a) a __attribute__ ((aligned (64))) 99 #define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128))) 100 #ifndef assert 101 #include <assert.h> 102 #endif 103 #ifdef BT_DEBUG 104 #ifdef __SPU__ 105 #include <spu_printf.h> 106 #define printf spu_printf 107 #define btAssert(x) {if(!(x)){printf("Assert "__FILE__ ":%u ("#x")\n", __LINE__);spu_hcmpeq(0,0);}} 108 #else 109 #define btAssert assert 110 #endif 111 112 #else 113 #define btAssert(x) 114 #endif 115 //btFullAssert is optional, slows down a lot 116 #define btFullAssert(x) 117 118 #define btLikely(_c) _c 119 #define btUnlikely(_c) _c 120 121 #else 122 123 #ifdef USE_LIBSPE2 124 125 #define SIMD_FORCE_INLINE __inline 126 #define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16))) 127 #define ATTRIBUTE_ALIGNED64(a) a __attribute__ ((aligned (64))) 91 128 #define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128))) 92 129 #ifndef assert … … 101 138 #define btFullAssert(x) 102 139 103 #define btLikely(_c) _c104 #define btUnlikely(_c) _c105 106 #else107 108 #ifdef USE_LIBSPE2109 110 #define SIMD_FORCE_INLINE __inline111 #define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16)))112 #define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128)))113 #ifndef assert114 #include <assert.h>115 #endif116 #ifdef BT_DEBUG117 #define btAssert assert118 #else119 #define btAssert(x)120 #endif121 //btFullAssert is optional, slows down a lot122 #define btFullAssert(x)123 124 140 125 141 #define btLikely(_c) __builtin_expect((_c), 1) … … 130 146 //non-windows systems 131 147 148 #if (defined (__APPLE__) && defined (__i386__) && (!defined (BT_USE_DOUBLE_PRECISION))) 149 #define BT_USE_SSE 150 #include <emmintrin.h> 151 152 #define SIMD_FORCE_INLINE inline 153 ///@todo: check out alignment methods for other platforms/compilers 154 #define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16))) 155 #define ATTRIBUTE_ALIGNED64(a) a __attribute__ ((aligned (64))) 156 #define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128))) 157 #ifndef assert 158 #include <assert.h> 159 #endif 160 161 #if defined(DEBUG) || defined (_DEBUG) 162 #define btAssert assert 163 #else 164 #define btAssert(x) 165 #endif 166 167 //btFullAssert is optional, slows down a lot 168 #define btFullAssert(x) 169 #define btLikely(_c) _c 170 #define btUnlikely(_c) _c 171 172 #else 173 132 174 #define SIMD_FORCE_INLINE inline 133 175 ///@todo: check out alignment methods for other platforms/compilers 134 176 ///#define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16))) 177 ///#define ATTRIBUTE_ALIGNED64(a) a __attribute__ ((aligned (64))) 135 178 ///#define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128))) 136 179 #define ATTRIBUTE_ALIGNED16(a) a 180 #define ATTRIBUTE_ALIGNED64(a) a 137 181 #define ATTRIBUTE_ALIGNED128(a) a 138 182 #ifndef assert … … 150 194 #define btLikely(_c) _c 151 195 #define btUnlikely(_c) _c 152 196 #endif //__APPLE__ 153 197 154 198 #endif // LIBSPE2 … … 157 201 #endif 158 202 159 /// older compilers (gcc 3.x) and Sun needs double version of sqrt etc.160 /// exclude Apple Intel (i's assumed to be a Macbook or new Intel Dual Core Processor)161 #if defined (__sun) || defined (__sun__) || defined (__sparc) || (defined (__APPLE__) && ! defined (__i386__))162 //use slow double float precision operation on those platforms163 #ifndef BT_USE_DOUBLE_PRECISION164 #define BT_FORCE_DOUBLE_FUNCTIONS165 #endif166 #endif167 203 168 204 ///The btScalar type abstracts floating point numbers, to easily switch between double and single floating point precision. 169 205 #if defined(BT_USE_DOUBLE_PRECISION) 170 206 typedef double btScalar; 207 //this number could be bigger in double precision 208 #define BT_LARGE_FLOAT 1e30 171 209 #else 172 210 typedef float btScalar; 211 //keep BT_LARGE_FLOAT*BT_LARGE_FLOAT < FLT_MAX 212 #define BT_LARGE_FLOAT 1e18f 173 213 #endif 174 214 … … 194 234 SIMD_FORCE_INLINE btScalar btSin(btScalar x) { return sin(x); } 195 235 SIMD_FORCE_INLINE btScalar btTan(btScalar x) { return tan(x); } 196 SIMD_FORCE_INLINE btScalar btAcos(btScalar x) { return acos(x); }197 SIMD_FORCE_INLINE btScalar btAsin(btScalar x) { return asin(x); }236 SIMD_FORCE_INLINE btScalar btAcos(btScalar x) { if (x<btScalar(-1)) x=btScalar(-1); if (x>btScalar(1)) x=btScalar(1); return acos(x); } 237 SIMD_FORCE_INLINE btScalar btAsin(btScalar x) { if (x<btScalar(-1)) x=btScalar(-1); if (x>btScalar(1)) x=btScalar(1); return asin(x); } 198 238 SIMD_FORCE_INLINE btScalar btAtan(btScalar x) { return atan(x); } 199 239 SIMD_FORCE_INLINE btScalar btAtan2(btScalar x, btScalar y) { return atan2(x, y); } … … 201 241 SIMD_FORCE_INLINE btScalar btLog(btScalar x) { return log(x); } 202 242 SIMD_FORCE_INLINE btScalar btPow(btScalar x,btScalar y) { return pow(x,y); } 243 SIMD_FORCE_INLINE btScalar btFmod(btScalar x,btScalar y) { return fmod(x,y); } 203 244 204 245 #else … … 213 254 *tfptr = (0xbfcdd90a - *tfptr)>>1; /* estimate of 1/sqrt(y) */ 214 255 x = tempf; 215 z = y*btScalar(0.5); /* hoist out the /2 */256 z = y*btScalar(0.5); 216 257 x = (btScalar(1.5)*x)-(x*x)*(x*z); /* iteration formula */ 217 258 x = (btScalar(1.5)*x)-(x*x)*(x*z); … … 229 270 SIMD_FORCE_INLINE btScalar btTan(btScalar x) { return tanf(x); } 230 271 SIMD_FORCE_INLINE btScalar btAcos(btScalar x) { 231 btAssert(x <= btScalar(1.)); 272 if (x<btScalar(-1)) 273 x=btScalar(-1); 274 if (x>btScalar(1)) 275 x=btScalar(1); 232 276 return acosf(x); 233 277 } 234 SIMD_FORCE_INLINE btScalar btAsin(btScalar x) { return asinf(x); } 278 SIMD_FORCE_INLINE btScalar btAsin(btScalar x) { 279 if (x<btScalar(-1)) 280 x=btScalar(-1); 281 if (x>btScalar(1)) 282 x=btScalar(1); 283 return asinf(x); 284 } 235 285 SIMD_FORCE_INLINE btScalar btAtan(btScalar x) { return atanf(x); } 236 286 SIMD_FORCE_INLINE btScalar btAtan2(btScalar x, btScalar y) { return atan2f(x, y); } … … 242 292 SIMD_FORCE_INLINE btScalar btPow(btScalar x,btScalar y) { return powf(x,y); } 243 293 #endif 294 SIMD_FORCE_INLINE btScalar btFmod(btScalar x,btScalar y) { return fmodf(x,y); } 244 295 245 296 #endif … … 250 301 #define SIMD_RADS_PER_DEG (SIMD_2_PI / btScalar(360.0)) 251 302 #define SIMD_DEGS_PER_RAD (btScalar(360.0) / SIMD_2_PI) 303 #define SIMDSQRT12 btScalar(0.7071067811865475244008443621048490) 304 305 #define btRecipSqrt(x) ((btScalar)(btScalar(1.0)/btSqrt(btScalar(x)))) /* reciprocal square root */ 306 252 307 253 308 #ifdef BT_USE_DOUBLE_PRECISION … … 440 495 } 441 496 442 497 // returns normalized value in range [-SIMD_PI, SIMD_PI] 498 SIMD_FORCE_INLINE btScalar btNormalizeAngle(btScalar angleInRadians) 499 { 500 angleInRadians = btFmod(angleInRadians, SIMD_2_PI); 501 if(angleInRadians < -SIMD_PI) 502 { 503 return angleInRadians + SIMD_2_PI; 504 } 505 else if(angleInRadians > SIMD_PI) 506 { 507 return angleInRadians - SIMD_2_PI; 508 } 509 else 510 { 511 return angleInRadians; 512 } 513 } 514 515 ///rudimentary class to provide type info 516 struct btTypedObject 517 { 518 btTypedObject(int objectType) 519 :m_objectType(objectType) 520 { 521 } 522 int m_objectType; 523 inline int getObjectType() const 524 { 525 return m_objectType; 526 } 527 }; 443 528 #endif //SIMD___SCALAR_H
Note: See TracChangeset
for help on using the changeset viewer.