0xPolygonMiden / compiler

Compiler from MidenIR to Miden Assembly
MIT License
55 stars 17 forks source link

Missing `memfill` op in IR #156

Closed greenhat closed 23 hours ago

greenhat commented 3 months ago

I encountered the Wasm memory.fill instruction in the GlobalAlloc::alloc_zeroed function, which is used to zero out the memory allocated by GlobalAlloc::alloc. Since the memory in Miden VM is guaranteed to be initialized to zeros, I ignored this instruction for now, but we're going to need it in the future.

See semantics at https://webassembly.github.io/spec/core/exec/instructions.html#exec-memory-fill

### Tasks
- [ ] Add `memfill` op in IR and lower it to MASM;
- [ ] Translate Wasm `memory.fill`;
bitwalker commented 3 months ago

The initial state of memory is guaranteed to be zero (for now at least), but alloc_zeroed is still needed because the allocator itself might free and reuse memory that was previously written to, which will no longer have that guarantee. So we'll definitely need this.

I'll make a note to add memset/memory.fill to the instruction set while I'm in there working on other things.

NOTE: We don't need this for the alpha, since we're leaning on WeeAlloc which doesn't reuse memory AFAIK, but we won't be able to make that assumption longer term.

bitwalker commented 23 hours ago

Implemented in #242