Skip to content

Commit e127c8d

Browse files
committed
Simplify jit memory
1 parent edfb02f commit e127c8d

File tree

3 files changed

+124
-283
lines changed

3 files changed

+124
-283
lines changed

src/jit/jit_asm.rs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::jit::assembler::BlockAsmBuf;
66
use crate::jit::disassembler::lookup_table::lookup_opcode;
77
use crate::jit::disassembler::thumb::lookup_table_thumb::lookup_thumb_opcode;
88
use crate::jit::inst_info::InstInfo;
9-
use crate::jit::jit_memory::JitInsertArgs;
109
use crate::jit::op::Op;
1110
use crate::jit::reg::Reg;
1211
use crate::jit::reg::{reg_reserve, RegReserve};
@@ -101,11 +100,20 @@ impl JitRuntimeData {
101100
}
102101
}
103102

104-
pub extern "C" fn emit_code_block<const CPU: CpuType, const THUMB: bool>() {
103+
pub extern "C" fn emit_code_block<const CPU: CpuType>() {
105104
let asm = unsafe { get_jit_asm_ptr::<CPU>().as_mut().unwrap_unchecked() };
106105

107106
let guest_pc = get_regs!(asm.emu, CPU).pc;
108-
let guest_pc = if THUMB { guest_pc & !1 } else { guest_pc & !3 };
107+
let thumb = (guest_pc & 1) == 1;
108+
if thumb {
109+
emit_code_block_internal::<CPU, true>(guest_pc & !1)
110+
} else {
111+
emit_code_block_internal::<CPU, false>(guest_pc & !3)
112+
}
113+
}
114+
115+
fn emit_code_block_internal<const CPU: CpuType, const THUMB: bool>(guest_pc: u32) {
116+
let asm = unsafe { get_jit_asm_ptr::<CPU>().as_mut().unwrap_unchecked() };
109117

110118
{
111119
let mut index = 0;
@@ -170,7 +178,7 @@ pub extern "C" fn emit_code_block<const CPU: CpuType, const THUMB: bool>() {
170178
println!("0x{opcode:x},");
171179
}
172180
}
173-
let insert_entry = get_jit_mut!(asm.emu).insert_block::<CPU, THUMB>(&opcodes, JitInsertArgs::new(guest_pc, asm.jit_buf.insts_cycle_counts.clone()));
181+
let insert_entry = get_jit_mut!(asm.emu).insert_block::<CPU>(&opcodes, guest_pc);
174182
let jit_entry: extern "C" fn() = unsafe { mem::transmute(insert_entry) };
175183

176184
if DEBUG_LOG {
@@ -182,12 +190,17 @@ pub extern "C" fn emit_code_block<const CPU: CpuType, const THUMB: bool>() {
182190
}
183191

184192
#[inline]
185-
fn execute_internal<const CPU: CpuType, const THUMB: bool>(guest_pc: u32) -> u16 {
193+
fn execute_internal<const CPU: CpuType>(guest_pc: u32) -> u16 {
186194
let asm = unsafe { get_jit_asm_ptr::<CPU>().as_mut().unwrap_unchecked() };
187195

188-
get_regs_mut!(asm.emu, CPU).set_thumb(THUMB);
196+
let thumb = (guest_pc & 1) == 1;
197+
debug_println!("{:?} Execute {:x} thumb {}", CPU, guest_pc, thumb);
189198

190-
let jit_entry: extern "C" fn() = unsafe { mem::transmute(get_jit!(asm.emu).get_jit_start_addr::<CPU, THUMB>(guest_pc)) };
199+
get_regs_mut!(asm.emu, CPU).set_thumb(thumb);
200+
201+
let guest_pc = if thumb { guest_pc & !1 } else { guest_pc & !3 };
202+
let jit_entry = get_jit!(asm.emu).get_jit_start_addr::<CPU>(guest_pc);
203+
let jit_entry: extern "C" fn() = unsafe { mem::transmute(jit_entry) };
191204

192205
debug_println!("{CPU:?} Enter jit addr {:x}", jit_entry as usize);
193206

@@ -214,7 +227,7 @@ fn execute_internal<const CPU: CpuType, const THUMB: bool>(guest_pc: u32) -> u16
214227

215228
if DEBUG_LOG && DEBUG_LOG_BRANCH_OUT {
216229
println!("{:?} reading opcode of breakout at {:x} executed cycles {executed_cycles}", CPU, asm.runtime_data.branch_out_pc);
217-
let inst_info = if THUMB {
230+
let inst_info = if thumb {
218231
let opcode = asm.emu.mem_read::<CPU, _>(asm.runtime_data.branch_out_pc);
219232
let (op, func) = lookup_thumb_opcode(opcode);
220233
InstInfo::from(func(opcode, *op))
@@ -252,14 +265,7 @@ impl<'a, const CPU: CpuType> JitAsm<'a, CPU> {
252265
#[inline(always)]
253266
pub fn execute(&mut self) -> u16 {
254267
let entry = get_regs!(self.emu, CPU).pc;
255-
256-
let thumb = (entry & 1) == 1;
257-
debug_println!("{:?} Execute {:x} thumb {}", CPU, entry, thumb);
258-
if thumb {
259-
execute_internal::<CPU, true>(entry & !1)
260-
} else {
261-
execute_internal::<CPU, false>(entry & !3)
262-
}
268+
execute_internal::<CPU>(entry)
263269
}
264270
}
265271

0 commit comments

Comments
 (0)