vm::atomic update, be_t update

1) MakeFromLE replaced with make(), MakeFromBE removed. Compiler seems
to be able to optimize it anyway.
2) be_t<> conversion operator temporarily replaced with conversion
through LE because it can't work with all possible numeric conversions
(float<>int for example)
This commit is contained in:
Nekotekina
2014-09-20 03:16:11 +04:00
parent 0baf295c1b
commit 66000240ac
16 changed files with 98 additions and 89 deletions
+5 -34
View File
@@ -306,17 +306,12 @@ public:
m_data = se_t<T, sizeof(T2)>::func(value);
}
static be_t MakeFromLE(const T value)
static be_t make(const T value)
{
T data = se_t<T, sizeof(T2)>::func(value);
return (be_t&)data;
}
static be_t MakeFromBE(const T value)
{
return (be_t&)value;
}
//template<typename T1>
operator const T() const
{
@@ -335,7 +330,8 @@ public:
template<typename T1>
operator const be_t<T1>() const
{
return _convert<T1, T, ((sizeof(T1) > sizeof(T)) ? 1 : (sizeof(T1) < sizeof(T) ? 2 : 0))>::func(m_data);
return be_t<T1>::make(ToLE());
//return _convert<T1, T, ((sizeof(T1) > sizeof(T)) ? 1 : (sizeof(T1) < sizeof(T) ? 2 : 0))>::func(m_data);
}
template<typename T1> be_t& operator += (T1 right) { return *this = T(*this) + right; }
@@ -401,17 +397,12 @@ public:
return se_t<const T, sizeof(T2)>::func(m_data);
}
static be_t MakeFromLE(const T value)
static be_t make(const T value)
{
const T data = se_t<const T, sizeof(T2)>::func(value);
return (be_t&)data;
}
static be_t MakeFromBE(const T value)
{
return (be_t&)value;
}
//template<typename T1>
operator const T() const
{
@@ -421,21 +412,7 @@ public:
template<typename T1>
operator const be_t<T1>() const
{
if (sizeof(T1) > sizeof(T) || std::is_floating_point<T>::value || std::is_floating_point<T1>::value)
{
T1 res = se_t<T1, sizeof(T1)>::func(ToLE());
return (be_t<T1>&)res;
}
else if (sizeof(T1) < sizeof(T))
{
T1 res = ToBE() >> ((sizeof(T) - sizeof(T1)) * 8);
return (be_t<T1>&)res;
}
else
{
T1 res = ToBE();
return (be_t<T1>&)res;
}
return be_t<T1>::make(ToLE());
}
template<typename T1> be_t operator & (const be_t<T1>& right) const { const T res = ToBE() & right.ToBE(); return (be_t&)res; }
@@ -540,12 +517,6 @@ template<typename T, typename T1, T1 value> struct _se<be_t<T>, T1, value> : pub
#define se32(x) _se<u32, decltype(x), x>::value
#define se64(x) _se<u64, decltype(x), x>::value
template<typename T>
__forceinline static const be_t<T> to_be(const T value)
{
return be_t<T>::MakeFromLE(value);
}
template<typename T> __forceinline static u8 Read8(T& f)
{
u8 ret;
+14 -3
View File
@@ -45,7 +45,7 @@ void strcpy_trunc(char(&dst)[size], const char(&src)[rsize])
#define INFINITE 0xFFFFFFFF
#define _CRT_ALIGN(x) __attribute__((aligned(x)))
#define InterlockedCompareExchange(ptr,new_val,old_val) __sync_val_compare_and_swap(ptr,old_val,new_val)
#define InterlockedCompareExchange64(ptr,new_val,old_val) __sync_val_compare_and_swap(ptr,old_val,new_val)
#define InterlockedExchange(ptr, value) __sync_lock_test_and_set(ptr, value)
inline int64_t InterlockedOr64(volatile int64_t *dest, int64_t val)
{
@@ -54,7 +54,7 @@ inline int64_t InterlockedOr64(volatile int64_t *dest, int64_t val)
do
{
olderval = oldval;
oldval = InterlockedCompareExchange64(dest, olderval | val, olderval);
oldval = __sync_val_compare_and_swap(dest, olderval | val, olderval);
} while (olderval != oldval);
return oldval;
}
@@ -100,4 +100,15 @@ static __forceinline uint64_t InterlockedCompareExchange(volatile uint64_t* dest
{
return _InterlockedCompareExchange64((volatile long long*)dest, exch, comp);
}
#endif
#endif
#ifndef InterlockedExchange
static __forceinline uint32_t InterlockedExchange(volatile uint32_t* dest, uint32_t value)
{
return _InterlockedExchange((volatile long*)dest, value);
}
static __forceinline uint64_t InterlockedExchange(volatile uint64_t* dest, uint64_t value)
{
return _InterlockedExchange64((volatile long long*)dest, value);
}
#endif