Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/disas/winch/aarch64/call/multi.wat
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
;; mov sp, x28
;; mov x1, x9
;; mov x2, x9
;; ldur x0, [x28, #0xc]
;; add x0, x28, #0xc
;; bl #0
;; c0: add x28, x28, #0xc
;; mov sp, x28
Expand Down
4 changes: 2 additions & 2 deletions winch/codegen/src/codegen/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,14 @@ impl FnCall {

match operand {
&ABIOperand::Reg { ty, reg, .. } => {
masm.load_addr(addr, writable!(reg), ty.try_into()?)?;
masm.compute_addr(addr, writable!(reg), ty.try_into()?)?;
}
&ABIOperand::Stack { ty, offset, .. } => {
let slot = masm.address_at_sp(SPOffset::from_u32(offset))?;
// Don't rely on `ABI::scratch_for` as we always use
// an int register as the return pointer.
let scratch = scratch!(M);
masm.load_addr(addr, writable!(scratch), ty.try_into()?)?;
masm.compute_addr(addr, writable!(scratch), ty.try_into()?)?;
masm.store(scratch.into(), slot, ty.try_into()?)?;
}
}
Expand Down
11 changes: 11 additions & 0 deletions winch/codegen/src/isa/aarch64/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ impl Address {
);
Self::Offset { base, offset }
}

/// Returns the register base and immediate offset of the given [`Address`].
///
/// # Panics
/// This function panics if the [`Address`] is not [`Address::Offset`].
pub fn unwrap_offset(&self) -> (Reg, i64) {
match self {
Self::Offset { base, offset } => (*base, *offset),
_ => panic!("Expected register and offset addressing mode"),
}
}
}

// Conversions between `winch-codegen`'s addressing mode representation
Expand Down
11 changes: 9 additions & 2 deletions winch/codegen/src/isa/aarch64/masm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,15 @@ impl Masm for MacroAssembler {
})
}

fn load_addr(&mut self, src: Self::Address, dst: WritableReg, size: OperandSize) -> Result<()> {
self.asm.uload(src, dst, size, TRUSTED_FLAGS);
fn compute_addr(
&mut self,
src: Self::Address,
dst: WritableReg,
size: OperandSize,
) -> Result<()> {
let (base, offset) = src.unwrap_offset();
self.asm
.add_ir(u64::try_from(offset).unwrap(), base, dst, size);
Ok(())
}

Expand Down
7 changes: 6 additions & 1 deletion winch/codegen/src/isa/x64/masm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,12 @@ impl Masm for MacroAssembler {
self.load(src, dst, self.ptr_size)
}

fn load_addr(&mut self, src: Self::Address, dst: WritableReg, size: OperandSize) -> Result<()> {
fn compute_addr(
&mut self,
src: Self::Address,
dst: WritableReg,
size: OperandSize,
) -> Result<()> {
self.asm.lea(&src, dst, size);
Ok(())
}
Expand Down
5 changes: 3 additions & 2 deletions winch/codegen/src/masm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1442,8 +1442,9 @@ pub(crate) trait MacroAssembler {
/// to the pointer size of the target.
fn load_ptr(&mut self, src: Self::Address, dst: WritableReg) -> Result<()>;

/// Loads the effective address into destination.
fn load_addr(
/// Computes the effective address and stores the result in the destination
/// register.
fn compute_addr(
&mut self,
_src: Self::Address,
_dst: WritableReg,
Expand Down