diff options
| -rw-r--r-- | ARCHITECTURE.md | 1 | ||||
| -rw-r--r-- | README.md | 10 | ||||
| -rw-r--r-- | benches/README.md | 20 | ||||
| -rwxr-xr-x | examples/rust/build.sh | 4 | ||||
| -rw-r--r-- | examples/rust/src/fibonacci.rs | 8 |
5 files changed, 39 insertions, 4 deletions
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index 9665745..28607da 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -12,6 +12,7 @@ Some key differences are: - TinyWasm is architectured to allow for a JIT compiler to be added later. Functions are stored as FunctionInstances which can contain either a `WasmFunction` or a `HostFunction`. A third variant `JitFunction` could be added later to store a pointer to the compiled function. This would allow for the JIT to be used transparently without changing the rest of the runtime. - TinyWasm is designed to be used in `no_std` environments. The `std` feature is enabled by default, but can be disabled to remove the dependency on `std` and `std::io`. This is done by disabling the `std` and `parser` features. The `logging` feature can also be disabled to remove the dependency on `log`. This is not recommended, since `libm` is not as performant as the compiler's math intrinsics, especially on wasm32 targets, but can be useful for resource-constrained devices or other environments where `std` is not available such as OS kernels. - Call Frames are executed in a loop instead of recursively. This allows the use of a single stack for all frames and makes it easier to pause execution and resume it later, or to step through the code one instruction at a time. +- While other interpreters convert `locals` to be register-based when parsing the function body, TinyWasm keeps them in a stack. This is mostly for simplicity in the implementation, but performance is still comparable or better than other interpreters. ## Bytecode Format @@ -5,11 +5,17 @@ <h1>TinyWasm</h1> A tiny WebAssembly Runtime written in Rust </div> - + <br> [](https://docs.rs/tinywasm) [](https://crates.io/crates/tinywasm) [](./LICENSE-APACHE) +# Why TinyWasm? + +- **Tiny** - Designed to be as small as possible without sacrificing too much performance or functionality. +- **Fast enough** - TinyWasm is reasonably fast, especially when compared to other interpreters. See [Performance](#performance) for more details. +- **Portable** - Runs on any platform llvm supports, including WebAssembly. Minimal external dependencies. + # Status TinyWasm, starting from version `0.3.0`, passes all the WebAssembly 1.0 tests in the [WebAssembly Test Suite](https://github.com/WebAssembly/testsuite). The 2.0 tests are in progress. This is enough to run most WebAssembly programs, including TinyWasm itself compiled to WebAssembly (see [examples/wasm-rust.rs](./examples/wasm-rust.rs)). @@ -17,7 +23,7 @@ TinyWasm, starting from version `0.3.0`, passes all the WebAssembly 1.0 tests in Some APIs to interact with the runtime are not yet exposed, and the existing ones are subject to change, but the core functionality is mostly complete. Results of the tests can be found [here](https://github.com/explodingcamera/tinywasm/tree/main/crates/tinywasm/tests/generated). -TinyWasm is not designed for performance, but rather for size and portability. However, it is still reasonably fast. +TinyWasm is not designed for performance, but rather for simplicity, size and portability. However, it is still reasonably fast, especially when compared to other interpreters. See [Performance](#performance) for more details. ## Supported Proposals diff --git a/benches/README.md b/benches/README.md index 6ed8cc5..39ba321 100644 --- a/benches/README.md +++ b/benches/README.md @@ -1,8 +1,26 @@ # Benchmark results +All benchmarks are run on a Ryzen 7 5800X, with 32GB of RAM, running Linux 6.6 with `intel_pstate=passive split_lock_detect=off mitigations=off`. + +## Results + Coming soon. -# Benchmarking +## WebAssembly Settings + +All WebAssembly files are compiled with the following settings: + +- `opt-level` is set to 3, `lto` is set to `thin`, `codegen-units` is set to 1. +- `reference-types`, `bulk-memory`, `mutable-globals` proposals are enabled. + +## Runtime Settings + +All runtimes are compiled with the following settings: + +- `unsafe` features are enabled +- `opt-level` is set to 3, `lto` is set to `thin`, `codegen-units` is set to 1. + +## Benchmarking Benchmarks are run using [Criterion.rs](https://github.com/bheisler/criterion.rs) and can be found in the `benches` directory. diff --git a/examples/rust/build.sh b/examples/rust/build.sh index 5450345..cabf00e 100755 --- a/examples/rust/build.sh +++ b/examples/rust/build.sh @@ -6,11 +6,13 @@ exclude_wat=("tinywasm") out_dir="./target/wasm32-unknown-unknown/wasm" dest_dir="out" +features="+reference-types,+bulk-memory,+mutable-globals" + # ensure out dir exists mkdir -p "$dest_dir" for bin in "${bins[@]}"; do - RUSTFLAGS="-C target-feature=+reference-types,+bulk-memory -C panic=abort" cargo build --target wasm32-unknown-unknown --package rust-wasm-examples --profile=wasm --bin "$bin" + RUSTFLAGS="-C target-feature=$features -C panic=abort" cargo build --target wasm32-unknown-unknown --package rust-wasm-examples --profile=wasm --bin "$bin" cp "$out_dir/$bin.wasm" "$dest_dir/" wasm-opt "$dest_dir/$bin.wasm" -o "$dest_dir/$bin.wasm" -O --intrinsic-lowering -O diff --git a/examples/rust/src/fibonacci.rs b/examples/rust/src/fibonacci.rs index 3e4be73..7924aef 100644 --- a/examples/rust/src/fibonacci.rs +++ b/examples/rust/src/fibonacci.rs @@ -19,3 +19,11 @@ pub extern "C" fn fibonacci(n: i32) -> i32 { } sum } + +#[no_mangle] +pub extern "C" fn fibonacci_recursive(n: i32) -> i32 { + if n <= 1 { + return n; + } + fibonacci_recursive(n - 1) + fibonacci_recursive(n - 2) +} |
