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
{
template<class T>
using lane_type = typename std::remove_reference<decltype(T{}[0])>::type;
template<class T>
constexpr size_t sizeof_lane();
template<class T>
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<class T>
[[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<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<>
constexpr size_t
ircd::simd::sizeof_lane<ircd::u128x1>()
{
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<>
constexpr size_t
ircd::simd::sizeof_lane<ircd::u256x1>()
{
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<>
constexpr size_t
ircd::simd::sizeof_lane<ircd::u512x1>()
{
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
#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<class T>
using lane_type = typename std::remove_reference<decltype(T{}[0])>::type;
template<class V,
class U = lane_type<V>>
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