Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:13:51

0001 #ifndef VECCORE_BACKEND_VC_SIMDARRAY_H
0002 #define VECCORE_BACKEND_VC_SIMDARRAY_H
0003 
0004 namespace vecCore {
0005 
0006 template <typename T, size_t N>
0007 struct TypeTraits<Vc::SimdMaskArray<T, N>> {
0008   using ScalarType = bool;
0009   using IndexType  = size_t;
0010   static constexpr size_t Size = N;
0011 };
0012 
0013 template <typename T, size_t N>
0014 struct TypeTraits<Vc::SimdArray<T, N>> {
0015   using ScalarType = T;
0016   using MaskType   = typename Vc::SimdArray<T, N>::MaskType;
0017   using IndexType  = typename Vc::SimdArray<T, N>::IndexType;
0018   static constexpr size_t Size = N;
0019 };
0020 
0021 namespace backend {
0022 
0023 template <size_t N = 16>
0024 class VcSimdArray {
0025 public:
0026   using Real_v   = Vc::SimdArray<Real_s, N>;
0027   using Float_v  = Vc::SimdArray<float, N>;
0028   using Double_v = Vc::SimdArray<double, N>;
0029 
0030   using Int_v   = Vc::SimdArray<int, N>;
0031   using Int16_v = Vc::SimdArray<int16_t, N>;
0032   using Int32_v = Vc::SimdArray<int32_t, N>;
0033   using Int64_v = Vc::SimdArray<int64_t, N>;
0034 
0035   using UInt_v   = Vc::SimdArray<unsigned int, N>;
0036   using UInt16_v = Vc::SimdArray<uint16_t, N>;
0037   using UInt32_v = Vc::SimdArray<uint32_t, N>;
0038   using UInt64_v = Vc::SimdArray<uint64_t, N>;
0039 };
0040 
0041 } // namespace backend
0042 
0043 template <typename T, size_t N>
0044 VECCORE_FORCE_INLINE
0045 bool MaskEmpty(const Vc::SimdMaskArray<T, N> &mask)
0046 {
0047   return mask.isEmpty();
0048 }
0049 
0050 template <typename T, size_t N>
0051 VECCORE_FORCE_INLINE
0052 bool MaskFull(const Vc::SimdMaskArray<T, N> &mask)
0053 {
0054   return mask.isFull();
0055 }
0056 
0057 template <typename T, size_t N>
0058 struct IndexingImplementation<Vc::SimdMaskArray<T, N>> {
0059   using M = Vc::SimdMaskArray<T, N>;
0060   static inline bool Get(const M &mask, size_t i) { return mask[i]; }
0061 
0062   static inline void Set(M &mask, size_t i, const bool val) { mask[i] = val; }
0063 };
0064 
0065 template <typename T, size_t N>
0066 struct LoadStoreImplementation<Vc::SimdArray<T, N>> {
0067   using V = Vc::SimdArray<T, N>;
0068 
0069   template <typename S = Scalar<V>>
0070   static inline void Load(V &v, S const *ptr)
0071   {
0072     v.load(ptr);
0073   }
0074 
0075   template <typename S = Scalar<V>>
0076   static inline void Store(V const &v, S *ptr)
0077   {
0078     v.store(ptr);
0079   }
0080 };
0081 
0082 template <typename T, size_t N>
0083 struct LoadStoreImplementation<Vc::SimdMaskArray<T, N>> {
0084   using M = Vc::SimdMaskArray<T, N>;
0085 
0086   template <typename S = Scalar<T>>
0087   static inline void Load(M &mask, bool const *ptr)
0088   {
0089     mask.load(ptr);
0090   }
0091 
0092   template <typename S = Scalar<T>>
0093   static inline void Store(M const &mask, S *ptr)
0094   {
0095     mask.store(ptr);
0096   }
0097 };
0098 
0099 template <typename T, size_t N>
0100 struct MaskingImplementation<Vc::SimdArray<T, N>> {
0101   using V = Vc::SimdArray<T, N>;
0102   using M = Vc::SimdMaskArray<T, N>;
0103 
0104   static inline void Assign(V &dst, M const &mask, V const &src) { dst(mask) = src; }
0105 
0106   static inline void Blend(V &dst, M const &mask, V const &src1, V const &src2)
0107   {
0108     dst       = src2;
0109     dst(mask) = src1;
0110   }
0111 };
0112 
0113 inline namespace math {
0114 
0115 template <typename T, size_t N>
0116 VECCORE_FORCE_INLINE
0117 Vc::SimdArray<T, N> CopySign(const Vc::SimdArray<T, N> &x, const Vc::SimdArray<T, N> &y)
0118 {
0119   return Vc::copysign(x, y);
0120 }
0121 
0122 #define VC_MATH_UNARY_FUNCTION(F, f)                \
0123 template <typename T, size_t N>                     \
0124 VECCORE_FORCE_INLINE                                \
0125 Vc::SimdArray<T, N> F(const Vc::SimdArray<T, N> &x) \
0126 { return Vc::f(x); }                                \
0127 
0128 VC_MATH_UNARY_FUNCTION(Exp, exp)
0129 VC_MATH_UNARY_FUNCTION(Log, log)
0130 VC_MATH_UNARY_FUNCTION(Log2, log2)
0131 VC_MATH_UNARY_FUNCTION(Log10, log10)
0132 VC_MATH_UNARY_FUNCTION(Sqrt, sqrt)
0133 VC_MATH_UNARY_FUNCTION(Rsqrt, rsqrt)
0134 
0135 VC_MATH_UNARY_FUNCTION(Sin, sin)
0136 VC_MATH_UNARY_FUNCTION(Cos, cos)
0137 VC_MATH_UNARY_FUNCTION(ASin, asin)
0138 VC_MATH_UNARY_FUNCTION(ATan, atan)
0139 
0140 // VC_MATH_UNARY_FUNCTION(Floor, floor) // broken
0141 // VC_MATH_UNARY_FUNCTION(Ceil, ceil)   // broken
0142 // VC_MATH_UNARY_FUNCTION(Trunc, trunc) // broken
0143 
0144 #undef VC_MATH_UNARY_FUNCTION
0145 
0146 template <typename T, size_t N>
0147 VECCORE_FORCE_INLINE
0148 Vc::SimdArray<T, N> Tan(const Vc::SimdArray<T, N> &x)
0149 {
0150   Vc::SimdArray<T, N> s, c;
0151   Vc::sincos(x, &s, &c);
0152   return s / c;
0153 }
0154 
0155 template <typename T, size_t N>
0156 VECCORE_FORCE_INLINE
0157 Vc::SimdMaskArray<T, N> IsInf(const Vc::SimdArray<T, N> &x)
0158 {
0159   return Vc::isinf(x);
0160 }
0161 
0162 }
0163 
0164 } // namespace vecCore
0165 
0166 #endif