2013-10-06 14:07:42 +02:00
|
|
|
#pragma once
|
|
|
|
|
2015-02-04 16:29:34 +01:00
|
|
|
#define IS_LE_MACHINE
|
|
|
|
|
2014-10-18 22:27:54 +02:00
|
|
|
union _CRT_ALIGN(16) u128
|
2014-09-06 18:30:13 +02:00
|
|
|
{
|
|
|
|
u64 _u64[2];
|
|
|
|
s64 _s64[2];
|
2014-10-07 15:35:44 +02:00
|
|
|
|
|
|
|
class u64_reversed_array_2
|
|
|
|
{
|
|
|
|
u64 data[2];
|
|
|
|
|
|
|
|
public:
|
|
|
|
u64& operator [] (s32 index)
|
|
|
|
{
|
|
|
|
return data[1 - index];
|
|
|
|
}
|
|
|
|
|
|
|
|
const u64& operator [] (s32 index) const
|
|
|
|
{
|
|
|
|
return data[1 - index];
|
|
|
|
}
|
|
|
|
|
|
|
|
} u64r;
|
|
|
|
|
2014-09-06 18:30:13 +02:00
|
|
|
u32 _u32[4];
|
|
|
|
s32 _s32[4];
|
2014-10-07 15:35:44 +02:00
|
|
|
|
|
|
|
class u32_reversed_array_4
|
|
|
|
{
|
|
|
|
u32 data[4];
|
|
|
|
|
|
|
|
public:
|
|
|
|
u32& operator [] (s32 index)
|
|
|
|
{
|
|
|
|
return data[3 - index];
|
|
|
|
}
|
|
|
|
|
|
|
|
const u32& operator [] (s32 index) const
|
|
|
|
{
|
|
|
|
return data[3 - index];
|
|
|
|
}
|
|
|
|
|
|
|
|
} u32r;
|
|
|
|
|
2014-09-06 18:30:13 +02:00
|
|
|
u16 _u16[8];
|
|
|
|
s16 _s16[8];
|
2014-10-07 15:35:44 +02:00
|
|
|
|
|
|
|
class u16_reversed_array_8
|
|
|
|
{
|
|
|
|
u16 data[8];
|
|
|
|
|
|
|
|
public:
|
|
|
|
u16& operator [] (s32 index)
|
|
|
|
{
|
|
|
|
return data[7 - index];
|
|
|
|
}
|
|
|
|
|
|
|
|
const u16& operator [] (s32 index) const
|
|
|
|
{
|
|
|
|
return data[7 - index];
|
|
|
|
}
|
|
|
|
|
|
|
|
} u16r;
|
|
|
|
|
2014-09-06 18:30:13 +02:00
|
|
|
u8 _u8[16];
|
|
|
|
s8 _s8[16];
|
2014-10-07 15:35:44 +02:00
|
|
|
|
|
|
|
class u8_reversed_array_16
|
|
|
|
{
|
|
|
|
u8 data[16];
|
|
|
|
|
|
|
|
public:
|
|
|
|
u8& operator [] (s32 index)
|
|
|
|
{
|
|
|
|
return data[15 - index];
|
|
|
|
}
|
|
|
|
|
|
|
|
const u8& operator [] (s32 index) const
|
|
|
|
{
|
|
|
|
return data[15 - index];
|
|
|
|
}
|
|
|
|
|
|
|
|
} u8r;
|
|
|
|
|
2014-09-06 18:30:13 +02:00
|
|
|
float _f[4];
|
|
|
|
double _d[2];
|
2014-10-07 23:37:04 +02:00
|
|
|
__m128 vf;
|
|
|
|
__m128i vi;
|
2015-03-21 15:29:33 +01:00
|
|
|
__m128d vd;
|
2014-09-06 18:30:13 +02:00
|
|
|
|
|
|
|
class bit_array_128
|
|
|
|
{
|
|
|
|
u64 data[2];
|
|
|
|
|
|
|
|
public:
|
|
|
|
class bit_element
|
|
|
|
{
|
|
|
|
u64& data;
|
|
|
|
const u64 mask;
|
|
|
|
|
|
|
|
public:
|
|
|
|
bit_element(u64& data, const u64 mask)
|
|
|
|
: data(data)
|
|
|
|
, mask(mask)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
__forceinline operator bool() const
|
|
|
|
{
|
|
|
|
return (data & mask) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
__forceinline bit_element& operator = (const bool right)
|
|
|
|
{
|
|
|
|
if (right)
|
|
|
|
{
|
|
|
|
data |= mask;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
data &= ~mask;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
__forceinline 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
|
2014-09-06 18:30:13 +02:00
|
|
|
bit_element operator [] (u32 index)
|
|
|
|
{
|
|
|
|
assert(index < 128);
|
2015-02-04 16:29:34 +01:00
|
|
|
|
|
|
|
#ifdef IS_LE_MACHINE
|
|
|
|
return bit_element(data[1 - (index >> 6)], 0x8000000000000000ull >> (index & 0x3F));
|
|
|
|
#else
|
|
|
|
return bit_element(data[index >> 6], 0x8000000000000000ull >> (index & 0x3F));
|
|
|
|
#endif
|
2014-09-06 18:30:13 +02:00
|
|
|
}
|
|
|
|
|
2015-02-04 16:29:34 +01:00
|
|
|
// Index 0 returns the MSB and index 127 returns the LSB
|
2014-09-06 18:30:13 +02:00
|
|
|
const bool operator [] (u32 index) const
|
|
|
|
{
|
|
|
|
assert(index < 128);
|
2015-02-04 16:29:34 +01:00
|
|
|
|
|
|
|
#ifdef IS_LE_MACHINE
|
|
|
|
return (data[1 - (index >> 6)] & (0x8000000000000000ull >> (index & 0x3F))) != 0;
|
|
|
|
#else
|
|
|
|
return (data[index >> 6] & (0x8000000000000000ull >> (index & 0x3F))) != 0;
|
|
|
|
#endif
|
2014-09-06 18:30:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} _bit;
|
|
|
|
|
|
|
|
//operator u64() const { return _u64[0]; }
|
|
|
|
//operator u32() const { return _u32[0]; }
|
|
|
|
//operator u16() const { return _u16[0]; }
|
|
|
|
//operator u8() const { return _u8[0]; }
|
|
|
|
|
|
|
|
//operator bool() const { return _u64[0] != 0 || _u64[1] != 0; }
|
|
|
|
|
2014-09-15 00:17:24 +02:00
|
|
|
static u128 from64(u64 _0, u64 _1 = 0)
|
2014-09-06 18:30:13 +02:00
|
|
|
{
|
2014-09-15 00:17:24 +02:00
|
|
|
u128 ret;
|
|
|
|
ret._u64[0] = _0;
|
|
|
|
ret._u64[1] = _1;
|
2014-09-06 18:30:13 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-10-07 15:35:44 +02:00
|
|
|
static u128 from64r(u64 _1, u64 _0 = 0)
|
|
|
|
{
|
|
|
|
return from64(_0, _1);
|
|
|
|
}
|
|
|
|
|
2014-09-15 00:17:24 +02:00
|
|
|
static u128 from32(u32 _0, u32 _1 = 0, u32 _2 = 0, u32 _3 = 0)
|
2014-09-06 18:30:13 +02:00
|
|
|
{
|
|
|
|
u128 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;
|
2014-09-06 18:30:13 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-10-02 12:29:20 +02:00
|
|
|
static u128 from32r(u32 _3, u32 _2 = 0, u32 _1 = 0, u32 _0 = 0)
|
|
|
|
{
|
2014-10-07 15:35:44 +02:00
|
|
|
return from32(_0, _1, _2, _3);
|
2014-10-02 12:29:20 +02:00
|
|
|
}
|
|
|
|
|
2014-10-07 23:37:04 +02:00
|
|
|
static u128 from32p(u32 value)
|
2014-10-02 12:29:20 +02:00
|
|
|
{
|
|
|
|
u128 ret;
|
2015-03-29 13:00:10 +02:00
|
|
|
ret.vi = _mm_set1_epi32(static_cast<s32>(value));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u128 from16p(u16 value)
|
|
|
|
{
|
|
|
|
u128 ret;
|
|
|
|
ret.vi = _mm_set1_epi16(static_cast<s16>(value));
|
2014-10-07 23:37:04 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u128 from8p(u8 value)
|
|
|
|
{
|
|
|
|
u128 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;
|
|
|
|
}
|
|
|
|
|
2014-09-06 18:30:13 +02:00
|
|
|
static u128 fromBit(u32 bit)
|
|
|
|
{
|
2014-09-15 00:17:24 +02:00
|
|
|
u128 ret = {};
|
2014-09-06 18:30:13 +02:00
|
|
|
ret._bit[bit] = true;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-10-07 23:37:04 +02:00
|
|
|
static u128 fromV(__m128i value)
|
|
|
|
{
|
|
|
|
u128 ret;
|
|
|
|
ret.vi = value;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-03-21 00:36:05 +01:00
|
|
|
static u128 fromF(__m128 value)
|
|
|
|
{
|
|
|
|
u128 ret;
|
|
|
|
ret.vf = value;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-03-21 15:29:33 +01:00
|
|
|
static u128 fromD(__m128d value)
|
|
|
|
{
|
|
|
|
u128 ret;
|
|
|
|
ret.vd = value;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-10-07 23:37:04 +02:00
|
|
|
static __forceinline u128 add8(const u128& left, const u128& right)
|
2014-09-06 18:30:13 +02:00
|
|
|
{
|
2014-10-07 23:37:04 +02:00
|
|
|
return fromV(_mm_add_epi8(left.vi, right.vi));
|
|
|
|
}
|
|
|
|
|
2015-03-21 00:36:05 +01:00
|
|
|
static __forceinline u128 add16(const u128& left, const u128& right)
|
|
|
|
{
|
|
|
|
return fromV(_mm_add_epi16(left.vi, right.vi));
|
|
|
|
}
|
|
|
|
|
|
|
|
static __forceinline u128 add32(const u128& left, const u128& right)
|
|
|
|
{
|
|
|
|
return fromV(_mm_add_epi32(left.vi, right.vi));
|
|
|
|
}
|
|
|
|
|
|
|
|
static __forceinline u128 addfs(const u128& left, const u128& right)
|
|
|
|
{
|
|
|
|
return fromF(_mm_add_ps(left.vf, right.vf));
|
|
|
|
}
|
|
|
|
|
2015-03-21 15:29:33 +01:00
|
|
|
static __forceinline u128 addfd(const u128& left, const u128& right)
|
|
|
|
{
|
|
|
|
return fromD(_mm_add_pd(left.vd, right.vd));
|
|
|
|
}
|
|
|
|
|
2014-10-07 23:37:04 +02:00
|
|
|
static __forceinline u128 sub8(const u128& left, const u128& right)
|
|
|
|
{
|
|
|
|
return fromV(_mm_sub_epi8(left.vi, right.vi));
|
|
|
|
}
|
|
|
|
|
2015-03-21 00:36:05 +01:00
|
|
|
static __forceinline u128 sub16(const u128& left, const u128& right)
|
|
|
|
{
|
|
|
|
return fromV(_mm_sub_epi16(left.vi, right.vi));
|
|
|
|
}
|
|
|
|
|
|
|
|
static __forceinline u128 sub32(const u128& left, const u128& right)
|
|
|
|
{
|
|
|
|
return fromV(_mm_sub_epi32(left.vi, right.vi));
|
|
|
|
}
|
|
|
|
|
|
|
|
static __forceinline u128 subfs(const u128& left, const u128& right)
|
|
|
|
{
|
|
|
|
return fromF(_mm_sub_ps(left.vf, right.vf));
|
|
|
|
}
|
|
|
|
|
2015-03-21 15:29:33 +01:00
|
|
|
static __forceinline u128 subfd(const u128& left, const u128& right)
|
|
|
|
{
|
|
|
|
return fromD(_mm_sub_pd(left.vd, right.vd));
|
|
|
|
}
|
|
|
|
|
2015-03-21 00:36:05 +01:00
|
|
|
static __forceinline u128 maxu8(const u128& left, const u128& right)
|
|
|
|
{
|
|
|
|
return fromV(_mm_max_epu8(left.vi, right.vi));
|
|
|
|
}
|
|
|
|
|
2014-10-07 23:37:04 +02:00
|
|
|
static __forceinline u128 minu8(const u128& left, const u128& right)
|
|
|
|
{
|
|
|
|
return fromV(_mm_min_epu8(left.vi, right.vi));
|
|
|
|
}
|
|
|
|
|
|
|
|
static __forceinline u128 eq8(const u128& left, const u128& right)
|
2014-09-06 18:30:13 +02:00
|
|
|
{
|
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 __forceinline u128 eq16(const u128& left, const u128& right)
|
|
|
|
{
|
|
|
|
return fromV(_mm_cmpeq_epi16(left.vi, right.vi));
|
|
|
|
}
|
|
|
|
|
|
|
|
static __forceinline u128 eq32(const u128& left, const u128& right)
|
|
|
|
{
|
|
|
|
return fromV(_mm_cmpeq_epi32(left.vi, right.vi));
|
2014-09-06 18:30:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool operator == (const u128& right) const
|
|
|
|
{
|
2014-09-15 00:17:24 +02:00
|
|
|
return (_u64[0] == right._u64[0]) && (_u64[1] == right._u64[1]);
|
2014-09-06 18:30:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool operator != (const u128& right) const
|
|
|
|
{
|
2014-09-15 00:17:24 +02:00
|
|
|
return (_u64[0] != right._u64[0]) || (_u64[1] != right._u64[1]);
|
2014-09-06 18:30:13 +02:00
|
|
|
}
|
|
|
|
|
2014-10-07 23:37:04 +02:00
|
|
|
__forceinline u128 operator | (const u128& right) const
|
2014-09-06 18:30:13 +02:00
|
|
|
{
|
2014-10-07 23:37:04 +02:00
|
|
|
return fromV(_mm_or_si128(vi, right.vi));
|
2014-09-06 18:30:13 +02:00
|
|
|
}
|
|
|
|
|
2014-10-07 23:37:04 +02:00
|
|
|
__forceinline u128 operator & (const u128& right) const
|
2014-09-06 18:30:13 +02:00
|
|
|
{
|
2014-10-07 23:37:04 +02:00
|
|
|
return fromV(_mm_and_si128(vi, right.vi));
|
2014-09-06 18:30:13 +02:00
|
|
|
}
|
|
|
|
|
2014-10-07 23:37:04 +02:00
|
|
|
__forceinline u128 operator ^ (const u128& right) const
|
2014-09-06 18:30:13 +02:00
|
|
|
{
|
2014-10-07 23:37:04 +02:00
|
|
|
return fromV(_mm_xor_si128(vi, right.vi));
|
2014-09-06 18:30:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
u128 operator ~ () const
|
|
|
|
{
|
2014-09-15 00:17:24 +02:00
|
|
|
return from64(~_u64[0], ~_u64[1]);
|
2014-09-06 18:30:13 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 18:56:57 +02:00
|
|
|
__forceinline bool is_any_1() const // check if any bit is 1
|
2015-04-01 16:01:04 +02:00
|
|
|
{
|
|
|
|
return _u64[0] || _u64[1];
|
|
|
|
}
|
|
|
|
|
2015-04-03 18:56:57 +02:00
|
|
|
__forceinline bool is_any_0() const // check if any bit is 0
|
2015-04-01 16:01:04 +02:00
|
|
|
{
|
|
|
|
return ~_u64[0] || ~_u64[1];
|
|
|
|
}
|
|
|
|
|
2014-10-07 23:37:04 +02:00
|
|
|
// result = (~left) & (right)
|
|
|
|
static __forceinline u128 andnot(const u128& left, const u128& right)
|
|
|
|
{
|
|
|
|
return fromV(_mm_andnot_si128(left.vi, right.vi));
|
|
|
|
}
|
|
|
|
|
2014-09-06 18:30:13 +02:00
|
|
|
void clear()
|
|
|
|
{
|
2014-09-15 00:17:24 +02:00
|
|
|
_u64[1] = _u64[0] = 0;
|
2014-09-06 18:30:13 +02:00
|
|
|
}
|
|
|
|
|
2015-01-12 19:12:06 +01:00
|
|
|
std::string to_hex() const;
|
2014-09-06 18:30:13 +02:00
|
|
|
|
2015-01-12 19:12:06 +01:00
|
|
|
std::string to_xyzw() const;
|
2014-09-06 18:30:13 +02:00
|
|
|
|
|
|
|
static __forceinline u128 byteswap(const u128 val)
|
|
|
|
{
|
|
|
|
u128 ret;
|
2014-09-15 00:17:24 +02:00
|
|
|
ret._u64[0] = _byteswap_uint64(val._u64[1]);
|
|
|
|
ret._u64[1] = _byteswap_uint64(val._u64[0]);
|
2014-09-06 18:30:13 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-05-27 11:51:25 +02:00
|
|
|
static __forceinline u128 sync_val_compare_and_swap(volatile u128* dest, u128 comp, u128 exch)
|
2014-10-10 20:19:14 +02:00
|
|
|
{
|
2015-05-27 05:11:59 +02:00
|
|
|
#if !defined(_MSC_VER)
|
2014-10-10 20:19:14 +02:00
|
|
|
auto res = __sync_val_compare_and_swap((volatile __int128_t*)dest, (__int128_t&)comp, (__int128_t&)exch);
|
|
|
|
return (u128&)res;
|
|
|
|
#else
|
2014-10-10 20:41:57 +02:00
|
|
|
_InterlockedCompareExchange128((volatile long long*)dest, exch._u64[1], exch._u64[0], (long long*)&comp);
|
|
|
|
return comp;
|
2014-10-10 20:19:14 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-05-27 11:51:25 +02:00
|
|
|
static __forceinline bool sync_bool_compare_and_swap(volatile u128* dest, u128 comp, u128 exch)
|
2014-10-10 20:19:14 +02:00
|
|
|
{
|
2015-05-27 05:11:59 +02:00
|
|
|
#if !defined(_MSC_VER)
|
2014-10-10 20:19:14 +02:00
|
|
|
return __sync_bool_compare_and_swap((volatile __int128_t*)dest, (__int128_t&)comp, (__int128_t&)exch);
|
|
|
|
#else
|
|
|
|
return _InterlockedCompareExchange128((volatile long long*)dest, exch._u64[1], exch._u64[0], (long long*)&comp) != 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-05-27 11:51:25 +02:00
|
|
|
static __forceinline u128 sync_lock_test_and_set(volatile u128* dest, u128 value)
|
2014-10-10 20:41:57 +02:00
|
|
|
{
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
const u128 old = *(u128*)dest;
|
2015-05-27 11:51:25 +02:00
|
|
|
if (sync_bool_compare_and_swap(dest, old, value)) return old;
|
2014-10-10 20:41:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-27 11:51:25 +02:00
|
|
|
static __forceinline u128 sync_fetch_and_or(volatile u128* dest, u128 value)
|
2014-10-10 20:41:57 +02:00
|
|
|
{
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
const u128 old = *(u128*)dest;
|
2015-05-27 11:51:25 +02:00
|
|
|
if (sync_bool_compare_and_swap(dest, old, value | old)) return old;
|
2014-10-10 20:41:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-27 11:51:25 +02:00
|
|
|
static __forceinline u128 sync_fetch_and_and(volatile u128* dest, u128 value)
|
2014-10-10 20:41:57 +02:00
|
|
|
{
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
const u128 old = *(u128*)dest;
|
2015-05-27 11:51:25 +02:00
|
|
|
if (sync_bool_compare_and_swap(dest, old, value & old)) return old;
|
2014-10-10 20:41:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-27 11:51:25 +02:00
|
|
|
static __forceinline u128 sync_fetch_and_xor(volatile u128* dest, u128 value)
|
2014-10-10 20:41:57 +02:00
|
|
|
{
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
const u128 old = *(u128*)dest;
|
2015-05-27 11:51:25 +02:00
|
|
|
if (sync_bool_compare_and_swap(dest, old, value ^ old)) return old;
|
2014-10-10 20:41:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-22 23:15:02 +02:00
|
|
|
#define re16(val) _byteswap_ushort(val)
|
|
|
|
#define re32(val) _byteswap_ulong(val)
|
|
|
|
#define re64(val) _byteswap_uint64(val)
|
|
|
|
#define re128(val) u128::byteswap(val)
|
2014-05-02 08:30:32 +02:00
|
|
|
|
2013-11-19 22:10:23 +01:00
|
|
|
template<typename T, int size = sizeof(T)> struct se_t;
|
|
|
|
|
2014-09-04 11:21:23 +02:00
|
|
|
template<typename T> struct se_t<T, 1>
|
|
|
|
{
|
2015-01-11 10:33:05 +01:00
|
|
|
static __forceinline u8 to_be(const T& src)
|
2014-09-04 11:21:23 +02:00
|
|
|
{
|
2015-01-11 10:33:05 +01:00
|
|
|
return (u8&)src;
|
|
|
|
}
|
|
|
|
|
|
|
|
static __forceinline T from_be(const u8 src)
|
|
|
|
{
|
|
|
|
return (T&)src;
|
2014-09-04 11:21:23 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T> struct se_t<T, 2>
|
|
|
|
{
|
2015-01-11 10:33:05 +01:00
|
|
|
static __forceinline u16 to_be(const T& src)
|
2014-09-04 11:21:23 +02:00
|
|
|
{
|
2015-01-11 10:33:05 +01:00
|
|
|
return _byteswap_ushort((u16&)src);
|
|
|
|
}
|
|
|
|
|
|
|
|
static __forceinline T from_be(const u16 src)
|
|
|
|
{
|
|
|
|
const u16 res = _byteswap_ushort(src);
|
2014-09-04 11:21:23 +02:00
|
|
|
return (T&)res;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T> struct se_t<T, 4>
|
|
|
|
{
|
2015-01-11 10:33:05 +01:00
|
|
|
static __forceinline u32 to_be(const T& src)
|
|
|
|
{
|
|
|
|
return _byteswap_ulong((u32&)src);
|
|
|
|
}
|
|
|
|
|
|
|
|
static __forceinline T from_be(const u32 src)
|
2014-09-04 11:21:23 +02:00
|
|
|
{
|
2015-01-11 10:33:05 +01:00
|
|
|
const u32 res = _byteswap_ulong(src);
|
2014-09-04 11:21:23 +02:00
|
|
|
return (T&)res;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T> struct se_t<T, 8>
|
|
|
|
{
|
2015-01-11 10:33:05 +01:00
|
|
|
static __forceinline u64 to_be(const T& src)
|
2014-09-04 11:21:23 +02:00
|
|
|
{
|
2015-01-11 10:33:05 +01:00
|
|
|
return _byteswap_uint64((u64&)src);
|
|
|
|
}
|
|
|
|
|
|
|
|
static __forceinline T from_be(const u64 src)
|
|
|
|
{
|
|
|
|
const u64 res = _byteswap_uint64(src);
|
2014-09-04 11:21:23 +02:00
|
|
|
return (T&)res;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-01-11 10:33:05 +01:00
|
|
|
template<typename T> struct se_t<T, 16>
|
|
|
|
{
|
|
|
|
static __forceinline u128 to_be(const T& src)
|
|
|
|
{
|
|
|
|
return u128::byteswap((u128&)src);
|
|
|
|
}
|
|
|
|
|
|
|
|
static __forceinline T from_be(const u128& src)
|
|
|
|
{
|
|
|
|
const u128 res = u128::byteswap(src);
|
|
|
|
return (T&)res;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T, T _value, size_t size = sizeof(T)> struct const_se_t;
|
2014-02-22 03:53:06 +01:00
|
|
|
|
2015-01-11 10:33:05 +01:00
|
|
|
template<u8 _value> struct const_se_t<u8, _value, 1>
|
2013-11-19 22:10:23 +01:00
|
|
|
{
|
2015-01-11 10:33:05 +01:00
|
|
|
static const u8 value = _value;
|
2013-11-19 22:10:23 +01:00
|
|
|
};
|
|
|
|
|
2015-01-11 10:33:05 +01:00
|
|
|
template<u16 _value> struct const_se_t<u16, _value, 2>
|
2013-11-19 22:10:23 +01:00
|
|
|
{
|
2015-01-11 10:33:05 +01:00
|
|
|
static const u16 value = ((_value >> 8) & 0xff) | ((_value << 8) & 0xff00);
|
2013-11-19 22:10:23 +01:00
|
|
|
};
|
|
|
|
|
2015-01-11 10:33:05 +01:00
|
|
|
template<u32 _value> struct const_se_t<u32, _value, 4>
|
2013-11-19 22:10:23 +01:00
|
|
|
{
|
2015-01-11 10:33:05 +01:00
|
|
|
static const u32 value =
|
2013-11-19 22:10:23 +01:00
|
|
|
((_value >> 24) & 0x000000ff) |
|
|
|
|
((_value >> 8) & 0x0000ff00) |
|
|
|
|
((_value << 8) & 0x00ff0000) |
|
|
|
|
((_value << 24) & 0xff000000);
|
|
|
|
};
|
|
|
|
|
2015-01-11 10:33:05 +01:00
|
|
|
template<u64 _value> struct const_se_t<u64, _value, 8>
|
2013-11-19 22:10:23 +01:00
|
|
|
{
|
2015-01-11 10:33:05 +01:00
|
|
|
static const u64 value =
|
2013-11-19 22:10:23 +01:00
|
|
|
((_value >> 56) & 0x00000000000000ff) |
|
|
|
|
((_value >> 40) & 0x000000000000ff00) |
|
|
|
|
((_value >> 24) & 0x0000000000ff0000) |
|
|
|
|
((_value >> 8) & 0x00000000ff000000) |
|
|
|
|
((_value << 8) & 0x000000ff00000000) |
|
|
|
|
((_value << 24) & 0x0000ff0000000000) |
|
|
|
|
((_value << 40) & 0x00ff000000000000) |
|
|
|
|
((_value << 56) & 0xff00000000000000);
|
|
|
|
};
|
|
|
|
|
2015-01-11 10:33:05 +01:00
|
|
|
template<typename T, size_t size = sizeof(T)>
|
|
|
|
struct be_storage_t
|
|
|
|
{
|
|
|
|
static_assert(!size, "Bad be_storage_t type");
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct be_storage_t<T, 1>
|
|
|
|
{
|
|
|
|
typedef u8 type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct be_storage_t<T, 2>
|
|
|
|
{
|
|
|
|
typedef u16 type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct be_storage_t<T, 4>
|
|
|
|
{
|
|
|
|
typedef u32 type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct be_storage_t<T, 8>
|
|
|
|
{
|
|
|
|
typedef u64 type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct be_storage_t<T, 16>
|
|
|
|
{
|
|
|
|
typedef u128 type;
|
|
|
|
};
|
|
|
|
|
2014-09-01 18:16:44 +02:00
|
|
|
template<typename T, typename T2 = T>
|
2013-10-06 14:07:42 +02:00
|
|
|
class be_t
|
|
|
|
{
|
2014-11-19 15:16:30 +01:00
|
|
|
public:
|
|
|
|
typedef typename std::remove_cv<T>::type type;
|
2015-01-11 10:33:05 +01:00
|
|
|
typedef typename be_storage_t<T2>::type stype;
|
2014-11-19 15:16:30 +01:00
|
|
|
|
|
|
|
private:
|
2015-01-11 10:33:05 +01:00
|
|
|
stype m_data;
|
2013-10-06 14:07:42 +02:00
|
|
|
|
2014-09-16 14:52:04 +02:00
|
|
|
template<typename Tto, typename Tfrom, int mode>
|
|
|
|
struct _convert
|
|
|
|
{
|
|
|
|
static __forceinline be_t<Tto>& func(Tfrom& be_value)
|
|
|
|
{
|
|
|
|
Tto res = be_value;
|
|
|
|
return (be_t<Tto>&)res;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename Tto, typename Tfrom>
|
|
|
|
struct _convert<Tto, Tfrom, 1>
|
|
|
|
{
|
|
|
|
static __forceinline be_t<Tto>& func(Tfrom& be_value)
|
|
|
|
{
|
|
|
|
Tto res = se_t<Tto, sizeof(Tto)>::func(se_t<Tfrom, sizeof(Tfrom)>::func(be_value));
|
|
|
|
return (be_t<Tto>&)res;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename Tto, typename Tfrom>
|
|
|
|
struct _convert<Tto, Tfrom, 2>
|
|
|
|
{
|
|
|
|
static __forceinline be_t<Tto>& func(Tfrom& be_value)
|
|
|
|
{
|
|
|
|
Tto res = be_value >> ((sizeof(Tfrom)-sizeof(Tto)) * 8);
|
|
|
|
return (be_t<Tto>&)res;
|
|
|
|
}
|
|
|
|
};
|
2014-11-19 15:16:30 +01:00
|
|
|
|
2015-01-11 10:33:05 +01:00
|
|
|
const stype& ToBE() const
|
2013-10-06 14:07:42 +02:00
|
|
|
{
|
|
|
|
return m_data;
|
|
|
|
}
|
|
|
|
|
2014-11-19 15:16:30 +01:00
|
|
|
type ToLE() const
|
2013-10-06 14:07:42 +02:00
|
|
|
{
|
2015-01-11 10:33:05 +01:00
|
|
|
return se_t<type, sizeof(T2)>::from_be(m_data);
|
2013-10-06 14:07:42 +02:00
|
|
|
}
|
|
|
|
|
2015-01-11 10:33:05 +01:00
|
|
|
void FromBE(const stype& value)
|
2013-10-06 14:07:42 +02:00
|
|
|
{
|
|
|
|
m_data = value;
|
|
|
|
}
|
|
|
|
|
2014-11-19 15:16:30 +01:00
|
|
|
void FromLE(const type& value)
|
2013-10-06 14:07:42 +02:00
|
|
|
{
|
2015-01-11 10:33:05 +01:00
|
|
|
m_data = se_t<type, sizeof(T2)>::to_be(value);
|
2013-10-06 14:07:42 +02:00
|
|
|
}
|
|
|
|
|
2015-01-14 00:08:00 +01:00
|
|
|
public:
|
2015-01-11 10:33:05 +01:00
|
|
|
static be_t MakeFromLE(const type& value)
|
2014-02-22 03:53:06 +01:00
|
|
|
{
|
2015-01-11 10:33:05 +01:00
|
|
|
stype data = se_t<type, sizeof(T2)>::to_be(value);
|
2014-09-04 11:21:23 +02:00
|
|
|
return (be_t&)data;
|
2014-02-22 03:53:06 +01:00
|
|
|
}
|
|
|
|
|
2015-01-11 10:33:05 +01:00
|
|
|
static be_t MakeFromBE(const stype& value)
|
2013-10-06 14:07:42 +02:00
|
|
|
{
|
2014-11-19 15:16:30 +01:00
|
|
|
return (be_t&)value;
|
2013-10-06 14:07:42 +02:00
|
|
|
}
|
|
|
|
|
2014-11-19 15:16:30 +01:00
|
|
|
//make be_t from current machine byte ordering
|
2015-01-11 10:33:05 +01:00
|
|
|
static be_t make(const type& value)
|
2014-11-19 15:16:30 +01:00
|
|
|
{
|
2015-01-11 10:33:05 +01:00
|
|
|
#ifdef IS_LE_MACHINE
|
|
|
|
return MakeFromLE(value);
|
|
|
|
#else
|
|
|
|
return MakeFromBE(value);
|
|
|
|
#endif
|
2014-11-19 15:16:30 +01:00
|
|
|
}
|
2014-09-16 13:23:58 +02:00
|
|
|
|
2014-11-19 15:16:30 +01:00
|
|
|
//get value in current machine byte ordering
|
|
|
|
__forceinline type value() const
|
|
|
|
{
|
2015-01-11 10:33:05 +01:00
|
|
|
#ifdef IS_LE_MACHINE
|
|
|
|
return ToLE();
|
|
|
|
#else
|
|
|
|
return ToBE();
|
|
|
|
#endif
|
2014-11-19 15:16:30 +01:00
|
|
|
}
|
2015-01-12 19:12:06 +01:00
|
|
|
|
|
|
|
const stype& data() const
|
|
|
|
{
|
|
|
|
return ToBE();
|
|
|
|
}
|
2014-11-20 20:41:04 +01:00
|
|
|
|
2014-11-19 15:16:30 +01:00
|
|
|
be_t& operator = (const be_t& value) = default;
|
|
|
|
|
2015-01-11 10:33:05 +01:00
|
|
|
be_t& operator = (const type& value)
|
2014-11-19 15:16:30 +01:00
|
|
|
{
|
2015-01-11 10:33:05 +01:00
|
|
|
m_data = se_t<type, sizeof(T2)>::to_be(value);
|
2014-09-16 13:23:58 +02:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-11-19 15:16:30 +01:00
|
|
|
operator type() const
|
|
|
|
{
|
|
|
|
return value();
|
|
|
|
}
|
|
|
|
|
2013-10-06 14:07:42 +02:00
|
|
|
template<typename T1>
|
|
|
|
operator const be_t<T1>() const
|
|
|
|
{
|
2014-11-20 20:41:04 +01:00
|
|
|
return be_t<T1>::make(value());
|
|
|
|
//return _convert<T1, T, ((sizeof(T1) > sizeof(T)) ? 1 : (sizeof(T1) < sizeof(T) ? 2 : 0))>::func(m_data);
|
2014-09-05 19:54:06 +02:00
|
|
|
}
|
|
|
|
|
2013-10-06 14:07:42 +02:00
|
|
|
template<typename T1> be_t& operator += (T1 right) { return *this = T(*this) + right; }
|
|
|
|
template<typename T1> be_t& operator -= (T1 right) { return *this = T(*this) - right; }
|
|
|
|
template<typename T1> be_t& operator *= (T1 right) { return *this = T(*this) * right; }
|
|
|
|
template<typename T1> be_t& operator /= (T1 right) { return *this = T(*this) / right; }
|
|
|
|
template<typename T1> be_t& operator %= (T1 right) { return *this = T(*this) % right; }
|
|
|
|
template<typename T1> be_t& operator &= (T1 right) { return *this = T(*this) & right; }
|
|
|
|
template<typename T1> be_t& operator |= (T1 right) { return *this = T(*this) | right; }
|
|
|
|
template<typename T1> be_t& operator ^= (T1 right) { return *this = T(*this) ^ right; }
|
|
|
|
template<typename T1> be_t& operator <<= (T1 right) { return *this = T(*this) << right; }
|
|
|
|
template<typename T1> be_t& operator >>= (T1 right) { return *this = T(*this) >> right; }
|
|
|
|
|
|
|
|
template<typename T1> be_t& operator += (const be_t<T1>& right) { return *this = ToLE() + right.ToLE(); }
|
|
|
|
template<typename T1> be_t& operator -= (const be_t<T1>& right) { return *this = ToLE() - right.ToLE(); }
|
|
|
|
template<typename T1> be_t& operator *= (const be_t<T1>& right) { return *this = ToLE() * right.ToLE(); }
|
|
|
|
template<typename T1> be_t& operator /= (const be_t<T1>& right) { return *this = ToLE() / right.ToLE(); }
|
|
|
|
template<typename T1> be_t& operator %= (const be_t<T1>& right) { return *this = ToLE() % right.ToLE(); }
|
|
|
|
template<typename T1> be_t& operator &= (const be_t<T1>& right) { return *this = ToBE() & right.ToBE(); }
|
|
|
|
template<typename T1> be_t& operator |= (const be_t<T1>& right) { return *this = ToBE() | right.ToBE(); }
|
|
|
|
template<typename T1> be_t& operator ^= (const be_t<T1>& right) { return *this = ToBE() ^ right.ToBE(); }
|
|
|
|
|
|
|
|
template<typename T1> be_t operator & (const be_t<T1>& right) const { be_t<T> res; res.FromBE(ToBE() & right.ToBE()); return res; }
|
|
|
|
template<typename T1> be_t operator | (const be_t<T1>& right) const { be_t<T> res; res.FromBE(ToBE() | right.ToBE()); return res; }
|
|
|
|
template<typename T1> be_t operator ^ (const be_t<T1>& right) const { be_t<T> res; res.FromBE(ToBE() ^ right.ToBE()); return res; }
|
|
|
|
|
2013-11-16 01:38:22 +01:00
|
|
|
template<typename T1> bool operator == (T1 right) const { return (T1)ToLE() == right; }
|
2013-10-06 14:07:42 +02:00
|
|
|
template<typename T1> bool operator != (T1 right) const { return !(*this == right); }
|
2013-11-16 01:38:22 +01:00
|
|
|
template<typename T1> bool operator > (T1 right) const { return (T1)ToLE() > right; }
|
|
|
|
template<typename T1> bool operator < (T1 right) const { return (T1)ToLE() < right; }
|
|
|
|
template<typename T1> bool operator >= (T1 right) const { return (T1)ToLE() >= right; }
|
|
|
|
template<typename T1> bool operator <= (T1 right) const { return (T1)ToLE() <= right; }
|
2013-10-06 14:07:42 +02:00
|
|
|
|
|
|
|
template<typename T1> bool operator == (const be_t<T1>& right) const { return ToBE() == right.ToBE(); }
|
|
|
|
template<typename T1> bool operator != (const be_t<T1>& right) const { return !(*this == right); }
|
2013-11-16 01:38:22 +01:00
|
|
|
template<typename T1> bool operator > (const be_t<T1>& right) const { return (T1)ToLE() > right.ToLE(); }
|
|
|
|
template<typename T1> bool operator < (const be_t<T1>& right) const { return (T1)ToLE() < right.ToLE(); }
|
|
|
|
template<typename T1> bool operator >= (const be_t<T1>& right) const { return (T1)ToLE() >= right.ToLE(); }
|
|
|
|
template<typename T1> bool operator <= (const be_t<T1>& right) const { return (T1)ToLE() <= right.ToLE(); }
|
2014-02-22 03:53:06 +01:00
|
|
|
|
|
|
|
be_t operator++ (int) { be_t res = *this; *this += 1; return res; }
|
|
|
|
be_t operator-- (int) { be_t res = *this; *this -= 1; return res; }
|
|
|
|
be_t& operator++ () { *this += 1; return *this; }
|
|
|
|
be_t& operator-- () { *this -= 1; return *this; }
|
2013-11-19 22:10:23 +01:00
|
|
|
};
|
2014-02-22 03:53:06 +01:00
|
|
|
|
2014-09-01 18:16:44 +02:00
|
|
|
template<typename T, typename T2 = T>
|
|
|
|
struct is_be_t : public std::integral_constant<bool, false> {};
|
|
|
|
|
|
|
|
template<typename T, typename T2>
|
2014-09-01 23:22:07 +02:00
|
|
|
struct is_be_t<be_t<T, T2>, T2> : public std::integral_constant<bool, true> {};
|
2014-09-01 18:16:44 +02:00
|
|
|
|
2014-09-01 23:22:07 +02:00
|
|
|
template<typename T, typename T2 = T>
|
2014-09-01 18:16:44 +02:00
|
|
|
struct remove_be_t
|
|
|
|
{
|
|
|
|
typedef T type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T, typename T2>
|
|
|
|
struct remove_be_t<be_t<T, T2>>
|
|
|
|
{
|
|
|
|
typedef T type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T, typename T2 = T>
|
|
|
|
class to_be_t
|
|
|
|
{
|
2014-09-01 18:45:22 +02:00
|
|
|
template<typename TT, typename TT2, bool is_need_swap>
|
2014-09-01 18:16:44 +02:00
|
|
|
struct _be_type_selector
|
|
|
|
{
|
2014-09-01 19:38:55 +02:00
|
|
|
typedef TT type;
|
2014-09-01 18:16:44 +02:00
|
|
|
};
|
|
|
|
|
2014-09-01 18:45:22 +02:00
|
|
|
template<typename TT, typename TT2>
|
|
|
|
struct _be_type_selector<TT, TT2, true>
|
2014-09-01 18:16:44 +02:00
|
|
|
{
|
2014-09-01 19:38:55 +02:00
|
|
|
typedef be_t<TT, TT2> type;
|
2014-09-01 18:16:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
//true if need swap endianes for be
|
2015-01-28 13:59:16 +01:00
|
|
|
static const bool value = std::is_arithmetic<T>::value || std::is_enum<T>::value;
|
2014-09-01 18:16:44 +02:00
|
|
|
|
|
|
|
//be_t<T, size> if need swap endianes, T otherwise
|
|
|
|
typedef typename _be_type_selector< T, T2, value >::type type;
|
2014-11-20 20:41:04 +01:00
|
|
|
|
|
|
|
typedef typename _be_type_selector< T, T2, !is_be_t<T, T2>::value >::type forced_type;
|
2014-09-01 18:16:44 +02:00
|
|
|
};
|
|
|
|
|
2015-01-28 13:59:16 +01:00
|
|
|
template<typename T, typename T2>
|
|
|
|
class to_be_t<T, const T2>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static const bool value = to_be_t<T, T2>::value;
|
|
|
|
typedef const typename to_be_t<T, T2>::type type;
|
|
|
|
typedef const typename to_be_t<T, T2>::forced_type forced_type;
|
|
|
|
};
|
|
|
|
|
2014-09-01 18:16:44 +02:00
|
|
|
template<typename T>
|
|
|
|
class to_be_t<T, void>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static const bool value = false;
|
|
|
|
typedef void type;
|
2015-01-28 13:59:16 +01:00
|
|
|
typedef void forced_type;
|
2014-09-01 18:16:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
2015-01-28 13:59:16 +01:00
|
|
|
class to_be_t<T, u8>
|
2014-09-01 18:16:44 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static const bool value = false;
|
2015-01-28 13:59:16 +01:00
|
|
|
typedef u8 type;
|
|
|
|
typedef u8 forced_type;
|
|
|
|
};
|
2014-09-01 18:16:44 +02:00
|
|
|
|
2015-01-28 13:59:16 +01:00
|
|
|
template<typename T>
|
|
|
|
class to_be_t<T, s8>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static const bool value = false;
|
|
|
|
typedef s8 type;
|
|
|
|
typedef s8 forced_type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class to_be_t<T, char>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static const bool value = false;
|
|
|
|
typedef char type;
|
|
|
|
typedef char forced_type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class to_be_t<T, bool>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static const bool value = false;
|
|
|
|
typedef bool type;
|
|
|
|
typedef bool forced_type;
|
2014-09-01 18:16:44 +02:00
|
|
|
};
|
|
|
|
|
2014-09-05 13:24:37 +02:00
|
|
|
template<typename T, typename T2 = T>
|
|
|
|
struct invert_be_t
|
|
|
|
{
|
|
|
|
typedef typename to_be_t<T, T2>::type type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T, typename T2>
|
|
|
|
struct invert_be_t<be_t<T, T2>>
|
|
|
|
{
|
|
|
|
typedef T type;
|
|
|
|
};
|
|
|
|
|
2014-02-22 03:53:06 +01:00
|
|
|
template<typename T, typename T1, T1 value> struct _se : public const_se_t<T, value> {};
|
|
|
|
template<typename T, typename T1, T1 value> struct _se<be_t<T>, T1, value> : public const_se_t<T, value> {};
|
|
|
|
|
2014-09-05 13:24:37 +02:00
|
|
|
//#define se(t, x) _se<decltype(t), decltype(x), x>::value
|
2014-02-22 03:53:06 +01:00
|
|
|
#define se16(x) _se<u16, decltype(x), x>::value
|
|
|
|
#define se32(x) _se<u32, decltype(x), x>::value
|
|
|
|
#define se64(x) _se<u64, decltype(x), x>::value
|
2014-08-25 16:56:13 +02:00
|
|
|
|
2014-11-20 20:41:04 +01:00
|
|
|
template<typename Tto, typename Tfrom>
|
|
|
|
struct convert_le_be_t
|
|
|
|
{
|
|
|
|
static Tto func(Tfrom&& value)
|
|
|
|
{
|
|
|
|
return (Tto)value;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename Tt, typename Tt1, typename Tfrom>
|
|
|
|
struct convert_le_be_t<be_t<Tt, Tt1>, Tfrom>
|
|
|
|
{
|
|
|
|
static be_t<Tt, Tt1> func(Tfrom&& value)
|
|
|
|
{
|
|
|
|
return be_t<Tt, Tt1>::make(value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename Tt, typename Tt1, typename Tf, typename Tf1>
|
|
|
|
struct convert_le_be_t<be_t<Tt, Tt1>, be_t<Tf, Tf1>>
|
|
|
|
{
|
|
|
|
static be_t<Tt, Tt1> func(be_t<Tf, Tf1>&& value)
|
|
|
|
{
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename Tto, typename Tf, typename Tf1>
|
|
|
|
struct convert_le_be_t<Tto, be_t<Tf, Tf1>>
|
|
|
|
{
|
|
|
|
static Tto func(be_t<Tf, Tf1>&& value)
|
|
|
|
{
|
|
|
|
return value.value();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename Tto, typename Tfrom>
|
|
|
|
__forceinline Tto convert_le_be(Tfrom&& value)
|
|
|
|
{
|
|
|
|
return convert_le_be_t<Tto, Tfrom>::func(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Tto, typename Tfrom>
|
|
|
|
__forceinline void convert_le_be(Tto& dst, Tfrom&& src)
|
|
|
|
{
|
2014-11-21 14:52:01 +01:00
|
|
|
dst = convert_le_be_t<Tto, Tfrom>::func(src);
|
2015-01-11 10:33:05 +01:00
|
|
|
}
|
2015-05-27 05:11:59 +02:00
|
|
|
|
|
|
|
template<typename T> using le_t = T;
|
|
|
|
|
|
|
|
template<typename T> struct to_le_t { using type = T; };
|