VecCore 0.8.1
C++ Library for Portable SIMD Vectorization
Loading...
Searching...
No Matches
VcVector.h
Go to the documentation of this file.
1#ifndef VECCORE_BACKEND_VC_VECTOR_H
2#define VECCORE_BACKEND_VC_VECTOR_H
3
4namespace vecCore {
5
6template <typename T, class Abi>
7struct TypeTraits<Vc::Mask<T, Abi>> {
8 using IndexType = size_t;
9 using ScalarType = bool;
10 static constexpr size_t Size = Vc::Mask<T, Abi>::Size;
11};
12
13template <typename T, class Abi>
14struct TypeTraits<Vc::Vector<T, Abi>> {
15 using ScalarType = T;
16 using MaskType = typename Vc::Vector<T, Abi>::MaskType;
17 using IndexType = typename Vc::Vector<T, Abi>::IndexType;
18 static constexpr size_t Size = Vc::Vector<T, Abi>::Size;
19};
20
21namespace backend {
22
23template <typename T = Real_s, class Abi = Vc::VectorAbi::Best<T>>
24class VcVectorT {
25public:
26 using Real_v = Vc::Vector<T, Abi>;
27 using Float_v = Vc::Vector<float, Abi>;
28 using Double_v = Vc::Vector<double, Abi>;
29
30 using Int_v = Vc::Vector<int, Abi>;
31 using Int16_v = Vc::Vector<int16_t, Abi>;
32 using Int32_v = Vc::Vector<int32_t, Abi>;
33 using Int64_v = Vc::Vector<int64_t, Abi>;
34
35 using UInt_v = Vc::Vector<unsigned int, Abi>;
36 using UInt16_v = Vc::Vector<uint16_t, Abi>;
37 using UInt32_v = Vc::Vector<uint32_t, Abi>;
38 using UInt64_v = Vc::Vector<uint64_t, Abi>;
39};
40
42
43} // namespace backend
44
45template <typename T, class Abi>
47bool MaskEmpty(const Vc::Mask<T, Abi> &mask)
48{
49 return mask.isEmpty();
50}
51
52template <typename T, class Abi>
54bool MaskFull(const Vc::Mask<T, Abi> &mask)
55{
56 return mask.isFull();
57}
58
59template <typename T, class Abi>
60struct IndexingImplementation<Vc::Mask<T, Abi>> {
61 using M = Vc::Mask<T, Abi>;
62 static inline bool Get(const M &mask, size_t i) { return mask[i]; }
63
64 static inline void Set(M &mask, size_t i, const bool val) { mask[i] = val; }
65};
66
67template <typename T, class Abi>
68struct LoadStoreImplementation<Vc::Vector<T, Abi>> {
69 using V = Vc::Vector<T, Abi>;
70 template <typename S = Scalar<V>>
71 static inline void Load(V &v, S const *ptr)
72 {
73 v.load(ptr);
74 }
75
76 template <typename S = Scalar<V>>
77 static inline void Store(V const &v, S *ptr)
78 {
79 v.store(ptr);
80 }
81};
82
83template <typename T, class Abi>
84struct LoadStoreImplementation<Vc::Mask<T, Abi>> {
85 using M = Vc::Mask<T, Abi>;
86
87 template <typename S = Scalar<T>>
88 static inline void Load(M &mask, bool const *ptr)
89 {
90 mask.load(ptr);
91 }
92
93 template <typename S = Scalar<T>>
94 static inline void Store(M const &mask, S *ptr)
95 {
96 mask.store(ptr);
97 }
98};
99
100template <typename T, class Abi>
101struct MaskingImplementation<Vc::Vector<T, Abi>> {
102 using M = Vc::Mask<T, Abi>;
103 using V = Vc::Vector<T, Abi>;
104
105 static inline void Assign(V &dst, M const &mask, V const &src) { dst(mask) = src; }
106
107 static inline void Blend(V &dst, M const &mask, V const &src1, V const src2)
108 {
109 dst = src2;
110 dst(mask) = src1;
111 }
112};
113
114inline namespace math {
115
116template <typename T, class Abi>
118Vc::Vector<T, Abi> CopySign(const Vc::Vector<T, Abi> &x, const Vc::Vector<T, Abi> &y)
119{
120 return Vc::copysign(x, y);
121}
122
123#define VC_MATH_UNARY_FUNCTION(F, f) \
124template <typename T, class Abi> \
125VECCORE_FORCE_INLINE \
126Vc::Vector<T, Abi> F(const Vc::Vector<T, Abi> &x) \
127{ return Vc::f(x); } \
128
132VC_MATH_UNARY_FUNCTION(Log2, log2)
133VC_MATH_UNARY_FUNCTION(Log10, log10)
134VC_MATH_UNARY_FUNCTION(Sqrt, sqrt)
136
139VC_MATH_UNARY_FUNCTION(ASin, asin)
140// VC_MATH_UNARY_FUNCTION(ATan, atan) // slower than std::atan()
141
142// VC_MATH_UNARY_FUNCTION(Floor, floor) // broken
143// VC_MATH_UNARY_FUNCTION(Ceil, ceil) // broken
144// VC_MATH_UNARY_FUNCTION(Trunc, trunc) // broken
145
146#undef VC_MATH_UNARY_FUNCTION
147
148template <typename T, class Abi>
150Vc::Vector<T, Abi> Tan(const Vc::Vector<T, Abi> &x)
151{
152 Vc::Vector<T, Abi> s, c;
153 Vc::sincos(x, &s, &c);
154 return s / c;
155}
156
157template <typename T, class Abi>
159Vc::Mask<T, Abi> IsInf(const Vc::Vector<T, Abi> &x)
160{
161 return Vc::isinf(x);
162}
163
164}
165
166} // namespace vecCore
167
168#endif
#define VECCORE_FORCE_INLINE
Definition: Common.h:32
#define VC_MATH_UNARY_FUNCTION(F, f)
Definition: VcSimdArray.h:122
Vc::Vector< int16_t, Abi > Int16_v
Definition: VcVector.h:31
Vc::Vector< float, Abi > Float_v
Definition: VcVector.h:27
Vc::Vector< uint16_t, Abi > UInt16_v
Definition: VcVector.h:36
Vc::Vector< T, Abi > Real_v
Definition: VcVector.h:26
Vc::Vector< int32_t, Abi > Int32_v
Definition: VcVector.h:32
Vc::Vector< unsigned int, Abi > UInt_v
Definition: VcVector.h:35
Vc::Vector< double, Abi > Double_v
Definition: VcVector.h:28
Vc::Vector< int64_t, Abi > Int64_v
Definition: VcVector.h:33
Vc::Vector< uint32_t, Abi > UInt32_v
Definition: VcVector.h:37
Vc::Vector< int, Abi > Int_v
Definition: VcVector.h:30
Vc::Vector< uint64_t, Abi > UInt64_v
Definition: VcVector.h:38
VECCORE_FORCE_INLINE UME::SIMD::SIMDVecMask< N > IsInf(const UME::SIMD::SIMDVec_f< T, N > &x)
VECCORE_FORCE_INLINE VECCORE_ATT_HOST_DEVICE T Rsqrt(const T &x)
Definition: VecMath.h:222
VECCORE_FORCE_INLINE Vc::SimdArray< T, N > CopySign(const Vc::SimdArray< T, N > &x, const Vc::SimdArray< T, N > &y)
Definition: VcSimdArray.h:117
VECCORE_FORCE_INLINE Vc::SimdArray< T, N > Tan(const Vc::SimdArray< T, N > &x)
Definition: VcSimdArray.h:148
VECCORE_ATT_HOST_DEVICE bool MaskEmpty(const M &mask)
typename TypeTraits< T >::MaskType Mask
Definition: Interface.h:10
VECCORE_ATT_HOST_DEVICE bool MaskFull(const M &mask)
static void Set(M &mask, size_t i, const bool val)
Definition: VcVector.h:64
static bool Get(const M &mask, size_t i)
Definition: VcVector.h:62
static void Store(M const &mask, S *ptr)
Definition: VcVector.h:94
static void Load(M &mask, bool const *ptr)
Definition: VcVector.h:88
static void Blend(V &dst, M const &mask, V const &src1, V const src2)
Definition: VcVector.h:107
static void Assign(V &dst, M const &mask, V const &src)
Definition: VcVector.h:105
typename Vc::Vector< T, Abi >::IndexType IndexType
Definition: VcVector.h:17
typename Vc::Vector< T, Abi >::MaskType MaskType
Definition: VcVector.h:16
static constexpr size_t Size
Definition: Scalar.h:14