Skip to content

Commit

Permalink
Merge pull request #8 from wasmi-labs/rf-integrate-stitch
Browse files Browse the repository at this point in the history
Add the stitch Wasm runtime to the set of tested VMs
  • Loading branch information
Robbepop authored May 15, 2024
2 parents b66c7f8 + b11e3da commit 8f77d2a
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ wasmer = { version = "4.3", default-features = false, features = ["engine", "com
wasmer-compiler-singlepass = "4.3"
wasmer-compiler-cranelift = "4.3"
wasmtime = { version = "20.0", default-features = false, features = ["winch", "cranelift", "runtime"] }
makepad-stitch = "0.1.0"
criterion = "0.5"
wat = "1"
serde_json = "1.0.117"
Expand All @@ -40,6 +41,9 @@ harness = false
lto = "fat"
codegen-units = 1

[profile.dev]
opt-level = 1 # required for the stitch Wasm runtime's LLVM's sibling calls optimization

[profile.wasm]
# The profile used to build Rust based benchmark inputs to WebAssembly.
inherits = "release"
Expand Down
3 changes: 3 additions & 0 deletions src/vms/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub use self::stitch::Stitch;
pub use self::tinywasm::Tinywasm;
pub use self::wasm3::Wasm3;
pub use self::wasmer::Wasmer;
Expand All @@ -7,6 +8,7 @@ pub use self::wasmtime::Wasmtime;
use crate::utils::TestFilter;
use ::wasmi_new::ModuleImportsIter;

mod stitch;
mod tinywasm;
mod wasm3;
mod wasmer;
Expand Down Expand Up @@ -74,6 +76,7 @@ pub fn vms_under_test() -> Vec<Box<dyn BenchVm>> {
Box::new(Wasm3 {
compilation_mode: wasm3::CompilationMode::Lazy,
}),
Box::new(Stitch),
Box::new(Wasmtime {
strategy: ::wasmtime::Strategy::Cranelift,
}),
Expand Down
87 changes: 87 additions & 0 deletions src/vms/stitch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
use crate::{CompileTestFilter, ExecuteTestFilter, TestFilter};

use super::{elapsed_ms, BenchRuntime, BenchVm};
use core::slice;
use makepad_stitch::{Engine, ExternVal, Func, Instance, Linker, Module, Store, Val};
use wasmi_new::ModuleImportsIter;

pub struct Stitch;

struct StitchRuntime {
store: Store,
_instance: Instance,
func: Func,
}

impl BenchVm for Stitch {
fn name(&self) -> &'static str {
"stitch"
}

fn test_filter(&self) -> TestFilter {
TestFilter {
execute: ExecuteTestFilter {
fib_tailrec: false, // stich does not yet support tail calls
argon2: false, // stitch currently seems to have a bug while executing
..ExecuteTestFilter::default()
},
compile: CompileTestFilter {
ffmpeg: false, // function body too large for stitch
// argon2: false, // stitch currently seems to have a bug while executing
..CompileTestFilter::default()
},
}
}

fn compile(&self, wasm: &[u8], _imports: ModuleImportsIter) {
let engine = Engine::new();
Module::new(&engine, wasm).unwrap();
}

fn load(&self, wasm: &[u8]) -> Box<dyn BenchRuntime> {
let engine = Engine::new();
let mut store = Store::new(engine);
let engine = store.engine();
let module = Module::new(engine, wasm).unwrap();
let linker = Linker::new();
let instance = linker.instantiate(&mut store, &module).unwrap();
let func = instance.exported_func("run").unwrap();
Box::new(StitchRuntime {
store,
_instance: instance,
func,
})
}

fn coremark(&self, wasm: &[u8]) -> f32 {
let engine = Engine::new();
let mut store = Store::new(engine);
let engine = store.engine();
let module = Module::new(engine, wasm).unwrap();
let mut linker = Linker::new();
linker.define(
"env",
"clock_ms",
ExternVal::Func(Func::wrap(&mut store, elapsed_ms)),
);
let instance = linker.instantiate(&mut store, &module).unwrap();
let func = instance.exported_func("run").unwrap();
let mut result = Val::F32(0.0);
func.call(&mut store, &[], slice::from_mut(&mut result))
.unwrap();
result.to_f32().unwrap()
}
}

impl BenchRuntime for StitchRuntime {
fn call(&mut self, input: i64) {
let mut result = Val::I64(0);
self.func
.call(
&mut self.store,
&[Val::I64(input)],
slice::from_mut(&mut result),
)
.unwrap();
}
}

0 comments on commit 8f77d2a

Please sign in to comment.