MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / emit_check_align

Method emit_check_align

winch/codegen/src/codegen/mod.rs:1280–1318  ·  view source on GitHub ↗

Emit checks to ensure that the address at `memarg` is correctly aligned for the access size.

(
        &mut self,
        heap: &HeapData,
        memarg: &MemArg,
        access_size: OperandSize,
    )

Source from the content-addressed store, hash-verified

1278 /// Emit checks to ensure that the address at `memarg` is
1279 /// correctly aligned for the access size.
1280 fn emit_check_align(
1281 &mut self,
1282 heap: &HeapData,
1283 memarg: &MemArg,
1284 access_size: OperandSize,
1285 ) -> Result<()> {
1286 if access_size.bytes() > 1 {
1287 let heap_ty_size: OperandSize = heap.index_type().try_into()?;
1288 let addr = *self
1289 .context
1290 .stack
1291 .peek()
1292 .ok_or_else(|| CodeGenError::missing_values_in_stack())?;
1293 let tmp = self.context.any_gpr(self.masm)?;
1294 self.context.move_val_to_reg(&addr, tmp, self.masm)?;
1295
1296 if memarg.offset != 0 {
1297 self.masm.add(
1298 writable!(tmp),
1299 tmp,
1300 RegImm::Imm(Imm::I64(memarg.offset)),
1301 heap_ty_size,
1302 )?;
1303 }
1304
1305 self.masm.and(
1306 writable!(tmp),
1307 tmp,
1308 RegImm::Imm(Imm::I32(access_size.bytes() - 1)),
1309 heap_ty_size,
1310 )?;
1311
1312 self.masm.cmp(tmp, RegImm::Imm(Imm::i64(0)), heap_ty_size)?;
1313 self.masm.trapif(IntCmpKind::Ne, TRAP_HEAP_MISALIGNED)?;
1314 self.context.free_reg(tmp);
1315 }
1316
1317 Ok(())
1318 }
1319
1320 pub fn emit_compute_heap_address_align_checked(
1321 &mut self,

Calls 14

i64Function · 0.85
OkFunction · 0.85
any_gprMethod · 0.80
move_val_to_regMethod · 0.80
free_regMethod · 0.80
ImmEnum · 0.50
bytesMethod · 0.45
try_intoMethod · 0.45
index_typeMethod · 0.45
peekMethod · 0.45
addMethod · 0.45
andMethod · 0.45

Tested by

no test coverage detected