godot/thirdparty/embree/common/simd/vuint4_sse2.h

// Copyright 2009-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "../math/emath.h"

#define vboolf
#define vboold
#define vint
#define vuint
#define vllong
#define vfloat
#define vdouble

namespace embree
{
  /* 4-wide SSE integer type */
  template<>
  struct vuint<4>
  {};

  ////////////////////////////////////////////////////////////////////////////////
  /// Unary Operators
  ////////////////////////////////////////////////////////////////////////////////

#if defined(__AVX512VL__)
  __forceinline vboolf4 asBool(const vuint4& a) { return _mm_movepi32_mask(a); }
#else
  __forceinline vboolf4 asBool(const vuint4& a) {}
#endif

  __forceinline vuint4 operator +(const vuint4& a) {}
  __forceinline vuint4 operator -(const vuint4& a) {}

  ////////////////////////////////////////////////////////////////////////////////
  /// Binary Operators
  ////////////////////////////////////////////////////////////////////////////////

  __forceinline vuint4 operator +(const vuint4& a, const vuint4& b) {}
  __forceinline vuint4 operator +(const vuint4& a, unsigned int  b) {}
  __forceinline vuint4 operator +(unsigned int  a, const vuint4& b) {}

  __forceinline vuint4 operator -(const vuint4& a, const vuint4& b) {}
  __forceinline vuint4 operator -(const vuint4& a, unsigned int  b) {}
  __forceinline vuint4 operator -(unsigned int  a, const vuint4& b) {}

//#if defined(__SSE4_1__)
//  __forceinline vuint4 operator *(const vuint4& a, const vuint4& b) { return _mm_mullo_epu32(a, b); }
//#else
//  __forceinline vuint4 operator *(const vuint4& a, const vuint4& b) { return vuint4(a[0]*b[0],a[1]*b[1],a[2]*b[2],a[3]*b[3]); }
//#endif
//  __forceinline vuint4 operator *(const vuint4& a, unsigned int  b) { return a * vuint4(b); }
//  __forceinline vuint4 operator *(unsigned int  a, const vuint4& b) { return vuint4(a) * b; }

  __forceinline vuint4 operator &(const vuint4& a, const vuint4& b) {}
  __forceinline vuint4 operator &(const vuint4& a, unsigned int  b) {}
  __forceinline vuint4 operator &(unsigned int  a, const vuint4& b) {}

  __forceinline vuint4 operator |(const vuint4& a, const vuint4& b) {}
  __forceinline vuint4 operator |(const vuint4& a, unsigned int  b) {}
  __forceinline vuint4 operator |(unsigned int  a, const vuint4& b) {}

  __forceinline vuint4 operator ^(const vuint4& a, const vuint4& b) {}
  __forceinline vuint4 operator ^(const vuint4& a, unsigned int  b) {}
  __forceinline vuint4 operator ^(unsigned int  a, const vuint4& b) {}

  __forceinline vuint4 operator <<(const vuint4& a, unsigned int n) {}
  __forceinline vuint4 operator >>(const vuint4& a, unsigned int n) {}

  __forceinline vuint4 sll (const vuint4& a, unsigned int b) {}
  __forceinline vuint4 sra (const vuint4& a, unsigned int b) {}
  __forceinline vuint4 srl (const vuint4& a, unsigned int b) {}
  
  ////////////////////////////////////////////////////////////////////////////////
  /// Assignment Operators
  ////////////////////////////////////////////////////////////////////////////////

  __forceinline vuint4& operator +=(vuint4& a, const vuint4& b) {}
  __forceinline vuint4& operator +=(vuint4& a, unsigned int  b) {}
  
  __forceinline vuint4& operator -=(vuint4& a, const vuint4& b) {}
  __forceinline vuint4& operator -=(vuint4& a, unsigned int  b) {}

//#if defined(__SSE4_1__)
//  __forceinline vuint4& operator *=(vuint4& a, const vuint4& b) { return a = a * b; }
//  __forceinline vuint4& operator *=(vuint4& a, unsigned int  b) { return a = a * b; }
//#endif
  
  __forceinline vuint4& operator &=(vuint4& a, const vuint4& b) {}
  __forceinline vuint4& operator &=(vuint4& a, unsigned int  b) {}
  
  __forceinline vuint4& operator |=(vuint4& a, const vuint4& b) {}
  __forceinline vuint4& operator |=(vuint4& a, unsigned int  b) {}
  
  __forceinline vuint4& operator <<=(vuint4& a, unsigned int  b) {}
  __forceinline vuint4& operator >>=(vuint4& a, unsigned int  b) {}

  ////////////////////////////////////////////////////////////////////////////////
  /// Comparison Operators + Select
  ////////////////////////////////////////////////////////////////////////////////

#if defined(__AVX512VL__)
  __forceinline vboolf4 operator ==(const vuint4& a, const vuint4& b) { return _mm_cmp_epu32_mask(a,b,_MM_CMPINT_EQ); }
  __forceinline vboolf4 operator !=(const vuint4& a, const vuint4& b) { return _mm_cmp_epu32_mask(a,b,_MM_CMPINT_NE); }
  //__forceinline vboolf4 operator < (const vuint4& a, const vuint4& b) { return _mm_cmp_epu32_mask(a,b,_MM_CMPINT_LT); }
  //__forceinline vboolf4 operator >=(const vuint4& a, const vuint4& b) { return _mm_cmp_epu32_mask(a,b,_MM_CMPINT_GE); }
  //__forceinline vboolf4 operator > (const vuint4& a, const vuint4& b) { return _mm_cmp_epu32_mask(a,b,_MM_CMPINT_GT); }
  //__forceinline vboolf4 operator <=(const vuint4& a, const vuint4& b) { return _mm_cmp_epu32_mask(a,b,_MM_CMPINT_LE); }
#else
  __forceinline vboolf4 operator ==(const vuint4& a, const vuint4& b) {}
  __forceinline vboolf4 operator !=(const vuint4& a, const vuint4& b) {}
  //__forceinline vboolf4 operator < (const vuint4& a, const vuint4& b) { return _mm_castsi128_ps(_mm_cmplt_epu32(a, b)); }
  //__forceinline vboolf4 operator >=(const vuint4& a, const vuint4& b) { return !(a <  b); }
  //__forceinline vboolf4 operator > (const vuint4& a, const vuint4& b) { return _mm_castsi128_ps(_mm_cmpgt_epu32(a, b)); }
  //__forceinline vboolf4 operator <=(const vuint4& a, const vuint4& b) { return !(a >  b); }
#endif

  __forceinline vboolf4 operator ==(const vuint4& a, unsigned int  b) {}
  __forceinline vboolf4 operator ==(unsigned int  a, const vuint4& b) {}

  __forceinline vboolf4 operator !=(const vuint4& a, unsigned int  b) {}
  __forceinline vboolf4 operator !=(unsigned int  a, const vuint4& b) {}

  //__forceinline vboolf4 operator < (const vuint4& a, unsigned int  b) { return a <  vuint4(b); }
  //__forceinline vboolf4 operator < (unsigned int  a, const vuint4& b) { return vuint4(a) <  b; }

  //__forceinline vboolf4 operator >=(const vuint4& a, unsigned int  b) { return a >= vuint4(b); }
  //__forceinline vboolf4 operator >=(unsigned int  a, const vuint4& b) { return vuint4(a) >= b; }

  //__forceinline vboolf4 operator > (const vuint4& a, unsigned int  b) { return a >  vuint4(b); }
  //__forceinline vboolf4 operator > (unsigned int  a, const vuint4& b) { return vuint4(a) >  b; }

  //__forceinline vboolf4 operator <=(const vuint4& a, unsigned int  b) { return a <= vuint4(b); }
  //__forceinline vboolf4 operator <=(unsigned int  a, const vuint4& b) { return vuint4(a) <= b; }

  __forceinline vboolf4 eq(const vuint4& a, const vuint4& b) {}
  __forceinline vboolf4 ne(const vuint4& a, const vuint4& b) {}
  //__forceinline vboolf4 lt(const vuint4& a, const vuint4& b) { return a <  b; }
  //__forceinline vboolf4 ge(const vuint4& a, const vuint4& b) { return a >= b; }
  //__forceinline vboolf4 gt(const vuint4& a, const vuint4& b) { return a >  b; }
  //__forceinline vboolf4 le(const vuint4& a, const vuint4& b) { return a <= b; }

#if defined(__AVX512VL__)
  __forceinline vboolf4 eq(const vboolf4& mask, const vuint4& a, const vuint4& b) { return _mm_mask_cmp_epu32_mask(mask, a, b, _MM_CMPINT_EQ); }
  __forceinline vboolf4 ne(const vboolf4& mask, const vuint4& a, const vuint4& b) { return _mm_mask_cmp_epu32_mask(mask, a, b, _MM_CMPINT_NE); }
  //__forceinline vboolf4 lt(const vboolf4& mask, const vuint4& a, const vuint4& b) { return _mm_mask_cmp_epu32_mask(mask, a, b, _MM_CMPINT_LT); }
  //__forceinline vboolf4 ge(const vboolf4& mask, const vuint4& a, const vuint4& b) { return _mm_mask_cmp_epu32_mask(mask, a, b, _MM_CMPINT_GE); }
  //__forceinline vboolf4 gt(const vboolf4& mask, const vuint4& a, const vuint4& b) { return _mm_mask_cmp_epu32_mask(mask, a, b, _MM_CMPINT_GT); }
  //__forceinline vboolf4 le(const vboolf4& mask, const vuint4& a, const vuint4& b) { return _mm_mask_cmp_epu32_mask(mask, a, b, _MM_CMPINT_LE); }
#else
  __forceinline vboolf4 eq(const vboolf4& mask, const vuint4& a, const vuint4& b) {}
  __forceinline vboolf4 ne(const vboolf4& mask, const vuint4& a, const vuint4& b) {}
  //__forceinline vboolf4 lt(const vboolf4& mask, const vuint4& a, const vuint4& b) { return mask & (a <  b); }
  //__forceinline vboolf4 ge(const vboolf4& mask, const vuint4& a, const vuint4& b) { return mask & (a >= b); }
  //__forceinline vboolf4 gt(const vboolf4& mask, const vuint4& a, const vuint4& b) { return mask & (a >  b); }
  //__forceinline vboolf4 le(const vboolf4& mask, const vuint4& a, const vuint4& b) { return mask & (a <= b); }
#endif

  template<int mask>
  __forceinline vuint4 select(const vuint4& t, const vuint4& f) {}

/*#if defined(__SSE4_1__)
  __forceinline vuint4 min(const vuint4& a, const vuint4& b) { return _mm_min_epu32(a, b); }
  __forceinline vuint4 max(const vuint4& a, const vuint4& b) { return _mm_max_epu32(a, b); }

#else
  __forceinline vuint4 min(const vuint4& a, const vuint4& b) { return select(a < b,a,b); }
  __forceinline vuint4 max(const vuint4& a, const vuint4& b) { return select(a < b,b,a); }
#endif

  __forceinline vuint4 min(const vuint4& a, unsigned int  b) { return min(a,vuint4(b)); }
  __forceinline vuint4 min(unsigned int  a, const vuint4& b) { return min(vuint4(a),b); }
  __forceinline vuint4 max(const vuint4& a, unsigned int  b) { return max(a,vuint4(b)); }
  __forceinline vuint4 max(unsigned int  a, const vuint4& b) { return max(vuint4(a),b); }*/

  ////////////////////////////////////////////////////////////////////////////////
  // Movement/Shifting/Shuffling Functions
  ////////////////////////////////////////////////////////////////////////////////

  __forceinline vuint4 unpacklo(const vuint4& a, const vuint4& b) {}
  __forceinline vuint4 unpackhi(const vuint4& a, const vuint4& b) {}

#if defined(__aarch64__)
  template<int i0, int i1, int i2, int i3>
  __forceinline vuint4 shuffle(const vuint4& v) {
    return vreinterpretq_s32_u8(vqtbl1q_u8( (uint8x16_t)v.v, _MN_SHUFFLE(i0, i1, i2, i3)));
  }
  template<int i0, int i1, int i2, int i3>
  __forceinline vuint4 shuffle(const vuint4& a, const vuint4& b) {
    return vreinterpretq_s32_u8(vqtbl2q_u8( (uint8x16x2_t){(uint8x16_t)a.v, (uint8x16_t)b.v}, _MF_SHUFFLE(i0, i1, i2, i3)));
  }
#else
  template<int i0, int i1, int i2, int i3>
  __forceinline vuint4 shuffle(const vuint4& v) {}

  template<int i0, int i1, int i2, int i3>
  __forceinline vuint4 shuffle(const vuint4& a, const vuint4& b) {}
#endif
#if defined(__SSE3__)
  template<> __forceinline vuint4 shuffle<0, 0, 2, 2>(const vuint4& v) { return _mm_castps_si128(_mm_moveldup_ps(_mm_castsi128_ps(v))); }
  template<> __forceinline vuint4 shuffle<1, 1, 3, 3>(const vuint4& v) { return _mm_castps_si128(_mm_movehdup_ps(_mm_castsi128_ps(v))); }
  template<> __forceinline vuint4 shuffle<0, 1, 0, 1>(const vuint4& v) { return _mm_castpd_si128(_mm_movedup_pd (_mm_castsi128_pd(v))); }
#endif

  template<int i>
  __forceinline vuint4 shuffle(const vuint4& v) {}

#if defined(__SSE4_1__) && !defined(__aarch64__)
  template<int src> __forceinline unsigned int extract(const vuint4& b) { return _mm_extract_epi32(b, src); }
  template<int dst> __forceinline vuint4 insert(const vuint4& a, const unsigned b) { return _mm_insert_epi32(a, b, dst); }
#else
  template<int src> __forceinline unsigned int extract(const vuint4& b) {}
  template<int dst> __forceinline vuint4 insert(const vuint4& a, const unsigned b) {}
#endif

  template<> __forceinline unsigned int extract<0>(const vuint4& b) {}

  __forceinline unsigned int toScalar(const vuint4& v) {}

  ////////////////////////////////////////////////////////////////////////////////
  /// Reductions
  ////////////////////////////////////////////////////////////////////////////////

#if 0
#if defined(__SSE4_1__)

  __forceinline vuint4 vreduce_min(const vuint4& v) { vuint4 h = min(shuffle<1,0,3,2>(v),v); return min(shuffle<2,3,0,1>(h),h); }
  __forceinline vuint4 vreduce_max(const vuint4& v) { vuint4 h = max(shuffle<1,0,3,2>(v),v); return max(shuffle<2,3,0,1>(h),h); }
  __forceinline vuint4 vreduce_add(const vuint4& v) { vuint4 h = shuffle<1,0,3,2>(v)   + v ; return shuffle<2,3,0,1>(h)   + h ; }

  __forceinline unsigned int reduce_min(const vuint4& v) { return toScalar(vreduce_min(v)); }
  __forceinline unsigned int reduce_max(const vuint4& v) { return toScalar(vreduce_max(v)); }
  __forceinline unsigned int reduce_add(const vuint4& v) { return toScalar(vreduce_add(v)); }

  __forceinline size_t select_min(const vuint4& v) { return bsf(movemask(v == vreduce_min(v))); }
  __forceinline size_t select_max(const vuint4& v) { return bsf(movemask(v == vreduce_max(v))); }

  //__forceinline size_t select_min(const vboolf4& valid, const vuint4& v) { const vuint4 a = select(valid,v,vuint4(pos_inf)); return bsf(movemask(valid & (a == vreduce_min(a)))); }
  //__forceinline size_t select_max(const vboolf4& valid, const vuint4& v) { const vuint4 a = select(valid,v,vuint4(neg_inf)); return bsf(movemask(valid & (a == vreduce_max(a)))); }

#else

  __forceinline unsigned int reduce_min(const vuint4& v) { return min(v[0],v[1],v[2],v[3]); }
  __forceinline unsigned int reduce_max(const vuint4& v) { return max(v[0],v[1],v[2],v[3]); }
  __forceinline unsigned int reduce_add(const vuint4& v) { return v[0]+v[1]+v[2]+v[3]; }

#endif
#endif

  ////////////////////////////////////////////////////////////////////////////////
  /// Output Operators
  ////////////////////////////////////////////////////////////////////////////////

  __forceinline embree_ostream operator <<(embree_ostream cout, const vuint4& a) {}
}

#undef vboolf
#undef vboold
#undef vint
#undef vuint
#undef vllong
#undef vfloat
#undef vdouble