Bring back RichardG's recompiler changes.

This commit is contained in:
OBattler
2025-12-17 19:33:29 +01:00
parent cc46ea4d8e
commit 528649b2f2
4 changed files with 33 additions and 9 deletions

View File

@@ -331,6 +331,7 @@ int scrnsz_y = SCREEN_RES_Y; /* current screen size, Y */
int config_changed; /* config has changed */
int title_update;
int framecountx = 0;
int seconds_elapsed = 0;
int hard_reset_pending = 0;
#if 0
@@ -1974,6 +1975,8 @@ pc_onesec(void)
framecount = 0;
title_update = 1;
seconds_elapsed++;
}
void

View File

@@ -392,10 +392,9 @@ static inline void __attribute__((optimize("O2")))
#else
static __inline void
#endif
exec386_dynarec_dyn(void)
exec386_dynarec_dyn(uint32_t phys_addr, page_t *page)
{
uint32_t start_pc = 0;
uint32_t phys_addr = get_phys(cs + cpu_state.pc);
int hash = HASH(phys_addr);
# ifdef USE_NEW_DYNAREC
codeblock_t *block = &codeblock[codeblock_hash[hash]];
@@ -410,8 +409,6 @@ exec386_dynarec_dyn(void)
if (block && !cpu_state.abrt)
# endif
{
page_t *page = &pages[phys_addr >> 12];
/* Block must match current CS, PC, code segment size,
and physical address. The physical address check will
also catch any page faults at this stage */
@@ -445,16 +442,30 @@ exec386_dynarec_dyn(void)
if (valid_block && (block->page_mask & *block->dirty_mask)) {
# ifdef USE_NEW_DYNAREC
codegen_check_flush(page, page->dirty_mask, phys_addr);
if (block->pc == BLOCK_PC_INVALID)
if (block->pc == BLOCK_PC_INVALID) {
valid_block = 0;
else if (block->flags & CODEBLOCK_IN_DIRTY_LIST)
goto invalid_block;
} else if (block->flags & CODEBLOCK_IN_DIRTY_LIST) {
block->flags &= ~CODEBLOCK_WAS_RECOMPILED;
invalid_block:
# else
codegen_check_flush(page, page->dirty_mask[(phys_addr >> 10) & 3], phys_addr);
page->dirty_mask[(phys_addr >> 10) & 3] = 0;
if (!block->valid)
if (!block->valid) {
valid_block = 0;
# endif
if (page->inv_timestamp != seconds_elapsed) {
page->inv_timestamp = seconds_elapsed;
page->inv_count = 1;
} else {
page->inv_count++;
# define INVALIDATION_LIMIT 100 /* amount of invalidations *per second* to kick a page to the interpreter */
# ifdef ENABLE_386_DYNAREC_LOG
if (page->inv_count >= INVALIDATION_LIMIT)
x386_dynarec_log("Forcing interpreter on page %08X\n", phys_addr & 0xfffff000);
# endif
}
}
}
if (valid_block && block->page_mask2) {
/* We don't want the second page to cause a page
@@ -779,11 +790,14 @@ exec386_dynarec(int32_t cycs)
cycles_old = cycles;
oldtsc = tsc;
tsc_old = tsc;
if (cpu_force_interpreter || cpu_override_dynarec || (!CACHE_ON())) /*Interpret block*/
uint32_t phys_addr = get_phys(cs + cpu_state.pc);
page_t *page = &pages[phys_addr >> 12];
if (cpu_force_interpreter || cpu_override_dynarec || (page->inv_count >= INVALIDATION_LIMIT) || (!CACHE_ON())) /*Interpret block*/
{
exec386_dynarec_int();
} else {
exec386_dynarec_dyn();
exec386_dynarec_dyn(phys_addr, page);
}
if (cpu_init) {

View File

@@ -321,6 +321,7 @@ extern void do_pause(int p);
extern double isa_timing;
extern int io_delay;
extern int framecountx;
extern int seconds_elapsed;
extern volatile int cpu_thread_run;
extern uint8_t postcard_codes[POSTCARDS_NUM];

View File

@@ -224,6 +224,9 @@ typedef struct page_t {
uint64_t *byte_dirty_mask;
uint64_t *byte_code_present_mask;
uint32_t inv_count;
uint32_t inv_timestamp;
} page_t;
extern uint32_t purgable_page_list_head;
@@ -250,6 +253,9 @@ typedef struct _page_ {
/*Head of codeblock tree associated with this page*/
struct codeblock_t *head;
uint32_t inv_count;
uint32_t inv_timestamp;
} page_t;
#endif