Dune Core Modules (unstable)

interface.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_INTERFACE_HH
4#define DUNE_COMMON_SIMD_INTERFACE_HH
5
17#include <cassert>
18#include <cstddef>
19#include <type_traits>
20#include <utility>
21
23#include <dune/common/typelist.hh>
24
25namespace Dune {
26
29
32 namespace Simd {
33
223
234 template<class V>
236
238
251 template<class S, class V>
252 using Rebind =
253 typename Overloads::RebindType<std::decay_t<S>, std::decay_t<V>>::type;
254
256
267
288 template<class V>
290
292
298
304 template<class V>
305 constexpr std::size_t lanes()
306 {
308 }
309
311
323 template<class V>
324 decltype(auto) lane(std::size_t l, V &&v)
325 {
326 assert(l < lanes<V>());
327 return lane(Overloads::ADLTag<7>{}, l, std::forward<V>(v));
328 }
329
331
344 template<class V, class U>
345 constexpr V implCast(U &&u)
346 {
347 static_assert(std::is_same<Scalar<V>, Scalar<U> >::value,
348 "Scalar types must match exactly in implCast");
349 static_assert(lanes<V>() == lanes<U>(),
350 "Number of lanes must match in implCast");
352 std::forward<U>(u));
353 }
354
356
365 template<class V, class S>
366 constexpr V broadcast(S s)
367 {
369 std::move(s));
370 }
371
373
385 template<class M, class V>
386 V cond(M &&mask, const V &ifTrue, const V &ifFalse)
387 {
388 return cond(Overloads::ADLTag<7>{},
389 implCast<Mask<V> >(std::forward<M>(mask)), ifTrue, ifFalse);
390 }
391
393
398 template<class V>
399 V cond(bool mask, const V &ifTrue, const V &ifFalse)
400 {
401 return mask ? ifTrue : ifFalse;
402 }
403
405
408 template<class V>
409 auto max(const V &v1, const V &v2)
410 {
411 return max(Overloads::ADLTag<7>{}, v1, v2);
412 }
413
415
418 template<class V>
419 auto min(const V &v1, const V &v2)
420 {
421 return min(Overloads::ADLTag<7>{}, v1, v2);
422 }
423
425
428 template<class Mask>
429 bool anyTrue(const Mask &mask)
430 {
432 }
433
435
438 template<class Mask>
439 bool allTrue(const Mask &mask)
440 {
442 }
443
445
448 template<class Mask>
449 bool anyFalse(const Mask &mask)
450 {
452 }
453
455
458 template<class Mask>
459 bool allFalse(const Mask &mask)
460 {
462 }
463
465
468 template<class V>
469 Scalar<V> max(const V &v)
470 {
471 return max(Overloads::ADLTag<7>{}, v);
472 }
473
475
478 template<class V>
479 Scalar<V> min(const V &v)
480 {
481 return min(Overloads::ADLTag<7>{}, v);
482 }
483
485
488 template<class V>
489 auto mask(const V &v)
490 {
491 return mask(Overloads::ADLTag<7>{}, v);
492 }
493
495
498 template<class V1, class V2>
499 auto maskOr(const V1 &v1, const V2 &v2)
500 {
501 return maskOr(Overloads::ADLTag<7>{}, v1, v2);
502 }
503
505
508 template<class V1, class V2>
509 auto maskAnd(const V1 &v1, const V2 &v2)
510 {
511 return maskAnd(Overloads::ADLTag<7>{}, v1, v2);
512 }
513
515
526
532 template<class V>
533 std::size_t lanes(const V &)
534 {
535 return lanes<V>();
536 }
537
539
541
542 } // namespace Simd
543} // namespace Dune
544
545#endif // DUNE_COMMON_SIMD_INTERFACE_HH
Basic definitions for SIMD Implementations.
bool anyTrue(const Mask &mask)
Whether any entry is true
Definition: interface.hh:429
auto maskOr(const V1 &v1, const V2 &v2)
Logic or of masks.
Definition: interface.hh:499
V cond(M &&mask, const V &ifTrue, const V &ifFalse)
Like the ?: operator.
Definition: interface.hh:386
auto mask(const V &v)
Convert to mask, analogue of bool(s) for scalars.
Definition: interface.hh:489
bool allTrue(const Mask &mask)
Whether all entries are true
Definition: interface.hh:439
typename Overloads::RebindType< std::decay_t< S >, std::decay_t< V > >::type Rebind
Construct SIMD type with different scalar type.
Definition: interface.hh:253
constexpr V broadcast(S s)
Broadcast a scalar to a vector explicitly.
Definition: interface.hh:366
auto max(const V &v1, const V &v2)
The binary maximum value over two simd objects.
Definition: interface.hh:409
bool anyFalse(const Mask &mask)
Whether any entry is false
Definition: interface.hh:449
constexpr V implCast(U &&u)
Cast an expression from one implementation to another.
Definition: interface.hh:345
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
bool allFalse(const Mask &mask)
Whether all entries are false
Definition: interface.hh:459
auto maskAnd(const V1 &v1, const V2 &v2)
Logic and of masks.
Definition: interface.hh:509
typename Overloads::ScalarType< std::decay_t< V > >::type Scalar
Element type of some SIMD type.
Definition: interface.hh:235
auto min(const V &v1, const V &v2)
The binary minimum value over two simd objects.
Definition: interface.hh:419
Dune namespace.
Definition: alignedallocator.hh:13
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
should be derived from a Dune::index_constant
Definition: standard.hh:74
should have a member type type
Definition: standard.hh:67
should have a member type type
Definition: standard.hh:60
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 21, 23:30, 2024)