iR5900: Cleanup code.

Variable scopes, constants, casts initializations.
This commit is contained in:
lightningterror 2023-09-08 18:33:40 +02:00
parent 6186f39068
commit a641d2a2de
1 changed files with 31 additions and 35 deletions

View File

@ -776,7 +776,7 @@ void recClear(u32 addr, u32 size)
if (blockidx == -1)
return;
u32 lowerextent = (u32)-1, upperextent = 0, ceiling = (u32)-1;
u32 lowerextent = static_cast<u32>(-1), upperextent = 0, ceiling = static_cast<u32>(-1);
BASEBLOCKEX* pexblock = recBlocks[blockidx + 1];
if (pexblock)
@ -1302,8 +1302,8 @@ void iFlushCall(int flushtype)
static u32 scaleblockcycles_calculation()
{
bool lowcycles = (s_nBlockCycles <= 40);
s8 cyclerate = EmuConfig.Speedhacks.EECycleRate;
const bool lowcycles = (s_nBlockCycles <= 40);
const s8 cyclerate = EmuConfig.Speedhacks.EECycleRate;
u32 scale_cycles = 0;
if (cyclerate == 0 || lowcycles || cyclerate < -99 || cyclerate > 3)
@ -1328,7 +1328,7 @@ static u32 scaleblockcycles_calculation()
static u32 scaleblockcycles()
{
u32 scaled = scaleblockcycles_calculation();
const u32 scaled = scaleblockcycles_calculation();
#if 0 // Enable this to get some runtime statistics about the scaling result in practice
static u32 scaled_overall = 0, unscaled_overall = 0;
@ -1544,7 +1544,7 @@ void dynarecCheckBreakpoint()
if (CBreakPoints::CheckSkipFirst(BREAKPOINT_EE, pc) != 0)
return;
int bpFlags = isBreakpointNeeded(pc);
const int bpFlags = isBreakpointNeeded(pc);
bool hit = false;
//check breakpoint at current pc
if (bpFlags & 1)
@ -1573,7 +1573,7 @@ void dynarecCheckBreakpoint()
void dynarecMemcheck()
{
u32 pc = cpuRegs.pc;
const u32 pc = cpuRegs.pc;
if (CBreakPoints::CheckSkipFirst(BREAKPOINT_EE, pc) != 0)
return;
@ -1596,8 +1596,8 @@ void recMemcheck(u32 op, u32 bits, bool store)
// compute accessed address
_eeMoveGPRtoR(ecx, (op >> 21) & 0x1F);
if ((s16)op != 0)
xADD(ecx, (s16)op);
if (static_cast<s16>(op) != 0)
xADD(ecx, static_cast<s16>(op));
if (bits == 128)
xAND(ecx, ~0x0F);
@ -1669,14 +1669,14 @@ void encodeBreakpoint()
void encodeMemcheck()
{
int needed = isMemcheckNeeded(pc);
const int needed = isMemcheckNeeded(pc);
if (needed == 0)
return;
u32 op = memRead32(needed == 2 ? pc + 4 : pc);
const u32 op = memRead32(needed == 2 ? pc + 4 : pc);
const OPCODE& opcode = GetInstruction(op);
bool store = (opcode.flags & IS_STORE) != 0;
const bool store = (opcode.flags & IS_STORE) != 0;
switch (opcode.flags & MEMTYPE_MASK)
{
case MEMTYPE_BYTE:
@ -1699,9 +1699,6 @@ void encodeMemcheck()
void recompileNextInstruction(bool delayslot, bool swapped_delay_slot)
{
u32 i;
int count;
if (EmuConfig.EnablePatches)
Patch::ApplyDynamicPatches(pc);
@ -1756,7 +1753,8 @@ void recompileNextInstruction(bool delayslot, bool swapped_delay_slot)
// pc might be past s_nEndBlock if the last instruction in the block is a DI.
if (pc <= s_nEndBlock)
{
for (i = 0; i < iREGCNT_GPR; ++i)
int count;
for (u32 i = 0; i < iREGCNT_GPR; ++i)
{
if (x86regs[i].inuse)
{
@ -1768,7 +1766,7 @@ void recompileNextInstruction(bool delayslot, bool swapped_delay_slot)
}
}
for (i = 0; i < iREGCNT_XMM; ++i)
for (u32 i = 0; i < iREGCNT_XMM; ++i)
{
if (xmmregs[i].inuse)
{
@ -2058,11 +2056,11 @@ void dyna_page_reset(u32 start, u32 sz)
static void memory_protect_recompiled_code(u32 startpc, u32 size)
{
u32 inpage_ptr = HWADDR(startpc);
u32 inpage_sz = size * 4;
const u32 inpage_sz = size * 4;
// The kernel context register is stored @ 0x800010C0-0x80001300
// The EENULL thread context register is stored @ 0x81000-....
bool contains_thread_stack = ((startpc >> 12) == 0x81) || ((startpc >> 12) == 0x80001);
const bool contains_thread_stack = ((startpc >> 12) == 0x81) || ((startpc >> 12) == 0x80001);
// note: blocks are guaranteed to reside within the confines of a single page.
const vtlb_ProtectionMode PageType = contains_thread_stack ? ProtMode_Manual : mmap_GetRamPageInfo(inpage_ptr);
@ -2148,9 +2146,9 @@ static bool skipMPEG_By_Pattern(u32 sPC)
// sceMpegIsEnd: lw reg, 0x40(a0); jr ra; lw v0, 0(reg)
if ((s_nEndBlock == sPC + 12) && (memRead32(sPC + 4) == 0x03e00008))
{
u32 code = memRead32(sPC);
u32 p1 = 0x8c800040;
u32 p2 = 0x8c020000 | (code & 0x1f0000) << 5;
const u32 code = memRead32(sPC);
const u32 p1 = 0x8c800040;
const u32 p2 = 0x8c020000 | (code & 0x1f0000) << 5;
if ((code & 0xffe0ffff) != p1)
return 0;
if (memRead32(sPC + 8) != p2)
@ -2255,7 +2253,7 @@ static void recRecompile(const u32 startpc)
if (HWADDR(startpc) == EELOAD_START)
{
// The EELOAD _start function is the same across all BIOS versions
u32 mainjump = memRead32(EELOAD_START + 0x9c);
const u32 mainjump = memRead32(EELOAD_START + 0x9c);
if (mainjump >> 26 == 3) // JAL
g_eeloadMain = ((EELOAD_START + 0xa0) & 0xf0000000U) | (mainjump << 2 & 0x0fffffffU);
}
@ -2267,10 +2265,10 @@ static void recRecompile(const u32 startpc)
{
// There are four known versions of EELOAD, identifiable by the location of the 'jal' to the EELOAD function which
// calls ExecPS2(). The function itself is at the same address in all BIOSs after v1.00-v1.10.
u32 typeAexecjump = memRead32(EELOAD_START + 0x470); // v1.00, v1.01?, v1.10?
u32 typeBexecjump = memRead32(EELOAD_START + 0x5B0); // v1.20, v1.50, v1.60 (3000x models)
u32 typeCexecjump = memRead32(EELOAD_START + 0x618); // v1.60 (3900x models)
u32 typeDexecjump = memRead32(EELOAD_START + 0x600); // v1.70, v1.90, v2.00, v2.20, v2.30
const u32 typeAexecjump = memRead32(EELOAD_START + 0x470); // v1.00, v1.01?, v1.10?
const u32 typeBexecjump = memRead32(EELOAD_START + 0x5B0); // v1.20, v1.50, v1.60 (3000x models)
const u32 typeCexecjump = memRead32(EELOAD_START + 0x618); // v1.60 (3900x models)
const u32 typeDexecjump = memRead32(EELOAD_START + 0x600); // v1.70, v1.90, v2.00, v2.20, v2.30
if ((typeBexecjump >> 26 == 3) || (typeCexecjump >> 26 == 3) || (typeDexecjump >> 26 == 3)) // JAL to 0x822B8
g_eeloadExec = EELOAD_START + 0x2B8;
else if (typeAexecjump >> 26 == 3) // JAL to 0x82170
@ -2341,9 +2339,9 @@ static void recRecompile(const u32 startpc)
bool is_timeout_loop = true;
// compile breakpoints as individual blocks
int n1 = isBreakpointNeeded(i);
int n2 = isMemcheckNeeded(i);
int n = std::max<int>(n1, n2);
const int n1 = isBreakpointNeeded(i);
const int n2 = isMemcheckNeeded(i);
const int n = std::max<int>(n1, n2);
if (n != 0)
{
s_nEndBlock = i + n * 4;
@ -2582,8 +2580,6 @@ StartRecomp:
// rec info //
bool has_cop2_instructions = false;
{
EEINST* pcur;
if (s_nInstCacheSize < (s_nEndBlock - startpc) / 4 + 1)
{
free(s_pInstCache);
@ -2592,7 +2588,7 @@ StartRecomp:
pxAssert(s_pInstCache != NULL);
}
pcur = s_pInstCache + (s_nEndBlock - startpc) / 4;
EEINST* pcur = s_pInstCache + (s_nEndBlock - startpc) / 4;
_recClearInst(pcur);
pcur->info = 0;
@ -2640,7 +2636,7 @@ StartRecomp:
memory_protect_recompiled_code(startpc, (s_nEndBlock - startpc) >> 2);
// Skip Recompilation if sceMpegIsEnd Pattern detected
bool doRecompilation = !skipMPEG_By_Pattern(startpc) && !recSkipTimeoutLoop(timeout_reg, is_timeout_loop);
const bool doRecompilation = !skipMPEG_By_Pattern(startpc) && !recSkipTimeoutLoop(timeout_reg, is_timeout_loop);
if (doRecompilation)
{
@ -2713,7 +2709,7 @@ StartRecomp:
s_pCurBlock->SetFnptr((uptr)recPtr);
for (i = 1; i < (u32)s_pCurBlockEx->size; i++)
for (i = 1; i < static_cast<u32>(s_pCurBlockEx->size); i++)
{
if ((uptr)JITCompile == s_pCurBlock[i].GetFnptr())
s_pCurBlock[i].SetFnptr((uptr)JITCompileInBlock);
@ -2749,7 +2745,7 @@ StartRecomp:
// case can result in very short blocks which should not issue branch tests for
// performance reasons.
int numinsts = (pc - startpc) / 4;
const int numinsts = (pc - startpc) / 4;
if (numinsts > 6)
SetBranchImm(pc);
else