Dune Core Modules (2.8.0)

defaults.hh
Go to the documentation of this file.
1#ifndef DUNE_COMMON_SIMD_DEFAULTS_HH
2#define DUNE_COMMON_SIMD_DEFAULTS_HH
3
15#include <algorithm>
16#include <cstddef>
17#include <type_traits>
18
22#include <dune/common/typelist.hh>
24
25namespace Dune {
26 namespace Simd {
27 namespace Overloads {
28
45 template<class V>
46 decltype(auto) lane(ADLTag<0>, std::size_t l, V v) = delete;
47
49 template<class V>
50 constexpr V implCast(ADLTag<0>, MetaType<V>, const V &u)
51 {
52 return u;
53 }
54
56 template<class V, class U>
57 constexpr V implCast(ADLTag<0>, MetaType<V>, const U &u)
58 {
59 V result(Simd::Scalar<V>(0));
60 for(auto l : range(Simd::lanes(u)))
61 Simd::lane(l, result) = Simd::lane(l, u);
62 return result;
63 }
64
66 template<class V, class S>
68 {
69 return V(Simd::Scalar<V>(s));
70 }
71
73 template<class V>
75 const V &ifTrue, const V &ifFalse) = delete;
76
78 template<class V>
79 auto max(ADLTag<0>, const V &v1, const V &v2)
80 {
81 using std::max;
82 return max(v1, v2);
83 }
84
86 template<class V>
87 auto min(ADLTag<0>, const V &v1, const V &v2)
88 {
89 using std::min;
90 return min(v1, v2);
91 }
92
94 template<class Mask>
95 bool anyTrue(ADLTag<0>, const Mask &mask) = delete;
96
98
101 template<class Mask>
103 {
104 return !Dune::Simd::anyTrue(!mask);
105 }
106
108
111 template<class Mask>
113 {
114 return Dune::Simd::anyTrue(!mask);
115 }
116
118
121 template<class Mask>
123 {
124 return !Dune::Simd::anyTrue(mask);
125 }
126
128 template<class V>
129 auto max(ADLTag<0>, const V &v)
130 {
131 Scalar<V> m = Simd::lane(0, v);
132 for(std::size_t l = 1; l < Simd::lanes(v); ++l)
133 if(m < Simd::lane(l, v))
134 m = Simd::lane(l, v);
135 return m;
136 }
137
139 template<class V>
140 auto min(ADLTag<0>, const V &v)
141 {
142 Scalar<V> m = Simd::lane(0, v);
143 for(std::size_t l = 1; l < Simd::lanes(v); ++l)
144 if(Simd::lane(l, v) < m)
145 m = Simd::lane(l, v);
146 return m;
147 }
148
150 template<class V>
151 Mask<V> mask(ADLTag<0, std::is_same<V, Mask<V> >::value>,
152 const V &v)
153 {
154 return v;
155 }
156
158 template<class V>
159 auto mask(ADLTag<0, !std::is_same<V, Mask<V> >::value>,
160 const V &v)
161 {
162 using Copy = AutonomousValue<V>; // just in case we are handed a proxy
163 return v != Copy(Scalar<Copy>(0));
164 }
165
167 template<class V1, class V2>
168 auto maskOr(ADLTag<0>, const V1 &v1, const V2 &v2)
169 {
170 return Simd::mask(v1) || Simd::mask(v2);
171 }
172
174 template<class V1, class V2>
175 auto maskAnd(ADLTag<0>, const V1 &v1, const V2 &v2)
176 {
177 return Simd::mask(v1) && Simd::mask(v2);
178 }
179
182 } // namespace Overloads
183 } // namespace Simd
184} // namespace Dune
185
186#endif // DUNE_COMMON_SIMD_DEFAULTS_HH
Basic definitions for SIMD Implementations.
User interface of the SIMD abstraction.
Traits for type conversions and type information.
typename AutonomousValueType< T >::type AutonomousValue
Type free of internal references that T can be converted to.
Definition: typetraits.hh:558
Mask< V > mask(ADLTag< 0, std::is_same< V, Mask< V > >::value >, const V &v)
implements Simd::mask()
Definition: defaults.hh:151
constexpr V implCast(ADLTag< 0 >, MetaType< V >, const V &u)
implements Simd::implCast<V>(V)
Definition: defaults.hh:50
auto min(ADLTag< 0 >, const V &v)
implements Simd::minValue()
Definition: defaults.hh:140
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
auto max(ADLTag< 0 >, const V &v)
implements Simd::maxValue()
Definition: defaults.hh:129
auto maskAnd(ADLTag< 0 >, const V1 &v1, const V2 &v2)
implements Simd::maskAnd()
Definition: defaults.hh:175
auto maskOr(ADLTag< 0 >, const V1 &v1, const V2 &v2)
implements Simd::maskOr()
Definition: defaults.hh:168
bool anyFalse(ADLTag< 0 >, const Mask &mask)
implements Simd::anyFalse()
Definition: defaults.hh:112
auto min(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::min()
Definition: defaults.hh:87
auto broadcast(ADLTag< 0 >, MetaType< V >, S s)
implements Simd::broadcast<V>()
Definition: defaults.hh:67
auto max(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::max()
Definition: defaults.hh:79
bool anyTrue(const Mask &mask)
Whether any entry is true
Definition: interface.hh:427
auto mask(const V &v)
Convert to mask, analogue of bool(s) for scalars.
Definition: interface.hh:487
constexpr std::size_t lanes()
Number of lanes in a SIMD type.
Definition: interface.hh:303
decltype(auto) lane(std::size_t l, V &&v)
Extract an element of a SIMD type.
Definition: interface.hh:322
Rebind< bool, V > Mask
Mask type type of some SIMD type.
Definition: interface.hh:287
typename Overloads::ScalarType< std::decay_t< V > >::type Scalar
Element type of some SIMD type.
Definition: interface.hh:233
Dune namespace.
Definition: alignedallocator.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.
A type that refers to another type.
Definition: typelist.hh:31
Tag used to force late-binding lookup in Dune::Simd::Overloads.
Definition: base.hh:180
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)