From 9e5fb17e5686f2dd18397fac01c9c3ae13316ef7 Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Fri, 28 Aug 2015 18:14:01 -0700 Subject: [PATCH 1/5] Add two tests compiled from C# --- ml-proto/test/countUp.wasm | 77 +++++ ml-proto/test/fannkuch.broken-wasm | 517 +++++++++++++++++++++++++++++ 2 files changed, 594 insertions(+) create mode 100644 ml-proto/test/countUp.wasm create mode 100644 ml-proto/test/fannkuch.broken-wasm diff --git a/ml-proto/test/countUp.wasm b/ml-proto/test/countUp.wasm new file mode 100644 index 0000000000..fcc7f33830 --- /dev/null +++ b/ml-proto/test/countUp.wasm @@ -0,0 +1,77 @@ +;; CountUp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + +(module + + (func $Program_countUp + (param $outOffset i32) (param $count i32) (local $i i32) (local $num i32) + + + (block + + ;; for (var (@ = 0); ...) + (setlocal $i (const.i32 0)) + + (label $loop_4096 + (loop + ;; for (...; (@ < @); ...) + + (if + (lts.i32 + (getlocal $i) + (getlocal $count) + ) + (nop) + (break $loop_4096) + ) + + ;; for (...) { + (block + (stores.1.i32 + (mul.i32 + (add.i32 + (getlocal $outOffset) + (getlocal $i) + ) + (const.i32 4) + ) + (getlocal $i) + ) + (setlocal $num (getlocal $i)) + (setlocal $i (add.i32 + (getlocal $num) + (const.i32 1) + )) + ) + ) + ) + ) + + ) + (func $Program_readI32 + (param $base i32) (param $offset i32) + (result i32) + + (return (loads.1.i32 (mul.i32 + (add.i32 + (getlocal $base) + (getlocal $offset) + ) + (const.i32 4) + ) )) + ) + + (export "countUp" $Program_countUp) + + (export "readI32" $Program_readI32) + + (memory 4096 4096) + +) + +(invoke "countUp" (const.i32 0) (const.i32 32) ) +(invoke "countUp" (const.i32 16) (const.i32 4) ) +(asserteq (invoke "readI32" (const.i32 0) (const.i32 0) ) (const.i32 0) ) +(asserteq (invoke "readI32" (const.i32 0) (const.i32 2) ) (const.i32 2) ) +(asserteq (invoke "readI32" (const.i32 0) (const.i32 31) ) (const.i32 31) ) +(asserteq (invoke "readI32" (const.i32 16) (const.i32 0) ) (const.i32 0) ) +(asserteq (invoke "readI32" (const.i32 16) (const.i32 3) ) (const.i32 3) ) diff --git a/ml-proto/test/fannkuch.broken-wasm b/ml-proto/test/fannkuch.broken-wasm new file mode 100644 index 0000000000..17e5f2908e --- /dev/null +++ b/ml-proto/test/fannkuch.broken-wasm @@ -0,0 +1,517 @@ +;; FannkuchRedux, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + +(module + + (func $Program_fannkuch + (param $n i32) (local $sign i32) (local $maxflips i32) (local $sum i32) + (local $j i32) (local $num i32) (local $q0 i32) (local $flag i32) + (local $k i32) (local $flips i32) (local $qq i32) (local $flag2 i32) + (local $flag3 i32) (local $l i32) (local $m i32) (local $t i32) + (local $flag4 i32) (local $flag5 i32) (local $t3 i32) (local $i2 i32) + (local $sx i32) (local $flag7 i32) (local $j2 i32) + (local $currentLabel_0 i32) + + (block + + ;; LabelGroup 0 + (setlocal $currentLabel_0 (const.i32 0)) + + (label $labelgroup_0 (loop (label $labelgroup_0_dispatch + ;; Begin Label $entry0 + (if (eq.i32 (getlocal $currentLabel_0) (const.i32 0)) + (block + (setlocal $sign (const.i32 1)) + (setlocal $maxflips (const.i32 0)) + (setlocal $sum (const.i32 0)) + + ;; for (var (@ = 0); ...) + (setlocal $j (const.i32 0)) + + (label $loop_4096 + (loop + ;; for (...; (@ < @); ...) + + (if + (lts.i32 + (getlocal $j) + (getlocal $n) + ) + (nop) + (break $loop_4096) + ) + + ;; for (...) { + (block + (stores.1.i32 + (mul.i32 + (add.i32 + (const.i32 32) + (getlocal $j) + ) + (const.i32 4) + ) + (getlocal $j) + ) + (stores.1.i32 + (mul.i32 + (add.i32 + (const.i32 64) + (getlocal $j) + ) + (const.i32 4) + ) + (getlocal $j) + ) + (stores.1.i32 + (mul.i32 + (add.i32 + (const.i32 96) + (getlocal $j) + ) + (const.i32 4) + ) + (getlocal $j) + ) + (setlocal $num (getlocal $j)) + (setlocal $j (add.i32 + (getlocal $num) + (const.i32 1) + )) + ) + ) + ) + + ;; while () + (label $loop_4097 + (loop + + (if + (const.i32 1) + (nop) + (break $loop_4097) + ) + + ;; while (...) { + (block + (setlocal $q0 (loads.1.i32 (const.i32 128) )) + (setlocal $flag (gts.i32 + (getlocal $q0) + (const.i32 0) + )) + + (if + (getlocal $flag) + (block + + ;; for (var (@ = 1); ...) + (setlocal $k (const.i32 1)) + + (label $loop_4098 + (loop + ;; for (...; (@ < @); ...) + + (if + (lts.i32 + (getlocal $k) + (getlocal $n) + ) + (nop) + (break $loop_4098) + ) + + ;; for (...) { + (block + (stores.1.i32 + (mul.i32 + (add.i32 + (const.i32 64) + (getlocal $k) + ) + (const.i32 4) + ) + (loads.1.i32 (mul.i32 + (add.i32 + (const.i32 32) + (getlocal $k) + ) + (const.i32 4) + ) ) + ) + (setlocal $num (getlocal $k)) + (setlocal $k (add.i32 + (getlocal $num) + (const.i32 1) + )) + ) + ) + ) + (setlocal $flips (const.i32 1)) + + ;; while () + (label $loop_3 + (loop + + (if + (const.i32 1) + (nop) + (break $loop_3) + ) + + ;; while (...) { + (block + (setlocal $qq (loads.1.i32 (mul.i32 + (add.i32 + (const.i32 64) + (getlocal $q0) + ) + (const.i32 4) + ) )) + (setlocal $flag2 (eq.i32 + (getlocal $qq) + (const.i32 0) + )) + + (if + (getlocal $flag2) + (break $loop_3) + ) + (stores.1.i32 + (mul.i32 + (add.i32 + (const.i32 64) + (getlocal $q0) + ) + (const.i32 4) + ) + (getlocal $q0) + ) + (setlocal $flag3 (ges.i32 + (getlocal $q0) + (const.i32 3) + )) + + (if + (getlocal $flag3) + (block + (setlocal $l (const.i32 1)) + (setlocal $m (sub.i32 + (getlocal $q0) + (const.i32 1) + )) + + ;; do { + (label $loop_4099 + (loop + (block + (setlocal $t (loads.1.i32 (mul.i32 + (add.i32 + (const.i32 64) + (getlocal $l) + ) + (const.i32 4) + ) )) + (stores.1.i32 + (mul.i32 + (add.i32 + (const.i32 64) + (getlocal $l) + ) + (const.i32 4) + ) + (loads.1.i32 (mul.i32 + (add.i32 + (const.i32 64) + (getlocal $m) + ) + (const.i32 4) + ) ) + ) + (stores.1.i32 + (mul.i32 + (add.i32 + (const.i32 64) + (getlocal $m) + ) + (const.i32 4) + ) + (getlocal $t) + ) + (setlocal $num (getlocal $l)) + (setlocal $l (add.i32 + (getlocal $num) + (const.i32 1) + )) + (setlocal $num (getlocal $m)) + (setlocal $m (sub.i32 + (getlocal $num) + (const.i32 1) + )) + ) + + ;; do { ... } while ((@ < @)) + + (if + (lts.i32 + (getlocal $l) + (getlocal $m) + ) + (nop) + (break $loop_4099) + ) + ) + ) + ) + ) + (setlocal $q0 (getlocal $qq)) + (setlocal $num (getlocal $flips)) + (setlocal $flips (add.i32 + (getlocal $num) + (const.i32 1) + )) + ) + ) + ) + (setlocal $sum (add.i32 + (getlocal $sum) + (mul.i32 + (getlocal $sign) + (getlocal $flips) + ) + )) + (setlocal $flag4 (gts.i32 + (getlocal $flips) + (getlocal $maxflips) + )) + + (if + (getlocal $flag4) + (setlocal $maxflips (getlocal $flips)) + ) + ) + ) + (setlocal $flag5 (eq.i32 + (getlocal $sign) + (const.i32 1) + )) + + (if + (getlocal $flag5) + (block + (stores.1.i32 + (const.i32 132) + (loads.1.i32 (const.i32 128) ) + ) + (stores.1.i32 + (const.i32 128) + (loads.1.i32 (const.i32 132) ) + ) + (setlocal $sign (const.i32 -1)) + ) + (block + (setlocal $t3 (loads.1.i32 (const.i32 132) )) + (stores.1.i32 + (const.i32 132) + (loads.1.i32 (const.i32 136) ) + ) + (stores.1.i32 + (const.i32 136) + (getlocal $t3) + ) + (setlocal $sign (const.i32 1)) + + ;; for (var (@ = 2); ...) + (setlocal $i2 (const.i32 2)) + + (label $loop_5 + (loop + ;; for (...; (@ < @); ...) + + (if + (lts.i32 + (getlocal $i2) + (getlocal $n) + ) + (nop) + (break $loop_5) + ) + + ;; for (...) { + (block + (setlocal $sx (loads.1.i32 (mul.i32 + (add.i32 + (const.i32 96) + (getlocal $i2) + ) + (const.i32 4) + ) )) + + (if + (gts.i32 + (getlocal $sx) + (const.i32 0) + ) + (block + (stores.1.i32 + (mul.i32 + (add.i32 + (const.i32 96) + (getlocal $i2) + ) + (const.i32 4) + ) + (sub.i32 + (getlocal $sx) + (const.i32 1) + ) + ) + (break $loop_5) + ) + ) + (setlocal $flag7 (eq.i32 + (getlocal $i2) + (sub.i32 + (getlocal $n) + (const.i32 1) + ) + )) + + (if + (getlocal $flag7) + ;; goto Block_8 + (block (setlocal $currentLabel_0 (const.i32 1)) (break $labelgroup_0_dispatch) ) + ) + (stores.1.i32 + (mul.i32 + (add.i32 + (const.i32 96) + (getlocal $i2) + ) + (const.i32 4) + ) + (getlocal $i2) + ) + (setlocal $t3 (loads.1.i32 (const.i32 128) )) + + ;; for (var (@ = 0); ...) + (setlocal $j2 (const.i32 0)) + + (label $loop_4100 + (loop + ;; for (...; (@ <= @); ...) + + (if + (les.i32 + (getlocal $j2) + (getlocal $i2) + ) + (nop) + (break $loop_4100) + ) + + ;; for (...) { + (block + (stores.1.i32 + (mul.i32 + (add.i32 + (const.i32 32) + (getlocal $j2) + ) + (const.i32 4) + ) + (loads.1.i32 (mul.i32 + (add.i32 + (const.i32 32) + (add.i32 + (getlocal $j2) + (const.i32 1) + ) + ) + (const.i32 4) + ) ) + ) + (setlocal $num (getlocal $j2)) + (setlocal $j2 (add.i32 + (getlocal $num) + (const.i32 1) + )) + ) + ) + ) + (stores.1.i32 + (mul.i32 + (add.i32 + (const.i32 32) + (add.i32 + (getlocal $i2) + (const.i32 1) + ) + ) + (const.i32 4) + ) + (getlocal $t3) + ) + (setlocal $num (getlocal $i2)) + (setlocal $i2 (add.i32 + (getlocal $num) + (const.i32 1) + )) + ) + ) + ) + ) + ) + ) + ) + ) + ) + + ) + ;; End Label $entry0 + + ;; Begin Label Block_8 + (if (eq.i32 (getlocal $currentLabel_0) (const.i32 1)) + (block + (stores.1.i32 + (const.i32 0) + (getlocal $sum) + ) + (stores.1.i32 + (const.i32 4) + (getlocal $maxflips) + ) + ) + + ) + ;; End Label Block_8 + + ;; Fallthrough exit from labelgroup 0 + (break $labelgroup_0) + ) + )) + ) + + ) + (func $Program_readI32 + (param $base i32) (param $offset i32) + (result i32) + + (return (loads.1.i32 (mul.i32 + (add.i32 + (getlocal $base) + (getlocal $offset) + ) + (const.i32 4) + ) )) + ) + + (export "fannkuch" $Program_fannkuch) + + (export "readI32" $Program_readI32) + + (memory 4096 4096) + +) + +(invoke "fannkuch" (const.i32 7) ) +(asserteq (invoke "readI32" (const.i32 0) (const.i32 0) ) (const.i32 228) ) +(asserteq (invoke "readI32" (const.i32 0) (const.i32 1) ) (const.i32 16) ) From 060bc889e026a0713e6c706864b44f712b13a1c7 Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Mon, 31 Aug 2015 09:48:52 -0700 Subject: [PATCH 2/5] Windows python runtests compatibility --- ml-proto/runtests.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ml-proto/runtests.py b/ml-proto/runtests.py index 609297cc19..affca0b5bd 100755 --- a/ml-proto/runtests.py +++ b/ml-proto/runtests.py @@ -9,6 +9,9 @@ class RunTests(unittest.TestCase): def _runTestFile(self, shortName, fileName, interpreterPath): + # HACK: Windows python compatibility + fileName = fileName.replace("\\", "/") + logPath = fileName.replace("test/", "test/output/").replace(".wasm", ".wasm.log") try: os.remove(logPath) @@ -59,6 +62,8 @@ def rebuild_interpreter(path): if __name__ == "__main__": interpreterPath = os.path.abspath("src/main.native") + # HACK: Windows python compatibility + interpreterPath = interpreterPath.replace("\\", "/") try: os.makedirs("test/output/") From 791ce064896fd9132754db7d199b049de415ab9f Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Mon, 31 Aug 2015 16:07:26 -0700 Subject: [PATCH 3/5] Add Sieve of Eratosthenes C# test --- ml-proto/test/sieve.wasm | 214 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 214 insertions(+) create mode 100644 ml-proto/test/sieve.wasm diff --git a/ml-proto/test/sieve.wasm b/ml-proto/test/sieve.wasm new file mode 100644 index 0000000000..02d43aeef8 --- /dev/null +++ b/ml-proto/test/sieve.wasm @@ -0,0 +1,214 @@ +;; Sieve, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + +(module + + (func $Program_AddResult + (param $result i32) (local $count i32) + + (block + (setlocal $count (loads.1.i32 (const.i32 0) )) + (stores.1.i32 + (mul.i32 + (add.i32 + (const.i32 4) + (getlocal $count) + ) + (const.i32 4) + ) + (getlocal $result) + ) + (stores.1.i32 + (const.i32 0) + (add.i32 + (getlocal $count) + (const.i32 1) + ) + ) + ) + + ) + (func $Program_Clear + (param $offset i32) (param $count i32) (local $i i32) + + (block + + ;; for (var (@ = 0); ...) + (setlocal $i (const.i32 0)) + + (label $loop_4096 + (loop + ;; for (...; (@ < @); ...) + + (if + (lts.i32 + (getlocal $i) + (getlocal $count) + ) + (nop) + (break $loop_4096) + ) + + ;; for (...) { + (storeu.1.i8 + (add.i32 + (getlocal $offset) + (getlocal $i) + ) + (const.i32 0) + ) + + ;; for (...; ...; ) + (setlocal $i (add.i32 + (getlocal $i) + (const.i32 1) + )) + ) + ) + ) + + ) + (func $Program_GetResult + (param $index i32) + (result i32) + + (return (loads.1.i32 (mul.i32 + (add.i32 + (const.i32 4) + (getlocal $index) + ) + (const.i32 4) + ) )) + ) + (func $Program_GetResultCount + + (result i32) + + (return (loads.1.i32 (const.i32 0) )) + ) + (func $Program_Sieve + (param $target i32) (local $squareRoot f64) (local $candidate i32) (local $multiple i32) + + + (block + (stores.1.i32 + (const.i32 0) + (const.i32 0) + ) + (call $Program_Clear (const.i32 4) (const.i32 16384) ) + (call $Program_Clear (const.i32 16388) (getlocal $target) ) + (setlocal $squareRoot (sqrt.f64 (converts.i32.f64 (getlocal $target)) )) + (call $Program_AddResult (const.i32 2) ) + + ;; for (var (@ = 3); ...) + (setlocal $candidate (const.i32 3)) + + (label $loop_4097 + (loop + ;; for (...; (@ < @); ...) + + (if + (lts.i32 + (getlocal $candidate) + (getlocal $target) + ) + (nop) + (break $loop_4097) + ) + + ;; for (...) { + (block + + (if + (eq.i32 + (loadu.1.i8 (add.i32 + (const.i32 16388) + (getlocal $candidate) + ) ) + (const.i32 0) + ) + (block + + (if + (lt.f64 + (converts.i32.f64 (getlocal $candidate)) + (getlocal $squareRoot) + ) + (block + + ;; for (var (@ = (@ * @)); ...) + (setlocal $multiple (mul.i32 + (getlocal $candidate) + (getlocal $candidate) + )) + + (label $loop_4098 + (loop + ;; for (...; (@ < @); ...) + + (if + (lts.i32 + (getlocal $multiple) + (getlocal $target) + ) + (nop) + (break $loop_4098) + ) + + ;; for (...) { + (storeu.1.i8 + (add.i32 + (const.i32 16388) + (getlocal $multiple) + ) + (const.i32 1) + ) + + ;; for (...; ...; ) + (setlocal $multiple (add.i32 + (getlocal $multiple) + (mul.i32 + (const.i32 2) + (getlocal $candidate) + ) + )) + ) + ) + ) + ) + (call $Program_AddResult (getlocal $candidate) ) + ) + ) + ) + + ;; for (...; ...; ) + (setlocal $candidate (add.i32 + (getlocal $candidate) + (const.i32 2) + )) + ) + ) + ) + + ) + + (export "getResult" $Program_GetResult) + + (export "getResultCount" $Program_GetResultCount) + + (export "sieve" $Program_Sieve) + + (memory 131072 131072) + +) + +(invoke "sieve" (const.i32 24) ) +(asserteq (invoke "getResultCount" ) (const.i32 9) ) +(asserteq (invoke "getResult" (const.i32 0) ) (const.i32 2) ) +(asserteq (invoke "getResult" (const.i32 1) ) (const.i32 3) ) +(asserteq (invoke "getResult" (const.i32 2) ) (const.i32 5) ) +(asserteq (invoke "getResult" (const.i32 3) ) (const.i32 7) ) +(asserteq (invoke "getResult" (const.i32 4) ) (const.i32 11) ) +(asserteq (invoke "getResult" (const.i32 5) ) (const.i32 13) ) +(asserteq (invoke "getResult" (const.i32 6) ) (const.i32 17) ) +(asserteq (invoke "getResult" (const.i32 7) ) (const.i32 19) ) +(asserteq (invoke "getResult" (const.i32 8) ) (const.i32 23) ) From ac6af3579ae1138e81769154a670b930f2505723 Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Mon, 31 Aug 2015 16:26:21 -0700 Subject: [PATCH 4/5] Add a simple goto test using loop-switch goto emulation --- ml-proto/test/goto.wasm | 207 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 207 insertions(+) create mode 100644 ml-proto/test/goto.wasm diff --git a/ml-proto/test/goto.wasm b/ml-proto/test/goto.wasm new file mode 100644 index 0000000000..961746f5e7 --- /dev/null +++ b/ml-proto/test/goto.wasm @@ -0,0 +1,207 @@ +;; Goto, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + +(module + + (func $Program_AddResult + (param $result i32) (local $count i32) + + (block + (setlocal $count (loads.1.i32 (const.i32 0) )) + (storeu.1.i8 + (add.i32 + (const.i32 4) + (getlocal $count) + ) + (getlocal $result) + ) + (stores.1.i32 + (const.i32 0) + (add.i32 + (getlocal $count) + (const.i32 1) + ) + ) + ) + + ) + (func $Program_Clear + (param $offset i32) (param $count i32) (local $i i32) + + (block + + ;; for (var (@ = 0); ...) + (setlocal $i (const.i32 0)) + + (label $loop_4096 + (loop + ;; for (...; (@ < @); ...) + + (if + (lts.i32 + (getlocal $i) + (getlocal $count) + ) + (nop) + (break $loop_4096) + ) + + ;; for (...) { + (storeu.1.i8 + (add.i32 + (getlocal $offset) + (getlocal $i) + ) + (const.i32 0) + ) + + ;; for (...; ...; ) + (setlocal $i (add.i32 + (getlocal $i) + (const.i32 1) + )) + ) + ) + ) + + ) + (func $Program_GetResult + (param $index i32) + (result i32) + + (return (loadu.1.i8 (add.i32 + (const.i32 4) + (getlocal $index) + ) )) + ) + (func $Program_GetResultCount + + (result i32) + + (return (loads.1.i32 (const.i32 0) )) + ) + (func $Program_Gotos + + + (block + (stores.1.i32 + (const.i32 0) + (const.i32 0) + ) + (call $Program_Clear (const.i32 4) (const.i32 128) ) + (call $Program_GotosInner ) + ) + + ) + (func $Program_GotosInner + (local $i i32) + (local $currentLabel_0 i32) + + (block + (setlocal $i (const.i32 0)) + + ;; while () + (label $loop_0 + (loop + + (if + (const.i32 1) + (nop) + (break $loop_0) + ) + + ;; while (...) { + (block + + ;; LabelGroup 0 (starting at IL_03) + (setlocal $currentLabel_0 (const.i32 0)) + + (label $labelgroup_0 (loop (label $labelgroup_0_dispatch + ;; Begin Label IL_03 + (if (eq.i32 (getlocal $currentLabel_0) (const.i32 0)) + (block + (setlocal $i (add.i32 + (getlocal $i) + (const.i32 1) + )) + (call $Program_AddResult (const.i32 1) ) + + (label $loop_4097 + (loop + ;; for (...; (@ < 16); ...) + + (if + (lts.i32 + (getlocal $i) + (const.i32 16) + ) + (nop) + (break $loop_4097) + ) + + ;; for (...) { + (block + + (if + (eq.i32 + (getlocal $i) + (const.i32 8) + ) + ;; goto IL_03 + (block (setlocal $currentLabel_0 (const.i32 0)) (break $labelgroup_0_dispatch) ) + ) + (call $Program_AddResult (const.i32 3) ) + ) + + ;; for (...; ...; ) + (setlocal $i (add.i32 + (getlocal $i) + (const.i32 1) + )) + ) + ) + (break $loop_0) + ) + + ) + ;; End Label IL_03 + + ;; Fallthrough exit from labelgroup 0 + (break $labelgroup_0) + ) + )) + ) + ) + ) + ) + + ) + + (export "getResult" $Program_GetResult) + + (export "getResultCount" $Program_GetResultCount) + + (export "gotos" $Program_Gotos) + + (memory 1024 1024) + +) + +(invoke "gotos" ) +(asserteq (invoke "getResultCount" ) (const.i32 16) ) +(asserteq (invoke "getResult" (const.i32 0) ) (const.i32 1) ) +(asserteq (invoke "getResult" (const.i32 1) ) (const.i32 3) ) +(asserteq (invoke "getResult" (const.i32 2) ) (const.i32 3) ) +(asserteq (invoke "getResult" (const.i32 3) ) (const.i32 3) ) +(asserteq (invoke "getResult" (const.i32 4) ) (const.i32 3) ) +(asserteq (invoke "getResult" (const.i32 5) ) (const.i32 3) ) +(asserteq (invoke "getResult" (const.i32 6) ) (const.i32 3) ) +(asserteq (invoke "getResult" (const.i32 7) ) (const.i32 3) ) +(asserteq (invoke "getResult" (const.i32 8) ) (const.i32 1) ) +(asserteq (invoke "getResult" (const.i32 9) ) (const.i32 3) ) +(asserteq (invoke "getResult" (const.i32 10) ) (const.i32 3) ) +(asserteq (invoke "getResult" (const.i32 11) ) (const.i32 3) ) +(asserteq (invoke "getResult" (const.i32 12) ) (const.i32 3) ) +(asserteq (invoke "getResult" (const.i32 13) ) (const.i32 3) ) +(asserteq (invoke "getResult" (const.i32 14) ) (const.i32 3) ) +(asserteq (invoke "getResult" (const.i32 15) ) (const.i32 3) ) +(asserteq (invoke "getResult" (const.i32 16) ) (const.i32 0) ) From 40b7be23102e7ccdc17ce3b1793624c1155649d3 Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Tue, 1 Sep 2015 14:25:50 -0700 Subject: [PATCH 5/5] Updated existing C# tests --- ml-proto/test/countUp.wasm | 38 +++--- ml-proto/test/fannkuch.broken-wasm | 198 ++++++++++++++--------------- ml-proto/test/goto.wasm | 60 ++++----- ml-proto/test/sieve.wasm | 60 ++++----- 4 files changed, 174 insertions(+), 182 deletions(-) diff --git a/ml-proto/test/countUp.wasm b/ml-proto/test/countUp.wasm index fcc7f33830..9150b30ffd 100644 --- a/ml-proto/test/countUp.wasm +++ b/ml-proto/test/countUp.wasm @@ -3,15 +3,14 @@ (module (func $Program_countUp - (param $outOffset i32) (param $count i32) (local $i i32) (local $num i32) - + (param $outOffset i32) (param $count i32) (local $i i32) (block ;; for (var (@ = 0); ...) (setlocal $i (const.i32 0)) - (label $loop_4096 + (label $loop_0 (loop ;; for (...; (@ < @); ...) @@ -21,32 +20,31 @@ (getlocal $count) ) (nop) - (break $loop_4096) + (break $loop_0) ) ;; for (...) { - (block - (stores.1.i32 - (mul.i32 - (add.i32 - (getlocal $outOffset) - (getlocal $i) - ) - (const.i32 4) + (stores.1.i32 + (mul.i32 + (add.i32 + (getlocal $outOffset) + (getlocal $i) ) - (getlocal $i) + (const.i32 4) ) - (setlocal $num (getlocal $i)) - (setlocal $i (add.i32 - (getlocal $num) - (const.i32 1) - )) + (getlocal $i) ) + + ;; for (...; ...; ) + (setlocal $i (add.i32 + (getlocal $i) + (const.i32 1) + )) ) ) ) - ) + (func $Program_readI32 (param $base i32) (param $offset i32) (result i32) @@ -61,13 +59,13 @@ ) (export "countUp" $Program_countUp) - (export "readI32" $Program_readI32) (memory 4096 4096) ) + (invoke "countUp" (const.i32 0) (const.i32 32) ) (invoke "countUp" (const.i32 16) (const.i32 4) ) (asserteq (invoke "readI32" (const.i32 0) (const.i32 0) ) (const.i32 0) ) diff --git a/ml-proto/test/fannkuch.broken-wasm b/ml-proto/test/fannkuch.broken-wasm index 17e5f2908e..8c1c846dc3 100644 --- a/ml-proto/test/fannkuch.broken-wasm +++ b/ml-proto/test/fannkuch.broken-wasm @@ -4,16 +4,15 @@ (func $Program_fannkuch (param $n i32) (local $sign i32) (local $maxflips i32) (local $sum i32) - (local $j i32) (local $num i32) (local $q0 i32) (local $flag i32) - (local $k i32) (local $flips i32) (local $qq i32) (local $flag2 i32) - (local $flag3 i32) (local $l i32) (local $m i32) (local $t i32) - (local $flag4 i32) (local $flag5 i32) (local $t3 i32) (local $i2 i32) - (local $sx i32) (local $flag7 i32) (local $j2 i32) + (local $j i32) (local $q0 i32) (local $k i32) (local $flips i32) + (local $qq i32) (local $l i32) (local $m i32) (local $t i32) + (local $t3 i32) (local $i2 i32) (local $sx i32) (local $j2 i32) + (local $currentLabel_0 i32) (block - ;; LabelGroup 0 + ;; LabelGroup 0 (starting at $entry0) (setlocal $currentLabel_0 (const.i32 0)) (label $labelgroup_0 (loop (label $labelgroup_0_dispatch @@ -27,7 +26,7 @@ ;; for (var (@ = 0); ...) (setlocal $j (const.i32 0)) - (label $loop_4096 + (label $loop_0 (loop ;; for (...; (@ < @); ...) @@ -37,7 +36,7 @@ (getlocal $n) ) (nop) - (break $loop_4096) + (break $loop_0) ) ;; for (...) { @@ -72,41 +71,41 @@ ) (getlocal $j) ) - (setlocal $num (getlocal $j)) - (setlocal $j (add.i32 - (getlocal $num) - (const.i32 1) - )) ) + + ;; for (...; ...; ) + (setlocal $j (add.i32 + (getlocal $j) + (const.i32 1) + )) ) ) ;; while () - (label $loop_4097 + (label $loop_1 (loop (if (const.i32 1) (nop) - (break $loop_4097) + (break $loop_1) ) ;; while (...) { (block (setlocal $q0 (loads.1.i32 (const.i32 128) )) - (setlocal $flag (gts.i32 - (getlocal $q0) - (const.i32 0) - )) (if - (getlocal $flag) + (neq.i32 + (getlocal $q0) + (const.i32 0) + ) (block ;; for (var (@ = 1); ...) (setlocal $k (const.i32 1)) - (label $loop_4098 + (label $loop_2 (loop ;; for (...; (@ < @); ...) @@ -116,33 +115,32 @@ (getlocal $n) ) (nop) - (break $loop_4098) + (break $loop_2) ) ;; for (...) { - (block - (stores.1.i32 - (mul.i32 + (stores.1.i32 + (mul.i32 + (add.i32 + (const.i32 64) + (getlocal $k) + ) + (const.i32 4) + ) + (loads.1.i32 (mul.i32 (add.i32 - (const.i32 64) + (const.i32 32) (getlocal $k) ) (const.i32 4) - ) - (loads.1.i32 (mul.i32 - (add.i32 - (const.i32 32) - (getlocal $k) - ) - (const.i32 4) - ) ) - ) - (setlocal $num (getlocal $k)) - (setlocal $k (add.i32 - (getlocal $num) - (const.i32 1) - )) + ) ) ) + + ;; for (...; ...; ) + (setlocal $k (add.i32 + (getlocal $k) + (const.i32 1) + )) ) ) (setlocal $flips (const.i32 1)) @@ -166,13 +164,12 @@ ) (const.i32 4) ) )) - (setlocal $flag2 (eq.i32 - (getlocal $qq) - (const.i32 0) - )) (if - (getlocal $flag2) + (eq.i32 + (getlocal $qq) + (const.i32 0) + ) (break $loop_3) ) (stores.1.i32 @@ -185,13 +182,12 @@ ) (getlocal $q0) ) - (setlocal $flag3 (ges.i32 - (getlocal $q0) - (const.i32 3) - )) (if - (getlocal $flag3) + (ges.i32 + (getlocal $q0) + (const.i32 3) + ) (block (setlocal $l (const.i32 1)) (setlocal $m (sub.i32 @@ -200,7 +196,7 @@ )) ;; do { - (label $loop_4099 + (label $loop_4 (loop (block (setlocal $t (loads.1.i32 (mul.i32 @@ -236,14 +232,12 @@ ) (getlocal $t) ) - (setlocal $num (getlocal $l)) (setlocal $l (add.i32 - (getlocal $num) + (getlocal $l) (const.i32 1) )) - (setlocal $num (getlocal $m)) (setlocal $m (sub.i32 - (getlocal $num) + (getlocal $m) (const.i32 1) )) ) @@ -256,16 +250,15 @@ (getlocal $m) ) (nop) - (break $loop_4099) + (break $loop_4) ) ) ) ) ) (setlocal $q0 (getlocal $qq)) - (setlocal $num (getlocal $flips)) (setlocal $flips (add.i32 - (getlocal $num) + (getlocal $flips) (const.i32 1) )) ) @@ -278,24 +271,22 @@ (getlocal $flips) ) )) - (setlocal $flag4 (gts.i32 - (getlocal $flips) - (getlocal $maxflips) - )) (if - (getlocal $flag4) + (gts.i32 + (getlocal $flips) + (getlocal $maxflips) + ) (setlocal $maxflips (getlocal $flips)) ) ) ) - (setlocal $flag5 (eq.i32 - (getlocal $sign) - (const.i32 1) - )) (if - (getlocal $flag5) + (eq.i32 + (getlocal $sign) + (const.i32 1) + ) (block (stores.1.i32 (const.i32 132) @@ -346,7 +337,7 @@ ) )) (if - (gts.i32 + (neq.i32 (getlocal $sx) (const.i32 0) ) @@ -367,16 +358,15 @@ (break $loop_5) ) ) - (setlocal $flag7 (eq.i32 + + (if + (eq.i32 (getlocal $i2) (sub.i32 (getlocal $n) (const.i32 1) ) - )) - - (if - (getlocal $flag7) + ) ;; goto Block_8 (block (setlocal $currentLabel_0 (const.i32 1)) (break $labelgroup_0_dispatch) ) ) @@ -395,7 +385,7 @@ ;; for (var (@ = 0); ...) (setlocal $j2 (const.i32 0)) - (label $loop_4100 + (label $loop_6 (loop ;; for (...; (@ <= @); ...) @@ -405,36 +395,35 @@ (getlocal $i2) ) (nop) - (break $loop_4100) + (break $loop_6) ) ;; for (...) { - (block - (stores.1.i32 - (mul.i32 + (stores.1.i32 + (mul.i32 + (add.i32 + (const.i32 32) + (getlocal $j2) + ) + (const.i32 4) + ) + (loads.1.i32 (mul.i32 (add.i32 (const.i32 32) - (getlocal $j2) - ) - (const.i32 4) - ) - (loads.1.i32 (mul.i32 (add.i32 - (const.i32 32) - (add.i32 - (getlocal $j2) - (const.i32 1) - ) + (getlocal $j2) + (const.i32 1) ) - (const.i32 4) - ) ) - ) - (setlocal $num (getlocal $j2)) - (setlocal $j2 (add.i32 - (getlocal $num) - (const.i32 1) - )) + ) + (const.i32 4) + ) ) ) + + ;; for (...; ...; ) + (setlocal $j2 (add.i32 + (getlocal $j2) + (const.i32 1) + )) ) ) (stores.1.i32 @@ -450,12 +439,13 @@ ) (getlocal $t3) ) - (setlocal $num (getlocal $i2)) - (setlocal $i2 (add.i32 - (getlocal $num) - (const.i32 1) - )) ) + + ;; for (...; ...; ) + (setlocal $i2 (add.i32 + (getlocal $i2) + (const.i32 1) + )) ) ) ) @@ -489,8 +479,8 @@ ) )) ) - ) + (func $Program_readI32 (param $base i32) (param $offset i32) (result i32) @@ -505,13 +495,13 @@ ) (export "fannkuch" $Program_fannkuch) - (export "readI32" $Program_readI32) (memory 4096 4096) ) + (invoke "fannkuch" (const.i32 7) ) (asserteq (invoke "readI32" (const.i32 0) (const.i32 0) ) (const.i32 228) ) (asserteq (invoke "readI32" (const.i32 0) (const.i32 1) ) (const.i32 16) ) diff --git a/ml-proto/test/goto.wasm b/ml-proto/test/goto.wasm index 961746f5e7..82fdd34439 100644 --- a/ml-proto/test/goto.wasm +++ b/ml-proto/test/goto.wasm @@ -6,24 +6,21 @@ (param $result i32) (local $count i32) (block - (setlocal $count (loads.1.i32 (const.i32 0) )) + (setlocal $count (call $Program_get_ResultCount)) (storeu.1.i8 (add.i32 - (const.i32 4) + (const.i32 0) (getlocal $count) ) (getlocal $result) ) - (stores.1.i32 - (const.i32 0) - (add.i32 + (call $Program_set_ResultCount (add.i32 (getlocal $count) (const.i32 1) - ) - ) + )) ) - ) + (func $Program_Clear (param $offset i32) (param $count i32) (local $i i32) @@ -32,7 +29,7 @@ ;; for (var (@ = 0); ...) (setlocal $i (const.i32 0)) - (label $loop_4096 + (label $loop_0 (loop ;; for (...; (@ < @); ...) @@ -42,7 +39,7 @@ (getlocal $count) ) (nop) - (break $loop_4096) + (break $loop_0) ) ;; for (...) { @@ -62,36 +59,34 @@ ) ) ) + ) + + (func $Program_get_ResultCount + + (result i32) + (return (load_global $Program_ResultCount_value)) ) + (func $Program_GetResult (param $index i32) (result i32) (return (loadu.1.i8 (add.i32 - (const.i32 4) + (const.i32 0) (getlocal $index) ) )) ) - (func $Program_GetResultCount - (result i32) - - (return (loads.1.i32 (const.i32 0) )) - ) (func $Program_Gotos - (block - (stores.1.i32 - (const.i32 0) - (const.i32 0) - ) - (call $Program_Clear (const.i32 4) (const.i32 128) ) + (call $Program_set_ResultCount (const.i32 0)) + (call $Program_Clear (const.i32 0) (const.i32 128) ) (call $Program_GotosInner ) ) - ) + (func $Program_GotosInner (local $i i32) (local $currentLabel_0 i32) @@ -125,7 +120,7 @@ )) (call $Program_AddResult (const.i32 1) ) - (label $loop_4097 + (label $loop_1 (loop ;; for (...; (@ < 16); ...) @@ -135,7 +130,7 @@ (const.i32 16) ) (nop) - (break $loop_4097) + (break $loop_1) ) ;; for (...) { @@ -173,21 +168,28 @@ ) ) ) - ) - (export "getResult" $Program_GetResult) + (func $Program_set_ResultCount + (param $value i32) - (export "getResultCount" $Program_GetResultCount) + (store_global $Program_ResultCount_value (getlocal $value)) + ) + (export "get_ResultCount" $Program_get_ResultCount) + (export "getResult" $Program_GetResult) (export "gotos" $Program_Gotos) + (export "set_ResultCount" $Program_set_ResultCount) + + (global $Program_ResultCount_value i32) (memory 1024 1024) ) + (invoke "gotos" ) -(asserteq (invoke "getResultCount" ) (const.i32 16) ) +(asserteq (invoke "get_ResultCount" ) (const.i32 16) ) (asserteq (invoke "getResult" (const.i32 0) ) (const.i32 1) ) (asserteq (invoke "getResult" (const.i32 1) ) (const.i32 3) ) (asserteq (invoke "getResult" (const.i32 2) ) (const.i32 3) ) diff --git a/ml-proto/test/sieve.wasm b/ml-proto/test/sieve.wasm index 02d43aeef8..64c3f0076b 100644 --- a/ml-proto/test/sieve.wasm +++ b/ml-proto/test/sieve.wasm @@ -6,27 +6,24 @@ (param $result i32) (local $count i32) (block - (setlocal $count (loads.1.i32 (const.i32 0) )) + (setlocal $count (call $Program_get_ResultCount)) (stores.1.i32 (mul.i32 (add.i32 - (const.i32 4) + (const.i32 0) (getlocal $count) ) (const.i32 4) ) (getlocal $result) ) - (stores.1.i32 - (const.i32 0) - (add.i32 + (call $Program_set_ResultCount (add.i32 (getlocal $count) (const.i32 1) - ) - ) + )) ) - ) + (func $Program_Clear (param $offset i32) (param $count i32) (local $i i32) @@ -35,7 +32,7 @@ ;; for (var (@ = 0); ...) (setlocal $i (const.i32 0)) - (label $loop_4096 + (label $loop_0 (loop ;; for (...; (@ < @); ...) @@ -45,7 +42,7 @@ (getlocal $count) ) (nop) - (break $loop_4096) + (break $loop_0) ) ;; for (...) { @@ -65,36 +62,40 @@ ) ) ) + ) + + (func $Program_get_ResultCount + (result i32) + + (return (load_global $Program_ResultCount_value)) ) + (func $Program_GetResult (param $index i32) (result i32) (return (loads.1.i32 (mul.i32 (add.i32 - (const.i32 4) + (const.i32 0) (getlocal $index) ) (const.i32 4) ) )) ) - (func $Program_GetResultCount - (result i32) + (func $Program_set_ResultCount + (param $value i32) - (return (loads.1.i32 (const.i32 0) )) + (store_global $Program_ResultCount_value (getlocal $value)) ) + (func $Program_Sieve (param $target i32) (local $squareRoot f64) (local $candidate i32) (local $multiple i32) - (block - (stores.1.i32 - (const.i32 0) - (const.i32 0) - ) - (call $Program_Clear (const.i32 4) (const.i32 16384) ) + (call $Program_set_ResultCount (const.i32 0)) + (call $Program_Clear (const.i32 0) (const.i32 16384) ) (call $Program_Clear (const.i32 16388) (getlocal $target) ) (setlocal $squareRoot (sqrt.f64 (converts.i32.f64 (getlocal $target)) )) (call $Program_AddResult (const.i32 2) ) @@ -102,7 +103,7 @@ ;; for (var (@ = 3); ...) (setlocal $candidate (const.i32 3)) - (label $loop_4097 + (label $loop_0 (loop ;; for (...; (@ < @); ...) @@ -112,7 +113,7 @@ (getlocal $target) ) (nop) - (break $loop_4097) + (break $loop_0) ) ;; for (...) { @@ -141,7 +142,7 @@ (getlocal $candidate) )) - (label $loop_4098 + (label $loop_1 (loop ;; for (...; (@ < @); ...) @@ -151,7 +152,7 @@ (getlocal $target) ) (nop) - (break $loop_4098) + (break $loop_1) ) ;; for (...) { @@ -188,21 +189,22 @@ ) ) ) - ) + (export "get_ResultCount" $Program_get_ResultCount) (export "getResult" $Program_GetResult) - - (export "getResultCount" $Program_GetResultCount) - + (export "set_ResultCount" $Program_set_ResultCount) (export "sieve" $Program_Sieve) + (global $Program_ResultCount_value i32) + (memory 131072 131072) ) + (invoke "sieve" (const.i32 24) ) -(asserteq (invoke "getResultCount" ) (const.i32 9) ) +(asserteq (invoke "get_ResultCount" ) (const.i32 9) ) (asserteq (invoke "getResult" (const.i32 0) ) (const.i32 2) ) (asserteq (invoke "getResult" (const.i32 1) ) (const.i32 3) ) (asserteq (invoke "getResult" (const.i32 2) ) (const.i32 5) )