From 2be7c0ff6fdfb1a0e0a03f89d299a61a7a4f7e5b Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 27 Feb 2021 12:50:32 -0800 Subject: [PATCH] ircd::simd: Improve lane size traits basis; fix conflicting templates. --- include/ircd/simd/traits.h | 78 +++----------------------------------- include/ircd/simd/type.h | 68 +++++++++++++++++++++++---------- 2 files changed, 52 insertions(+), 94 deletions(-) diff --git a/include/ircd/simd/traits.h b/include/ircd/simd/traits.h index 22dfe1240..4f8f1d59b 100644 --- a/include/ircd/simd/traits.h +++ b/include/ircd/simd/traits.h @@ -14,13 +14,7 @@ namespace ircd::simd { template - using lane_type = typename std::remove_reference::type; - - template - constexpr size_t sizeof_lane(); - - template - constexpr size_t lanes(); + static constexpr size_t lanes(); // lane number convenience constants extern const u8x64 u8x64_lane_id; @@ -51,8 +45,7 @@ namespace ircd::simd /// Get number of lanes for vector type (the number after the x in the /// type name). template -[[gnu::always_inline]] -inline constexpr size_t +constexpr size_t ircd::simd::lanes() { constexpr size_t ret @@ -68,84 +61,23 @@ ircd::simd::lanes() return ret; } -/// Get the size of each lane; i.e the size of one integral element. -template -[[gnu::always_inline]] -inline constexpr size_t -ircd::simd::sizeof_lane() -{ - constexpr size_t ret - { - sizeof(T{}[0]) - }; - - static_assert - ( - ret >= 1 && ret <= 64 - ); - - return ret; -} - template<> constexpr size_t ircd::simd::sizeof_lane() { return 16; -}; - -template<> -constexpr size_t -ircd::simd::sizeof_lane() -{ - return 16; -}; - -template<> -constexpr size_t -ircd::simd::sizeof_lane() -{ - return 16; -}; +} template<> constexpr size_t ircd::simd::sizeof_lane() { return 32; -}; - -template<> -constexpr size_t -ircd::simd::sizeof_lane() -{ - return 32; -}; - -template<> -constexpr size_t -ircd::simd::sizeof_lane() -{ - return 32; -}; +} template<> constexpr size_t ircd::simd::sizeof_lane() { return 64; -}; - -template<> -constexpr size_t -ircd::simd::sizeof_lane() -{ - return 64; -}; - -template<> -constexpr size_t -ircd::simd::sizeof_lane() -{ - return 64; -}; +} diff --git a/include/ircd/simd/type.h b/include/ircd/simd/type.h index e42ac1529..fcc32b16e 100644 --- a/include/ircd/simd/type.h +++ b/include/ircd/simd/type.h @@ -11,28 +11,44 @@ #pragma once #define HAVE_IRCD_SIMD_TYPE_H -#define IRCD_SIMD_TYPEUSE(_T_, _U_, _V_) \ -namespace ircd \ -{ \ - namespace simd \ - { \ - using _T_ = _U_ \ - __attribute__((aligned((_V_)))); \ - } \ - \ - using simd::_T_; \ +namespace ircd::simd +{ + template + using lane_type = typename std::remove_reference::type; + + template> + static constexpr size_t sizeof_lane() = delete; } -#define IRCD_SIMD_TYPEVEC(_T_, _U_, _V_) \ -namespace ircd \ -{ \ - namespace simd \ - { \ - using _T_ = _U_ \ - __attribute__((vector_size((_V_)))); \ - } \ - \ - using simd::_T_; \ +#define IRCD_SIMD_TYPEVEC(_T_, _U_, _V_) \ +namespace ircd \ +{ \ + namespace simd \ + { \ + using _T_ = _U_ \ + __attribute__((vector_size((_V_)))); \ + } \ + \ + using simd::_T_; \ +} + +#define IRCD_SIMD_TYPEUSE(_T_, _U_, _V_) \ +namespace ircd \ +{ \ + namespace simd \ + { \ + using _T_ = _U_ \ + __attribute__((aligned((_V_)))); \ + \ + template<> \ + constexpr size_t sizeof_lane<_T_, _U_>() \ + { \ + return sizeof(_U_); \ + } \ + } \ + \ + using simd::_T_; \ } #define IRCD_SIMD_TYPEDEF(_T_, _U_, _V_) \ @@ -42,6 +58,12 @@ namespace ircd \ { \ using _T_ = _U_ \ __attribute__((vector_size((_V_)), aligned((_V_)))); \ + \ + template<> \ + constexpr size_t sizeof_lane<_T_, _U_>() \ + { \ + return sizeof(_U_); \ + } \ } \ \ using simd::_T_; \ @@ -68,7 +90,9 @@ namespace ircd typedef uint32_t u32; typedef uint64_t u64; typedef uint128_t u128; - typedef int8_t f8; // ??? + #if defined(HAVE___FP8) + typedef __fp8 f8; + #endif #if defined(HAVE__FLOAT16) typedef _Float16 f16; #elif defined(HAVE___FP16) @@ -190,9 +214,11 @@ IRCD_SIMD_TYPEDEF(f16x32, f16, 64) // - [_0_|_1_|_2_|_3_|_4_|_5_|_6_|_7_|_8_| IRCD_SIMD_TYPEDEF(f16x16, f16, 32) // - [_0_|_1_|_2_|_3_|_4_|_5_|_6_|_7_|_8_|_9_|... IRCD_SIMD_TYPEDEF(f16x8, f16, 16) // - [_0_|_1_|_2_|_3_|_4_|_5_|_6_|_7_] +#if defined(HAVE___FP8) IRCD_SIMD_TYPEDEF(f8x64, f8, 64) // - [0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f|0|1|2|3|4|5|6|7|... IRCD_SIMD_TYPEDEF(f8x32, f8, 32) // - [0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f|0|1|2|3|4... IRCD_SIMD_TYPEDEF(f8x16, f8, 16) // + [0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f] +#endif // // other words