| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 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 |
|
| 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 |
|
| 54 |
|
| 55 |
inline boolInVec(const floatInVec &vec); |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
explicit inline boolInVec(bool scalar); |
| 60 |
|
| 61 |
#ifdef _VECTORMATH_NO_SCALAR_CAST |
| 62 |
|
| 63 |
|
| 64 |
inline bool getAsBool() const; |
| 65 |
#else |
| 66 |
|
| 67 |
|
| 68 |
inline operator bool() const; |
| 69 |
#endif |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
inline __m128 get128() const; |
| 75 |
|
| 76 |
|
| 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 |
|
| 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 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 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 |
|
| 113 |
|
| 114 |
|
| 115 |
inline const boolInVec select(const boolInVec &vec0, const boolInVec &vec1, const boolInVec &select_vec1); |
| 116 |
|
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
|
| 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); |
| 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 |
} |
| 230 |
|
| 231 |
#endif |