Dune Core Modules (2.7.1)

interface.hh
Go to the documentation of this file.
1#ifndef DUNE_COMMON_SIMD_INTERFACE_HH
2#define DUNE_COMMON_SIMD_INTERFACE_HH
3
15#include <cassert>
16#include <cstddef>
17#include <type_traits>
18#include <utility>
19
21#include <dune/common/typelist.hh>
22
23namespace Dune {
24
27
30 namespace Simd {
31
221
232 template<class V>
234
236
249 template<class S, class V>
250 using Rebind =
251 typename Overloads::RebindType<std::decay_t<S>, std::decay_t<V>>::type;
252
254
265
286 template<class V>
288
290
296
302 template<class V>
303 constexpr std::size_t lanes()
304 {
306 }
307
309
321 template<class V>
322 decltype(auto) lane(std::size_t l, V &&v)
323 {
324 assert(l < lanes<V>());
325 return lane(Overloads::ADLTag<7>{}, l, std::forward<V>(v));
326 }
327
329
342 template<class V, class U>
343 constexpr V implCast(U &&u)
344 {
345 static_assert(std::is_same<Scalar<V>, Scalar<U> >::value,
346 "Scalar types must match exactly in implCast");
347 static_assert(lanes<V>() == lanes<U>(),
348 "Number of lanes must match in implCast");
350 std::forward<U>(u));
351 }
352
354
363 template<class V, class S>
364 constexpr V broadcast(S s)
365 {
367 std::move(s));
368 }
369
371
383 template<class M, class V>
384 V cond(M &&mask, const V &ifTrue, const V &ifFalse)
385 {
386 return cond(Overloads::ADLTag<7>{},
387 implCast<Mask<V> >(std::forward<M>(mask)), ifTrue, ifFalse);
388 }
389
391
396 template<class V>
397 V cond(bool mask, const V &ifTrue, const V &ifFalse)
398 {
399 return mask ? ifTrue : ifFalse;
400 }
401
403
406 template<class V>
407 auto max(const V &v1, const V &v2)
408 {
409 return max(Overloads::ADLTag<7>{}, v1, v2);
410 }
411
413
416 template<class V>
417 auto min(const V &v1, const V &v2)
418 {
419 return min(Overloads::ADLTag<7>{}, v1, v2);
420 }
421
423
426 template<class Mask>
427 bool anyTrue(const Mask &mask)
428 {
430 }
431
433
436 template<class Mask>
437 bool allTrue(const Mask &mask)
438 {
440 }
441
443
446 template<class Mask>
447 bool anyFalse(const Mask &mask)
448 {
450 }
451
453
456 template<class Mask>
457 bool allFalse(const Mask &mask)
458 {
460 }
461
463
466 template<class V>
467 Scalar<V> max(const V &v)
468 {
469 return max(Overloads::ADLTag<7>{}, v);
470 }
471
473
476 template<class V>
477 Scalar<V> min(const V &v)
478 {
479 return min(Overloads::ADLTag<7>{}, v);
480 }
481
483
486 template<class V>
487 auto mask(const V &v)
488 {
489 return mask(Overloads::ADLTag<7>{}, v);
490 }
491
493
496 template<class V1, class V2>
497 auto maskOr(const V1 &v1, const V2 &v2)
498 {
499 return maskOr(Overloads::ADLTag<7>{}, v1, v2);
500 }
501
503
506 template<class V1, class V2>
507 auto maskAnd(const V1 &v1, const V2 &v2)
508 {
509 return maskAnd(Overloads::ADLTag<7>{}, v1, v2);
510 }
511
513
524
530 template<class V>
531 std::size_t lanes(const V &)
532 {
533 return lanes<V>();
534 }
535
537
539
540 } // namespace Simd
541} // namespace Dune
542
543#endif // DUNE_COMMON_SIMD_INTERFACE_HH
Basic definitions for SIMD Implementations.
bool anyTrue(const Mask &mask)
Whether any entry is true
Definition: interface.hh:427
auto maskOr(const V1 &v1, const V2 &v2)
Logic or of masks.
Definition: interface.hh:497
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
bool allTrue(const Mask &mask)
Whether all entries are true
Definition: interface.hh:437
typename Overloads::RebindType< std::decay_t< S >, std::decay_t< V > >::type Rebind
Construct SIMD type with different scalar type.
Definition: interface.hh:251
constexpr V broadcast(S s)
Broadcast a scalar to a vector explicitly.
Definition: interface.hh:364
auto max(const V &v1, const V &v2)
The binary maximum value over two simd objects.
Definition: interface.hh:407
bool anyFalse(const Mask &mask)
Whether any entry is false
Definition: interface.hh:447
constexpr V implCast(U &&u)
Cast an expression from one implementation to another.
Definition: interface.hh:343
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
bool allFalse(const Mask &mask)
Whether all entries are false
Definition: interface.hh:457
auto maskAnd(const V1 &v1, const V2 &v2)
Logic and of masks.
Definition: interface.hh:507
typename Overloads::ScalarType< std::decay_t< V > >::type Scalar
Element type of some SIMD type.
Definition: interface.hh:233
auto min(const V &v1, const V &v2)
The binary minimum value over two simd objects.
Definition: interface.hh:417
Dune namespace.
Definition: alignedallocator.hh:14
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: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
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)