Skip to content

Commit

Permalink
add doc for check_align
Browse files Browse the repository at this point in the history
  • Loading branch information
MarinPostma committed Jan 13, 2025
1 parent b3a5af8 commit e462bb3
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions winch/codegen/src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,12 +845,12 @@ where
Ok(addr)
}

/// Emit checks to ensure that the address at `memarg` is correctly aligned for `size`.
fn check_align(&mut self, memarg: &MemArg, size: OperandSize) -> Result<()> {
if size.bytes() > 1 {
let addr = *self.context.stack.peek().unwrap();
let tmp = self.context.any_gpr(self.masm)?;
self.context
.move_val_to_reg(&addr, tmp, self.masm)?;
self.context.move_val_to_reg(&addr, tmp, self.masm)?;
if memarg.offset != 0 {
self.masm.add(
writable!(tmp),
Expand All @@ -866,8 +866,7 @@ where
size,
)?;

self.masm
.cmp(tmp, RegImm::Imm(Imm::i64(0)), size)?;
self.masm.cmp(tmp, RegImm::Imm(Imm::i64(0)), size)?;
self.masm.trapif(IntCmpKind::Ne, TRAP_HEAP_MISALIGNED)?;

self.context.free_reg(tmp);
Expand Down

0 comments on commit e462bb3

Please sign in to comment.