Skip to content
This repository was archived by the owner on Oct 3, 2025. It is now read-only.

Commit 5e573f0

Browse files
no more simd
Signed-off-by: Henry Gressmann <[email protected]>
1 parent 0fa1bca commit 5e573f0

File tree

10 files changed

+250
-97
lines changed

10 files changed

+250
-97
lines changed

crates/benchmarks/benches/fibonacci.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ fn run_wasmi(wasm: &[u8], iterations: i32, name: &str) {
1717

1818
fn run_wasmer(wasm: &[u8], iterations: i32, name: &str) {
1919
use wasmer::*;
20-
let engine: Engine = wasmer::Singlepass::default().into();
21-
let mut store = Store::default();
20+
let compiler = wasmer::Singlepass::default();
21+
let mut store = Store::new(compiler);
2222
let import_object = imports! {};
23-
let module = wasmer::Module::from_binary(&engine, wasm).expect("wasmer::Module::from_binary");
23+
let module = wasmer::Module::from_binary(&store, wasm).expect("wasmer::Module::from_binary");
2424
let instance = Instance::new(&mut store, &module, &import_object).expect("Instance::new");
2525
let fib = instance.exports.get_typed_function::<i32, i32>(&store, name).expect("get_function");
2626
fib.call(&mut store, iterations).expect("call");

crates/parser/src/visit.rs

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,6 @@ impl<'a> wasmparser::VisitOperator<'a> for FunctionBuilder {
142142
define_primitive_operands! {
143143
visit_br, Instruction::Br, u32,
144144
visit_br_if, Instruction::BrIf, u32,
145-
visit_local_get, Instruction::LocalGet, u32,
146-
visit_local_set, Instruction::LocalSet, u32,
147-
visit_local_tee, Instruction::LocalTee, u32,
148145
visit_global_get, Instruction::GlobalGet, u32,
149146
visit_global_set, Instruction::GlobalSet, u32,
150147
visit_i32_const, Instruction::I32Const, i32,
@@ -220,7 +217,7 @@ impl<'a> wasmparser::VisitOperator<'a> for FunctionBuilder {
220217
visit_i32_clz, Instruction::I32Clz,
221218
visit_i32_ctz, Instruction::I32Ctz,
222219
visit_i32_popcnt, Instruction::I32Popcnt,
223-
visit_i32_add, Instruction::I32Add,
220+
// visit_i32_add, Instruction::I32Add, custom implementation
224221
visit_i32_sub, Instruction::I32Sub,
225222
visit_i32_mul, Instruction::I32Mul,
226223
visit_i32_div_s, Instruction::I32DivS,
@@ -251,7 +248,7 @@ impl<'a> wasmparser::VisitOperator<'a> for FunctionBuilder {
251248
visit_i64_shl, Instruction::I64Shl,
252249
visit_i64_shr_s, Instruction::I64ShrS,
253250
visit_i64_shr_u, Instruction::I64ShrU,
254-
visit_i64_rotl, Instruction::I64Rotl,
251+
// visit_i64_rotl, Instruction::I64Rotl, custom implementation
255252
visit_i64_rotr, Instruction::I64Rotr,
256253
visit_f32_abs, Instruction::F32Abs,
257254
visit_f32_neg, Instruction::F32Neg,
@@ -325,6 +322,68 @@ impl<'a> wasmparser::VisitOperator<'a> for FunctionBuilder {
325322
visit_i64_trunc_sat_f64_u, Instruction::I64TruncSatF64U
326323
}
327324

325+
fn visit_local_get(&mut self, idx: u32) -> Self::Output {
326+
if let Some(instruction) = self.instructions.last_mut() {
327+
match instruction {
328+
// Instruction::LocalGet(a) => *instruction = Instruction::LocalGet2(*a, idx),
329+
// Instruction::LocalGet2(a, b) => *instruction = Instruction::LocalGet3(*a, *b, idx),
330+
// Instruction::LocalGet3(a, b, c) => *instruction = Instruction::LocalGet4(*a, *b, *c, idx),
331+
// Instruction::LocalTee(a) => *instruction = Instruction::LocalTeeGet(*a, idx),
332+
_ => return self.visit(Instruction::LocalGet(idx)),
333+
};
334+
Ok(())
335+
} else {
336+
self.visit(Instruction::LocalGet(idx))
337+
}
338+
}
339+
340+
fn visit_local_set(&mut self, idx: u32) -> Self::Output {
341+
// LocalGetSet
342+
if let Some(instruction) = self.instructions.last_mut() {
343+
match instruction {
344+
// Instruction::LocalGet(a) => *instruction = Instruction::LocalGetSet(*a, idx),
345+
_ => return self.visit(Instruction::LocalSet(idx)),
346+
};
347+
Ok(())
348+
} else {
349+
self.visit(Instruction::LocalSet(idx))
350+
}
351+
}
352+
353+
fn visit_local_tee(&mut self, idx: u32) -> Self::Output {
354+
self.visit(Instruction::LocalTee(idx))
355+
}
356+
357+
fn visit_i64_rotl(&mut self) -> Self::Output {
358+
if self.instructions.len() < 2 {
359+
return self.visit(Instruction::I64Rotl);
360+
}
361+
362+
match self.instructions[self.instructions.len() - 2..] {
363+
// [Instruction::I64Xor, Instruction::I64Const(a)] => {
364+
// self.instructions.pop();
365+
// self.instructions.pop();
366+
// self.visit(Instruction::I64XorConstRotl(a))
367+
// }
368+
_ => self.visit(Instruction::I64Rotl),
369+
}
370+
}
371+
372+
fn visit_i32_add(&mut self) -> Self::Output {
373+
if self.instructions.len() < 2 {
374+
return self.visit(Instruction::I32Add);
375+
}
376+
377+
match self.instructions[self.instructions.len() - 2..] {
378+
// [Instruction::LocalGet(a), Instruction::I32Const(b)] => {
379+
// self.instructions.pop();
380+
// self.instructions.pop();
381+
// self.visit(Instruction::I32LocalGetConstAdd(a, b))
382+
// }
383+
_ => self.visit(Instruction::I32Add),
384+
}
385+
}
386+
328387
fn visit_block(&mut self, blockty: wasmparser::BlockType) -> Self::Output {
329388
self.label_ptrs.push(self.instructions.len());
330389
self.visit(Instruction::Block(convert_blocktype(blockty), 0))

crates/tinywasm/src/runtime/interpreter/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// from a function, so we need to check if the label stack is empty
1212
macro_rules! break_to {
1313
($cf:ident, $stack:ident, $break_to_relative:ident) => {{
14-
if $cf.break_to(*$break_to_relative, &mut $stack.values, &mut $stack.blocks).is_none() {
14+
if $cf.break_to($break_to_relative, &mut $stack.values, &mut $stack.blocks).is_none() {
1515
if $stack.call_stack.is_empty() {
1616
return Ok(ExecResult::Return);
1717
} else {

0 commit comments

Comments
 (0)