summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/dot_s/traps.clamp.wast113
-rw-r--r--test/dot_s/traps.js.wast65
-rw-r--r--test/dot_s/traps.s14
-rw-r--r--test/dot_s/traps.wast49
-rw-r--r--test/emcc_hello_world.fromasm.clamp28
-rw-r--r--test/emcc_hello_world.fromasm.clamp.no-opts28
-rw-r--r--test/passes/trap-mode-clamp.txt432
-rw-r--r--test/passes/trap-mode-clamp.wast26
-rw-r--r--test/passes/trap-mode-js.txt334
-rw-r--r--test/passes/trap-mode-js.wast26
-rw-r--r--test/unit.fromasm.clamp63
-rw-r--r--test/unit.fromasm.clamp.no-opts60
-rw-r--r--test/wasm-only.fromasm102
-rw-r--r--test/wasm-only.fromasm.clamp102
-rw-r--r--test/wasm-only.fromasm.clamp.no-opts92
-rw-r--r--test/wasm-only.fromasm.no-opts92
16 files changed, 1564 insertions, 62 deletions
diff --git a/test/dot_s/traps.clamp.wast b/test/dot_s/traps.clamp.wast
new file mode 100644
index 000000000..3cab71072
--- /dev/null
+++ b/test/dot_s/traps.clamp.wast
@@ -0,0 +1,113 @@
+(module
+ (import "env" "memory" (memory $0 1))
+ (table 0 anyfunc)
+ (export "stackSave" (func $stackSave))
+ (export "stackAlloc" (func $stackAlloc))
+ (export "stackRestore" (func $stackRestore))
+ (export "test_traps" (func $test_traps))
+ (func $test_traps (param $0 f32) (param $1 f64) (result i32)
+ (call $i32u-div
+ (call $f32-to-int
+ (get_local $0)
+ )
+ (call $f64-to-uint
+ (get_local $1)
+ )
+ )
+ )
+ (func $f32-to-int (param $0 f32) (result i32)
+ (if (result i32)
+ (f32.ne
+ (get_local $0)
+ (get_local $0)
+ )
+ (i32.const -2147483648)
+ (if (result i32)
+ (f32.ge
+ (get_local $0)
+ (f32.const 2147483648)
+ )
+ (i32.const -2147483648)
+ (if (result i32)
+ (f32.le
+ (get_local $0)
+ (f32.const -2147483648)
+ )
+ (i32.const -2147483648)
+ (i32.trunc_s/f32
+ (get_local $0)
+ )
+ )
+ )
+ )
+ )
+ (func $f64-to-uint (param $0 f64) (result i32)
+ (if (result i32)
+ (f64.ne
+ (get_local $0)
+ (get_local $0)
+ )
+ (i32.const 0)
+ (if (result i32)
+ (f64.ge
+ (get_local $0)
+ (f64.const 4294967296)
+ )
+ (i32.const 0)
+ (if (result i32)
+ (f64.le
+ (get_local $0)
+ (f64.const -1)
+ )
+ (i32.const 0)
+ (i32.trunc_u/f64
+ (get_local $0)
+ )
+ )
+ )
+ )
+ )
+ (func $i32u-div (param $0 i32) (param $1 i32) (result i32)
+ (if (result i32)
+ (i32.eqz
+ (get_local $1)
+ )
+ (i32.const 0)
+ (i32.div_u
+ (get_local $0)
+ (get_local $1)
+ )
+ )
+ )
+ (func $stackSave (result i32)
+ (i32.load offset=4
+ (i32.const 0)
+ )
+ )
+ (func $stackAlloc (param $0 i32) (result i32)
+ (local $1 i32)
+ (set_local $1
+ (i32.load offset=4
+ (i32.const 0)
+ )
+ )
+ (i32.store offset=4
+ (i32.const 0)
+ (i32.and
+ (i32.sub
+ (get_local $1)
+ (get_local $0)
+ )
+ (i32.const -16)
+ )
+ )
+ (get_local $1)
+ )
+ (func $stackRestore (param $0 i32)
+ (i32.store offset=4
+ (i32.const 0)
+ (get_local $0)
+ )
+ )
+)
+;; METADATA: { "asmConsts": {},"staticBump": 12, "initializers": [] }
diff --git a/test/dot_s/traps.js.wast b/test/dot_s/traps.js.wast
new file mode 100644
index 000000000..39d08f4c0
--- /dev/null
+++ b/test/dot_s/traps.js.wast
@@ -0,0 +1,65 @@
+(module
+ (type $FUNCSIG$id (func (param f64) (result i32)))
+ (import "asm2wasm" "f64-to-int" (func $f64-to-int (param f64) (result i32)))
+ (import "env" "memory" (memory $0 1))
+ (table 0 anyfunc)
+ (export "stackSave" (func $stackSave))
+ (export "stackAlloc" (func $stackAlloc))
+ (export "stackRestore" (func $stackRestore))
+ (export "test_traps" (func $test_traps))
+ (func $test_traps (param $0 f32) (param $1 f64) (result i32)
+ (call $i32u-div
+ (call $f64-to-int
+ (f64.promote/f32
+ (get_local $0)
+ )
+ )
+ (call $f64-to-int
+ (get_local $1)
+ )
+ )
+ )
+ (func $i32u-div (param $0 i32) (param $1 i32) (result i32)
+ (if (result i32)
+ (i32.eqz
+ (get_local $1)
+ )
+ (i32.const 0)
+ (i32.div_u
+ (get_local $0)
+ (get_local $1)
+ )
+ )
+ )
+ (func $stackSave (result i32)
+ (i32.load offset=4
+ (i32.const 0)
+ )
+ )
+ (func $stackAlloc (param $0 i32) (result i32)
+ (local $1 i32)
+ (set_local $1
+ (i32.load offset=4
+ (i32.const 0)
+ )
+ )
+ (i32.store offset=4
+ (i32.const 0)
+ (i32.and
+ (i32.sub
+ (get_local $1)
+ (get_local $0)
+ )
+ (i32.const -16)
+ )
+ )
+ (get_local $1)
+ )
+ (func $stackRestore (param $0 i32)
+ (i32.store offset=4
+ (i32.const 0)
+ (get_local $0)
+ )
+ )
+)
+;; METADATA: { "asmConsts": {},"staticBump": 12, "initializers": [] }
diff --git a/test/dot_s/traps.s b/test/dot_s/traps.s
new file mode 100644
index 000000000..b75cf8d00
--- /dev/null
+++ b/test/dot_s/traps.s
@@ -0,0 +1,14 @@
+ .text
+ .file ""
+ .globl test_traps
+ .type test_traps,@function
+test_traps:
+ .param f32, f64
+ .result i32
+# BB#0:
+ i32.trunc_s/f32 $push0=, $0
+ i32.trunc_u/f64 $push1=, $1
+ i32.div_u $push2=, $pop0, $pop1
+ .endfunc
+.Lfunc_end0:
+ .size test_traps, .Lfunc_end0-test_traps
diff --git a/test/dot_s/traps.wast b/test/dot_s/traps.wast
new file mode 100644
index 000000000..2ade5362a
--- /dev/null
+++ b/test/dot_s/traps.wast
@@ -0,0 +1,49 @@
+(module
+ (import "env" "memory" (memory $0 1))
+ (table 0 anyfunc)
+ (export "stackSave" (func $stackSave))
+ (export "stackAlloc" (func $stackAlloc))
+ (export "stackRestore" (func $stackRestore))
+ (export "test_traps" (func $test_traps))
+ (func $test_traps (param $0 f32) (param $1 f64) (result i32)
+ (i32.div_u
+ (i32.trunc_s/f32
+ (get_local $0)
+ )
+ (i32.trunc_u/f64
+ (get_local $1)
+ )
+ )
+ )
+ (func $stackSave (result i32)
+ (i32.load offset=4
+ (i32.const 0)
+ )
+ )
+ (func $stackAlloc (param $0 i32) (result i32)
+ (local $1 i32)
+ (set_local $1
+ (i32.load offset=4
+ (i32.const 0)
+ )
+ )
+ (i32.store offset=4
+ (i32.const 0)
+ (i32.and
+ (i32.sub
+ (get_local $1)
+ (get_local $0)
+ )
+ (i32.const -16)
+ )
+ )
+ (get_local $1)
+ )
+ (func $stackRestore (param $0 i32)
+ (i32.store offset=4
+ (i32.const 0)
+ (get_local $0)
+ )
+ )
+)
+;; METADATA: { "asmConsts": {},"staticBump": 12, "initializers": [] }
diff --git a/test/emcc_hello_world.fromasm.clamp b/test/emcc_hello_world.fromasm.clamp
index b074afa30..e483ed89c 100644
--- a/test/emcc_hello_world.fromasm.clamp
+++ b/test/emcc_hello_world.fromasm.clamp
@@ -2214,6 +2214,32 @@
)
)
)
+ (func $f64-to-uint (param $0 f64) (result i32)
+ (if (result i32)
+ (f64.ne
+ (get_local $0)
+ (get_local $0)
+ )
+ (i32.const 0)
+ (if (result i32)
+ (f64.ge
+ (get_local $0)
+ (f64.const 4294967296)
+ )
+ (i32.const 0)
+ (if (result i32)
+ (f64.le
+ (get_local $0)
+ (f64.const -1)
+ )
+ (i32.const 0)
+ (i32.trunc_u/f64
+ (get_local $0)
+ )
+ )
+ )
+ )
+ )
(func $i32s-div (param $0 i32) (param $1 i32) (result i32)
(if (result i32)
(get_local $1)
@@ -4587,7 +4613,7 @@
(i32.store
(get_local $7)
(tee_local $5
- (call $f64-to-int
+ (call $f64-to-uint
(get_local $15)
)
)
diff --git a/test/emcc_hello_world.fromasm.clamp.no-opts b/test/emcc_hello_world.fromasm.clamp.no-opts
index 3662e5d36..36d34018c 100644
--- a/test/emcc_hello_world.fromasm.clamp.no-opts
+++ b/test/emcc_hello_world.fromasm.clamp.no-opts
@@ -4658,6 +4658,32 @@
)
)
)
+ (func $f64-to-uint (param $0 f64) (result i32)
+ (if (result i32)
+ (f64.ne
+ (get_local $0)
+ (get_local $0)
+ )
+ (i32.const 0)
+ (if (result i32)
+ (f64.ge
+ (get_local $0)
+ (f64.const 4294967296)
+ )
+ (i32.const 0)
+ (if (result i32)
+ (f64.le
+ (get_local $0)
+ (f64.const -1)
+ )
+ (i32.const 0)
+ (i32.trunc_u/f64
+ (get_local $0)
+ )
+ )
+ )
+ )
+ )
(func $i32s-div (param $0 i32) (param $1 i32) (result i32)
(if (result i32)
(i32.eqz
@@ -9934,7 +9960,7 @@
(loop $while-in60
(block $while-out59
(set_local $$conv216$i
- (call $f64-to-int
+ (call $f64-to-uint
(get_local $$y$addr$4$i)
)
)
diff --git a/test/passes/trap-mode-clamp.txt b/test/passes/trap-mode-clamp.txt
new file mode 100644
index 000000000..91ba19203
--- /dev/null
+++ b/test/passes/trap-mode-clamp.txt
@@ -0,0 +1,432 @@
+(module
+ (type $0 (func (param i32 i64)))
+ (type $1 (func (param f32)))
+ (type $2 (func (param f64)))
+ (memory $0 0)
+ (func $test_div (type $0) (param $0 i32) (param $1 i64)
+ (drop
+ (call $i32s-div
+ (get_local $0)
+ (get_local $0)
+ )
+ )
+ (drop
+ (call $i32u-div
+ (get_local $0)
+ (get_local $0)
+ )
+ )
+ (drop
+ (call $i64s-div
+ (get_local $1)
+ (get_local $1)
+ )
+ )
+ (drop
+ (call $i64u-div
+ (get_local $1)
+ (get_local $1)
+ )
+ )
+ )
+ (func $test_rem (type $0) (param $0 i32) (param $1 i64)
+ (drop
+ (call $i32s-rem
+ (get_local $0)
+ (get_local $0)
+ )
+ )
+ (drop
+ (call $i32u-rem
+ (get_local $0)
+ (get_local $0)
+ )
+ )
+ (drop
+ (call $i64s-rem
+ (get_local $1)
+ (get_local $1)
+ )
+ )
+ (drop
+ (call $i64u-rem
+ (get_local $1)
+ (get_local $1)
+ )
+ )
+ )
+ (func $test_f32_to_int (type $1) (param $0 f32)
+ (drop
+ (call $f32-to-int
+ (get_local $0)
+ )
+ )
+ (drop
+ (call $f32-to-uint
+ (get_local $0)
+ )
+ )
+ (drop
+ (call $f32-to-int64
+ (get_local $0)
+ )
+ )
+ (drop
+ (call $f32-to-uint64
+ (get_local $0)
+ )
+ )
+ )
+ (func $test_f64_to_int (type $2) (param $0 f64)
+ (drop
+ (call $f64-to-int
+ (get_local $0)
+ )
+ )
+ (drop
+ (call $f64-to-uint
+ (get_local $0)
+ )
+ )
+ (drop
+ (call $f64-to-int64
+ (get_local $0)
+ )
+ )
+ (drop
+ (call $f64-to-uint64
+ (get_local $0)
+ )
+ )
+ )
+ (func $f32-to-int (param $0 f32) (result i32)
+ (if (result i32)
+ (f32.ne
+ (get_local $0)
+ (get_local $0)
+ )
+ (i32.const -2147483648)
+ (if (result i32)
+ (f32.ge
+ (get_local $0)
+ (f32.const 2147483648)
+ )
+ (i32.const -2147483648)
+ (if (result i32)
+ (f32.le
+ (get_local $0)
+ (f32.const -2147483648)
+ )
+ (i32.const -2147483648)
+ (i32.trunc_s/f32
+ (get_local $0)
+ )
+ )
+ )
+ )
+ )
+ (func $f32-to-int64 (param $0 f32) (result i64)
+ (if (result i64)
+ (f32.ne
+ (get_local $0)
+ (get_local $0)
+ )
+ (i64.const -9223372036854775808)
+ (if (result i64)
+ (f32.ge
+ (get_local $0)
+ (f32.const 9223372036854775808)
+ )
+ (i64.const -9223372036854775808)
+ (if (result i64)
+ (f32.le
+ (get_local $0)
+ (f32.const -9223372036854775808)
+ )
+ (i64.const -9223372036854775808)
+ (i64.trunc_s/f32
+ (get_local $0)
+ )
+ )
+ )
+ )
+ )
+ (func $f32-to-uint (param $0 f32) (result i32)
+ (if (result i32)
+ (f32.ne
+ (get_local $0)
+ (get_local $0)
+ )
+ (i32.const 0)
+ (if (result i32)
+ (f32.ge
+ (get_local $0)
+ (f32.const 4294967296)
+ )
+ (i32.const 0)
+ (if (result i32)
+ (f32.le
+ (get_local $0)
+ (f32.const -1)
+ )
+ (i32.const 0)
+ (i32.trunc_u/f32
+ (get_local $0)
+ )
+ )
+ )
+ )
+ )
+ (func $f32-to-uint64 (param $0 f32) (result i64)
+ (if (result i64)
+ (f32.ne
+ (get_local $0)
+ (get_local $0)
+ )
+ (i64.const 0)
+ (if (result i64)
+ (f32.ge
+ (get_local $0)
+ (f32.const 18446744073709551615)
+ )
+ (i64.const 0)
+ (if (result i64)
+ (f32.le
+ (get_local $0)
+ (f32.const -1)
+ )
+ (i64.const 0)
+ (i64.trunc_u/f32
+ (get_local $0)
+ )
+ )
+ )
+ )
+ )
+ (func $f64-to-int (param $0 f64) (result i32)
+ (if (result i32)
+ (f64.ne
+ (get_local $0)
+ (get_local $0)
+ )
+ (i32.const -2147483648)
+ (if (result i32)
+ (f64.ge
+ (get_local $0)
+ (f64.const 2147483648)
+ )
+ (i32.const -2147483648)
+ (if (result i32)
+ (f64.le
+ (get_local $0)
+ (f64.const -2147483649)
+ )
+ (i32.const -2147483648)
+ (i32.trunc_s/f64
+ (get_local $0)
+ )
+ )
+ )
+ )
+ )
+ (func $f64-to-int64 (param $0 f64) (result i64)
+ (if (result i64)
+ (f64.ne
+ (get_local $0)
+ (get_local $0)
+ )
+ (i64.const -9223372036854775808)
+ (if (result i64)
+ (f64.ge
+ (get_local $0)
+ (f64.const 9223372036854775808)
+ )
+ (i64.const -9223372036854775808)
+ (if (result i64)
+ (f64.le
+ (get_local $0)
+ (f64.const -9223372036854775808)
+ )
+ (i64.const -9223372036854775808)
+ (i64.trunc_s/f64
+ (get_local $0)
+ )
+ )
+ )
+ )
+ )
+ (func $f64-to-uint (param $0 f64) (result i32)
+ (if (result i32)
+ (f64.ne
+ (get_local $0)
+ (get_local $0)
+ )
+ (i32.const 0)
+ (if (result i32)
+ (f64.ge
+ (get_local $0)
+ (f64.const 4294967296)
+ )
+ (i32.const 0)
+ (if (result i32)
+ (f64.le
+ (get_local $0)
+ (f64.const -1)
+ )
+ (i32.const 0)
+ (i32.trunc_u/f64
+ (get_local $0)
+ )
+ )
+ )
+ )
+ )
+ (func $f64-to-uint64 (param $0 f64) (result i64)
+ (if (result i64)
+ (f64.ne
+ (get_local $0)
+ (get_local $0)
+ )
+ (i64.const 0)
+ (if (result i64)
+ (f64.ge
+ (get_local $0)
+ (f64.const 18446744073709551615)
+ )
+ (i64.const 0)
+ (if (result i64)
+ (f64.le
+ (get_local $0)
+ (f64.const -1)
+ )
+ (i64.const 0)
+ (i64.trunc_u/f64
+ (get_local $0)
+ )
+ )
+ )
+ )
+ )
+ (func $i32s-div (param $0 i32) (param $1 i32) (result i32)
+ (if (result i32)
+ (i32.eqz
+ (get_local $1)
+ )
+ (i32.const 0)
+ (if (result i32)
+ (i32.and
+ (i32.eq
+ (get_local $0)
+ (i32.const -2147483648)
+ )
+ (i32.eq
+ (get_local $1)
+ (i32.const -1)
+ )
+ )
+ (i32.const 0)
+ (i32.div_s
+ (get_local $0)
+ (get_local $1)
+ )
+ )
+ )
+ )
+ (func $i32s-rem (param $0 i32) (param $1 i32) (result i32)
+ (if (result i32)
+ (i32.eqz
+ (get_local $1)
+ )
+ (i32.const 0)
+ (i32.rem_s
+ (get_local $0)
+ (get_local $1)
+ )
+ )
+ )
+ (func $i32u-div (param $0 i32) (param $1 i32) (result i32)
+ (if (result i32)
+ (i32.eqz
+ (get_local $1)
+ )
+ (i32.const 0)
+ (i32.div_u
+ (get_local $0)
+ (get_local $1)
+ )
+ )
+ )
+ (func $i32u-rem (param $0 i32) (param $1 i32) (result i32)
+ (if (result i32)
+ (i32.eqz
+ (get_local $1)
+ )
+ (i32.const 0)
+ (i32.rem_u
+ (get_local $0)
+ (get_local $1)
+ )
+ )
+ )
+ (func $i64s-div (param $0 i64) (param $1 i64) (result i64)
+ (if (result i64)
+ (i64.eqz
+ (get_local $1)
+ )
+ (i64.const 0)
+ (if (result i64)
+ (i32.and
+ (i64.eq
+ (get_local $0)
+ (i64.const -9223372036854775808)
+ )
+ (i64.eq
+ (get_local $1)
+ (i64.const -1)
+ )
+ )
+ (i64.const 0)
+ (i64.div_s
+ (get_local $0)
+ (get_local $1)
+ )
+ )
+ )
+ )
+ (func $i64s-rem (param $0 i64) (param $1 i64) (result i64)
+ (if (result i64)
+ (i64.eqz
+ (get_local $1)
+ )
+ (i64.const 0)
+ (i64.rem_s
+ (get_local $0)
+ (get_local $1)
+ )
+ )
+ )
+ (func $i64u-div (param $0 i64) (param $1 i64) (result i64)
+ (if (result i64)
+ (i64.eqz
+ (get_local $1)
+ )
+ (i64.const 0)
+ (i64.div_u
+ (get_local $0)
+ (get_local $1)
+ )
+ )
+ )
+ (func $i64u-rem (param $0 i64) (param $1 i64) (result i64)
+ (if (result i64)
+ (i64.eqz
+ (get_local $1)
+ )
+ (i64.const 0)
+ (i64.rem_u
+ (get_local $0)
+ (get_local $1)
+ )
+ )
+ )
+)
diff --git a/test/passes/trap-mode-clamp.wast b/test/passes/trap-mode-clamp.wast
new file mode 100644
index 000000000..5a44e50ec
--- /dev/null
+++ b/test/passes/trap-mode-clamp.wast
@@ -0,0 +1,26 @@
+(module
+ (func $test_div (param $0 i32) (param $1 i64)
+ (drop (i32.div_s (get_local $0) (get_local $0)))
+ (drop (i32.div_u (get_local $0) (get_local $0)))
+ (drop (i64.div_s (get_local $1) (get_local $1)))
+ (drop (i64.div_u (get_local $1) (get_local $1)))
+ )
+ (func $test_rem (param $0 i32) (param $1 i64)
+ (drop (i32.rem_s (get_local $0) (get_local $0)))
+ (drop (i32.rem_u (get_local $0) (get_local $0)))
+ (drop (i64.rem_s (get_local $1) (get_local $1)))
+ (drop (i64.rem_u (get_local $1) (get_local $1)))
+ )
+ (func $test_f32_to_int (param $0 f32)
+ (drop (i32.trunc_s/f32 (get_local $0)))
+ (drop (i32.trunc_u/f32 (get_local $0)))
+ (drop (i64.trunc_s/f32 (get_local $0)))
+ (drop (i64.trunc_u/f32 (get_local $0)))
+ )
+ (func $test_f64_to_int (param $0 f64)
+ (drop (i32.trunc_s/f64 (get_local $0)))
+ (drop (i32.trunc_u/f64 (get_local $0)))
+ (drop (i64.trunc_s/f64 (get_local $0)))
+ (drop (i64.trunc_u/f64 (get_local $0)))
+ )
+)
diff --git a/test/passes/trap-mode-js.txt b/test/passes/trap-mode-js.txt
new file mode 100644
index 000000000..57ef09f91
--- /dev/null
+++ b/test/passes/trap-mode-js.txt
@@ -0,0 +1,334 @@
+(module
+ (type $0 (func (param i32 i64)))
+ (type $1 (func (param f32)))
+ (type $2 (func (param f64)))
+ (type $FUNCSIG$id (func (param f64) (result i32)))
+ (import "asm2wasm" "f64-to-int" (func $f64-to-int (param f64) (result i32)))
+ (memory $0 0)
+ (func $test_div (type $0) (param $0 i32) (param $1 i64)
+ (drop
+ (call $i32s-div
+ (get_local $0)
+ (get_local $0)
+ )
+ )
+ (drop
+ (call $i32u-div
+ (get_local $0)
+ (get_local $0)
+ )
+ )
+ (drop
+ (call $i64s-div
+ (get_local $1)
+ (get_local $1)
+ )
+ )
+ (drop
+ (call $i64u-div
+ (get_local $1)
+ (get_local $1)
+ )
+ )
+ )
+ (func $test_rem (type $0) (param $0 i32) (param $1 i64)
+ (drop
+ (call $i32s-rem
+ (get_local $0)
+ (get_local $0)
+ )
+ )
+ (drop
+ (call $i32u-rem
+ (get_local $0)
+ (get_local $0)
+ )
+ )
+ (drop
+ (call $i64s-rem
+ (get_local $1)
+ (get_local $1)
+ )
+ )
+ (drop
+ (call $i64u-rem
+ (get_local $1)
+ (get_local $1)
+ )
+ )
+ )
+ (func $test_f32_to_int (type $1) (param $0 f32)
+ (drop
+ (call $f64-to-int
+ (f64.promote/f32
+ (get_local $0)
+ )
+ )
+ )
+ (drop
+ (call $f64-to-int
+ (f64.promote/f32
+ (get_local $0)
+ )
+ )
+ )
+ (drop
+ (call $f32-to-int64
+ (get_local $0)
+ )
+ )
+ (drop
+ (call $f32-to-uint64
+ (get_local $0)
+ )
+ )
+ )
+ (func $test_f64_to_int (type $2) (param $0 f64)
+ (drop
+ (call $f64-to-int
+ (get_local $0)
+ )
+ )
+ (drop
+ (call $f64-to-int
+ (get_local $0)
+ )
+ )
+ (drop
+ (call $f64-to-int64
+ (get_local $0)
+ )
+ )
+ (drop
+ (call $f64-to-uint64
+ (get_local $0)
+ )
+ )
+ )
+ (func $f32-to-int64 (param $0 f32) (result i64)
+ (if (result i64)
+ (f32.ne
+ (get_local $0)
+ (get_local $0)
+ )
+ (i64.const -9223372036854775808)
+ (if (result i64)
+ (f32.ge
+ (get_local $0)
+ (f32.const 9223372036854775808)
+ )
+ (i64.const -9223372036854775808)
+ (if (result i64)
+ (f32.le
+ (get_local $0)
+ (f32.const -9223372036854775808)
+ )
+ (i64.const -9223372036854775808)
+ (i64.trunc_s/f32
+ (get_local $0)
+ )
+ )
+ )
+ )
+ )
+ (func $f32-to-uint64 (param $0 f32) (result i64)
+ (if (result i64)
+ (f32.ne
+ (get_local $0)
+ (get_local $0)
+ )
+ (i64.const 0)
+ (if (result i64)
+ (f32.ge
+ (get_local $0)
+ (f32.const 18446744073709551615)
+ )
+ (i64.const 0)
+ (if (result i64)
+ (f32.le
+ (get_local $0)
+ (f32.const -1)
+ )
+ (i64.const 0)
+ (i64.trunc_u/f32
+ (get_local $0)
+ )
+ )
+ )
+ )
+ )
+ (func $f64-to-int64 (param $0 f64) (result i64)
+ (if (result i64)
+ (f64.ne
+ (get_local $0)
+ (get_local $0)
+ )
+ (i64.const -9223372036854775808)
+ (if (result i64)
+ (f64.ge
+ (get_local $0)
+ (f64.const 9223372036854775808)
+ )
+ (i64.const -9223372036854775808)
+ (if (result i64)
+ (f64.le
+ (get_local $0)
+ (f64.const -9223372036854775808)
+ )
+ (i64.const -9223372036854775808)
+ (i64.trunc_s/f64
+ (get_local $0)
+ )
+ )
+ )
+ )
+ )
+ (func $f64-to-uint64 (param $0 f64) (result i64)
+ (if (result i64)
+ (f64.ne
+ (get_local $0)
+ (get_local $0)
+ )
+ (i64.const 0)
+ (if (result i64)
+ (f64.ge
+ (get_local $0)
+ (f64.const 18446744073709551615)
+ )
+ (i64.const 0)
+ (if (result i64)
+ (f64.le
+ (get_local $0)
+ (f64.const -1)
+ )
+ (i64.const 0)
+ (i64.trunc_u/f64
+ (get_local $0)
+ )
+ )
+ )
+ )
+ )
+ (func $i32s-div (param $0 i32) (param $1 i32) (result i32)
+ (if (result i32)
+ (i32.eqz
+ (get_local $1)
+ )
+ (i32.const 0)
+ (if (result i32)
+ (i32.and
+ (i32.eq
+ (get_local $0)
+ (i32.const -2147483648)
+ )
+ (i32.eq
+ (get_local $1)
+ (i32.const -1)
+ )
+ )
+ (i32.const 0)
+ (i32.div_s
+ (get_local $0)
+ (get_local $1)
+ )
+ )
+ )
+ )
+ (func $i32s-rem (param $0 i32) (param $1 i32) (result i32)
+ (if (result i32)
+ (i32.eqz
+ (get_local $1)
+ )
+ (i32.const 0)
+ (i32.rem_s
+ (get_local $0)
+ (get_local $1)
+ )
+ )
+ )
+ (func $i32u-div (param $0 i32) (param $1 i32) (result i32)
+ (if (result i32)
+ (i32.eqz
+ (get_local $1)
+ )
+ (i32.const 0)
+ (i32.div_u
+ (get_local $0)
+ (get_local $1)
+ )
+ )
+ )
+ (func $i32u-rem (param $0 i32) (param $1 i32) (result i32)
+ (if (result i32)
+ (i32.eqz
+ (get_local $1)
+ )
+ (i32.const 0)
+ (i32.rem_u
+ (get_local $0)
+ (get_local $1)
+ )
+ )
+ )
+ (func $i64s-div (param $0 i64) (param $1 i64) (result i64)
+ (if (result i64)
+ (i64.eqz
+ (get_local $1)
+ )
+ (i64.const 0)
+ (if (result i64)
+ (i32.and
+ (i64.eq
+ (get_local $0)
+ (i64.const -9223372036854775808)
+ )
+ (i64.eq
+ (get_local $1)
+ (i64.const -1)
+ )
+ )
+ (i64.const 0)
+ (i64.div_s
+ (get_local $0)
+ (get_local $1)
+ )
+ )
+ )
+ )
+ (func $i64s-rem (param $0 i64) (param $1 i64) (result i64)
+ (if (result i64)
+ (i64.eqz
+ (get_local $1)
+ )
+ (i64.const 0)
+ (i64.rem_s
+ (get_local $0)
+ (get_local $1)
+ )
+ )
+ )
+ (func $i64u-div (param $0 i64) (param $1 i64) (result i64)
+ (if (result i64)
+ (i64.eqz
+ (get_local $1)
+ )
+ (i64.const 0)
+ (i64.div_u
+ (get_local $0)
+ (get_local $1)
+ )
+ )
+ )
+ (func $i64u-rem (param $0 i64) (param $1 i64) (result i64)
+ (if (result i64)
+ (i64.eqz
+ (get_local $1)
+ )
+ (i64.const 0)
+ (i64.rem_u
+ (get_local $0)
+ (get_local $1)
+ )
+ )
+ )
+)
diff --git a/test/passes/trap-mode-js.wast b/test/passes/trap-mode-js.wast
new file mode 100644
index 000000000..5a44e50ec
--- /dev/null
+++ b/test/passes/trap-mode-js.wast
@@ -0,0 +1,26 @@
+(module
+ (func $test_div (param $0 i32) (param $1 i64)
+ (drop (i32.div_s (get_local $0) (get_local $0)))
+ (drop (i32.div_u (get_local $0) (get_local $0)))
+ (drop (i64.div_s (get_local $1) (get_local $1)))
+ (drop (i64.div_u (get_local $1) (get_local $1)))
+ )
+ (func $test_rem (param $0 i32) (param $1 i64)
+ (drop (i32.rem_s (get_local $0) (get_local $0)))
+ (drop (i32.rem_u (get_local $0) (get_local $0)))
+ (drop (i64.rem_s (get_local $1) (get_local $1)))
+ (drop (i64.rem_u (get_local $1) (get_local $1)))
+ )
+ (func $test_f32_to_int (param $0 f32)
+ (drop (i32.trunc_s/f32 (get_local $0)))
+ (drop (i32.trunc_u/f32 (get_local $0)))
+ (drop (i64.trunc_s/f32 (get_local $0)))
+ (drop (i64.trunc_u/f32 (get_local $0)))
+ )
+ (func $test_f64_to_int (param $0 f64)
+ (drop (i32.trunc_s/f64 (get_local $0)))
+ (drop (i32.trunc_u/f64 (get_local $0)))
+ (drop (i64.trunc_s/f64 (get_local $0)))
+ (drop (i64.trunc_u/f64 (get_local $0)))
+ )
+)
diff --git a/test/unit.fromasm.clamp b/test/unit.fromasm.clamp
index 4393c362c..c4f133481 100644
--- a/test/unit.fromasm.clamp
+++ b/test/unit.fromasm.clamp
@@ -168,6 +168,32 @@
)
)
)
+ (func $f32-to-int (param $0 f32) (result i32)
+ (if (result i32)
+ (f32.ne
+ (get_local $0)
+ (get_local $0)
+ )
+ (i32.const -2147483648)
+ (if (result i32)
+ (f32.ge
+ (get_local $0)
+ (f32.const 2147483648)
+ )
+ (i32.const -2147483648)
+ (if (result i32)
+ (f32.le
+ (get_local $0)
+ (f32.const -2147483648)
+ )
+ (i32.const -2147483648)
+ (i32.trunc_s/f32
+ (get_local $0)
+ )
+ )
+ )
+ )
+ )
(func $conversions (param $0 i32) (param $1 f64) (param $2 f32)
(drop
(call $f64-to-int
@@ -175,10 +201,8 @@
)
)
(drop
- (call $f64-to-int
- (f64.promote/f32
- (get_local $2)
- )
+ (call $f32-to-int
+ (get_local $2)
)
)
)
@@ -1186,9 +1210,30 @@
)
)
)
- (func $f2u (param $0 f64) (result i32)
- (call $f64-to-int
- (get_local $0)
+ (func $f64-to-uint (param $0 f64) (result i32)
+ (if (result i32)
+ (f64.ne
+ (get_local $0)
+ (get_local $0)
+ )
+ (i32.const 0)
+ (if (result i32)
+ (f64.ge
+ (get_local $0)
+ (f64.const 4294967296)
+ )
+ (i32.const 0)
+ (if (result i32)
+ (f64.le
+ (get_local $0)
+ (f64.const -1)
+ )
+ (i32.const 0)
+ (i32.trunc_u/f64
+ (get_local $0)
+ )
+ )
+ )
)
)
(func $keepAlive
@@ -1203,12 +1248,12 @@
)
)
(drop
- (call $f2u
+ (call $f64-to-uint
(f64.const 100)
)
)
(drop
- (call $f2u
+ (call $f64-to-int
(f64.const 100)
)
)
diff --git a/test/unit.fromasm.clamp.no-opts b/test/unit.fromasm.clamp.no-opts
index 00b1814c4..b1b22cf66 100644
--- a/test/unit.fromasm.clamp.no-opts
+++ b/test/unit.fromasm.clamp.no-opts
@@ -234,6 +234,32 @@
)
)
)
+ (func $f32-to-int (param $0 f32) (result i32)
+ (if (result i32)
+ (f32.ne
+ (get_local $0)
+ (get_local $0)
+ )
+ (i32.const -2147483648)
+ (if (result i32)
+ (f32.ge
+ (get_local $0)
+ (f32.const 2147483648)
+ )
+ (i32.const -2147483648)
+ (if (result i32)
+ (f32.le
+ (get_local $0)
+ (f32.const -2147483648)
+ )
+ (i32.const -2147483648)
+ (i32.trunc_s/f32
+ (get_local $0)
+ )
+ )
+ )
+ )
+ )
(func $conversions (param $i i32) (param $d f64) (param $f f32)
(set_local $i
(call $f64-to-int
@@ -241,10 +267,8 @@
)
)
(set_local $i
- (call $f64-to-int
- (f64.promote/f32
- (get_local $f)
- )
+ (call $f32-to-int
+ (get_local $f)
)
)
(set_local $d
@@ -1972,9 +1996,35 @@
)
)
)
+ (func $f64-to-uint (param $0 f64) (result i32)
+ (if (result i32)
+ (f64.ne
+ (get_local $0)
+ (get_local $0)
+ )
+ (i32.const 0)
+ (if (result i32)
+ (f64.ge
+ (get_local $0)
+ (f64.const 4294967296)
+ )
+ (i32.const 0)
+ (if (result i32)
+ (f64.le
+ (get_local $0)
+ (f64.const -1)
+ )
+ (i32.const 0)
+ (i32.trunc_u/f64
+ (get_local $0)
+ )
+ )
+ )
+ )
+ )
(func $f2u (param $x f64) (result i32)
(return
- (call $f64-to-int
+ (call $f64-to-uint
(get_local $x)
)
)
diff --git a/test/wasm-only.fromasm b/test/wasm-only.fromasm
index 2ac96b8ae..6eb8bb5fe 100644
--- a/test/wasm-only.fromasm
+++ b/test/wasm-only.fromasm
@@ -266,6 +266,32 @@
)
)
)
+ (func $f32-to-int64 (param $0 f32) (result i64)
+ (if (result i64)
+ (f32.ne
+ (get_local $0)
+ (get_local $0)
+ )
+ (i64.const -9223372036854775808)
+ (if (result i64)
+ (f32.ge
+ (get_local $0)
+ (f32.const 9223372036854775808)
+ )
+ (i64.const -9223372036854775808)
+ (if (result i64)
+ (f32.le
+ (get_local $0)
+ (f32.const -9223372036854775808)
+ )
+ (i64.const -9223372036854775808)
+ (i64.trunc_s/f32
+ (get_local $0)
+ )
+ )
+ )
+ )
+ )
(func $f64-to-int64 (param $0 f64) (result i64)
(if (result i64)
(f64.ne
@@ -292,6 +318,58 @@
)
)
)
+ (func $f32-to-uint64 (param $0 f32) (result i64)
+ (if (result i64)
+ (f32.ne
+ (get_local $0)
+ (get_local $0)
+ )
+ (i64.const 0)
+ (if (result i64)
+ (f32.ge
+ (get_local $0)
+ (f32.const 18446744073709551615)
+ )
+ (i64.const 0)
+ (if (result i64)
+ (f32.le
+ (get_local $0)
+ (f32.const -1)
+ )
+ (i64.const 0)
+ (i64.trunc_u/f32
+ (get_local $0)
+ )
+ )
+ )
+ )
+ )
+ (func $f64-to-uint64 (param $0 f64) (result i64)
+ (if (result i64)
+ (f64.ne
+ (get_local $0)
+ (get_local $0)
+ )
+ (i64.const 0)
+ (if (result i64)
+ (f64.ge
+ (get_local $0)
+ (f64.const 18446744073709551615)
+ )
+ (i64.const 0)
+ (if (result i64)
+ (f64.le
+ (get_local $0)
+ (f64.const -1)
+ )
+ (i64.const 0)
+ (i64.trunc_u/f64
+ (get_local $0)
+ )
+ )
+ )
+ )
+ )
(func $test64
(local $0 i64)
(local $1 f32)
@@ -376,15 +454,13 @@
(get_local $0)
)
(drop
- (call $f64-to-int64
- (f64.promote/f32
- (tee_local $1
- (f32.convert_u/i64
- (tee_local $0
- (i64.extend_u/i32
- (i32.wrap/i64
- (get_local $0)
- )
+ (call $f32-to-int64
+ (tee_local $1
+ (f32.convert_u/i64
+ (tee_local $0
+ (i64.extend_u/i32
+ (i32.wrap/i64
+ (get_local $0)
)
)
)
@@ -402,14 +478,12 @@
)
)
(drop
- (call $f64-to-int64
- (f64.promote/f32
- (get_local $1)
- )
+ (call $f32-to-uint64
+ (get_local $1)
)
)
(drop
- (call $f64-to-int64
+ (call $f64-to-uint64
(get_local $2)
)
)
diff --git a/test/wasm-only.fromasm.clamp b/test/wasm-only.fromasm.clamp
index 2ac96b8ae..6eb8bb5fe 100644
--- a/test/wasm-only.fromasm.clamp
+++ b/test/wasm-only.fromasm.clamp
@@ -266,6 +266,32 @@
)
)
)
+ (func $f32-to-int64 (param $0 f32) (result i64)
+ (if (result i64)
+ (f32.ne
+ (get_local $0)
+ (get_local $0)
+ )
+ (i64.const -9223372036854775808)
+ (if (result i64)
+ (f32.ge
+ (get_local $0)
+ (f32.const 9223372036854775808)
+ )
+ (i64.const -9223372036854775808)
+ (if (result i64)
+ (f32.le
+ (get_local $0)
+ (f32.const -9223372036854775808)
+ )
+ (i64.const -9223372036854775808)
+ (i64.trunc_s/f32
+ (get_local $0)
+ )
+ )
+ )
+ )
+ )
(func $f64-to-int64 (param $0 f64) (result i64)
(if (result i64)
(f64.ne
@@ -292,6 +318,58 @@
)
)
)
+ (func $f32-to-uint64 (param $0 f32) (result i64)
+ (if (result i64)
+ (f32.ne
+ (get_local $0)
+ (get_local $0)
+ )
+ (i64.const 0)
+ (if (result i64)
+ (f32.ge
+ (get_local $0)
+ (f32.const 18446744073709551615)
+ )
+ (i64.const 0)
+ (if (result i64)
+ (f32.le
+ (get_local $0)
+ (f32.const -1)
+ )
+ (i64.const 0)
+ (i64.trunc_u/f32
+ (get_local $0)
+ )
+ )
+ )
+ )
+ )
+ (func $f64-to-uint64 (param $0 f64) (result i64)
+ (if (result i64)
+ (f64.ne
+ (get_local $0)
+ (get_local $0)
+ )
+ (i64.const 0)
+ (if (result i64)
+ (f64.ge
+ (get_local $0)
+ (f64.const 18446744073709551615)
+ )
+ (i64.const 0)
+ (if (result i64)
+ (f64.le
+ (get_local $0)
+ (f64.const -1)
+ )
+ (i64.const 0)
+ (i64.trunc_u/f64
+ (get_local $0)
+ )
+ )
+ )
+ )
+ )
(func $test64
(local $0 i64)
(local $1 f32)
@@ -376,15 +454,13 @@
(get_local $0)
)
(drop
- (call $f64-to-int64
- (f64.promote/f32
- (tee_local $1
- (f32.convert_u/i64
- (tee_local $0
- (i64.extend_u/i32
- (i32.wrap/i64
- (get_local $0)
- )
+ (call $f32-to-int64
+ (tee_local $1
+ (f32.convert_u/i64
+ (tee_local $0
+ (i64.extend_u/i32
+ (i32.wrap/i64
+ (get_local $0)
)
)
)
@@ -402,14 +478,12 @@
)
)
(drop
- (call $f64-to-int64
- (f64.promote/f32
- (get_local $1)
- )
+ (call $f32-to-uint64
+ (get_local $1)
)
)
(drop
- (call $f64-to-int64
+ (call $f64-to-uint64
(get_local $2)
)
)
diff --git a/test/wasm-only.fromasm.clamp.no-opts b/test/wasm-only.fromasm.clamp.no-opts
index c0cfa4676..bbb32c5f3 100644
--- a/test/wasm-only.fromasm.clamp.no-opts
+++ b/test/wasm-only.fromasm.clamp.no-opts
@@ -343,6 +343,32 @@
)
)
)
+ (func $f32-to-int64 (param $0 f32) (result i64)
+ (if (result i64)
+ (f32.ne
+ (get_local $0)
+ (get_local $0)
+ )
+ (i64.const -9223372036854775808)
+ (if (result i64)
+ (f32.ge
+ (get_local $0)
+ (f32.const 9223372036854775808)
+ )
+ (i64.const -9223372036854775808)
+ (if (result i64)
+ (f32.le
+ (get_local $0)
+ (f32.const -9223372036854775808)
+ )
+ (i64.const -9223372036854775808)
+ (i64.trunc_s/f32
+ (get_local $0)
+ )
+ )
+ )
+ )
+ )
(func $f64-to-int64 (param $0 f64) (result i64)
(if (result i64)
(f64.ne
@@ -369,6 +395,58 @@
)
)
)
+ (func $f32-to-uint64 (param $0 f32) (result i64)
+ (if (result i64)
+ (f32.ne
+ (get_local $0)
+ (get_local $0)
+ )
+ (i64.const 0)
+ (if (result i64)
+ (f32.ge
+ (get_local $0)
+ (f32.const 18446744073709551615)
+ )
+ (i64.const 0)
+ (if (result i64)
+ (f32.le
+ (get_local $0)
+ (f32.const -1)
+ )
+ (i64.const 0)
+ (i64.trunc_u/f32
+ (get_local $0)
+ )
+ )
+ )
+ )
+ )
+ (func $f64-to-uint64 (param $0 f64) (result i64)
+ (if (result i64)
+ (f64.ne
+ (get_local $0)
+ (get_local $0)
+ )
+ (i64.const 0)
+ (if (result i64)
+ (f64.ge
+ (get_local $0)
+ (f64.const 18446744073709551615)
+ )
+ (i64.const 0)
+ (if (result i64)
+ (f64.le
+ (get_local $0)
+ (f64.const -1)
+ )
+ (i64.const 0)
+ (i64.trunc_u/f64
+ (get_local $0)
+ )
+ )
+ )
+ )
+ )
(func $test64
(local $x i64)
(local $y i64)
@@ -601,10 +679,8 @@
)
)
(set_local $x
- (call $f64-to-int64
- (f64.promote/f32
- (get_local $float32)
- )
+ (call $f32-to-int64
+ (get_local $float32)
)
)
(set_local $x
@@ -613,14 +689,12 @@
)
)
(set_local $x
- (call $f64-to-int64
- (f64.promote/f32
- (get_local $float32)
- )
+ (call $f32-to-uint64
+ (get_local $float32)
)
)
(set_local $x
- (call $f64-to-int64
+ (call $f64-to-uint64
(get_local $float64)
)
)
diff --git a/test/wasm-only.fromasm.no-opts b/test/wasm-only.fromasm.no-opts
index c0cfa4676..bbb32c5f3 100644
--- a/test/wasm-only.fromasm.no-opts
+++ b/test/wasm-only.fromasm.no-opts
@@ -343,6 +343,32 @@
)
)
)
+ (func $f32-to-int64 (param $0 f32) (result i64)
+ (if (result i64)
+ (f32.ne
+ (get_local $0)
+ (get_local $0)
+ )
+ (i64.const -9223372036854775808)
+ (if (result i64)
+ (f32.ge
+ (get_local $0)
+ (f32.const 9223372036854775808)
+ )
+ (i64.const -9223372036854775808)
+ (if (result i64)
+ (f32.le
+ (get_local $0)
+ (f32.const -9223372036854775808)
+ )
+ (i64.const -9223372036854775808)
+ (i64.trunc_s/f32
+ (get_local $0)
+ )
+ )
+ )
+ )
+ )
(func $f64-to-int64 (param $0 f64) (result i64)
(if (result i64)
(f64.ne
@@ -369,6 +395,58 @@
)
)
)
+ (func $f32-to-uint64 (param $0 f32) (result i64)
+ (if (result i64)
+ (f32.ne
+ (get_local $0)
+ (get_local $0)
+ )
+ (i64.const 0)
+ (if (result i64)
+ (f32.ge
+ (get_local $0)
+ (f32.const 18446744073709551615)
+ )
+ (i64.const 0)
+ (if (result i64)
+ (f32.le
+ (get_local $0)
+ (f32.const -1)
+ )
+ (i64.const 0)
+ (i64.trunc_u/f32
+ (get_local $0)
+ )
+ )
+ )
+ )
+ )
+ (func $f64-to-uint64 (param $0 f64) (result i64)
+ (if (result i64)
+ (f64.ne
+ (get_local $0)
+ (get_local $0)
+ )
+ (i64.const 0)
+ (if (result i64)
+ (f64.ge
+ (get_local $0)
+ (f64.const 18446744073709551615)
+ )
+ (i64.const 0)
+ (if (result i64)
+ (f64.le
+ (get_local $0)
+ (f64.const -1)
+ )
+ (i64.const 0)
+ (i64.trunc_u/f64
+ (get_local $0)
+ )
+ )
+ )
+ )
+ )
(func $test64
(local $x i64)
(local $y i64)
@@ -601,10 +679,8 @@
)
)
(set_local $x
- (call $f64-to-int64
- (f64.promote/f32
- (get_local $float32)
- )
+ (call $f32-to-int64
+ (get_local $float32)
)
)
(set_local $x
@@ -613,14 +689,12 @@
)
)
(set_local $x
- (call $f64-to-int64
- (f64.promote/f32
- (get_local $float32)
- )
+ (call $f32-to-uint64
+ (get_local $float32)
)
)
(set_local $x
- (call $f64-to-int64
+ (call $f64-to-uint64
(get_local $float64)
)
)