1 #ifndef OPENMM_VECTORIZE_PNACL_H_
2 #define OPENMM_VECTORIZE_PNACL_H_
43 static bool isVec4Supported() {
47 typedef float __m128 __attribute__((vector_size(16), aligned(4)));
48 typedef int __m128i __attribute__((vector_size(16), aligned(4)));
63 fvec4(
float v1,
float v2,
float v3,
float v4) {
64 val = {v1, v2, v3, v4};
70 operator __m128()
const {
107 return (
fvec4) (((__m128i)
val)&((__m128i)other.
val));
110 return (
fvec4) (((__m128i)
val)|((__m128i)other.
val));
130 operator ivec4()
const;
144 ivec4(
int v1,
int v2,
int v3,
int v4) {
145 val = {v1, v2, v3, v4};
149 val = *((__m128*) v);
151 operator __m128i()
const {
158 *((__m128*) v) =
val;
205 operator fvec4()
const;
210 inline fvec4::operator
ivec4()
const {
211 return __builtin_convertvector(val, __m128i);
214 inline ivec4::operator
fvec4()
const {
215 return __builtin_convertvector(val, __m128);
221 return fvec4(std::floor(v[0]), std::floor(v[1]), std::floor(v[2]), std::floor(v[3]));
225 return fvec4(std::ceil(v[0]), std::ceil(v[1]), std::ceil(v[2]), std::ceil(v[3]));
229 return fvec4(std::round(v[0]), std::round(v[1]), std::round(v[2]), std::round(v[3]));
233 return fvec4(std::min(v1[0], v2[0]), std::min(v1[1], v2[1]), std::min(v1[2], v2[2]), std::min(v1[3], v2[3]));
237 return fvec4(std::max(v1[0], v2[0]), std::max(v1[1], v2[1]), std::max(v1[2], v2[2]), std::max(v1[3], v2[3]));
241 return fvec4(std::abs(v[0]), std::abs(v[1]), std::abs(v[2]), std::abs(v[3]));
245 return fvec4(std::sqrt(v[0]), std::sqrt(v[1]), std::sqrt(v[2]), std::sqrt(v[3]));
248 static inline float dot3(
const fvec4& v1,
const fvec4& v2) {
250 return r[0]+r[1]+r[2];
253 static inline float dot4(
const fvec4& v1,
const fvec4& v2) {
255 return r[0]+r[1]+r[2]+r[3];
259 __m128 a1 = __builtin_shufflevector(v1.
val, v2.
val, 0, 4, 2, 6);
260 __m128 a2 = __builtin_shufflevector(v1.
val, v2.
val, 1, 5, 3, 7);
261 __m128 a3 = __builtin_shufflevector(v3.
val, v4.
val, 0, 4, 2, 6);
262 __m128 a4 = __builtin_shufflevector(v3.
val, v4.
val, 1, 5, 3, 7);
263 v1 = __builtin_shufflevector(a1, a3, 0, 1, 4, 5);
264 v2 = __builtin_shufflevector(a2, a4, 0, 1, 4, 5);
265 v3 = __builtin_shufflevector(a1, a3, 2, 3, 6, 7);
266 v4 = __builtin_shufflevector(a2, a4, 2, 3, 6, 7);
272 return ivec4(std::min(v1[0], v2[0]), std::min(v1[1], v2[1]), std::min(v1[2], v2[2]), std::min(v1[3], v2[3]));
276 return ivec4(std::max(v1[0], v2[0]), std::max(v1[1], v2[1]), std::max(v1[2], v2[2]), std::max(v1[3], v2[3]));
280 return ivec4(abs(v[0]), abs(v[1]), abs(v[2]), abs(v[3]));
283 static inline bool any(
const __m128i& v) {
284 return (v[0] || v[1] || v[2] || v[3]);
289 static inline fvec4 operator+(
float v1,
const fvec4& v2) {
293 static inline fvec4 operator-(
float v1,
const fvec4& v2) {
297 static inline fvec4 operator*(
float v1,
const fvec4& v2) {
301 static inline fvec4 operator/(
float v1,
const fvec4& v2) {
307 static inline fvec4 blend(
const fvec4& v1,
const fvec4& v2,
const __m128i& mask) {
308 return fvec4(mask[0] ? v2[0] : v1[0], mask[1] ? v2[1] : v1[1], mask[2] ? v2[2] : v1[2], mask[3] ? v2[3] : v1[3]);
fvec4 operator>=(const fvec4 &other) const
Definition: vectorize_pnacl.h:124
fvec4 operator+(const fvec4 &other) const
Definition: vectorize_pnacl.h:79
A four element vector of ints.
Definition: vectorize_neon.h:150
ivec4 operator==(const ivec4 &other) const
Definition: vectorize_pnacl.h:187
int operator[](int i) const
Definition: vectorize_pnacl.h:154
fvec4 operator-(const fvec4 &other) const
Definition: vectorize_pnacl.h:82
__m128 val
Definition: vectorize_pnacl.h:57
float operator[](int i) const
Definition: vectorize_pnacl.h:73
ivec4 operator<(const ivec4 &other) const
Definition: vectorize_pnacl.h:196
fvec4 operator<(const fvec4 &other) const
Definition: vectorize_pnacl.h:121
fvec4(__m128 v)
Definition: vectorize_pnacl.h:66
void operator/=(const fvec4 &other)
Definition: vectorize_pnacl.h:100
void operator*=(const fvec4 &other)
Definition: vectorize_pnacl.h:97
fvec4(const float *v)
Definition: vectorize_pnacl.h:67
ivec4 operator-(const ivec4 &other) const
Definition: vectorize_pnacl.h:163
void store(int *v) const
Definition: vectorize_pnacl.h:157
ivec4 operator>=(const ivec4 &other) const
Definition: vectorize_pnacl.h:199
ivec4(__m128i v)
Definition: vectorize_pnacl.h:147
A four element vector of floats.
Definition: vectorize_neon.h:56
ivec4 operator!=(const ivec4 &other) const
Definition: vectorize_pnacl.h:190
ivec4(int v1, int v2, int v3, int v4)
Definition: vectorize_pnacl.h:144
ivec4(const int *v)
Definition: vectorize_pnacl.h:148
fvec4 operator==(const fvec4 &other) const
Definition: vectorize_pnacl.h:112
fvec4 operator<=(const fvec4 &other) const
Definition: vectorize_pnacl.h:127
void store(float *v) const
Definition: vectorize_pnacl.h:76
void operator-=(const ivec4 &other)
Definition: vectorize_pnacl.h:172
void operator+=(const ivec4 &other)
Definition: vectorize_pnacl.h:169
ivec4 operator+(const ivec4 &other) const
Definition: vectorize_pnacl.h:160
fvec4()
Definition: vectorize_pnacl.h:59
ivec4 operator-() const
Definition: vectorize_pnacl.h:178
fvec4 operator/(const fvec4 &other) const
Definition: vectorize_pnacl.h:88
ivec4 operator|(const ivec4 &other) const
Definition: vectorize_pnacl.h:184
fvec4 operator!=(const fvec4 &other) const
Definition: vectorize_pnacl.h:115
ivec4 operator>(const ivec4 &other) const
Definition: vectorize_pnacl.h:193
ivec4()
Definition: vectorize_pnacl.h:140
void operator-=(const fvec4 &other)
Definition: vectorize_pnacl.h:94
fvec4 operator&(const fvec4 &other) const
Definition: vectorize_pnacl.h:106
fvec4 operator*(const fvec4 &other) const
Definition: vectorize_pnacl.h:85
fvec4(float v1, float v2, float v3, float v4)
Definition: vectorize_pnacl.h:63
fvec4 operator|(const fvec4 &other) const
Definition: vectorize_pnacl.h:109
fvec4(float v)
Definition: vectorize_pnacl.h:60
fvec4 operator>(const fvec4 &other) const
Definition: vectorize_pnacl.h:118
fvec4 operator-() const
Definition: vectorize_pnacl.h:103
void operator+=(const fvec4 &other)
Definition: vectorize_pnacl.h:91
ivec4(int v)
Definition: vectorize_pnacl.h:141
ivec4 operator*(const ivec4 &other) const
Definition: vectorize_pnacl.h:166
ivec4 operator<=(const ivec4 &other) const
Definition: vectorize_pnacl.h:202
ivec4 operator&(const ivec4 &other) const
Definition: vectorize_pnacl.h:181
void operator*=(const ivec4 &other)
Definition: vectorize_pnacl.h:175
__m128i val
Definition: vectorize_pnacl.h:138