[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-physics / third-party / bullet3 / src / Bullet3Common / b3QuadWord.h
1 /*
2 Copyright (c) 2003-2013 Gino van den Bergen / Erwin Coumans  http://bulletphysics.org
3
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:
9
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.
13 */
14
15 #ifndef B3_SIMD_QUADWORD_H
16 #define B3_SIMD_QUADWORD_H
17
18 #include "b3Scalar.h"
19 #include "b3MinMax.h"
20
21 #if defined(__CELLOS_LV2) && defined(__SPU__)
22 #include <altivec.h>
23 #endif
24
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.
27  */
28 #ifndef USE_LIBSPE2
29 B3_ATTRIBUTE_ALIGNED16(class)
30 b3QuadWord
31 #else
32 class b3QuadWord
33 #endif
34 {
35 protected:
36 #if defined(__SPU__) && defined(__CELLOS_LV2__)
37         union {
38                 vec_float4 mVec128;
39                 b3Scalar m_floats[4];
40         };
41
42 public:
43         vec_float4 get128() const
44         {
45                 return mVec128;
46         }
47
48 #else  //__CELLOS_LV2__ __SPU__
49
50 #if defined(B3_USE_SSE) || defined(B3_USE_NEON)
51 public:
52         union {
53                 b3SimdFloat4 mVec128;
54                 b3Scalar m_floats[4];
55                 struct
56                 {
57                         b3Scalar x, y, z, w;
58                 };
59         };
60
61 public:
62         B3_FORCE_INLINE b3SimdFloat4 get128() const
63         {
64                 return mVec128;
65         }
66         B3_FORCE_INLINE void set128(b3SimdFloat4 v128)
67         {
68                 mVec128 = v128;
69         }
70 #else
71 public:
72         union {
73                 b3Scalar m_floats[4];
74                 struct
75                 {
76                         b3Scalar x, y, z, w;
77                 };
78         };
79 #endif  // B3_USE_SSE
80
81 #endif  //__CELLOS_LV2__ __SPU__
82
83 public:
84 #if defined(B3_USE_SSE) || defined(B3_USE_NEON)
85
86         // Set Vector
87         B3_FORCE_INLINE b3QuadWord(const b3SimdFloat4 vec)
88         {
89                 mVec128 = vec;
90         }
91
92         // Copy constructor
93         B3_FORCE_INLINE b3QuadWord(const b3QuadWord& rhs)
94         {
95                 mVec128 = rhs.mVec128;
96         }
97
98         // Assignment Operator
99         B3_FORCE_INLINE b3QuadWord&
100         operator=(const b3QuadWord& v)
101         {
102                 mVec128 = v.mVec128;
103
104                 return *this;
105         }
106
107 #endif
108
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 */
124
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]; }
130
131         B3_FORCE_INLINE bool operator==(const b3QuadWord& other) const
132         {
133 #ifdef B3_USE_SSE
134                 return (0xf == _mm_movemask_ps((__m128)_mm_cmpeq_ps(mVec128, other.mVec128)));
135 #else
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]));
140 #endif
141         }
142
143         B3_FORCE_INLINE bool operator!=(const b3QuadWord& other) const
144         {
145                 return !(*this == other);
146         }
147
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
152    */
153         B3_FORCE_INLINE void setValue(const b3Scalar& _x, const b3Scalar& _y, const b3Scalar& _z)
154         {
155                 m_floats[0] = _x;
156                 m_floats[1] = _y;
157                 m_floats[2] = _z;
158                 m_floats[3] = 0.f;
159         }
160
161         /*              void getValue(b3Scalar *m) const 
162                 {
163                         m[0] = m_floats[0];
164                         m[1] = m_floats[1];
165                         m[2] = m_floats[2];
166                 }
167 */
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
173    */
174         B3_FORCE_INLINE void setValue(const b3Scalar& _x, const b3Scalar& _y, const b3Scalar& _z, const b3Scalar& _w)
175         {
176                 m_floats[0] = _x;
177                 m_floats[1] = _y;
178                 m_floats[2] = _z;
179                 m_floats[3] = _w;
180         }
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.))
184         {
185         }
186
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
191    */
192         B3_FORCE_INLINE b3QuadWord(const b3Scalar& _x, const b3Scalar& _y, const b3Scalar& _z)
193         {
194                 m_floats[0] = _x, m_floats[1] = _y, m_floats[2] = _z, m_floats[3] = 0.0f;
195         }
196
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
202    */
203         B3_FORCE_INLINE b3QuadWord(const b3Scalar& _x, const b3Scalar& _y, const b3Scalar& _z, const b3Scalar& _w)
204         {
205                 m_floats[0] = _x, m_floats[1] = _y, m_floats[2] = _z, m_floats[3] = _w;
206         }
207
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 
210    */
211         B3_FORCE_INLINE void setMax(const b3QuadWord& other)
212         {
213 #ifdef B3_USE_SSE
214                 mVec128 = _mm_max_ps(mVec128, other.mVec128);
215 #elif defined(B3_USE_NEON)
216                 mVec128 = vmaxq_f32(mVec128, other.mVec128);
217 #else
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]);
222 #endif
223         }
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 
226    */
227         B3_FORCE_INLINE void setMin(const b3QuadWord& other)
228         {
229 #ifdef B3_USE_SSE
230                 mVec128 = _mm_min_ps(mVec128, other.mVec128);
231 #elif defined(B3_USE_NEON)
232                 mVec128 = vminq_f32(mVec128, other.mVec128);
233 #else
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]);
238 #endif
239         }
240 };
241
242 #endif  //B3_SIMD_QUADWORD_H