From 85efb6262e90153cb3fb37dd35f4663598470c41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Tue, 3 May 2022 21:38:07 +0200 Subject: [PATCH] Improve sieve-raw-wasm --- src/web/benchmarks/sieve/sieve.wat | 31 ++++++++++++------------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/src/web/benchmarks/sieve/sieve.wat b/src/web/benchmarks/sieve/sieve.wat index bd738f7..f70400a 100644 --- a/src/web/benchmarks/sieve/sieve.wat +++ b/src/web/benchmarks/sieve/sieve.wat @@ -1,5 +1,4 @@ -(module - (import "js" "print" (func $print (param i32))) +(module $sieve-raw (memory 8192) (func $sieve (export "sieve") (param $n i32) (result i32) (local $i i32) @@ -17,29 +16,23 @@ (local.set $i (i32.const 2)) (block $endLoop (loop $loop - (br_if $endLoop (i32.ge_s (i32.mul (local.get $i) (local.get $i)) - (local.get $n))) + (br_if $endLoop (i32.ge_s (i32.mul (local.get $i) (local.get $i)) (local.get $n))) (if (i32.eq (i32.load8_s (local.get $i)) (i32.const 1)) (then (local.set $j (i32.mul (local.get $i) (local.get $i))) - (block $endInnerLoop - (loop $innerLoop - (i32.store8 (local.get $j) (i32.const 0)) - (local.set $j (i32.add (local.get $j) (local.get $i))) - (br_if $endInnerLoop (i32.ge_s (local.get $j) (local.get $n))) - (br $innerLoop))))) + (loop $innerLoop + (i32.store8 (local.get $j) (i32.const 0)) + (local.set $j (i32.add (local.get $j) (local.get $i))) + (br_if $innerLoop (i32.lt_s (local.get $j) (local.get $n)))))) (local.set $i (i32.add (local.get $i) (i32.const 1))) (br $loop))) (local.set $i (i32.const 2)) - (block $endLoop - (loop $loop - (if (i32.eq (i32.load8_s (local.get $i)) (i32.const 1)) - (then - ;; (call $print (local.get $i)) - (local.set $last (local.get $i)))) - (local.set $i (i32.add (local.get $i) (i32.const 1))) - (br_if $endLoop (i32.ge_s (local.get $i) (local.get $n))) - (br $loop))) + (loop $loop + (if (i32.eq (i32.load8_s (local.get $i)) (i32.const 1)) + (then + (local.set $last (local.get $i)))) + (local.set $i (i32.add (local.get $i) (i32.const 1))) + (br_if $loop (i32.lt_s (local.get $i) (local.get $n)))) (return (local.get $last))))