3#ifndef DUNE_DEBUGALIGN_HH
4#define DUNE_DEBUGALIGN_HH
20#include <dune/common/indices.hh>
29 std::function<void(
const char*, std::size_t,
const void*)>;
54 inline bool isAligned(
const void *p, std::size_t align)
58 return std::uintptr_t(p) % align == 0;
62 template<std::
size_t align,
class Impl>
65 void checkAlignment()
const
67 auto pimpl =
static_cast<const Impl*
>(
this);
84 namespace AlignedNumberImpl {
86 template<
class T, std::
size_t align = debugAlignment>
91 using AlignedNumberImpl::AlignedNumber;
94 template<std::
size_t align = debugAlignment,
class T>
103 namespace AlignedNumberImpl {
106 template<
class T, std::
size_t align>
108 :
public AlignedBase<align, AlignedNumber<T, align> >
115 template<
class U, std::size_t uAlign,
116 class = std::enable_if_t<(align >= uAlign) &&
117 std::is_convertible<U, T>::value> >
122 class = std::enable_if_t<std::is_convertible<T, U>::value> >
123 explicit operator U()
const {
return value_; }
125 const T &value()
const {
return value_; }
126 T &value() {
return value_; }
129 template<
class charT,
class Traits>
130 friend std::basic_istream<charT, Traits>&
133 return str >> u.value_;
136 template<
class charT,
class Traits>
137 friend std::basic_ostream<charT, Traits>&
138 operator<<(std::basic_ostream<charT, Traits>& str,
141 return str << u.value_;
153 template<class U = T, class = void_t<decltype(++std::declval<U&>())> >
156 template<
class U = T,
class =
void_t<
decltype(--std::declval<U&>())> >
159 template<class U = T, class = void_t<decltype(std::declval<U&>()++)> >
160 decltype(
auto) operator++(
int) {
return aligned<align>(value_++); }
162 template<class U = T, class = void_t<decltype(std::declval<U&>()--)> >
163 decltype(
auto) operator--(
int) {
return aligned<align>(value_--); }
166 template<
class U = T,
168 decltype(
auto) operator+()
const {
return aligned<align>(+value_); }
170 template<
class U = T,
171 class =
void_t<
decltype(-std::declval<const U&>())> >
172 decltype(
auto) operator-()
const {
return aligned<align>(-value_); }
179# pragma GCC diagnostic push
180# pragma GCC diagnostic ignored "-Wbool-operation"
182 template<
class U = T,
184 decltype(
auto) operator~()
const {
return aligned<align>(~value_); }
186# pragma GCC diagnostic pop
189 template<
class U = T,
191 decltype(
auto) operator!()
const {
return aligned<align>(!value_); }
194#define DUNE_ASSIGN_OP(OP) \
195 template<class U, std::size_t uAlign, \
196 class = std::enable_if_t< \
197 ( uAlign <= align && \
198 sizeof(std::declval<T&>() OP std::declval<U>()) ) \
200 AlignedNumber &operator OP(const AlignedNumber<U, uAlign> &u) \
207 class = void_t<decltype(std::declval<T&>() OP \
208 std::declval<U>())> > \
209 AlignedNumber &operator OP(const U &u) \
215 static_assert(true, "Require semicolon to unconfuse editors")
235#define DUNE_BINARY_OP(OP) \
236 template<class T, std::size_t tAlign, class U, std::size_t uAlign, \
237 class = void_t<decltype(std::declval<T>() \
238 OP std::declval<U>())> > \
240 operator OP(const AlignedNumber<T, tAlign> &t, \
241 const AlignedNumber<U, uAlign> &u) \
244 return aligned<(tAlign > uAlign ? tAlign : uAlign)>(T(t) OP U(u)); \
247 template<class T, class U, std::size_t uAlign, \
248 class = void_t<decltype(std::declval<T>() \
249 OP std::declval<U>())> > \
251 operator OP(const T &t, const AlignedNumber<U, uAlign> &u) \
253 return aligned<uAlign>(t OP U(u)); \
256 template<class T, std::size_t tAlign, class U, \
257 class = void_t<decltype(std::declval<T>() \
258 OP std::declval<U>())> > \
260 operator OP(const AlignedNumber<T, tAlign> &t, const U &u) \
262 return aligned<tAlign>(T(t) OP u); \
265 static_assert(true, "Require semicolon to unconfuse editors")
297#define DUNE_UNARY_FUNC(name) \
298 template<class T, std::size_t align> \
299 decltype(auto) name(const AlignedNumber<T, align> &u) \
302 return aligned<align>(name(T(u))); \
304 static_assert(true, "Require semicolon to unconfuse editors")
318 DUNE_UNARY_FUNC(abs);
319 DUNE_UNARY_FUNC(acos);
320 DUNE_UNARY_FUNC(acosh);
321 DUNE_UNARY_FUNC(asin);
322 DUNE_UNARY_FUNC(asinh);
323 DUNE_UNARY_FUNC(atan);
325 DUNE_UNARY_FUNC(atanh);
326 DUNE_UNARY_FUNC(cbrt);
327 DUNE_UNARY_FUNC(ceil);
329 DUNE_UNARY_FUNC(cos);
330 DUNE_UNARY_FUNC(cosh);
331 DUNE_UNARY_FUNC(erf);
332 DUNE_UNARY_FUNC(erfc);
333 DUNE_UNARY_FUNC(exp);
334 DUNE_UNARY_FUNC(exp2);
335 DUNE_UNARY_FUNC(expm1);
336 DUNE_UNARY_FUNC(fabs);
338 DUNE_UNARY_FUNC(floor);
345 DUNE_UNARY_FUNC(ilogb);
347 DUNE_UNARY_FUNC(lgamma);
348 DUNE_UNARY_FUNC(llrint);
349 DUNE_UNARY_FUNC(llround);
350 DUNE_UNARY_FUNC(log);
351 DUNE_UNARY_FUNC(log10);
352 DUNE_UNARY_FUNC(log1p);
353 DUNE_UNARY_FUNC(log2);
354 DUNE_UNARY_FUNC(logb);
355 DUNE_UNARY_FUNC(lrint);
356 DUNE_UNARY_FUNC(lround);
358 DUNE_UNARY_FUNC(nearbyint);
364 DUNE_UNARY_FUNC(rint);
365 DUNE_UNARY_FUNC(
round);
368 DUNE_UNARY_FUNC(sin);
369 DUNE_UNARY_FUNC(sinh);
370 DUNE_UNARY_FUNC(sqrt);
371 DUNE_UNARY_FUNC(tan);
372 DUNE_UNARY_FUNC(tanh);
373 DUNE_UNARY_FUNC(tgamma);
374 DUNE_UNARY_FUNC(
trunc);
376 DUNE_UNARY_FUNC(isfinite);
377 DUNE_UNARY_FUNC(isinf);
378 DUNE_UNARY_FUNC(isnan);
379 DUNE_UNARY_FUNC(isnormal);
380 DUNE_UNARY_FUNC(signbit);
395 DUNE_UNARY_FUNC(real);
397#undef DUNE_UNARY_FUNC
411 template<
class T, std::
size_t align>
416 return aligned<align>(
max(T(a), T(b)));
419 template<
class T, std::
size_t align>
423 return aligned<align>(
max(a, T(b)));
426 template<
class T, std::
size_t align>
427 auto max(
const AlignedNumber<T, align> &a,
const T &b)
430 return aligned<align>(
max(T(a), b));
433 template<
class T, std::
size_t align>
434 auto min(
const AlignedNumber<T, align> &a,
435 const AlignedNumber<T, align> &b)
438 return aligned<align>(
min(T(a), T(b)));
441 template<
class T, std::
size_t align>
442 auto min(
const T &a,
const AlignedNumber<T, align> &b)
445 return aligned<align>(
min(a, T(b)));
448 template<
class T, std::
size_t align>
449 auto min(
const AlignedNumber<T, align> &a,
const T &b)
452 return aligned<align>(
min(T(a), b));
458 template<
class T, std::
size_t align>
459 AlignedNumber<T, align>
460 cond(
const AlignedNumber<bool, align> &b,
461 const AlignedNumber<T, align> &v1,
const AlignedNumber<T, align> &v2)
467 template<
class T, std::
size_t align>
468 T max_value(
const AlignedNumber<T, align>& val)
473 template<
class T, std::
size_t align>
474 T min_value(
const AlignedNumber<T, align>& val)
479 template<std::
size_t align>
480 bool any_true(
const AlignedNumber<bool, align>& val)
485 template<std::
size_t align>
486 bool all_true(
const AlignedNumber<bool, align>& val)
493 namespace Overloads {
495 template<
class T, std::
size_t align>
498 template<
class U,
class T, std::
size_t align>
503 template<
class T, std::
size_t align>
506 template<
class T, std::
size_t align>
513 template<
class T, std::
size_t align>
520 template<
class T, std::
size_t align>
526 return mask ? ifTrue : ifFalse;
529 template<std::
size_t align>
Basic definitions for SIMD Implementations.
CRTP base mixin class to check alignment.
Definition: debugalign.hh:64
aligned wrappers for arithmetic types
Definition: debugalign.hh:109
A free function to provide the demangled class name of a given object or type as a string.
Default implementations for SIMD Implementations.
Stream & operator>>(Stream &stream, std::tuple< Ts... > &t)
Read a std::tuple.
Definition: streamoperators.hh:41
std::integral_constant< std::size_t, i > index_constant
An index constant with value i.
Definition: indices.hh:28
typename Impl::voider< Types... >::type void_t
Is void for all valid input types (see N3911). The workhorse for C++11 SFINAE-techniques.
Definition: typetraits.hh:40
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
Mask< V > mask(ADLTag< 0, std::is_same< V, Mask< V > >::value >, const V &v)
implements Simd::mask()
Definition: defaults.hh:151
auto min(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::min()
Definition: defaults.hh:87
bool anyTrue(ADLTag< 0 >, const Mask &mask)=delete
implements Simd::anyTrue()
auto max(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::max()
Definition: defaults.hh:79
Dune namespace.
Definition: alignedallocator.hh:14
void violatedAlignment(const char *className, std::size_t expectedAlignment, const void *address)
called when an alignment violation is detected
Definition: debugalign.cc:37
std::string className()
Provide the demangled class name of a type T as a string.
Definition: classname.hh:44
static constexpr auto debugAlignment
an alignment large enough to trigger alignment errors
Definition: debugalign.hh:82
T lane(std::size_t l, const T &v)
access a lane of a simd vector (scalar version)
Definition: simd.hh:364
const T1 cond(bool b, const T1 &v1, const T2 &v2)
conditional evaluate
Definition: conditional.hh:26
AlignedNumber< T, align > aligned(T value)
align a value to a certain alignment
Definition: debugalign.hh:95
ViolatedAlignmentHandler & violatedAlignmentHandler()
access the handler called by violatedAlignment()
Definition: debugalign.cc:31
bool isAligned(const void *p, std::size_t align)
check whether an address conforms to the given alignment
Definition: debugalign.hh:54
std::function< void(const char *, std::size_t, const void *)> ViolatedAlignmentHandler
type of the handler called by violatedAlignment()
Definition: debugalign.hh:29
Tag used to force late-binding lookup in Dune::Simd::Overloads.
Definition: base.hh:180
should be derived from a Dune::index_constant
Definition: standard.hh:72
should have a member type type
Definition: standard.hh:65
should have a member type type
Definition: standard.hh:58
Traits for type conversions and type information.