From 14b7845d26e06df6861f202607ca5c6b1599189e Mon Sep 17 00:00:00 2001 From: Florent Hivert Date: Sat, 16 Jun 2018 22:37:35 +0200 Subject: [PATCH] WIP --- include/perm16.hpp | 68 +++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 40 deletions(-) diff --git a/include/perm16.hpp b/include/perm16.hpp index 86853079..b4827e88 100644 --- a/include/perm16.hpp +++ b/include/perm16.hpp @@ -46,22 +46,32 @@ namespace HPCombi { /// SIMD vector of 16 unsigned bytes using epu8 = uint8_t __attribute__((vector_size(16))); +/// SIMD vector of 32 unsigned bytes +using xpu8 = uint8_t __attribute__((vector_size(32))); /// -template HPCOMBI_CONSTEXPR -epu8 make_epu8_helper(Function f, std::index_sequence) { - return epu8{f(Indices)...}; +template HPCOMBI_CONSTEXPR +epu8 make_Tpu_helper(Function f, std::index_sequence, Tpu) { + return Tpu {f(Indices)...}; } template HPCOMBI_CONSTEXPR epu8 make_epu8(Function f) { - return make_epu8_helper(f, std::make_index_sequence<16>{}); + return make_Tpu_helper(f, std::make_index_sequence<16>{}, epu8{}); +} + +template HPCOMBI_CONSTEXPR xpu8 make_xpu8(Function f) { + return make_Tpu_helper(f, std::make_index_sequence<32>{}, xpu8{}); } template HPCOMBI_CONSTEXPR uint8_t constfun(uint8_t) { return c; } template HPCOMBI_CONSTEXPR epu8 make_const_epu8() { - return make_epu8_helper(constfun, std::make_index_sequence<16>{}); + return make_Tpu_helper(constfun, std::make_index_sequence<16>{}, epu8{}); +} + +template HPCOMBI_CONSTEXPR xpu8 make_const_xpu8() { + return make_Tpu_helper(constfun, std::make_index_sequence<32>{}, xpu8{}); } // The following functions should be constexpr lambdas writen directly in @@ -108,44 +118,22 @@ struct PTransf16; struct Transf16; -/** A class for vector of 16 unsigned bytes +std::array &as_array(epu8& v) { + return reinterpret_cast &>(v); +} +/** Return self as a const array (just a cast) * + * This is usually faster for algorithm using a lot of indexed acces. */ -struct alignas(16) Vect16 { - - static constexpr size_t Size() { return 16; }; - epu8 v; - - Vect16() = default; - HPCOMBI_CONSTEXPR_CONSTRUCTOR Vect16(epu8 x) : v(x) {} - Vect16(std::initializer_list il, uint8_t def = 0); - HPCOMBI_CONSTEXPR_CONSTRUCTOR operator epu8() const { return v; } - Vect16 &operator=(const Vect16 &) = default; - Vect16 &operator=(const epu8 &vv) { - v = vv; - return *this; - } - - /** Return self as an array (just a cast) - * - * This is usually faster for algorithm using a lot of indexed acces. - */ - std::array &as_array() { - return reinterpret_cast &>(v); - } - /** Return self as a const array (just a cast) - * - * This is usually faster for algorithm using a lot of indexed acces. - */ - const std::array &as_array() const { - return reinterpret_cast &>(v); - } +const std::array &as_array(const epu8& v) const { + return reinterpret_cast &>(v); +} - // The following two functions are refused by clang++ - // const uint8_t & operator[](uint64_t i) const { return v[i]; } - // uint8_t & operator[](uint64_t i) { return v[i]; } - const uint8_t &operator[](uint64_t i) const { return as_array()[i]; } - uint8_t &operator[](uint64_t i) { return as_array()[i]; } +// The following two functions are refused by clang++ +// const uint8_t & operator[](uint64_t i) const { return v[i]; } +// uint8_t & operator[](uint64_t i) { return v[i]; } +const uint8_t &operator[](uint64_t i) const { return as_array()[i]; } +uint8_t &operator[](uint64_t i) { return as_array()[i]; } // Auto is only valid here in C++14 using iter = std::array::iterator;