Changeset 2472 for code/branches/presentation/src/bullet
- Timestamp:
- Dec 15, 2008, 10:20:59 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation/src/bullet/LinearMath/btScalar.h
r2471 r2472 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); } … … 250 250 #endif 251 251 252 SIMD_FORCE_INLINE btScalar btAtan2Fast(btScalar y, btScalar x) 252 SIMD_FORCE_INLINE btScalar btAtan2Fast(btScalar y, btScalar x) 253 253 { 254 254 btScalar coeff_1 = SIMD_PI / 4.0f; … … 308 308 ///btSelect avoids branches, which makes performance much better for consoles like Playstation 3 and XBox 360 309 309 ///Thanks Phil Knight. See also http://www.cellperformance.com/articles/2006/04/more_techniques_for_eliminatin_1.html 310 SIMD_FORCE_INLINE unsigned btSelect(unsigned condition, unsigned valueIfConditionNonZero, unsigned valueIfConditionZero) 310 SIMD_FORCE_INLINE unsigned btSelect(unsigned condition, unsigned valueIfConditionNonZero, unsigned valueIfConditionZero) 311 311 { 312 312 // Set testNz to 0xFFFFFFFF if condition is nonzero, 0x00000000 if condition is zero 313 313 // Rely on positive value or'ed with its negative having sign bit on 314 // 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 315 315 // Use arithmetic shift right, shifting the sign bit through all 32 bits 316 316 unsigned testNz = (unsigned)(((int)condition | -(int)condition) >> 31); 317 317 unsigned testEqz = ~testNz; 318 return ((valueIfConditionNonZero & testNz) | (valueIfConditionZero & testEqz)); 318 return ((valueIfConditionNonZero & testNz) | (valueIfConditionZero & testEqz)); 319 319 } 320 320 SIMD_FORCE_INLINE int btSelect(unsigned condition, int valueIfConditionNonZero, int valueIfConditionZero) 321 321 { 322 322 unsigned testNz = (unsigned)(((int)condition | -(int)condition) >> 31); 323 unsigned testEqz = ~testNz; 323 unsigned testEqz = ~testNz; 324 324 return static_cast<int>((valueIfConditionNonZero & testNz) | (valueIfConditionZero & testEqz)); 325 325 } … … 329 329 return (float)btFsel((btScalar)condition - btScalar(1.0f), valueIfConditionNonZero, valueIfConditionZero); 330 330 #else 331 return (condition != 0) ? valueIfConditionNonZero : valueIfConditionZero; 331 return (condition != 0) ? valueIfConditionNonZero : valueIfConditionZero; 332 332 #endif 333 333 } … … 364 364 ///btSwapFloat uses using char pointers to swap the endianness 365 365 ////btSwapFloat/btSwapDouble will NOT return a float, because the machine might 'correct' invalid floating point values 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. 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. 369 369 ///so instead of returning a float/double, we return integer/long long integer 370 370 SIMD_FORCE_INLINE unsigned int btSwapEndianFloat(float d) … … 382 382 383 383 // unswap using char pointers 384 SIMD_FORCE_INLINE float btUnswapEndianFloat(unsigned int a) 384 SIMD_FORCE_INLINE float btUnswapEndianFloat(unsigned int a) 385 385 { 386 386 float d = 0.0f; … … 414 414 415 415 // unswap using char pointers 416 SIMD_FORCE_INLINE double btUnswapEndianDouble(const unsigned char *src) 416 SIMD_FORCE_INLINE double btUnswapEndianDouble(const unsigned char *src) 417 417 { 418 418 double d = 0.0;
Note: See TracChangeset
for help on using the changeset viewer.