Merge pull request #112 from davidgfnet/master

Enable runtime dynarec enable/disable
This commit is contained in:
Autechre 2021-03-18 03:15:03 +01:00 committed by GitHub
commit 5ef784ab8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 43 additions and 58 deletions

View File

@ -31,6 +31,7 @@
#define PATH_SEPARATOR_CHAR '/' #define PATH_SEPARATOR_CHAR '/'
#endif #endif
/* On x86 we pass arguments via registers instead of stack */
#ifdef X86_ARCH #ifdef X86_ARCH
#define function_cc __attribute__((regparm(2))) #define function_cc __attribute__((regparm(2)))
#else #else
@ -55,8 +56,6 @@
// functions on PSP for vastly improved memstick performance. // functions on PSP for vastly improved memstick performance.
#ifdef PSP #ifdef PSP
#define fastcall
#include <pspkernel.h> #include <pspkernel.h>
#include <pspdebug.h> #include <pspdebug.h>
#include <pspctrl.h> #include <pspctrl.h>
@ -64,13 +63,8 @@
#include <pspaudio.h> #include <pspaudio.h>
#include <pspaudiolib.h> #include <pspaudiolib.h>
#include <psprtc.h> #include <psprtc.h>
#define convert_palette(value) \
value = ((value & 0x7FE0) << 1) | (value & 0x1F)
#include <time.h> #include <time.h>
#else #else
typedef unsigned char u8; typedef unsigned char u8;
typedef signed char s8; typedef signed char s8;
typedef unsigned short int u16; typedef unsigned short int u16;
@ -79,10 +73,14 @@
typedef signed int s32; typedef signed int s32;
typedef unsigned long long int u64; typedef unsigned long long int u64;
typedef signed long long int s64; typedef signed long long int s64;
#endif
#ifdef USE_BGR_FORMAT
#define convert_palette(value) \
value = ((value & 0x7FE0) << 1) | (value & 0x1F)
#else
#define convert_palette(value) \ #define convert_palette(value) \
value = ((value & 0x1F) << 11) | ((value & 0x03E0) << 1) | (value >> 10) value = ((value & 0x1F) << 11) | ((value & 0x03E0) << 1) | (value >> 10)
#endif #endif
#define GBA_SCREEN_WIDTH (240) #define GBA_SCREEN_WIDTH (240)

1
cpu.h
View File

@ -174,6 +174,7 @@ extern u32 *rom_branch_hash[ROM_BRANCH_HASH_SIZE];
void flush_translation_cache_rom(void); void flush_translation_cache_rom(void);
void flush_translation_cache_ram(void); void flush_translation_cache_ram(void);
void dump_translation_cache(void); void dump_translation_cache(void);
void wipe_caches(void);
extern u32 reg_mode[7][7]; extern u32 reg_mode[7][7];
extern u32 spsr[6]; extern u32 spsr[6];

View File

@ -3686,6 +3686,17 @@ void flush_translation_cache_rom(void)
memset(rom_branch_hash, 0, sizeof(rom_branch_hash)); memset(rom_branch_hash, 0, sizeof(rom_branch_hash));
} }
void wipe_caches(void)
{
/* Ensure we wipe everything including the SMC mirrors */
flush_translation_cache_rom();
ewram_code_min = 0;
ewram_code_max = 0x3FFFF;
iwram_code_min = 0;
iwram_code_max = 0x7FFF;
flush_translation_cache_ram();
}
#define cache_dump_prefix "" #define cache_dump_prefix ""
void dump_translation_cache(void) void dump_translation_cache(void)

View File

@ -3394,10 +3394,7 @@ void gba_load_state(const void* src)
#ifdef HAVE_DYNAREC #ifdef HAVE_DYNAREC
if (dynarec_enable) if (dynarec_enable)
{ wipe_caches();
flush_translation_cache_ram();
flush_translation_cache_rom();
}
#endif #endif
oam_update = 1; oam_update = 1;

View File

@ -408,7 +408,13 @@ void retro_get_system_av_info(struct retro_system_av_info* info)
void retro_init(void) void retro_init(void)
{ {
#if defined(_3DS) && defined(HAVE_DYNAREC) #if defined(HAVE_DYNAREC)
#if defined(HAVE_MMAP)
rom_translation_cache = mmap(NULL, ROM_TRANSLATION_CACHE_SIZE,
PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0);
ram_translation_cache = mmap(NULL, RAM_TRANSLATION_CACHE_SIZE,
PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0);
#elif defined(_3DS)
if (__ctr_svchax && !translation_caches_inited) if (__ctr_svchax && !translation_caches_inited)
{ {
uint32_t currentHandle; uint32_t currentHandle;
@ -430,9 +436,7 @@ void retro_init(void)
ctr_flush_invalidate_cache(); ctr_flush_invalidate_cache();
translation_caches_inited = 1; translation_caches_inited = 1;
} }
#endif #elif defined(VITA)
#if defined(VITA) && defined(HAVE_DYNAREC)
if(!translation_caches_inited){ if(!translation_caches_inited){
void* currentHandle; void* currentHandle;
@ -457,7 +461,7 @@ void retro_init(void)
sceKernelOpenVMDomain(); sceKernelOpenVMDomain();
translation_caches_inited = 1; translation_caches_inited = 1;
} }
#endif
#endif #endif
if (!gamepak_rom) if (!gamepak_rom)
@ -641,16 +645,19 @@ static void check_variables(int started_from_load)
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{ {
if (started_from_load) int prevvalue = dynarec_enable;
{
if (strcmp(var.value, "disabled") == 0) if (strcmp(var.value, "disabled") == 0)
dynarec_enable = 0; dynarec_enable = 0;
else if (strcmp(var.value, "enabled") == 0) else if (strcmp(var.value, "enabled") == 0)
dynarec_enable = 1; dynarec_enable = 1;
}
if (dynarec_enable != prevvalue)
wipe_caches();
} }
else else
dynarec_enable = 1; dynarec_enable = 1;
#else
dynarec_enable = 0;
#endif #endif
var.key = "gpsp_frameskip"; var.key = "gpsp_frameskip";
@ -779,34 +786,6 @@ bool retro_load_game(const struct retro_game_info* info)
check_variables(1); check_variables(1);
set_input_descriptors(); set_input_descriptors();
#if defined(HAVE_DYNAREC)
if (dynarec_enable)
{
#if defined(HAVE_MMAP)
rom_translation_cache = mmap(NULL, ROM_TRANSLATION_CACHE_SIZE,
PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0);
ram_translation_cache = mmap(NULL, RAM_TRANSLATION_CACHE_SIZE,
PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0);
rom_translation_ptr = rom_translation_cache;
ram_translation_ptr = ram_translation_cache;
#elif defined(_3DS)
dynarec_enable = __ctr_svchax;
rom_translation_ptr = rom_translation_cache;
ram_translation_ptr = ram_translation_cache;
#elif defined(PSP) || defined(VITA)
dynarec_enable = 1;
rom_translation_ptr = rom_translation_cache;
ram_translation_ptr = ram_translation_cache;
#endif
}
else
dynarec_enable = 0;
#else
dynarec_enable = 0;
#endif
char filename_bios[MAX_PATH]; char filename_bios[MAX_PATH];
const char* dir = NULL; const char* dir = NULL;

View File

@ -147,7 +147,7 @@ struct retro_core_option_definition option_defs_us[] = {
#if defined(HAVE_DYNAREC) #if defined(HAVE_DYNAREC)
{ {
"gpsp_drc", "gpsp_drc",
"Dynamic Recompiler (Restart)", "Dynamic Recompiler",
"Dynamically recompile CPU instructions to native instructions. Greatly improves performance, but may reduce accuracy.", "Dynamically recompile CPU instructions to native instructions. Greatly improves performance, but may reduce accuracy.",
{ {
{ "enabled", NULL }, { "enabled", NULL },

3
main.c
View File

@ -114,8 +114,7 @@ void init_main(void)
video_count = 960; video_count = 960;
#ifdef HAVE_DYNAREC #ifdef HAVE_DYNAREC
flush_translation_cache_rom(); wipe_caches();
flush_translation_cache_ram();
init_emitter(); init_emitter();
#endif #endif
} }

View File

@ -538,7 +538,7 @@ _execute_arm_translate:
# (if the CPU is halted, do not start executing but # (if the CPU is halted, do not start executing but
# loop in the alert loop until it wakes up) # loop in the alert loop until it wakes up)
cmp $0, CPU_HALT_STATE(%ebx) cmpl $0, CPU_HALT_STATE(%ebx)
je 1f je 1f
call alert_loop # Need to push something to the stack call alert_loop # Need to push something to the stack