Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/embree/common/simd/vint8_avx.h
9912 views
1
// Copyright 2009-2021 Intel Corporation
2
// SPDX-License-Identifier: Apache-2.0
3
4
#pragma once
5
6
#define vboolf vboolf_impl
7
#define vboold vboold_impl
8
#define vint vint_impl
9
#define vuint vuint_impl
10
#define vllong vllong_impl
11
#define vfloat vfloat_impl
12
#define vdouble vdouble_impl
13
14
namespace embree
15
{
16
/* 8-wide AVX integer type */
17
template<>
18
struct vint<8>
19
{
20
ALIGNED_STRUCT_(32);
21
22
typedef vboolf8 Bool;
23
typedef vint8 Int;
24
typedef vfloat8 Float;
25
26
enum { size = 8 }; // number of SIMD elements
27
union { // data
28
__m256i v;
29
struct { __m128i vl,vh; };
30
int i[8];
31
};
32
33
////////////////////////////////////////////////////////////////////////////////
34
/// Constructors, Assignment & Cast Operators
35
////////////////////////////////////////////////////////////////////////////////
36
37
__forceinline vint() {}
38
__forceinline vint(const vint8& a) { v = a.v; }
39
__forceinline vint8& operator =(const vint8& a) { v = a.v; return *this; }
40
41
__forceinline vint(__m256i a) : v(a) {}
42
__forceinline operator const __m256i&() const { return v; }
43
__forceinline operator __m256i&() { return v; }
44
45
__forceinline explicit vint(const vint4& a) : v(_mm256_insertf128_si256(_mm256_castsi128_si256(a),a,1)) {}
46
__forceinline vint(const vint4& a, const vint4& b) : v(_mm256_insertf128_si256(_mm256_castsi128_si256(a),b,1)) {}
47
__forceinline vint(const __m128i& a, const __m128i& b) : vl(a), vh(b) {}
48
49
__forceinline explicit vint(const int* a) : v(_mm256_castps_si256(_mm256_loadu_ps((const float*)a))) {}
50
__forceinline vint(int a) : v(_mm256_set1_epi32(a)) {}
51
__forceinline vint(int a, int b) : v(_mm256_set_epi32(b, a, b, a, b, a, b, a)) {}
52
__forceinline vint(int a, int b, int c, int d) : v(_mm256_set_epi32(d, c, b, a, d, c, b, a)) {}
53
__forceinline vint(int a, int b, int c, int d, int e, int f, int g, int vh) : v(_mm256_set_epi32(vh, g, f, e, d, c, b, a)) {}
54
55
__forceinline explicit vint(__m256 a) : v(_mm256_cvtps_epi32(a)) {}
56
57
////////////////////////////////////////////////////////////////////////////////
58
/// Constants
59
////////////////////////////////////////////////////////////////////////////////
60
61
__forceinline vint(ZeroTy) : v(_mm256_setzero_si256()) {}
62
__forceinline vint(OneTy) : v(_mm256_set_epi32(1,1,1,1,1,1,1,1)) {}
63
__forceinline vint(PosInfTy) : v(_mm256_set_epi32(pos_inf,pos_inf,pos_inf,pos_inf,pos_inf,pos_inf,pos_inf,pos_inf)) {}
64
__forceinline vint(NegInfTy) : v(_mm256_set_epi32(neg_inf,neg_inf,neg_inf,neg_inf,neg_inf,neg_inf,neg_inf,neg_inf)) {}
65
__forceinline vint(StepTy) : v(_mm256_set_epi32(7, 6, 5, 4, 3, 2, 1, 0)) {}
66
__forceinline vint(ReverseStepTy) : v(_mm256_set_epi32(0, 1, 2, 3, 4, 5, 6, 7)) {}
67
__forceinline vint(UndefinedTy) : v(_mm256_undefined_si256()) {}
68
69
////////////////////////////////////////////////////////////////////////////////
70
/// Loads and Stores
71
////////////////////////////////////////////////////////////////////////////////
72
73
static __forceinline vint8 load (const void* a) { return _mm256_castps_si256(_mm256_load_ps((float*)a)); }
74
static __forceinline vint8 loadu(const void* a) { return _mm256_castps_si256(_mm256_loadu_ps((float*)a)); }
75
76
static __forceinline vint8 load (const vboolf8& mask, const void* a) { return _mm256_castps_si256(_mm256_maskload_ps((float*)a,mask)); }
77
static __forceinline vint8 loadu(const vboolf8& mask, const void* a) { return _mm256_castps_si256(_mm256_maskload_ps((float*)a,mask)); }
78
79
static __forceinline void store (void* ptr, const vint8& f) { _mm256_store_ps((float*)ptr,_mm256_castsi256_ps(f)); }
80
static __forceinline void storeu(void* ptr, const vint8& f) { _mm256_storeu_ps((float*)ptr,_mm256_castsi256_ps(f)); }
81
82
static __forceinline void store (const vboolf8& mask, void* ptr, const vint8& f) { _mm256_maskstore_ps((float*)ptr,_mm256_castps_si256(mask.v),_mm256_castsi256_ps(f)); }
83
static __forceinline void storeu(const vboolf8& mask, void* ptr, const vint8& f) { _mm256_maskstore_ps((float*)ptr,_mm256_castps_si256(mask.v),_mm256_castsi256_ps(f)); }
84
85
static __forceinline void store_nt(void* ptr, const vint8& v) {
86
_mm256_stream_ps((float*)ptr,_mm256_castsi256_ps(v));
87
}
88
89
static __forceinline vint8 load(const unsigned char* ptr) {
90
vint4 il = vint4::load(ptr+0);
91
vint4 ih = vint4::load(ptr+4);
92
return vint8(il,ih);
93
}
94
95
static __forceinline vint8 loadu(const unsigned char* ptr) {
96
vint4 il = vint4::loadu(ptr+0);
97
vint4 ih = vint4::loadu(ptr+4);
98
return vint8(il,ih);
99
}
100
101
static __forceinline vint8 load(const unsigned short* ptr) {
102
vint4 il = vint4::load(ptr+0);
103
vint4 ih = vint4::load(ptr+4);
104
return vint8(il,ih);
105
}
106
107
static __forceinline vint8 loadu(const unsigned short* ptr) {
108
vint4 il = vint4::loadu(ptr+0);
109
vint4 ih = vint4::loadu(ptr+4);
110
return vint8(il,ih);
111
}
112
113
static __forceinline void store(unsigned char* ptr, const vint8& i) {
114
vint4 il(i.vl);
115
vint4 ih(i.vh);
116
vint4::store(ptr + 0,il);
117
vint4::store(ptr + 4,ih);
118
}
119
120
static __forceinline void store(unsigned short* ptr, const vint8& v) {
121
for (size_t i=0;i<8;i++)
122
ptr[i] = (unsigned short)v[i];
123
}
124
125
template<int scale = 4>
126
static __forceinline vint8 gather(const int* ptr, const vint8& index) {
127
return vint8(
128
*(int*)(((char*)ptr)+scale*index[0]),
129
*(int*)(((char*)ptr)+scale*index[1]),
130
*(int*)(((char*)ptr)+scale*index[2]),
131
*(int*)(((char*)ptr)+scale*index[3]),
132
*(int*)(((char*)ptr)+scale*index[4]),
133
*(int*)(((char*)ptr)+scale*index[5]),
134
*(int*)(((char*)ptr)+scale*index[6]),
135
*(int*)(((char*)ptr)+scale*index[7]));
136
}
137
138
template<int scale = 4>
139
static __forceinline vint8 gather(const vboolf8& mask, const int* ptr, const vint8& index) {
140
vint8 r = zero;
141
if (likely(mask[0])) r[0] = *(int*)(((char*)ptr)+scale*index[0]);
142
if (likely(mask[1])) r[1] = *(int*)(((char*)ptr)+scale*index[1]);
143
if (likely(mask[2])) r[2] = *(int*)(((char*)ptr)+scale*index[2]);
144
if (likely(mask[3])) r[3] = *(int*)(((char*)ptr)+scale*index[3]);
145
if (likely(mask[4])) r[4] = *(int*)(((char*)ptr)+scale*index[4]);
146
if (likely(mask[5])) r[5] = *(int*)(((char*)ptr)+scale*index[5]);
147
if (likely(mask[6])) r[6] = *(int*)(((char*)ptr)+scale*index[6]);
148
if (likely(mask[7])) r[7] = *(int*)(((char*)ptr)+scale*index[7]);
149
return r;
150
}
151
152
template<int scale = 4>
153
static __forceinline void scatter(void* ptr, const vint8& ofs, const vint8& v)
154
{
155
*(int*)(((char*)ptr)+scale*ofs[0]) = v[0];
156
*(int*)(((char*)ptr)+scale*ofs[1]) = v[1];
157
*(int*)(((char*)ptr)+scale*ofs[2]) = v[2];
158
*(int*)(((char*)ptr)+scale*ofs[3]) = v[3];
159
*(int*)(((char*)ptr)+scale*ofs[4]) = v[4];
160
*(int*)(((char*)ptr)+scale*ofs[5]) = v[5];
161
*(int*)(((char*)ptr)+scale*ofs[6]) = v[6];
162
*(int*)(((char*)ptr)+scale*ofs[7]) = v[7];
163
}
164
165
template<int scale = 4>
166
static __forceinline void scatter(const vboolf8& mask, void* ptr, const vint8& ofs, const vint8& v)
167
{
168
if (likely(mask[0])) *(int*)(((char*)ptr)+scale*ofs[0]) = v[0];
169
if (likely(mask[1])) *(int*)(((char*)ptr)+scale*ofs[1]) = v[1];
170
if (likely(mask[2])) *(int*)(((char*)ptr)+scale*ofs[2]) = v[2];
171
if (likely(mask[3])) *(int*)(((char*)ptr)+scale*ofs[3]) = v[3];
172
if (likely(mask[4])) *(int*)(((char*)ptr)+scale*ofs[4]) = v[4];
173
if (likely(mask[5])) *(int*)(((char*)ptr)+scale*ofs[5]) = v[5];
174
if (likely(mask[6])) *(int*)(((char*)ptr)+scale*ofs[6]) = v[6];
175
if (likely(mask[7])) *(int*)(((char*)ptr)+scale*ofs[7]) = v[7];
176
}
177
178
179
static __forceinline vint8 broadcast64(const long long& a) { return _mm256_set1_epi64x(a); }
180
181
////////////////////////////////////////////////////////////////////////////////
182
/// Array Access
183
////////////////////////////////////////////////////////////////////////////////
184
185
__forceinline const int& operator [](size_t index) const { assert(index < 8); return i[index]; }
186
__forceinline int& operator [](size_t index) { assert(index < 8); return i[index]; }
187
};
188
189
////////////////////////////////////////////////////////////////////////////////
190
/// Unary Operators
191
////////////////////////////////////////////////////////////////////////////////
192
193
__forceinline vboolf8 asBool(const vint8& a) { return _mm256_castsi256_ps(a); }
194
195
__forceinline vint8 operator +(const vint8& a) { return a; }
196
__forceinline vint8 operator -(const vint8& a) { return vint8(_mm_sub_epi32(_mm_setzero_si128(), a.vl), _mm_sub_epi32(_mm_setzero_si128(), a.vh)); }
197
__forceinline vint8 abs (const vint8& a) { return vint8(_mm_abs_epi32(a.vl), _mm_abs_epi32(a.vh)); }
198
199
////////////////////////////////////////////////////////////////////////////////
200
/// Binary Operators
201
////////////////////////////////////////////////////////////////////////////////
202
203
__forceinline vint8 operator +(const vint8& a, const vint8& b) { return vint8(_mm_add_epi32(a.vl, b.vl), _mm_add_epi32(a.vh, b.vh)); }
204
__forceinline vint8 operator +(const vint8& a, int b) { return a + vint8(b); }
205
__forceinline vint8 operator +(int a, const vint8& b) { return vint8(a) + b; }
206
207
__forceinline vint8 operator -(const vint8& a, const vint8& b) { return vint8(_mm_sub_epi32(a.vl, b.vl), _mm_sub_epi32(a.vh, b.vh)); }
208
__forceinline vint8 operator -(const vint8& a, int b) { return a - vint8(b); }
209
__forceinline vint8 operator -(int a, const vint8& b) { return vint8(a) - b; }
210
211
__forceinline vint8 operator *(const vint8& a, const vint8& b) { return vint8(_mm_mullo_epi32(a.vl, b.vl), _mm_mullo_epi32(a.vh, b.vh)); }
212
__forceinline vint8 operator *(const vint8& a, int b) { return a * vint8(b); }
213
__forceinline vint8 operator *(int a, const vint8& b) { return vint8(a) * b; }
214
215
__forceinline vint8 operator &(const vint8& a, const vint8& b) { return _mm256_castps_si256(_mm256_and_ps(_mm256_castsi256_ps(a), _mm256_castsi256_ps(b))); }
216
__forceinline vint8 operator &(const vint8& a, int b) { return a & vint8(b); }
217
__forceinline vint8 operator &(int a, const vint8& b) { return vint8(a) & b; }
218
219
__forceinline vint8 operator |(const vint8& a, const vint8& b) { return _mm256_castps_si256(_mm256_or_ps (_mm256_castsi256_ps(a), _mm256_castsi256_ps(b))); }
220
__forceinline vint8 operator |(const vint8& a, int b) { return a | vint8(b); }
221
__forceinline vint8 operator |(int a, const vint8& b) { return vint8(a) | b; }
222
223
__forceinline vint8 operator ^(const vint8& a, const vint8& b) { return _mm256_castps_si256(_mm256_xor_ps(_mm256_castsi256_ps(a), _mm256_castsi256_ps(b))); }
224
__forceinline vint8 operator ^(const vint8& a, int b) { return a ^ vint8(b); }
225
__forceinline vint8 operator ^(int a, const vint8& b) { return vint8(a) ^ b; }
226
227
__forceinline vint8 operator <<(const vint8& a, int n) { return vint8(_mm_slli_epi32(a.vl, n), _mm_slli_epi32(a.vh, n)); }
228
__forceinline vint8 operator >>(const vint8& a, int n) { return vint8(_mm_srai_epi32(a.vl, n), _mm_srai_epi32(a.vh, n)); }
229
230
__forceinline vint8 sll (const vint8& a, int b) { return vint8(_mm_slli_epi32(a.vl, b), _mm_slli_epi32(a.vh, b)); }
231
__forceinline vint8 sra (const vint8& a, int b) { return vint8(_mm_srai_epi32(a.vl, b), _mm_srai_epi32(a.vh, b)); }
232
__forceinline vint8 srl (const vint8& a, int b) { return vint8(_mm_srli_epi32(a.vl, b), _mm_srli_epi32(a.vh, b)); }
233
234
__forceinline vint8 min(const vint8& a, const vint8& b) { return vint8(_mm_min_epi32(a.vl, b.vl), _mm_min_epi32(a.vh, b.vh)); }
235
__forceinline vint8 min(const vint8& a, int b) { return min(a,vint8(b)); }
236
__forceinline vint8 min(int a, const vint8& b) { return min(vint8(a),b); }
237
238
__forceinline vint8 max(const vint8& a, const vint8& b) { return vint8(_mm_max_epi32(a.vl, b.vl), _mm_max_epi32(a.vh, b.vh)); }
239
__forceinline vint8 max(const vint8& a, int b) { return max(a,vint8(b)); }
240
__forceinline vint8 max(int a, const vint8& b) { return max(vint8(a),b); }
241
242
__forceinline vint8 umin(const vint8& a, const vint8& b) { return vint8(_mm_min_epu32(a.vl, b.vl), _mm_min_epu32(a.vh, b.vh)); }
243
__forceinline vint8 umin(const vint8& a, int b) { return umin(a,vint8(b)); }
244
__forceinline vint8 umin(int a, const vint8& b) { return umin(vint8(a),b); }
245
246
__forceinline vint8 umax(const vint8& a, const vint8& b) { return vint8(_mm_max_epu32(a.vl, b.vl), _mm_max_epu32(a.vh, b.vh)); }
247
__forceinline vint8 umax(const vint8& a, int b) { return umax(a,vint8(b)); }
248
__forceinline vint8 umax(int a, const vint8& b) { return umax(vint8(a),b); }
249
250
////////////////////////////////////////////////////////////////////////////////
251
/// Assignment Operators
252
////////////////////////////////////////////////////////////////////////////////
253
254
__forceinline vint8& operator +=(vint8& a, const vint8& b) { return a = a + b; }
255
__forceinline vint8& operator +=(vint8& a, int b) { return a = a + b; }
256
257
__forceinline vint8& operator -=(vint8& a, const vint8& b) { return a = a - b; }
258
__forceinline vint8& operator -=(vint8& a, int b) { return a = a - b; }
259
260
__forceinline vint8& operator *=(vint8& a, const vint8& b) { return a = a * b; }
261
__forceinline vint8& operator *=(vint8& a, int b) { return a = a * b; }
262
263
__forceinline vint8& operator &=(vint8& a, const vint8& b) { return a = a & b; }
264
__forceinline vint8& operator &=(vint8& a, int b) { return a = a & b; }
265
266
__forceinline vint8& operator |=(vint8& a, const vint8& b) { return a = a | b; }
267
__forceinline vint8& operator |=(vint8& a, int b) { return a = a | b; }
268
269
__forceinline vint8& operator <<=(vint8& a, int b) { return a = a << b; }
270
__forceinline vint8& operator >>=(vint8& a, int b) { return a = a >> b; }
271
272
////////////////////////////////////////////////////////////////////////////////
273
/// Comparison Operators + Select
274
////////////////////////////////////////////////////////////////////////////////
275
276
__forceinline vboolf8 operator ==(const vint8& a, const vint8& b) { return vboolf8(_mm_castsi128_ps(_mm_cmpeq_epi32 (a.vl, b.vl)),
277
_mm_castsi128_ps(_mm_cmpeq_epi32 (a.vh, b.vh))); }
278
__forceinline vboolf8 operator ==(const vint8& a, int b) { return a == vint8(b); }
279
__forceinline vboolf8 operator ==(int a, const vint8& b) { return vint8(a) == b; }
280
281
__forceinline vboolf8 operator !=(const vint8& a, const vint8& b) { return !(a == b); }
282
__forceinline vboolf8 operator !=(const vint8& a, int b) { return a != vint8(b); }
283
__forceinline vboolf8 operator !=(int a, const vint8& b) { return vint8(a) != b; }
284
285
__forceinline vboolf8 operator < (const vint8& a, const vint8& b) { return vboolf8(_mm_castsi128_ps(_mm_cmplt_epi32 (a.vl, b.vl)),
286
_mm_castsi128_ps(_mm_cmplt_epi32 (a.vh, b.vh))); }
287
__forceinline vboolf8 operator < (const vint8& a, int b) { return a < vint8(b); }
288
__forceinline vboolf8 operator < (int a, const vint8& b) { return vint8(a) < b; }
289
290
__forceinline vboolf8 operator >=(const vint8& a, const vint8& b) { return !(a < b); }
291
__forceinline vboolf8 operator >=(const vint8& a, int b) { return a >= vint8(b); }
292
__forceinline vboolf8 operator >=(int a, const vint8& b) { return vint8(a) >= b; }
293
294
__forceinline vboolf8 operator > (const vint8& a, const vint8& b) { return vboolf8(_mm_castsi128_ps(_mm_cmpgt_epi32 (a.vl, b.vl)),
295
_mm_castsi128_ps(_mm_cmpgt_epi32 (a.vh, b.vh))); }
296
__forceinline vboolf8 operator > (const vint8& a, int b) { return a > vint8(b); }
297
__forceinline vboolf8 operator > (int a, const vint8& b) { return vint8(a) > b; }
298
299
__forceinline vboolf8 operator <=(const vint8& a, const vint8& b) { return !(a > b); }
300
__forceinline vboolf8 operator <=(const vint8& a, int b) { return a <= vint8(b); }
301
__forceinline vboolf8 operator <=(int a, const vint8& b) { return vint8(a) <= b; }
302
303
__forceinline vboolf8 eq(const vint8& a, const vint8& b) { return a == b; }
304
__forceinline vboolf8 ne(const vint8& a, const vint8& b) { return a != b; }
305
__forceinline vboolf8 lt(const vint8& a, const vint8& b) { return a < b; }
306
__forceinline vboolf8 ge(const vint8& a, const vint8& b) { return a >= b; }
307
__forceinline vboolf8 gt(const vint8& a, const vint8& b) { return a > b; }
308
__forceinline vboolf8 le(const vint8& a, const vint8& b) { return a <= b; }
309
310
__forceinline vboolf8 eq(const vboolf8& mask, const vint8& a, const vint8& b) { return mask & (a == b); }
311
__forceinline vboolf8 ne(const vboolf8& mask, const vint8& a, const vint8& b) { return mask & (a != b); }
312
__forceinline vboolf8 lt(const vboolf8& mask, const vint8& a, const vint8& b) { return mask & (a < b); }
313
__forceinline vboolf8 ge(const vboolf8& mask, const vint8& a, const vint8& b) { return mask & (a >= b); }
314
__forceinline vboolf8 gt(const vboolf8& mask, const vint8& a, const vint8& b) { return mask & (a > b); }
315
__forceinline vboolf8 le(const vboolf8& mask, const vint8& a, const vint8& b) { return mask & (a <= b); }
316
317
__forceinline vint8 select(const vboolf8& m, const vint8& t, const vint8& f) {
318
return _mm256_castps_si256(_mm256_blendv_ps(_mm256_castsi256_ps(f), _mm256_castsi256_ps(t), m));
319
}
320
321
////////////////////////////////////////////////////////////////////////////////
322
/// Movement/Shifting/Shuffling Functions
323
////////////////////////////////////////////////////////////////////////////////
324
325
__forceinline vint8 unpacklo(const vint8& a, const vint8& b) { return _mm256_castps_si256(_mm256_unpacklo_ps(_mm256_castsi256_ps(a), _mm256_castsi256_ps(b))); }
326
__forceinline vint8 unpackhi(const vint8& a, const vint8& b) { return _mm256_castps_si256(_mm256_unpackhi_ps(_mm256_castsi256_ps(a), _mm256_castsi256_ps(b))); }
327
328
template<int i>
329
__forceinline vint8 shuffle(const vint8& v) {
330
return _mm256_castps_si256(_mm256_permute_ps(_mm256_castsi256_ps(v), _MM_SHUFFLE(i, i, i, i)));
331
}
332
333
template<int i0, int i1>
334
__forceinline vint8 shuffle4(const vint8& v) {
335
return _mm256_permute2f128_si256(v, v, (i1 << 4) | (i0 << 0));
336
}
337
338
template<int i0, int i1>
339
__forceinline vint8 shuffle4(const vint8& a, const vint8& b) {
340
return _mm256_permute2f128_si256(a, b, (i1 << 4) | (i0 << 0));
341
}
342
343
template<int i0, int i1, int i2, int i3>
344
__forceinline vint8 shuffle(const vint8& v) {
345
return _mm256_castps_si256(_mm256_permute_ps(_mm256_castsi256_ps(v), _MM_SHUFFLE(i3, i2, i1, i0)));
346
}
347
348
template<int i0, int i1, int i2, int i3>
349
__forceinline vint8 shuffle(const vint8& a, const vint8& b) {
350
return _mm256_castps_si256(_mm256_shuffle_ps(_mm256_castsi256_ps(a), _mm256_castsi256_ps(b), _MM_SHUFFLE(i3, i2, i1, i0)));
351
}
352
353
template<> __forceinline vint8 shuffle<0, 0, 2, 2>(const vint8& v) { return _mm256_castps_si256(_mm256_moveldup_ps(_mm256_castsi256_ps(v))); }
354
template<> __forceinline vint8 shuffle<1, 1, 3, 3>(const vint8& v) { return _mm256_castps_si256(_mm256_movehdup_ps(_mm256_castsi256_ps(v))); }
355
template<> __forceinline vint8 shuffle<0, 1, 0, 1>(const vint8& v) { return _mm256_castps_si256(_mm256_castpd_ps(_mm256_movedup_pd(_mm256_castps_pd(_mm256_castsi256_ps(v))))); }
356
357
__forceinline vint8 broadcast(const int* ptr) { return _mm256_castps_si256(_mm256_broadcast_ss((const float*)ptr)); }
358
template<int i> __forceinline vint8 insert4(const vint8& a, const vint4& b) { return _mm256_insertf128_si256(a, b, i); }
359
template<int i> __forceinline vint4 extract4(const vint8& a) { return _mm256_extractf128_si256(a, i); }
360
template<> __forceinline vint4 extract4<0>(const vint8& a) { return _mm256_castsi256_si128(a); }
361
362
__forceinline int toScalar(const vint8& v) { return _mm_cvtsi128_si32(_mm256_castsi256_si128(v)); }
363
364
365
////////////////////////////////////////////////////////////////////////////////
366
/// Reductions
367
////////////////////////////////////////////////////////////////////////////////
368
369
__forceinline vint8 vreduce_min2(const vint8& v) { return min(v,shuffle<1,0,3,2>(v)); }
370
__forceinline vint8 vreduce_min4(const vint8& v) { vint8 v1 = vreduce_min2(v); return min(v1,shuffle<2,3,0,1>(v1)); }
371
__forceinline vint8 vreduce_min (const vint8& v) { vint8 v1 = vreduce_min4(v); return min(v1,shuffle4<1,0>(v1)); }
372
373
__forceinline vint8 vreduce_max2(const vint8& v) { return max(v,shuffle<1,0,3,2>(v)); }
374
__forceinline vint8 vreduce_max4(const vint8& v) { vint8 v1 = vreduce_max2(v); return max(v1,shuffle<2,3,0,1>(v1)); }
375
__forceinline vint8 vreduce_max (const vint8& v) { vint8 v1 = vreduce_max4(v); return max(v1,shuffle4<1,0>(v1)); }
376
377
__forceinline vint8 vreduce_add2(const vint8& v) { return v + shuffle<1,0,3,2>(v); }
378
__forceinline vint8 vreduce_add4(const vint8& v) { vint8 v1 = vreduce_add2(v); return v1 + shuffle<2,3,0,1>(v1); }
379
__forceinline vint8 vreduce_add (const vint8& v) { vint8 v1 = vreduce_add4(v); return v1 + shuffle4<1,0>(v1); }
380
381
__forceinline int reduce_min(const vint8& v) { return toScalar(vreduce_min(v)); }
382
__forceinline int reduce_max(const vint8& v) { return toScalar(vreduce_max(v)); }
383
__forceinline int reduce_add(const vint8& v) { return toScalar(vreduce_add(v)); }
384
385
__forceinline size_t select_min(const vint8& v) { return bsf(movemask(v == vreduce_min(v))); }
386
__forceinline size_t select_max(const vint8& v) { return bsf(movemask(v == vreduce_max(v))); }
387
388
__forceinline size_t select_min(const vboolf8& valid, const vint8& v) { const vint8 a = select(valid,v,vint8(pos_inf)); return bsf(movemask(valid & (a == vreduce_min(a)))); }
389
__forceinline size_t select_max(const vboolf8& valid, const vint8& v) { const vint8 a = select(valid,v,vint8(neg_inf)); return bsf(movemask(valid & (a == vreduce_max(a)))); }
390
391
////////////////////////////////////////////////////////////////////////////////
392
/// Sorting networks
393
////////////////////////////////////////////////////////////////////////////////
394
395
__forceinline vint8 usort_ascending(const vint8& v)
396
{
397
const vint8 a0 = v;
398
const vint8 b0 = shuffle<1,0,3,2>(a0);
399
const vint8 c0 = umin(a0,b0);
400
const vint8 d0 = umax(a0,b0);
401
const vint8 a1 = select(0x99 /* 0b10011001 */,c0,d0);
402
const vint8 b1 = shuffle<2,3,0,1>(a1);
403
const vint8 c1 = umin(a1,b1);
404
const vint8 d1 = umax(a1,b1);
405
const vint8 a2 = select(0xc3 /* 0b11000011 */,c1,d1);
406
const vint8 b2 = shuffle<1,0,3,2>(a2);
407
const vint8 c2 = umin(a2,b2);
408
const vint8 d2 = umax(a2,b2);
409
const vint8 a3 = select(0xa5 /* 0b10100101 */,c2,d2);
410
const vint8 b3 = shuffle4<1,0>(a3);
411
const vint8 c3 = umin(a3,b3);
412
const vint8 d3 = umax(a3,b3);
413
const vint8 a4 = select(0xf /* 0b00001111 */,c3,d3);
414
const vint8 b4 = shuffle<2,3,0,1>(a4);
415
const vint8 c4 = umin(a4,b4);
416
const vint8 d4 = umax(a4,b4);
417
const vint8 a5 = select(0x33 /* 0b00110011 */,c4,d4);
418
const vint8 b5 = shuffle<1,0,3,2>(a5);
419
const vint8 c5 = umin(a5,b5);
420
const vint8 d5 = umax(a5,b5);
421
const vint8 a6 = select(0x55 /* 0b01010101 */,c5,d5);
422
return a6;
423
}
424
425
__forceinline vint8 usort_descending(const vint8& v)
426
{
427
const vint8 a0 = v;
428
const vint8 b0 = shuffle<1,0,3,2>(a0);
429
const vint8 c0 = umax(a0,b0);
430
const vint8 d0 = umin(a0,b0);
431
const vint8 a1 = select(0x99 /* 0b10011001 */,c0,d0);
432
const vint8 b1 = shuffle<2,3,0,1>(a1);
433
const vint8 c1 = umax(a1,b1);
434
const vint8 d1 = umin(a1,b1);
435
const vint8 a2 = select(0xc3 /* 0b11000011 */,c1,d1);
436
const vint8 b2 = shuffle<1,0,3,2>(a2);
437
const vint8 c2 = umax(a2,b2);
438
const vint8 d2 = umin(a2,b2);
439
const vint8 a3 = select(0xa5 /* 0b10100101 */,c2,d2);
440
const vint8 b3 = shuffle4<1,0>(a3);
441
const vint8 c3 = umax(a3,b3);
442
const vint8 d3 = umin(a3,b3);
443
const vint8 a4 = select(0xf /* 0b00001111 */,c3,d3);
444
const vint8 b4 = shuffle<2,3,0,1>(a4);
445
const vint8 c4 = umax(a4,b4);
446
const vint8 d4 = umin(a4,b4);
447
const vint8 a5 = select(0x33 /* 0b00110011 */,c4,d4);
448
const vint8 b5 = shuffle<1,0,3,2>(a5);
449
const vint8 c5 = umax(a5,b5);
450
const vint8 d5 = umin(a5,b5);
451
const vint8 a6 = select(0x55 /* 0b01010101 */,c5,d5);
452
return a6;
453
}
454
455
////////////////////////////////////////////////////////////////////////////////
456
/// Output Operators
457
////////////////////////////////////////////////////////////////////////////////
458
459
__forceinline embree_ostream operator <<(embree_ostream cout, const vint8& a) {
460
return cout << "<" << a[0] << ", " << a[1] << ", " << a[2] << ", " << a[3] << ", " << a[4] << ", " << a[5] << ", " << a[6] << ", " << a[7] << ">";
461
}
462
}
463
464
#undef vboolf
465
#undef vboold
466
#undef vint
467
#undef vuint
468
#undef vllong
469
#undef vfloat
470
#undef vdouble
471
472