Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/embree/common/simd/vuint8_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 vuint<8>
19
{
20
ALIGNED_STRUCT_(32);
21
22
typedef vboolf8 Bool;
23
typedef vuint8 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
unsigned int i[8];
31
};
32
33
////////////////////////////////////////////////////////////////////////////////
34
/// Constructors, Assignment & Cast Operators
35
////////////////////////////////////////////////////////////////////////////////
36
37
__forceinline vuint() {}
38
__forceinline vuint(const vuint8& a) { v = a.v; }
39
__forceinline vuint8& operator =(const vuint8& a) { v = a.v; return *this; }
40
41
__forceinline vuint(__m256i a) : v(a) {}
42
__forceinline operator const __m256i&() const { return v; }
43
__forceinline operator __m256i&() { return v; }
44
45
__forceinline explicit vuint(const vuint4& a) : v(_mm256_insertf128_si256(_mm256_castsi128_si256(a),a,1)) {}
46
__forceinline vuint(const vuint4& a, const vuint4& b) : v(_mm256_insertf128_si256(_mm256_castsi128_si256(a),b,1)) {}
47
__forceinline vuint(const __m128i& a, const __m128i& b) : vl(a), vh(b) {}
48
49
__forceinline explicit vuint(const unsigned int* a) : v(_mm256_castps_si256(_mm256_loadu_ps((const float*)a))) {}
50
__forceinline vuint(unsigned int a) : v(_mm256_set1_epi32(a)) {}
51
__forceinline vuint(unsigned int a, unsigned int b) : v(_mm256_set_epi32(b, a, b, a, b, a, b, a)) {}
52
__forceinline vuint(unsigned int a, unsigned int b, unsigned int c, unsigned int d) : v(_mm256_set_epi32(d, c, b, a, d, c, b, a)) {}
53
__forceinline vuint(unsigned int a, unsigned int b, unsigned int c, unsigned int d, unsigned int e, unsigned int f, unsigned int g, unsigned int vh) : v(_mm256_set_epi32(vh, g, f, e, d, c, b, a)) {}
54
55
__forceinline explicit vuint(__m256 a) : v(_mm256_cvtps_epi32(a)) {}
56
57
////////////////////////////////////////////////////////////////////////////////
58
/// Constants
59
////////////////////////////////////////////////////////////////////////////////
60
61
__forceinline vuint(ZeroTy) : v(_mm256_setzero_si256()) {}
62
__forceinline vuint(OneTy) : v(_mm256_set1_epi32(1)) {}
63
__forceinline vuint(PosInfTy) : v(_mm256_set1_epi32(0xFFFFFFFF)) {}
64
__forceinline vuint(StepTy) : v(_mm256_set_epi32(7, 6, 5, 4, 3, 2, 1, 0)) {}
65
__forceinline vuint(UndefinedTy) : v(_mm256_undefined_si256()) {}
66
67
////////////////////////////////////////////////////////////////////////////////
68
/// Loads and Stores
69
////////////////////////////////////////////////////////////////////////////////
70
71
static __forceinline vuint8 load (const void* a) { return _mm256_castps_si256(_mm256_load_ps((float*)a)); }
72
static __forceinline vuint8 loadu(const void* a) { return _mm256_castps_si256(_mm256_loadu_ps((float*)a)); }
73
74
static __forceinline vuint8 load (const vboolf8& mask, const void* a) { return _mm256_castps_si256(_mm256_maskload_ps((float*)a,mask)); }
75
static __forceinline vuint8 loadu(const vboolf8& mask, const void* a) { return _mm256_castps_si256(_mm256_maskload_ps((float*)a,mask)); }
76
77
static __forceinline void store (void* ptr, const vuint8& f) { _mm256_store_ps((float*)ptr,_mm256_castsi256_ps(f)); }
78
static __forceinline void storeu(void* ptr, const vuint8& f) { _mm256_storeu_ps((float*)ptr,_mm256_castsi256_ps(f)); }
79
80
static __forceinline void store (const vboolf8& mask, void* ptr, const vuint8& f) { _mm256_maskstore_ps((float*)ptr,_mm256_castps_si256(mask.v),_mm256_castsi256_ps(f)); }
81
static __forceinline void storeu(const vboolf8& mask, void* ptr, const vuint8& f) { _mm256_maskstore_ps((float*)ptr,_mm256_castps_si256(mask.v),_mm256_castsi256_ps(f)); }
82
83
static __forceinline void store_nt(void* ptr, const vuint8& v) {
84
_mm256_stream_ps((float*)ptr,_mm256_castsi256_ps(v));
85
}
86
87
static __forceinline vuint8 load(const unsigned char* ptr) {
88
vuint4 il = vuint4::load(ptr+0);
89
vuint4 ih = vuint4::load(ptr+4);
90
return vuint8(il,ih);
91
}
92
93
static __forceinline vuint8 loadu(const unsigned char* ptr) {
94
vuint4 il = vuint4::loadu(ptr+0);
95
vuint4 ih = vuint4::loadu(ptr+4);
96
return vuint8(il,ih);
97
}
98
99
static __forceinline vuint8 load(const unsigned short* ptr) {
100
vuint4 il = vuint4::load(ptr+0);
101
vuint4 ih = vuint4::load(ptr+4);
102
return vuint8(il,ih);
103
}
104
105
static __forceinline vuint8 loadu(const unsigned short* ptr) {
106
vuint4 il = vuint4::loadu(ptr+0);
107
vuint4 ih = vuint4::loadu(ptr+4);
108
return vuint8(il,ih);
109
}
110
111
static __forceinline void store(unsigned char* ptr, const vuint8& i) {
112
vuint4 il(i.vl);
113
vuint4 ih(i.vh);
114
vuint4::store(ptr + 0,il);
115
vuint4::store(ptr + 4,ih);
116
}
117
118
static __forceinline void store(unsigned short* ptr, const vuint8& v) {
119
for (size_t i=0;i<8;i++)
120
ptr[i] = (unsigned short)v[i];
121
}
122
123
template<int scale = 4>
124
static __forceinline vuint8 gather(const unsigned int* ptr, const vint8& index) {
125
return vuint8(
126
*(unsigned int*)(((char*)ptr)+scale*index[0]),
127
*(unsigned int*)(((char*)ptr)+scale*index[1]),
128
*(unsigned int*)(((char*)ptr)+scale*index[2]),
129
*(unsigned int*)(((char*)ptr)+scale*index[3]),
130
*(unsigned int*)(((char*)ptr)+scale*index[4]),
131
*(unsigned int*)(((char*)ptr)+scale*index[5]),
132
*(unsigned int*)(((char*)ptr)+scale*index[6]),
133
*(unsigned int*)(((char*)ptr)+scale*index[7]));
134
}
135
136
template<int scale = 4>
137
static __forceinline vuint8 gather(const vboolf8& mask, const unsigned int* ptr, const vint8& index) {
138
vuint8 r = zero;
139
if (likely(mask[0])) r[0] = *(unsigned int*)(((char*)ptr)+scale*index[0]);
140
if (likely(mask[1])) r[1] = *(unsigned int*)(((char*)ptr)+scale*index[1]);
141
if (likely(mask[2])) r[2] = *(unsigned int*)(((char*)ptr)+scale*index[2]);
142
if (likely(mask[3])) r[3] = *(unsigned int*)(((char*)ptr)+scale*index[3]);
143
if (likely(mask[4])) r[4] = *(unsigned int*)(((char*)ptr)+scale*index[4]);
144
if (likely(mask[5])) r[5] = *(unsigned int*)(((char*)ptr)+scale*index[5]);
145
if (likely(mask[6])) r[6] = *(unsigned int*)(((char*)ptr)+scale*index[6]);
146
if (likely(mask[7])) r[7] = *(unsigned int*)(((char*)ptr)+scale*index[7]);
147
return r;
148
}
149
150
template<int scale = 4>
151
static __forceinline void scatter(void* ptr, const vint8& ofs, const vuint8& v)
152
{
153
*(unsigned int*)(((char*)ptr)+scale*ofs[0]) = v[0];
154
*(unsigned int*)(((char*)ptr)+scale*ofs[1]) = v[1];
155
*(unsigned int*)(((char*)ptr)+scale*ofs[2]) = v[2];
156
*(unsigned int*)(((char*)ptr)+scale*ofs[3]) = v[3];
157
*(unsigned int*)(((char*)ptr)+scale*ofs[4]) = v[4];
158
*(unsigned int*)(((char*)ptr)+scale*ofs[5]) = v[5];
159
*(unsigned int*)(((char*)ptr)+scale*ofs[6]) = v[6];
160
*(unsigned int*)(((char*)ptr)+scale*ofs[7]) = v[7];
161
}
162
163
template<int scale = 4>
164
static __forceinline void scatter(const vboolf8& mask, void* ptr, const vint8& ofs, const vuint8& v)
165
{
166
if (likely(mask[0])) *(unsigned int*)(((char*)ptr)+scale*ofs[0]) = v[0];
167
if (likely(mask[1])) *(unsigned int*)(((char*)ptr)+scale*ofs[1]) = v[1];
168
if (likely(mask[2])) *(unsigned int*)(((char*)ptr)+scale*ofs[2]) = v[2];
169
if (likely(mask[3])) *(unsigned int*)(((char*)ptr)+scale*ofs[3]) = v[3];
170
if (likely(mask[4])) *(unsigned int*)(((char*)ptr)+scale*ofs[4]) = v[4];
171
if (likely(mask[5])) *(unsigned int*)(((char*)ptr)+scale*ofs[5]) = v[5];
172
if (likely(mask[6])) *(unsigned int*)(((char*)ptr)+scale*ofs[6]) = v[6];
173
if (likely(mask[7])) *(unsigned int*)(((char*)ptr)+scale*ofs[7]) = v[7];
174
}
175
176
177
static __forceinline vuint8 broadcast64(const long long& a) { return _mm256_set1_epi64x(a); }
178
179
////////////////////////////////////////////////////////////////////////////////
180
/// Array Access
181
////////////////////////////////////////////////////////////////////////////////
182
183
__forceinline const unsigned int& operator [](size_t index) const { assert(index < 8); return i[index]; }
184
__forceinline unsigned int& operator [](size_t index) { assert(index < 8); return i[index]; }
185
};
186
187
////////////////////////////////////////////////////////////////////////////////
188
/// Unary Operators
189
////////////////////////////////////////////////////////////////////////////////
190
191
__forceinline vboolf8 asBool(const vuint8& a) { return _mm256_castsi256_ps(a); }
192
193
__forceinline vuint8 operator +(const vuint8& a) { return a; }
194
195
////////////////////////////////////////////////////////////////////////////////
196
/// Binary Operators
197
////////////////////////////////////////////////////////////////////////////////
198
199
__forceinline vuint8 operator +(const vuint8& a, const vuint8& b) { return vuint8(_mm_add_epi32(a.vl, b.vl), _mm_add_epi32(a.vh, b.vh)); }
200
__forceinline vuint8 operator +(const vuint8& a, unsigned int b) { return a + vuint8(b); }
201
__forceinline vuint8 operator +(unsigned int a, const vuint8& b) { return vuint8(a) + b; }
202
203
__forceinline vuint8 operator -(const vuint8& a, const vuint8& b) { return vuint8(_mm_sub_epi32(a.vl, b.vl), _mm_sub_epi32(a.vh, b.vh)); }
204
__forceinline vuint8 operator -(const vuint8& a, unsigned int b) { return a - vuint8(b); }
205
__forceinline vuint8 operator -(unsigned int a, const vuint8& b) { return vuint8(a) - b; }
206
207
//__forceinline vuint8 operator *(const vuint8& a, const vuint8& b) { return vuint8(_mm_mullo_epu32(a.vl, b.vl), _mm_mullo_epu32(a.vh, b.vh)); }
208
//__forceinline vuint8 operator *(const vuint8& a, unsigned int b) { return a * vuint8(b); }
209
//__forceinline vuint8 operator *(unsigned int a, const vuint8& b) { return vuint8(a) * b; }
210
211
__forceinline vuint8 operator &(const vuint8& a, const vuint8& b) { return _mm256_castps_si256(_mm256_and_ps(_mm256_castsi256_ps(a), _mm256_castsi256_ps(b))); }
212
__forceinline vuint8 operator &(const vuint8& a, unsigned int b) { return a & vuint8(b); }
213
__forceinline vuint8 operator &(unsigned int a, const vuint8& b) { return vuint8(a) & b; }
214
215
__forceinline vuint8 operator |(const vuint8& a, const vuint8& b) { return _mm256_castps_si256(_mm256_or_ps (_mm256_castsi256_ps(a), _mm256_castsi256_ps(b))); }
216
__forceinline vuint8 operator |(const vuint8& a, unsigned int b) { return a | vuint8(b); }
217
__forceinline vuint8 operator |(unsigned int a, const vuint8& b) { return vuint8(a) | b; }
218
219
__forceinline vuint8 operator ^(const vuint8& a, const vuint8& b) { return _mm256_castps_si256(_mm256_xor_ps(_mm256_castsi256_ps(a), _mm256_castsi256_ps(b))); }
220
__forceinline vuint8 operator ^(const vuint8& a, unsigned int b) { return a ^ vuint8(b); }
221
__forceinline vuint8 operator ^(unsigned int a, const vuint8& b) { return vuint8(a) ^ b; }
222
223
__forceinline vuint8 operator <<(const vuint8& a, unsigned int n) { return vuint8(_mm_slli_epi32(a.vl, n), _mm_slli_epi32(a.vh, n)); }
224
__forceinline vuint8 operator >>(const vuint8& a, unsigned int n) { return vuint8(_mm_srai_epi32(a.vl, n), _mm_srli_epi32(a.vh, n)); }
225
226
__forceinline vuint8 sll (const vuint8& a, unsigned int b) { return vuint8(_mm_slli_epi32(a.vl, b), _mm_slli_epi32(a.vh, b)); }
227
__forceinline vuint8 sra (const vuint8& a, unsigned int b) { return vuint8(_mm_srai_epi32(a.vl, b), _mm_srai_epi32(a.vh, b)); }
228
__forceinline vuint8 srl (const vuint8& a, unsigned int b) { return vuint8(_mm_srli_epi32(a.vl, b), _mm_srli_epi32(a.vh, b)); }
229
230
__forceinline vuint8 min(const vuint8& a, const vuint8& b) { return vuint8(_mm_min_epu32(a.vl, b.vl), _mm_min_epu32(a.vh, b.vh)); }
231
__forceinline vuint8 min(const vuint8& a, unsigned int b) { return min(a,vuint8(b)); }
232
__forceinline vuint8 min(unsigned int a, const vuint8& b) { return min(vuint8(a),b); }
233
234
__forceinline vuint8 max(const vuint8& a, const vuint8& b) { return vuint8(_mm_max_epu32(a.vl, b.vl), _mm_max_epu32(a.vh, b.vh)); }
235
__forceinline vuint8 max(const vuint8& a, unsigned int b) { return max(a,vuint8(b)); }
236
__forceinline vuint8 max(unsigned int a, const vuint8& b) { return max(vuint8(a),b); }
237
238
////////////////////////////////////////////////////////////////////////////////
239
/// Assignment Operators
240
////////////////////////////////////////////////////////////////////////////////
241
242
__forceinline vuint8& operator +=(vuint8& a, const vuint8& b) { return a = a + b; }
243
__forceinline vuint8& operator +=(vuint8& a, unsigned int b) { return a = a + b; }
244
245
__forceinline vuint8& operator -=(vuint8& a, const vuint8& b) { return a = a - b; }
246
__forceinline vuint8& operator -=(vuint8& a, unsigned int b) { return a = a - b; }
247
248
//__forceinline vuint8& operator *=(vuint8& a, const vuint8& b) { return a = a * b; }
249
//__forceinline vuint8& operator *=(vuint8& a, unsigned int b) { return a = a * b; }
250
251
__forceinline vuint8& operator &=(vuint8& a, const vuint8& b) { return a = a & b; }
252
__forceinline vuint8& operator &=(vuint8& a, unsigned int b) { return a = a & b; }
253
254
__forceinline vuint8& operator |=(vuint8& a, const vuint8& b) { return a = a | b; }
255
__forceinline vuint8& operator |=(vuint8& a, unsigned int b) { return a = a | b; }
256
257
__forceinline vuint8& operator <<=(vuint8& a, unsigned int b) { return a = a << b; }
258
__forceinline vuint8& operator >>=(vuint8& a, unsigned int b) { return a = a >> b; }
259
260
////////////////////////////////////////////////////////////////////////////////
261
/// Comparison Operators + Select
262
////////////////////////////////////////////////////////////////////////////////
263
264
__forceinline vboolf8 operator ==(const vuint8& a, const vuint8& b) { return vboolf8(_mm_castsi128_ps(_mm_cmpeq_epi32 (a.vl, b.vl)),
265
_mm_castsi128_ps(_mm_cmpeq_epi32 (a.vh, b.vh))); }
266
__forceinline vboolf8 operator ==(const vuint8& a, unsigned int b) { return a == vuint8(b); }
267
__forceinline vboolf8 operator ==(unsigned int a, const vuint8& b) { return vuint8(a) == b; }
268
269
__forceinline vboolf8 operator !=(const vuint8& a, const vuint8& b) { return !(a == b); }
270
__forceinline vboolf8 operator !=(const vuint8& a, unsigned int b) { return a != vuint8(b); }
271
__forceinline vboolf8 operator !=(unsigned int a, const vuint8& b) { return vuint8(a) != b; }
272
273
//__forceinline vboolf8 operator < (const vuint8& a, const vuint8& b) { return vboolf8(_mm_castsi128_ps(_mm_cmplt_epu32 (a.vl, b.vl)),
274
// _mm_castsi128_ps(_mm_cmplt_epu32 (a.vh, b.vh))); }
275
//__forceinline vboolf8 operator < (const vuint8& a, unsigned int b) { return a < vuint8(b); }
276
//__forceinline vboolf8 operator < (unsigned int a, const vuint8& b) { return vuint8(a) < b; }
277
278
//__forceinline vboolf8 operator >=(const vuint8& a, const vuint8& b) { return !(a < b); }
279
//__forceinline vboolf8 operator >=(const vuint8& a, unsigned int b) { return a >= vuint8(b); }
280
//__forceinline vboolf8 operator >=(unsigned int a, const vuint8& b) { return vuint8(a) >= b; }
281
282
//__forceinline vboolf8 operator > (const vuint8& a, const vuint8& b) { return vboolf8(_mm_castsi128_ps(_mm_cmpgt_epu32 (a.vl, b.vl)),
283
// _mm_castsi128_ps(_mm_cmpgt_epu32 (a.vh, b.vh))); }
284
//__forceinline vboolf8 operator > (const vuint8& a, unsigned int b) { return a > vuint8(b); }
285
//__forceinline vboolf8 operator > (unsigned int a, const vuint8& b) { return vuint8(a) > b; }
286
287
//__forceinline vboolf8 operator <=(const vuint8& a, const vuint8& b) { return !(a > b); }
288
//__forceinline vboolf8 operator <=(const vuint8& a, unsigned int b) { return a <= vuint8(b); }
289
//__forceinline vboolf8 operator <=(unsigned int a, const vuint8& b) { return vuint8(a) <= b; }
290
291
__forceinline vboolf8 eq(const vuint8& a, const vuint8& b) { return a == b; }
292
__forceinline vboolf8 ne(const vuint8& a, const vuint8& b) { return a != b; }
293
294
__forceinline vboolf8 eq(const vboolf8& mask, const vuint8& a, const vuint8& b) { return mask & (a == b); }
295
__forceinline vboolf8 ne(const vboolf8& mask, const vuint8& a, const vuint8& b) { return mask & (a != b); }
296
297
__forceinline vuint8 select(const vboolf8& m, const vuint8& t, const vuint8& f) {
298
return _mm256_castps_si256(_mm256_blendv_ps(_mm256_castsi256_ps(f), _mm256_castsi256_ps(t), m));
299
}
300
301
302
////////////////////////////////////////////////////////////////////////////////
303
/// Movement/Shifting/Shuffling Functions
304
////////////////////////////////////////////////////////////////////////////////
305
306
__forceinline vuint8 unpacklo(const vuint8& a, const vuint8& b) { return _mm256_castps_si256(_mm256_unpacklo_ps(_mm256_castsi256_ps(a), _mm256_castsi256_ps(b))); }
307
__forceinline vuint8 unpackhi(const vuint8& a, const vuint8& b) { return _mm256_castps_si256(_mm256_unpackhi_ps(_mm256_castsi256_ps(a), _mm256_castsi256_ps(b))); }
308
309
template<int i>
310
__forceinline vuint8 shuffle(const vuint8& v) {
311
return _mm256_castps_si256(_mm256_permute_ps(_mm256_castsi256_ps(v), _MM_SHUFFLE(i, i, i, i)));
312
}
313
314
template<int i0, int i1>
315
__forceinline vuint8 shuffle4(const vuint8& v) {
316
return _mm256_permute2f128_si256(v, v, (i1 << 4) | (i0 << 0));
317
}
318
319
template<int i0, int i1>
320
__forceinline vuint8 shuffle4(const vuint8& a, const vuint8& b) {
321
return _mm256_permute2f128_si256(a, b, (i1 << 4) | (i0 << 0));
322
}
323
324
template<int i0, int i1, int i2, int i3>
325
__forceinline vuint8 shuffle(const vuint8& v) {
326
return _mm256_castps_si256(_mm256_permute_ps(_mm256_castsi256_ps(v), _MM_SHUFFLE(i3, i2, i1, i0)));
327
}
328
329
template<int i0, int i1, int i2, int i3>
330
__forceinline vuint8 shuffle(const vuint8& a, const vuint8& b) {
331
return _mm256_castps_si256(_mm256_shuffle_ps(_mm256_castsi256_ps(a), _mm256_castsi256_ps(b), _MM_SHUFFLE(i3, i2, i1, i0)));
332
}
333
334
template<> __forceinline vuint8 shuffle<0, 0, 2, 2>(const vuint8& v) { return _mm256_castps_si256(_mm256_moveldup_ps(_mm256_castsi256_ps(v))); }
335
template<> __forceinline vuint8 shuffle<1, 1, 3, 3>(const vuint8& v) { return _mm256_castps_si256(_mm256_movehdup_ps(_mm256_castsi256_ps(v))); }
336
template<> __forceinline vuint8 shuffle<0, 1, 0, 1>(const vuint8& v) { return _mm256_castps_si256(_mm256_castpd_ps(_mm256_movedup_pd(_mm256_castps_pd(_mm256_castsi256_ps(v))))); }
337
338
template<int i> __forceinline vuint8 insert4(const vuint8& a, const vuint4& b) { return _mm256_insertf128_si256(a, b, i); }
339
template<int i> __forceinline vuint4 extract4(const vuint8& a) { return _mm256_extractf128_si256(a, i); }
340
template<> __forceinline vuint4 extract4<0>(const vuint8& a) { return _mm256_castsi256_si128(a); }
341
342
__forceinline int toScalar(const vuint8& v) { return _mm_cvtsi128_si32(_mm256_castsi256_si128(v)); }
343
344
345
////////////////////////////////////////////////////////////////////////////////
346
/// Reductions
347
////////////////////////////////////////////////////////////////////////////////
348
349
//__forceinline vuint8 vreduce_min2(const vuint8& v) { return min(v,shuffle<1,0,3,2>(v)); }
350
//__forceinline vuint8 vreduce_min4(const vuint8& v) { vuint8 v1 = vreduce_min2(v); return min(v1,shuffle<2,3,0,1>(v1)); }
351
//__forceinline vuint8 vreduce_min (const vuint8& v) { vuint8 v1 = vreduce_min4(v); return min(v1,shuffle4<1,0>(v1)); }
352
353
//__forceinline vuint8 vreduce_max2(const vuint8& v) { return max(v,shuffle<1,0,3,2>(v)); }
354
//__forceinline vuint8 vreduce_max4(const vuint8& v) { vuint8 v1 = vreduce_max2(v); return max(v1,shuffle<2,3,0,1>(v1)); }
355
//__forceinline vuint8 vreduce_max (const vuint8& v) { vuint8 v1 = vreduce_max4(v); return max(v1,shuffle4<1,0>(v1)); }
356
357
__forceinline vuint8 vreduce_add2(const vuint8& v) { return v + shuffle<1,0,3,2>(v); }
358
__forceinline vuint8 vreduce_add4(const vuint8& v) { vuint8 v1 = vreduce_add2(v); return v1 + shuffle<2,3,0,1>(v1); }
359
__forceinline vuint8 vreduce_add (const vuint8& v) { vuint8 v1 = vreduce_add4(v); return v1 + shuffle4<1,0>(v1); }
360
361
//__forceinline int reduce_min(const vuint8& v) { return toScalar(vreduce_min(v)); }
362
//__forceinline int reduce_max(const vuint8& v) { return toScalar(vreduce_max(v)); }
363
__forceinline int reduce_add(const vuint8& v) { return toScalar(vreduce_add(v)); }
364
365
//__forceinline size_t select_min(const vuint8& v) { return bsf(movemask(v == vreduce_min(v))); }
366
//__forceinline size_t select_max(const vuint8& v) { return bsf(movemask(v == vreduce_max(v))); }
367
368
//__forceinline size_t select_min(const vboolf8& valid, const vuint8& v) { const vuint8 a = select(valid,v,vuint8(pos_inf)); return bsf(movemask(valid & (a == vreduce_min(a)))); }
369
//__forceinline size_t select_max(const vboolf8& valid, const vuint8& v) { const vuint8 a = select(valid,v,vuint8(neg_inf)); return bsf(movemask(valid & (a == vreduce_max(a)))); }
370
371
////////////////////////////////////////////////////////////////////////////////
372
/// Output Operators
373
////////////////////////////////////////////////////////////////////////////////
374
375
__forceinline embree_ostream operator <<(embree_ostream cout, const vuint8& a) {
376
return cout << "<" << a[0] << ", " << a[1] << ", " << a[2] << ", " << a[3] << ", " << a[4] << ", " << a[5] << ", " << a[6] << ", " << a[7] << ">";
377
}
378
}
379
380
#undef vboolf
381
#undef vboold
382
#undef vint
383
#undef vuint
384
#undef vllong
385
#undef vfloat
386
#undef vdouble
387
388