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

Method emit_compute_memory_size

winch/codegen/src/codegen/mod.rs:1525–1541  ·  view source on GitHub ↗

Retrieves the size of the memory, pushing the result to the value stack.

(&mut self, heap_data: &HeapData)

Source from the content-addressed store, hash-verified

1523
1524 /// Retrieves the size of the memory, pushing the result to the value stack.
1525 pub fn emit_compute_memory_size(&mut self, heap_data: &HeapData) -> Result<()> {
1526 let size_reg = self.context.any_gpr(self.masm)?;
1527 self.load_memory_length(heap_data, size_reg)?;
1528
1529 // Emit a shift to get the size in pages rather than in bytes.
1530 let dst = TypedReg::new(heap_data.index_type(), size_reg);
1531 let pow = heap_data.memory.page_size_log2;
1532 self.masm.shift_ir(
1533 writable!(dst.reg),
1534 Imm::i32(pow as i32),
1535 dst.into(),
1536 ShiftKind::ShrU,
1537 self.env.ptr_type().try_into()?,
1538 )?;
1539 self.context.stack.push(dst.into());
1540 Ok(())
1541 }
1542
1543 /// Emit a bounds check for `ptr+len` and put the native address for this
1544 /// wasm address into `dst`.

Callers 1

visit_memory_sizeMethod · 0.80

Calls 9

OkFunction · 0.85
any_gprMethod · 0.80
load_memory_lengthMethod · 0.80
newFunction · 0.50
index_typeMethod · 0.45
shift_irMethod · 0.45
try_intoMethod · 0.45
ptr_typeMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected