Back to index

supertuxkart  0.5+dfsg1
Defines | Typedefs | Functions
btScalar.h File Reference
#include <math.h>
#include <cstdlib>
#include <cfloat>
#include <float.h>
#include <assert.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define BT_BULLET_VERSION   268
#define SIMD_FORCE_INLINE   inline
#define ATTRIBUTE_ALIGNED16(a)   a
#define ATTRIBUTE_ALIGNED128(a)   a
#define btAssert   assert
#define btFullAssert(x)
#define btLikely(_c)   _c
#define btUnlikely(_c)   _c
#define BT_DECLARE_ALIGNED_ALLOCATOR()
#define SIMD_2_PI   btScalar(6.283185307179586232)
#define SIMD_PI   (SIMD_2_PI * btScalar(0.5))
#define SIMD_HALF_PI   (SIMD_2_PI * btScalar(0.25))
#define SIMD_RADS_PER_DEG   (SIMD_2_PI / btScalar(360.0))
#define SIMD_DEGS_PER_RAD   (btScalar(360.0) / SIMD_2_PI)
#define SIMD_EPSILON   FLT_EPSILON
#define SIMD_INFINITY   FLT_MAX
#define BT_DECLARE_HANDLE(name)   typedef struct name##__ { int unused; } *name
#define btFsels(a, b, c)   (btScalar)btFsel(a,b,c)

Typedefs

typedef float btScalar
 older compilers (gcc 3.x) and Sun needs double version of sqrt etc. exclude Apple Intel (i's assumed to be a Macbook or new Intel Dual Core Processor)

Functions

int btGetVersion ()
SIMD_FORCE_INLINE btScalar btSqrt (btScalar y)
SIMD_FORCE_INLINE btScalar btFabs (btScalar x)
SIMD_FORCE_INLINE btScalar btCos (btScalar x)
SIMD_FORCE_INLINE btScalar btSin (btScalar x)
SIMD_FORCE_INLINE btScalar btTan (btScalar x)
SIMD_FORCE_INLINE btScalar btAcos (btScalar x)
SIMD_FORCE_INLINE btScalar btAsin (btScalar x)
SIMD_FORCE_INLINE btScalar btAtan (btScalar x)
SIMD_FORCE_INLINE btScalar btAtan2 (btScalar x, btScalar y)
SIMD_FORCE_INLINE btScalar btExp (btScalar x)
SIMD_FORCE_INLINE btScalar btLog (btScalar x)
SIMD_FORCE_INLINE btScalar btPow (btScalar x, btScalar y)
SIMD_FORCE_INLINE btScalar btAtan2Fast (btScalar y, btScalar x)
SIMD_FORCE_INLINE bool btFuzzyZero (btScalar x)
SIMD_FORCE_INLINE bool btEqual (btScalar a, btScalar eps)
SIMD_FORCE_INLINE bool btGreaterEqual (btScalar a, btScalar eps)
SIMD_FORCE_INLINE int btIsNegative (btScalar x)
SIMD_FORCE_INLINE btScalar btRadians (btScalar x)
SIMD_FORCE_INLINE btScalar btDegrees (btScalar x)
SIMD_FORCE_INLINE btScalar btFsel (btScalar a, btScalar b, btScalar c)
SIMD_FORCE_INLINE bool btMachineIsLittleEndian ()
SIMD_FORCE_INLINE unsigned btSelect (unsigned condition, unsigned valueIfConditionNonZero, unsigned valueIfConditionZero)
 btSelect avoids branches, which makes performance much better for consoles like Playstation 3 and XBox 360 Thanks Phil Knight. See also http://www.cellperformance.com/articles/2006/04/more_techniques_for_eliminatin_1.html
SIMD_FORCE_INLINE int btSelect (unsigned condition, int valueIfConditionNonZero, int valueIfConditionZero)
SIMD_FORCE_INLINE float btSelect (unsigned condition, float valueIfConditionNonZero, float valueIfConditionZero)
template<typename T >
SIMD_FORCE_INLINE void btSwap (T &a, T &b)
SIMD_FORCE_INLINE unsigned btSwapEndian (unsigned val)
SIMD_FORCE_INLINE unsigned short btSwapEndian (unsigned short val)
SIMD_FORCE_INLINE unsigned btSwapEndian (int val)
SIMD_FORCE_INLINE unsigned short btSwapEndian (short val)
SIMD_FORCE_INLINE unsigned int btSwapEndianFloat (float d)
 btSwapFloat uses using char pointers to swap the endianness /btSwapFloat/btSwapDouble will NOT return a float, because the machine might 'correct' invalid floating point values Not all values of sign/exponent/mantissa are valid floating point numbers according to IEEE 754. When a floating point unit is faced with an invalid value, it may actually change the value, or worse, throw an exception. 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. so instead of returning a float/double, we return integer/long long integer
SIMD_FORCE_INLINE float btUnswapEndianFloat (unsigned int a)
SIMD_FORCE_INLINE void btSwapEndianDouble (double d, unsigned char *dst)
SIMD_FORCE_INLINE double btUnswapEndianDouble (const unsigned char *src)

Define Documentation

#define ATTRIBUTE_ALIGNED128 (   a)    a

Definition at line 112 of file btScalar.h.

#define ATTRIBUTE_ALIGNED16 (   a)    a

Definition at line 111 of file btScalar.h.

#define BT_BULLET_VERSION   268

Definition at line 26 of file btScalar.h.

Value:
SIMD_FORCE_INLINE void* operator new(size_t sizeInBytes)       { return btAlignedAlloc(sizeInBytes,16); }       \
       SIMD_FORCE_INLINE void  operator delete(void* ptr)                    { btAlignedFree(ptr); }     \
       SIMD_FORCE_INLINE void* operator new(size_t, void* ptr) { return ptr; }      \
       SIMD_FORCE_INLINE void  operator delete(void*, void*)          { }    \

Definition at line 144 of file btScalar.h.

#define BT_DECLARE_HANDLE (   name)    typedef struct name##__ { int unused; } *name

Definition at line 253 of file btScalar.h.

#define btAssert   assert

Definition at line 116 of file btScalar.h.

#define btFsels (   a,
  b,
 
)    (btScalar)btFsel(a,b,c)

Definition at line 261 of file btScalar.h.

#define btFullAssert (   x)

Definition at line 118 of file btScalar.h.

#define btLikely (   _c)    _c

Definition at line 119 of file btScalar.h.

#define btUnlikely (   _c)    _c

Definition at line 120 of file btScalar.h.

#define SIMD_2_PI   btScalar(6.283185307179586232)

Definition at line 206 of file btScalar.h.

#define SIMD_DEGS_PER_RAD   (btScalar(360.0) / SIMD_2_PI)

Definition at line 210 of file btScalar.h.

#define SIMD_EPSILON   FLT_EPSILON

Definition at line 216 of file btScalar.h.

#define SIMD_FORCE_INLINE   inline

Definition at line 110 of file btScalar.h.

#define SIMD_HALF_PI   (SIMD_2_PI * btScalar(0.25))

Definition at line 208 of file btScalar.h.

#define SIMD_INFINITY   FLT_MAX

Definition at line 217 of file btScalar.h.

#define SIMD_PI   (SIMD_2_PI * btScalar(0.5))

Definition at line 207 of file btScalar.h.

#define SIMD_RADS_PER_DEG   (SIMD_2_PI / btScalar(360.0))

Definition at line 209 of file btScalar.h.


Typedef Documentation

typedef float btScalar

older compilers (gcc 3.x) and Sun needs double version of sqrt etc. exclude Apple Intel (i's assumed to be a Macbook or new Intel Dual Core Processor)

Definition at line 140 of file btScalar.h.


Function Documentation

Definition at line 193 of file btScalar.h.

                                              { 
       btAssert(x <= btScalar(1.));
       return acosf(x); 
}

Here is the caller graph for this function:

Definition at line 197 of file btScalar.h.

{ return asinf(x); }

Here is the caller graph for this function:

Definition at line 198 of file btScalar.h.

{ return atanf(x); }

Definition at line 199 of file btScalar.h.

{ return atan2f(x, y); }

Here is the caller graph for this function:

Definition at line 220 of file btScalar.h.

{
       btScalar coeff_1 = SIMD_PI / 4.0f;
       btScalar coeff_2 = 3.0f * coeff_1;
       btScalar abs_y = btFabs(y);
       btScalar angle;
       if (x >= 0.0f) {
              btScalar r = (x - abs_y) / (x + abs_y);
              angle = coeff_1 - coeff_1 * r;
       } else {
              btScalar r = (x + abs_y) / (abs_y - x);
              angle = coeff_2 - coeff_1 * r;
       }
       return (y < 0.0f) ? -angle : angle;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 190 of file btScalar.h.

{ return cosf(x); }

Here is the caller graph for this function:

Definition at line 251 of file btScalar.h.

{ return x * SIMD_DEGS_PER_RAD; }
SIMD_FORCE_INLINE bool btEqual ( btScalar  a,
btScalar  eps 
)

Definition at line 238 of file btScalar.h.

                                                              {
       return (((a) <= eps) && !((a) < -eps));
}

Definition at line 200 of file btScalar.h.

{ return expf(x); }

Definition at line 189 of file btScalar.h.

{ return fabsf(x); }

Here is the caller graph for this function:

Definition at line 256 of file btScalar.h.

{
       return a >= 0 ? b : c;
}

Here is the caller graph for this function:

Definition at line 236 of file btScalar.h.

{ return btFabs(x) < SIMD_EPSILON; }

Here is the call graph for this function:

Here is the caller graph for this function:

int btGetVersion ( ) [inline]

Definition at line 28 of file btScalar.h.

{
       return BT_BULLET_VERSION;
}

Definition at line 241 of file btScalar.h.

                                                                      {
       return (!((a) <= eps));
}

Definition at line 246 of file btScalar.h.

                                                     {
    return x < btScalar(0.0) ? 1 : 0;
}

Definition at line 201 of file btScalar.h.

{ return logf(x); }

Definition at line 264 of file btScalar.h.

{
   long int i = 1;
   const char *p = (const char *) &i;
   if (p[0] == 1)  // Lowest address contains the least significant byte
          return true;
   else
          return false;
}

Definition at line 202 of file btScalar.h.

{ return powf(x,y); }

Definition at line 250 of file btScalar.h.

{ return x * SIMD_RADS_PER_DEG; }
SIMD_FORCE_INLINE unsigned btSelect ( unsigned  condition,
unsigned  valueIfConditionNonZero,
unsigned  valueIfConditionZero 
)

btSelect avoids branches, which makes performance much better for consoles like Playstation 3 and XBox 360 Thanks Phil Knight. See also http://www.cellperformance.com/articles/2006/04/more_techniques_for_eliminatin_1.html

Definition at line 278 of file btScalar.h.

{
    // Set testNz to 0xFFFFFFFF if condition is nonzero, 0x00000000 if condition is zero
    // Rely on positive value or'ed with its negative having sign bit on
    // and zero value or'ed with its negative (which is still zero) having sign bit off 
    // Use arithmetic shift right, shifting the sign bit through all 32 bits
    unsigned testNz = (unsigned)(((int)condition | -(int)condition) >> 31);
    unsigned testEqz = ~testNz;
    return ((valueIfConditionNonZero & testNz) | (valueIfConditionZero & testEqz)); 
}
SIMD_FORCE_INLINE int btSelect ( unsigned  condition,
int  valueIfConditionNonZero,
int  valueIfConditionZero 
)

Definition at line 288 of file btScalar.h.

{
    unsigned testNz = (unsigned)(((int)condition | -(int)condition) >> 31);
    unsigned testEqz = ~testNz; 
    return ((valueIfConditionNonZero & testNz) | (valueIfConditionZero & testEqz));
}
SIMD_FORCE_INLINE float btSelect ( unsigned  condition,
float  valueIfConditionNonZero,
float  valueIfConditionZero 
)

Definition at line 294 of file btScalar.h.

{
#ifdef BT_HAVE_NATIVE_FSEL
    return (float)btFsel((btScalar)condition - btScalar(1.0f), valueIfConditionNonZero, valueIfConditionZero);
#else
    return (condition != 0) ? valueIfConditionNonZero : valueIfConditionZero; 
#endif
}

Here is the call graph for this function:

Definition at line 191 of file btScalar.h.

{ return sinf(x); }

Here is the caller graph for this function:

Definition at line 169 of file btScalar.h.

{ 
#ifdef USE_APPROXIMATION
    double x, z, tempf;
    unsigned long *tfptr = ((unsigned long *)&tempf) + 1;

       tempf = y;
       *tfptr = (0xbfcdd90a - *tfptr)>>1; /* estimate of 1/sqrt(y) */
       x =  tempf;
       z =  y*btScalar(0.5);                        /* hoist out the /2    */
       x = (btScalar(1.5)*x)-(x*x)*(x*z);         /* iteration formula     */
       x = (btScalar(1.5)*x)-(x*x)*(x*z);
       x = (btScalar(1.5)*x)-(x*x)*(x*z);
       x = (btScalar(1.5)*x)-(x*x)*(x*z);
       x = (btScalar(1.5)*x)-(x*x)*(x*z);
       return x*y;
#else
       return sqrtf(y); 
#endif
}

Here is the caller graph for this function:

template<typename T >
SIMD_FORCE_INLINE void btSwap ( T &  a,
T &  b 
)

Definition at line 303 of file btScalar.h.

{
       T tmp = a;
       a = b;
       b = tmp;
}

Here is the caller graph for this function:

SIMD_FORCE_INLINE unsigned btSwapEndian ( unsigned  val)

Definition at line 312 of file btScalar.h.

{
       return (((val & 0xff000000) >> 24) | ((val & 0x00ff0000) >> 8) | ((val & 0x0000ff00) << 8)  | ((val & 0x000000ff) << 24));
}

Here is the caller graph for this function:

SIMD_FORCE_INLINE unsigned short btSwapEndian ( unsigned short  val)

Definition at line 317 of file btScalar.h.

{
       return (((val & 0xff00) >> 8) | ((val & 0x00ff) << 8));
}
SIMD_FORCE_INLINE unsigned btSwapEndian ( int  val)

Definition at line 322 of file btScalar.h.

{
       return btSwapEndian((unsigned)val);
}

Here is the call graph for this function:

SIMD_FORCE_INLINE unsigned short btSwapEndian ( short  val)

Definition at line 327 of file btScalar.h.

{
       return btSwapEndian((unsigned short) val);
}

Here is the call graph for this function:

SIMD_FORCE_INLINE void btSwapEndianDouble ( double  d,
unsigned char *  dst 
)

Definition at line 368 of file btScalar.h.

{
    unsigned char *src = (unsigned char *)&d;

    dst[0] = src[7];
    dst[1] = src[6];
    dst[2] = src[5];
    dst[3] = src[4];
    dst[4] = src[3];
    dst[5] = src[2];
    dst[6] = src[1];
    dst[7] = src[0];

}
SIMD_FORCE_INLINE unsigned int btSwapEndianFloat ( float  d)

btSwapFloat uses using char pointers to swap the endianness /btSwapFloat/btSwapDouble will NOT return a float, because the machine might 'correct' invalid floating point values Not all values of sign/exponent/mantissa are valid floating point numbers according to IEEE 754. When a floating point unit is faced with an invalid value, it may actually change the value, or worse, throw an exception. 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. so instead of returning a float/double, we return integer/long long integer

Definition at line 338 of file btScalar.h.

{
    unsigned int a;
    unsigned char *dst = (unsigned char *)&a;
    unsigned char *src = (unsigned char *)&d;

    dst[0] = src[3];
    dst[1] = src[2];
    dst[2] = src[1];
    dst[3] = src[0];
    return a;
}

Definition at line 192 of file btScalar.h.

{ return tanf(x); }
SIMD_FORCE_INLINE double btUnswapEndianDouble ( const unsigned char *  src)

Definition at line 384 of file btScalar.h.

{
    double d;
    unsigned char *dst = (unsigned char *)&d;

    dst[0] = src[7];
    dst[1] = src[6];
    dst[2] = src[5];
    dst[3] = src[4];
    dst[4] = src[3];
    dst[5] = src[2];
    dst[6] = src[1];
    dst[7] = src[0];

       return d;
}
SIMD_FORCE_INLINE float btUnswapEndianFloat ( unsigned int  a)

Definition at line 352 of file btScalar.h.

{
    float d;
    unsigned char *src = (unsigned char *)&a;
    unsigned char *dst = (unsigned char *)&d;

    dst[0] = src[3];
    dst[1] = src[2];
    dst[2] = src[1];
    dst[3] = src[0];

    return d;
}