Bullet Collision Detection & Physics Library
btQuadWord.h
Go to the documentation of this file.
1/*
2Copyright (c) 2003-2006 Gino van den Bergen / Erwin Coumans https://bulletphysics.org
3
4This software is provided 'as-is', without any express or implied warranty.
5In no event will the authors be held liable for any damages arising from the use of this software.
6Permission is granted to anyone to use this software for any purpose,
7including commercial applications, and to alter it and redistribute it freely,
8subject to the following restrictions:
9
101. 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.
112. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
123. This notice may not be removed or altered from any source distribution.
13*/
14
15#ifndef BT_SIMD_QUADWORD_H
16#define BT_SIMD_QUADWORD_H
17
18#include "btScalar.h"
19#include "btMinMax.h"
20
21#if defined(__CELLOS_LV2) && defined(__SPU__)
22#include <altivec.h>
23#endif
24
28#ifndef USE_LIBSPE2
31#else
32class btQuadWord
33#endif
34{
35protected:
36#if defined(__SPU__) && defined(__CELLOS_LV2__)
37 union {
40 };
41
42public:
43 vec_float4 get128() const
44 {
45 return mVec128;
46 }
47
48protected:
49#else //__CELLOS_LV2__ __SPU__
50
51#if defined(BT_USE_SSE) || defined(BT_USE_NEON)
52 union {
55 };
56
57public:
59 {
60 return mVec128;
61 }
63 {
64 mVec128 = v128;
65 }
66#else
68#endif // BT_USE_SSE
69
70#endif //__CELLOS_LV2__ __SPU__
71
72public:
73#if (defined(BT_USE_SSE_IN_API) && defined(BT_USE_SSE)) || defined(BT_USE_NEON)
74
75 // Set Vector
77 {
78 mVec128 = vec;
79 }
80
81 // Copy constructor
83 {
84 mVec128 = rhs.mVec128;
85 }
86
87 // Assignment Operator
89 operator=(const btQuadWord& v)
90 {
91 mVec128 = v.mVec128;
92
93 return *this;
94 }
95
96#endif
97
99 SIMD_FORCE_INLINE const btScalar& getX() const { return m_floats[0]; }
101 SIMD_FORCE_INLINE const btScalar& getY() const { return m_floats[1]; }
103 SIMD_FORCE_INLINE const btScalar& getZ() const { return m_floats[2]; }
113 SIMD_FORCE_INLINE const btScalar& x() const { return m_floats[0]; }
115 SIMD_FORCE_INLINE const btScalar& y() const { return m_floats[1]; }
117 SIMD_FORCE_INLINE const btScalar& z() const { return m_floats[2]; }
119 SIMD_FORCE_INLINE const btScalar& w() const { return m_floats[3]; }
120
121 //SIMD_FORCE_INLINE btScalar& operator[](int i) { return (&m_floats[0])[i]; }
122 //SIMD_FORCE_INLINE const btScalar& operator[](int i) const { return (&m_floats[0])[i]; }
124 SIMD_FORCE_INLINE operator btScalar*() { return &m_floats[0]; }
125 SIMD_FORCE_INLINE operator const btScalar*() const { return &m_floats[0]; }
126
127 SIMD_FORCE_INLINE bool operator==(const btQuadWord& other) const
128 {
129#ifdef BT_USE_SSE
130 return (0xf == _mm_movemask_ps((__m128)_mm_cmpeq_ps(mVec128, other.mVec128)));
131#else
132 return ((m_floats[3] == other.m_floats[3]) &&
133 (m_floats[2] == other.m_floats[2]) &&
134 (m_floats[1] == other.m_floats[1]) &&
135 (m_floats[0] == other.m_floats[0]));
136#endif
137 }
138
139 SIMD_FORCE_INLINE bool operator!=(const btQuadWord& other) const
140 {
141 return !(*this == other);
142 }
143
150 {
151 m_floats[0] = _x;
152 m_floats[1] = _y;
153 m_floats[2] = _z;
154 m_floats[3] = 0.f;
155 }
156
157 /* void getValue(btScalar *m) const
158 {
159 m[0] = m_floats[0];
160 m[1] = m_floats[1];
161 m[2] = m_floats[2];
162 }
163*/
170 SIMD_FORCE_INLINE void setValue(const btScalar& _x, const btScalar& _y, const btScalar& _z, const btScalar& _w)
171 {
172 m_floats[0] = _x;
173 m_floats[1] = _y;
174 m_floats[2] = _z;
175 m_floats[3] = _w;
176 }
179 // :m_floats[0](btScalar(0.)),m_floats[1](btScalar(0.)),m_floats[2](btScalar(0.)),m_floats[3](btScalar(0.))
180 {
181 }
182
189 {
190 m_floats[0] = _x, m_floats[1] = _y, m_floats[2] = _z, m_floats[3] = 0.0f;
191 }
192
200 {
201 m_floats[0] = _x, m_floats[1] = _y, m_floats[2] = _z, m_floats[3] = _w;
202 }
203
208 {
209#ifdef BT_USE_SSE
210 mVec128 = _mm_max_ps(mVec128, other.mVec128);
211#elif defined(BT_USE_NEON)
212 mVec128 = vmaxq_f32(mVec128, other.mVec128);
213#else
214 btSetMax(m_floats[0], other.m_floats[0]);
215 btSetMax(m_floats[1], other.m_floats[1]);
216 btSetMax(m_floats[2], other.m_floats[2]);
217 btSetMax(m_floats[3], other.m_floats[3]);
218#endif
219 }
224 {
225#ifdef BT_USE_SSE
226 mVec128 = _mm_min_ps(mVec128, other.mVec128);
227#elif defined(BT_USE_NEON)
228 mVec128 = vminq_f32(mVec128, other.mVec128);
229#else
230 btSetMin(m_floats[0], other.m_floats[0]);
231 btSetMin(m_floats[1], other.m_floats[1]);
232 btSetMin(m_floats[2], other.m_floats[2]);
233 btSetMin(m_floats[3], other.m_floats[3]);
234#endif
235 }
236};
237
238#endif //BT_SIMD_QUADWORD_H
void btSetMin(T &a, const T &b)
Definition btMinMax.h:39
const T & btMax(const T &a, const T &b)
Definition btMinMax.h:27
void btSetMax(T &a, const T &b)
Definition btMinMax.h:48
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition btScalar.h:314
#define ATTRIBUTE_ALIGNED16(a)
Definition btScalar.h:99
#define SIMD_FORCE_INLINE
Definition btScalar.h:98
The btQuadWord class is base class for btVector3 and btQuaternion.
Definition btQuadWord.h:34
btQuadWord(const btScalar &_x, const btScalar &_y, const btScalar &_z)
Three argument constructor (zeros w)
Definition btQuadWord.h:188
const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
const btScalar & getY() const
Return the y value.
Definition btQuadWord.h:101
void setZ(btScalar _z)
Set the z value.
Definition btQuadWord.h:109
const btScalar & getX() const
Return the x value.
Definition btQuadWord.h:99
btScalar m_floats[4]
Definition btQuadWord.h:67
btQuadWord(const btScalar &_x, const btScalar &_y, const btScalar &_z, const btScalar &_w)
Initializing constructor.
Definition btQuadWord.h:199
void setW(btScalar _w)
Set the w value.
Definition btQuadWord.h:111
const btScalar & getZ() const
Return the z value.
Definition btQuadWord.h:103
void setMax(const btQuadWord &other)
Set each element to the max of the current values and the values of another btQuadWord.
Definition btQuadWord.h:207
const btScalar & z() const
Return the z value.
Definition btQuadWord.h:117
const btScalar & y() const
Return the y value.
Definition btQuadWord.h:115
void setMin(const btQuadWord &other)
Set each element to the min of the current values and the values of another btQuadWord.
Definition btQuadWord.h:223
bool operator==(const btQuadWord &other) const
Definition btQuadWord.h:127
void setY(btScalar _y)
Set the y value.
Definition btQuadWord.h:107
void setX(btScalar _x)
Set the x value.
Definition btQuadWord.h:105
btQuadWord()
No initialization constructor.
Definition btQuadWord.h:178
bool operator!=(const btQuadWord &other) const
Definition btQuadWord.h:139
void setValue(const btScalar &_x, const btScalar &_y, const btScalar &_z, const btScalar &_w)
Set the values.
Definition btQuadWord.h:170
void setValue(const btScalar &_x, const btScalar &_y, const btScalar &_z)
Set x,y,z and zero w.
Definition btQuadWord.h:149
const btScalar & x() const
Return the x value.
Definition btQuadWord.h:113