This seems like a pretty clean map to me—most of the architectures these days have native support for 32-bit and 64-bit types these days. You only get 16-bit and 8-bit support with SIMD or load/store, much like how WASM does it.
This seems like a pretty clean map to me—most of the architectures these days have native support for 32-bit and 64-bit types these days. You only get 16-bit and 8-bit support with SIMD or load/store, much like how WASM does it.
wasmtime uses cranelift, which has a complex register allocator. wasm3 uses a simple register file.
> In M3/Wasm, the stack machine model is translated into a more direct and efficient "register file" approach.
https://github.com/wasm3/wasm3/blob/main/docs/Interpreter.md
A "register file" is the name of such an array.
1. Check the type at the top of the stack to make sure it's i32 and trap otherwise
2. Pop the top of the stack
3. Check the top of the stack and make sure it's i32 and trap otherwise
4. Pop the top of the stack.
5. Add the two values together
6. Push the result to the top of the stack along with its type.
Compare this to ADD from RISC-V where you can just add the contents of 2 source registers and store it in a destination register. There is not a bunch of type book keeping or alignment that you have to worry about.
The stack isn’t dynamically typed, so it doesn’t make sense to trap.
You'd need to validate function types during runtime though, which is something that a CPU emulator does not need to.
If you squint and look sideways, you can think of it as a flattened tree, rather than a stack machine.
Wasn't it based on previous work by the Mozilla team?