CPU/NewRec: Allocate callee-saved registers before caller-saved

This commit is contained in:
Stenzek 2023-12-21 01:53:14 +10:00
parent b7c3c76014
commit 8fe6ef1fa8
No known key found for this signature in database

View file

@ -525,11 +525,20 @@ u32 CPU::NewRec::Compiler::GetFreeHostReg(u32 flags)
{
const u32 req_flags = HR_USABLE | (flags & HR_CALLEE_SAVED);
u32 fallback = NUM_HOST_REGS;
for (u32 i = 0; i < NUM_HOST_REGS; i++)
{
if ((m_host_regs[i].flags & (req_flags | HR_NEEDED | HR_ALLOCATED)) == req_flags)
return i;
{
// Prefer callee-saved registers.
if (m_host_regs[i].flags & HR_CALLEE_SAVED)
return i;
else if (fallback == NUM_HOST_REGS)
fallback = i;
}
}
if (fallback != NUM_HOST_REGS)
return fallback;
// find register with lowest counter
u32 lowest = NUM_HOST_REGS;