Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/embree/common/simd/vint16_avx512.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
/* 16-wide AVX-512 integer type */
17
template<>
18
struct vint<16>
19
{
20
ALIGNED_STRUCT_(64);
21
22
typedef vboolf16 Bool;
23
typedef vint16 Int;
24
typedef vfloat16 Float;
25
26
enum { size = 16 }; // number of SIMD elements
27
union { // data
28
__m512i v;
29
int i[16];
30
};
31
32
////////////////////////////////////////////////////////////////////////////////
33
/// Constructors, Assignment & Cast Operators
34
////////////////////////////////////////////////////////////////////////////////
35
36
__forceinline vint() {}
37
__forceinline vint(const vint16& t) { v = t.v; }
38
__forceinline vint16& operator =(const vint16& f) { v = f.v; return *this; }
39
40
__forceinline vint(const __m512i& t) { v = t; }
41
__forceinline operator __m512i() const { return v; }
42
__forceinline operator __m256i() const { return _mm512_castsi512_si256(v); }
43
44
__forceinline vint(int i) {
45
v = _mm512_set1_epi32(i);
46
}
47
48
__forceinline vint(int a, int b, int c, int d) {
49
v = _mm512_set4_epi32(d,c,b,a);
50
}
51
52
__forceinline vint(int a0 , int a1 , int a2 , int a3,
53
int a4 , int a5 , int a6 , int a7,
54
int a8 , int a9 , int a10, int a11,
55
int a12, int a13, int a14, int a15)
56
{
57
v = _mm512_set_epi32(a15,a14,a13,a12,a11,a10,a9,a8,a7,a6,a5,a4,a3,a2,a1,a0);
58
}
59
60
__forceinline vint(const vint4& i) {
61
v = _mm512_broadcast_i32x4(i);
62
}
63
64
__forceinline vint(const vint4& a, const vint4& b, const vint4& c, const vint4& d) {
65
v = _mm512_castsi128_si512(a);
66
v = _mm512_inserti32x4(v, b, 1);
67
v = _mm512_inserti32x4(v, c, 2);
68
v = _mm512_inserti32x4(v, d, 3);
69
}
70
71
__forceinline vint(const vint8& i) {
72
v = _mm512_castps_si512(_mm512_castpd_ps(_mm512_broadcast_f64x4(_mm256_castsi256_pd(i))));
73
}
74
75
__forceinline vint(const vint8& a, const vint8& b) {
76
v = _mm512_castsi256_si512(a);
77
v = _mm512_inserti64x4(v, b, 1);
78
}
79
80
__forceinline explicit vint(const __m512& f) {
81
v = _mm512_cvtps_epi32(f);
82
}
83
84
////////////////////////////////////////////////////////////////////////////////
85
/// Constants
86
////////////////////////////////////////////////////////////////////////////////
87
88
__forceinline vint(ZeroTy) : v(_mm512_setzero_epi32()) {}
89
__forceinline vint(OneTy) : v(_mm512_set1_epi32(1)) {}
90
__forceinline vint(PosInfTy) : v(_mm512_set1_epi32(pos_inf)) {}
91
__forceinline vint(NegInfTy) : v(_mm512_set1_epi32(neg_inf)) {}
92
__forceinline vint(StepTy) : v(_mm512_set_epi32(15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)) {}
93
__forceinline vint(ReverseStepTy) : v(_mm512_setr_epi32(15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)) {}
94
95
////////////////////////////////////////////////////////////////////////////////
96
/// Loads and Stores
97
////////////////////////////////////////////////////////////////////////////////
98
99
static __forceinline vint16 load (const void* addr) { return _mm512_load_si512((int*)addr); }
100
101
static __forceinline vint16 load(const unsigned char* ptr) { return _mm512_cvtepu8_epi32(_mm_load_si128((__m128i*)ptr)); }
102
static __forceinline vint16 load(const unsigned short* ptr) { return _mm512_cvtepu16_epi32(_mm256_load_si256((__m256i*)ptr)); }
103
104
static __forceinline vint16 loadu(const unsigned char* ptr) { return _mm512_cvtepu8_epi32(_mm_loadu_si128((__m128i*)ptr)); }
105
static __forceinline vint16 loadu(const unsigned short* ptr) { return _mm512_cvtepu16_epi32(_mm256_loadu_si256((__m256i*)ptr)); }
106
107
static __forceinline vint16 loadu(const void* addr) { return _mm512_loadu_si512(addr); }
108
109
static __forceinline vint16 load (const vboolf16& mask, const void* addr) { return _mm512_mask_load_epi32 (_mm512_setzero_epi32(),mask,addr); }
110
static __forceinline vint16 loadu(const vboolf16& mask, const void* addr) { return _mm512_mask_loadu_epi32(_mm512_setzero_epi32(),mask,addr); }
111
112
static __forceinline void store (void* ptr, const vint16& v) { _mm512_store_si512 (ptr,v); }
113
static __forceinline void storeu(void* ptr, const vint16& v) { _mm512_storeu_si512(ptr,v); }
114
115
static __forceinline void store (const vboolf16& mask, void* addr, const vint16& v2) { _mm512_mask_store_epi32(addr,mask,v2); }
116
static __forceinline void storeu(const vboolf16& mask, void* ptr, const vint16& f) { _mm512_mask_storeu_epi32((int*)ptr,mask,f); }
117
118
static __forceinline void store_nt(void* __restrict__ ptr, const vint16& a) { _mm512_stream_si512((__m512i*)ptr,a); }
119
120
static __forceinline vint16 compact(const vboolf16& mask, vint16 &v) {
121
return _mm512_mask_compress_epi32(v,mask,v);
122
}
123
124
static __forceinline vint16 compact(const vboolf16& mask, const vint16 &a, vint16 &b) {
125
return _mm512_mask_compress_epi32(a,mask,b);
126
}
127
128
static __forceinline vint16 expand(const vboolf16& mask, const vint16& a, vint16& b) {
129
return _mm512_mask_expand_epi32(b,mask,a);
130
}
131
132
template<int scale = 4>
133
static __forceinline vint16 gather(const int* ptr, const vint16& index) {
134
return _mm512_i32gather_epi32(index,ptr,scale);
135
}
136
137
template<int scale = 4>
138
static __forceinline vint16 gather(const vboolf16& mask, const int* ptr, const vint16& index) {
139
return _mm512_mask_i32gather_epi32(_mm512_undefined_epi32(),mask,index,ptr,scale);
140
}
141
142
template<int scale = 4>
143
static __forceinline vint16 gather(const vboolf16& mask, vint16& dest, const int* ptr, const vint16& index) {
144
return _mm512_mask_i32gather_epi32(dest,mask,index,ptr,scale);
145
}
146
147
template<int scale = 4>
148
static __forceinline void scatter(int* ptr, const vint16& index, const vint16& v) {
149
_mm512_i32scatter_epi32((int*)ptr,index,v,scale);
150
}
151
152
template<int scale = 4>
153
static __forceinline void scatter(const vboolf16& mask, int* ptr, const vint16& index, const vint16& v) {
154
_mm512_mask_i32scatter_epi32((int*)ptr,mask,index,v,scale);
155
}
156
157
////////////////////////////////////////////////////////////////////////////////
158
/// Array Access
159
////////////////////////////////////////////////////////////////////////////////
160
161
__forceinline int& operator [](size_t index) { assert(index < 16); return i[index]; }
162
__forceinline const int& operator [](size_t index) const { assert(index < 16); return i[index]; }
163
164
__forceinline unsigned int uint (size_t index) const { assert(index < 16); return ((unsigned int*)i)[index]; }
165
__forceinline size_t& uint64_t(size_t index) const { assert(index < 8); return ((size_t*)i)[index]; }
166
};
167
168
////////////////////////////////////////////////////////////////////////////////
169
/// Unary Operators
170
////////////////////////////////////////////////////////////////////////////////
171
172
__forceinline vboolf16 asBool(const vint16& a) { return _mm512_movepi32_mask(a); }
173
174
__forceinline vint16 operator +(const vint16& a) { return a; }
175
__forceinline vint16 operator -(const vint16& a) { return _mm512_sub_epi32(_mm512_setzero_epi32(), a); }
176
177
////////////////////////////////////////////////////////////////////////////////
178
/// Binary Operators
179
////////////////////////////////////////////////////////////////////////////////
180
181
__forceinline vint16 operator +(const vint16& a, const vint16& b) { return _mm512_add_epi32(a, b); }
182
__forceinline vint16 operator +(const vint16& a, int b) { return a + vint16(b); }
183
__forceinline vint16 operator +(int a, const vint16& b) { return vint16(a) + b; }
184
185
__forceinline vint16 operator -(const vint16& a, const vint16& b) { return _mm512_sub_epi32(a, b); }
186
__forceinline vint16 operator -(const vint16& a, int b) { return a - vint16(b); }
187
__forceinline vint16 operator -(int a, const vint16& b) { return vint16(a) - b; }
188
189
__forceinline vint16 operator *(const vint16& a, const vint16& b) { return _mm512_mullo_epi32(a, b); }
190
__forceinline vint16 operator *(const vint16& a, int b) { return a * vint16(b); }
191
__forceinline vint16 operator *(int a, const vint16& b) { return vint16(a) * b; }
192
193
__forceinline vint16 operator &(const vint16& a, const vint16& b) { return _mm512_and_epi32(a, b); }
194
__forceinline vint16 operator &(const vint16& a, int b) { return a & vint16(b); }
195
__forceinline vint16 operator &(int a, const vint16& b) { return vint16(a) & b; }
196
197
__forceinline vint16 operator |(const vint16& a, const vint16& b) { return _mm512_or_epi32(a, b); }
198
__forceinline vint16 operator |(const vint16& a, int b) { return a | vint16(b); }
199
__forceinline vint16 operator |(int a, const vint16& b) { return vint16(a) | b; }
200
201
__forceinline vint16 operator ^(const vint16& a, const vint16& b) { return _mm512_xor_epi32(a, b); }
202
__forceinline vint16 operator ^(const vint16& a, int b) { return a ^ vint16(b); }
203
__forceinline vint16 operator ^(int a, const vint16& b) { return vint16(a) ^ b; }
204
205
__forceinline vint16 operator <<(const vint16& a, int n) { return _mm512_slli_epi32(a, n); }
206
__forceinline vint16 operator >>(const vint16& a, int n) { return _mm512_srai_epi32(a, n); }
207
208
__forceinline vint16 operator <<(const vint16& a, const vint16& n) { return _mm512_sllv_epi32(a, n); }
209
__forceinline vint16 operator >>(const vint16& a, const vint16& n) { return _mm512_srav_epi32(a, n); }
210
211
__forceinline vint16 sll (const vint16& a, int b) { return _mm512_slli_epi32(a, b); }
212
__forceinline vint16 sra (const vint16& a, int b) { return _mm512_srai_epi32(a, b); }
213
__forceinline vint16 srl (const vint16& a, int b) { return _mm512_srli_epi32(a, b); }
214
215
__forceinline vint16 min(const vint16& a, const vint16& b) { return _mm512_min_epi32(a, b); }
216
__forceinline vint16 min(const vint16& a, int b) { return min(a,vint16(b)); }
217
__forceinline vint16 min(int a, const vint16& b) { return min(vint16(a),b); }
218
219
__forceinline vint16 max(const vint16& a, const vint16& b) { return _mm512_max_epi32(a, b); }
220
__forceinline vint16 max(const vint16& a, int b) { return max(a,vint16(b)); }
221
__forceinline vint16 max(int a, const vint16& b) { return max(vint16(a),b); }
222
223
__forceinline vint16 umin(const vint16& a, const vint16& b) { return _mm512_min_epu32(a, b); }
224
__forceinline vint16 umax(const vint16& a, const vint16& b) { return _mm512_max_epu32(a, b); }
225
226
__forceinline vint16 mask_add(const vboolf16& mask, vint16& c, const vint16& a, const vint16& b) { return _mm512_mask_add_epi32(c,mask,a,b); }
227
__forceinline vint16 mask_sub(const vboolf16& mask, vint16& c, const vint16& a, const vint16& b) { return _mm512_mask_sub_epi32(c,mask,a,b); }
228
229
__forceinline vint16 mask_and(const vboolf16& m, vint16& c, const vint16& a, const vint16& b) { return _mm512_mask_and_epi32(c,m,a,b); }
230
__forceinline vint16 mask_or (const vboolf16& m, vint16& c, const vint16& a, const vint16& b) { return _mm512_mask_or_epi32(c,m,a,b); }
231
232
////////////////////////////////////////////////////////////////////////////////
233
/// Assignment Operators
234
////////////////////////////////////////////////////////////////////////////////
235
236
__forceinline vint16& operator +=(vint16& a, const vint16& b) { return a = a + b; }
237
__forceinline vint16& operator +=(vint16& a, int b) { return a = a + b; }
238
239
__forceinline vint16& operator -=(vint16& a, const vint16& b) { return a = a - b; }
240
__forceinline vint16& operator -=(vint16& a, int b) { return a = a - b; }
241
242
__forceinline vint16& operator *=(vint16& a, const vint16& b) { return a = a * b; }
243
__forceinline vint16& operator *=(vint16& a, int b) { return a = a * b; }
244
245
__forceinline vint16& operator &=(vint16& a, const vint16& b) { return a = a & b; }
246
__forceinline vint16& operator &=(vint16& a, int b) { return a = a & b; }
247
248
__forceinline vint16& operator |=(vint16& a, const vint16& b) { return a = a | b; }
249
__forceinline vint16& operator |=(vint16& a, int b) { return a = a | b; }
250
251
__forceinline vint16& operator <<=(vint16& a, int b) { return a = a << b; }
252
__forceinline vint16& operator >>=(vint16& a, int b) { return a = a >> b; }
253
254
255
////////////////////////////////////////////////////////////////////////////////
256
/// Comparison Operators + Select
257
////////////////////////////////////////////////////////////////////////////////
258
259
__forceinline vboolf16 operator ==(const vint16& a, const vint16& b) { return _mm512_cmp_epi32_mask(a,b,_MM_CMPINT_EQ); }
260
__forceinline vboolf16 operator ==(const vint16& a, int b) { return a == vint16(b); }
261
__forceinline vboolf16 operator ==(int a, const vint16& b) { return vint16(a) == b; }
262
263
__forceinline vboolf16 operator !=(const vint16& a, const vint16& b) { return _mm512_cmp_epi32_mask(a,b,_MM_CMPINT_NE); }
264
__forceinline vboolf16 operator !=(const vint16& a, int b) { return a != vint16(b); }
265
__forceinline vboolf16 operator !=(int a, const vint16& b) { return vint16(a) != b; }
266
267
__forceinline vboolf16 operator < (const vint16& a, const vint16& b) { return _mm512_cmp_epi32_mask(a,b,_MM_CMPINT_LT); }
268
__forceinline vboolf16 operator < (const vint16& a, int b) { return a < vint16(b); }
269
__forceinline vboolf16 operator < (int a, const vint16& b) { return vint16(a) < b; }
270
271
__forceinline vboolf16 operator >=(const vint16& a, const vint16& b) { return _mm512_cmp_epi32_mask(a,b,_MM_CMPINT_GE); }
272
__forceinline vboolf16 operator >=(const vint16& a, int b) { return a >= vint16(b); }
273
__forceinline vboolf16 operator >=(int a, const vint16& b) { return vint16(a) >= b; }
274
275
__forceinline vboolf16 operator > (const vint16& a, const vint16& b) { return _mm512_cmp_epi32_mask(a,b,_MM_CMPINT_GT); }
276
__forceinline vboolf16 operator > (const vint16& a, int b) { return a > vint16(b); }
277
__forceinline vboolf16 operator > (int a, const vint16& b) { return vint16(a) > b; }
278
279
__forceinline vboolf16 operator <=(const vint16& a, const vint16& b) { return _mm512_cmp_epi32_mask(a,b,_MM_CMPINT_LE); }
280
__forceinline vboolf16 operator <=(const vint16& a, int b) { return a <= vint16(b); }
281
__forceinline vboolf16 operator <=(int a, const vint16& b) { return vint16(a) <= b; }
282
283
__forceinline vboolf16 eq(const vint16& a, const vint16& b) { return _mm512_cmp_epi32_mask(a,b,_MM_CMPINT_EQ); }
284
__forceinline vboolf16 ne(const vint16& a, const vint16& b) { return _mm512_cmp_epi32_mask(a,b,_MM_CMPINT_NE); }
285
__forceinline vboolf16 lt(const vint16& a, const vint16& b) { return _mm512_cmp_epi32_mask(a,b,_MM_CMPINT_LT); }
286
__forceinline vboolf16 ge(const vint16& a, const vint16& b) { return _mm512_cmp_epi32_mask(a,b,_MM_CMPINT_GE); }
287
__forceinline vboolf16 gt(const vint16& a, const vint16& b) { return _mm512_cmp_epi32_mask(a,b,_MM_CMPINT_GT); }
288
__forceinline vboolf16 le(const vint16& a, const vint16& b) { return _mm512_cmp_epi32_mask(a,b,_MM_CMPINT_LE); }
289
__forceinline vboolf16 uint_le(const vint16& a, const vint16& b) { return _mm512_cmp_epu32_mask(a,b,_MM_CMPINT_LE); }
290
__forceinline vboolf16 uint_gt(const vint16& a, const vint16& b) { return _mm512_cmp_epu32_mask(a,b,_MM_CMPINT_GT); }
291
292
__forceinline vboolf16 eq(const vboolf16 mask, const vint16& a, const vint16& b) { return _mm512_mask_cmp_epi32_mask(mask,a,b,_MM_CMPINT_EQ); }
293
__forceinline vboolf16 ne(const vboolf16 mask, const vint16& a, const vint16& b) { return _mm512_mask_cmp_epi32_mask(mask,a,b,_MM_CMPINT_NE); }
294
__forceinline vboolf16 lt(const vboolf16 mask, const vint16& a, const vint16& b) { return _mm512_mask_cmp_epi32_mask(mask,a,b,_MM_CMPINT_LT); }
295
__forceinline vboolf16 ge(const vboolf16 mask, const vint16& a, const vint16& b) { return _mm512_mask_cmp_epi32_mask(mask,a,b,_MM_CMPINT_GE); }
296
__forceinline vboolf16 gt(const vboolf16 mask, const vint16& a, const vint16& b) { return _mm512_mask_cmp_epi32_mask(mask,a,b,_MM_CMPINT_GT); }
297
__forceinline vboolf16 le(const vboolf16 mask, const vint16& a, const vint16& b) { return _mm512_mask_cmp_epi32_mask(mask,a,b,_MM_CMPINT_LE); }
298
__forceinline vboolf16 uint_le(const vboolf16 mask, const vint16& a, const vint16& b) { return _mm512_mask_cmp_epu32_mask(mask,a,b,_MM_CMPINT_LE); }
299
__forceinline vboolf16 uint_gt(const vboolf16 mask, const vint16& a, const vint16& b) { return _mm512_mask_cmp_epu32_mask(mask,a,b,_MM_CMPINT_GT); }
300
301
302
__forceinline vint16 select(const vboolf16& m, const vint16& t, const vint16& f) {
303
return _mm512_mask_or_epi32(f,m,t,t);
304
}
305
306
////////////////////////////////////////////////////////////////////////////////
307
// Movement/Shifting/Shuffling Functions
308
////////////////////////////////////////////////////////////////////////////////
309
310
__forceinline vint16 unpacklo(const vint16& a, const vint16& b) { return _mm512_unpacklo_epi32(a, b); }
311
__forceinline vint16 unpackhi(const vint16& a, const vint16& b) { return _mm512_unpackhi_epi32(a, b); }
312
313
template<int i>
314
__forceinline vint16 shuffle(const vint16& v) {
315
return _mm512_castps_si512(_mm512_permute_ps(_mm512_castsi512_ps(v), _MM_SHUFFLE(i, i, i, i)));
316
}
317
318
template<int i0, int i1, int i2, int i3>
319
__forceinline vint16 shuffle(const vint16& v) {
320
return _mm512_castps_si512(_mm512_permute_ps(_mm512_castsi512_ps(v), _MM_SHUFFLE(i3, i2, i1, i0)));
321
}
322
323
template<int i>
324
__forceinline vint16 shuffle4(const vint16& v) {
325
return _mm512_castps_si512(_mm512_shuffle_f32x4(_mm512_castsi512_ps(v), _mm512_castsi512_ps(v), _MM_SHUFFLE(i, i, i, i)));
326
}
327
328
template<int i0, int i1, int i2, int i3>
329
__forceinline vint16 shuffle4(const vint16& v) {
330
return _mm512_castps_si512(_mm512_shuffle_f32x4(_mm512_castsi512_ps(v), _mm512_castsi512_ps(v), _MM_SHUFFLE(i3, i2, i1, i0)));
331
}
332
333
template<int i>
334
__forceinline vint16 align_shift_right(const vint16& a, const vint16& b) {
335
return _mm512_alignr_epi32(a, b, i);
336
};
337
338
__forceinline int toScalar(const vint16& v) {
339
return _mm_cvtsi128_si32(_mm512_castsi512_si128(v));
340
}
341
342
template<int i> __forceinline vint16 insert4(const vint16& a, const vint4& b) { return _mm512_inserti32x4(a, b, i); }
343
344
template<int N, int i>
345
vint<N> extractN(const vint16& v);
346
347
template<> __forceinline vint4 extractN<4,0>(const vint16& v) { return _mm512_castsi512_si128(v); }
348
template<> __forceinline vint4 extractN<4,1>(const vint16& v) { return _mm512_extracti32x4_epi32(v, 1); }
349
template<> __forceinline vint4 extractN<4,2>(const vint16& v) { return _mm512_extracti32x4_epi32(v, 2); }
350
template<> __forceinline vint4 extractN<4,3>(const vint16& v) { return _mm512_extracti32x4_epi32(v, 3); }
351
352
template<> __forceinline vint8 extractN<8,0>(const vint16& v) { return _mm512_castsi512_si256(v); }
353
template<> __forceinline vint8 extractN<8,1>(const vint16& v) { return _mm512_extracti32x8_epi32(v, 1); }
354
355
template<int i> __forceinline vint4 extract4 (const vint16& v) { return _mm512_extracti32x4_epi32(v, i); }
356
template<> __forceinline vint4 extract4<0>(const vint16& v) { return _mm512_castsi512_si128(v); }
357
358
template<int i> __forceinline vint8 extract8 (const vint16& v) { return _mm512_extracti32x8_epi32(v, i); }
359
template<> __forceinline vint8 extract8<0>(const vint16& v) { return _mm512_castsi512_si256(v); }
360
361
////////////////////////////////////////////////////////////////////////////////
362
/// Reductions
363
////////////////////////////////////////////////////////////////////////////////
364
365
__forceinline vint16 vreduce_min2(vint16 x) { return min(x, shuffle<1,0,3,2>(x)); }
366
__forceinline vint16 vreduce_min4(vint16 x) { x = vreduce_min2(x); return min(x, shuffle<2,3,0,1>(x)); }
367
__forceinline vint16 vreduce_min8(vint16 x) { x = vreduce_min4(x); return min(x, shuffle4<1,0,3,2>(x)); }
368
__forceinline vint16 vreduce_min (vint16 x) { x = vreduce_min8(x); return min(x, shuffle4<2,3,0,1>(x)); }
369
370
__forceinline vint16 vreduce_max2(vint16 x) { return max(x, shuffle<1,0,3,2>(x)); }
371
__forceinline vint16 vreduce_max4(vint16 x) { x = vreduce_max2(x); return max(x, shuffle<2,3,0,1>(x)); }
372
__forceinline vint16 vreduce_max8(vint16 x) { x = vreduce_max4(x); return max(x, shuffle4<1,0,3,2>(x)); }
373
__forceinline vint16 vreduce_max (vint16 x) { x = vreduce_max8(x); return max(x, shuffle4<2,3,0,1>(x)); }
374
375
__forceinline vint16 vreduce_and2(vint16 x) { return x & shuffle<1,0,3,2>(x); }
376
__forceinline vint16 vreduce_and4(vint16 x) { x = vreduce_and2(x); return x & shuffle<2,3,0,1>(x); }
377
__forceinline vint16 vreduce_and8(vint16 x) { x = vreduce_and4(x); return x & shuffle4<1,0,3,2>(x); }
378
__forceinline vint16 vreduce_and (vint16 x) { x = vreduce_and8(x); return x & shuffle4<2,3,0,1>(x); }
379
380
__forceinline vint16 vreduce_or2(vint16 x) { return x | shuffle<1,0,3,2>(x); }
381
__forceinline vint16 vreduce_or4(vint16 x) { x = vreduce_or2(x); return x | shuffle<2,3,0,1>(x); }
382
__forceinline vint16 vreduce_or8(vint16 x) { x = vreduce_or4(x); return x | shuffle4<1,0,3,2>(x); }
383
__forceinline vint16 vreduce_or (vint16 x) { x = vreduce_or8(x); return x | shuffle4<2,3,0,1>(x); }
384
385
__forceinline vint16 vreduce_add2(vint16 x) { return x + shuffle<1,0,3,2>(x); }
386
__forceinline vint16 vreduce_add4(vint16 x) { x = vreduce_add2(x); return x + shuffle<2,3,0,1>(x); }
387
__forceinline vint16 vreduce_add8(vint16 x) { x = vreduce_add4(x); return x + shuffle4<1,0,3,2>(x); }
388
__forceinline vint16 vreduce_add (vint16 x) { x = vreduce_add8(x); return x + shuffle4<2,3,0,1>(x); }
389
390
__forceinline int reduce_min(const vint16& v) { return toScalar(vreduce_min(v)); }
391
__forceinline int reduce_max(const vint16& v) { return toScalar(vreduce_max(v)); }
392
__forceinline int reduce_and(const vint16& v) { return toScalar(vreduce_and(v)); }
393
__forceinline int reduce_or (const vint16& v) { return toScalar(vreduce_or (v)); }
394
__forceinline int reduce_add(const vint16& v) { return toScalar(vreduce_add(v)); }
395
396
////////////////////////////////////////////////////////////////////////////////
397
/// Memory load and store operations
398
////////////////////////////////////////////////////////////////////////////////
399
400
__forceinline vint16 conflict(const vint16& index)
401
{
402
return _mm512_conflict_epi32(index);
403
}
404
405
__forceinline vint16 conflict(const vboolf16& mask, vint16& dest, const vint16& index)
406
{
407
return _mm512_mask_conflict_epi32(dest,mask,index);
408
}
409
410
__forceinline vint16 convert_uint32_t(const __m512& f) {
411
return _mm512_cvtps_epu32(f);
412
}
413
414
__forceinline vint16 permute(vint16 v, vint16 index) {
415
return _mm512_permutexvar_epi32(index,v);
416
}
417
418
__forceinline vint16 reverse(const vint16 &a) {
419
return permute(a,vint16(reverse_step));
420
}
421
422
__forceinline vint16 prefix_sum(const vint16& a)
423
{
424
const vint16 z(zero);
425
vint16 v = a;
426
v = v + align_shift_right<16-1>(v,z);
427
v = v + align_shift_right<16-2>(v,z);
428
v = v + align_shift_right<16-4>(v,z);
429
v = v + align_shift_right<16-8>(v,z);
430
return v;
431
}
432
433
__forceinline vint16 reverse_prefix_sum(const vint16& a)
434
{
435
const vint16 z(zero);
436
vint16 v = a;
437
v = v + align_shift_right<1>(z,v);
438
v = v + align_shift_right<2>(z,v);
439
v = v + align_shift_right<4>(z,v);
440
v = v + align_shift_right<8>(z,v);
441
return v;
442
}
443
444
/* this should use a vbool8 and a vint8_64...*/
445
template<int scale = 1, int hint = _MM_HINT_T0>
446
__forceinline void gather_prefetch64(const void* base_addr, const vbool16& mask, const vint16& offset)
447
{
448
#if defined(__AVX512PF__)
449
_mm512_mask_prefetch_i64gather_pd(offset, mask, base_addr, scale, hint);
450
#endif
451
}
452
453
////////////////////////////////////////////////////////////////////////////////
454
/// Output Operators
455
////////////////////////////////////////////////////////////////////////////////
456
457
__forceinline embree_ostream operator <<(embree_ostream cout, const vint16& v)
458
{
459
cout << "<" << v[0];
460
for (int i=1; i<16; i++) cout << ", " << v[i];
461
cout << ">";
462
return cout;
463
}
464
}
465
466
#undef vboolf
467
#undef vboold
468
#undef vint
469
#undef vuint
470
#undef vllong
471
#undef vfloat
472
#undef vdouble
473
474