Debian Codegraph @

test/Bullet2/vectormath/sse/floatInVec.h

raw symbols SCIP
1 /*
2 Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
3 All rights reserved.
4
5 Redistribution and use in source and binary forms,
6 with or without modification, are permitted provided that the
7 following conditions are met:
8 * Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 * Neither the name of the Sony Computer Entertainment Inc nor the names
14 of its contributors may be used to endorse or promote products derived
15 from this software without specific prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #ifndef _FLOATINVEC_H
31 #define _FLOATINVEC_H
32
33 #include <math.h>
34 #include <xmmintrin.h>
35
36 namespace Vectormath
37 {
38 class boolInVec;
39
40 //--------------------------------------------------------------------------------------------------
41 // floatInVec class
42 //
43
44 class floatInVec
45 {
46 private:
47 __m128 mData;
48
49 public:
50 inline floatInVec(__m128 vec);
51
52 inline floatInVec() {}
53
54 // matches standard type conversions
55 //
56 inline floatInVec(const boolInVec &vec);
57
58 // construct from a slot of __m128
59 //
60 inline floatInVec(__m128 vec, int slot);
61
62 // explicit cast from float
63 //
64 explicit inline floatInVec(float scalar);
65
66 #ifdef _VECTORMATH_NO_SCALAR_CAST
67 // explicit cast to float
68 //
69 inline float getAsFloat() const;
70 #else
71 // implicit cast to float
72 //
73 inline operator float() const;
74 #endif
75
76 // get vector data
77 // float value is splatted across all word slots of vector
78 //
79 inline __m128 get128() const;
80
81 // operators
82 //
83 inline const floatInVec operator++(int);
84 inline const floatInVec operator--(int);
85 inline floatInVec &operator++();
86 inline floatInVec &operator--();
87 inline const floatInVec operator-() const;
88 inline floatInVec &operator=(const floatInVec &vec);
89 inline floatInVec &operator*=(const floatInVec &vec);
90 inline floatInVec &operator/=(const floatInVec &vec);
91 inline floatInVec &operator+=(const floatInVec &vec);
92 inline floatInVec &operator-=(const floatInVec &vec);
93
94 // friend functions
95 //
96 friend inline const floatInVec operator*(const floatInVec &vec0, const floatInVec &vec1);
97 friend inline const floatInVec operator/(const floatInVec &vec0, const floatInVec &vec1);
98 friend inline const floatInVec operator+(const floatInVec &vec0, const floatInVec &vec1);
99 friend inline const floatInVec operator-(const floatInVec &vec0, const floatInVec &vec1);
100 friend inline const floatInVec select(const floatInVec &vec0, const floatInVec &vec1, boolInVec select_vec1);
101 };
102
103 //--------------------------------------------------------------------------------------------------
104 // floatInVec functions
105 //
106
107 // operators
108 //
109 inline const floatInVec operator*(const floatInVec &vec0, const floatInVec &vec1);
110 inline const floatInVec operator/(const floatInVec &vec0, const floatInVec &vec1);
111 inline const floatInVec operator+(const floatInVec &vec0, const floatInVec &vec1);
112 inline const floatInVec operator-(const floatInVec &vec0, const floatInVec &vec1);
113 inline const boolInVec operator<(const floatInVec &vec0, const floatInVec &vec1);
114 inline const boolInVec operator<=(const floatInVec &vec0, const floatInVec &vec1);
115 inline const boolInVec operator>(const floatInVec &vec0, const floatInVec &vec1);
116 inline const boolInVec operator>=(const floatInVec &vec0, const floatInVec &vec1);
117 inline const boolInVec operator==(const floatInVec &vec0, const floatInVec &vec1);
118 inline const boolInVec operator!=(const floatInVec &vec0, const floatInVec &vec1);
119
120 // select between vec0 and vec1 using boolInVec.
121 // false selects vec0, true selects vec1
122 //
123 inline const floatInVec select(const floatInVec &vec0, const floatInVec &vec1, const boolInVec &select_vec1);
124
125 } // namespace Vectormath
126
127 //--------------------------------------------------------------------------------------------------
128 // floatInVec implementation
129 //
130
131 #include "boolInVec.h"
132
133 namespace Vectormath
134 {
135 inline floatInVec::floatInVec(__m128 vec)
136 {
137 mData = vec;
138 }
139
140 inline floatInVec::floatInVec(const boolInVec &vec)
141 {
142 mData = vec_sel(_mm_setzero_ps(), _mm_set1_ps(1.0f), vec.get128());
143 }
144
145 inline floatInVec::floatInVec(__m128 vec, int slot)
146 {
147 SSEFloat v;
148 v.m128 = vec;
149 mData = _mm_set1_ps(v.f[slot]);
150 }
151
152 inline floatInVec::floatInVec(float scalar)
153 {
154 mData = _mm_set1_ps(scalar);
155 }
156
157 #ifdef _VECTORMATH_NO_SCALAR_CAST
158 inline float
159 floatInVec::getAsFloat() const
160 #else
161 inline floatInVec::operator float() const
162 #endif
163 {
164 return *((float *)&mData);
165 }
166
167 inline __m128
168 floatInVec::get128() const
169 {
170 return mData;
171 }
172
173 inline const floatInVec
174 floatInVec::operator++(int)
175 {
176 __m128 olddata = mData;
177 operator++();
178 return floatInVec(olddata);
179 }
180
181 inline const floatInVec
182 floatInVec::operator--(int)
183 {
184 __m128 olddata = mData;
185 operator--();
186 return floatInVec(olddata);
187 }
188
189 inline floatInVec &
190 floatInVec::operator++()
191 {
192 *this += floatInVec(_mm_set1_ps(1.0f));
193 return *this;
194 }
195
196 inline floatInVec &
197 floatInVec::operator--()
198 {
199 *this -= floatInVec(_mm_set1_ps(1.0f));
200 return *this;
201 }
202
203 inline const floatInVec
204 floatInVec::operator-() const
205 {
206 return floatInVec(_mm_sub_ps(_mm_setzero_ps(), mData));
207 }
208
209 inline floatInVec &
210 floatInVec::operator=(const floatInVec &vec)
211 {
212 mData = vec.mData;
213 return *this;
214 }
215
216 inline floatInVec &
217 floatInVec::operator*=(const floatInVec &vec)
218 {
219 *this = *this * vec;
220 return *this;
221 }
222
223 inline floatInVec &
224 floatInVec::operator/=(const floatInVec &vec)
225 {
226 *this = *this / vec;
227 return *this;
228 }
229
230 inline floatInVec &
231 floatInVec::operator+=(const floatInVec &vec)
232 {
233 *this = *this + vec;
234 return *this;
235 }
236
237 inline floatInVec &
238 floatInVec::operator-=(const floatInVec &vec)
239 {
240 *this = *this - vec;
241 return *this;
242 }
243
244 inline const floatInVec
245 operator*(const floatInVec &vec0, const floatInVec &vec1)
246 {
247 return floatInVec(_mm_mul_ps(vec0.get128(), vec1.get128()));
248 }
249
250 inline const floatInVec
251 operator/(const floatInVec &num, const floatInVec &den)
252 {
253 return floatInVec(_mm_div_ps(num.get128(), den.get128()));
254 }
255
256 inline const floatInVec
257 operator+(const floatInVec &vec0, const floatInVec &vec1)
258 {
259 return floatInVec(_mm_add_ps(vec0.get128(), vec1.get128()));
260 }
261
262 inline const floatInVec
263 operator-(const floatInVec &vec0, const floatInVec &vec1)
264 {
265 return floatInVec(_mm_sub_ps(vec0.get128(), vec1.get128()));
266 }
267
268 inline const boolInVec
269 operator<(const floatInVec &vec0, const floatInVec &vec1)
270 {
271 return boolInVec(_mm_cmpgt_ps(vec1.get128(), vec0.get128()));
272 }
273
274 inline const boolInVec
275 operator<=(const floatInVec &vec0, const floatInVec &vec1)
276 {
277 return boolInVec(_mm_cmpge_ps(vec1.get128(), vec0.get128()));
278 }
279
280 inline const boolInVec
281 operator>(const floatInVec &vec0, const floatInVec &vec1)
282 {
283 return boolInVec(_mm_cmpgt_ps(vec0.get128(), vec1.get128()));
284 }
285
286 inline const boolInVec
287 operator>=(const floatInVec &vec0, const floatInVec &vec1)
288 {
289 return boolInVec(_mm_cmpge_ps(vec0.get128(), vec1.get128()));
290 }
291
292 inline const boolInVec
293 operator==(const floatInVec &vec0, const floatInVec &vec1)
294 {
295 return boolInVec(_mm_cmpeq_ps(vec0.get128(), vec1.get128()));
296 }
297
298 inline const boolInVec
299 operator!=(const floatInVec &vec0, const floatInVec &vec1)
300 {
301 return boolInVec(_mm_cmpneq_ps(vec0.get128(), vec1.get128()));
302 }
303
304 inline const floatInVec
305 select(const floatInVec &vec0, const floatInVec &vec1, const boolInVec &select_vec1)
306 {
307 return floatInVec(vec_sel(vec0.get128(), vec1.get128(), select_vec1.get128()));
308 }
309
310 } // namespace Vectormath
311
312 #endif // floatInVec_h