1#ifndef DUNE_COMMON_SIMD_VC_HH
2#define DUNE_COMMON_SIMD_VC_HH
13#include <dune/common/indices.hh>
16#include <dune/common/simd/loop.hh>
156 template<
class V,
class SFINAE =
void>
159 template<
typename T,
typename A>
160 struct IsMask<Vc::
Mask<T, A> > : std::true_type {};
162 template<
typename T, std::
size_t n,
typename V, std::
size_t m>
163 struct IsMask<Vc::SimdMaskArray<T, n, V, m> > : std::true_type {};
166 template<
class V,
class SFINAE =
void>
169 template<
typename T,
typename A>
170 struct IsVector<Vc::Vector<T, A> > : std::true_type {};
172 template<
typename T, std::
size_t n,
typename V, std::
size_t m>
173 struct IsVector<Vc::SimdArray<T, n, V, m> > : std::true_type {};
175 template<
typename T>
struct IsVectorizable : std::false_type {};
176 template<>
struct IsVectorizable<double> : std::true_type {};
177 template<>
struct IsVectorizable<float> : std::true_type {};
178 template<>
struct IsVectorizable<
std::int32_t> : std::true_type {};
179 template<>
struct IsVectorizable<
std::uint32_t> : std::true_type {};
180 template<>
struct IsVectorizable<
std::int16_t> : std::true_type {};
181 template<>
struct IsVectorizable<
std::uint16_t> : std::true_type {};
199 static_assert(std::is_same<V, std::decay_t<V> >::value,
"Class Proxy "
200 "may only be instantiated with unqualified types");
202 using value_type =
typename V::value_type;
205 static_assert(std::is_arithmetic<value_type>::value,
206 "Only artihmetic types are supported");
211 Proxy(std::size_t idx, V &vec)
212 : vec_(vec), idx_(idx)
219 operator value_type()
const {
return vec_[idx_]; }
222#define DUNE_SIMD_VC_ASSIGNMENT(OP) \
224 class = decltype(std::declval<value_type&>() OP \
225 autoCopy(std::declval<T>()) )> \
226 Proxy operator OP(T &&o) && \
228 vec_[idx_] OP autoCopy(std::forward<T>(o)); \
229 return { idx_, vec_ }; \
231 DUNE_SIMD_VC_ASSIGNMENT(=);
232 DUNE_SIMD_VC_ASSIGNMENT(*=);
233 DUNE_SIMD_VC_ASSIGNMENT(/=);
234 DUNE_SIMD_VC_ASSIGNMENT(%=);
235 DUNE_SIMD_VC_ASSIGNMENT(+=);
236 DUNE_SIMD_VC_ASSIGNMENT(-=);
237 DUNE_SIMD_VC_ASSIGNMENT(<<=);
238 DUNE_SIMD_VC_ASSIGNMENT(>>=);
239 DUNE_SIMD_VC_ASSIGNMENT(&=);
240 DUNE_SIMD_VC_ASSIGNMENT(^=);
241 DUNE_SIMD_VC_ASSIGNMENT(|=);
242#undef DUNE_SIMD_VC_ASSIGNMENT
245 template<
class T = value_type,
246 class = std::enable_if_t<!std::is_same<T, bool>::value> >
247 Proxy operator++() { ++(vec_[idx_]);
return *
this; }
248 template<
class T = value_type,
249 class = std::enable_if_t<!std::is_same<T, bool>::value> >
250 Proxy operator--() { --(vec_[idx_]);
return *
this; }
253 template<
class T = value_type,
254 class = std::enable_if_t<!std::is_same<T, bool>::value> >
255 value_type operator++(
int) {
return vec_[idx_]++; }
256 template<
class T = value_type,
257 class = std::enable_if_t<!std::is_same<T, bool>::value> >
258 value_type operator--(
int) {
return vec_[idx_]--; }
263 friend void swap(
const Proxy &a,
const Proxy &b) {
266 value_type tmp = std::move(a.vec_[a.idx_]);
267 a.vec_[a.idx_] = std::move(b.vec_[b.idx_]);
268 b.vec_[b.idx_] = std::move(tmp);
270 friend void swap(value_type &a,
const Proxy &b) {
273 value_type tmp = std::move(a);
274 a = std::move(b.vec_[b.idx_]);
275 b.vec_[b.idx_] = std::move(tmp);
277 friend void swap(
const Proxy &a, value_type &b) {
280 value_type tmp = std::move(a.vec_[a.idx_]);
281 a.vec_[a.idx_] = std::move(b);
344#define DUNE_SIMD_VC_BINARY(OP) \
345 template<class T, class Abi> \
346 friend auto operator OP(const Vc::Vector<T, Abi> &l, Proxy&& r) \
347 -> decltype(l OP std::declval<value_type>()) \
349 return l OP value_type(r); \
351 template<class T, class Abi> \
352 auto operator OP(const Vc::Vector<T, Abi> &r) && \
353 -> decltype(std::declval<value_type>() OP r) \
355 return value_type(*this) OP r; \
357 template<class T, std::size_t n, class Vec, std::size_t m> \
359 operator OP(const Vc::SimdArray<T, n, Vec, m> &l, Proxy&& r) \
360 -> decltype(l OP std::declval<value_type>()) \
362 return l OP value_type(r); \
364 template<class T, std::size_t n, class Vec, std::size_t m> \
365 auto operator OP(const Vc::SimdArray<T, n, Vec, m> &r) && \
366 -> decltype(std::declval<value_type>() OP r) \
368 return value_type(*this) OP r; \
371 DUNE_SIMD_VC_BINARY(*);
372 DUNE_SIMD_VC_BINARY(/);
373 DUNE_SIMD_VC_BINARY(%);
374 DUNE_SIMD_VC_BINARY(+);
375 DUNE_SIMD_VC_BINARY(-);
376 DUNE_SIMD_VC_BINARY(<<);
377 DUNE_SIMD_VC_BINARY(>>);
378 DUNE_SIMD_VC_BINARY(&);
379 DUNE_SIMD_VC_BINARY(^);
380 DUNE_SIMD_VC_BINARY(|);
381 DUNE_SIMD_VC_BINARY(<);
382 DUNE_SIMD_VC_BINARY(>);
383 DUNE_SIMD_VC_BINARY(<=);
384 DUNE_SIMD_VC_BINARY(>=);
385 DUNE_SIMD_VC_BINARY(==);
386 DUNE_SIMD_VC_BINARY(!=);
387#undef DUNE_SIMD_VC_BINARY
391 template<
class T,
class Abi,
392 class = std::enable_if_t<std::is_convertible<value_type,
394 operator Vc::Vector<T, Abi>() &&
396 return value_type(*
this);
398 template<
class T, std::size_t n,
class Vec, std::size_t m,
399 class = std::enable_if_t<std::is_convertible<value_type,
401 operator Vc::SimdArray<T, n, Vec, m>() &&
403 return value_type(*
this);
406#define DUNE_SIMD_VC_ASSIGN(OP) \
407 template<class T, class Abi> \
408 friend auto operator OP(Vc::Vector<T, Abi> &l, Proxy&& r) \
409 -> decltype(l OP std::declval<value_type>()) \
411 return l OP value_type(r); \
414 DUNE_SIMD_VC_ASSIGN(*=);
415 DUNE_SIMD_VC_ASSIGN(/=);
416 DUNE_SIMD_VC_ASSIGN(%=);
417 DUNE_SIMD_VC_ASSIGN(+=);
418 DUNE_SIMD_VC_ASSIGN(-=);
419 DUNE_SIMD_VC_ASSIGN(&=);
420 DUNE_SIMD_VC_ASSIGN(^=);
421 DUNE_SIMD_VC_ASSIGN(|=);
427 DUNE_SIMD_VC_ASSIGN(<<=);
428 DUNE_SIMD_VC_ASSIGN(>>=);
429#undef DUNE_SIMD_VC_ASSIGN
434 namespace Overloads {
448 using type =
typename V::value_type;
461 std::enable_if_t<VcImpl::IsVector<V>::value> >
475 !VcImpl::IsMask<V>::value>>
477 using type =
typename V::mask_type;
489 std::enable_if_t<VcImpl::IsMask<M>::value>>
491 using type =
typename M::Vector;
501 template<
class S,
class M>
504 VcImpl::IsMask<M>::value &&
505 VcImpl::IsVectorizable<S>::value &&
506 !std::is_same<S, Scalar<typename M::Vector> >::value
509 using type = Vc::SimdArray<S, Simd::lanes<M>()>;
519 template<
class S,
class V>
521 std::enable_if_t<VcImpl::IsVector<V>::value &&
522 !VcImpl::IsMask<V>::value &&
523 VcImpl::IsVectorizable<S>::value &&
524 !std::is_same<S, Scalar<V> >::value> >
526 using type = Vc::SimdArray<S, Simd::lanes<V>()>;
537 template<
class S,
class V>
539 std::enable_if_t<VcImpl::IsVector<V>::value &&
540 !VcImpl::IsVectorizable<S>::value &&
541 !std::is_same<S, bool>::value &&
542 !std::is_same<S, Scalar<V> >::value> >
567 std::size_t l,
const V &v)
581 class = std::enable_if_t<!std::is_reference<V>::value> >
583 std::size_t l, V &&v)
585 return std::forward<V>(v)[l];
592 const Mask<V> &
mask,
const V &ifTrue,
const V &ifFalse)
594 return Vc::iif(
mask, ifTrue, ifFalse);
603 const V &
mask,
const V &ifTrue,
const V &ifFalse)
605 return (
mask && ifTrue) || (!
mask && ifFalse);
612 const V &v1,
const V &v2)
620 const M &m1,
const M &m2)
629 const V &v1,
const V &v2)
637 const M &m1,
const M &m2)
646 return Vc::any_of(
mask);
653 return Vc::all_of(
mask);
662 return Vc::none_of(
mask);
678 return Vc::any_of(
mask);
694 return !Vc::any_of(!
mask);
698 template<
class S1,
class V2>
701 const S1 &s1,
const V2 &v2)
707 template<
class V1,
class S2>
709 std::is_same<
Mask<S2>,
bool>::value>,
710 const V1 &v1,
const S2 &s2)
716 template<
class S1,
class V2>
719 const S1 &s1,
const V2 &v2)
725 template<
class V1,
class S2>
727 std::is_same<
Mask<S2>,
bool>::value>,
728 const V1 &v1,
const S2 &s2)
743 template <
typename T, std::
size_t N>
744 struct IsNumber<Vc::SimdArray<T, N>>
745 :
public std::integral_constant<bool, IsNumber<T>::value> {
748 template <
typename T,
typename Abi>
749 struct IsNumber<Vc::Vector<T, Abi>>
750 :
public std::integral_constant<bool, IsNumber<T>::value> {
Basic definitions for SIMD Implementations.
A reference-like proxy for elements of random-access vectors.
Definition: vc.hh:198
Default implementations for SIMD Implementations.
std::integral_constant< std::size_t, i > index_constant
An index constant with value i.
Definition: indices.hh:28
Mask< V > mask(ADLTag< 0, std::is_same< V, Mask< V > >::value >, const V &v)
implements Simd::mask()
Definition: defaults.hh:151
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 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
auto min(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::min()
Definition: defaults.hh:87
auto max(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::max()
Definition: defaults.hh:79
V cond(M &&mask, const V &ifTrue, const V &ifFalse)
Like the ?: operator.
Definition: interface.hh:384
auto mask(const V &v)
Convert to mask, analogue of bool(s) for scalars.
Definition: interface.hh:487
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:14
const T1 cond(bool b, const T1 &v1, const T2 &v2)
conditional evaluate
Definition: conditional.hh:26
Type free of internal references that T can be converted to.
Definition: typetraits.hh:582
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
specialized to true for Vc mask types
Definition: vc.hh:157
specialized to true for Vc vector and mask types
Definition: vc.hh:167
Traits for type conversions and type information.
Compatibility header for including <Vc/Vc>