diff --git a/src/codegen.c b/src/codegen.c index 06f6213..a84e8cf 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -22,9 +22,10 @@ static struct x86seg *op_ea_seg; uint32_t op_32; int first_uop; + int TOP; } codegen_instructions[MAX_INSTRUCTION_COUNT]; -int codegen_get_instruction_uop(codeblock_t *block, uint32_t pc, int *first_instruction) +int codegen_get_instruction_uop(codeblock_t *block, uint32_t pc, int *first_instruction, int *TOP) { int c; @@ -33,6 +34,7 @@ int codegen_get_instruction_uop(codeblock_t *block, uint32_t pc, int *first_inst if (codegen_instructions[c].pc == pc) { *first_instruction = c; + *TOP = codegen_instructions[c].TOP; return codegen_instructions[c].first_uop; } } @@ -590,6 +592,7 @@ generate_call: codegen_instructions[block->ins].op_ssegs = last_op_ssegs; codegen_instructions[block->ins].op_ea_seg = last_op_ea_seg; codegen_instructions[block->ins].op_32 = last_op_32; + codegen_instructions[block->ins].TOP = cpu_state.TOP; codegen_instructions[block->ins].first_uop = ir->wr_pos; codegen_timing_opcode(opcode, fetchdat, op_32, op_pc); diff --git a/src/codegen.h b/src/codegen.h index 0f246b3..1d88e23 100644 --- a/src/codegen.h +++ b/src/codegen.h @@ -404,7 +404,7 @@ extern int codegen_in_recompile; void codegen_generate_reset(); -int codegen_get_instruction_uop(codeblock_t *block, uint32_t pc, int *first_instruction); +int codegen_get_instruction_uop(codeblock_t *block, uint32_t pc, int *first_instruction, int *TOP); void codegen_set_loop_start(struct ir_data_t *ir, int first_instruction); #ifdef DEBUG_EXTRA diff --git a/src/codegen_ops_helpers.c b/src/codegen_ops_helpers.c index 903a0e5..896ac29 100644 --- a/src/codegen_ops_helpers.c +++ b/src/codegen_ops_helpers.c @@ -34,9 +34,10 @@ int codegen_can_unroll_full(codeblock_t *block, ir_data_t *ir, uint32_t next_pc, int start; int max_unroll; int first_instruction; + int TOP = -1; /*Check that dest instruction was actually compiled into block*/ - start = codegen_get_instruction_uop(block, dest_addr, &first_instruction); + start = codegen_get_instruction_uop(block, dest_addr, &first_instruction, &TOP); /*Couldn't find any uOPs corresponding to the destination instruction*/ if (start == -1) @@ -48,8 +49,14 @@ int codegen_can_unroll_full(codeblock_t *block, ir_data_t *ir, uint32_t next_pc, return 0; } else + { start = ir->wr_pos; + TOP = cpu_state.TOP; + } } + + if (TOP != cpu_state.TOP) + return 0; max_unroll = UNROLL_MAX_UOPS / ((ir->wr_pos-start)+6); if (max_unroll > (UNROLL_MAX_REG_REFERENCES / max_version_refcount))