Loading...
Searching...
No Matches
defaults.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_DEFAULTS_HH
#define DUNE_COMMON_SIMD_DEFAULTS_HH
#include <algorithm>
#include <cstddef>
#include <type_traits>
#include <dune/common/rangeutilities.hh>
#include <dune/common/simd/base.hh>
#include <dune/common/simd/interface.hh>
#include <dune/common/typelist.hh>
#include <dune/common/typetraits.hh>
namespace Dune {
namespace Simd {
namespace Overloads {
template<class V>
decltype(auto) lane(ADLTag<0>, std::size_t l, V v) = delete;
template<class V>
constexpr V implCast(ADLTag<0>, MetaType<V>, const V &u)
{
return u;
}
template<class V, class U>
constexpr V implCast(ADLTag<0>, MetaType<V>, const U &u)
{
V result(Simd::Scalar<V>(0));
for(auto l : range(Simd::lanes(u)))
Simd::lane(l, result) = Simd::lane(l, u);
return result;
}
template<class V, class S>
auto broadcast(ADLTag<0>, MetaType<V>, S s)
{
return V(Simd::Scalar<V>(s));
}
template<class V>
V cond(ADLTag<0>, const Mask<V> &mask,
const V &ifTrue, const V &ifFalse) = delete;
template<class V>
auto max(ADLTag<0>, const V &v1, const V &v2)
{
using std::max;
return max(v1, v2);
}
template<class V>
auto min(ADLTag<0>, const V &v1, const V &v2)
{
using std::min;
return min(v1, v2);
}
template<class Mask>
bool anyTrue(ADLTag<0>, const Mask &mask) = delete;
template<class Mask>
bool allTrue(ADLTag<0>, const Mask &mask)
{
return !Dune::Simd::anyTrue(!mask);
}
template<class Mask>
bool anyFalse(ADLTag<0>, const Mask &mask)
{
return Dune::Simd::anyTrue(!mask);
}
template<class Mask>
bool allFalse(ADLTag<0>, const Mask &mask)
{
return !Dune::Simd::anyTrue(mask);
}
template<class V>
auto max(ADLTag<0>, const V &v)
{
Scalar<V> m = Simd::lane(0, v);
for(std::size_t l = 1; l < Simd::lanes(v); ++l)
if(m < Simd::lane(l, v))
m = Simd::lane(l, v);
return m;
}
template<class V>
auto min(ADLTag<0>, const V &v)
{
Scalar<V> m = Simd::lane(0, v);
for(std::size_t l = 1; l < Simd::lanes(v); ++l)
if(Simd::lane(l, v) < m)
m = Simd::lane(l, v);
return m;
}
template<class V>
Mask<V> mask(ADLTag<0, std::is_same<V, Mask<V> >::value>,
const V &v)
{
return v;
}
template<class V>
auto mask(ADLTag<0, !std::is_same<V, Mask<V> >::value>,
const V &v)
{
using Copy = AutonomousValue<V>; // just in case we are handed a proxy
return v != Copy(Scalar<Copy>(0));
}
template<class V1, class V2>
auto maskOr(ADLTag<0>, const V1 &v1, const V2 &v2)
{
return Simd::mask(v1) || Simd::mask(v2);
}
template<class V1, class V2>
auto maskAnd(ADLTag<0>, const V1 &v1, const V2 &v2)
{
return Simd::mask(v1) && Simd::mask(v2);
}
} // namespace Overloads
} // namespace Simd
} // namespace Dune
#endif // DUNE_COMMON_SIMD_DEFAULTS_HH
typetraits.hh
Traits for type conversions and type information.
typelist.hh
rangeutilities.hh
Utilities for reduction like operations on ranges.
base.hh
Basic definitions for SIMD Implementations.
Dune::range
static constexpr IntegralRange< std::decay_t< T > > range(T &&from, U &&to) noexcept
free standing function for setting up a range based for loop over an integer range for (auto i: range...
Definition rangeutilities.hh:288
Dune::AutonomousValue
typename AutonomousValueType< T >::type AutonomousValue
Type free of internal references that T can be converted to.
Definition typetraits.hh:566
Dune::Simd::anyTrue
bool anyTrue(const Mask &mask)
Whether any entry is true.
Definition simd/interface.hh:429
Dune::Simd::mask
auto mask(const V &v)
Convert to mask, analogue of bool(s) for scalars.
Definition simd/interface.hh:489
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::Mask
Rebind< bool, V > Mask
Mask type type of some SIMD type.
Definition simd/interface.hh:289
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::Overloads::mask
Mask< V > mask(ADLTag< 0, std::is_same< V, Mask< V > >::value >, const V &v)
implements Simd::mask()
Definition defaults.hh:153
Dune::Simd::Overloads::implCast
constexpr V implCast(ADLTag< 0 >, MetaType< V >, const V &u)
implements Simd::implCast<V>(V)
Definition defaults.hh:52
Dune::Simd::Overloads::allFalse
bool allFalse(ADLTag< 0 >, const Mask &mask)
implements Simd::allFalse()
Definition defaults.hh:124
Dune::Simd::Overloads::allTrue
bool allTrue(ADLTag< 0 >, const Mask &mask)
implements Simd::allTrue()
Definition defaults.hh:104
Dune::Simd::Overloads::maskAnd
auto maskAnd(ADLTag< 0 >, const V1 &v1, const V2 &v2)
implements Simd::maskAnd()
Definition defaults.hh:177
Dune::Simd::Overloads::maskOr
auto maskOr(ADLTag< 0 >, const V1 &v1, const V2 &v2)
implements Simd::maskOr()
Definition defaults.hh:170
Dune::Simd::Overloads::anyFalse
bool anyFalse(ADLTag< 0 >, const Mask &mask)
implements Simd::anyFalse()
Definition defaults.hh:114
Dune::Simd::Overloads::min
auto min(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::min()
Definition defaults.hh:89
Dune::Simd::Overloads::broadcast
auto broadcast(ADLTag< 0 >, MetaType< V >, S s)
implements Simd::broadcast<V>()
Definition defaults.hh:69
Dune::Simd::Overloads::max
auto max(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::max()
Definition defaults.hh:81
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
Namespace for the overloads and specializations that make up a SIMD implementation.
Definition debugalign.hh:519
Dune::Simd::Overloads::anyTrue
bool anyTrue(ADLTag< 5 >, const AlignedNumber< bool, align > &mask)
Definition debugalign.hh:556
Dune::Simd::Overloads::cond
const AlignedNumber< T, align > & cond(ADLTag< 5 >, AlignedNumber< bool, align > mask, const AlignedNumber< T, align > &ifTrue, const AlignedNumber< T, align > &ifFalse)
Definition debugalign.hh:548
Dune::Simd::Overloads::lane
T & lane(ADLTag< 5 >, std::size_t l, AlignedNumber< T, align > &v)
Definition debugalign.hh:533
Dune::Simd::Overloads::ADLTag
Tag used to force late-binding lookup in Dune::Simd::Overloads.
Definition base.hh:182
Dune::MetaType
A type that refers to another type.
Definition typelist.hh:33
interface.hh
User interface of the SIMD abstraction.