16#ifndef RANS_INTERNAL_COMMON_SIMDTYPES_H_
17#define RANS_INTERNAL_COMMON_SIMDTYPES_H_
32enum class SIMDWidth : uint32_t {
SSE = 128u,
35[[nodiscard]]
inline constexpr size_t getLaneWidthBits(SIMDWidth
width)
noexcept {
return static_cast<size_t>(
width); };
37[[nodiscard]]
inline constexpr size_t getLaneWidthBytes(SIMDWidth
width)
noexcept {
return utils::toBytes(
static_cast<size_t>(
width)); };
39[[nodiscard]]
inline constexpr size_t getAlignment(SIMDWidth
width)
noexcept {
return getLaneWidthBytes(
width); };
41template <
class T,
size_t N>
42[[nodiscard]]
inline constexpr T* assume_aligned(T*
ptr)
noexcept
44 return reinterpret_cast<T*
>(__builtin_assume_aligned(
ptr, N, 0));
47template <
class T, SIMDW
idth w
idth_V>
48[[nodiscard]]
inline constexpr T* assume_aligned(T*
ptr)
noexcept
50 constexpr size_t alignment = getAlignment(width_V);
51 return assume_aligned<T, alignment>(
ptr);
54template <
typename T, SIMDW
idth w
idth_V>
55[[nodiscard]]
inline constexpr bool isAligned(T*
ptr)
58 constexpr size_t alignment = getAlignment(width_V);
59 return !(
reinterpret_cast<uintptr_t
>(
ptr) % alignment);
63[[nodiscard]]
inline constexpr size_t getElementCount(SIMDWidth
width)
noexcept
65 return getLaneWidthBytes(
width) /
sizeof(
T);
69[[nodiscard]]
inline constexpr SIMDWidth getSimdWidth(
size_t nHardwareStreams)
noexcept
71 return static_cast<SIMDWidth
>(nHardwareStreams * utils::toBits<T>());
78struct SimdInt<SIMDWidth::
SSE> {
79 using value_type = __m128i;
84struct SimdInt<SIMDWidth::AVX> {
85 using value_type = __m256i;
89template <SIMDW
idth w
idth_V>
90using simdI_t =
typename SimdInt<width_V>::value_type;
92using simdIsse_t = simdI_t<SIMDWidth::SSE>;
94using simdIavx_t = simdI_t<SIMDWidth::AVX>;
101struct SimdDouble<SIMDWidth::
SSE> {
102 using value_type = __m128d;
107struct SimdDouble<SIMDWidth::AVX> {
108 using value_type = __m256d;
112template <SIMDW
idth w
idth_V>
113using simdD_t =
typename SimdDouble<width_V>::value_type;
115using simdDsse_t = simdD_t<SIMDWidth::SSE>;
117using simdDavx_t = simdD_t<SIMDWidth::AVX>;
common helper classes and functions
preprocessor defines to enable features based on CPU architecture
constexpr size_t toBytes(size_t bits) noexcept