btQuadWord.h

Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2003-2006 Gino van den Bergen / Erwin Coumans  http://continuousphysics.com/Bullet/
00003 
00004 This software is provided 'as-is', without any express or implied warranty.
00005 In no event will the authors be held liable for any damages arising from the use of this software.
00006 Permission is granted to anyone to use this software for any purpose, 
00007 including commercial applications, and to alter it and redistribute it freely, 
00008 subject to the following restrictions:
00009 
00010 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
00011 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
00012 3. This notice may not be removed or altered from any source distribution.
00013 */
00014 
00015 
00016 #ifndef BT_SIMD_QUADWORD_H
00017 #define BT_SIMD_QUADWORD_H
00018 
00019 #include "btScalar.h"
00020 #include "btMinMax.h"
00021 
00022 
00023 
00024 
00025 
00026 #if defined (__CELLOS_LV2) && defined (__SPU__)
00027 #include <altivec.h>
00028 #endif
00029 
00033 #ifndef USE_LIBSPE2
00034 ATTRIBUTE_ALIGNED16(class) btQuadWord
00035 #else
00036 class btQuadWord
00037 #endif
00038 {
00039 protected:
00040 
00041 #if defined (__SPU__) && defined (__CELLOS_LV2__)
00042         union {
00043                 vec_float4 mVec128;
00044                 btScalar        m_floats[4];
00045         };
00046 public:
00047         vec_float4      get128() const
00048         {
00049                 return mVec128;
00050         }
00051 protected:
00052 #else //__CELLOS_LV2__ __SPU__
00053 
00054 #if defined(BT_USE_SSE) || defined(BT_USE_NEON) 
00055         union {
00056                 btSimdFloat4 mVec128;
00057                 btScalar        m_floats[4];
00058         };
00059 public:
00060         SIMD_FORCE_INLINE       btSimdFloat4    get128() const
00061         {
00062                 return mVec128;
00063         }
00064         SIMD_FORCE_INLINE       void    set128(btSimdFloat4 v128)
00065         {
00066                 mVec128 = v128;
00067         }
00068 #else
00069         btScalar        m_floats[4];
00070 #endif // BT_USE_SSE
00071 
00072 #endif //__CELLOS_LV2__ __SPU__
00073 
00074         public:
00075   
00076 #if defined(BT_USE_SSE) || defined(BT_USE_NEON)
00077 
00078         // Set Vector 
00079         SIMD_FORCE_INLINE btQuadWord(const btSimdFloat4 vec)
00080         {
00081                 mVec128 = vec;
00082         }
00083 
00084         // Copy constructor
00085         SIMD_FORCE_INLINE btQuadWord(const btQuadWord& rhs)
00086         {
00087                 mVec128 = rhs.mVec128;
00088         }
00089 
00090         // Assignment Operator
00091         SIMD_FORCE_INLINE btQuadWord& 
00092         operator=(const btQuadWord& v) 
00093         {
00094                 mVec128 = v.mVec128;
00095                 
00096                 return *this;
00097         }
00098         
00099 #endif
00100 
00102                 SIMD_FORCE_INLINE const btScalar& getX() const { return m_floats[0]; }
00104                 SIMD_FORCE_INLINE const btScalar& getY() const { return m_floats[1]; }
00106                 SIMD_FORCE_INLINE const btScalar& getZ() const { return m_floats[2]; }
00108                 SIMD_FORCE_INLINE void  setX(btScalar _x) { m_floats[0] = _x;};
00110                 SIMD_FORCE_INLINE void  setY(btScalar _y) { m_floats[1] = _y;};
00112                 SIMD_FORCE_INLINE void  setZ(btScalar _z) { m_floats[2] = _z;};
00114                 SIMD_FORCE_INLINE void  setW(btScalar _w) { m_floats[3] = _w;};
00116                 SIMD_FORCE_INLINE const btScalar& x() const { return m_floats[0]; }
00118                 SIMD_FORCE_INLINE const btScalar& y() const { return m_floats[1]; }
00120                 SIMD_FORCE_INLINE const btScalar& z() const { return m_floats[2]; }
00122                 SIMD_FORCE_INLINE const btScalar& w() const { return m_floats[3]; }
00123 
00124         //SIMD_FORCE_INLINE btScalar&       operator[](int i)       { return (&m_floats[0])[i]; }      
00125         //SIMD_FORCE_INLINE const btScalar& operator[](int i) const { return (&m_floats[0])[i]; }
00127         SIMD_FORCE_INLINE       operator       btScalar *()       { return &m_floats[0]; }
00128         SIMD_FORCE_INLINE       operator const btScalar *() const { return &m_floats[0]; }
00129 
00130         SIMD_FORCE_INLINE       bool    operator==(const btQuadWord& other) const
00131         {
00132 #ifdef BT_USE_SSE
00133         return (0xf == _mm_movemask_ps((__m128)_mm_cmpeq_ps(mVec128, other.mVec128)));
00134 #else 
00135                 return ((m_floats[3]==other.m_floats[3]) && 
00136                 (m_floats[2]==other.m_floats[2]) && 
00137                 (m_floats[1]==other.m_floats[1]) && 
00138                 (m_floats[0]==other.m_floats[0]));
00139 #endif
00140         }
00141 
00142         SIMD_FORCE_INLINE       bool    operator!=(const btQuadWord& other) const
00143         {
00144                 return !(*this == other);
00145         }
00146 
00152                 SIMD_FORCE_INLINE void  setValue(const btScalar& _x, const btScalar& _y, const btScalar& _z)
00153                 {
00154                         m_floats[0]=_x;
00155                         m_floats[1]=_y;
00156                         m_floats[2]=_z;
00157                         m_floats[3] = 0.f;
00158                 }
00159 
00160 /*              void getValue(btScalar *m) const 
00161                 {
00162                         m[0] = m_floats[0];
00163                         m[1] = m_floats[1];
00164                         m[2] = m_floats[2];
00165                 }
00166 */
00173                 SIMD_FORCE_INLINE void  setValue(const btScalar& _x, const btScalar& _y, const btScalar& _z,const btScalar& _w)
00174                 {
00175                         m_floats[0]=_x;
00176                         m_floats[1]=_y;
00177                         m_floats[2]=_z;
00178                         m_floats[3]=_w;
00179                 }
00181                 SIMD_FORCE_INLINE btQuadWord()
00182                 //      :m_floats[0](btScalar(0.)),m_floats[1](btScalar(0.)),m_floats[2](btScalar(0.)),m_floats[3](btScalar(0.))
00183                 {
00184                 }
00185  
00191                 SIMD_FORCE_INLINE btQuadWord(const btScalar& _x, const btScalar& _y, const btScalar& _z)                
00192                 {
00193                         m_floats[0] = _x, m_floats[1] = _y, m_floats[2] = _z, m_floats[3] = 0.0f;
00194                 }
00195 
00202                 SIMD_FORCE_INLINE btQuadWord(const btScalar& _x, const btScalar& _y, const btScalar& _z,const btScalar& _w) 
00203                 {
00204                         m_floats[0] = _x, m_floats[1] = _y, m_floats[2] = _z, m_floats[3] = _w;
00205                 }
00206 
00210                 SIMD_FORCE_INLINE void  setMax(const btQuadWord& other)
00211                 {
00212         #ifdef BT_USE_SSE
00213             mVec128 = _mm_max_ps(mVec128, other.mVec128);
00214         #elif defined(BT_USE_NEON)
00215             mVec128 = vmaxq_f32(mVec128, other.mVec128);
00216         #else
00217                 btSetMax(m_floats[0], other.m_floats[0]);
00218                         btSetMax(m_floats[1], other.m_floats[1]);
00219                         btSetMax(m_floats[2], other.m_floats[2]);
00220                         btSetMax(m_floats[3], other.m_floats[3]);
00221                 #endif
00222         }
00226                 SIMD_FORCE_INLINE void  setMin(const btQuadWord& other)
00227                 {
00228         #ifdef BT_USE_SSE
00229             mVec128 = _mm_min_ps(mVec128, other.mVec128);
00230         #elif defined(BT_USE_NEON)
00231             mVec128 = vminq_f32(mVec128, other.mVec128);
00232         #else
00233                 btSetMin(m_floats[0], other.m_floats[0]);
00234                         btSetMin(m_floats[1], other.m_floats[1]);
00235                         btSetMin(m_floats[2], other.m_floats[2]);
00236                         btSetMin(m_floats[3], other.m_floats[3]);
00237                 #endif
00238         }
00239 
00240 
00241 
00242 };
00243 
00244 #endif //BT_SIMD_QUADWORD_H