explodingcamera / tinywasm

A tiny, interpreted WebAssembly Runtime written in Rust
Apache License 2.0
472 stars 18 forks source link

Consolidate Stack #24

Open danielstuart14 opened 1 month ago

danielstuart14 commented 1 month ago

Currently, tinywasm uses multiple vectors to store the stack values for each type size supported (https://github.com/explodingcamera/tinywasm/blob/c00031a82782393eb32a9143aedb61e902a7c5d0/crates/tinywasm/src/interpreter/stack/value_stack.rs#L13).

This increases the default stack size by a lot, which makes it difficult to use tinywasm on restrained devices (ex: MCUs).

Is it something desired for the stacks to be consolidated into a single one?

I can think of some ways to do it, but a deeper discussion should be done.

explodingcamera commented 1 month ago

I've been planning to add some config options for the initial stack sizes when initializing stores that hopefully should mostly solve this in the short term. The main reason for this Struct of Arrays pattern for the stack is to allow for using native rust number/simd types for the stack values instead of having to hope the rust compiler turns the byte conversions into transmutes. This also depends on the alignment so probably wouldn't be very efficient if everything shared the same stack without adding a lot of memory usage by padding everything (which was the previous solution i used). I'd be also open for other ideas, it's not super ergonomic/efficient to have to pass around 4 different stack pointers everywhere.