2 Copyright (c) 2003-2013 Gino van den Bergen / Erwin Coumans http://bulletphysics.org
4 This software is provided 'as-is', without any express or implied warranty.
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,
8 subject to the following restrictions:
10 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.
11 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
12 3. This notice may not be removed or altered from any source distribution.
15 #ifndef B3_SIMD_QUADWORD_H
16 #define B3_SIMD_QUADWORD_H
21 #if defined(__CELLOS_LV2) && defined(__SPU__)
25 /**@brief The b3QuadWord class is base class for b3Vector3 and b3Quaternion.
26 * Some issues under PS3 Linux with IBM 2.1 SDK, gcc compiler prevent from using aligned quadword.
29 B3_ATTRIBUTE_ALIGNED16(class)
36 #if defined(__SPU__) && defined(__CELLOS_LV2__)
43 vec_float4 get128() const
48 #else //__CELLOS_LV2__ __SPU__
50 #if defined(B3_USE_SSE) || defined(B3_USE_NEON)
62 B3_FORCE_INLINE b3SimdFloat4 get128() const
66 B3_FORCE_INLINE void set128(b3SimdFloat4 v128)
81 #endif //__CELLOS_LV2__ __SPU__
84 #if defined(B3_USE_SSE) || defined(B3_USE_NEON)
87 B3_FORCE_INLINE b3QuadWord(const b3SimdFloat4 vec)
93 B3_FORCE_INLINE b3QuadWord(const b3QuadWord& rhs)
95 mVec128 = rhs.mVec128;
98 // Assignment Operator
99 B3_FORCE_INLINE b3QuadWord&
100 operator=(const b3QuadWord& v)
109 /**@brief Return the x value */
110 B3_FORCE_INLINE const b3Scalar& getX() const { return m_floats[0]; }
111 /**@brief Return the y value */
112 B3_FORCE_INLINE const b3Scalar& getY() const { return m_floats[1]; }
113 /**@brief Return the z value */
114 B3_FORCE_INLINE const b3Scalar& getZ() const { return m_floats[2]; }
115 /**@brief Set the x value */
116 B3_FORCE_INLINE void setX(b3Scalar _x) { m_floats[0] = _x; };
117 /**@brief Set the y value */
118 B3_FORCE_INLINE void setY(b3Scalar _y) { m_floats[1] = _y; };
119 /**@brief Set the z value */
120 B3_FORCE_INLINE void setZ(b3Scalar _z) { m_floats[2] = _z; };
121 /**@brief Set the w value */
122 B3_FORCE_INLINE void setW(b3Scalar _w) { m_floats[3] = _w; };
123 /**@brief Return the x value */
125 //B3_FORCE_INLINE b3Scalar& operator[](int i) { return (&m_floats[0])[i]; }
126 //B3_FORCE_INLINE const b3Scalar& operator[](int i) const { return (&m_floats[0])[i]; }
127 ///operator b3Scalar*() replaces operator[], using implicit conversion. We added operator != and operator == to avoid pointer comparisons.
128 B3_FORCE_INLINE operator b3Scalar*() { return &m_floats[0]; }
129 B3_FORCE_INLINE operator const b3Scalar*() const { return &m_floats[0]; }
131 B3_FORCE_INLINE bool operator==(const b3QuadWord& other) const
134 return (0xf == _mm_movemask_ps((__m128)_mm_cmpeq_ps(mVec128, other.mVec128)));
136 return ((m_floats[3] == other.m_floats[3]) &&
137 (m_floats[2] == other.m_floats[2]) &&
138 (m_floats[1] == other.m_floats[1]) &&
139 (m_floats[0] == other.m_floats[0]));
143 B3_FORCE_INLINE bool operator!=(const b3QuadWord& other) const
145 return !(*this == other);
148 /**@brief Set x,y,z and zero w
149 * @param x Value of x
150 * @param y Value of y
151 * @param z Value of z
153 B3_FORCE_INLINE void setValue(const b3Scalar& _x, const b3Scalar& _y, const b3Scalar& _z)
161 /* void getValue(b3Scalar *m) const
168 /**@brief Set the values
169 * @param x Value of x
170 * @param y Value of y
171 * @param z Value of z
172 * @param w Value of w
174 B3_FORCE_INLINE void setValue(const b3Scalar& _x, const b3Scalar& _y, const b3Scalar& _z, const b3Scalar& _w)
181 /**@brief No initialization constructor */
182 B3_FORCE_INLINE b3QuadWord()
183 // :m_floats[0](b3Scalar(0.)),m_floats[1](b3Scalar(0.)),m_floats[2](b3Scalar(0.)),m_floats[3](b3Scalar(0.))
187 /**@brief Three argument constructor (zeros w)
188 * @param x Value of x
189 * @param y Value of y
190 * @param z Value of z
192 B3_FORCE_INLINE b3QuadWord(const b3Scalar& _x, const b3Scalar& _y, const b3Scalar& _z)
194 m_floats[0] = _x, m_floats[1] = _y, m_floats[2] = _z, m_floats[3] = 0.0f;
197 /**@brief Initializing constructor
198 * @param x Value of x
199 * @param y Value of y
200 * @param z Value of z
201 * @param w Value of w
203 B3_FORCE_INLINE b3QuadWord(const b3Scalar& _x, const b3Scalar& _y, const b3Scalar& _z, const b3Scalar& _w)
205 m_floats[0] = _x, m_floats[1] = _y, m_floats[2] = _z, m_floats[3] = _w;
208 /**@brief Set each element to the max of the current values and the values of another b3QuadWord
209 * @param other The other b3QuadWord to compare with
211 B3_FORCE_INLINE void setMax(const b3QuadWord& other)
214 mVec128 = _mm_max_ps(mVec128, other.mVec128);
215 #elif defined(B3_USE_NEON)
216 mVec128 = vmaxq_f32(mVec128, other.mVec128);
218 b3SetMax(m_floats[0], other.m_floats[0]);
219 b3SetMax(m_floats[1], other.m_floats[1]);
220 b3SetMax(m_floats[2], other.m_floats[2]);
221 b3SetMax(m_floats[3], other.m_floats[3]);
224 /**@brief Set each element to the min of the current values and the values of another b3QuadWord
225 * @param other The other b3QuadWord to compare with
227 B3_FORCE_INLINE void setMin(const b3QuadWord& other)
230 mVec128 = _mm_min_ps(mVec128, other.mVec128);
231 #elif defined(B3_USE_NEON)
232 mVec128 = vminq_f32(mVec128, other.mVec128);
234 b3SetMin(m_floats[0], other.m_floats[0]);
235 b3SetMin(m_floats[1], other.m_floats[1]);
236 b3SetMin(m_floats[2], other.m_floats[2]);
237 b3SetMin(m_floats[3], other.m_floats[3]);
242 #endif //B3_SIMD_QUADWORD_H