3#ifndef DUNE_COMMON_SIMD_LOOP_HH
4#define DUNE_COMMON_SIMD_LOOP_HH
25# pragma GCC diagnostic push
26# pragma GCC diagnostic ignored "-Wbool-operation"
27# pragma GCC diagnostic ignored "-Wint-in-bool-context"
28# define GCC_WARNING_DISABLED
36#if __has_warning("-Wbitwise-instead-of-logical")
37# pragma clang diagnostic push
38# pragma clang diagnostic ignored "-Wbitwise-instead-of-logical"
39# define CLANG_WARNING_DISABLED
47 #define DUNE_PRAGMA_OMP_SIMD _Pragma("omp simd")
49 #define DUNE_PRAGMA_OMP_SIMD
64 template<
class T, std::
size_t S, std::
size_t A = 0>
81 template<std::
size_t OA>
83 :
std::array<T,S>(other)
93#define DUNE_SIMD_LOOP_PREFIX_OP(SYMBOL) \
94 auto operator SYMBOL() { \
95 DUNE_PRAGMA_OMP_SIMD \
96 for(std::size_t i=0; i<S; i++){ \
101 static_assert(true, "expecting ;")
105#undef DUNE_SIMD_LOOP_PREFIX_OP
108#define DUNE_SIMD_LOOP_UNARY_OP(SYMBOL) \
109 auto operator SYMBOL() const { \
110 LoopSIMD<T,S,A> out; \
111 DUNE_PRAGMA_OMP_SIMD \
112 for(std::size_t i=0; i<S; i++){ \
113 out[i] = SYMBOL((*this)[i]); \
117 static_assert(true, "expecting ;")
127 out[i] = !((*this)[i]);
131#undef DUNE_SIMD_LOOP_UNARY_OP
134#define DUNE_SIMD_LOOP_POSTFIX_OP(SYMBOL) \
135 auto operator SYMBOL(int){ \
136 LoopSIMD<T,S,A> out = *this; \
140 static_assert(true, "expecting ;")
144#undef DUNE_SIMD_LOOP_POSTFIX_OP
147#define DUNE_SIMD_LOOP_ASSIGNMENT_OP(SYMBOL) \
148 auto operator SYMBOL(const Simd::Scalar<T> s) { \
149 DUNE_PRAGMA_OMP_SIMD \
150 for(std::size_t i=0; i<S; i++){ \
151 (*this)[i] SYMBOL s; \
156 auto operator SYMBOL(const LoopSIMD<T,S,A> &v) { \
157 DUNE_PRAGMA_OMP_SIMD \
158 for(std::size_t i=0; i<S; i++){ \
159 (*this)[i] SYMBOL v[i]; \
163 static_assert(true, "expecting ;")
175#undef DUNE_SIMD_LOOP_ASSIGNMENT_OP
179#define DUNE_SIMD_LOOP_BINARY_OP(SYMBOL) \
180 template<class T, std::size_t S, std::size_t A> \
181 auto operator SYMBOL(const LoopSIMD<T,S,A> &v, const Simd::Scalar<T> s) { \
182 LoopSIMD<T,S,A> out; \
183 DUNE_PRAGMA_OMP_SIMD \
184 for(std::size_t i=0; i<S; i++){ \
185 out[i] = v[i] SYMBOL s; \
189 template<class T, std::size_t S, std::size_t A> \
190 auto operator SYMBOL(const Simd::Scalar<T> s, const LoopSIMD<T,S,A> &v) { \
191 LoopSIMD<T,S,A> out; \
192 DUNE_PRAGMA_OMP_SIMD \
193 for(std::size_t i=0; i<S; i++){ \
194 out[i] = s SYMBOL v[i]; \
198 template<class T, std::size_t S, std::size_t A> \
199 auto operator SYMBOL(const LoopSIMD<T,S,A> &v, \
200 const LoopSIMD<T,S,A> &w) { \
201 LoopSIMD<T,S,A> out; \
202 DUNE_PRAGMA_OMP_SIMD \
203 for(std::size_t i=0; i<S; i++){ \
204 out[i] = v[i] SYMBOL w[i]; \
208 static_assert(true, "expecting ;")
220#undef DUNE_SIMD_LOOP_BINARY_OP
223#define DUNE_SIMD_LOOP_BITSHIFT_OP(SYMBOL) \
224 template<class T, std::size_t S, std::size_t A, class U> \
225 auto operator SYMBOL(const LoopSIMD<T,S,A> &v, const U s) { \
226 LoopSIMD<T,S,A> out; \
227 DUNE_PRAGMA_OMP_SIMD \
228 for(std::size_t i=0; i<S; i++){ \
229 out[i] = v[i] SYMBOL s; \
233 template<class T, std::size_t S, std::size_t A, class U, std::size_t AU> \
234 auto operator SYMBOL(const LoopSIMD<T,S,A> &v, \
235 const LoopSIMD<U,S,AU> &w) { \
236 LoopSIMD<T,S,A> out; \
237 DUNE_PRAGMA_OMP_SIMD \
238 for(std::size_t i=0; i<S; i++){ \
239 out[i] = v[i] SYMBOL w[i]; \
243 static_assert(true, "expecting ;")
248#undef DUNE_SIMD_LOOP_BITSHIFT_OP
251#define DUNE_SIMD_LOOP_COMPARISON_OP(SYMBOL) \
252 template<class T, std::size_t S, std::size_t A, class U> \
253 auto operator SYMBOL(const LoopSIMD<T,S,A> &v, const U s) { \
254 Simd::Mask<LoopSIMD<T,S,A>> out; \
255 DUNE_PRAGMA_OMP_SIMD \
256 for(std::size_t i=0; i<S; i++){ \
257 out[i] = v[i] SYMBOL s; \
261 template<class T, std::size_t S, std::size_t A> \
262 auto operator SYMBOL(const Simd::Scalar<T> s, const LoopSIMD<T,S,A> &v) { \
263 Simd::Mask<LoopSIMD<T,S,A>> out; \
264 DUNE_PRAGMA_OMP_SIMD \
265 for(std::size_t i=0; i<S; i++){ \
266 out[i] = s SYMBOL v[i]; \
270 template<class T, std::size_t S, std::size_t A> \
271 auto operator SYMBOL(const LoopSIMD<T,S,A> &v, \
272 const LoopSIMD<T,S,A> &w) { \
273 Simd::Mask<LoopSIMD<T,S,A>> out; \
274 DUNE_PRAGMA_OMP_SIMD \
275 for(std::size_t i=0; i<S; i++){ \
276 out[i] = v[i] SYMBOL w[i]; \
280 static_assert(true, "expecting ;")
288#undef DUNE_SIMD_LOOP_COMPARISON_OP
291#define DUNE_SIMD_LOOP_BOOLEAN_OP(SYMBOL) \
292 template<class T, std::size_t S, std::size_t A> \
293 auto operator SYMBOL(const LoopSIMD<T,S,A> &v, const Simd::Scalar<T> s) { \
294 Simd::Mask<LoopSIMD<T,S,A>> out; \
295 DUNE_PRAGMA_OMP_SIMD \
296 for(std::size_t i=0; i<S; i++){ \
297 out[i] = v[i] SYMBOL s; \
301 template<class T, std::size_t S, std::size_t A> \
302 auto operator SYMBOL(const Simd::Mask<T>& s, const LoopSIMD<T,S,A> &v) { \
303 Simd::Mask<LoopSIMD<T,S,A>> out; \
304 DUNE_PRAGMA_OMP_SIMD \
305 for(std::size_t i=0; i<S; i++){ \
306 out[i] = s SYMBOL v[i]; \
310 template<class T, std::size_t S, std::size_t A> \
311 auto operator SYMBOL(const LoopSIMD<T,S,A> &v, \
312 const LoopSIMD<T,S,A> &w) { \
313 Simd::Mask<LoopSIMD<T,S,A>> out; \
314 DUNE_PRAGMA_OMP_SIMD \
315 for(std::size_t i=0; i<S; i++){ \
316 out[i] = v[i] SYMBOL w[i]; \
320 static_assert(true, "expecting ;")
324#undef DUNE_SIMD_LOOP_BOOLEAN_OP
327 template<
class T, std::
size_t S, std::
size_t A>
338 namespace Overloads {
345 template<
class T, std::
size_t S, std::
size_t A>
350 template<
class U,
class T, std::
size_t S, std::
size_t A>
356 template<
class T, std::
size_t S, std::
size_t A>
359 template<
class T, std::
size_t S, std::
size_t A>
361 ->
decltype(std::move(
Simd::lane(l%lanes<T>(), v[l/lanes<T>()])))
363 return std::move(
Simd::lane(l%lanes<T>(), v[l/lanes<T>()]));
366 template<
class T, std::
size_t S, std::
size_t A>
368 ->
decltype(
Simd::lane(l%lanes<T>(), v[l/lanes<T>()]))
370 return Simd::lane(l%lanes<T>(), v[l/lanes<T>()]);
373 template<
class T, std::
size_t S, std::
size_t A>
375 ->
decltype(
Simd::lane(l%lanes<T>(), v[l/lanes<T>()]))
377 return Simd::lane(l%lanes<T>(), v[l/lanes<T>()]);
380 template<
class T, std::
size_t S, std::
size_t AM, std::
size_t AD>
390 template<
class M,
class T, std::
size_t S, std::
size_t A>
401 template<
class M, std::
size_t S, std::
size_t A>
410 template<
class M, std::
size_t S, std::
size_t A>
419 template<
class M, std::
size_t S, std::
size_t A>
428 template<
class M, std::
size_t S, std::
size_t A>
448#define DUNE_SIMD_LOOP_CMATH_UNARY_OP(expr) \
449 template<class T, std::size_t S, std::size_t A, typename Sfinae = \
450 typename std::enable_if_t<!std::is_integral<Simd::Scalar<T>>::value> > \
451 auto expr(const LoopSIMD<T,S,A> &v) { \
453 LoopSIMD<T,S,A> out; \
454 for(std::size_t i=0; i<S; i++) { \
455 out[i] = expr(v[i]); \
459 static_assert(true, "expecting ;")
461#define DUNE_SIMD_LOOP_CMATH_UNARY_OP_WITH_RETURN(expr, returnType) \
462 template<class T, std::size_t S, std::size_t A, typename Sfinae = \
463 typename std::enable_if_t<!std::is_integral<Simd::Scalar<T>>::value> > \
464 auto expr(const LoopSIMD<T,S,A> &v) { \
466 LoopSIMD<returnType,S> out; \
467 for(std::size_t i=0; i<S; i++) { \
468 out[i] = expr(v[i]); \
472 static_assert(true, "expecting ;")
519#undef DUNE_SIMD_LOOP_CMATH_UNARY_OP
520#undef DUNE_SIMD_LOOP_CMATH_UNARY_OP_WITH_RETURN
542#define DUNE_SIMD_LOOP_STD_UNARY_OP(expr) \
543 template<class T, std::size_t S, std::size_t A> \
544 auto expr(const LoopSIMD<T,S,A> &v) { \
546 LoopSIMD<T,S,A> out; \
547 for(std::size_t i=0; i<S; i++) { \
548 out[i] = expr(v[i]); \
553 template<class T, std::size_t S, std::size_t A> \
554 auto expr(const LoopSIMD<std::complex<T>,S,A> &v) { \
556 LoopSIMD<T,S,A> out; \
557 for(std::size_t i=0; i<S; i++) { \
558 out[i] = expr(v[i]); \
562 static_assert(true, "expecting ;")
567#undef DUNE_SIMD_LOOP_STD_UNARY_OP
569#define DUNE_SIMD_LOOP_STD_BINARY_OP(expr) \
570 template<class T, std::size_t S, std::size_t A> \
571 auto expr(const LoopSIMD<T,S,A> &v, const LoopSIMD<T,S,A> &w) { \
573 LoopSIMD<T,S,A> out; \
574 for(std::size_t i=0; i<S; i++) { \
575 out[i] = expr(v[i],w[i]); \
579 static_assert(true, "expecting ;")
584#undef DUNE_SIMD_LOOP_STD_BINARY_OP
586 namespace MathOverloads {
587 template<
class T, std::
size_t S, std::
size_t A>
590 for(
auto l :
range(S))
591 out[l] = Dune::isNaN(v[l]);
595 template<
class T, std::
size_t S, std::
size_t A>
598 for(
auto l :
range(S))
599 out[l] = Dune::isInf(v[l]);
603 template<
class T, std::
size_t S, std::
size_t A>
606 for(
auto l :
range(S))
607 out[l] = Dune::isFinite(v[l]);
612 template<
class T, std::
size_t S, std::
size_t A>
617#ifdef CLANG_WARNING_DISABLED
618# pragma clang diagnostic pop
619# undef CLANG_WARNING_DISABLED
622#ifdef GCC_WARNING_DISABLED
623# pragma GCC diagnostic pop
624# undef GCC_WARNING_DISABLED
#define DUNE_SIMD_LOOP_BINARY_OP(SYMBOL)
Definition loop.hh:179
#define DUNE_SIMD_LOOP_BOOLEAN_OP(SYMBOL)
Definition loop.hh:291
#define DUNE_SIMD_LOOP_STD_BINARY_OP(expr)
Definition loop.hh:569
#define DUNE_SIMD_LOOP_STD_UNARY_OP(expr)
Definition loop.hh:542
#define DUNE_SIMD_LOOP_BITSHIFT_OP(SYMBOL)
Definition loop.hh:223
#define DUNE_SIMD_LOOP_CMATH_UNARY_OP(expr)
Definition loop.hh:448
#define DUNE_PRAGMA_OMP_SIMD
Definition loop.hh:49
#define DUNE_SIMD_LOOP_CMATH_UNARY_OP_WITH_RETURN(expr, returnType)
Definition loop.hh:461
#define DUNE_SIMD_LOOP_ASSIGNMENT_OP(SYMBOL)
Definition loop.hh:147
Traits for type conversions and type information.
Some useful basic math stuff.
static constexpr IntegralRange< std::decay_t< T > > range(T &&from, U &&to) noexcept
free standing function for setting up a range based for loop over an integer range for (auto i: range...
Definition rangeutilities.hh:293
std::ostream & operator<<(std::ostream &s, const bigunsignedint< k > &x)
Definition bigunsignedint.hh:301
bool anyTrue(const Mask &mask)
Whether any entry is true
Definition simd/interface.hh:429
V cond(M &&mask, const V &ifTrue, const V &ifFalse)
Like the ?: operator.
Definition simd/interface.hh:386
bool allTrue(const Mask &mask)
Whether all entries are true
Definition simd/interface.hh:439
bool anyFalse(const Mask &mask)
Whether any entry is false
Definition simd/interface.hh:449
constexpr std::size_t lanes()
Number of lanes in a SIMD type.
Definition simd/interface.hh:305
decltype(auto) lane(std::size_t l, V &&v)
Extract an element of a SIMD type.
Definition simd/interface.hh:324
Rebind< bool, V > Mask
Mask type type of some SIMD type.
Definition simd/interface.hh:289
bool allFalse(const Mask &mask)
Whether all entries are false
Definition simd/interface.hh:459
typename Overloads::ScalarType< std::decay_t< V > >::type Scalar
Element type of some SIMD type.
Definition simd/interface.hh:235
Mask< V > mask(ADLTag< 0, std::is_same< V, Mask< V > >::value >, const V &v)
implements Simd::mask()
Definition defaults.hh:153
bool allFalse(ADLTag< 0 >, const Mask &mask)
implements Simd::allFalse()
Definition defaults.hh:124
bool allTrue(ADLTag< 0 >, const Mask &mask)
implements Simd::allTrue()
Definition defaults.hh:104
bool anyFalse(ADLTag< 0 >, const Mask &mask)
implements Simd::anyFalse()
Definition defaults.hh:114
Dune namespace
Definition alignedallocator.hh:13
DUNE_SIMD_LOOP_COMPARISON_OP(<)
bool anyTrue(ADLTag< 5 >, const AlignedNumber< bool, align > &mask)
Definition debugalign.hh:556
const AlignedNumber< T, align > & cond(ADLTag< 5 >, AlignedNumber< bool, align > mask, const AlignedNumber< T, align > &ifTrue, const AlignedNumber< T, align > &ifFalse)
Definition debugalign.hh:548
T & lane(ADLTag< 5 >, std::size_t l, AlignedNumber< T, align > &v)
Definition debugalign.hh:533
bool isNaN(const FieldVector< K, SIZE > &b, PriorityTag< 2 >, ADLTag)
Returns whether any entry is NaN.
Definition fvector.hh:458
bool isInf(const FieldVector< K, SIZE > &b, PriorityTag< 2 >, ADLTag)
Returns whether any entry is infinite.
Definition fvector.hh:446
auto isFinite(const FieldVector< K, SIZE > &b, PriorityTag< 2 >, ADLTag)
Returns whether all entries are finite.
Definition fvector.hh:435
Whether this type acts as a scalar in the context of (hierarchically blocked) containers.
Definition typetraits.hh:194
Tag to make sure the functions in this namespace can be found by ADL.
Definition math.hh:212
Tag used to force late-binding lookup in Dune::Simd::Overloads.
Definition base.hh:182
should have a member type type
Definition standard.hh:60
should have a member type type
Definition standard.hh:67
should be derived from a Dune::index_constant
Definition standard.hh:74
LoopSIMD(Simd::Scalar< T > i)
Definition loop.hh:77
DUNE_SIMD_LOOP_PREFIX_OP(++)
auto operator!() const
Definition loop.hh:123
DUNE_SIMD_LOOP_POSTFIX_OP(--)
DUNE_SIMD_LOOP_ASSIGNMENT_OP * DUNE_SIMD_LOOP_ASSIGNMENT_OP(/=);DUNE_SIMD_LOOP_ASSIGNMENT_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_POSTFIX_OP(++)
DUNE_SIMD_LOOP_ASSIGNMENT_OP(-=)
LoopSIMD(const LoopSIMD< T, S, OA > &other)
Definition loop.hh:82
LoopSIMD()
Definition loop.hh:70
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(> >=)
Simd::Scalar< T > type
Definition loop.hh:347
Helper class for tagging priorities.
Definition typeutilities.hh:73
Include file for users of the SIMD abstraction layer.