Skip to content

Commit

Permalink
Avoid saving ldr dest reg twice
Browse files Browse the repository at this point in the history
  • Loading branch information
Grarak committed Jan 12, 2025
1 parent afedac8 commit b95c155
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
14 changes: 13 additions & 1 deletion src/jit/emitter/emit_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ impl<const CPU: CpuType> JitAsm<'_, CPU> {

let slow_read_patch_label = block_asm.new_label();
let slow_read_label = block_asm.new_label();
let fast_mem_mark_dirty_label = block_asm.new_label();
let continue_label = block_asm.new_label();

block_asm.branch(slow_read_label, Cond::NV);
Expand Down Expand Up @@ -260,7 +261,11 @@ impl<const CPU: CpuType> JitAsm<'_, CPU> {
block_asm.mov(op0, (fast_read_value_reg, ShiftType::Ror, fast_read_addr_masked_reg));
}

block_asm.branch_fallthrough(continue_label, Cond::AL);
block_asm.mark_reg_dirty(op0, false);
if amount == MemoryAmount::Double {
block_asm.mark_reg_dirty(Reg::from(op0 as u8 + 1), false);
}
block_asm.branch_fallthrough(fast_mem_mark_dirty_label, Cond::AL);
block_asm.branch(slow_read_patch_label, Cond::AL);

block_asm.label_unlikely(slow_read_patch_label);
Expand Down Expand Up @@ -306,6 +311,13 @@ impl<const CPU: CpuType> JitAsm<'_, CPU> {
block_asm.restore_reg(Reg::CPSR);

block_asm.branch(continue_label, Cond::AL);

block_asm.label(fast_mem_mark_dirty_label);
block_asm.mark_reg_dirty(op0, true);
if amount == MemoryAmount::Double {
block_asm.mark_reg_dirty(Reg::from(op0 as u8 + 1), true);
}

block_asm.label(continue_label);

block_asm.free_reg(cpsr_backup_reg);
Expand Down
25 changes: 18 additions & 7 deletions src/jit/inst_jit_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,28 @@ pub unsafe extern "C" fn inst_slow_mem_patch(pc: u32) {
debug_assert_ne!(fast_mem_end, 0);

let mut fast_mem_start = 0;
let mut found_non_op = false;
let mut found_nop_op = 0;
for pc_offset in (4..256).step_by(4) {
let ptr = (fast_mem_end - pc_offset) as *const u32;
let opcode = ptr.read();
if found_non_op {
if opcode == nop_opcode {
fast_mem_start = ptr as usize;
break;
match found_nop_op {
0 => {
if opcode == nop_opcode {
found_nop_op = 1;
}
}
} else if opcode != nop_opcode {
found_non_op = true;
1 => {
if opcode != nop_opcode {
found_nop_op = 2;
}
}
2 => {
if opcode == nop_opcode {
fast_mem_start = ptr as usize;
break;
}
}
_ => {}
}
}
debug_assert_ne!(fast_mem_start, 0);
Expand Down

0 comments on commit b95c155

Please sign in to comment.