Dune Core Modules (2.10.0)

defaults.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3#ifndef DUNE_COMMON_SIMD_DEFAULTS_HH
4#define DUNE_COMMON_SIMD_DEFAULTS_HH
5
17#include <algorithm>
18#include <cstddef>
19#include <type_traits>
20
24#include <dune/common/typelist.hh>
26
27namespace Dune {
28 namespace Simd {
29 namespace Overloads {
30
47 template<class V>
48 decltype(auto) lane(ADLTag<0>, std::size_t l, V v) = delete;
49
51 template<class V>
52 constexpr V implCast(ADLTag<0>, MetaType<V>, const V &u)
53 {
54 return u;
55 }
56
58 template<class V, class U>
59 constexpr V implCast(ADLTag<0>, MetaType<V>, const U &u)
60 {
61 V result(Simd::Scalar<V>(0));
62 for(auto l : range(Simd::lanes(u)))
63 Simd::lane(l, result) = Simd::lane(l, u);
64 return result;
65 }
66
68 template<class V, class S>
70 {
71 return V(Simd::Scalar<V>(s));
72 }
73
75 template<class V>
77 const V &ifTrue, const V &ifFalse) = delete;
78
80 template<class V>
81 auto max(ADLTag<0>, const V &v1, const V &v2)
82 {
83 using std::max;
84 return max(v1, v2);
85 }
86
88 template<class V>
89 auto min(ADLTag<0>, const V &v1, const V &v2)
90 {
91 using std::min;
92 return min(v1, v2);
93 }
94
96 template<class Mask>
97 bool anyTrue(ADLTag<0>, const Mask &mask) = delete;
98
100
103 template<class Mask>
105 {
106 return !Dune::Simd::anyTrue(!mask);
107 }
108
110
113 template<class Mask>
115 {
116 return Dune::Simd::anyTrue(!mask);
117 }
118
120
123 template<class Mask>
125 {
126 return !Dune::Simd::anyTrue(mask);
127 }
128
130 template<class V>
131 auto max(ADLTag<0>, const V &v)
132 {
133 Scalar<V> m = Simd::lane(0, v);
134 for(std::size_t l = 1; l < Simd::lanes(v); ++l)
135 if(m < Simd::lane(l, v))
136 m = Simd::lane(l, v);
137 return m;
138 }
139
141 template<class V>
142 auto min(ADLTag<0>, const V &v)
143 {
144 Scalar<V> m = Simd::lane(0, v);
145 for(std::size_t l = 1; l < Simd::lanes(v); ++l)
146 if(Simd::lane(l, v) < m)
147 m = Simd::lane(l, v);
148 return m;
149 }
150
152 template<class V>
153 Mask<V> mask(ADLTag<0, std::is_same<V, Mask<V> >::value>,
154 const V &v)
155 {
156 return v;
157 }
158
160 template<class V>
161 auto mask(ADLTag<0, !std::is_same<V, Mask<V> >::value>,
162 const V &v)
163 {
164 using Copy = AutonomousValue<V>; // just in case we are handed a proxy
165 return v != Copy(Scalar<Copy>(0));
166 }
167
169 template<class V1, class V2>
170 auto maskOr(ADLTag<0>, const V1 &v1, const V2 &v2)
171 {
172 return Simd::mask(v1) || Simd::mask(v2);
173 }
174
176 template<class V1, class V2>
177 auto maskAnd(ADLTag<0>, const V1 &v1, const V2 &v2)
178 {
179 return Simd::mask(v1) && Simd::mask(v2);
180 }
181
184 } // namespace Overloads
185 } // namespace Simd
186} // namespace Dune
187
188#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:588
Mask< V > mask(ADLTag< 0, std::is_same< V, Mask< V > >::value >, const V &v)
implements Simd::mask()
Definition: defaults.hh:153
constexpr V implCast(ADLTag< 0 >, MetaType< V >, const V &u)
implements Simd::implCast<V>(V)
Definition: defaults.hh:52
auto min(ADLTag< 0 >, const V &v)
implements Simd::minValue()
Definition: defaults.hh:142
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
auto max(ADLTag< 0 >, const V &v)
implements Simd::maxValue()
Definition: defaults.hh:131
auto maskAnd(ADLTag< 0 >, const V1 &v1, const V2 &v2)
implements Simd::maskAnd()
Definition: defaults.hh:177
auto maskOr(ADLTag< 0 >, const V1 &v1, const V2 &v2)
implements Simd::maskOr()
Definition: defaults.hh:170
bool anyFalse(ADLTag< 0 >, const Mask &mask)
implements Simd::anyFalse()
Definition: defaults.hh:114
auto min(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::min()
Definition: defaults.hh:89
auto broadcast(ADLTag< 0 >, MetaType< V >, S s)
implements Simd::broadcast<V>()
Definition: defaults.hh:69
auto max(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::max()
Definition: defaults.hh:81
bool anyTrue(const Mask &mask)
Whether any entry is true
Definition: interface.hh:429
auto mask(const V &v)
Convert to mask, analogue of bool(s) for scalars.
Definition: interface.hh:489
constexpr std::size_t lanes()
Number of lanes in a SIMD type.
Definition: interface.hh:305
decltype(auto) lane(std::size_t l, V &&v)
Extract an element of a SIMD type.
Definition: interface.hh:324
Rebind< bool, V > Mask
Mask type type of some SIMD type.
Definition: interface.hh:289
typename Overloads::ScalarType< std::decay_t< V > >::type Scalar
Element type of some SIMD type.
Definition: interface.hh:235
Dune namespace.
Definition: alignedallocator.hh:13
const T1 cond(bool b, const T1 &v1, const T2 &v2)
conditional evaluate
Definition: conditional.hh:28
Utilities for reduction like operations on ranges.
A type that refers to another type.
Definition: typelist.hh:33
Tag used to force late-binding lookup in Dune::Simd::Overloads.
Definition: base.hh:182
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 27, 23:30, 2024)