core: arm7tdmi: optimization: split flush_pipeline to arm and thumb

Reduces an if check


Former-commit-id: 4380c54f86238ef8818356f4593f59277f055fa6
This commit is contained in:
Michel Heily 2020-01-01 01:21:33 +02:00
parent 0872ff650a
commit 36cf4e62ce
4 changed files with 24 additions and 26 deletions

View file

@ -44,7 +44,7 @@ impl Core {
} }
self.pc = (self.pc as i32).wrapping_add(insn.branch_offset()) as u32 & !1; self.pc = (self.pc as i32).wrapping_add(insn.branch_offset()) as u32 & !1;
self.flush_pipeline(sb); self.flush_pipeline32(sb);
Ok(()) Ok(())
} }
@ -63,7 +63,7 @@ impl Core {
} }
self.pc = addr; self.pc = addr;
self.flush_pipeline(sb); // +1S+1N self.flush_pipeline32(sb); // +1S+1N
Ok(()) Ok(())
} }
@ -258,7 +258,7 @@ impl Core {
if let Some(result) = alu_res { if let Some(result) = alu_res {
if reg_rd == REG_PC { if reg_rd == REG_PC {
self.flush_pipeline(sb); self.flush_pipeline32(sb);
} }
self.set_reg(reg_rd, result as u32); self.set_reg(reg_rd, result as u32);
} }
@ -306,7 +306,7 @@ impl Core {
self.add_cycle(); self.add_cycle();
if insn.rd() == REG_PC { if insn.rd() == REG_PC {
self.flush_pipeline(sb); self.flush_pipeline32(sb);
} }
} else { } else {
let value = if insn.rd() == REG_PC { let value = if insn.rd() == REG_PC {
@ -374,7 +374,7 @@ impl Core {
self.add_cycle(); self.add_cycle();
if insn.rd() == REG_PC { if insn.rd() == REG_PC {
self.flush_pipeline(sb); self.flush_pipeline32(sb);
} }
} else { } else {
let value = if insn.rd() == REG_PC { let value = if insn.rd() == REG_PC {
@ -459,7 +459,7 @@ impl Core {
if psr_transfer { if psr_transfer {
self.transfer_spsr_mode(); self.transfer_spsr_mode();
} }
self.flush_pipeline(sb); self.flush_pipeline32(sb);
} }
if !full { if !full {
@ -504,7 +504,7 @@ impl Core {
if is_load { if is_load {
let val = self.ldr_word(addr as u32, sb); let val = self.ldr_word(addr as u32, sb);
self.set_reg(REG_PC, val & !3); self.set_reg(REG_PC, val & !3);
self.flush_pipeline(sb); self.flush_pipeline32(sb);
} else { } else {
self.write_32(addr as u32, self.pc + 4, sb); self.write_32(addr as u32, self.pc + 4, sb);
} }

View file

@ -367,18 +367,16 @@ impl Core {
Ok(()) Ok(())
} }
pub(super) fn flush_pipeline(&mut self, sb: &mut SysBus) { pub(super) fn flush_pipeline16(&mut self, sb: &mut SysBus) {
self.pipeline_state = PipelineState::Refill1; self.pipeline_state = PipelineState::Refill1;
match self.cpsr.state() {
CpuState::ARM => {
self.N_cycle32(sb, self.pc);
self.S_cycle32(sb, self.pc + 4);
}
CpuState::THUMB => {
self.N_cycle16(sb, self.pc); self.N_cycle16(sb, self.pc);
self.S_cycle16(sb, self.pc + 2); self.S_cycle16(sb, self.pc + 2);
} }
}
pub(super) fn flush_pipeline32(&mut self, sb: &mut SysBus) {
self.pipeline_state = PipelineState::Refill1;
self.N_cycle32(sb, self.pc);
self.S_cycle32(sb, self.pc + 4);
} }
fn trace_opcode(&self, insn: u32) { fn trace_opcode(&self, insn: u32) {

View file

@ -58,7 +58,7 @@ impl Core {
// Set PC to vector address // Set PC to vector address
self.pc = e as u32; self.pc = e as u32;
self.flush_pipeline(sb); self.flush_pipeline32(sb);
} }
pub fn irq(&mut self, sb: &mut SysBus) { pub fn irq(&mut self, sb: &mut SysBus) {

View file

@ -183,7 +183,7 @@ impl Core {
OpFormat5::ADD => { OpFormat5::ADD => {
self.set_reg(dst_reg, op1.wrapping_add(op2)); self.set_reg(dst_reg, op1.wrapping_add(op2));
if dst_reg == REG_PC { if dst_reg == REG_PC {
self.flush_pipeline(sb); self.flush_pipeline16(sb);
} }
} }
OpFormat5::CMP => { OpFormat5::CMP => {
@ -195,7 +195,7 @@ impl Core {
OpFormat5::MOV => { OpFormat5::MOV => {
self.set_reg(dst_reg, op2 as u32); self.set_reg(dst_reg, op2 as u32);
if dst_reg == REG_PC { if dst_reg == REG_PC {
self.flush_pipeline(sb); self.flush_pipeline16(sb);
} }
} }
} }
@ -409,7 +409,7 @@ impl Core {
if pc_lr_flag { if pc_lr_flag {
pop(self, sb, REG_PC); pop(self, sb, REG_PC);
self.pc = self.pc & !1; self.pc = self.pc & !1;
self.flush_pipeline(sb); self.flush_pipeline16(sb);
} }
self.S_cycle16(sb, self.pc + 2); self.S_cycle16(sb, self.pc + 2);
} else { } else {
@ -481,7 +481,7 @@ impl Core {
if is_load { if is_load {
let val = self.ldr_word(addr, sb); let val = self.ldr_word(addr, sb);
self.set_reg(REG_PC, val & !1); self.set_reg(REG_PC, val & !1);
self.flush_pipeline(sb); self.flush_pipeline16(sb);
} else { } else {
self.write_32(addr, self.pc + 2, sb); self.write_32(addr, self.pc + 2, sb);
} }
@ -507,7 +507,7 @@ impl Core {
let offset = insn.bcond_offset(); let offset = insn.bcond_offset();
self.S_cycle16(sb, self.pc); self.S_cycle16(sb, self.pc);
self.pc = (self.pc as i32).wrapping_add(offset) as u32; self.pc = (self.pc as i32).wrapping_add(offset) as u32;
self.flush_pipeline(sb); self.flush_pipeline16(sb);
Ok(()) Ok(())
} }
} }
@ -516,7 +516,7 @@ impl Core {
let offset = ((insn.offset11() << 21) >> 20) as i32; let offset = ((insn.offset11() << 21) >> 20) as i32;
self.pc = (self.pc as i32).wrapping_add(offset) as u32; self.pc = (self.pc as i32).wrapping_add(offset) as u32;
self.S_cycle16(sb, self.pc); self.S_cycle16(sb, self.pc);
self.flush_pipeline(sb); self.flush_pipeline16(sb);
Ok(()) Ok(())
} }
@ -533,7 +533,7 @@ impl Core {
self.pc = ((self.gpr[REG_LR] & !1) as i32).wrapping_add(off) as u32; self.pc = ((self.gpr[REG_LR] & !1) as i32).wrapping_add(off) as u32;
self.gpr[REG_LR] = next_pc; self.gpr[REG_LR] = next_pc;
self.flush_pipeline(sb); self.flush_pipeline16(sb);
Ok(()) Ok(())
} else { } else {
off = (off << 21) >> 9; off = (off << 21) >> 9;