Dune Core Modules (2.5.0)

simd.hh
1#ifndef DUNE_COMMON_SIMD_HH
2#define DUNE_COMMON_SIMD_HH
3
21#include <dune/common/conditional.hh>
22#if HAVE_VC
23#include <Vc/Vc>
24#endif
25
26namespace Dune
27{
28
29 template<typename T>
30 struct SimdScalarTypeTraits
31 {
32 using type = T;
33 };
34
35 template<typename T>
36 using SimdScalar = typename SimdScalarTypeTraits<T>::type;
37
38#if HAVE_VC
39 /*
40 Add Vc specializations for the SimdScalarTypeTraits trais class
41 */
42 template<typename T, typename A>
43 struct SimdScalarTypeTraits< Vc::Vector<T,A> >
44 {
45 using type = T;
46 };
47
48 template<typename T, std::size_t N, typename V, std::size_t M>
49 struct SimdScalarTypeTraits< Vc::SimdArray<T,N,V,M> >
50 {
51 using type = T;
52 };
53#endif // HAVE_VC
54
55#if HAVE_VC
56 /*
57 Add Vc specializations for cond(), see conditional.hh
58 */
59 template<typename T, typename A>
60 Vc::Vector<T,A> cond(const Vc::Mask<T,A> & b,
61 const Vc::Vector<T,A> & v1,
62 const Vc::Vector<T,A> & v2)
63 {
64 return std::move(Vc::iif(b, v1, v2));
65 }
66
67 template<typename T, std::size_t N, typename V, std::size_t M>
68 Vc::SimdArray<T,N,V,M> cond(const typename Vc::SimdArray<T,N,V,M>::mask_type & b,
69 const Vc::SimdArray<T,N,V,M> & v1,
70 const Vc::SimdArray<T,N,V,M> & v2)
71 {
72 return std::move(Vc::iif(b, v1, v2));
73 }
74#endif // HAVE_VC
75
76#if HAVE_VC
77 /*
78 Add Vc specializations for several boolean operations, see rangeutitlities.hh:
79
80 max_value, min_value, any_true, all_true
81 */
82 template<typename T, typename A>
83 T max_value(const Vc::Vector<T,A> & v)
84 {
85 return v.max();
86 }
87
88 template<typename T, std::size_t N, typename V, std::size_t M>
89 double max_value(const Vc::SimdArray<T,N,V,M> & v)
90 {
91 return v.max();
92 }
93
94 template<typename T, typename A>
95 T min_value(const Vc::Vector<T,A> & v)
96 {
97 return v.min();
98 }
99
100 template<typename T, std::size_t N, typename V, std::size_t M>
101 double min_value(const Vc::SimdArray<T,N,V,M> & v)
102 {
103 return v.min();
104 }
105
106 template<typename T, typename A>
107 bool any_true(const Vc::Mask<T,A> & v)
108 {
109 return Vc::any_of(v);
110 }
111
112 template<typename T, std::size_t N, typename V, std::size_t M>
113 bool any_true(const Vc::SimdMaskArray<T,N,V,M> & v)
114 {
115 return Vc::any_of(v);
116 }
117
118 template<typename T, typename A>
119 bool all_true(const Vc::Mask<T,A> & v)
120 {
121 return Vc::all_of(v);
122 }
123
124 template<typename T, std::size_t N, typename V, std::size_t M>
125 bool all_true(const Vc::SimdMaskArray<T,N,V,M> & v)
126 {
127 return Vc::all_of(v);
128 }
129#endif // HAVE_VC
130
131} // end namespace Dune
132
133#endif // DUNE_COMMON_SIMD_HH
bool any_true(const T &v)
similar to std::bitset<N>::any() return true, if any entries is true
Definition: rangeutilities.hh:66
bool all_true(const T &v)
similar to std::bitset<N>::all() return true, if any entries is true
Definition: rangeutilities.hh:90
T::value_type min_value(const T &v)
compute the minimum value over a range
Definition: rangeutilities.hh:50
T::value_type max_value(const T &v)
compute the maximum value over a range
Definition: rangeutilities.hh:33
Dune namespace.
Definition: alignment.hh:11
const T1 cond(bool b, const T1 &v1, const T2 &v2)
conditional evaluate
Definition: conditional.hh:26
Utilities for reduction like operations on ranges.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)