Skip to content

Commit cf08d39

Browse files
committed
Simplify read instructions
1 parent db1ab73 commit cf08d39

File tree

3 files changed

+9
-20
lines changed

3 files changed

+9
-20
lines changed

src/jit/emitter/emit_transfer.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,9 @@ impl<const CPU: CpuType> JitAsm<'_, CPU> {
155155
}
156156

157157
let fast_read_value_reg = block_asm.new_reg();
158-
let fast_read_value2_reg = block_asm.new_reg();
159158
let fast_read_next_addr_reg = block_asm.new_reg();
160159
let fast_read_addr_masked_reg = block_asm.new_reg();
161160

162-
let fast_read_assign_label = block_asm.new_label();
163161
let slow_read_label = block_asm.new_label();
164162
let continue_label = block_asm.new_label();
165163

@@ -169,27 +167,29 @@ impl<const CPU: CpuType> JitAsm<'_, CPU> {
169167
let base_ptr = mmu.get_base_tcm_ptr();
170168
let size = if amount == MemoryAmount::Double { MemoryAmount::Word.size() } else { amount.size() };
171169
block_asm.bic(fast_read_addr_masked_reg, addr_reg, 0xF0000000 | (size as u32 - 1));
170+
let needs_ror = amount == MemoryAmount::Word || amount == MemoryAmount::Double;
172171
block_asm.transfer_read(
173-
fast_read_value_reg,
172+
if needs_ror { fast_read_value_reg } else { op0.into() },
174173
fast_read_addr_masked_reg,
175174
base_ptr as u32,
176175
op.mem_transfer_single_signed(),
177176
if amount == MemoryAmount::Double { MemoryAmount::Word } else { amount },
178177
);
179-
if amount == MemoryAmount::Word || amount == MemoryAmount::Double {
178+
if needs_ror {
180179
block_asm.mov(fast_read_addr_masked_reg, (addr_reg.into(), ShiftType::Lsl, BlockOperand::from(3)));
181-
block_asm.mov(fast_read_value_reg, (fast_read_value_reg, ShiftType::Ror, fast_read_addr_masked_reg));
180+
block_asm.mov(op0, (fast_read_value_reg, ShiftType::Ror, fast_read_addr_masked_reg));
182181
}
183182
if amount == MemoryAmount::Double {
183+
let op0 = Reg::from(op0 as u8 + 1);
184184
block_asm.add(fast_read_next_addr_reg, addr_reg, 4);
185185
block_asm.bic(fast_read_addr_masked_reg, fast_read_next_addr_reg, 0xF0000000 | (size as u32 - 1));
186-
block_asm.transfer_read(fast_read_value2_reg, fast_read_addr_masked_reg, base_ptr as u32, false, MemoryAmount::Word);
186+
block_asm.transfer_read(fast_read_value_reg, fast_read_addr_masked_reg, base_ptr as u32, false, MemoryAmount::Word);
187187
block_asm.mov(fast_read_addr_masked_reg, (fast_read_next_addr_reg.into(), ShiftType::Lsl, BlockOperand::from(3)));
188-
block_asm.mov(fast_read_value2_reg, (fast_read_value2_reg, ShiftType::Ror, fast_read_addr_masked_reg));
188+
block_asm.mov(op0, (fast_read_value_reg, ShiftType::Ror, fast_read_addr_masked_reg));
189189
}
190190

191191
block_asm.nop();
192-
block_asm.branch_fallthrough(fast_read_assign_label, Cond::AL);
192+
block_asm.branch_fallthrough(continue_label, Cond::AL);
193193

194194
block_asm.label(slow_read_label);
195195
block_asm.save_context();
@@ -214,17 +214,10 @@ impl<const CPU: CpuType> JitAsm<'_, CPU> {
214214

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

217-
block_asm.label(fast_read_assign_label);
218-
block_asm.mov(op0, fast_read_value_reg);
219-
if amount == MemoryAmount::Double {
220-
block_asm.mov(Reg::from(op0 as u8 + 1), fast_read_value2_reg);
221-
}
222-
223217
block_asm.label(continue_label);
224218

225219
block_asm.free_reg(fast_read_addr_masked_reg);
226220
block_asm.free_reg(fast_read_next_addr_reg);
227-
block_asm.free_reg(fast_read_value2_reg);
228221
block_asm.free_reg(fast_read_value_reg);
229222
block_asm.free_reg(op0_addr_reg);
230223
block_asm.free_reg(addr_reg);

src/jit/jit_asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ fn emit_code_block_internal<const CPU: CpuType, const THUMB: bool>(asm: &mut Jit
186186
}
187187

188188
let jit_entry = {
189-
// unsafe { BLOCK_LOG = guest_pc == 0x20025dc };
189+
// unsafe { BLOCK_LOG = guest_pc == 0x20019ec };
190190

191191
let mut block_asm = asm.new_block_asm(false);
192192

src/jit/jit_memory.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,6 @@ impl JitMemory {
355355
}
356356

357357
*host_pc = fast_mem_end + 4;
358-
359-
// let cache_begin = fast_mem_begin & !(PAGE_SIZE - 1);
360-
// let size = utils::align_up(fast_mem_exit - cache_begin, PAGE_SIZE);
361-
// unsafe { flush_icache(cache_begin as _, size) };
362358
unsafe { flush_icache(fast_mem_begin as _, fast_mem_exit - fast_mem_begin + 4) }
363359
true
364360
}

0 commit comments

Comments
 (0)