1 #ifndef DUNE_COMMON_SIMD_LOOP_HH
2 #define DUNE_COMMON_SIMD_LOOP_HH
21 # pragma GCC diagnostic push
22 # pragma GCC diagnostic ignored "-Wbool-operation"
23 # pragma GCC diagnostic ignored "-Wint-in-bool-context"
37 template<
class T, std::
size_t S, std::
size_t A = 0>
38 class alignas(A==0?alignof(T):A)
LoopSIMD :
public std::array<T,S> {
52 template<std::
size_t OA>
54 : std::array<T,S>(other)
64 #define DUNE_SIMD_LOOP_PREFIX_OP(SYMBOL) \
65 auto operator SYMBOL() { \
66 for(std::size_t i=0; i<S; i++){ \
71 static_assert(true, "expecting ;")
75 #undef DUNE_SIMD_LOOP_PREFIX_OP
78 #define DUNE_SIMD_LOOP_UNARY_OP(SYMBOL) \
79 auto operator SYMBOL() const { \
80 LoopSIMD<T,S,A> out; \
81 for(std::size_t i=0; i<S; i++){ \
82 out[i] = SYMBOL((*this)[i]); \
86 static_assert(true, "expecting ;")
94 for(std::size_t i=0; i<S; i++){
95 out[i] = !((*this)[i]);
99 #undef DUNE_SIMD_LOOP_UNARY_OP
102 #define DUNE_SIMD_LOOP_POSTFIX_OP(SYMBOL) \
103 auto operator SYMBOL(int){ \
104 LoopSIMD<T,S,A> out = *this; \
108 static_assert(true, "expecting ;")
112 #undef DUNE_SIMD_LOOP_POSTFIX_OP
115 #define DUNE_SIMD_LOOP_ASSIGNMENT_OP(SYMBOL) \
116 auto operator SYMBOL(const Simd::Scalar<T> s) { \
117 for(std::size_t i=0; i<S; i++){ \
118 (*this)[i] SYMBOL s; \
123 auto operator SYMBOL(const LoopSIMD<T,S,A> &v) { \
124 for(std::size_t i=0; i<S; i++){ \
125 (*this)[i] SYMBOL v[i]; \
129 static_assert(true, "expecting ;")
141 #undef DUNE_SIMD_LOOP_ASSIGNMENT_OP
145 #define DUNE_SIMD_LOOP_BINARY_OP(SYMBOL) \
146 template<class T, std::size_t S, std::size_t A> \
147 auto operator SYMBOL(const LoopSIMD<T,S,A> &v, const Simd::Scalar<T> s) { \
148 LoopSIMD<T,S,A> out; \
149 for(std::size_t i=0; i<S; i++){ \
150 out[i] = v[i] SYMBOL s; \
154 template<class T, std::size_t S, std::size_t A> \
155 auto operator SYMBOL(const Simd::Scalar<T> s, const LoopSIMD<T,S,A> &v) { \
156 LoopSIMD<T,S,A> out; \
157 for(std::size_t i=0; i<S; i++){ \
158 out[i] = s SYMBOL v[i]; \
162 template<class T, std::size_t S, std::size_t A> \
163 auto operator SYMBOL(const LoopSIMD<T,S,A> &v, \
164 const LoopSIMD<T,S,A> &w) { \
165 LoopSIMD<T,S,A> out; \
166 for(std::size_t i=0; i<S; i++){ \
167 out[i] = v[i] SYMBOL w[i]; \
171 static_assert(true, "expecting ;")
183 #undef DUNE_SIMD_LOOP_BINARY_OP
186 #define DUNE_SIMD_LOOP_BITSHIFT_OP(SYMBOL) \
187 template<class T, std::size_t S, std::size_t A, class U> \
188 auto operator SYMBOL(const LoopSIMD<T,S,A> &v, const U s) { \
189 LoopSIMD<T,S,A> out; \
190 for(std::size_t i=0; i<S; i++){ \
191 out[i] = v[i] SYMBOL s; \
195 template<class T, std::size_t S, std::size_t A, class U, std::size_t AU> \
196 auto operator SYMBOL(const LoopSIMD<T,S,A> &v, \
197 const LoopSIMD<U,S,AU> &w) { \
198 LoopSIMD<T,S,A> out; \
199 for(std::size_t i=0; i<S; i++){ \
200 out[i] = v[i] SYMBOL w[i]; \
204 static_assert(true, "expecting ;")
209 #undef DUNE_SIMD_LOOP_BITSHIFT_OP
212 #define DUNE_SIMD_LOOP_COMPARISON_OP(SYMBOL) \
213 template<class T, std::size_t S, std::size_t A, class U> \
214 auto operator SYMBOL(const LoopSIMD<T,S,A> &v, const U s) { \
215 Simd::Mask<LoopSIMD<T,S,A>> out; \
216 for(std::size_t i=0; i<S; i++){ \
217 out[i] = v[i] SYMBOL s; \
221 template<class T, std::size_t S, std::size_t A> \
222 auto operator SYMBOL(const Simd::Scalar<T> s, const LoopSIMD<T,S,A> &v) { \
223 Simd::Mask<LoopSIMD<T,S,A>> out; \
224 for(std::size_t i=0; i<S; i++){ \
225 out[i] = s SYMBOL v[i]; \
229 template<class T, std::size_t S, std::size_t A> \
230 auto operator SYMBOL(const LoopSIMD<T,S,A> &v, \
231 const LoopSIMD<T,S,A> &w) { \
232 Simd::Mask<LoopSIMD<T,S,A>> out; \
233 for(std::size_t i=0; i<S; i++){ \
234 out[i] = v[i] SYMBOL w[i]; \
238 static_assert(true, "expecting ;")
246 #undef DUNE_SIMD_LOOP_COMPARISON_OP
249 #define DUNE_SIMD_LOOP_BOOLEAN_OP(SYMBOL) \
250 template<class T, std::size_t S, std::size_t A> \
251 auto operator SYMBOL(const LoopSIMD<T,S,A> &v, const Simd::Scalar<T> s) { \
252 Simd::Mask<LoopSIMD<T,S,A>> out; \
253 for(std::size_t i=0; i<S; i++){ \
254 out[i] = v[i] SYMBOL s; \
258 template<class T, std::size_t S, std::size_t A> \
259 auto operator SYMBOL(const Simd::Mask<T> s, const LoopSIMD<T,S,A> &v) { \
260 Simd::Mask<LoopSIMD<T,S,A>> out; \
261 for(std::size_t i=0; i<S; i++){ \
262 out[i] = s SYMBOL v[i]; \
266 template<class T, std::size_t S, std::size_t A> \
267 auto operator SYMBOL(const LoopSIMD<T,S,A> &v, \
268 const LoopSIMD<T,S,A> &w) { \
269 Simd::Mask<LoopSIMD<T,S,A>> out; \
270 for(std::size_t i=0; i<S; i++){ \
271 out[i] = v[i] SYMBOL w[i]; \
275 static_assert(true, "expecting ;")
279 #undef DUNE_SIMD_LOOP_BOOLEAN_OP
282 template<
class T, std::
size_t S, std::
size_t A>
285 for(std::size_t i=0; i<S-1; i++) {
293 namespace Overloads {
300 template<
class T, std::
size_t S, std::
size_t A>
305 template<
class U,
class T, std::
size_t S, std::
size_t A>
311 template<
class T, std::
size_t S, std::
size_t A>
314 template<
class T, std::
size_t S, std::
size_t A>
316 -> decltype(std::move(
Simd::lane(l%lanes<T>(), v[l/lanes<T>()])))
318 return std::move(
Simd::lane(l%lanes<T>(), v[l/lanes<T>()]));
321 template<
class T, std::
size_t S, std::
size_t A>
323 -> decltype(
Simd::lane(l%lanes<T>(), v[l/lanes<T>()]))
325 return Simd::lane(l%lanes<T>(), v[l/lanes<T>()]);
328 template<
class T, std::
size_t S, std::
size_t A>
330 -> decltype(
Simd::lane(l%lanes<T>(), v[l/lanes<T>()]))
332 return Simd::lane(l%lanes<T>(), v[l/lanes<T>()]);
335 template<
class T, std::
size_t S, std::
size_t AM, std::
size_t AD>
339 for(std::size_t i=0; i<S; i++) {
345 template<
class M,
class T, std::
size_t S, std::
size_t A>
356 template<
class M, std::
size_t S, std::
size_t A>
359 for(std::size_t i=0; i<S; i++) {
365 template<
class M, std::
size_t S, std::
size_t A>
368 for(std::size_t i=0; i<S; i++) {
374 template<
class M, std::
size_t S, std::
size_t A>
377 for(std::size_t i=0; i<S; i++) {
383 template<
class M, std::
size_t S, std::
size_t A>
386 for(std::size_t i=0; i<S; i++) {
403 #define DUNE_SIMD_LOOP_CMATH_UNARY_OP(expr) \
404 template<class T, std::size_t S, std::size_t A, typename Sfinae = \
405 typename std::enable_if_t<!std::is_integral<Simd::Scalar<T>>::value> > \
406 auto expr(const LoopSIMD<T,S,A> &v) { \
408 LoopSIMD<T,S,A> out; \
409 for(std::size_t i=0; i<S; i++) { \
410 out[i] = expr(v[i]); \
414 static_assert(true, "expecting ;")
416 #define DUNE_SIMD_LOOP_CMATH_UNARY_OP_WITH_RETURN(expr, returnType) \
417 template<class T, std::size_t S, std::size_t A, typename Sfinae = \
418 typename std::enable_if_t<!std::is_integral<Simd::Scalar<T>>::value> > \
419 auto expr(const LoopSIMD<T,S,A> &v) { \
421 LoopSIMD<returnType,S> out; \
422 for(std::size_t i=0; i<S; i++) { \
423 out[i] = expr(v[i]); \
427 static_assert(true, "expecting ;")
474 #undef DUNE_SIMD_LOOP_CMATH_UNARY_OP
475 #undef DUNE_SIMD_LOOP_CMATH_UNARY_OP_WITH_RETURN
497 #define DUNE_SIMD_LOOP_STD_UNARY_OP(expr) \
498 template<class T, std::size_t S, std::size_t A> \
499 auto expr(const LoopSIMD<T,S,A> &v) { \
501 LoopSIMD<T,S,A> out; \
502 for(std::size_t i=0; i<S; i++) { \
503 out[i] = expr(v[i]); \
508 template<class T, std::size_t S, std::size_t A> \
509 auto expr(const LoopSIMD<std::complex<T>,S,A> &v) { \
511 LoopSIMD<T,S,A> out; \
512 for(std::size_t i=0; i<S; i++) { \
513 out[i] = expr(v[i]); \
517 static_assert(true, "expecting ;")
522 #undef DUNE_SIMD_LOOP_STD_UNARY_OP
524 #define DUNE_SIMD_LOOP_STD_BINARY_OP(expr) \
525 template<class T, std::size_t S, std::size_t A> \
526 auto expr(const LoopSIMD<T,S,A> &v, const LoopSIMD<T,S,A> &w) { \
528 LoopSIMD<T,S,A> out; \
529 for(std::size_t i=0; i<S; i++) { \
530 out[i] = expr(v[i],w[i]); \
534 static_assert(true, "expecting ;")
539 #undef DUNE_SIMD_LOOP_STD_BINARY_OP
541 namespace MathOverloads {
542 template<
class T, std::
size_t S, std::
size_t A>
545 for(
auto l :
range(S))
550 template<
class T, std::
size_t S, std::
size_t A>
553 for(
auto l :
range(S))
558 template<
class T, std::
size_t S, std::
size_t A>
561 for(
auto l :
range(S))
567 template<
class T, std::
size_t S, std::
size_t A>
569 public std::integral_constant<bool, IsNumber<T>::value>{
573 # pragma GCC diagnostic pop
Some useful basic math stuff.
Traits for type conversions and type information.
std::integral_constant< std::size_t, i > index_constant
An index constant with value i.
Definition: indices.hh:28
static StaticIntegralRange< T, to, from > range(std::integral_constant< T, from >, std::integral_constant< T, to >) noexcept
Definition: rangeutilities.hh:298
std::ostream & operator<<(std::ostream &s, const bigunsignedint< k > &x)
Definition: bigunsignedint.hh:273
I round(const T &val, typename EpsilonType< T >::Type epsilon)
round using epsilon
Definition: float_cmp.cc:309
I trunc(const T &val, typename EpsilonType< T >::Type epsilon)
truncate using epsilon
Definition: float_cmp.cc:405
bool anyTrue(const Mask &mask)
Whether any entry is true
Definition: simd/interface.hh:427
V cond(M &&mask, const V &ifTrue, const V &ifFalse)
Like the ?: operator.
Definition: simd/interface.hh:384
bool allTrue(const Mask &mask)
Whether all entries are true
Definition: simd/interface.hh:437
bool anyFalse(const Mask &mask)
Whether any entry is false
Definition: simd/interface.hh:447
constexpr std::size_t lanes()
Number of lanes in a SIMD type.
Definition: simd/interface.hh:303
decltype(auto) lane(std::size_t l, V &&v)
Extract an element of a SIMD type.
Definition: simd/interface.hh:322
Rebind< bool, V > Mask
Mask type type of some SIMD type.
Definition: simd/interface.hh:287
bool allFalse(const Mask &mask)
Whether all entries are false
Definition: simd/interface.hh:457
typename Overloads::ScalarType< std::decay_t< V > >::type Scalar
Element type of some SIMD type.
Definition: simd/interface.hh:233
bool allFalse(ADLTag< 0 >, const Mask &mask)
implements Simd::allFalse()
Definition: defaults.hh:122
bool allTrue(ADLTag< 0 >, const Mask &mask)
implements Simd::allTrue()
Definition: defaults.hh:102
Mask< V > mask(ADLTag< 0, std::is_same< V, Mask< V > >::value >, const V &v)
implements Simd::mask()
Definition: defaults.hh:151
bool anyFalse(ADLTag< 0 >, const Mask &mask)
implements Simd::anyFalse()
Definition: defaults.hh:112
Dune namespace.
Definition: alignedallocator.hh:11
DUNE_SIMD_LOOP_CMATH_UNARY_OP_WITH_RETURN(ilogb, int)
DUNE_SIMD_LOOP_STD_BINARY_OP(max)
DUNE_SIMD_LOOP_BOOLEAN_OP && DUNE_SIMD_LOOP_BOOLEAN_OP(||);template< class T, std::size_t S, std::size_t A > std::ostream &operator<<(std::ostream &os, const LoopSIMD< T, S, A > &v
Definition: loop.hh:278
DUNE_SIMD_LOOP_BINARY_OP(+)
DUNE_SIMD_LOOP_CMATH_UNARY_OP(cos)
DUNE_SIMD_LOOP_COMPARISON_OP(<)
DUNE_SIMD_LOOP_BITSHIFT_OP(<<)
DUNE_SIMD_LOOP_STD_UNARY_OP(real)
auto min(const AlignedNumber< T, align > &a, const AlignedNumber< T, align > &b)
Definition: debugalign.hh:434
auto max(const AlignedNumber< T, align > &a, const AlignedNumber< T, align > &b)
Definition: debugalign.hh:412
bool anyTrue(ADLTag< 5 >, const AlignedNumber< bool, align > &mask)
Definition: debugalign.hh:530
T & lane(ADLTag< 5 >, std::size_t l, AlignedNumber< T, align > &v)
Definition: debugalign.hh:507
const AlignedNumber< T, align > & cond(ADLTag< 5 >, AlignedNumber< bool, align > mask, const AlignedNumber< T, align > &ifTrue, const AlignedNumber< T, align > &ifFalse)
Definition: debugalign.hh:522
bool isNaN(const FieldVector< K, SIZE > &b, PriorityTag< 2 >, ADLTag)
Definition: fvector.hh:610
bool isInf(const FieldVector< K, SIZE > &b, PriorityTag< 2 >, ADLTag)
Definition: fvector.hh:600
auto isFinite(const LoopSIMD< T, S, A > &v, PriorityTag< 3 >, ADLTag)
Definition: loop.hh:559
auto isNaN(const LoopSIMD< T, S, A > &v, PriorityTag< 3 >, ADLTag)
Definition: loop.hh:543
auto isFinite(const FieldVector< K, SIZE > &b, PriorityTag< 2 >, ADLTag)
Definition: fvector.hh:590
auto isInf(const LoopSIMD< T, S, A > &v, PriorityTag< 3 >, ADLTag)
Definition: loop.hh:551
Tag to make sure the functions in this namespace can be found by ADL.
Definition: math.hh:227
Tag used to force late-binding lookup in Dune::Simd::Overloads.
Definition: base.hh:180
should have a member type type
Definition: standard.hh:58
should have a member type type
Definition: standard.hh:65
should be derived from a Dune::index_constant
Definition: standard.hh:72
LoopSIMD(Simd::Scalar< T > i)
Definition: loop.hh:48
DUNE_SIMD_LOOP_PREFIX_OP(++)
auto operator!() const
Definition: loop.hh:92
DUNE_SIMD_LOOP_POSTFIX_OP(--)
DUNE_SIMD_LOOP_ASSIGNMENT_OP & DUNE_SIMD_LOOP_ASSIGNMENT_OP(|=);DUNE_SIMD_LOOP_ASSIGNMENT_OP(^=
DUNE_SIMD_LOOP_UNARY_OP(-)
DUNE_SIMD_LOOP_PREFIX_OP(--)
DUNE_SIMD_LOOP_ASSIGNMENT_OP(>>=)
DUNE_SIMD_LOOP_POSTFIX_OP(++)
DUNE_SIMD_LOOP_ASSIGNMENT_OP(-=)
LoopSIMD(const LoopSIMD< T, S, OA > &other)
Definition: loop.hh:53
LoopSIMD()
Definition: loop.hh:43
DUNE_SIMD_LOOP_UNARY_OP(~)
DUNE_SIMD_LOOP_ASSIGNMENT_OP(+=)
DUNE_SIMD_LOOP_UNARY_OP(+)
DUNE_SIMD_LOOP_ASSIGNMENT_OP * DUNE_SIMD_LOOP_ASSIGNMENT_OP(/=);DUNE_SIMD_LOOP_ASSIGNMENT_OP(%=
DUNE_SIMD_LOOP_ASSIGNMENT_OP(<<=)
Simd::Scalar< T > type
Definition: loop.hh:302
Whether this type acts as a scalar in the context of (hierarchically blocked) containers.
Definition: typetraits.hh:194
Helper class for tagging priorities.
Definition: typeutilities.hh:71
Include file for users of the SIMD abstraction layer.