Skip to content

Commit fb59d2c

Browse files
committed
winch: address review comments on aarch64 check_stack
1 parent 33fa104 commit fb59d2c

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

winch/codegen/src/isa/aarch64/asm.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,17 +1297,20 @@ pub(crate) struct PatchableAddToReg {
12971297
region: PatchRegion,
12981298

12991299
// The destination register for the add instruction.
1300-
reg: Reg,
1300+
reg: Writable<Reg>,
13011301

13021302
// The temporary register used to hold the immediate value.
1303-
tmp: Reg,
1303+
tmp: Writable<Reg>,
13041304
}
13051305

13061306
impl PatchableAddToReg {
1307-
/// Create a new [`PatchableAddToReg`] by capturing a region in the output buffer where the
1308-
/// add-with-immediate sequence occurs. The [`MachBuffer`] will have and add-with-immediate instruction
1309-
/// sequence present in that region, though it will add `0` until the `::finalize` method is called.
1310-
pub(crate) fn new(reg: Reg, tmp: Reg, buf: &mut MachBuffer<Inst>) -> Self {
1307+
/// Create a new [`PatchableAddToReg`] by capturing a region in the output
1308+
/// buffer containing an instruction sequence that loads an immediate into a
1309+
/// register `tmp`, then adds it to a register `reg`. The [`MachBuffer`]
1310+
/// will have that instruction sequence written to the region, though the
1311+
/// immediate loaded into `tmp` will be `0` until the `::finalize` method is
1312+
/// called.
1313+
pub(crate) fn new(reg: Writable<Reg>, tmp: Writable<Reg>, buf: &mut MachBuffer<Inst>) -> Self {
13111314
let insns = Self::add_immediate_instruction_sequence(reg, tmp, 0);
13121315
let open = buf.start_patchable();
13131316
buf.put_data(&insns);
@@ -1316,7 +1319,11 @@ impl PatchableAddToReg {
13161319
Self { region, reg, tmp }
13171320
}
13181321

1319-
fn add_immediate_instruction_sequence(reg: Reg, tmp: Reg, imm: i32) -> [u8; 12] {
1322+
fn add_immediate_instruction_sequence(
1323+
reg: Writable<Reg>,
1324+
tmp: Writable<Reg>,
1325+
imm: i32,
1326+
) -> [u8; 12] {
13201327
let imm_hi = imm as u64 & 0xffff_0000;
13211328
let imm_hi = MoveWideConst::maybe_from_u64(imm_hi).unwrap();
13221329

@@ -1325,18 +1332,15 @@ impl PatchableAddToReg {
13251332

13261333
let size = OperandSize::S64.into();
13271334

1328-
let tmp = writable!(tmp);
13291335
let tmp = tmp.map(Into::into);
1336+
let rd = reg.map(Into::into);
13301337

13311338
// This is "movz to bits 16-31 of 64 bit reg tmp and zero the rest"
13321339
let mov_insn = enc_move_wide(inst::MoveWideOp::MovZ, tmp, imm_hi, size);
13331340

13341341
// This is "movk to bits 0-15 of 64 bit reg tmp"
13351342
let movk_insn = enc_movk(tmp, imm_lo, size);
13361343

1337-
let rd = writable!(reg);
1338-
let rd = rd.map(Into::into);
1339-
13401344
// This is "add tmp to rd". The opcodes are somewhat buried in the
13411345
// instruction encoder so we just repeat them here.
13421346
let add_bits_31_21: u32 = 0b00001011_000 | (size.sf_bit() << 10);

winch/codegen/src/isa/aarch64/masm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl MacroAssembler {
6969
/// Add the maximum stack used to a register, recording an obligation to update the
7070
/// add-with-immediate instruction emitted to use the real stack max when the masm is being
7171
/// finalized.
72-
fn add_stack_max(&mut self, reg: Reg, tmp: Reg) {
72+
fn add_stack_max(&mut self, reg: WritableReg, tmp: WritableReg) {
7373
assert!(self.stack_max_use_add.is_none());
7474
let patch = PatchableAddToReg::new(reg, tmp, self.asm.buffer_mut());
7575
self.stack_max_use_add.replace(patch);
@@ -172,11 +172,11 @@ impl Masm for MacroAssembler {
172172
writable!(scratch_stk_limit),
173173
)?;
174174

175-
self.add_stack_max(scratch_stk_limit, scratch_tmp);
175+
self.add_stack_max(writable!(scratch_stk_limit), writable!(scratch_tmp));
176176

177177
self.asm
178178
.subs_rrr(scratch_stk_limit, regs::sp(), OperandSize::S64);
179-
self.asm.trapif(Cond::Gt, TrapCode::STACK_OVERFLOW);
179+
self.trapif(IntCmpKind::GtU, TrapCode::STACK_OVERFLOW)?;
180180

181181
Ok(())
182182
}

0 commit comments

Comments
 (0)