Skip to content

Commit ad623db

Browse files
committed
Simplify cpsr store
1 parent f9f53c2 commit ad623db

File tree

3 files changed

+15
-54
lines changed

3 files changed

+15
-54
lines changed

src/jit/assembler/basic_block.rs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,25 +79,18 @@ impl BasicBlock {
7979
guest_reg,
8080
reg_mapped: if guest_reg == Reg::PC { last_pc_reg } else { guest_reg.into() },
8181
thread_regs_addr_reg,
82-
tmp_guest_cpsr_reg,
8382
});
8483
}
8584
}
8685
last_guest_regs_outputs.fill(None);
8786
add_inst = false;
8887
}
89-
BlockInst::SaveReg {
90-
guest_reg,
91-
thread_regs_addr_reg,
92-
tmp_guest_cpsr_reg,
93-
..
94-
} => {
88+
BlockInst::SaveReg { guest_reg, thread_regs_addr_reg, .. } => {
9589
if guest_reg == Reg::PC {
9690
asm.buf.insts[i] = BlockInst::SaveReg {
9791
guest_reg: Reg::PC,
9892
reg_mapped: last_pc_reg,
9993
thread_regs_addr_reg,
100-
tmp_guest_cpsr_reg,
10194
}
10295
}
10396
last_guest_regs_outputs[guest_reg as usize] = None;
@@ -185,28 +178,24 @@ impl BasicBlock {
185178
op: BlockSystemRegOp::Mrs,
186179
operand: Reg::CPSR.into(),
187180
});
181+
188182
self.insts_link.insert_end(asm.buf.insts.len());
189183
asm.buf.insts.push(BlockInst::Transfer {
190184
op: BlockTransferOp::Read,
191185
operands: [asm.tmp_guest_cpsr_reg.into(), asm.thread_regs_addr_reg.into(), (Reg::CPSR as u32 * 4).into()],
192186
signed: false,
193-
amount: MemoryAmount::Word,
187+
amount: MemoryAmount::Half,
194188
add_to_base: true,
195189
});
190+
196191
self.insts_link.insert_end(asm.buf.insts.len());
197192
asm.buf.insts.push(BlockInst::Alu3 {
198193
op: BlockAluOp::And,
199194
operands: [Reg::CPSR.into(), Reg::CPSR.into(), (0xF8, ShiftType::Ror, 4).into()],
200195
set_cond: BlockAluSetCond::None,
201196
thumb_pc_aligned: false,
202197
});
203-
self.insts_link.insert_end(asm.buf.insts.len());
204-
asm.buf.insts.push(BlockInst::Alu3 {
205-
op: BlockAluOp::Bic,
206-
operands: [asm.tmp_guest_cpsr_reg.into(), asm.tmp_guest_cpsr_reg.into(), (0xF8, ShiftType::Ror, 4).into()],
207-
set_cond: BlockAluSetCond::None,
208-
thumb_pc_aligned: false,
209-
});
198+
210199
self.insts_link.insert_end(asm.buf.insts.len());
211200
asm.buf.insts.push(BlockInst::Alu3 {
212201
op: BlockAluOp::Orr,
@@ -279,7 +268,6 @@ impl BasicBlock {
279268
guest_reg,
280269
reg_mapped: guest_reg.into(),
281270
thread_regs_addr_reg: asm.thread_regs_addr_reg,
282-
tmp_guest_cpsr_reg: asm.tmp_guest_cpsr_reg,
283271
});
284272
}
285273
}

src/jit/assembler/block_asm.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,6 @@ impl<'a> BlockAsm<'a> {
385385
guest_reg,
386386
reg_mapped: BlockReg::from(guest_reg),
387387
thread_regs_addr_reg: self.thread_regs_addr_reg,
388-
tmp_guest_cpsr_reg: self.tmp_guest_cpsr_reg,
389388
});
390389
}
391390

src/jit/assembler/block_inst.rs

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ impl BlockInst {
142142
guest_reg,
143143
reg_mapped,
144144
thread_regs_addr_reg,
145-
tmp_guest_cpsr_reg,
146145
} => {
147146
let mut inputs = BlockRegSet::new();
148147
let mut outputs = BlockRegSet::new();
@@ -151,7 +150,6 @@ impl BlockInst {
151150
inputs += BlockReg::Fixed(Reg::CPSR);
152151
inputs += *thread_regs_addr_reg;
153152
outputs += *reg_mapped;
154-
outputs += *tmp_guest_cpsr_reg;
155153
}
156154
_ => {
157155
inputs += *reg_mapped;
@@ -335,16 +333,10 @@ impl BlockInst {
335333
BlockInst::Bfc { operand, .. } => Self::replace_reg(operand, old, new),
336334
BlockInst::Bfi { operands, .. } => Self::replace_reg(&mut operands[0], old, new),
337335
BlockInst::SaveContext { tmp_guest_cpsr_reg, .. } => Self::replace_reg(tmp_guest_cpsr_reg, old, new),
338-
BlockInst::SaveReg {
339-
guest_reg,
340-
reg_mapped,
341-
tmp_guest_cpsr_reg,
342-
..
343-
} => {
336+
BlockInst::SaveReg { guest_reg, reg_mapped, .. } => {
344337
if *guest_reg == Reg::CPSR {
345338
Self::replace_reg(reg_mapped, old, new);
346339
}
347-
Self::replace_reg(tmp_guest_cpsr_reg, old, new)
348340
}
349341
BlockInst::RestoreReg {
350342
guest_reg,
@@ -384,13 +376,11 @@ impl BlockInst {
384376
BlockInst::SaveContext { .. } => {
385377
unreachable!()
386378
}
387-
BlockInst::SaveReg {
388-
reg_mapped,
389-
thread_regs_addr_reg,
390-
tmp_guest_cpsr_reg,
391-
..
379+
BlockInst::SaveReg { reg_mapped, thread_regs_addr_reg, .. } => {
380+
Self::replace_reg(reg_mapped, old, new);
381+
Self::replace_reg(thread_regs_addr_reg, old, new);
392382
}
393-
| BlockInst::RestoreReg {
383+
BlockInst::RestoreReg {
394384
reg_mapped,
395385
thread_regs_addr_reg,
396386
tmp_guest_cpsr_reg,
@@ -411,26 +401,11 @@ impl BlockInst {
411401
}
412402
}
413403

414-
fn save_guest_cpsr(opcodes: &mut Vec<u32>, thread_regs_addr_reg: Reg, host_reg: Reg, guest_reg: Reg) {
404+
fn save_guest_cpsr(opcodes: &mut Vec<u32>, thread_regs_addr_reg: Reg, host_reg: Reg) {
415405
opcodes.push(Mrs::cpsr(host_reg, Cond::AL));
416-
opcodes.push(LdrStrImm::ldr_offset_al(guest_reg, thread_regs_addr_reg, Reg::CPSR as u16 * 4));
417406
// Only copy the cond flags from host cpsr
418-
opcodes.push(AluImm::and(
419-
host_reg,
420-
host_reg,
421-
0xF8,
422-
4, // 8 Bytes, steps of 2
423-
Cond::AL,
424-
));
425-
opcodes.push(AluImm::bic(
426-
guest_reg,
427-
guest_reg,
428-
0xF8,
429-
4, // 8 Bytes, steps of 2
430-
Cond::AL,
431-
));
432-
opcodes.push(AluShiftImm::orr_al(guest_reg, host_reg, guest_reg));
433-
opcodes.push(LdrStrImm::str_offset_al(guest_reg, thread_regs_addr_reg, Reg::CPSR as u16 * 4));
407+
opcodes.push(AluShiftImm::mov(host_reg, host_reg, ShiftType::Lsr, 16, Cond::AL));
408+
opcodes.push(LdrStrImmSBHD::strh(host_reg, thread_regs_addr_reg, Reg::CPSR as u8 * 4 + 2, Cond::AL));
434409
}
435410

436411
pub fn emit_opcode(&mut self, opcodes: &mut Vec<u32>, opcode_index: usize, branch_placeholders: &mut Vec<usize>, opcodes_offset: usize, used_host_regs: RegReserve) {
@@ -588,9 +563,9 @@ impl BlockInst {
588563
guest_reg,
589564
reg_mapped,
590565
thread_regs_addr_reg,
591-
tmp_guest_cpsr_reg,
566+
..
592567
} => match guest_reg {
593-
Reg::CPSR => Self::save_guest_cpsr(opcodes, thread_regs_addr_reg.as_fixed(), reg_mapped.as_fixed(), tmp_guest_cpsr_reg.as_fixed()),
568+
Reg::CPSR => Self::save_guest_cpsr(opcodes, thread_regs_addr_reg.as_fixed(), reg_mapped.as_fixed()),
594569
_ => opcodes.push(LdrStrImm::str_offset_al(reg_mapped.as_fixed(), thread_regs_addr_reg.as_fixed(), *guest_reg as u16 * 4)),
595570
},
596571
BlockInst::RestoreReg {
@@ -769,7 +744,6 @@ pub enum BlockInst {
769744
guest_reg: Reg,
770745
reg_mapped: BlockReg,
771746
thread_regs_addr_reg: BlockReg,
772-
tmp_guest_cpsr_reg: BlockReg,
773747
},
774748
RestoreReg {
775749
guest_reg: Reg,

0 commit comments

Comments
 (0)