Loading...
Searching...
No Matches
simd/interface.hh
Go to the documentation of this file.
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
#ifndef DUNE_COMMON_SIMD_INTERFACE_HH
#define DUNE_COMMON_SIMD_INTERFACE_HH
#include <cassert>
#include <cstddef>
#include <type_traits>
#include <utility>
#include <dune/common/simd/base.hh>
#include <dune/common/typelist.hh>
namespace Dune {
namespace Simd {
template<class V>
using Scalar = typename Overloads::ScalarType<std::decay_t<V> >::type;
template<class S, class V>
using Rebind =
typename Overloads::RebindType<std::decay_t<S>, std::decay_t<V>>::type;
template<class V>
using Mask = Rebind<bool, V>;
template<class V>
constexpr std::size_t lanes()
{
return Overloads::LaneCount<std::decay_t<V>>::value;
}
template<class V>
decltype(auto) lane(std::size_t l, V &&v)
{
assert(l < lanes<V>());
return lane(Overloads::ADLTag<7>{}, l, std::forward<V>(v));
}
template<class V, class U>
constexpr V implCast(U &&u)
{
static_assert(std::is_same<Scalar<V>, Scalar<U> >::value,
"Scalar types must match exactly in implCast");
static_assert(lanes<V>() == lanes<U>(),
"Number of lanes must match in implCast");
return implCast(Overloads::ADLTag<7>{}, MetaType<std::decay_t<V> >{},
std::forward<U>(u));
}
template<class V, class S>
constexpr V broadcast(S s)
{
return broadcast(Overloads::ADLTag<7>{}, MetaType<std::decay_t<V> >{},
std::move(s));
}
template<class M, class V>
V cond(M &&mask, const V &ifTrue, const V &ifFalse)
{
return cond(Overloads::ADLTag<7>{},
implCast<Mask<V> >(std::forward<M>(mask)), ifTrue, ifFalse);
}
template<class V>
V cond(bool mask, const V &ifTrue, const V &ifFalse)
{
return mask ? ifTrue : ifFalse;
}
template<class V>
auto max(const V &v1, const V &v2)
{
return max(Overloads::ADLTag<7>{}, v1, v2);
}
template<class V>
auto min(const V &v1, const V &v2)
{
return min(Overloads::ADLTag<7>{}, v1, v2);
}
template<class Mask>
bool anyTrue(const Mask &mask)
{
return anyTrue(Overloads::ADLTag<7>{}, mask);
}
template<class Mask>
bool allTrue(const Mask &mask)
{
return allTrue(Overloads::ADLTag<7>{}, mask);
}
template<class Mask>
bool anyFalse(const Mask &mask)
{
return anyFalse(Overloads::ADLTag<7>{}, mask);
}
template<class Mask>
bool allFalse(const Mask &mask)
{
return allFalse(Overloads::ADLTag<7>{}, mask);
}
template<class V>
Scalar<V> max(const V &v)
{
return max(Overloads::ADLTag<7>{}, v);
}
template<class V>
Scalar<V> min(const V &v)
{
return min(Overloads::ADLTag<7>{}, v);
}
template<class V>
auto mask(const V &v)
{
return mask(Overloads::ADLTag<7>{}, v);
}
template<class V1, class V2>
auto maskOr(const V1 &v1, const V2 &v2)
{
return maskOr(Overloads::ADLTag<7>{}, v1, v2);
}
template<class V1, class V2>
auto maskAnd(const V1 &v1, const V2 &v2)
{
return maskAnd(Overloads::ADLTag<7>{}, v1, v2);
}
template<class V>
std::size_t lanes(const V &)
{
return lanes<V>();
}
} // namespace Simd
} // namespace Dune
#endif // DUNE_COMMON_SIMD_INTERFACE_HH
typelist.hh
base.hh
Basic definitions for SIMD Implementations.
Dune::Simd::anyTrue
bool anyTrue(const Mask &mask)
Whether any entry is true.
Definition simd/interface.hh:429
Dune::Simd::maskOr
auto maskOr(const V1 &v1, const V2 &v2)
Logic or of masks.
Definition simd/interface.hh:499
Dune::Simd::cond
V cond(M &&mask, const V &ifTrue, const V &ifFalse)
Like the ?: operator.
Definition simd/interface.hh:386
Dune::Simd::mask
auto mask(const V &v)
Convert to mask, analogue of bool(s) for scalars.
Definition simd/interface.hh:489
Dune::Simd::allTrue
bool allTrue(const Mask &mask)
Whether all entries are true.
Definition simd/interface.hh:439
Dune::Simd::Scalar
typename Overloads::ScalarType< std::decay_t< V > >::type Scalar
Element type of some SIMD type.
Definition simd/interface.hh:235
Dune::Simd::broadcast
constexpr V broadcast(S s)
Broadcast a scalar to a vector explicitly.
Definition simd/interface.hh:366
Dune::Simd::max
auto max(const V &v1, const V &v2)
The binary maximum value over two simd objects.
Definition simd/interface.hh:409
Dune::Simd::anyFalse
bool anyFalse(const Mask &mask)
Whether any entry is false.
Definition simd/interface.hh:449
Dune::Simd::implCast
constexpr V implCast(U &&u)
Cast an expression from one implementation to another.
Definition simd/interface.hh:345
Dune::Simd::Mask
Rebind< bool, V > Mask
Mask type type of some SIMD type.
Definition simd/interface.hh:289
Dune::Simd::Rebind
typename Overloads::RebindType< std::decay_t< S >, std::decay_t< V > >::type Rebind
Construct SIMD type with different scalar type.
Definition simd/interface.hh:252
Dune::Simd::lanes
constexpr std::size_t lanes()
Number of lanes in a SIMD type.
Definition simd/interface.hh:305
Dune::Simd::lane
decltype(auto) lane(std::size_t l, V &&v)
Extract an element of a SIMD type.
Definition simd/interface.hh:324
Dune::Simd::allFalse
bool allFalse(const Mask &mask)
Whether all entries are false.
Definition simd/interface.hh:459
Dune::Simd::maskAnd
auto maskAnd(const V1 &v1, const V2 &v2)
Logic and of masks.
Definition simd/interface.hh:509
Dune::Simd::min
auto min(const V &v1, const V &v2)
The binary minimum value over two simd objects.
Definition simd/interface.hh:419
Dune
Dune namespace
Definition alignedallocator.hh:13
Dune::Simd
Namespace for vectorization interface functions used by library developers.
Definition debugalign.hh:518
Dune::Simd::Overloads::ADLTag
Tag used to force late-binding lookup in Dune::Simd::Overloads.
Definition base.hh:182
Dune::Simd::Overloads::ScalarType
should have a member type type
Definition standard.hh:60
Dune::Simd::Overloads::RebindType
should have a member type type
Definition standard.hh:67
Dune::Simd::Overloads::LaneCount
should be derived from a Dune::index_constant
Definition standard.hh:74
Dune::type
Dune::MetaType
A type that refers to another type.
Definition typelist.hh:33