Project
Loading...
Searching...
No Matches
VcShim.h
Go to the documentation of this file.
1// Copyright 2020-2025 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
16
17#ifndef GPU_UTILS_VCSHIM_H
18#define GPU_UTILS_VCSHIM_H
19
20#ifndef GPUCA_NO_VC
21
22#include <Vc/Vc>
23
24#else
25
26#include <algorithm>
27#include <array>
28#include <bitset>
29#include <cstddef>
30
31namespace Vc
32{
33
34constexpr struct VectorSpecialInitializerZero {
35} Zero;
36constexpr struct AlignedTag {
37} Aligned;
38
39template <typename T>
40typename T::vector_type& internal_data(T& v)
41{
42 return v.mData;
43}
44
45template <typename T>
46const typename T::vector_type& internal_data(const T& v)
47{
48 return v.mData;
49}
50
51namespace Common
52{
53
54template <typename V, typename M>
55class WriteMaskVector
56{
57 private:
58 const M& mMask;
59 V& mVec;
60
61 public:
62 using value_type = typename V::value_type;
63
64 WriteMaskVector(V& v, const M& m) : mMask(m), mVec(v) {}
65
66 WriteMaskVector& operator++(int)
67 {
68 for (size_t i = 0; i < mVec.size(); i++)
69 mVec[i] += value_type(mMask[i]);
70 return *this;
71 }
72
73 WriteMaskVector& operator=(const value_type& v)
74 {
75 for (size_t i = 0; i < mVec.size(); i++) {
76 if (mMask[i])
77 mVec[i] = v;
78 }
79 return *this;
80 }
81};
82
83inline void prefetchMid(const void*) {}
84inline void prefetchFar(const void*) {}
85inline void prefetchForOneRead(const void*) {}
86
87} // namespace Common
88
89template <typename T, size_t N>
90class fixed_size_simd_mask
91{
92 private:
93 std::bitset<N> mData;
94
95 public:
96 bool isNotEmpty() const { return mData.any(); }
97
98 std::bitset<N>::reference operator[](size_t i) { return mData[i]; }
99 bool operator[](size_t i) const { return mData[i]; }
100
101 fixed_size_simd_mask operator!() const
102 {
103 auto o = *this;
104 o.mData.flip();
105 return o;
106 }
107};
108
109template <typename T, size_t N>
110class fixed_size_simd
111{
112 private:
113 std::array<T, N> mData;
114
115 public:
116 using vector_type = std::array<T, N>;
117 using value_type = T;
118 using mask_type = fixed_size_simd_mask<T, N>;
119
120 static constexpr size_t size() { return N; }
121
122 fixed_size_simd() = default;
123 explicit fixed_size_simd(VectorSpecialInitializerZero) { mData = {}; }
124
125 template <typename U>
126 fixed_size_simd(const fixed_size_simd<U, N>& w)
127 {
128 std::copy_n(internal_data(w).begin(), N, mData.begin());
129 }
130
131 fixed_size_simd(const T* d, AlignedTag) { std::copy_n(d, N, mData.begin()); }
132
133 T& operator[](size_t i) { return mData[i]; }
134 const T& operator[](size_t i) const { return mData[i]; }
135
136 Common::WriteMaskVector<fixed_size_simd, mask_type> operator()(const mask_type& m) { return {*this, m}; }
137
138 fixed_size_simd& operator=(const T& v)
139 {
140 for (auto& x : mData)
141 x = v;
142 return *this;
143 }
144
145 fixed_size_simd& operator+=(const T& v)
146 {
147 for (auto& x : mData)
148 x += v;
149 return *this;
150 }
151
152 fixed_size_simd& operator/=(const T& v)
153 {
154 for (auto& x : mData)
155 x /= v;
156 return *this;
157 }
158
159 fixed_size_simd operator/(const T& v) const
160 {
161 auto x = *this;
162 return x /= v;
163 }
164
165 mask_type operator==(const T& v) const
166 {
167 mask_type m;
168 for (size_t i = 0; i < N; i++)
169 m[i] = mData[i] == v;
170 return m;
171 }
172
173 mask_type operator!=(const T& v) const { return !(*this == v); }
174
175 friend vector_type& internal_data<>(fixed_size_simd& x);
176 friend const vector_type& internal_data<>(const fixed_size_simd& x);
177};
178
179template <typename V>
180V max(const V& a, const V& b)
181{
182 V o;
183 for (size_t i = 0; i < a.size(); i++)
184 o[i] = std::max(a[i], b[i]);
185 return o;
186}
187
188} // namespace Vc
189
190#endif // ifndef GPUCA_NO_VC
191
192#endif
int32_t i
GLint GLenum GLint x
Definition glcorearb.h:403
const GLfloat * m
Definition glcorearb.h:4066
GLsizeiptr size
Definition glcorearb.h:659
const GLdouble * v
Definition glcorearb.h:832
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
GLubyte GLubyte GLubyte GLubyte w
Definition glcorearb.h:852
auto operator+=(std::string &lhs, StringRef rhs) -> std::string &
constexpr int Zero
bool operator!=(const DsChannelId &a, const DsChannelId &b)
Definition DsChannelId.h:66
Enum< T >::Iterator begin(Enum< T >)
Definition Defs.h:173
bool operator==(const CoarseLocation &a, const CoarseLocation &b)
constexpr size_t max