Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
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
00079 SIMD_FORCE_INLINE btQuadWord(const btSimdFloat4 vec)
00080 {
00081 mVec128 = vec;
00082 }
00083
00084
00085 SIMD_FORCE_INLINE btQuadWord(const btQuadWord& rhs)
00086 {
00087 mVec128 = rhs.mVec128;
00088 }
00089
00090
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
00125
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
00161
00162
00163
00164
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
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