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:
parent
063ffb4eab
commit
ab124776a0
36 changed files with 1719 additions and 233 deletions
|
|
@ -17,6 +17,7 @@ uint32_t ropJMP_r8(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t f
|
|||
dest_addr &= 0xffff;
|
||||
|
||||
uop_MOV_IMM(ir, IREG_pc, dest_addr);
|
||||
codegen_mark_code_present(block, cs+op_pc, 1);
|
||||
return -1;
|
||||
}
|
||||
uint32_t ropJMP_r16(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc)
|
||||
|
|
@ -27,6 +28,7 @@ uint32_t ropJMP_r16(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t
|
|||
dest_addr &= 0xffff;
|
||||
|
||||
uop_MOV_IMM(ir, IREG_pc, dest_addr);
|
||||
codegen_mark_code_present(block, cs+op_pc, 2);
|
||||
return -1;
|
||||
}
|
||||
uint32_t ropJMP_r32(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc)
|
||||
|
|
@ -35,6 +37,7 @@ uint32_t ropJMP_r32(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t
|
|||
uint32_t dest_addr = op_pc+4+offset;
|
||||
|
||||
uop_MOV_IMM(ir, IREG_pc, dest_addr);
|
||||
codegen_mark_code_present(block, cs+op_pc, 4);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -49,6 +52,7 @@ uint32_t ropJMP_far_16(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32
|
|||
uop_LOAD_FUNC_ARG_IMM(ir, 1, op_pc + 4);
|
||||
uop_CALL_FUNC(ir, loadcsjmp);
|
||||
|
||||
codegen_mark_code_present(block, cs+op_pc, 4);
|
||||
return -1;
|
||||
}
|
||||
uint32_t ropJMP_far_32(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc)
|
||||
|
|
@ -62,6 +66,7 @@ uint32_t ropJMP_far_32(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32
|
|||
uop_LOAD_FUNC_ARG_IMM(ir, 1, op_pc + 4);
|
||||
uop_CALL_FUNC(ir, loadcsjmp);
|
||||
|
||||
codegen_mark_code_present(block, cs+op_pc, 6);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -80,6 +85,7 @@ uint32_t ropCALL_r16(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t
|
|||
SUB_SP(ir, 2);
|
||||
uop_MOV_IMM(ir, IREG_pc, dest_addr);
|
||||
|
||||
codegen_mark_code_present(block, cs+op_pc, 2);
|
||||
return -1;
|
||||
}
|
||||
uint32_t ropCALL_r32(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc)
|
||||
|
|
@ -95,6 +101,7 @@ uint32_t ropCALL_r32(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t
|
|||
SUB_SP(ir, 4);
|
||||
uop_MOV_IMM(ir, IREG_pc, dest_addr);
|
||||
|
||||
codegen_mark_code_present(block, cs+op_pc, 4);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -146,6 +153,7 @@ uint32_t ropRET_imm_16(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32
|
|||
ADD_SP(ir, 2+offset);
|
||||
uop_MOVZX(ir, IREG_pc, IREG_temp0_W);
|
||||
|
||||
codegen_mark_code_present(block, cs+op_pc, 2);
|
||||
return -1;
|
||||
}
|
||||
uint32_t ropRET_imm_32(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc)
|
||||
|
|
@ -163,6 +171,7 @@ uint32_t ropRET_imm_32(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32
|
|||
}
|
||||
ADD_SP(ir, 4+offset);
|
||||
|
||||
codegen_mark_code_present(block, cs+op_pc, 2);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -243,6 +252,7 @@ uint32_t ropRETF_imm_16(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint3
|
|||
uop_CALL_FUNC(ir, loadcs);
|
||||
ADD_SP(ir, 4+offset);
|
||||
|
||||
codegen_mark_code_present(block, cs+op_pc, 2);
|
||||
return -1;
|
||||
}
|
||||
uint32_t ropRETF_imm_32(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc)
|
||||
|
|
@ -271,5 +281,6 @@ uint32_t ropRETF_imm_32(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint3
|
|||
uop_CALL_FUNC(ir, loadcs);
|
||||
ADD_SP(ir, 8+offset);
|
||||
|
||||
codegen_mark_code_present(block, cs+op_pc, 2);
|
||||
return -1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue