1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 18:53:28 +01:00
rpcs3/Utilities/BEType.h

925 lines
21 KiB
C
Raw Normal View History

#pragma once
2016-02-01 22:55:43 +01:00
#include "types.h"
#include "Platform.h"
2016-02-01 22:55:43 +01:00
union alignas(16) v128
{
2016-02-01 22:55:43 +01:00
char _bytes[16];
template<typename T, std::size_t N, std::size_t M>
struct masked_array_t // array type accessed as (index ^ M)
2014-10-07 15:35:44 +02:00
{
T m_data[N];
2014-10-07 15:35:44 +02:00
public:
T& operator [](std::size_t index)
{
return m_data[index ^ M];
}
2014-10-07 15:35:44 +02:00
const T& operator [](std::size_t index) const
{
return m_data[index ^ M];
}
};
2014-10-07 15:35:44 +02:00
2016-02-01 22:55:43 +01:00
#if IS_LE_MACHINE == 1
template<typename T, std::size_t N = 16 / sizeof(T)> using normal_array_t = masked_array_t<T, N, 0>;
template<typename T, std::size_t N = 16 / sizeof(T)> using reversed_array_t = masked_array_t<T, N, N - 1>;
#endif
2014-10-07 15:35:44 +02:00
normal_array_t<u64> _u64;
normal_array_t<s64> _s64;
reversed_array_t<u64> u64r;
reversed_array_t<s64> s64r;
2014-10-07 15:35:44 +02:00
normal_array_t<u32> _u32;
normal_array_t<s32> _s32;
reversed_array_t<u32> u32r;
reversed_array_t<s32> s32r;
2014-10-07 15:35:44 +02:00
normal_array_t<u16> _u16;
normal_array_t<s16> _s16;
reversed_array_t<u16> u16r;
reversed_array_t<s16> s16r;
2014-10-07 15:35:44 +02:00
normal_array_t<u8> _u8;
normal_array_t<s8> _s8;
reversed_array_t<u8> u8r;
reversed_array_t<s8> s8r;
2014-10-07 15:35:44 +02:00
normal_array_t<f32> _f;
normal_array_t<f64> _d;
reversed_array_t<f32> fr;
reversed_array_t<f64> dr;
2014-10-07 15:35:44 +02:00
2014-10-07 23:37:04 +02:00
__m128 vf;
__m128i vi;
2015-03-21 15:29:33 +01:00
__m128d vd;
2016-02-01 22:55:43 +01:00
struct bit_array_128
{
u64 m_data[2];
public:
class bit_element
{
u64& data;
const u64 mask;
public:
bit_element(u64& data, const u64 mask)
: data(data)
, mask(mask)
{
}
operator bool() const
{
return (data & mask) != 0;
}
bit_element& operator =(const bool right)
{
if (right)
{
data |= mask;
}
else
{
data &= ~mask;
}
return *this;
}
bit_element& operator =(const bit_element& right)
{
if (right)
{
data |= mask;
}
else
{
data &= ~mask;
}
return *this;
}
};
2015-02-04 16:29:34 +01:00
// Index 0 returns the MSB and index 127 returns the LSB
bit_element operator [](u32 index)
{
2016-02-01 22:55:43 +01:00
#if IS_LE_MACHINE == 1
return bit_element(m_data[1 - (index >> 6)], 0x8000000000000000ull >> (index & 0x3F));
2015-02-04 16:29:34 +01:00
#endif
}
2015-02-04 16:29:34 +01:00
// Index 0 returns the MSB and index 127 returns the LSB
bool operator [](u32 index) const
{
2016-02-01 22:55:43 +01:00
#if IS_LE_MACHINE == 1
return (m_data[1 - (index >> 6)] & (0x8000000000000000ull >> (index & 0x3F))) != 0;
2015-02-04 16:29:34 +01:00
#endif
}
}
_bit;
static v128 from64(u64 _0, u64 _1 = 0)
{
v128 ret;
2014-09-15 00:17:24 +02:00
ret._u64[0] = _0;
ret._u64[1] = _1;
return ret;
}
static v128 from64r(u64 _1, u64 _0 = 0)
2014-10-07 15:35:44 +02:00
{
return from64(_0, _1);
}
static v128 from32(u32 _0, u32 _1 = 0, u32 _2 = 0, u32 _3 = 0)
{
v128 ret;
2014-09-15 00:17:24 +02:00
ret._u32[0] = _0;
ret._u32[1] = _1;
ret._u32[2] = _2;
ret._u32[3] = _3;
return ret;
}
static v128 from32r(u32 _3, u32 _2 = 0, u32 _1 = 0, u32 _0 = 0)
2014-10-02 12:29:20 +02:00
{
2014-10-07 15:35:44 +02:00
return from32(_0, _1, _2, _3);
2014-10-02 12:29:20 +02:00
}
static v128 from32p(u32 value)
2014-10-02 12:29:20 +02:00
{
v128 ret;
2015-03-29 13:00:10 +02:00
ret.vi = _mm_set1_epi32(static_cast<s32>(value));
return ret;
}
static v128 from16p(u16 value)
2015-03-29 13:00:10 +02:00
{
v128 ret;
2015-03-29 13:00:10 +02:00
ret.vi = _mm_set1_epi16(static_cast<s16>(value));
2014-10-07 23:37:04 +02:00
return ret;
}
static v128 from8p(u8 value)
2014-10-07 23:37:04 +02:00
{
v128 ret;
2015-03-29 13:00:10 +02:00
ret.vi = _mm_set1_epi8(static_cast<s8>(value));
2014-10-02 12:29:20 +02:00
return ret;
}
static v128 fromBit(u32 bit)
{
v128 ret = {};
ret._bit[bit] = true;
return ret;
}
static v128 fromV(__m128i value)
2014-10-07 23:37:04 +02:00
{
v128 ret;
2014-10-07 23:37:04 +02:00
ret.vi = value;
return ret;
}
static v128 fromF(__m128 value)
2015-03-21 00:36:05 +01:00
{
v128 ret;
2015-03-21 00:36:05 +01:00
ret.vf = value;
return ret;
}
static v128 fromD(__m128d value)
2015-03-21 15:29:33 +01:00
{
v128 ret;
2015-03-21 15:29:33 +01:00
ret.vd = value;
return ret;
}
static inline v128 add8(const v128& left, const v128& right)
{
2014-10-07 23:37:04 +02:00
return fromV(_mm_add_epi8(left.vi, right.vi));
}
static inline v128 add16(const v128& left, const v128& right)
2015-03-21 00:36:05 +01:00
{
return fromV(_mm_add_epi16(left.vi, right.vi));
}
static inline v128 add32(const v128& left, const v128& right)
2015-03-21 00:36:05 +01:00
{
return fromV(_mm_add_epi32(left.vi, right.vi));
}
static inline v128 addfs(const v128& left, const v128& right)
2015-03-21 00:36:05 +01:00
{
return fromF(_mm_add_ps(left.vf, right.vf));
}
static inline v128 addfd(const v128& left, const v128& right)
2015-03-21 15:29:33 +01:00
{
return fromD(_mm_add_pd(left.vd, right.vd));
}
static inline v128 sub8(const v128& left, const v128& right)
2014-10-07 23:37:04 +02:00
{
return fromV(_mm_sub_epi8(left.vi, right.vi));
}
static inline v128 sub16(const v128& left, const v128& right)
2015-03-21 00:36:05 +01:00
{
return fromV(_mm_sub_epi16(left.vi, right.vi));
}
static inline v128 sub32(const v128& left, const v128& right)
2015-03-21 00:36:05 +01:00
{
return fromV(_mm_sub_epi32(left.vi, right.vi));
}
static inline v128 subfs(const v128& left, const v128& right)
2015-03-21 00:36:05 +01:00
{
return fromF(_mm_sub_ps(left.vf, right.vf));
}
static inline v128 subfd(const v128& left, const v128& right)
2015-03-21 15:29:33 +01:00
{
return fromD(_mm_sub_pd(left.vd, right.vd));
}
static inline v128 maxu8(const v128& left, const v128& right)
2015-03-21 00:36:05 +01:00
{
return fromV(_mm_max_epu8(left.vi, right.vi));
}
static inline v128 minu8(const v128& left, const v128& right)
2014-10-07 23:37:04 +02:00
{
return fromV(_mm_min_epu8(left.vi, right.vi));
}
static inline v128 eq8(const v128& left, const v128& right)
{
2014-10-07 23:37:04 +02:00
return fromV(_mm_cmpeq_epi8(left.vi, right.vi));
2015-03-29 13:00:10 +02:00
}
static inline v128 eq16(const v128& left, const v128& right)
2015-03-29 13:00:10 +02:00
{
return fromV(_mm_cmpeq_epi16(left.vi, right.vi));
}
static inline v128 eq32(const v128& left, const v128& right)
2015-03-29 13:00:10 +02:00
{
return fromV(_mm_cmpeq_epi32(left.vi, right.vi));
}
bool operator ==(const v128& right) const
{
return _u64[0] == right._u64[0] && _u64[1] == right._u64[1];
}
bool operator !=(const v128& right) const
{
return _u64[0] != right._u64[0] || _u64[1] != right._u64[1];
}
2014-10-07 23:37:04 +02:00
// result = (~left) & (right)
static inline v128 andnot(const v128& left, const v128& right)
2014-10-07 23:37:04 +02:00
{
return fromV(_mm_andnot_si128(left.vi, right.vi));
}
void clear()
{
_u64[0] = 0;
_u64[1] = 0;
}
std::string to_hex() const;
std::string to_xyzw() const;
};
inline v128 operator |(const v128& left, const v128& right)
{
return v128::fromV(_mm_or_si128(left.vi, right.vi));
}
inline v128 operator &(const v128& left, const v128& right)
{
return v128::fromV(_mm_and_si128(left.vi, right.vi));
}
inline v128 operator ^(const v128& left, const v128& right)
{
return v128::fromV(_mm_xor_si128(left.vi, right.vi));
}
inline v128 operator ~(const v128& other)
{
return v128::from64(~other._u64[0], ~other._u64[1]);
}
2016-02-01 22:55:43 +01:00
#define IS_INTEGER(t) (std::is_integral<t>::value || std::is_enum<t>::value)
#define IS_BINARY_COMPARABLE(t1, t2) (IS_INTEGER(t1) && IS_INTEGER(t2) && sizeof(t1) == sizeof(t2))
template<typename T, std::size_t Size = sizeof(T)>
struct se_storage
{
static_assert(!Size, "Bad se_storage<> type");
};
2016-02-01 22:55:43 +01:00
template<typename T>
struct se_storage<T, 2>
{
using type = u16;
2016-02-01 22:55:43 +01:00
static constexpr u16 swap(u16 src)
2015-11-26 09:13:33 +01:00
{
#if defined(__GNUG__)
return __builtin_bswap16(src);
#else
return _byteswap_ushort(src);
#endif
}
static inline u16 to(const T& src)
{
2015-11-26 09:13:33 +01:00
return swap(reinterpret_cast<const u16&>(src));
}
static inline T from(u16 src)
{
2015-11-26 09:13:33 +01:00
const u16 result = swap(src);
return reinterpret_cast<const T&>(result);
}
};
2016-02-01 22:55:43 +01:00
template<typename T>
struct se_storage<T, 4>
{
using type = u32;
2016-02-01 22:55:43 +01:00
static constexpr u32 swap(u32 src)
2015-11-26 09:13:33 +01:00
{
#if defined(__GNUG__)
return __builtin_bswap32(src);
#else
return _byteswap_ulong(src);
#endif
}
static inline u32 to(const T& src)
{
2015-11-26 09:13:33 +01:00
return swap(reinterpret_cast<const u32&>(src));
}
static inline T from(u32 src)
{
2015-11-26 09:13:33 +01:00
const u32 result = swap(src);
return reinterpret_cast<const T&>(result);
}
};
2016-02-01 22:55:43 +01:00
template<typename T>
struct se_storage<T, 8>
{
using type = u64;
2016-02-01 22:55:43 +01:00
static constexpr u64 swap(u64 src)
2015-11-26 09:13:33 +01:00
{
#if defined(__GNUG__)
return __builtin_bswap64(src);
#else
return _byteswap_uint64(src);
#endif
}
static inline u64 to(const T& src)
{
2015-11-26 09:13:33 +01:00
return swap(reinterpret_cast<const u64&>(src));
}
static inline T from(u64 src)
{
2015-11-26 09:13:33 +01:00
const u64 result = swap(src);
return reinterpret_cast<const T&>(result);
}
};
2016-02-01 22:55:43 +01:00
template<typename T>
struct se_storage<T, 16>
{
using type = v128;
2016-02-01 22:55:43 +01:00
static inline v128 swap(const v128& src)
{
return v128::fromV(_mm_shuffle_epi8(src.vi, _mm_set_epi8(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)));
}
static inline v128 to(const T& src)
{
2016-02-01 22:55:43 +01:00
return swap(reinterpret_cast<const v128&>(src));
}
static inline T from(const v128& src)
{
2016-02-01 22:55:43 +01:00
const v128 result = swap(src);
return reinterpret_cast<const T&>(result);
}
};
template<typename T> using se_storage_t = typename se_storage<T>::type;
2016-02-01 22:55:43 +01:00
template<typename T1, typename T2>
struct se_convert
{
using type_from = std::remove_cv_t<T1>;
using type_to = std::remove_cv_t<T2>;
using stype_from = se_storage_t<std::remove_cv_t<T1>>;
using stype_to = se_storage_t<std::remove_cv_t<T2>>;
using storage_from = se_storage<std::remove_cv_t<T1>>;
using storage_to = se_storage<std::remove_cv_t<T2>>;
static inline std::enable_if_t<std::is_same<type_from, type_to>::value, stype_to> convert(const stype_from& data)
{
return data;
}
static inline stype_to convert(const stype_from& data, ...)
{
return storage_to::to(storage_from::from(data));
}
};
static struct se_raw_tag_t {} constexpr se_raw{};
2015-09-15 18:23:17 +02:00
2016-02-01 22:55:43 +01:00
template<typename T, bool Se = true>
class se_t;
2016-02-01 22:55:43 +01:00
// Switched endianness
template<typename T>
class se_t<T, true>
{
using type = typename std::remove_cv<T>::type;
2015-09-15 18:23:17 +02:00
using stype = se_storage_t<type>;
using storage = se_storage<type>;
stype m_data;
static_assert(!std::is_pointer<type>::value, "se_t<> error: invalid type (pointer)");
static_assert(!std::is_reference<type>::value, "se_t<> error: invalid type (reference)");
static_assert(!std::is_array<type>::value, "se_t<> error: invalid type (array)");
2016-02-01 22:55:43 +01:00
static_assert(sizeof(type) == alignof(type), "se_t<> error: unexpected alignment");
2016-02-01 22:55:43 +01:00
template<typename T2, typename = void>
struct bool_converter
{
static inline bool to_bool(const se_t<T2>& value)
{
return static_cast<bool>(value.value());
}
};
2016-02-01 22:55:43 +01:00
template<typename T2>
struct bool_converter<T2, std::enable_if_t<std::is_integral<T2>::value>>
{
static inline bool to_bool(const se_t<T2>& value)
{
return value.m_data != 0;
}
};
public:
se_t() = default;
2015-09-15 18:23:17 +02:00
se_t(const se_t& right) = default;
se_t(type value)
: m_data(storage::to(value))
{
}
2016-02-01 22:55:43 +01:00
// Construct directly from raw data (don't use)
constexpr se_t(const stype& raw_value, const se_raw_tag_t&)
2015-09-15 18:23:17 +02:00
: m_data(raw_value)
{
}
type value() const
{
return storage::from(m_data);
}
2016-02-01 22:55:43 +01:00
// Access underlying raw data (don't use)
constexpr const stype& raw_data() const noexcept
{
return m_data;
}
se_t& operator =(const se_t&) = default;
se_t& operator =(type value)
{
return m_data = storage::to(value), *this;
}
2016-02-01 22:55:43 +01:00
using simple_type = simple_t<T>;
operator type() const
{
return storage::from(m_data);
}
2015-09-15 18:23:17 +02:00
2016-02-01 22:55:43 +01:00
// Optimization
explicit operator bool() const
2015-09-15 18:23:17 +02:00
{
return bool_converter<type>::to_bool(*this);
2015-09-15 18:23:17 +02:00
}
2016-02-01 22:55:43 +01:00
// Optimization
template<typename T2>
std::enable_if_t<IS_BINARY_COMPARABLE(T, T2), se_t&> operator &=(const se_t<T2>& right)
2015-09-15 18:23:17 +02:00
{
return m_data &= right.raw_data(), *this;
}
2016-02-01 22:55:43 +01:00
// Optimization
template<typename CT>
std::enable_if_t<std::is_integral<T>::value && std::is_convertible<CT, T>::value, se_t&> operator &=(CT right)
2015-09-15 18:23:17 +02:00
{
return m_data &= storage::to(right), *this;
}
2016-02-01 22:55:43 +01:00
// Optimization
template<typename T2>
std::enable_if_t<IS_BINARY_COMPARABLE(T, T2), se_t&> operator |=(const se_t<T2>& right)
2015-09-15 18:23:17 +02:00
{
return m_data |= right.raw_data(), *this;
}
2016-02-01 22:55:43 +01:00
// Optimization
template<typename CT>
std::enable_if_t<std::is_integral<T>::value && std::is_convertible<CT, T>::value, se_t&> operator |=(CT right)
2015-09-15 18:23:17 +02:00
{
return m_data |= storage::to(right), *this;
}
2016-02-01 22:55:43 +01:00
// Optimization
template<typename T2>
std::enable_if_t<IS_BINARY_COMPARABLE(T, T2), se_t&> operator ^=(const se_t<T2>& right)
2015-09-15 18:23:17 +02:00
{
return m_data ^= right.raw_data(), *this;
}
2016-02-01 22:55:43 +01:00
// Optimization
template<typename CT>
std::enable_if_t<std::is_integral<T>::value && std::is_convertible<CT, T>::value, se_t&> operator ^=(CT right)
2015-09-15 18:23:17 +02:00
{
return m_data ^= storage::to(right), *this;
}
};
2016-02-01 22:55:43 +01:00
// Native endianness
template<typename T>
class se_t<T, false>
{
using type = typename std::remove_cv<T>::type;
static_assert(!std::is_pointer<type>::value, "se_t<> error: invalid type (pointer)");
static_assert(!std::is_reference<type>::value, "se_t<> error: invalid type (reference)");
static_assert(!std::is_array<type>::value, "se_t<> error: invalid type (array)");
2016-02-01 22:55:43 +01:00
static_assert(sizeof(type) == alignof(type), "se_t<> error: unexpected alignment");
type m_data;
public:
se_t() = default;
constexpr se_t(type value)
: m_data(value)
{
}
2016-02-01 22:55:43 +01:00
// Construct directly from raw data (don't use)
constexpr se_t(const type& raw_value, const se_raw_tag_t&)
: m_data(raw_value)
{
}
constexpr type value() const
{
return m_data;
}
// Access underlying raw data (don't use)
constexpr const type& raw_data() const noexcept
{
return m_data;
}
se_t& operator =(const se_t& value) = default;
se_t& operator =(type value)
{
return m_data = value, *this;
}
2016-02-01 22:55:43 +01:00
using simple_type = simple_t<T>;
constexpr operator type() const
{
return m_data;
}
2016-02-01 22:55:43 +01:00
template<typename CT>
std::enable_if_t<std::is_integral<T>::value && std::is_convertible<CT, T>::value, se_t&> operator &=(const CT& right)
2015-09-15 18:23:17 +02:00
{
return m_data &= right, *this;
}
2016-02-01 22:55:43 +01:00
template<typename CT>
std::enable_if_t<std::is_integral<T>::value && std::is_convertible<CT, T>::value, se_t&> operator |=(const CT& right)
2015-09-15 18:23:17 +02:00
{
return m_data |= right, *this;
}
2016-02-01 22:55:43 +01:00
template<typename CT>
std::enable_if_t<std::is_integral<T>::value && std::is_convertible<CT, T>::value, se_t&> operator ^=(const CT& right)
2015-09-15 18:23:17 +02:00
{
return m_data ^= right, *this;
}
};
// se_t with native endianness (alias)
template<typename T> using nse_t = se_t<T, false>;
2016-02-01 22:55:43 +01:00
template<typename T, bool Se, typename T1>
inline se_t<T, Se>& operator +=(se_t<T, Se>& left, const T1& right)
{
auto value = left.value();
return left = (value += right);
}
2016-02-01 22:55:43 +01:00
template<typename T, bool Se, typename T1>
inline se_t<T, Se>& operator -=(se_t<T, Se>& left, const T1& right)
{
auto value = left.value();
return left = (value -= right);
}
2016-02-01 22:55:43 +01:00
template<typename T, bool Se, typename T1>
inline se_t<T, Se>& operator *=(se_t<T, Se>& left, const T1& right)
{
auto value = left.value();
return left = (value *= right);
}
2016-02-01 22:55:43 +01:00
template<typename T, bool Se, typename T1>
inline se_t<T, Se>& operator /=(se_t<T, Se>& left, const T1& right)
{
auto value = left.value();
return left = (value /= right);
}
2016-02-01 22:55:43 +01:00
template<typename T, bool Se, typename T1>
inline se_t<T, Se>& operator %=(se_t<T, Se>& left, const T1& right)
{
auto value = left.value();
return left = (value %= right);
}
2016-02-01 22:55:43 +01:00
template<typename T, bool Se, typename T1>
inline se_t<T, Se>& operator <<=(se_t<T, Se>& left, const T1& right)
{
auto value = left.value();
return left = (value <<= right);
}
2016-02-01 22:55:43 +01:00
template<typename T, bool Se, typename T1>
inline se_t<T, Se>& operator >>=(se_t<T, Se>& left, const T1& right)
{
auto value = left.value();
return left = (value >>= right);
}
2016-02-01 22:55:43 +01:00
template<typename T, bool Se>
inline se_t<T, Se> operator ++(se_t<T, Se>& left, int)
{
auto value = left.value();
auto result = value++;
left = value;
return result;
}
2016-02-01 22:55:43 +01:00
template<typename T, bool Se>
inline se_t<T, Se> operator --(se_t<T, Se>& left, int)
{
auto value = left.value();
auto result = value--;
left = value;
return result;
}
2016-02-01 22:55:43 +01:00
template<typename T, bool Se>
inline se_t<T, Se>& operator ++(se_t<T, Se>& right)
{
auto value = right.value();
return right = ++value;
}
2016-02-01 22:55:43 +01:00
template<typename T, bool Se>
inline se_t<T, Se>& operator --(se_t<T, Se>& right)
{
auto value = right.value();
return right = --value;
}
2016-02-01 22:55:43 +01:00
// Optimization
template<typename T1, typename T2>
inline std::enable_if_t<IS_BINARY_COMPARABLE(T1, T2), bool> operator ==(const se_t<T1>& left, const se_t<T2>& right)
2015-09-15 18:23:17 +02:00
{
return left.raw_data() == right.raw_data();
}
2016-02-01 22:55:43 +01:00
// Optimization
template<typename T1, typename T2>
inline std::enable_if_t<std::is_integral<T1>::value && IS_INTEGER(T2) && sizeof(T1) >= sizeof(T2), bool> operator ==(const se_t<T1>& left, T2 right)
2015-09-15 18:23:17 +02:00
{
return left.raw_data() == se_storage<T1>::to(right);
2015-09-15 18:23:17 +02:00
}
2016-02-01 22:55:43 +01:00
// Optimization
template<typename T1, typename T2>
inline std::enable_if_t<IS_INTEGER(T1) && std::is_integral<T2>::value && sizeof(T1) <= sizeof(T2), bool> operator ==(T1 left, const se_t<T2>& right)
2015-09-15 18:23:17 +02:00
{
return se_storage<T2>::to(left) == right.raw_data();
2015-09-15 18:23:17 +02:00
}
2016-02-01 22:55:43 +01:00
// Optimization
template<typename T1, typename T2>
inline std::enable_if_t<IS_BINARY_COMPARABLE(T1, T2), bool> operator !=(const se_t<T1>& left, const se_t<T2>& right)
2015-09-15 18:23:17 +02:00
{
return left.raw_data() != right.raw_data();
}
2016-02-01 22:55:43 +01:00
// Optimization
template<typename T1, typename T2>
inline std::enable_if_t<std::is_integral<T1>::value && IS_INTEGER(T2) && sizeof(T1) >= sizeof(T2), bool> operator !=(const se_t<T1>& left, T2 right)
2015-09-15 18:23:17 +02:00
{
return left.raw_data() != se_storage<T1>::to(right);
2015-09-15 18:23:17 +02:00
}
2016-02-01 22:55:43 +01:00
// Optimization
template<typename T1, typename T2>
inline std::enable_if_t<IS_INTEGER(T1) && std::is_integral<T2>::value && sizeof(T1) <= sizeof(T2), bool> operator !=(T1 left, const se_t<T2>& right)
2015-09-15 18:23:17 +02:00
{
return se_storage<T2>::to(left) != right.raw_data();
2015-09-15 18:23:17 +02:00
}
2016-02-01 22:55:43 +01:00
// Optimization
template<typename T1, typename T2>
inline std::enable_if_t<IS_BINARY_COMPARABLE(T1, T2) && sizeof(T1) >= 4, se_t<decltype(T1() & T2())>> operator &(const se_t<T1>& left, const se_t<T2>& right)
2015-09-15 18:23:17 +02:00
{
return{ left.raw_data() & right.raw_data(), se_raw };
2015-09-15 18:23:17 +02:00
}
2016-02-01 22:55:43 +01:00
// Optimization
template<typename T1, typename T2>
inline std::enable_if_t<std::is_integral<T1>::value && IS_INTEGER(T2) && sizeof(T1) >= sizeof(T2) && sizeof(T1) >= 4, se_t<decltype(T1() & T2())>> operator &(const se_t<T1>& left, T2 right)
2015-09-15 18:23:17 +02:00
{
return{ left.raw_data() & se_storage<T1>::to(right), se_raw };
2015-09-15 18:23:17 +02:00
}
2016-02-01 22:55:43 +01:00
// Optimization
template<typename T1, typename T2>
inline std::enable_if_t<IS_INTEGER(T1) && std::is_integral<T2>::value && sizeof(T1) <= sizeof(T2) && sizeof(T2) >= 4, se_t<decltype(T1() & T2())>> operator &(T1 left, const se_t<T2>& right)
2015-09-15 18:23:17 +02:00
{
return{ se_storage<T2>::to(left) & right.raw_data(), se_raw };
2015-09-15 18:23:17 +02:00
}
2016-02-01 22:55:43 +01:00
// Optimization
template<typename T1, typename T2>
inline std::enable_if_t<IS_BINARY_COMPARABLE(T1, T2) && sizeof(T1) >= 4, se_t<decltype(T1() | T2())>> operator |(const se_t<T1>& left, const se_t<T2>& right)
2015-09-15 18:23:17 +02:00
{
return{ left.raw_data() | right.raw_data(), se_raw };
2015-09-15 18:23:17 +02:00
}
2016-02-01 22:55:43 +01:00
// Optimization
template<typename T1, typename T2>
inline std::enable_if_t<std::is_integral<T1>::value && IS_INTEGER(T2) && sizeof(T1) >= sizeof(T2) && sizeof(T1) >= 4, se_t<decltype(T1() | T2())>> operator |(const se_t<T1>& left, T2 right)
2015-09-15 18:23:17 +02:00
{
return{ left.raw_data() | se_storage<T1>::to(right), se_raw };
2015-09-15 18:23:17 +02:00
}
2016-02-01 22:55:43 +01:00
// Optimization
template<typename T1, typename T2>
inline std::enable_if_t<IS_INTEGER(T1) && std::is_integral<T2>::value && sizeof(T1) <= sizeof(T2) && sizeof(T2) >= 4, se_t<decltype(T1() | T2())>> operator |(T1 left, const se_t<T2>& right)
2015-09-15 18:23:17 +02:00
{
return{ se_storage<T2>::to(left) | right.raw_data(), se_raw };
2015-09-15 18:23:17 +02:00
}
2016-02-01 22:55:43 +01:00
// Optimization
template<typename T1, typename T2>
inline std::enable_if_t<IS_BINARY_COMPARABLE(T1, T2) && sizeof(T1) >= 4, se_t<decltype(T1() ^ T2())>> operator ^(const se_t<T1>& left, const se_t<T2>& right)
2015-09-15 18:23:17 +02:00
{
return{ left.raw_data() ^ right.raw_data(), se_raw };
2015-09-15 18:23:17 +02:00
}
2016-02-01 22:55:43 +01:00
// Optimization
template<typename T1, typename T2>
inline std::enable_if_t<std::is_integral<T1>::value && IS_INTEGER(T2) && sizeof(T1) >= sizeof(T2) && sizeof(T1) >= 4, se_t<decltype(T1() ^ T2())>> operator ^(const se_t<T1>& left, T2 right)
2015-09-15 18:23:17 +02:00
{
return{ left.raw_data() ^ se_storage<T1>::to(right), se_raw };
2015-09-15 18:23:17 +02:00
}
2016-02-01 22:55:43 +01:00
// Optimization
template<typename T1, typename T2>
inline std::enable_if_t<IS_INTEGER(T1) && std::is_integral<T2>::value && sizeof(T1) <= sizeof(T2) && sizeof(T2) >= 4, se_t<decltype(T1() ^ T2())>> operator ^(T1 left, const se_t<T2>& right)
2015-09-15 18:23:17 +02:00
{
return{ se_storage<T2>::to(left) ^ right.raw_data(), se_raw };
2015-09-15 18:23:17 +02:00
}
2016-02-01 22:55:43 +01:00
// Optimization
template<typename T>
inline std::enable_if_t<std::is_integral<T>::value && sizeof(T) >= 4, se_t<decltype(~T())>> operator ~(const se_t<T>& right)
2015-09-15 18:23:17 +02:00
{
return{ ~right.raw_data(), se_raw };
2015-09-15 18:23:17 +02:00
}
2016-02-01 22:55:43 +01:00
#if IS_LE_MACHINE == 1
template<typename T> using be_t = se_t<T, true>;
template<typename T> using le_t = se_t<T, false>;
#endif
2016-02-01 22:55:43 +01:00
// Type converter: converts native endianness arithmetic/enum types to appropriate se_t<> type
template<typename T, bool Se, typename = void>
struct to_se
2014-09-01 18:16:44 +02:00
{
2016-02-01 22:55:43 +01:00
// Convert arithmetic and enum types
using type = typename std::conditional<std::is_arithmetic<T>::value || std::is_enum<T>::value, se_t<T, Se>, T>::type;
2015-01-28 13:59:16 +01:00
};
2014-09-01 18:16:44 +02:00
2016-02-01 22:55:43 +01:00
template<bool Se> struct to_se<v128, Se> { using type = se_t<v128, Se>; };
template<bool Se> struct to_se<bool, Se> { using type = bool; };
template<bool Se> struct to_se<char, Se> { using type = char; };
template<bool Se> struct to_se<u8, Se> { using type = u8; };
template<bool Se> struct to_se<s8, Se> { using type = s8; };
template<typename T, bool Se>
struct to_se<const T, Se, std::enable_if_t<!std::is_array<T>::value>>
2015-06-15 19:00:08 +02:00
{
2016-02-01 22:55:43 +01:00
// Move const qualifier
using type = const typename to_se<T, Se>::type;
2015-06-15 19:00:08 +02:00
};
2016-02-01 22:55:43 +01:00
template<typename T, bool Se>
struct to_se<volatile T, Se, std::enable_if_t<!std::is_array<T>::value && !std::is_const<T>::value>>
2015-06-15 19:00:08 +02:00
{
2016-02-01 22:55:43 +01:00
// Move volatile qualifier
using type = volatile typename to_se<T, Se>::type;
2015-06-15 19:00:08 +02:00
};
2016-02-01 22:55:43 +01:00
template<typename T, bool Se>
struct to_se<T[], Se>
2015-01-28 13:59:16 +01:00
{
2016-02-01 22:55:43 +01:00
// Move array qualifier
using type = typename to_se<T, Se>::type[];
2015-01-28 13:59:16 +01:00
};
2016-02-01 22:55:43 +01:00
template<typename T, bool Se, std::size_t N>
struct to_se<T[N], Se>
2015-01-28 13:59:16 +01:00
{
2016-02-01 22:55:43 +01:00
// Move array qualifier
using type = typename to_se<T, Se>::type[N];
2014-09-01 18:16:44 +02:00
};
2016-02-01 22:55:43 +01:00
// BE/LE aliases for to_se<>
#if IS_LE_MACHINE == 1
template<typename T> using to_be_t = typename to_se<T, true>::type;
template<typename T> using to_le_t = typename to_se<T, false>::type;
#endif
2016-02-01 22:55:43 +01:00
// BE/LE aliases for atomic_t
#if IS_LE_MACHINE == 1
template<typename T> using atomic_be_t = atomic_t<be_t<T>>;
template<typename T> using atomic_le_t = atomic_t<le_t<T>>;
#endif
2015-06-15 19:00:08 +02:00
// Formatting for BE/LE data
template<typename T, bool Se>
struct unveil<se_t<T, Se>, void>
{
static inline auto get(const se_t<T, Se>& arg)
2016-02-01 22:55:43 +01:00
{
return unveil<T>::get(arg);
}
};
2015-06-15 14:24:37 +02:00
2016-02-01 22:55:43 +01:00
#undef IS_BINARY_COMPARABLE
#undef IS_INTEGER