Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef _BOOLINVEC_H
00031 #define _BOOLINVEC_H
00032
00033 #include <math.h>
00034
00035 namespace Vectormath {
00036
00037 class floatInVec;
00038
00039
00040
00041
00042
00043 class boolInVec
00044 {
00045 private:
00046 __m128 mData;
00047
00048 inline boolInVec(__m128 vec);
00049 public:
00050 inline boolInVec() {}
00051
00052
00053
00054 inline boolInVec(const floatInVec &vec);
00055
00056
00057
00058 explicit inline boolInVec(bool scalar);
00059
00060 #ifdef _VECTORMATH_NO_SCALAR_CAST
00061
00062
00063 inline bool getAsBool() const;
00064 #else
00065
00066
00067 inline operator bool() const;
00068 #endif
00069
00070
00071
00072
00073 inline __m128 get128() const;
00074
00075
00076
00077 inline const boolInVec operator ! () const;
00078 inline boolInVec& operator = (const boolInVec &vec);
00079 inline boolInVec& operator &= (const boolInVec &vec);
00080 inline boolInVec& operator ^= (const boolInVec &vec);
00081 inline boolInVec& operator |= (const boolInVec &vec);
00082
00083
00084
00085 friend inline const boolInVec operator == (const boolInVec &vec0, const boolInVec &vec1);
00086 friend inline const boolInVec operator != (const boolInVec &vec0, const boolInVec &vec1);
00087 friend inline const boolInVec operator < (const floatInVec &vec0, const floatInVec &vec1);
00088 friend inline const boolInVec operator <= (const floatInVec &vec0, const floatInVec &vec1);
00089 friend inline const boolInVec operator > (const floatInVec &vec0, const floatInVec &vec1);
00090 friend inline const boolInVec operator >= (const floatInVec &vec0, const floatInVec &vec1);
00091 friend inline const boolInVec operator == (const floatInVec &vec0, const floatInVec &vec1);
00092 friend inline const boolInVec operator != (const floatInVec &vec0, const floatInVec &vec1);
00093 friend inline const boolInVec operator & (const boolInVec &vec0, const boolInVec &vec1);
00094 friend inline const boolInVec operator ^ (const boolInVec &vec0, const boolInVec &vec1);
00095 friend inline const boolInVec operator | (const boolInVec &vec0, const boolInVec &vec1);
00096 friend inline const boolInVec select(const boolInVec &vec0, const boolInVec &vec1, const boolInVec &select_vec1);
00097 };
00098
00099
00100
00101
00102
00103
00104
00105 inline const boolInVec operator == (const boolInVec &vec0, const boolInVec &vec1);
00106 inline const boolInVec operator != (const boolInVec &vec0, const boolInVec &vec1);
00107 inline const boolInVec operator & (const boolInVec &vec0, const boolInVec &vec1);
00108 inline const boolInVec operator ^ (const boolInVec &vec0, const boolInVec &vec1);
00109 inline const boolInVec operator | (const boolInVec &vec0, const boolInVec &vec1);
00110
00111
00112
00113
00114 inline const boolInVec select(const boolInVec &vec0, const boolInVec &vec1, const boolInVec &select_vec1);
00115
00116 }
00117
00118
00119
00120
00121
00122 #include "floatInVec.h"
00123
00124 namespace Vectormath {
00125
00126 inline
00127 boolInVec::boolInVec(__m128 vec)
00128 {
00129 mData = vec;
00130 }
00131
00132 inline
00133 boolInVec::boolInVec(const floatInVec &vec)
00134 {
00135 *this = (vec != floatInVec(0.0f));
00136 }
00137
00138 inline
00139 boolInVec::boolInVec(bool scalar)
00140 {
00141 unsigned int mask = -(int)scalar;
00142 mData = _mm_set1_ps(*(float *)&mask);
00143 }
00144
00145 #ifdef _VECTORMATH_NO_SCALAR_CAST
00146 inline
00147 bool
00148 boolInVec::getAsBool() const
00149 #else
00150 inline
00151 boolInVec::operator bool() const
00152 #endif
00153 {
00154 return *(bool *)&mData;
00155 }
00156
00157 inline
00158 __m128
00159 boolInVec::get128() const
00160 {
00161 return mData;
00162 }
00163
00164 inline
00165 const boolInVec
00166 boolInVec::operator ! () const
00167 {
00168 return boolInVec(_mm_andnot_ps(mData, _mm_cmpneq_ps(_mm_setzero_ps(),_mm_setzero_ps())));
00169 }
00170
00171 inline
00172 boolInVec&
00173 boolInVec::operator = (const boolInVec &vec)
00174 {
00175 mData = vec.mData;
00176 return *this;
00177 }
00178
00179 inline
00180 boolInVec&
00181 boolInVec::operator &= (const boolInVec &vec)
00182 {
00183 *this = *this & vec;
00184 return *this;
00185 }
00186
00187 inline
00188 boolInVec&
00189 boolInVec::operator ^= (const boolInVec &vec)
00190 {
00191 *this = *this ^ vec;
00192 return *this;
00193 }
00194
00195 inline
00196 boolInVec&
00197 boolInVec::operator |= (const boolInVec &vec)
00198 {
00199 *this = *this | vec;
00200 return *this;
00201 }
00202
00203 inline
00204 const boolInVec
00205 operator == (const boolInVec &vec0, const boolInVec &vec1)
00206 {
00207 return boolInVec(_mm_cmpeq_ps(vec0.get128(), vec1.get128()));
00208 }
00209
00210 inline
00211 const boolInVec
00212 operator != (const boolInVec &vec0, const boolInVec &vec1)
00213 {
00214 return boolInVec(_mm_cmpneq_ps(vec0.get128(), vec1.get128()));
00215 }
00216
00217 inline
00218 const boolInVec
00219 operator & (const boolInVec &vec0, const boolInVec &vec1)
00220 {
00221 return boolInVec(_mm_and_ps(vec0.get128(), vec1.get128()));
00222 }
00223
00224 inline
00225 const boolInVec
00226 operator | (const boolInVec &vec0, const boolInVec &vec1)
00227 {
00228 return boolInVec(_mm_or_ps(vec0.get128(), vec1.get128()));
00229 }
00230
00231 inline
00232 const boolInVec
00233 operator ^ (const boolInVec &vec0, const boolInVec &vec1)
00234 {
00235 return boolInVec(_mm_xor_ps(vec0.get128(), vec1.get128()));
00236 }
00237
00238 inline
00239 const boolInVec
00240 select(const boolInVec &vec0, const boolInVec &vec1, const boolInVec &select_vec1)
00241 {
00242 return boolInVec(vec_sel(vec0.get128(), vec1.get128(), select_vec1.get128()));
00243 }
00244
00245 }
00246
00247 #endif // boolInVec_h