re() removed, added be_t<const T> specialization

This commit is contained in:
Nekotekina 2014-09-04 13:21:23 +04:00
parent 4b49d57f97
commit 05cebd1017
6 changed files with 136 additions and 36 deletions

View File

@ -6,13 +6,44 @@
#define re128(val) u128::byteswap(val)
template<typename T, int size = sizeof(T)> struct se_t;
template<typename T> struct se_t<T, 1> { static __forceinline void func(T& dst, const T src) { (u8&)dst = (u8&)src; } };
template<typename T> struct se_t<T, 2> { static __forceinline void func(T& dst, const T src) { (u16&)dst = _byteswap_ushort((u16&)src); } };
template<typename T> struct se_t<T, 4> { static __forceinline void func(T& dst, const T src) { (u32&)dst = _byteswap_ulong((u32&)src); } };
template<typename T> struct se_t<T, 8> { static __forceinline void func(T& dst, const T src) { (u64&)dst = _byteswap_uint64((u64&)src); } };
template<typename T> T re(const T val) { T res; se_t<T>::func(res, val); return res; }
template<typename T1, typename T2> void re(T1& dst, const T2 val) { se_t<T1>::func(dst, val); }
template<typename T> struct se_t<T, 1>
{
static __forceinline T func(const T src)
{
return src;
}
};
template<typename T> struct se_t<T, 2>
{
static __forceinline T func(const T src)
{
const u16 res = _byteswap_ushort((u16&)src);
return (T&)res;
}
};
template<typename T> struct se_t<T, 4>
{
static __forceinline T func(const T src)
{
const u32 res = _byteswap_ulong((u32&)src);
return (T&)res;
}
};
template<typename T> struct se_t<T, 8>
{
static __forceinline T func(const T src)
{
const u64 res = _byteswap_uint64((u64&)src);
return (T&)res;
}
};
//template<typename T> T re(const T val) { T res; se_t<T>::func(res, val); return res; }
//template<typename T1, typename T2> void re(T1& dst, const T2 val) { se_t<T1>::func(dst, val); }
template<typename T, s64 _value, int size = sizeof(T)> struct const_se_t;
template<typename T, s64 _value> struct const_se_t<T, _value, 1>
@ -63,11 +94,7 @@ public:
T ToLE() const
{
T res;
se_t<T, sizeof(T2)>::func(res, m_data);
return res;
return se_t<T, sizeof(T2)>::func(m_data);
}
void FromBE(const T& value)
@ -77,21 +104,18 @@ public:
void FromLE(const T& value)
{
se_t<T, sizeof(T2)>::func(m_data, value);
m_data = se_t<T, sizeof(T2)>::func(value);
}
static be_t MakeFromLE(const T value)
{
be_t res;
res.FromLE(value);
return res;
T data = se_t<T, sizeof(T2)>::func(value);
return (be_t&)data;
}
static be_t MakeFromBE(const T value)
{
be_t res;
res.FromBE(value);
return res;
return (be_t&)value;
}
//template<typename T1>
@ -103,25 +127,26 @@ public:
template<typename T1>
operator const be_t<T1>() const
{
be_t<T1> res;
if (sizeof(T1) < sizeof(T))
if (sizeof(T1) > sizeof(T) || std::is_floating_point<T>::value || std::is_floating_point<T1>::value)
{
res.FromBE(ToBE() >> ((sizeof(T)-sizeof(T1)) * 8));
T1 res = se_t<T1, sizeof(T1)>::func(ToLE());
return (be_t<T1>&)res;
}
else if (sizeof(T1) > sizeof(T))
else if (sizeof(T1) < sizeof(T))
{
res.FromLE(ToLE());
T1 res = ToBE() >> ((sizeof(T) - sizeof(T1)) * 8);
return (be_t<T1>&)res;
}
else
{
res.FromBE(ToBE());
T1 res = ToBE();
return (be_t<T1>&)res;
}
return res;
}
be_t& operator = (const T& right)
{
FromLE(right);
m_data = se_t<T, sizeof(T2)>::func(right);
return *this;
}
@ -171,6 +196,81 @@ public:
be_t& operator-- () { *this -= 1; return *this; }
};
template<typename T, typename T2>
class be_t<const T, T2>
{
static_assert(sizeof(T2) == 1 || sizeof(T2) == 2 || sizeof(T2) == 4 || sizeof(T2) == 8, "Bad be_t type");
const T m_data;
public:
typedef const T type;
const T& ToBE() const
{
return m_data;
}
const T ToLE() const
{
return se_t<const T, sizeof(T2)>::func(m_data);
}
static be_t MakeFromLE(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
{
return ToLE();
}
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;
}
}
template<typename T1> be_t operator & (const be_t<T1>& right) const { const T res; res = ToBE() & right.ToBE(); return (be_t&)res; }
template<typename T1> be_t operator | (const be_t<T1>& right) const { const T res; res = ToBE() | right.ToBE(); return (be_t&)res; }
template<typename T1> be_t operator ^ (const be_t<T1>& right) const { const T res; res = ToBE() ^ right.ToBE(); return (be_t&)res; }
template<typename T1> bool operator == (T1 right) const { return (T1)ToLE() == right; }
template<typename T1> bool operator != (T1 right) const { return !(*this == 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; }
template<typename T1> bool operator <= (T1 right) const { return (T1)ToLE() <= right; }
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); }
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(); }
};
template<typename T, typename T2 = T>
struct is_be_t : public std::integral_constant<bool, false> {};

View File

@ -127,11 +127,11 @@ void SPURecompilerCore::Compile(u16 pos)
m_enc->do_finalize = true;
}
bool fin = m_enc->do_finalize;
if (entry[pos].valid == re(opcode))
if (entry[pos].valid == re32(opcode))
{
excess++;
}
entry[pos].valid = re(opcode);
entry[pos].valid = re32(opcode);
if (fin) break;
CPU.PC += 4;

View File

@ -99,7 +99,7 @@ void RSXVertexData::Load(u32 start, u32 count, u32 baseOffset, u32 baseIndex=0)
{
const u16* c_src = (const u16*)src;
u16* c_dst = (u16*)dst;
for(u32 j=0; j<size; ++j) *c_dst++ = re(*c_src++);
for(u32 j=0; j<size; ++j) *c_dst++ = re16(*c_src++);
}
break;
@ -107,7 +107,7 @@ void RSXVertexData::Load(u32 start, u32 count, u32 baseOffset, u32 baseIndex=0)
{
const u32* c_src = (const u32*)src;
u32* c_dst = (u32*)dst;
for(u32 j=0; j<size; ++j) *c_dst++ = re(*c_src++);
for(u32 j=0; j<size; ++j) *c_dst++ = re32(*c_src++);
}
break;
}
@ -2168,8 +2168,8 @@ void RSXThread::Task()
u32 put, get;
// this code produces only mov + bswap:
se_t<u32>::func(put, std::atomic_load((volatile std::atomic<u32>*)((u8*)m_ctrl + offsetof(CellGcmControl, put))));
se_t<u32>::func(get, std::atomic_load((volatile std::atomic<u32>*)((u8*)m_ctrl + offsetof(CellGcmControl, get))));
put = se_t<u32>::func(std::atomic_load((volatile std::atomic<u32>*)((u8*)m_ctrl + offsetof(CellGcmControl, put))));
get = se_t<u32>::func(std::atomic_load((volatile std::atomic<u32>*)((u8*)m_ctrl + offsetof(CellGcmControl, get))));
/*
se_t<u32>::func(put, InterlockedCompareExchange((volatile unsigned long*)((u8*)m_ctrl + offsetof(CellGcmControl, put)), 0, 0));
se_t<u32>::func(get, InterlockedCompareExchange((volatile unsigned long*)((u8*)m_ctrl + offsetof(CellGcmControl, get)), 0, 0));

View File

@ -160,7 +160,7 @@ struct CellVideoOutDisplayMode
u8 conversion;
u8 aspect;
u8 reserved[2];
u16 refreshRates;
be_t<u16> refreshRates;
};
struct CellVideoOutResolution

View File

@ -155,8 +155,8 @@ __forceinline void Module::AddFuncSub(const char group[8], const u64 ops[], cons
op.mask = ops[i] >> 32;
op.crc = (u32)ops[i];
if (op.mask) op.crc &= op.mask;
op.mask = re(op.mask);
op.crc = re(op.crc);
op.mask = re32(op.mask);
op.crc = re32(op.crc);
sf->ops.push_back(op);
}
PushNewFuncSub(sf);

View File

@ -152,7 +152,7 @@ int cellVideoOutGetState(u32 videoOut, u32 deviceIndex, vm::ptr<CellVideoOutStat
state->displayMode.scanMode = Emu.GetGSManager().GetInfo().mode.scanMode;
state->displayMode.conversion = Emu.GetGSManager().GetInfo().mode.conversion;
state->displayMode.aspect = Emu.GetGSManager().GetInfo().mode.aspect;
state->displayMode.refreshRates = re(Emu.GetGSManager().GetInfo().mode.refreshRates);
state->displayMode.refreshRates = Emu.GetGSManager().GetInfo().mode.refreshRates;
return CELL_VIDEO_OUT_SUCCEEDED;
case CELL_VIDEO_OUT_SECONDARY: