dune-common 2.12-git
Loading...
Searching...
No Matches
simd/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
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 =
254
256
267
288 template<class V>
290
292
298
304 template<class V>
305 constexpr std::size_t lanes()
306 {
308 }
309
311
330 template<class V>
331 decltype(auto) lane(std::size_t l, V &&v)
332 {
333 assert(l < lanes<V>());
334 return lane(Overloads::ADLTag<7>{}, l, std::forward<V>(v));
335 }
336
338
351 template<class V, class U>
352 constexpr V implCast(U &&u)
353 {
354 static_assert(std::is_same<Scalar<V>, Scalar<U> >::value,
355 "Scalar types must match exactly in implCast");
356 static_assert(lanes<V>() == lanes<U>(),
357 "Number of lanes must match in implCast");
359 std::forward<U>(u));
360 }
361
363
372 template<class V, class S>
373 constexpr V broadcast(S s)
374 {
376 std::move(s));
377 }
378
380
392 template<class M, class V>
393 V cond(M &&mask, const V &ifTrue, const V &ifFalse)
394 {
395 return cond(Overloads::ADLTag<7>{},
396 implCast<Mask<V> >(std::forward<M>(mask)), ifTrue, ifFalse);
397 }
398
400
405 template<class V>
406 V cond(bool mask, const V &ifTrue, const V &ifFalse)
407 {
408 return mask ? ifTrue : ifFalse;
409 }
410
412
421 template<class V>
422 auto max(const V &v1, const V &v2)
423 {
424 return max(Overloads::ADLTag<7>{}, v1, v2);
425 }
426
428
431 template<class V>
432 auto min(const V &v1, const V &v2)
433 {
434 return min(Overloads::ADLTag<7>{}, v1, v2);
435 }
436
438
441 template<class Mask>
442 bool anyTrue(const Mask &mask)
443 {
445 }
446
448
451 template<class Mask>
452 bool allTrue(const Mask &mask)
453 {
455 }
456
458
461 template<class Mask>
462 bool anyFalse(const Mask &mask)
463 {
465 }
466
468
471 template<class Mask>
472 bool allFalse(const Mask &mask)
473 {
475 }
476
478
481 template<class V>
482 Scalar<V> max(const V &v)
483 {
484 return max(Overloads::ADLTag<7>{}, v);
485 }
486
488
491 template<class V>
492 Scalar<V> min(const V &v)
493 {
494 return min(Overloads::ADLTag<7>{}, v);
495 }
496
498
501 template<class V>
502 auto mask(const V &v)
503 {
504 return mask(Overloads::ADLTag<7>{}, v);
505 }
506
508
511 template<class V1, class V2>
512 auto maskOr(const V1 &v1, const V2 &v2)
513 {
514 return maskOr(Overloads::ADLTag<7>{}, v1, v2);
515 }
516
518
521 template<class V1, class V2>
522 auto maskAnd(const V1 &v1, const V2 &v2)
523 {
524 return maskAnd(Overloads::ADLTag<7>{}, v1, v2);
525 }
526
528
539
545 template<class V>
547 {
548 return lanes<V>();
549 }
550
552
554
555 } // namespace Simd
556} // namespace Dune
557
558#endif // DUNE_COMMON_SIMD_INTERFACE_HH
Basic definitions for SIMD Implementations.
bool anyTrue(const Mask &mask)
Whether any entry is true
Definition simd/interface.hh:442
auto maskOr(const V1 &v1, const V2 &v2)
Logic or of masks.
Definition simd/interface.hh:512
V cond(M &&mask, const V &ifTrue, const V &ifFalse)
Like the ?: operator.
Definition simd/interface.hh:393
auto mask(const V &v)
Convert to mask, analogue of bool(s) for scalars.
Definition simd/interface.hh:502
bool allTrue(const Mask &mask)
Whether all entries are true
Definition simd/interface.hh:452
typename Overloads::RebindType< std::decay_t< S >, std::decay_t< V > >::type Rebind
Construct SIMD type with different scalar type.
Definition simd/interface.hh:253
constexpr V broadcast(S s)
Broadcast a scalar to a vector explicitly.
Definition simd/interface.hh:373
auto max(const V &v1, const V &v2)
The binary maximum value over two simd objects.
Definition simd/interface.hh:422
bool anyFalse(const Mask &mask)
Whether any entry is false
Definition simd/interface.hh:462
constexpr V implCast(U &&u)
Cast an expression from one implementation to another.
Definition simd/interface.hh:352
constexpr std::size_t lanes()
Number of lanes in a SIMD type.
Definition simd/interface.hh:305
decltype(auto) lane(std::size_t l, V &&v)
Extract an element of a SIMD type.
Definition simd/interface.hh:331
Rebind< bool, V > Mask
Mask type type of some SIMD type.
Definition simd/interface.hh:289
bool allFalse(const Mask &mask)
Whether all entries are false
Definition simd/interface.hh:472
auto maskAnd(const V1 &v1, const V2 &v2)
Logic and of masks.
Definition simd/interface.hh:522
typename Overloads::ScalarType< std::decay_t< V > >::type Scalar
Element type of some SIMD type.
Definition simd/interface.hh:235
auto min(const V &v1, const V &v2)
The binary minimum value over two simd objects.
Definition simd/interface.hh:432
Dune namespace
Definition alignedallocator.hh:13
Tag used to force late-binding lookup in Dune::Simd::Overloads.
Definition base.hh:182
should have a member type type
Definition standard.hh:60
should have a member type type
Definition standard.hh:67
should be derived from a Dune::index_constant
Definition standard.hh:74
A type that refers to another type.
Definition typelist.hh:33