0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-25 23:14:13 +01:00

ircd::simd: Improve lane size traits basis; fix conflicting templates.

This commit is contained in:
Jason Volk 2021-02-27 12:50:32 -08:00
parent b1d6defd5a
commit 2be7c0ff6f
2 changed files with 52 additions and 94 deletions

View file

@ -14,13 +14,7 @@
namespace ircd::simd namespace ircd::simd
{ {
template<class T> template<class T>
using lane_type = typename std::remove_reference<decltype(T{}[0])>::type; static constexpr size_t lanes();
template<class T>
constexpr size_t sizeof_lane();
template<class T>
constexpr size_t lanes();
// lane number convenience constants // lane number convenience constants
extern const u8x64 u8x64_lane_id; 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 /// Get number of lanes for vector type (the number after the x in the
/// type name). /// type name).
template<class T> template<class T>
[[gnu::always_inline]] constexpr size_t
inline constexpr size_t
ircd::simd::lanes() ircd::simd::lanes()
{ {
constexpr size_t ret constexpr size_t ret
@ -68,84 +61,23 @@ ircd::simd::lanes()
return ret; return ret;
} }
/// Get the size of each lane; i.e the size of one integral element.
template<class T>
[[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<> template<>
constexpr size_t constexpr size_t
ircd::simd::sizeof_lane<ircd::u128x1>() ircd::simd::sizeof_lane<ircd::u128x1>()
{ {
return 16; return 16;
}; }
template<>
constexpr size_t
ircd::simd::sizeof_lane<ircd::f128x1>()
{
return 16;
};
template<>
constexpr size_t
ircd::simd::sizeof_lane<ircd::d128x1>()
{
return 16;
};
template<> template<>
constexpr size_t constexpr size_t
ircd::simd::sizeof_lane<ircd::u256x1>() ircd::simd::sizeof_lane<ircd::u256x1>()
{ {
return 32; return 32;
}; }
template<>
constexpr size_t
ircd::simd::sizeof_lane<ircd::f256x1>()
{
return 32;
};
template<>
constexpr size_t
ircd::simd::sizeof_lane<ircd::d256x1>()
{
return 32;
};
template<> template<>
constexpr size_t constexpr size_t
ircd::simd::sizeof_lane<ircd::u512x1>() ircd::simd::sizeof_lane<ircd::u512x1>()
{ {
return 64; return 64;
}; }
template<>
constexpr size_t
ircd::simd::sizeof_lane<ircd::f512x1>()
{
return 64;
};
template<>
constexpr size_t
ircd::simd::sizeof_lane<ircd::d512x1>()
{
return 64;
};

View file

@ -11,28 +11,44 @@
#pragma once #pragma once
#define HAVE_IRCD_SIMD_TYPE_H #define HAVE_IRCD_SIMD_TYPE_H
#define IRCD_SIMD_TYPEUSE(_T_, _U_, _V_) \ namespace ircd::simd
namespace ircd \ {
{ \ template<class T>
namespace simd \ using lane_type = typename std::remove_reference<decltype(T{}[0])>::type;
{ \
using _T_ = _U_ \ template<class V,
__attribute__((aligned((_V_)))); \ class U = lane_type<V>>
} \ static constexpr size_t sizeof_lane() = delete;
\
using simd::_T_; \
} }
#define IRCD_SIMD_TYPEVEC(_T_, _U_, _V_) \ #define IRCD_SIMD_TYPEVEC(_T_, _U_, _V_) \
namespace ircd \ namespace ircd \
{ \ { \
namespace simd \ namespace simd \
{ \ { \
using _T_ = _U_ \ using _T_ = _U_ \
__attribute__((vector_size((_V_)))); \ __attribute__((vector_size((_V_)))); \
} \ } \
\ \
using simd::_T_; \ 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_) \ #define IRCD_SIMD_TYPEDEF(_T_, _U_, _V_) \
@ -42,6 +58,12 @@ namespace ircd \
{ \ { \
using _T_ = _U_ \ using _T_ = _U_ \
__attribute__((vector_size((_V_)), aligned((_V_)))); \ __attribute__((vector_size((_V_)), aligned((_V_)))); \
\
template<> \
constexpr size_t sizeof_lane<_T_, _U_>() \
{ \
return sizeof(_U_); \
} \
} \ } \
\ \
using simd::_T_; \ using simd::_T_; \
@ -68,7 +90,9 @@ namespace ircd
typedef uint32_t u32; typedef uint32_t u32;
typedef uint64_t u64; typedef uint64_t u64;
typedef uint128_t u128; typedef uint128_t u128;
typedef int8_t f8; // ??? #if defined(HAVE___FP8)
typedef __fp8 f8;
#endif
#if defined(HAVE__FLOAT16) #if defined(HAVE__FLOAT16)
typedef _Float16 f16; typedef _Float16 f16;
#elif defined(HAVE___FP16) #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(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_] 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(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(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] 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 // other words