-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from wasmi-labs/rf-integrate-stitch
Add the stitch Wasm runtime to the set of tested VMs
- Loading branch information
Showing
4 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |