From b764a07294a6c6cea9ae2de6d05a86c9c944a88d Mon Sep 17 00:00:00 2001 From: butterunderflow Date: Wed, 9 Oct 2024 22:22:16 +0800 Subject: [PATCH] a failed test case --- benchmarks/wasm/tribonacci.rs | 13 +++++ benchmarks/wasm/tribonacci.wat | 68 ++++++++++++++++++++++++++ src/test/scala/genwasym/TestEval.scala | 1 + 3 files changed, 82 insertions(+) create mode 100644 benchmarks/wasm/tribonacci.rs create mode 100644 benchmarks/wasm/tribonacci.wat diff --git a/benchmarks/wasm/tribonacci.rs b/benchmarks/wasm/tribonacci.rs new file mode 100644 index 00000000..ae576056 --- /dev/null +++ b/benchmarks/wasm/tribonacci.rs @@ -0,0 +1,13 @@ +#[no_mangle] +#[inline(never)] +fn tribonacci(n: i32) -> i32 { + if n == 0 { 0 } + else if n == 1 { 1 } + else if n == 2 { 1 } + else { tribonacci(n - 1) + tribonacci(n - 2) + tribonacci(n - 3) } +} + +#[no_mangle] +fn real_main() -> i32 { + tribonacci(12) +} diff --git a/benchmarks/wasm/tribonacci.wat b/benchmarks/wasm/tribonacci.wat new file mode 100644 index 00000000..f2c0e678 --- /dev/null +++ b/benchmarks/wasm/tribonacci.wat @@ -0,0 +1,68 @@ +(module + (type (;0;) (func (param i32) (result i32))) + (type (;1;) (func (result i32))) + (func (;0;) (type 0) (param i32) (result i32) + (local i32 i32) + local.get 0 + i32.const 2 + i32.shl + i32.const 1048576 + i32.add + local.set 1 + i32.const 0 + local.set 2 + local.get 0 + local.set 0 + loop (result i32) ;; label = @1 + local.get 2 + local.set 2 + local.get 1 + local.set 1 + block ;; label = @2 + local.get 0 + local.tee 0 + i32.const 2 + i32.gt_u + br_if 0 (;@2;) + local.get 1 + i32.load + local.get 2 + i32.add + return + end + local.get 1 + i32.const -12 + i32.add + local.set 1 + local.get 0 + i32.const -1 + i32.add + call 0 + local.get 0 + i32.const -2 + i32.add + call 0 + i32.add + local.get 2 + i32.add + local.set 2 + local.get 0 + i32.const -3 + i32.add + local.set 0 + br 0 (;@1;) + end) + (func (;1;) (type 1) (result i32) + i32.const 12 + call 0) + (start 1) + (table (;0;) 1 1 funcref) + (memory (;0;) 17) + (global (;0;) (mut i32) (i32.const 1048576)) + (global (;1;) i32 (i32.const 1048588)) + (global (;2;) i32 (i32.const 1048592)) + (export "memory" (memory 0)) + (export "tribonacci" (func 0)) + (export "real_main" (func 1)) + (export "__data_end" (global 1)) + (export "__heap_base" (global 2))) diff --git a/src/test/scala/genwasym/TestEval.scala b/src/test/scala/genwasym/TestEval.scala index f2d66b15..2518ce65 100644 --- a/src/test/scala/genwasym/TestEval.scala +++ b/src/test/scala/genwasym/TestEval.scala @@ -44,6 +44,7 @@ class TestEval extends FunSuite { test("load") { testFile("./benchmarks/wasm/load.wat", None, Some(1)) } test("btree") { testFile("./benchmarks/wasm/btree/2o1u-unlabeled.wat") } test("fib") { testFile("./benchmarks/wasm/fib.wat", None, Some(144)) } + test("tribonacci") { testFile("./benchmarks/wasm/tribonacci.wat", None, Some(504)) } // TODO: add wasm spec tests? How to utilize wast files? }