Path: blob/master/thirdparty/embree/common/simd/vint16_avx512.h
9912 views
// Copyright 2009-2021 Intel Corporation1// SPDX-License-Identifier: Apache-2.023#pragma once45#define vboolf vboolf_impl6#define vboold vboold_impl7#define vint vint_impl8#define vuint vuint_impl9#define vllong vllong_impl10#define vfloat vfloat_impl11#define vdouble vdouble_impl1213namespace embree14{15/* 16-wide AVX-512 integer type */16template<>17struct vint<16>18{19ALIGNED_STRUCT_(64);2021typedef vboolf16 Bool;22typedef vint16 Int;23typedef vfloat16 Float;2425enum { size = 16 }; // number of SIMD elements26union { // data27__m512i v;28int i[16];29};3031////////////////////////////////////////////////////////////////////////////////32/// Constructors, Assignment & Cast Operators33////////////////////////////////////////////////////////////////////////////////3435__forceinline vint() {}36__forceinline vint(const vint16& t) { v = t.v; }37__forceinline vint16& operator =(const vint16& f) { v = f.v; return *this; }3839__forceinline vint(const __m512i& t) { v = t; }40__forceinline operator __m512i() const { return v; }41__forceinline operator __m256i() const { return _mm512_castsi512_si256(v); }4243__forceinline vint(int i) {44v = _mm512_set1_epi32(i);45}4647__forceinline vint(int a, int b, int c, int d) {48v = _mm512_set4_epi32(d,c,b,a);49}5051__forceinline vint(int a0 , int a1 , int a2 , int a3,52int a4 , int a5 , int a6 , int a7,53int a8 , int a9 , int a10, int a11,54int a12, int a13, int a14, int a15)55{56v = _mm512_set_epi32(a15,a14,a13,a12,a11,a10,a9,a8,a7,a6,a5,a4,a3,a2,a1,a0);57}5859__forceinline vint(const vint4& i) {60v = _mm512_broadcast_i32x4(i);61}6263__forceinline vint(const vint4& a, const vint4& b, const vint4& c, const vint4& d) {64v = _mm512_castsi128_si512(a);65v = _mm512_inserti32x4(v, b, 1);66v = _mm512_inserti32x4(v, c, 2);67v = _mm512_inserti32x4(v, d, 3);68}6970__forceinline vint(const vint8& i) {71v = _mm512_castps_si512(_mm512_castpd_ps(_mm512_broadcast_f64x4(_mm256_castsi256_pd(i))));72}7374__forceinline vint(const vint8& a, const vint8& b) {75v = _mm512_castsi256_si512(a);76v = _mm512_inserti64x4(v, b, 1);77}7879__forceinline explicit vint(const __m512& f) {80v = _mm512_cvtps_epi32(f);81}8283////////////////////////////////////////////////////////////////////////////////84/// Constants85////////////////////////////////////////////////////////////////////////////////8687__forceinline vint(ZeroTy) : v(_mm512_setzero_epi32()) {}88__forceinline vint(OneTy) : v(_mm512_set1_epi32(1)) {}89__forceinline vint(PosInfTy) : v(_mm512_set1_epi32(pos_inf)) {}90__forceinline vint(NegInfTy) : v(_mm512_set1_epi32(neg_inf)) {}91__forceinline vint(StepTy) : v(_mm512_set_epi32(15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)) {}92__forceinline vint(ReverseStepTy) : v(_mm512_setr_epi32(15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)) {}9394////////////////////////////////////////////////////////////////////////////////95/// Loads and Stores96////////////////////////////////////////////////////////////////////////////////9798static __forceinline vint16 load (const void* addr) { return _mm512_load_si512((int*)addr); }99100static __forceinline vint16 load(const unsigned char* ptr) { return _mm512_cvtepu8_epi32(_mm_load_si128((__m128i*)ptr)); }101static __forceinline vint16 load(const unsigned short* ptr) { return _mm512_cvtepu16_epi32(_mm256_load_si256((__m256i*)ptr)); }102103static __forceinline vint16 loadu(const unsigned char* ptr) { return _mm512_cvtepu8_epi32(_mm_loadu_si128((__m128i*)ptr)); }104static __forceinline vint16 loadu(const unsigned short* ptr) { return _mm512_cvtepu16_epi32(_mm256_loadu_si256((__m256i*)ptr)); }105106static __forceinline vint16 loadu(const void* addr) { return _mm512_loadu_si512(addr); }107108static __forceinline vint16 load (const vboolf16& mask, const void* addr) { return _mm512_mask_load_epi32 (_mm512_setzero_epi32(),mask,addr); }109static __forceinline vint16 loadu(const vboolf16& mask, const void* addr) { return _mm512_mask_loadu_epi32(_mm512_setzero_epi32(),mask,addr); }110111static __forceinline void store (void* ptr, const vint16& v) { _mm512_store_si512 (ptr,v); }112static __forceinline void storeu(void* ptr, const vint16& v) { _mm512_storeu_si512(ptr,v); }113114static __forceinline void store (const vboolf16& mask, void* addr, const vint16& v2) { _mm512_mask_store_epi32(addr,mask,v2); }115static __forceinline void storeu(const vboolf16& mask, void* ptr, const vint16& f) { _mm512_mask_storeu_epi32((int*)ptr,mask,f); }116117static __forceinline void store_nt(void* __restrict__ ptr, const vint16& a) { _mm512_stream_si512((__m512i*)ptr,a); }118119static __forceinline vint16 compact(const vboolf16& mask, vint16 &v) {120return _mm512_mask_compress_epi32(v,mask,v);121}122123static __forceinline vint16 compact(const vboolf16& mask, const vint16 &a, vint16 &b) {124return _mm512_mask_compress_epi32(a,mask,b);125}126127static __forceinline vint16 expand(const vboolf16& mask, const vint16& a, vint16& b) {128return _mm512_mask_expand_epi32(b,mask,a);129}130131template<int scale = 4>132static __forceinline vint16 gather(const int* ptr, const vint16& index) {133return _mm512_i32gather_epi32(index,ptr,scale);134}135136template<int scale = 4>137static __forceinline vint16 gather(const vboolf16& mask, const int* ptr, const vint16& index) {138return _mm512_mask_i32gather_epi32(_mm512_undefined_epi32(),mask,index,ptr,scale);139}140141template<int scale = 4>142static __forceinline vint16 gather(const vboolf16& mask, vint16& dest, const int* ptr, const vint16& index) {143return _mm512_mask_i32gather_epi32(dest,mask,index,ptr,scale);144}145146template<int scale = 4>147static __forceinline void scatter(int* ptr, const vint16& index, const vint16& v) {148_mm512_i32scatter_epi32((int*)ptr,index,v,scale);149}150151template<int scale = 4>152static __forceinline void scatter(const vboolf16& mask, int* ptr, const vint16& index, const vint16& v) {153_mm512_mask_i32scatter_epi32((int*)ptr,mask,index,v,scale);154}155156////////////////////////////////////////////////////////////////////////////////157/// Array Access158////////////////////////////////////////////////////////////////////////////////159160__forceinline int& operator [](size_t index) { assert(index < 16); return i[index]; }161__forceinline const int& operator [](size_t index) const { assert(index < 16); return i[index]; }162163__forceinline unsigned int uint (size_t index) const { assert(index < 16); return ((unsigned int*)i)[index]; }164__forceinline size_t& uint64_t(size_t index) const { assert(index < 8); return ((size_t*)i)[index]; }165};166167////////////////////////////////////////////////////////////////////////////////168/// Unary Operators169////////////////////////////////////////////////////////////////////////////////170171__forceinline vboolf16 asBool(const vint16& a) { return _mm512_movepi32_mask(a); }172173__forceinline vint16 operator +(const vint16& a) { return a; }174__forceinline vint16 operator -(const vint16& a) { return _mm512_sub_epi32(_mm512_setzero_epi32(), a); }175176////////////////////////////////////////////////////////////////////////////////177/// Binary Operators178////////////////////////////////////////////////////////////////////////////////179180__forceinline vint16 operator +(const vint16& a, const vint16& b) { return _mm512_add_epi32(a, b); }181__forceinline vint16 operator +(const vint16& a, int b) { return a + vint16(b); }182__forceinline vint16 operator +(int a, const vint16& b) { return vint16(a) + b; }183184__forceinline vint16 operator -(const vint16& a, const vint16& b) { return _mm512_sub_epi32(a, b); }185__forceinline vint16 operator -(const vint16& a, int b) { return a - vint16(b); }186__forceinline vint16 operator -(int a, const vint16& b) { return vint16(a) - b; }187188__forceinline vint16 operator *(const vint16& a, const vint16& b) { return _mm512_mullo_epi32(a, b); }189__forceinline vint16 operator *(const vint16& a, int b) { return a * vint16(b); }190__forceinline vint16 operator *(int a, const vint16& b) { return vint16(a) * b; }191192__forceinline vint16 operator &(const vint16& a, const vint16& b) { return _mm512_and_epi32(a, b); }193__forceinline vint16 operator &(const vint16& a, int b) { return a & vint16(b); }194__forceinline vint16 operator &(int a, const vint16& b) { return vint16(a) & b; }195196__forceinline vint16 operator |(const vint16& a, const vint16& b) { return _mm512_or_epi32(a, b); }197__forceinline vint16 operator |(const vint16& a, int b) { return a | vint16(b); }198__forceinline vint16 operator |(int a, const vint16& b) { return vint16(a) | b; }199200__forceinline vint16 operator ^(const vint16& a, const vint16& b) { return _mm512_xor_epi32(a, b); }201__forceinline vint16 operator ^(const vint16& a, int b) { return a ^ vint16(b); }202__forceinline vint16 operator ^(int a, const vint16& b) { return vint16(a) ^ b; }203204__forceinline vint16 operator <<(const vint16& a, int n) { return _mm512_slli_epi32(a, n); }205__forceinline vint16 operator >>(const vint16& a, int n) { return _mm512_srai_epi32(a, n); }206207__forceinline vint16 operator <<(const vint16& a, const vint16& n) { return _mm512_sllv_epi32(a, n); }208__forceinline vint16 operator >>(const vint16& a, const vint16& n) { return _mm512_srav_epi32(a, n); }209210__forceinline vint16 sll (const vint16& a, int b) { return _mm512_slli_epi32(a, b); }211__forceinline vint16 sra (const vint16& a, int b) { return _mm512_srai_epi32(a, b); }212__forceinline vint16 srl (const vint16& a, int b) { return _mm512_srli_epi32(a, b); }213214__forceinline vint16 min(const vint16& a, const vint16& b) { return _mm512_min_epi32(a, b); }215__forceinline vint16 min(const vint16& a, int b) { return min(a,vint16(b)); }216__forceinline vint16 min(int a, const vint16& b) { return min(vint16(a),b); }217218__forceinline vint16 max(const vint16& a, const vint16& b) { return _mm512_max_epi32(a, b); }219__forceinline vint16 max(const vint16& a, int b) { return max(a,vint16(b)); }220__forceinline vint16 max(int a, const vint16& b) { return max(vint16(a),b); }221222__forceinline vint16 umin(const vint16& a, const vint16& b) { return _mm512_min_epu32(a, b); }223__forceinline vint16 umax(const vint16& a, const vint16& b) { return _mm512_max_epu32(a, b); }224225__forceinline vint16 mask_add(const vboolf16& mask, vint16& c, const vint16& a, const vint16& b) { return _mm512_mask_add_epi32(c,mask,a,b); }226__forceinline vint16 mask_sub(const vboolf16& mask, vint16& c, const vint16& a, const vint16& b) { return _mm512_mask_sub_epi32(c,mask,a,b); }227228__forceinline vint16 mask_and(const vboolf16& m, vint16& c, const vint16& a, const vint16& b) { return _mm512_mask_and_epi32(c,m,a,b); }229__forceinline vint16 mask_or (const vboolf16& m, vint16& c, const vint16& a, const vint16& b) { return _mm512_mask_or_epi32(c,m,a,b); }230231////////////////////////////////////////////////////////////////////////////////232/// Assignment Operators233////////////////////////////////////////////////////////////////////////////////234235__forceinline vint16& operator +=(vint16& a, const vint16& b) { return a = a + b; }236__forceinline vint16& operator +=(vint16& a, int b) { return a = a + b; }237238__forceinline vint16& operator -=(vint16& a, const vint16& b) { return a = a - b; }239__forceinline vint16& operator -=(vint16& a, int b) { return a = a - b; }240241__forceinline vint16& operator *=(vint16& a, const vint16& b) { return a = a * b; }242__forceinline vint16& operator *=(vint16& a, int b) { return a = a * b; }243244__forceinline vint16& operator &=(vint16& a, const vint16& b) { return a = a & b; }245__forceinline vint16& operator &=(vint16& a, int b) { return a = a & b; }246247__forceinline vint16& operator |=(vint16& a, const vint16& b) { return a = a | b; }248__forceinline vint16& operator |=(vint16& a, int b) { return a = a | b; }249250__forceinline vint16& operator <<=(vint16& a, int b) { return a = a << b; }251__forceinline vint16& operator >>=(vint16& a, int b) { return a = a >> b; }252253254////////////////////////////////////////////////////////////////////////////////255/// Comparison Operators + Select256////////////////////////////////////////////////////////////////////////////////257258__forceinline vboolf16 operator ==(const vint16& a, const vint16& b) { return _mm512_cmp_epi32_mask(a,b,_MM_CMPINT_EQ); }259__forceinline vboolf16 operator ==(const vint16& a, int b) { return a == vint16(b); }260__forceinline vboolf16 operator ==(int a, const vint16& b) { return vint16(a) == b; }261262__forceinline vboolf16 operator !=(const vint16& a, const vint16& b) { return _mm512_cmp_epi32_mask(a,b,_MM_CMPINT_NE); }263__forceinline vboolf16 operator !=(const vint16& a, int b) { return a != vint16(b); }264__forceinline vboolf16 operator !=(int a, const vint16& b) { return vint16(a) != b; }265266__forceinline vboolf16 operator < (const vint16& a, const vint16& b) { return _mm512_cmp_epi32_mask(a,b,_MM_CMPINT_LT); }267__forceinline vboolf16 operator < (const vint16& a, int b) { return a < vint16(b); }268__forceinline vboolf16 operator < (int a, const vint16& b) { return vint16(a) < b; }269270__forceinline vboolf16 operator >=(const vint16& a, const vint16& b) { return _mm512_cmp_epi32_mask(a,b,_MM_CMPINT_GE); }271__forceinline vboolf16 operator >=(const vint16& a, int b) { return a >= vint16(b); }272__forceinline vboolf16 operator >=(int a, const vint16& b) { return vint16(a) >= b; }273274__forceinline vboolf16 operator > (const vint16& a, const vint16& b) { return _mm512_cmp_epi32_mask(a,b,_MM_CMPINT_GT); }275__forceinline vboolf16 operator > (const vint16& a, int b) { return a > vint16(b); }276__forceinline vboolf16 operator > (int a, const vint16& b) { return vint16(a) > b; }277278__forceinline vboolf16 operator <=(const vint16& a, const vint16& b) { return _mm512_cmp_epi32_mask(a,b,_MM_CMPINT_LE); }279__forceinline vboolf16 operator <=(const vint16& a, int b) { return a <= vint16(b); }280__forceinline vboolf16 operator <=(int a, const vint16& b) { return vint16(a) <= b; }281282__forceinline vboolf16 eq(const vint16& a, const vint16& b) { return _mm512_cmp_epi32_mask(a,b,_MM_CMPINT_EQ); }283__forceinline vboolf16 ne(const vint16& a, const vint16& b) { return _mm512_cmp_epi32_mask(a,b,_MM_CMPINT_NE); }284__forceinline vboolf16 lt(const vint16& a, const vint16& b) { return _mm512_cmp_epi32_mask(a,b,_MM_CMPINT_LT); }285__forceinline vboolf16 ge(const vint16& a, const vint16& b) { return _mm512_cmp_epi32_mask(a,b,_MM_CMPINT_GE); }286__forceinline vboolf16 gt(const vint16& a, const vint16& b) { return _mm512_cmp_epi32_mask(a,b,_MM_CMPINT_GT); }287__forceinline vboolf16 le(const vint16& a, const vint16& b) { return _mm512_cmp_epi32_mask(a,b,_MM_CMPINT_LE); }288__forceinline vboolf16 uint_le(const vint16& a, const vint16& b) { return _mm512_cmp_epu32_mask(a,b,_MM_CMPINT_LE); }289__forceinline vboolf16 uint_gt(const vint16& a, const vint16& b) { return _mm512_cmp_epu32_mask(a,b,_MM_CMPINT_GT); }290291__forceinline vboolf16 eq(const vboolf16 mask, const vint16& a, const vint16& b) { return _mm512_mask_cmp_epi32_mask(mask,a,b,_MM_CMPINT_EQ); }292__forceinline vboolf16 ne(const vboolf16 mask, const vint16& a, const vint16& b) { return _mm512_mask_cmp_epi32_mask(mask,a,b,_MM_CMPINT_NE); }293__forceinline vboolf16 lt(const vboolf16 mask, const vint16& a, const vint16& b) { return _mm512_mask_cmp_epi32_mask(mask,a,b,_MM_CMPINT_LT); }294__forceinline vboolf16 ge(const vboolf16 mask, const vint16& a, const vint16& b) { return _mm512_mask_cmp_epi32_mask(mask,a,b,_MM_CMPINT_GE); }295__forceinline vboolf16 gt(const vboolf16 mask, const vint16& a, const vint16& b) { return _mm512_mask_cmp_epi32_mask(mask,a,b,_MM_CMPINT_GT); }296__forceinline vboolf16 le(const vboolf16 mask, const vint16& a, const vint16& b) { return _mm512_mask_cmp_epi32_mask(mask,a,b,_MM_CMPINT_LE); }297__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); }298__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); }299300301__forceinline vint16 select(const vboolf16& m, const vint16& t, const vint16& f) {302return _mm512_mask_or_epi32(f,m,t,t);303}304305////////////////////////////////////////////////////////////////////////////////306// Movement/Shifting/Shuffling Functions307////////////////////////////////////////////////////////////////////////////////308309__forceinline vint16 unpacklo(const vint16& a, const vint16& b) { return _mm512_unpacklo_epi32(a, b); }310__forceinline vint16 unpackhi(const vint16& a, const vint16& b) { return _mm512_unpackhi_epi32(a, b); }311312template<int i>313__forceinline vint16 shuffle(const vint16& v) {314return _mm512_castps_si512(_mm512_permute_ps(_mm512_castsi512_ps(v), _MM_SHUFFLE(i, i, i, i)));315}316317template<int i0, int i1, int i2, int i3>318__forceinline vint16 shuffle(const vint16& v) {319return _mm512_castps_si512(_mm512_permute_ps(_mm512_castsi512_ps(v), _MM_SHUFFLE(i3, i2, i1, i0)));320}321322template<int i>323__forceinline vint16 shuffle4(const vint16& v) {324return _mm512_castps_si512(_mm512_shuffle_f32x4(_mm512_castsi512_ps(v), _mm512_castsi512_ps(v), _MM_SHUFFLE(i, i, i, i)));325}326327template<int i0, int i1, int i2, int i3>328__forceinline vint16 shuffle4(const vint16& v) {329return _mm512_castps_si512(_mm512_shuffle_f32x4(_mm512_castsi512_ps(v), _mm512_castsi512_ps(v), _MM_SHUFFLE(i3, i2, i1, i0)));330}331332template<int i>333__forceinline vint16 align_shift_right(const vint16& a, const vint16& b) {334return _mm512_alignr_epi32(a, b, i);335};336337__forceinline int toScalar(const vint16& v) {338return _mm_cvtsi128_si32(_mm512_castsi512_si128(v));339}340341template<int i> __forceinline vint16 insert4(const vint16& a, const vint4& b) { return _mm512_inserti32x4(a, b, i); }342343template<int N, int i>344vint<N> extractN(const vint16& v);345346template<> __forceinline vint4 extractN<4,0>(const vint16& v) { return _mm512_castsi512_si128(v); }347template<> __forceinline vint4 extractN<4,1>(const vint16& v) { return _mm512_extracti32x4_epi32(v, 1); }348template<> __forceinline vint4 extractN<4,2>(const vint16& v) { return _mm512_extracti32x4_epi32(v, 2); }349template<> __forceinline vint4 extractN<4,3>(const vint16& v) { return _mm512_extracti32x4_epi32(v, 3); }350351template<> __forceinline vint8 extractN<8,0>(const vint16& v) { return _mm512_castsi512_si256(v); }352template<> __forceinline vint8 extractN<8,1>(const vint16& v) { return _mm512_extracti32x8_epi32(v, 1); }353354template<int i> __forceinline vint4 extract4 (const vint16& v) { return _mm512_extracti32x4_epi32(v, i); }355template<> __forceinline vint4 extract4<0>(const vint16& v) { return _mm512_castsi512_si128(v); }356357template<int i> __forceinline vint8 extract8 (const vint16& v) { return _mm512_extracti32x8_epi32(v, i); }358template<> __forceinline vint8 extract8<0>(const vint16& v) { return _mm512_castsi512_si256(v); }359360////////////////////////////////////////////////////////////////////////////////361/// Reductions362////////////////////////////////////////////////////////////////////////////////363364__forceinline vint16 vreduce_min2(vint16 x) { return min(x, shuffle<1,0,3,2>(x)); }365__forceinline vint16 vreduce_min4(vint16 x) { x = vreduce_min2(x); return min(x, shuffle<2,3,0,1>(x)); }366__forceinline vint16 vreduce_min8(vint16 x) { x = vreduce_min4(x); return min(x, shuffle4<1,0,3,2>(x)); }367__forceinline vint16 vreduce_min (vint16 x) { x = vreduce_min8(x); return min(x, shuffle4<2,3,0,1>(x)); }368369__forceinline vint16 vreduce_max2(vint16 x) { return max(x, shuffle<1,0,3,2>(x)); }370__forceinline vint16 vreduce_max4(vint16 x) { x = vreduce_max2(x); return max(x, shuffle<2,3,0,1>(x)); }371__forceinline vint16 vreduce_max8(vint16 x) { x = vreduce_max4(x); return max(x, shuffle4<1,0,3,2>(x)); }372__forceinline vint16 vreduce_max (vint16 x) { x = vreduce_max8(x); return max(x, shuffle4<2,3,0,1>(x)); }373374__forceinline vint16 vreduce_and2(vint16 x) { return x & shuffle<1,0,3,2>(x); }375__forceinline vint16 vreduce_and4(vint16 x) { x = vreduce_and2(x); return x & shuffle<2,3,0,1>(x); }376__forceinline vint16 vreduce_and8(vint16 x) { x = vreduce_and4(x); return x & shuffle4<1,0,3,2>(x); }377__forceinline vint16 vreduce_and (vint16 x) { x = vreduce_and8(x); return x & shuffle4<2,3,0,1>(x); }378379__forceinline vint16 vreduce_or2(vint16 x) { return x | shuffle<1,0,3,2>(x); }380__forceinline vint16 vreduce_or4(vint16 x) { x = vreduce_or2(x); return x | shuffle<2,3,0,1>(x); }381__forceinline vint16 vreduce_or8(vint16 x) { x = vreduce_or4(x); return x | shuffle4<1,0,3,2>(x); }382__forceinline vint16 vreduce_or (vint16 x) { x = vreduce_or8(x); return x | shuffle4<2,3,0,1>(x); }383384__forceinline vint16 vreduce_add2(vint16 x) { return x + shuffle<1,0,3,2>(x); }385__forceinline vint16 vreduce_add4(vint16 x) { x = vreduce_add2(x); return x + shuffle<2,3,0,1>(x); }386__forceinline vint16 vreduce_add8(vint16 x) { x = vreduce_add4(x); return x + shuffle4<1,0,3,2>(x); }387__forceinline vint16 vreduce_add (vint16 x) { x = vreduce_add8(x); return x + shuffle4<2,3,0,1>(x); }388389__forceinline int reduce_min(const vint16& v) { return toScalar(vreduce_min(v)); }390__forceinline int reduce_max(const vint16& v) { return toScalar(vreduce_max(v)); }391__forceinline int reduce_and(const vint16& v) { return toScalar(vreduce_and(v)); }392__forceinline int reduce_or (const vint16& v) { return toScalar(vreduce_or (v)); }393__forceinline int reduce_add(const vint16& v) { return toScalar(vreduce_add(v)); }394395////////////////////////////////////////////////////////////////////////////////396/// Memory load and store operations397////////////////////////////////////////////////////////////////////////////////398399__forceinline vint16 conflict(const vint16& index)400{401return _mm512_conflict_epi32(index);402}403404__forceinline vint16 conflict(const vboolf16& mask, vint16& dest, const vint16& index)405{406return _mm512_mask_conflict_epi32(dest,mask,index);407}408409__forceinline vint16 convert_uint32_t(const __m512& f) {410return _mm512_cvtps_epu32(f);411}412413__forceinline vint16 permute(vint16 v, vint16 index) {414return _mm512_permutexvar_epi32(index,v);415}416417__forceinline vint16 reverse(const vint16 &a) {418return permute(a,vint16(reverse_step));419}420421__forceinline vint16 prefix_sum(const vint16& a)422{423const vint16 z(zero);424vint16 v = a;425v = v + align_shift_right<16-1>(v,z);426v = v + align_shift_right<16-2>(v,z);427v = v + align_shift_right<16-4>(v,z);428v = v + align_shift_right<16-8>(v,z);429return v;430}431432__forceinline vint16 reverse_prefix_sum(const vint16& a)433{434const vint16 z(zero);435vint16 v = a;436v = v + align_shift_right<1>(z,v);437v = v + align_shift_right<2>(z,v);438v = v + align_shift_right<4>(z,v);439v = v + align_shift_right<8>(z,v);440return v;441}442443/* this should use a vbool8 and a vint8_64...*/444template<int scale = 1, int hint = _MM_HINT_T0>445__forceinline void gather_prefetch64(const void* base_addr, const vbool16& mask, const vint16& offset)446{447#if defined(__AVX512PF__)448_mm512_mask_prefetch_i64gather_pd(offset, mask, base_addr, scale, hint);449#endif450}451452////////////////////////////////////////////////////////////////////////////////453/// Output Operators454////////////////////////////////////////////////////////////////////////////////455456__forceinline embree_ostream operator <<(embree_ostream cout, const vint16& v)457{458cout << "<" << v[0];459for (int i=1; i<16; i++) cout << ", " << v[i];460cout << ">";461return cout;462}463}464465#undef vboolf466#undef vboold467#undef vint468#undef vuint469#undef vllong470#undef vfloat471#undef vdouble472473474