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