Changeset 2471
- Timestamp:
- Dec 15, 2008, 9:56:08 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation/src/bullet/LinearMath/btScalar.h
r2459 r2471 4 4 This software is provided 'as-is', without any express or implied warranty. 5 5 In no event will the authors be held liable for any damages arising from the use of this software. 6 Permission is granted to anyone to use this software for any purpose, 7 including commercial applications, and to alter it and redistribute it freely, 6 Permission is granted to anyone to use this software for any purpose, 7 including commercial applications, and to alter it and redistribute it freely, 8 8 subject to the following restrictions: 9 9 … … 79 79 80 80 #else 81 81 82 82 #if defined (__CELLOS_LV2__) 83 83 #define SIMD_FORCE_INLINE inline … … 119 119 #define btLikely(_c) __builtin_expect((_c), 1) 120 120 #define btUnlikely(_c) __builtin_expect((_c), 0) 121 121 122 122 123 123 #else … … 179 179 180 180 #if defined(BT_USE_DOUBLE_PRECISION) || defined(BT_FORCE_DOUBLE_FUNCTIONS) 181 181 182 182 SIMD_FORCE_INLINE btScalar btSqrt(btScalar x) { return sqrt(x); } 183 183 SIMD_FORCE_INLINE btScalar btFabs(btScalar x) { return fabs(x); } … … 194 194 195 195 #else 196 197 SIMD_FORCE_INLINE btScalar btSqrt(btScalar y) 198 { 196 197 SIMD_FORCE_INLINE btScalar btSqrt(btScalar y) 198 { 199 199 #ifdef USE_APPROXIMATION 200 200 double x, z, tempf; … … 212 212 return x*y; 213 213 #else 214 return sqrtf(y); 214 return sqrtf(y); 215 215 #endif 216 216 } … … 219 219 SIMD_FORCE_INLINE btScalar btSin(btScalar x) { return sinf(x); } 220 220 SIMD_FORCE_INLINE btScalar btTan(btScalar x) { return tanf(x); } 221 SIMD_FORCE_INLINE btScalar btAcos(btScalar x) { 221 SIMD_FORCE_INLINE btScalar btAcos(btScalar x) { 222 222 btAssert(x <= btScalar(1.)); 223 return acosf(x); 223 return acosf(x); 224 224 } 225 225 SIMD_FORCE_INLINE btScalar btAsin(btScalar x) { return asinf(x); } … … 228 228 SIMD_FORCE_INLINE btScalar btExp(btScalar x) { return expf(x); } 229 229 SIMD_FORCE_INLINE btScalar btLog(btScalar x) { return logf(x); } 230 SIMD_FORCE_INLINE btScalar btPow(btScalar x,btScalar y) { return powf(x,y); } 231 230 #if defined( __MINGW32__ ) 231 SIMD_FORCE_INLINE btScalar btPow(btScalar x,btScalar y) { return pow(x,y); } 232 #else 233 SIMD_FORCE_INLINE btScalar btPow(btScalar x,btScalar y) { return powf(x,y); } 234 #endif 235 232 236 #endif 233 237 … … 246 250 #endif 247 251 248 SIMD_FORCE_INLINE btScalar btAtan2Fast(btScalar y, btScalar x) 252 SIMD_FORCE_INLINE btScalar btAtan2Fast(btScalar y, btScalar x) 249 253 { 250 254 btScalar coeff_1 = SIMD_PI / 4.0f; … … 304 308 ///btSelect avoids branches, which makes performance much better for consoles like Playstation 3 and XBox 360 305 309 ///Thanks Phil Knight. See also http://www.cellperformance.com/articles/2006/04/more_techniques_for_eliminatin_1.html 306 SIMD_FORCE_INLINE unsigned btSelect(unsigned condition, unsigned valueIfConditionNonZero, unsigned valueIfConditionZero) 310 SIMD_FORCE_INLINE unsigned btSelect(unsigned condition, unsigned valueIfConditionNonZero, unsigned valueIfConditionZero) 307 311 { 308 312 // Set testNz to 0xFFFFFFFF if condition is nonzero, 0x00000000 if condition is zero 309 313 // Rely on positive value or'ed with its negative having sign bit on 310 // and zero value or'ed with its negative (which is still zero) having sign bit off 314 // and zero value or'ed with its negative (which is still zero) having sign bit off 311 315 // Use arithmetic shift right, shifting the sign bit through all 32 bits 312 316 unsigned testNz = (unsigned)(((int)condition | -(int)condition) >> 31); 313 317 unsigned testEqz = ~testNz; 314 return ((valueIfConditionNonZero & testNz) | (valueIfConditionZero & testEqz)); 318 return ((valueIfConditionNonZero & testNz) | (valueIfConditionZero & testEqz)); 315 319 } 316 320 SIMD_FORCE_INLINE int btSelect(unsigned condition, int valueIfConditionNonZero, int valueIfConditionZero) 317 321 { 318 322 unsigned testNz = (unsigned)(((int)condition | -(int)condition) >> 31); 319 unsigned testEqz = ~testNz; 323 unsigned testEqz = ~testNz; 320 324 return static_cast<int>((valueIfConditionNonZero & testNz) | (valueIfConditionZero & testEqz)); 321 325 } … … 325 329 return (float)btFsel((btScalar)condition - btScalar(1.0f), valueIfConditionNonZero, valueIfConditionZero); 326 330 #else 327 return (condition != 0) ? valueIfConditionNonZero : valueIfConditionZero; 331 return (condition != 0) ? valueIfConditionNonZero : valueIfConditionZero; 328 332 #endif 329 333 } … … 360 364 ///btSwapFloat uses using char pointers to swap the endianness 361 365 ////btSwapFloat/btSwapDouble will NOT return a float, because the machine might 'correct' invalid floating point values 362 ///Not all values of sign/exponent/mantissa are valid floating point numbers according to IEEE 754. 363 ///When a floating point unit is faced with an invalid value, it may actually change the value, or worse, throw an exception. 364 ///In most systems, running user mode code, you wouldn't get an exception, but instead the hardware/os/runtime will 'fix' the number for you. 366 ///Not all values of sign/exponent/mantissa are valid floating point numbers according to IEEE 754. 367 ///When a floating point unit is faced with an invalid value, it may actually change the value, or worse, throw an exception. 368 ///In most systems, running user mode code, you wouldn't get an exception, but instead the hardware/os/runtime will 'fix' the number for you. 365 369 ///so instead of returning a float/double, we return integer/long long integer 366 370 SIMD_FORCE_INLINE unsigned int btSwapEndianFloat(float d) … … 378 382 379 383 // unswap using char pointers 380 SIMD_FORCE_INLINE float btUnswapEndianFloat(unsigned int a) 384 SIMD_FORCE_INLINE float btUnswapEndianFloat(unsigned int a) 381 385 { 382 386 float d = 0.0f; … … 410 414 411 415 // unswap using char pointers 412 SIMD_FORCE_INLINE double btUnswapEndianDouble(const unsigned char *src) 416 SIMD_FORCE_INLINE double btUnswapEndianDouble(const unsigned char *src) 413 417 { 414 418 double d = 0.0;
Note: See TracChangeset
for help on using the changeset viewer.