1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-25 12:12:50 +01:00

be_t<> constructor elimination

This commit is contained in:
Nekotekina 2014-07-18 20:55:26 +04:00
parent a7971b55ee
commit 74914c5916
15 changed files with 81 additions and 103 deletions

View File

@ -63,24 +63,6 @@ class be_t
public:
typedef T type;
#ifdef _WIN32
be_t(){}
#else
be_t() noexcept = default;
#endif
be_t(const be_t<T,size>& value) = default;
be_t(const T& value)
{
FromLE(value);
}
template<typename T1>
explicit be_t(const be_t<T1>& value)
{
FromBE(value.ToBE());
}
const T& ToBE() const
{
@ -130,7 +112,18 @@ public:
operator const be_t<T1>() const
{
be_t<T1> res;
res.FromBE(ToBE());
if (sizeof(T1) < sizeof(T))
{
res.FromBE(ToBE() >> ((sizeof(T)-sizeof(T1)) * 8));
}
else if (sizeof(T1) > sizeof(T))
{
res.FromBE((T1)ToBE() << ((sizeof(T1)-sizeof(T)) * 8));
}
else
{
res.FromBE(ToBE());
}
return res;
}

View File

@ -36,5 +36,5 @@ __forceinline u32 SM_GetCurrentCPUThreadId()
__forceinline be_t<u32> SM_GetCurrentCPUThreadIdBE()
{
return SM_GetCurrentCPUThreadId();
return be_t<u32>::MakeFromLE(SM_GetCurrentCPUThreadId());
}

View File

@ -22,8 +22,8 @@ enum SMutexResult
template
<
typename T,
u64 free_value = 0,
u64 dead_value = 0xffffffff,
const u64 free_value = 0,
const u64 dead_value = 0xffffffffffffffffull,
void (*wait)() = SM_Sleep
>
class SMutexBase
@ -32,20 +32,26 @@ class SMutexBase
std::atomic<T> owner;
public:
SMutexBase()
: owner((T)free_value)
static const T GetFreeValue()
{
static const u64 value = free_value;
return (const T&)value;
}
static const T GetDeadValue()
{
static const u64 value = dead_value;
return (const T&)value;
}
void initialize()
{
(T&)owner = free_value;
owner = GetFreeValue();
}
~SMutexBase()
void finalize()
{
lock((T)dead_value);
owner = (T)dead_value;
owner = GetDeadValue();
}
__forceinline T GetOwner() const
@ -53,23 +59,13 @@ public:
return (T&)owner;
}
__forceinline T GetFreeValue() const
{
return (T)free_value;
}
__forceinline T GetDeadValue() const
{
return (T)dead_value;
}
SMutexResult trylock(T tid)
{
if (Emu.IsStopped())
{
return SMR_ABORT;
}
T old = (T)free_value;
T old = GetFreeValue();
if (!owner.compare_exchange_strong(old, tid))
{
@ -77,7 +73,7 @@ public:
{
return SMR_DEADLOCK;
}
if (old == (T)dead_value)
if (old == GetDeadValue())
{
return SMR_DESTROYED;
}
@ -87,7 +83,7 @@ public:
return SMR_OK;
}
SMutexResult unlock(T tid, T to = (T)free_value)
SMutexResult unlock(T tid, T to = GetFreeValue())
{
if (Emu.IsStopped())
{
@ -97,11 +93,11 @@ public:
if (!owner.compare_exchange_strong(old, to))
{
if (old == (T)free_value)
if (old == GetFreeValue())
{
return SMR_FAILED;
}
if (old == (T)dead_value)
if (old == GetDeadValue())
{
return SMR_DESTROYED;
}

View File

@ -113,8 +113,9 @@ int Decrypt(rFile& pkg_f, rFile& dec_pkg_f, PKGHeader* m_header)
{
aes_crypt_ecb(&c, AES_ENCRYPT, iv, ctr+j*HASH_LEN);
be_t<u64> hi = *(be_t<u64>*)&iv[0];
be_t<u64> lo = *(be_t<u64>*)&iv[8] + 1;
be_t<u64> hi = be_t<u64>::MakeFromBE(*(u64*)&iv[0]);
be_t<u64> lo = be_t<u64>::MakeFromBE(*(u64*)&iv[8]);
lo++;
if (lo == 0)
hi += 1;

View File

@ -223,15 +223,15 @@ enum CellVideoOutRGBOutputRange
static const CellVideoOutResolution ResolutionTable[] =
{
{(u16)-1, (u16)-1}, //0 - 0
{1920, 1080}, //1 - 1
{1280, 720}, //2 - 2
{720, 480}, //4 - 3
{720, 576}, //5 - 4
{1600, 1080}, //10 - 5
{1440, 1080}, //11 - 6
{1280, 1080}, //12 - 7
{960, 1080}, //13 - 8
{ be_t<u16>::MakeFromBE(se16(0xffff)), be_t<u16>::MakeFromBE(se16(0xffff)) }, //0 - 0
{ be_t<u16>::MakeFromBE(se16(1920)), be_t<u16>::MakeFromBE(se16(1080)) }, //1 - 1
{ be_t<u16>::MakeFromBE(se16(1280)), be_t<u16>::MakeFromBE(se16(720)) }, //2 - 2
{ be_t<u16>::MakeFromBE(se16(720)), be_t<u16>::MakeFromBE(se16(480)) }, //4 - 3
{ be_t<u16>::MakeFromBE(se16(720)), be_t<u16>::MakeFromBE(se16(576)) }, //5 - 4
{ be_t<u16>::MakeFromBE(se16(1600)), be_t<u16>::MakeFromBE(se16(1080)) }, //10 - 5
{ be_t<u16>::MakeFromBE(se16(1440)), be_t<u16>::MakeFromBE(se16(1080)) }, //11 - 6
{ be_t<u16>::MakeFromBE(se16(1280)), be_t<u16>::MakeFromBE(se16(1080)) }, //12 - 7
{ be_t<u16>::MakeFromBE(se16(960)), be_t<u16>::MakeFromBE(se16(1080)) }, //13 - 8
};
inline static u32 ResolutionIdToNum(u32 id)

View File

@ -517,29 +517,29 @@ public:
}
}
bool CopyToReal(void* real, u64 from, u32 count)
template<typename T> bool CopyToReal(void* real, T from, u32 count)
{
if (!IsGoodAddr(from, count)) return false;
if (!IsGoodAddr<T>(from, count)) return false;
memcpy(real, GetMemFromAddr(from), count);
memcpy(real, GetMemFromAddr<T>(from), count);
return true;
}
bool CopyFromReal(u64 to, const void* real, u32 count)
template<typename T> bool CopyFromReal(T to, const void* real, u32 count)
{
if (!IsGoodAddr(to, count)) return false;
if (!IsGoodAddr<T>(to, count)) return false;
memcpy(GetMemFromAddr(to), real, count);
memcpy(GetMemFromAddr<T>(to), real, count);
return true;
}
bool Copy(u64 to, u64 from, u32 count)
template<typename T1, typename T2> bool Copy(T1 to, T2 from, u32 count)
{
if (!IsGoodAddr(to, count) || !IsGoodAddr(from, count)) return false;
if (!IsGoodAddr<T1>(to, count) || !IsGoodAddr<T2>(from, count)) return false;
memmove(GetMemFromAddr(to), GetMemFromAddr(from), count);
memmove(GetMemFromAddr<T1>(to), GetMemFromAddr<T2>(from), count);
return true;
}
@ -564,14 +564,14 @@ public:
for (u32 i = 0; i < size; ++i) Write8(addr + (size - 1 - i), src[i]);
}
template<typename T> void WriteData(const u64 addr, const T* data)
template<typename T, typename Td> void WriteData(const T addr, const Td* data)
{
memcpy(GetMemFromAddr(addr), data, sizeof(T));
memcpy(GetMemFromAddr<T>(addr), data, sizeof(Td));
}
template<typename T> void WriteData(const u64 addr, const T data)
template<typename T, typename Td> void WriteData(const T addr, const Td data)
{
*(T*)GetMemFromAddr(addr) = data;
*(Td*)GetMemFromAddr<T>(addr) = data;
}
std::string ReadString(const u64 addr, const u64 len)

View File

@ -366,25 +366,6 @@ public:
}
};
class NullMemoryBlock : public MemoryBlock
{
public:
virtual bool IsNULL() { return true; }
virtual bool IsMyAddress(const u64 addr) { return true; }
virtual bool Read8(const u64 addr, u8* value);
virtual bool Read16(const u64 addr, u16* value);
virtual bool Read32(const u64 addr, u32* value);
virtual bool Read64(const u64 addr, u64* value);
virtual bool Read128(const u64 addr, u128* value);
virtual bool Write8(const u64 addr, const u8 value);
virtual bool Write16(const u64 addr, const u16 value);
virtual bool Write32(const u64 addr, const u32 value);
virtual bool Write64(const u64 addr, const u64 value);
virtual bool Write128(const u64 addr, const u128 value);
};
template<typename PT>
class DynamicMemoryBlockBase : public PT
{

View File

@ -332,6 +332,8 @@ int cellPadGetInfo2(u32 info_addr)
if(!Emu.GetPadManager().IsInited()) return CELL_PAD_ERROR_UNINITIALIZED;
CellPadInfo2 info = {};
//sys_io->Warning("*** info{}: max_connect=0x%x, now_connect=0x%x, system_info=0x%x, port_status[0]=0x%x, port_setting[0]=0x%x",
// (u32)info.max_connect, (u32)info.now_connect, (u32)info.system_info, (u32)info.port_status[0], (u32)info.port_setting[0]);
const PadInfo& rinfo = Emu.GetPadManager().GetInfo();
info.max_connect = rinfo.max_connect;

View File

@ -178,7 +178,7 @@ void getSaveDataStat(SaveDataEntry entry, mem_ptr_t<CellSaveDataStatGet> statGet
memcpy(statGet->getParam.listParam, entry.listParam.c_str(), CELL_SAVEDATA_SYSP_LPARAM_SIZE);
statGet->fileNum = 0;
statGet->fileList.SetAddr(0);
statGet->fileList.SetAddr(be_t<u32>::MakeFromBE(0));
statGet->fileListNum = 0;
std::string saveDir = "/dev_hdd0/home/00000001/savedata/" + entry.dirName; // TODO: Get the path of the current user
vfsDir dir(saveDir);
@ -210,7 +210,7 @@ void getSaveDataStat(SaveDataEntry entry, mem_ptr_t<CellSaveDataStatGet> statGet
}
}
statGet->fileList.SetAddr(Memory.Alloc(sizeof(CellSaveDataFileStat) * fileEntries.size(), sizeof(CellSaveDataFileStat)));
statGet->fileList.SetAddr(be_t<u32>::MakeFromLE(Memory.Alloc(sizeof(CellSaveDataFileStat)* fileEntries.size(), sizeof(CellSaveDataFileStat))));
for (u32 i=0; i<fileEntries.size(); i++)
memcpy(&statGet->fileList[i], &fileEntries[i], sizeof(CellSaveDataFileStat));
}

View File

@ -213,7 +213,7 @@ int cellSSPlayerSetWave(u32 handle, mem_ptr_t<CellSSPlayerWaveParam> waveInfo, m
ssp[handle].m_addr = waveInfo->addr;
ssp[handle].m_samples = waveInfo->samples;
ssp[handle].m_loop_start = waveInfo->loopStartOffset - 1;
ssp[handle].m_loop_mode = commonInfo.GetAddr() ? commonInfo->loopMode : CELL_SSPLAYER_ONESHOT;
ssp[handle].m_loop_mode = commonInfo.GetAddr() ? (u32)commonInfo->loopMode : CELL_SSPLAYER_ONESHOT;
ssp[handle].m_position = waveInfo->startOffset - 1;
return CELL_OK;

View File

@ -189,7 +189,7 @@ s32 sys_lwcond_wait(mem_ptr_t<sys_lwcond_t> lwcond, u64 timeout)
mem_ptr_t<sys_lwmutex_t> mutex(lwcond->lwmutex);
u32 tid_le = GetCurrentPPUThread().GetId();
be_t<u32> tid = tid_le;
be_t<u32> tid = be_t<u32>::MakeFromLE(tid_le);
SleepQueue* sq = nullptr;
Emu.GetIdManager().GetIDData((u32)mutex->sleep_queue, sq);
@ -211,7 +211,7 @@ s32 sys_lwcond_wait(mem_ptr_t<sys_lwcond_t> lwcond, u64 timeout)
if (sq)
{
mutex->mutex.unlock(tid, mutex->attribute.ToBE() == se32(SYS_SYNC_PRIORITY) ? sq->pop_prio() : sq->pop());
mutex->mutex.unlock(tid, be_t<u32>::MakeFromLE(mutex->attribute.ToBE() == se32(SYS_SYNC_PRIORITY) ? sq->pop_prio() : sq->pop()));
}
else if (mutex->attribute.ToBE() == se32(SYS_SYNC_RETRY))
{

View File

@ -77,7 +77,7 @@ s32 sys_lwmutex_lock(mem_ptr_t<sys_lwmutex_t> lwmutex, u64 timeout)
//ConLog.Write("*** lock mutex (addr=0x%x, attr=0x%x, Nrec=%d, owner=%d, waiter=%d)",
//lwmutex.GetAddr(), (u32)lwmutex->attribute, (u32)lwmutex->recursive_count, lwmutex->vars.parts.owner.GetOwner(), (u32)lwmutex->waiter);
return lwmutex->lock(GetCurrentPPUThread().GetId(), timeout ? ((timeout < 1000) ? 1 : (timeout / 1000)) : 0);
return lwmutex->lock(be_t<u32>::MakeFromLE(GetCurrentPPUThread().GetId()), timeout ? ((timeout < 1000) ? 1 : (timeout / 1000)) : 0);
}
s32 sys_lwmutex_trylock(mem_ptr_t<sys_lwmutex_t> lwmutex)
@ -86,7 +86,7 @@ s32 sys_lwmutex_trylock(mem_ptr_t<sys_lwmutex_t> lwmutex)
if (!lwmutex.IsGood()) return CELL_EFAULT;
return lwmutex->trylock(GetCurrentPPUThread().GetId());
return lwmutex->trylock(be_t<u32>::MakeFromLE(GetCurrentPPUThread().GetId()));
}
s32 sys_lwmutex_unlock(mem_ptr_t<sys_lwmutex_t> lwmutex)
@ -98,7 +98,7 @@ s32 sys_lwmutex_unlock(mem_ptr_t<sys_lwmutex_t> lwmutex)
//ConLog.Write("*** unlocking mutex (addr=0x%x, attr=0x%x, Nrec=%d, owner=%d, waiter=%d)",
//lwmutex.GetAddr(), (u32)lwmutex->attribute, (u32)lwmutex->recursive_count, (u32)lwmutex->vars.parts.owner.GetOwner(), (u32)lwmutex->waiter);
return lwmutex->unlock(GetCurrentPPUThread().GetId());
return lwmutex->unlock(be_t<u32>::MakeFromLE(GetCurrentPPUThread().GetId()));
}
void SleepQueue::push(u32 tid)
@ -294,7 +294,7 @@ int sys_lwmutex_t::unlock(be_t<u32> tid)
recursive_count -= 1;
if (!recursive_count.ToBE())
{
be_t<u32> target = 0;
be_t<u32> target = be_t<u32>::MakeFromBE(se32(0));
switch (attribute.ToBE() & se32(SYS_SYNC_ATTR_PROTOCOL_MASK))
{
case se32(SYS_SYNC_FIFO):

View File

@ -209,8 +209,8 @@ void sys_ppu_thread_once(mem_ptr_t<std::atomic<be_t<u32>>> once_ctrl, u32 entry)
{
sysPrxForUser->Warning("sys_ppu_thread_once(once_ctrl_addr=0x%x, entry=0x%x)", once_ctrl.GetAddr(), entry);
be_t<u32> old = SYS_PPU_THREAD_ONCE_INIT;
if (once_ctrl->compare_exchange_weak(old, SYS_PPU_THREAD_DONE_INIT))
be_t<u32> old = be_t<u32>::MakeFromBE(se32(SYS_PPU_THREAD_ONCE_INIT));
if (once_ctrl->compare_exchange_weak(old, be_t<u32>::MakeFromBE(se32(SYS_PPU_THREAD_DONE_INIT))))
{
CPUThread& new_thread = Emu.GetCPU().AddThread(CPU_THREAD_PPU);
new_thread.SetEntry(entry);

View File

@ -19,7 +19,7 @@ void sys_spinlock_lock(mem_ptr_t<spinlock> lock)
{
sys_spinlock.Log("sys_spinlock_lock(lock_addr=0x%x)", lock.GetAddr());
be_t<u32> tid = GetCurrentPPUThread().GetId();
be_t<u32> tid = be_t<u32>::MakeFromLE(GetCurrentPPUThread().GetId());
switch (lock->mutex.lock(tid))
{
case SMR_ABORT: LOG_WARNING(HLE, "sys_spinlock_lock(0x%x) aborted", lock.GetAddr()); break;
@ -32,7 +32,7 @@ s32 sys_spinlock_trylock(mem_ptr_t<spinlock> lock)
{
sys_spinlock.Log("sys_spinlock_trylock(lock_addr=0x%x)", lock.GetAddr());
be_t<u32> tid = GetCurrentPPUThread().GetId();
be_t<u32> tid = be_t<u32>::MakeFromLE(GetCurrentPPUThread().GetId());
switch (lock->mutex.trylock(tid))
{
case SMR_FAILED: return CELL_EBUSY;

View File

@ -143,8 +143,11 @@ bool TROPUSRLoader::Generate(const std::string& filepath, const std::string& con
default: trophy_grade = 0;
}
TROPUSREntry4 entry4 = {4, sizeof(TROPUSREntry4)-0x10, m_table4.size(), 0, trophy_id, trophy_grade, 0xFFFFFFFF};
TROPUSREntry6 entry6 = {6, sizeof(TROPUSREntry6)-0x10, m_table6.size(), 0, trophy_id, 0, 0, 0, 0, 0};
TROPUSREntry4 entry4 = { be_t<u32>::MakeFromBE(se32(4)), be_t<u32>::MakeFromBE(se32(sizeof(TROPUSREntry4) - 0x10)),
be_t<u32>::MakeFromLE(m_table4.size()), be_t<u32>::MakeFromBE(se32(0)), be_t<u32>::MakeFromLE(trophy_id),
be_t<u32>::MakeFromLE(trophy_grade), be_t<u32>::MakeFromBE(se32(0xFFFFFFFF)) };
TROPUSREntry6 entry6 = { be_t<u32>::MakeFromBE(se32(6)), be_t<u32>::MakeFromBE(se32(sizeof(TROPUSREntry6) - 0x10)),
be_t<u32>::MakeFromLE(m_table6.size()), be_t<u32>::MakeFromBE(0), be_t<u32>::MakeFromLE(trophy_id) };
m_table4.push_back(entry4);
m_table6.push_back(entry6);
@ -152,9 +155,11 @@ bool TROPUSRLoader::Generate(const std::string& filepath, const std::string& con
}
u64 offset = sizeof(TROPUSRHeader) + 2 * sizeof(TROPUSRTableHeader);
TROPUSRTableHeader table4header = {4, sizeof(TROPUSREntry4)-0x10, 1, m_table4.size(), offset, 0};
TROPUSRTableHeader table4header = { be_t<u32>::MakeFromBE(se32(4)), be_t<u32>::MakeFromBE(se32(sizeof(TROPUSREntry4)-0x10)),
be_t<u32>::MakeFromBE(se32(1)), be_t<u32>::MakeFromLE(m_table4.size()), be_t<u64>::MakeFromLE(offset) };
offset += m_table4.size() * sizeof(TROPUSREntry4);
TROPUSRTableHeader table6header = {6, sizeof(TROPUSREntry6)-0x10, 1, m_table6.size(), offset, 0};
TROPUSRTableHeader table6header = { be_t<u32>::MakeFromBE(se32(6)), be_t<u32>::MakeFromBE(se32(sizeof(TROPUSREntry6)-0x10)),
be_t<u32>::MakeFromBE(se32(1)), be_t<u32>::MakeFromLE(m_table6.size()), be_t<u64>::MakeFromLE(offset) };
offset += m_table6.size() * sizeof(TROPUSREntry6);
m_tableHeaders.clear();