Debian Codegraph @

test/Bullet2/vectormath/sse/boolInVec.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 _BOOLINVEC_H
31 #define _BOOLINVEC_H
32
33 #include <math.h>
34
35 namespace Vectormath
36 {
37 class floatInVec;
38
39 //--------------------------------------------------------------------------------------------------
40 // boolInVec class
41 //
42
43 class boolInVec
44 {
45 private:
46 __m128 mData;
47
48 inline boolInVec(__m128 vec);
49
50 public:
51 inline boolInVec() {}
52
53 // matches standard type conversions
54 //
55 inline boolInVec(const floatInVec &vec);
56
57 // explicit cast from bool
58 //
59 explicit inline boolInVec(bool scalar);
60
61 #ifdef _VECTORMATH_NO_SCALAR_CAST
62 // explicit cast to bool
63 //
64 inline bool getAsBool() const;
65 #else
66 // implicit cast to bool
67 //
68 inline operator bool() const;
69 #endif
70
71 // get vector data
72 // bool value is splatted across all word slots of vector as 0 (false) or -1 (true)
73 //
74 inline __m128 get128() const;
75
76 // operators
77 //
78 inline const boolInVec operator!() const;
79 inline boolInVec &operator=(const boolInVec &vec);
80 inline boolInVec &operator&=(const boolInVec &vec);
81 inline boolInVec &operator^=(const boolInVec &vec);
82 inline boolInVec &operator|=(const boolInVec &vec);
83
84 // friend functions
85 //
86 friend inline const boolInVec operator==(const boolInVec &vec0, const boolInVec &vec1);
87 friend inline const boolInVec operator!=(const boolInVec &vec0, const boolInVec &vec1);
88 friend inline const boolInVec operator<(const floatInVec &vec0, const floatInVec &vec1);
89 friend inline const boolInVec operator<=(const floatInVec &vec0, const floatInVec &vec1);
90 friend inline const boolInVec operator>(const floatInVec &vec0, const floatInVec &vec1);
91 friend inline const boolInVec operator>=(const floatInVec &vec0, const floatInVec &vec1);
92 friend inline const boolInVec operator==(const floatInVec &vec0, const floatInVec &vec1);
93 friend inline const boolInVec operator!=(const floatInVec &vec0, const floatInVec &vec1);
94 friend inline const boolInVec operator&(const boolInVec &vec0, const boolInVec &vec1);
95 friend inline const boolInVec operator^(const boolInVec &vec0, const boolInVec &vec1);
96 friend inline const boolInVec operator|(const boolInVec &vec0, const boolInVec &vec1);
97 friend inline const boolInVec select(const boolInVec &vec0, const boolInVec &vec1, const boolInVec &select_vec1);
98 };
99
100 //--------------------------------------------------------------------------------------------------
101 // boolInVec functions
102 //
103
104 // operators
105 //
106 inline const boolInVec operator==(const boolInVec &vec0, const boolInVec &vec1);
107 inline const boolInVec operator!=(const boolInVec &vec0, const boolInVec &vec1);
108 inline const boolInVec operator&(const boolInVec &vec0, const boolInVec &vec1);
109 inline const boolInVec operator^(const boolInVec &vec0, const boolInVec &vec1);
110 inline const boolInVec operator|(const boolInVec &vec0, const boolInVec &vec1);
111
112 // select between vec0 and vec1 using boolInVec.
113 // false selects vec0, true selects vec1
114 //
115 inline const boolInVec select(const boolInVec &vec0, const boolInVec &vec1, const boolInVec &select_vec1);
116
117 } // namespace Vectormath
118
119 //--------------------------------------------------------------------------------------------------
120 // boolInVec implementation
121 //
122
123 #include "floatInVec.h"
124
125 namespace Vectormath
126 {
127 inline boolInVec::boolInVec(__m128 vec)
128 {
129 mData = vec;
130 }
131
132 inline boolInVec::boolInVec(const floatInVec &vec)
133 {
134 *this = (vec != floatInVec(0.0f));
135 }
136
137 inline boolInVec::boolInVec(bool scalar)
138 {
139 unsigned int mask = -(int)scalar;
140 mData = _mm_set1_ps(*(float *)&mask); // TODO: Union
141 }
142
143 #ifdef _VECTORMATH_NO_SCALAR_CAST
144 inline bool
145 boolInVec::getAsBool() const
146 #else
147 inline boolInVec::operator bool() const
148 #endif
149 {
150 return *(bool *)&mData;
151 }
152
153 inline __m128
154 boolInVec::get128() const
155 {
156 return mData;
157 }
158
159 inline const boolInVec
160 boolInVec::operator!() const
161 {
162 return boolInVec(_mm_andnot_ps(mData, _mm_cmpneq_ps(_mm_setzero_ps(), _mm_setzero_ps())));
163 }
164
165 inline boolInVec &
166 boolInVec::operator=(const boolInVec &vec)
167 {
168 mData = vec.mData;
169 return *this;
170 }
171
172 inline boolInVec &
173 boolInVec::operator&=(const boolInVec &vec)
174 {
175 *this = *this & vec;
176 return *this;
177 }
178
179 inline boolInVec &
180 boolInVec::operator^=(const boolInVec &vec)
181 {
182 *this = *this ^ vec;
183 return *this;
184 }
185
186 inline boolInVec &
187 boolInVec::operator|=(const boolInVec &vec)
188 {
189 *this = *this | vec;
190 return *this;
191 }
192
193 inline const boolInVec
194 operator==(const boolInVec &vec0, const boolInVec &vec1)
195 {
196 return boolInVec(_mm_cmpeq_ps(vec0.get128(), vec1.get128()));
197 }
198
199 inline const boolInVec
200 operator!=(const boolInVec &vec0, const boolInVec &vec1)
201 {
202 return boolInVec(_mm_cmpneq_ps(vec0.get128(), vec1.get128()));
203 }
204
205 inline const boolInVec
206 operator&(const boolInVec &vec0, const boolInVec &vec1)
207 {
208 return boolInVec(_mm_and_ps(vec0.get128(), vec1.get128()));
209 }
210
211 inline const boolInVec
212 operator|(const boolInVec &vec0, const boolInVec &vec1)
213 {
214 return boolInVec(_mm_or_ps(vec0.get128(), vec1.get128()));
215 }
216
217 inline const boolInVec
218 operator^(const boolInVec &vec0, const boolInVec &vec1)
219 {
220 return boolInVec(_mm_xor_ps(vec0.get128(), vec1.get128()));
221 }
222
223 inline const boolInVec
224 select(const boolInVec &vec0, const boolInVec &vec1, const boolInVec &select_vec1)
225 {
226 return boolInVec(vec_sel(vec0.get128(), vec1.get128(), select_vec1.get128()));
227 }
228
229 } // namespace Vectormath
230
231 #endif // boolInVec_h