Recompiler fix

This commit is contained in:
SSimco
2024-02-16 22:50:07 +02:00
parent 36157ae5e7
commit 610cced493
3 changed files with 23 additions and 6 deletions
@@ -21,6 +21,16 @@
#include "BackendAArch64/BackendAArch64.h"
#endif
std::bitset<PPC_REC_ALIGN_TO_4MB(PPC_REC_CODE_AREA_SIZE/4)> ppcRecompilerDirectJumpTableInitialized;
void ppcRecompilerDirectJumpTableUpdateInitialzed(int position)
{
ppcRecompilerDirectJumpTableInitialized.set(position);
}
bool isppcRecompilerDirectJumpTableUpdateInitialzed(int position)
{
return ppcRecompilerDirectJumpTableInitialized.test(position);
}
struct PPCInvalidationRange
{
MPTR startAddress;
@@ -45,10 +55,12 @@ void ATTR_MS_ABI (*PPCRecompiler_leaveRecompilerCode_unvisited)();
PPCRecompilerInstanceData_t* ppcRecompilerInstanceData;
bool ppcRecompilerEnabled = false;
// this function does never block and can fail if the recompiler lock cannot be acquired immediately
void PPCRecompiler_visitAddressNoBlock(uint32 enterAddress)
{
if(!isppcRecompilerDirectJumpTableUpdateInitialzed(enterAddress/4))
return;
// quick read-only check without lock
if (ppcRecompilerInstanceData->ppcRecompilerDirectJumpTable[enterAddress / 4] != PPCRecompiler_leaveRecompilerCode_unvisited)
return;
@@ -107,6 +119,9 @@ void PPCRecompiler_attemptEnterWithoutRecompile(PPCInterpreter_t* hCPU, uint32 e
cemu_assert_debug(hCPU->instructionPointer == enterAddress);
if (ppcRecompilerEnabled == false)
return;
if(!isppcRecompilerDirectJumpTableUpdateInitialzed(enterAddress/4))
return;
auto funcPtr = ppcRecompilerInstanceData->ppcRecompilerDirectJumpTable[enterAddress / 4];
if (funcPtr != PPCRecompiler_leaveRecompilerCode_unvisited && funcPtr != PPCRecompiler_leaveRecompilerCode_visited)
{
@@ -122,6 +137,9 @@ void PPCRecompiler_attemptEnter(PPCInterpreter_t* hCPU, uint32 enterAddress)
return;
if (hCPU->remainingCycles <= 0)
return;
if(!isppcRecompilerDirectJumpTableUpdateInitialzed(enterAddress/4))
return;
auto funcPtr = ppcRecompilerInstanceData->ppcRecompilerDirectJumpTable[enterAddress / 4];
if (funcPtr == PPCRecompiler_leaveRecompilerCode_unvisited)
{
@@ -487,9 +505,9 @@ void PPCRecompiler_reserveLookupTableBlock(uint32 offset)
if (ppcRecompiler_reservedBlockMask[blockIndex])
return;
ppcRecompiler_reservedBlockMask[blockIndex] = true;
void* p1 = MemMapper::AllocateMemory(&(ppcRecompilerInstanceData->ppcRecompilerFuncTable[offset/4]), (PPC_REC_ALLOC_BLOCK_SIZE/4)*sizeof(void*), MemMapper::PAGE_PERMISSION::P_RW, true);
void* p3 = MemMapper::AllocateMemory(&(ppcRecompilerInstanceData->ppcRecompilerDirectJumpTable[offset/4]), (PPC_REC_ALLOC_BLOCK_SIZE/4)*sizeof(void*), MemMapper::PAGE_PERMISSION::P_RW, true);
ppcRecompilerDirectJumpTableUpdateInitialzed(offset/4);
if( !p1 || !p3 )
{
cemuLog_log(LogType::Force, "Failed to allocate memory for recompiler (0x{:08x})", offset);
@@ -499,6 +517,7 @@ void PPCRecompiler_reserveLookupTableBlock(uint32 offset)
for(uint32 i=0; i<PPC_REC_ALLOC_BLOCK_SIZE/4; i++)
{
ppcRecompilerInstanceData->ppcRecompilerDirectJumpTable[offset/4+i] = PPCRecompiler_leaveRecompilerCode_unvisited;
ppcRecompilerDirectJumpTableUpdateInitialzed(offset/4+1);
}
}
@@ -1,5 +1,7 @@
#pragma once
#include <bitset>
#include <condition_variable>
#define PPC_REC_CODE_AREA_START (0x00000000) // lower bound of executable memory area. Recompiler expects this address to be 0
#define PPC_REC_CODE_AREA_END (0x10000000) // upper bound of executable memory area
#define PPC_REC_CODE_AREA_SIZE (PPC_REC_CODE_AREA_END - PPC_REC_CODE_AREA_START)
-4
View File
@@ -65,9 +65,6 @@ bool ActiveSettings::FullscreenEnabled()
CPUMode ActiveSettings::GetCPUMode()
{
#ifndef ARCH_X86_64
return CPUMode::SinglecoreRecompiler;
#else
auto mode = g_current_game_profile->GetCPUMode().value_or(CPUMode::Auto);
if (mode == CPUMode::Auto)
@@ -81,7 +78,6 @@ CPUMode ActiveSettings::GetCPUMode()
mode = CPUMode::MulticoreRecompiler;
return mode;
#endif
}
uint8 ActiveSettings::GetTimerShiftFactor()