2013-10-06 12:07:42 +00:00
|
|
|
#pragma once
|
|
|
|
|
2016-02-01 21:55:43 +00:00
|
|
|
#include "types.h"
|
2019-09-26 18:57:03 +00:00
|
|
|
#include "util/endian.hpp"
|
2019-01-22 19:00:52 +00:00
|
|
|
#include <cstring>
|
2015-08-17 15:14:29 +00:00
|
|
|
|
2020-02-17 17:55:20 +00:00
|
|
|
#if __has_include(<bit>)
|
|
|
|
#include <bit>
|
|
|
|
#else
|
|
|
|
#include <type_traits>
|
|
|
|
#endif
|
|
|
|
|
2016-08-13 13:36:04 +00:00
|
|
|
// 128-bit vector type and also se_storage<> storage type
|
2016-02-01 21:55:43 +00:00
|
|
|
union alignas(16) v128
|
2014-09-06 16:30:13 +00:00
|
|
|
{
|
2016-02-01 21:55:43 +00:00
|
|
|
char _bytes[16];
|
|
|
|
|
2016-08-13 13:36:04 +00:00
|
|
|
template <typename T, std::size_t N, std::size_t M>
|
2016-02-01 21:55:43 +00:00
|
|
|
struct masked_array_t // array type accessed as (index ^ M)
|
2014-10-07 13:35:44 +00:00
|
|
|
{
|
2020-03-17 13:05:42 +00:00
|
|
|
char m_data[16];
|
2014-10-07 13:35:44 +00:00
|
|
|
|
2015-09-26 20:46:04 +00:00
|
|
|
public:
|
2016-08-13 13:36:04 +00:00
|
|
|
T& operator[](std::size_t index)
|
2015-09-26 20:46:04 +00:00
|
|
|
{
|
2020-03-17 13:05:42 +00:00
|
|
|
return reinterpret_cast<T*>(m_data)[index ^ M];
|
2015-09-26 20:46:04 +00:00
|
|
|
}
|
2014-10-07 13:35:44 +00:00
|
|
|
|
2016-08-13 13:36:04 +00:00
|
|
|
const T& operator[](std::size_t index) const
|
2015-09-26 20:46:04 +00:00
|
|
|
{
|
2020-03-17 13:05:42 +00:00
|
|
|
return reinterpret_cast<const T*>(m_data)[index ^ M];
|
2015-09-26 20:46:04 +00:00
|
|
|
}
|
|
|
|
};
|
2014-10-07 13:35:44 +00:00
|
|
|
|
2016-08-13 13:36:04 +00:00
|
|
|
template <typename T, std::size_t N = 16 / sizeof(T)>
|
2020-02-17 17:55:20 +00:00
|
|
|
using normal_array_t = masked_array_t<T, N, std::endian::little == std::endian::native ? 0 : N - 1>;
|
2016-08-13 13:36:04 +00:00
|
|
|
template <typename T, std::size_t N = 16 / sizeof(T)>
|
2020-02-17 17:55:20 +00:00
|
|
|
using reversed_array_t = masked_array_t<T, N, std::endian::little == std::endian::native ? N - 1 : 0>;
|
2014-10-07 13:35:44 +00:00
|
|
|
|
2016-08-13 13:36:04 +00:00
|
|
|
normal_array_t<u64> _u64;
|
|
|
|
normal_array_t<s64> _s64;
|
2015-09-14 16:32:35 +00:00
|
|
|
reversed_array_t<u64> u64r;
|
|
|
|
reversed_array_t<s64> s64r;
|
2014-10-07 13:35:44 +00:00
|
|
|
|
2016-08-13 13:36:04 +00:00
|
|
|
normal_array_t<u32> _u32;
|
|
|
|
normal_array_t<s32> _s32;
|
2015-09-14 16:32:35 +00:00
|
|
|
reversed_array_t<u32> u32r;
|
|
|
|
reversed_array_t<s32> s32r;
|
2014-10-07 13:35:44 +00:00
|
|
|
|
2016-08-13 13:36:04 +00:00
|
|
|
normal_array_t<u16> _u16;
|
|
|
|
normal_array_t<s16> _s16;
|
2015-09-14 16:32:35 +00:00
|
|
|
reversed_array_t<u16> u16r;
|
|
|
|
reversed_array_t<s16> s16r;
|
2014-10-07 13:35:44 +00:00
|
|
|
|
2016-08-13 13:36:04 +00:00
|
|
|
normal_array_t<u8> _u8;
|
|
|
|
normal_array_t<s8> _s8;
|
|
|
|
reversed_array_t<u8> u8r;
|
|
|
|
reversed_array_t<s8> s8r;
|
2014-10-07 13:35:44 +00:00
|
|
|
|
2016-08-13 13:36:04 +00:00
|
|
|
normal_array_t<f32> _f;
|
|
|
|
normal_array_t<f64> _d;
|
2015-09-14 16:32:35 +00:00
|
|
|
reversed_array_t<f32> fr;
|
|
|
|
reversed_array_t<f64> dr;
|
2014-10-07 13:35:44 +00:00
|
|
|
|
2014-10-07 21:37:04 +00:00
|
|
|
__m128 vf;
|
|
|
|
__m128i vi;
|
2015-03-21 14:29:33 +00:00
|
|
|
__m128d vd;
|
2014-09-06 16:30:13 +00:00
|
|
|
|
2016-02-01 21:55:43 +00:00
|
|
|
struct bit_array_128
|
2014-09-06 16:30:13 +00:00
|
|
|
{
|
2020-03-17 13:05:42 +00:00
|
|
|
char m_data[16];
|
2014-09-06 16:30:13 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
class bit_element
|
|
|
|
{
|
|
|
|
u64& data;
|
|
|
|
const u64 mask;
|
|
|
|
|
|
|
|
public:
|
|
|
|
bit_element(u64& data, const u64 mask)
|
|
|
|
: data(data)
|
|
|
|
, mask(mask)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-09-26 20:46:04 +00:00
|
|
|
operator bool() const
|
2014-09-06 16:30:13 +00:00
|
|
|
{
|
|
|
|
return (data & mask) != 0;
|
|
|
|
}
|
|
|
|
|
2016-08-13 13:36:04 +00:00
|
|
|
bit_element& operator=(const bool right)
|
2014-09-06 16:30:13 +00:00
|
|
|
{
|
|
|
|
if (right)
|
|
|
|
{
|
|
|
|
data |= mask;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
data &= ~mask;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-08-13 13:36:04 +00:00
|
|
|
bit_element& operator=(const bit_element& right)
|
2014-09-06 16:30:13 +00:00
|
|
|
{
|
|
|
|
if (right)
|
|
|
|
{
|
|
|
|
data |= mask;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
data &= ~mask;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-02-04 15:29:34 +00:00
|
|
|
// Index 0 returns the MSB and index 127 returns the LSB
|
2016-08-13 13:36:04 +00:00
|
|
|
bit_element operator[](u32 index)
|
2014-09-06 16:30:13 +00:00
|
|
|
{
|
2020-03-17 13:05:42 +00:00
|
|
|
const auto data_ptr = reinterpret_cast<u64*>(m_data);
|
|
|
|
|
2020-02-17 17:55:20 +00:00
|
|
|
if constexpr (std::endian::little == std::endian::native)
|
|
|
|
{
|
2020-03-17 13:05:42 +00:00
|
|
|
return bit_element(data_ptr[1 - (index >> 6)], 0x8000000000000000ull >> (index & 0x3F));
|
2020-02-17 17:55:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-03-17 13:05:42 +00:00
|
|
|
return bit_element(data_ptr[index >> 6], 0x8000000000000000ull >> (index & 0x3F));
|
2020-02-17 17:55:20 +00:00
|
|
|
}
|
2014-09-06 16:30:13 +00:00
|
|
|
}
|
|
|
|
|
2015-02-04 15:29:34 +00:00
|
|
|
// Index 0 returns the MSB and index 127 returns the LSB
|
2016-08-13 13:36:04 +00:00
|
|
|
bool operator[](u32 index) const
|
2014-09-06 16:30:13 +00:00
|
|
|
{
|
2020-03-17 13:05:42 +00:00
|
|
|
const auto data_ptr = reinterpret_cast<const u64*>(m_data);
|
|
|
|
|
2020-02-17 17:55:20 +00:00
|
|
|
if constexpr (std::endian::little == std::endian::native)
|
|
|
|
{
|
2020-03-17 13:05:42 +00:00
|
|
|
return (data_ptr[1 - (index >> 6)] & (0x8000000000000000ull >> (index & 0x3F))) != 0;
|
2020-02-17 17:55:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-03-17 13:05:42 +00:00
|
|
|
return (data_ptr[index >> 6] & (0x8000000000000000ull >> (index & 0x3F))) != 0;
|
2020-02-17 17:55:20 +00:00
|
|
|
}
|
2014-09-06 16:30:13 +00:00
|
|
|
}
|
2016-08-13 13:36:04 +00:00
|
|
|
} _bit;
|
2014-09-06 16:30:13 +00:00
|
|
|
|
2015-08-06 13:31:13 +00:00
|
|
|
static v128 from64(u64 _0, u64 _1 = 0)
|
2014-09-06 16:30:13 +00:00
|
|
|
{
|
2015-08-06 13:31:13 +00:00
|
|
|
v128 ret;
|
2014-09-14 22:17:24 +00:00
|
|
|
ret._u64[0] = _0;
|
|
|
|
ret._u64[1] = _1;
|
2014-09-06 16:30:13 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-08-06 13:31:13 +00:00
|
|
|
static v128 from64r(u64 _1, u64 _0 = 0)
|
2014-10-07 13:35:44 +00:00
|
|
|
{
|
|
|
|
return from64(_0, _1);
|
|
|
|
}
|
|
|
|
|
2015-08-06 13:31:13 +00:00
|
|
|
static v128 from32(u32 _0, u32 _1 = 0, u32 _2 = 0, u32 _3 = 0)
|
2014-09-06 16:30:13 +00:00
|
|
|
{
|
2015-08-06 13:31:13 +00:00
|
|
|
v128 ret;
|
2014-09-14 22:17:24 +00:00
|
|
|
ret._u32[0] = _0;
|
|
|
|
ret._u32[1] = _1;
|
|
|
|
ret._u32[2] = _2;
|
|
|
|
ret._u32[3] = _3;
|
2014-09-06 16:30:13 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-08-06 13:31:13 +00:00
|
|
|
static v128 from32r(u32 _3, u32 _2 = 0, u32 _1 = 0, u32 _0 = 0)
|
2014-10-02 10:29:20 +00:00
|
|
|
{
|
2014-10-07 13:35:44 +00:00
|
|
|
return from32(_0, _1, _2, _3);
|
2014-10-02 10:29:20 +00:00
|
|
|
}
|
|
|
|
|
2015-08-06 13:31:13 +00:00
|
|
|
static v128 from32p(u32 value)
|
2014-10-02 10:29:20 +00:00
|
|
|
{
|
2015-08-06 13:31:13 +00:00
|
|
|
v128 ret;
|
2015-03-29 11:00:10 +00:00
|
|
|
ret.vi = _mm_set1_epi32(static_cast<s32>(value));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-08-06 13:31:13 +00:00
|
|
|
static v128 from16p(u16 value)
|
2015-03-29 11:00:10 +00:00
|
|
|
{
|
2015-08-06 13:31:13 +00:00
|
|
|
v128 ret;
|
2015-03-29 11:00:10 +00:00
|
|
|
ret.vi = _mm_set1_epi16(static_cast<s16>(value));
|
2014-10-07 21:37:04 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-08-06 13:31:13 +00:00
|
|
|
static v128 from8p(u8 value)
|
2014-10-07 21:37:04 +00:00
|
|
|
{
|
2015-08-06 13:31:13 +00:00
|
|
|
v128 ret;
|
2015-03-29 11:00:10 +00:00
|
|
|
ret.vi = _mm_set1_epi8(static_cast<s8>(value));
|
2014-10-02 10:29:20 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-08-06 13:31:13 +00:00
|
|
|
static v128 fromBit(u32 bit)
|
2014-09-06 16:30:13 +00:00
|
|
|
{
|
2015-08-06 13:31:13 +00:00
|
|
|
v128 ret = {};
|
2014-09-06 16:30:13 +00:00
|
|
|
ret._bit[bit] = true;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-08-06 13:31:13 +00:00
|
|
|
static v128 fromV(__m128i value)
|
2014-10-07 21:37:04 +00:00
|
|
|
{
|
2015-08-06 13:31:13 +00:00
|
|
|
v128 ret;
|
2014-10-07 21:37:04 +00:00
|
|
|
ret.vi = value;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-08-06 13:31:13 +00:00
|
|
|
static v128 fromF(__m128 value)
|
2015-03-20 23:36:05 +00:00
|
|
|
{
|
2015-08-06 13:31:13 +00:00
|
|
|
v128 ret;
|
2015-03-20 23:36:05 +00:00
|
|
|
ret.vf = value;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-08-06 13:31:13 +00:00
|
|
|
static v128 fromD(__m128d value)
|
2015-03-21 14:29:33 +00:00
|
|
|
{
|
2015-08-06 13:31:13 +00:00
|
|
|
v128 ret;
|
2015-03-21 14:29:33 +00:00
|
|
|
ret.vd = value;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-04-10 07:05:23 +00:00
|
|
|
// Unaligned load with optional index offset
|
|
|
|
static v128 loadu(const void* ptr, std::size_t index = 0)
|
|
|
|
{
|
|
|
|
v128 ret;
|
|
|
|
std::memcpy(&ret, static_cast<const u8*>(ptr) + index * sizeof(v128), sizeof(v128));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unaligned store with optional index offset
|
|
|
|
static void storeu(v128 value, void* ptr, std::size_t index = 0)
|
|
|
|
{
|
|
|
|
std::memcpy(static_cast<u8*>(ptr) + index * sizeof(v128), &value, sizeof(v128));
|
|
|
|
}
|
|
|
|
|
2015-09-14 16:32:35 +00:00
|
|
|
static inline v128 add8(const v128& left, const v128& right)
|
2014-09-06 16:30:13 +00:00
|
|
|
{
|
2014-10-07 21:37:04 +00:00
|
|
|
return fromV(_mm_add_epi8(left.vi, right.vi));
|
|
|
|
}
|
|
|
|
|
2015-09-14 16:32:35 +00:00
|
|
|
static inline v128 add16(const v128& left, const v128& right)
|
2015-03-20 23:36:05 +00:00
|
|
|
{
|
|
|
|
return fromV(_mm_add_epi16(left.vi, right.vi));
|
|
|
|
}
|
|
|
|
|
2015-09-14 16:32:35 +00:00
|
|
|
static inline v128 add32(const v128& left, const v128& right)
|
2015-03-20 23:36:05 +00:00
|
|
|
{
|
|
|
|
return fromV(_mm_add_epi32(left.vi, right.vi));
|
|
|
|
}
|
|
|
|
|
2015-09-14 16:32:35 +00:00
|
|
|
static inline v128 addfs(const v128& left, const v128& right)
|
2015-03-20 23:36:05 +00:00
|
|
|
{
|
|
|
|
return fromF(_mm_add_ps(left.vf, right.vf));
|
|
|
|
}
|
|
|
|
|
2015-09-14 16:32:35 +00:00
|
|
|
static inline v128 addfd(const v128& left, const v128& right)
|
2015-03-21 14:29:33 +00:00
|
|
|
{
|
|
|
|
return fromD(_mm_add_pd(left.vd, right.vd));
|
|
|
|
}
|
|
|
|
|
2015-09-14 16:32:35 +00:00
|
|
|
static inline v128 sub8(const v128& left, const v128& right)
|
2014-10-07 21:37:04 +00:00
|
|
|
{
|
|
|
|
return fromV(_mm_sub_epi8(left.vi, right.vi));
|
|
|
|
}
|
|
|
|
|
2015-09-14 16:32:35 +00:00
|
|
|
static inline v128 sub16(const v128& left, const v128& right)
|
2015-03-20 23:36:05 +00:00
|
|
|
{
|
|
|
|
return fromV(_mm_sub_epi16(left.vi, right.vi));
|
|
|
|
}
|
|
|
|
|
2015-09-14 16:32:35 +00:00
|
|
|
static inline v128 sub32(const v128& left, const v128& right)
|
2015-03-20 23:36:05 +00:00
|
|
|
{
|
|
|
|
return fromV(_mm_sub_epi32(left.vi, right.vi));
|
|
|
|
}
|
|
|
|
|
2015-09-14 16:32:35 +00:00
|
|
|
static inline v128 subfs(const v128& left, const v128& right)
|
2015-03-20 23:36:05 +00:00
|
|
|
{
|
|
|
|
return fromF(_mm_sub_ps(left.vf, right.vf));
|
|
|
|
}
|
|
|
|
|
2015-09-14 16:32:35 +00:00
|
|
|
static inline v128 subfd(const v128& left, const v128& right)
|
2015-03-21 14:29:33 +00:00
|
|
|
{
|
|
|
|
return fromD(_mm_sub_pd(left.vd, right.vd));
|
|
|
|
}
|
|
|
|
|
2015-09-14 16:32:35 +00:00
|
|
|
static inline v128 maxu8(const v128& left, const v128& right)
|
2015-03-20 23:36:05 +00:00
|
|
|
{
|
|
|
|
return fromV(_mm_max_epu8(left.vi, right.vi));
|
|
|
|
}
|
|
|
|
|
2015-09-14 16:32:35 +00:00
|
|
|
static inline v128 minu8(const v128& left, const v128& right)
|
2014-10-07 21:37:04 +00:00
|
|
|
{
|
|
|
|
return fromV(_mm_min_epu8(left.vi, right.vi));
|
|
|
|
}
|
|
|
|
|
2015-09-14 16:32:35 +00:00
|
|
|
static inline v128 eq8(const v128& left, const v128& right)
|
2014-09-06 16:30:13 +00:00
|
|
|
{
|
2014-10-07 21:37:04 +00:00
|
|
|
return fromV(_mm_cmpeq_epi8(left.vi, right.vi));
|
2015-03-29 11:00:10 +00:00
|
|
|
}
|
|
|
|
|
2015-09-14 16:32:35 +00:00
|
|
|
static inline v128 eq16(const v128& left, const v128& right)
|
2015-03-29 11:00:10 +00:00
|
|
|
{
|
|
|
|
return fromV(_mm_cmpeq_epi16(left.vi, right.vi));
|
|
|
|
}
|
|
|
|
|
2015-09-14 16:32:35 +00:00
|
|
|
static inline v128 eq32(const v128& left, const v128& right)
|
2015-03-29 11:00:10 +00:00
|
|
|
{
|
|
|
|
return fromV(_mm_cmpeq_epi32(left.vi, right.vi));
|
2014-09-06 16:30:13 +00:00
|
|
|
}
|
|
|
|
|
2016-08-13 13:36:04 +00:00
|
|
|
bool operator==(const v128& right) const
|
2014-09-06 16:30:13 +00:00
|
|
|
{
|
2015-09-14 16:32:35 +00:00
|
|
|
return _u64[0] == right._u64[0] && _u64[1] == right._u64[1];
|
2014-09-06 16:30:13 +00:00
|
|
|
}
|
|
|
|
|
2016-08-13 13:36:04 +00:00
|
|
|
bool operator!=(const v128& right) const
|
2014-09-06 16:30:13 +00:00
|
|
|
{
|
2015-09-14 16:32:35 +00:00
|
|
|
return _u64[0] != right._u64[0] || _u64[1] != right._u64[1];
|
2014-09-06 16:30:13 +00:00
|
|
|
}
|
|
|
|
|
2014-10-07 21:37:04 +00:00
|
|
|
// result = (~left) & (right)
|
2015-09-14 16:32:35 +00:00
|
|
|
static inline v128 andnot(const v128& left, const v128& right)
|
2014-10-07 21:37:04 +00:00
|
|
|
{
|
|
|
|
return fromV(_mm_andnot_si128(left.vi, right.vi));
|
|
|
|
}
|
|
|
|
|
2014-09-06 16:30:13 +00:00
|
|
|
void clear()
|
|
|
|
{
|
2015-09-14 16:32:35 +00:00
|
|
|
_u64[0] = 0;
|
|
|
|
_u64[1] = 0;
|
2014-09-06 16:30:13 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-04-19 11:31:56 +00:00
|
|
|
template <typename T, std::size_t N, std::size_t M>
|
|
|
|
struct offset32_array<v128::masked_array_t<T, N, M>>
|
|
|
|
{
|
|
|
|
template <typename Arg>
|
|
|
|
static inline u32 index32(const Arg& arg)
|
|
|
|
{
|
2018-09-03 15:46:14 +00:00
|
|
|
return u32{sizeof(T)} * (static_cast<u32>(arg) ^ static_cast<u32>(M));
|
2017-04-19 11:31:56 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-08-13 13:36:04 +00:00
|
|
|
inline v128 operator|(const v128& left, const v128& right)
|
2015-06-24 11:53:47 +00:00
|
|
|
{
|
2015-08-06 13:31:13 +00:00
|
|
|
return v128::fromV(_mm_or_si128(left.vi, right.vi));
|
2015-06-24 11:53:47 +00:00
|
|
|
}
|
|
|
|
|
2016-08-13 13:36:04 +00:00
|
|
|
inline v128 operator&(const v128& left, const v128& right)
|
2015-06-24 11:53:47 +00:00
|
|
|
{
|
2015-08-06 13:31:13 +00:00
|
|
|
return v128::fromV(_mm_and_si128(left.vi, right.vi));
|
2015-06-24 11:53:47 +00:00
|
|
|
}
|
|
|
|
|
2016-08-13 13:36:04 +00:00
|
|
|
inline v128 operator^(const v128& left, const v128& right)
|
2015-06-24 11:53:47 +00:00
|
|
|
{
|
2015-08-06 13:31:13 +00:00
|
|
|
return v128::fromV(_mm_xor_si128(left.vi, right.vi));
|
2015-06-24 11:53:47 +00:00
|
|
|
}
|
|
|
|
|
2016-08-13 13:36:04 +00:00
|
|
|
inline v128 operator~(const v128& other)
|
2015-06-24 11:53:47 +00:00
|
|
|
{
|
2015-08-06 13:31:13 +00:00
|
|
|
return v128::from64(~other._u64[0], ~other._u64[1]);
|
2015-06-24 11:53:47 +00:00
|
|
|
}
|
|
|
|
|
2019-09-26 18:57:03 +00:00
|
|
|
using stx::se_t;
|
|
|
|
using stx::se_storage;
|
2015-06-24 11:53:47 +00:00
|
|
|
|
2016-08-13 13:36:04 +00:00
|
|
|
// se_t<> with native endianness
|
|
|
|
template <typename T, std::size_t Align = alignof(T)>
|
|
|
|
using nse_t = se_t<T, false, Align>;
|
2015-09-17 22:41:14 +00:00
|
|
|
|
2016-08-13 13:36:04 +00:00
|
|
|
template <typename T, std::size_t Align = alignof(T)>
|
2020-02-17 17:55:20 +00:00
|
|
|
using be_t = se_t<T, std::endian::little == std::endian::native, Align>;
|
2016-08-13 13:36:04 +00:00
|
|
|
template <typename T, std::size_t Align = alignof(T)>
|
2020-02-17 17:55:20 +00:00
|
|
|
using le_t = se_t<T, std::endian::big == std::endian::native, Align>;
|
2015-09-14 16:32:35 +00:00
|
|
|
|
2016-02-01 21:55:43 +00:00
|
|
|
// Type converter: converts native endianness arithmetic/enum types to appropriate se_t<> type
|
2016-08-13 13:36:04 +00:00
|
|
|
template <typename T, bool Se, typename = void>
|
2016-02-01 21:55:43 +00:00
|
|
|
struct to_se
|
2014-09-01 16:16:44 +00:00
|
|
|
{
|
2016-08-13 13:36:04 +00:00
|
|
|
template <typename T2, typename = void>
|
2016-05-26 15:06:06 +00:00
|
|
|
struct to_se_
|
|
|
|
{
|
|
|
|
using type = T2;
|
|
|
|
};
|
|
|
|
|
2016-08-13 13:36:04 +00:00
|
|
|
template <typename T2>
|
2016-05-26 15:06:06 +00:00
|
|
|
struct to_se_<T2, std::enable_if_t<std::is_arithmetic<T2>::value || std::is_enum<T2>::value>>
|
|
|
|
{
|
2019-09-27 19:04:48 +00:00
|
|
|
using type = std::conditional_t<(sizeof(T2) > 1), se_t<T2, Se>, T2>;
|
2016-05-26 15:06:06 +00:00
|
|
|
};
|
|
|
|
|
2016-02-01 21:55:43 +00:00
|
|
|
// Convert arithmetic and enum types
|
2016-05-26 15:06:06 +00:00
|
|
|
using type = typename to_se_<T>::type;
|
2015-01-28 12:59:16 +00:00
|
|
|
};
|
2014-09-01 16:16:44 +00:00
|
|
|
|
2016-08-13 13:36:04 +00:00
|
|
|
template <bool Se>
|
|
|
|
struct to_se<v128, Se>
|
|
|
|
{
|
|
|
|
using type = se_t<v128, Se>;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <bool Se>
|
|
|
|
struct to_se<u128, Se>
|
|
|
|
{
|
|
|
|
using type = se_t<u128, Se>;
|
|
|
|
};
|
2016-02-01 21:55:43 +00:00
|
|
|
|
2016-08-13 13:36:04 +00:00
|
|
|
template <bool Se>
|
|
|
|
struct to_se<s128, Se>
|
|
|
|
{
|
|
|
|
using type = se_t<s128, Se>;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T, bool Se>
|
|
|
|
struct to_se<const T, Se, std::enable_if_t<!std::is_array<T>::value>>
|
2015-06-15 17:00:08 +00:00
|
|
|
{
|
2016-02-01 21:55:43 +00:00
|
|
|
// Move const qualifier
|
2015-09-26 20:46:04 +00:00
|
|
|
using type = const typename to_se<T, Se>::type;
|
2015-06-15 17:00:08 +00:00
|
|
|
};
|
|
|
|
|
2016-08-13 13:36:04 +00:00
|
|
|
template <typename T, bool Se>
|
2016-02-01 21:55:43 +00:00
|
|
|
struct to_se<volatile T, Se, std::enable_if_t<!std::is_array<T>::value && !std::is_const<T>::value>>
|
2015-06-15 17:00:08 +00:00
|
|
|
{
|
2016-02-01 21:55:43 +00:00
|
|
|
// Move volatile qualifier
|
2015-09-26 20:46:04 +00:00
|
|
|
using type = volatile typename to_se<T, Se>::type;
|
2015-06-15 17:00:08 +00:00
|
|
|
};
|
|
|
|
|
2016-08-13 13:36:04 +00:00
|
|
|
template <typename T, bool Se>
|
2016-02-01 21:55:43 +00:00
|
|
|
struct to_se<T[], Se>
|
2015-01-28 12:59:16 +00:00
|
|
|
{
|
2016-02-01 21:55:43 +00:00
|
|
|
// Move array qualifier
|
2015-09-26 20:46:04 +00:00
|
|
|
using type = typename to_se<T, Se>::type[];
|
2015-01-28 12:59:16 +00:00
|
|
|
};
|
|
|
|
|
2016-08-13 13:36:04 +00:00
|
|
|
template <typename T, bool Se, std::size_t N>
|
2016-02-01 21:55:43 +00:00
|
|
|
struct to_se<T[N], Se>
|
2015-01-28 12:59:16 +00:00
|
|
|
{
|
2016-02-01 21:55:43 +00:00
|
|
|
// Move array qualifier
|
2015-09-26 20:46:04 +00:00
|
|
|
using type = typename to_se<T, Se>::type[N];
|
2014-09-01 16:16:44 +00:00
|
|
|
};
|
|
|
|
|
2016-02-01 21:55:43 +00:00
|
|
|
// BE/LE aliases for to_se<>
|
2016-08-13 13:36:04 +00:00
|
|
|
template <typename T>
|
2020-02-17 17:55:20 +00:00
|
|
|
using to_be_t = typename to_se<T, std::endian::little == std::endian::native>::type;
|
2016-08-13 13:36:04 +00:00
|
|
|
template <typename T>
|
2020-02-17 17:55:20 +00:00
|
|
|
using to_le_t = typename to_se<T, std::endian::big == std::endian::native>::type;
|
2015-06-14 21:52:22 +00:00
|
|
|
|
2016-02-01 21:55:43 +00:00
|
|
|
// BE/LE aliases for atomic_t
|
2016-08-13 13:36:04 +00:00
|
|
|
template <typename T>
|
|
|
|
using atomic_be_t = atomic_t<be_t<T>>;
|
|
|
|
template <typename T>
|
|
|
|
using atomic_le_t = atomic_t<le_t<T>>;
|
2015-06-15 17:00:08 +00:00
|
|
|
|
2016-08-13 13:36:04 +00:00
|
|
|
template <typename T, bool Se, std::size_t Align>
|
2016-08-03 20:51:05 +00:00
|
|
|
struct fmt_unveil<se_t<T, Se, Align>, void>
|
2015-06-13 01:31:45 +00:00
|
|
|
{
|
2016-08-03 20:51:05 +00:00
|
|
|
using type = typename fmt_unveil<T>::type;
|
|
|
|
|
2016-08-07 13:59:46 +00:00
|
|
|
static inline auto get(const se_t<T, Se, Align>& arg)
|
2016-02-01 21:55:43 +00:00
|
|
|
{
|
2016-08-03 20:51:05 +00:00
|
|
|
return fmt_unveil<T>::get(arg);
|
2016-04-25 10:49:12 +00:00
|
|
|
}
|
|
|
|
};
|