Commit 795a69ea authored by Jö Fahlke's avatar Jö Fahlke

Replace Simd::Index with Simd::Rebind

parent 7f5ae870
Pipeline #16096 passed with stage
in 14 minutes and 8 seconds
......@@ -16,7 +16,7 @@ int main() {
#cmake @template@
#if MAX_VECTOR_SIZE >= @VECTOR_SIZE@
test.checkVector<Vec@LANES@@TYPE@>();
test.checkVector<Vec@LANES@@TYPE@, Rebinds>();
#endif // MAX_VECTOR_SIZE >= @VECTOR_SIZE@
#cmake @endtemplate@
......
......@@ -6,15 +6,19 @@
#include <cstddef>
#include <dune/common/simd/test.hh>
#include <dune/common/typelist.hh>
#include <dune/vectorclass/vectorclass.hh>
using Rebinds = Dune::TypeList<int, long, float, double>;
namespace Dune {
namespace Simd {
#cmake @template@
#if MAX_VECTOR_SIZE >= @VECTOR_SIZE@
extern template void UnitTest::checkVector<Vec@LANES@@TYPE@>();
extern template void UnitTest::checkMask<Vec@LANES@@TYPE@b>();
extern template void UnitTest::checkVector<Vec@LANES@@TYPE@, Rebinds>();
extern template void UnitTest::checkMask<Vec@LANES@@TYPE@b, Rebinds>();
#endif // MAX_VECTOR_SIZE >= @VECTOR_SIZE@
#cmake @endtemplate@
......
......@@ -8,7 +8,7 @@ namespace Dune {
namespace Simd {
#if MAX_VECTOR_SIZE >= @VECTOR_SIZE@
template void UnitTest::checkMask<Vec@LANES@@TYPE@b>();
template void UnitTest::checkMask<Vec@LANES@@TYPE@b, Rebinds>();
#endif // MAX_VECTOR_SIZE >= @VECTOR_SIZE@
}
......
......@@ -8,7 +8,7 @@ namespace Dune {
namespace Simd {
#if MAX_VECTOR_SIZE >= @VECTOR_SIZE@
template void UnitTest::checkVector<Vec@LANES@@TYPE@>();
template void UnitTest::checkVector<Vec@LANES@@TYPE@, Rebinds>();
#endif // MAX_VECTOR_SIZE >= @VECTOR_SIZE@
}
......
......@@ -7,6 +7,7 @@
#include <dune/common/math.hh>
#include <dune/common/rangeutilities.hh>
#include <dune/common/typetraits.hh> //needed for AlwaysTrue
#include <dune/common/simd/loop.hh>
#include <dune/common/simd/simd.hh>
#pragma GCC diagnostic push
......@@ -160,86 +161,97 @@ namespace Dune {
struct IsMask<T, std::enable_if_t<IsVector<T>::value && std::is_same<Scalar<T>,bool>::value>>
: std::true_type {};
// construct a vectorclass vector for a given scalar and size
// falls back to loopsimd
template<class S, std::size_t size>
struct Vector {
using type = LoopSIMD<S, size>;
};
// construct a vectorclass mask for a given vectorclass vector
template<class V>
struct Mask;
} //namespace VectorclassImpl
#define DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(CLASS_TYPE, SCALAR_TYPE, INDEX_TYPE, MASK_TYPE, SIZE) \
namespace VectorclassImpl { \
template<> \
struct IsVector<CLASS_TYPE> : std::true_type {}; \
} \
/* Overloads necessary for SIMD-interface-compatibility */ \
namespace Overloads { \
template<> \
struct ScalarType<CLASS_TYPE> { \
using type = SCALAR_TYPE; \
}; \
template<> \
struct IndexType<CLASS_TYPE, std::enable_if_t<!std::is_void<CLASS_TYPE>::value>> { \
using type = INDEX_TYPE; \
}; \
template<> \
struct MaskType<CLASS_TYPE, std::enable_if_t<!std::is_void<CLASS_TYPE>::value>> { \
using type = MASK_TYPE; \
}; \
template<> \
struct LaneCount<CLASS_TYPE> : index_constant<SIZE> {}; \
} //namespace Overloads
// declare a vectorclass vector and corresponding mask
// the mask name is constructed from the vector name by appending a "b"
#define DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(VECTOR, SCALAR, SIZE) \
namespace VectorclassImpl { \
template<> struct IsVector<VECTOR> : std::true_type {}; \
template<> struct IsVector<VECTOR##b> : std::true_type {}; \
template<> struct Vector<SCALAR, SIZE> { using type = VECTOR; }; \
template<> struct Mask<VECTOR> { using type = VECTOR##b; }; \
} \
/* Overloads necessary for SIMD-interface-compatibility */ \
namespace Overloads { \
template<> struct ScalarType<VECTOR> { using type = SCALAR; }; \
template<> struct ScalarType<VECTOR##b> { using type = bool; }; \
template<> struct LaneCount<VECTOR> : index_constant<SIZE> {}; \
template<> struct LaneCount<VECTOR##b> : index_constant<SIZE> {}; \
} \
static_assert(true, "unfudge automatic indent")
// instruction set SSE2 or higher
#if MAX_VECTOR_SIZE >= 128
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec16c, char, Vec16c, Vec16cb, 16);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec8s, short, Vec8s, Vec8sb, 8);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec4i, int, Vec4i, Vec4ib, 4);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec2q, long, Vec2q, Vec2qb, 2);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec4f, float, Vec4i, Vec4fb, 4);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec2d, double, Vec2q, Vec2db, 2);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec16cb, bool, Vec16c, Vec16cb, 16);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec8sb, bool, Vec8s, Vec8sb, 8);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec4ib, bool, Vec4i, Vec4ib, 4);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec2qb, bool, Vec2q, Vec2qb, 2);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec4fb, bool, Vec4i, Vec4fb, 4);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec2db, bool, Vec2q, Vec2db, 2);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec16c, char, 16);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec8s, short, 8);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec4i, int, 4);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec2q, long, 2);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec4f, float, 4);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec2d, double, 2);
#endif
// instruction set AVX or higher (or emulated)
#if MAX_VECTOR_SIZE >= 256
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec8f, float, Vec8i, Vec8fb, 8);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec4d, double, Vec4q, Vec4db, 4);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec8fb, bool, Vec8i, Vec8fb, 8);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec4db, bool, Vec4q, Vec4db, 4);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec8f, float, 8);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec4d, double, 4);
// instruction set AVX2 or higher (or emulated)
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec32c, char, Vec32c, Vec32cb, 32);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec16s, short, Vec16s, Vec16sb, 16);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec8i, int, Vec8i, Vec8ib, 8);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec4q, long, Vec4q, Vec4qb, 4);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec32cb, bool, Vec32c, Vec32cb, 32);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec16sb, bool, Vec16s, Vec16sb, 16);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec8ib, bool, Vec8i, Vec8ib, 8);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec4qb, bool, Vec4q, Vec4qb, 4);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec32c, char, 32);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec16s, short, 16);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec8i, int, 8);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec4q, long, 4);
#endif
// instruction set AVX512 or higher (or emulated)
#if MAX_VECTOR_SIZE >= 512
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec16i, int, Vec16i, Vec16ib, 16);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec8q, long, Vec8q, Vec8qb, 8);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec16f, float, Vec16i, Vec16fb, 16);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec8d, double, Vec8q, Vec8db, 8);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec16i, int, 16);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec8q, long, 8);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec16ib, bool, Vec16i, Vec16ib, 16);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec8qb, bool, Vec8q, Vec8qb, 8);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec8db, bool, Vec8q, Vec8db, 8);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec16fb, bool, Vec16i, Vec16fb, 16);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec16f, float, 16);
DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES(Vec8d, double, 8);
#endif
#undef DUNE_VECTORCLASS_VECTORCLASS_SIMD_TYPES
namespace Overloads {
template<class S, class V>
struct RebindType<S, V,
std::enable_if_t<!std::is_same<S, bool>::value &&
VectorclassImpl::IsVector<V>::value> >
: VectorclassImpl::Vector<S, Simd::lanes<V>()>
{};
template<class V>
struct RebindType<bool, V,
std::enable_if_t<VectorclassImpl::IsVector<V>::value &&
!VectorclassImpl::IsMask<V>::value> >
: VectorclassImpl::Mask<V>
{};
template<class V>
struct RebindType<bool, V,
std::enable_if_t<VectorclassImpl::IsMask<V>::value> >
{
using type = V;
};
template<class V>
struct MaskType<V,
std::enable_if_t<VectorclassImpl::IsVector<V>::value> >
{
using type = Simd::Rebind<bool, V>;
};
template<class Vec, typename = std::enable_if_t<VectorclassImpl::IsVector<Vec>::value>>
Scalar<Vec> lane(ADLTag<5>, std::size_t l, const Vec &v) {
return v.extract(l);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment