Rework self modifying code handling.

Code blocks now have a varying level of granularity in the page and dirty masks.
Most blocks have 64-byte granularity, but blocks that are repeatedly modified
drop to 1-byte granularity. This reduces the maximum size of the affected block
significantly, but reduces recompilation due to data located too close to code.

If the block is still marked as dirty, then it is recompiled without any
immediate instruction parameters being baked into the recompiled code, instead
being fetched from the RAM array as needed. This severely reduces recompilation
rates on some SMC-heavy games, eg Duke Nukem 3D, System Shock, Screamer etc,
giving a major speedup.
This commit is contained in:
SarahW 2019-03-16 14:53:26 +00:00
commit ab124776a0
36 changed files with 1719 additions and 233 deletions

View file

@ -112,6 +112,13 @@ mem_mapping_t bios_high_mapping[8];
extern mem_mapping_t ram_high_mapping;
extern mem_mapping_t ram_remapped_mapping;
extern uint64_t *byte_dirty_mask;
extern uint64_t *byte_code_present_mask;
#define PAGE_BYTE_MASK_SHIFT 6
#define PAGE_BYTE_MASK_OFFSET_MASK 63
#define PAGE_BYTE_MASK_MASK 63
#define EVICT_NOT_IN_LIST ((uint32_t)-1)
typedef struct page_t
{
@ -121,14 +128,17 @@ typedef struct page_t
uint8_t *mem;
uint16_t block[4], block_2[4];
uint16_t block, block_2;
/*Head of codeblock tree associated with this page*/
uint16_t head;
uint64_t code_present_mask[4], dirty_mask[4];
uint64_t code_present_mask, dirty_mask;
uint32_t evict_prev, evict_next;
uint64_t *byte_dirty_mask;
uint64_t *byte_code_present_mask;
} page_t;
extern page_t *pages;