summaryrefslogtreecommitdiff
path: root/test/spec/float_memory.wast
diff options
context:
space:
mode:
authorJay Phelps <hello@jayphelps.com>2018-09-11 16:09:45 -0400
committerAlon Zakai <alonzakai@gmail.com>2018-09-11 13:09:45 -0700
commit30de95a537857eac7c33b46cdf3606f93dff37c9 (patch)
tree989b06234755d04350f7e7a1bed1e4cf973da931 /test/spec/float_memory.wast
parent249b4b78d765c0f83029c3afd107cbe9ea025681 (diff)
downloadbinaryen-30de95a537857eac7c33b46cdf3606f93dff37c9.tar.gz
binaryen-30de95a537857eac7c33b46cdf3606f93dff37c9.tar.bz2
binaryen-30de95a537857eac7c33b46cdf3606f93dff37c9.zip
check-in the test/spec suite instead of as submodule (#1677)
Diffstat (limited to 'test/spec/float_memory.wast')
-rw-r--r--test/spec/float_memory.wast157
1 files changed, 157 insertions, 0 deletions
diff --git a/test/spec/float_memory.wast b/test/spec/float_memory.wast
new file mode 100644
index 000000000..3801158f9
--- /dev/null
+++ b/test/spec/float_memory.wast
@@ -0,0 +1,157 @@
+;; Test that floating-point load and store are bit-preserving.
+
+;; Test that load and store do not canonicalize NaNs as x87 does.
+
+(module
+ (memory (data "\00\00\a0\7f"))
+
+ (func (export "f32.load") (result f32) (f32.load (i32.const 0)))
+ (func (export "i32.load") (result i32) (i32.load (i32.const 0)))
+ (func (export "f32.store") (f32.store (i32.const 0) (f32.const nan:0x200000)))
+ (func (export "i32.store") (i32.store (i32.const 0) (i32.const 0x7fa00000)))
+ (func (export "reset") (i32.store (i32.const 0) (i32.const 0)))
+)
+
+(assert_return (invoke "i32.load") (i32.const 0x7fa00000))
+(assert_return (invoke "f32.load") (f32.const nan:0x200000))
+(invoke "reset")
+(assert_return (invoke "i32.load") (i32.const 0x0))
+(assert_return (invoke "f32.load") (f32.const 0.0))
+(invoke "f32.store")
+(assert_return (invoke "i32.load") (i32.const 0x7fa00000))
+(assert_return (invoke "f32.load") (f32.const nan:0x200000))
+(invoke "reset")
+(assert_return (invoke "i32.load") (i32.const 0x0))
+(assert_return (invoke "f32.load") (f32.const 0.0))
+(invoke "i32.store")
+(assert_return (invoke "i32.load") (i32.const 0x7fa00000))
+(assert_return (invoke "f32.load") (f32.const nan:0x200000))
+
+(module
+ (memory (data "\00\00\00\00\00\00\f4\7f"))
+
+ (func (export "f64.load") (result f64) (f64.load (i32.const 0)))
+ (func (export "i64.load") (result i64) (i64.load (i32.const 0)))
+ (func (export "f64.store") (f64.store (i32.const 0) (f64.const nan:0x4000000000000)))
+ (func (export "i64.store") (i64.store (i32.const 0) (i64.const 0x7ff4000000000000)))
+ (func (export "reset") (i64.store (i32.const 0) (i64.const 0)))
+)
+
+(assert_return (invoke "i64.load") (i64.const 0x7ff4000000000000))
+(assert_return (invoke "f64.load") (f64.const nan:0x4000000000000))
+(invoke "reset")
+(assert_return (invoke "i64.load") (i64.const 0x0))
+(assert_return (invoke "f64.load") (f64.const 0.0))
+(invoke "f64.store")
+(assert_return (invoke "i64.load") (i64.const 0x7ff4000000000000))
+(assert_return (invoke "f64.load") (f64.const nan:0x4000000000000))
+(invoke "reset")
+(assert_return (invoke "i64.load") (i64.const 0x0))
+(assert_return (invoke "f64.load") (f64.const 0.0))
+(invoke "i64.store")
+(assert_return (invoke "i64.load") (i64.const 0x7ff4000000000000))
+(assert_return (invoke "f64.load") (f64.const nan:0x4000000000000))
+
+;; Test that unaligned load and store do not canonicalize NaNs.
+
+(module
+ (memory (data "\00\00\00\a0\7f"))
+
+ (func (export "f32.load") (result f32) (f32.load (i32.const 1)))
+ (func (export "i32.load") (result i32) (i32.load (i32.const 1)))
+ (func (export "f32.store") (f32.store (i32.const 1) (f32.const nan:0x200000)))
+ (func (export "i32.store") (i32.store (i32.const 1) (i32.const 0x7fa00000)))
+ (func (export "reset") (i32.store (i32.const 1) (i32.const 0)))
+)
+
+(assert_return (invoke "i32.load") (i32.const 0x7fa00000))
+(assert_return (invoke "f32.load") (f32.const nan:0x200000))
+(invoke "reset")
+(assert_return (invoke "i32.load") (i32.const 0x0))
+(assert_return (invoke "f32.load") (f32.const 0.0))
+(invoke "f32.store")
+(assert_return (invoke "i32.load") (i32.const 0x7fa00000))
+(assert_return (invoke "f32.load") (f32.const nan:0x200000))
+(invoke "reset")
+(assert_return (invoke "i32.load") (i32.const 0x0))
+(assert_return (invoke "f32.load") (f32.const 0.0))
+(invoke "i32.store")
+(assert_return (invoke "i32.load") (i32.const 0x7fa00000))
+(assert_return (invoke "f32.load") (f32.const nan:0x200000))
+
+(module
+ (memory (data "\00\00\00\00\00\00\00\f4\7f"))
+
+ (func (export "f64.load") (result f64) (f64.load (i32.const 1)))
+ (func (export "i64.load") (result i64) (i64.load (i32.const 1)))
+ (func (export "f64.store") (f64.store (i32.const 1) (f64.const nan:0x4000000000000)))
+ (func (export "i64.store") (i64.store (i32.const 1) (i64.const 0x7ff4000000000000)))
+ (func (export "reset") (i64.store (i32.const 1) (i64.const 0)))
+)
+
+(assert_return (invoke "i64.load") (i64.const 0x7ff4000000000000))
+(assert_return (invoke "f64.load") (f64.const nan:0x4000000000000))
+(invoke "reset")
+(assert_return (invoke "i64.load") (i64.const 0x0))
+(assert_return (invoke "f64.load") (f64.const 0.0))
+(invoke "f64.store")
+(assert_return (invoke "i64.load") (i64.const 0x7ff4000000000000))
+(assert_return (invoke "f64.load") (f64.const nan:0x4000000000000))
+(invoke "reset")
+(assert_return (invoke "i64.load") (i64.const 0x0))
+(assert_return (invoke "f64.load") (f64.const 0.0))
+(invoke "i64.store")
+(assert_return (invoke "i64.load") (i64.const 0x7ff4000000000000))
+(assert_return (invoke "f64.load") (f64.const nan:0x4000000000000))
+
+;; Test that load and store do not canonicalize NaNs as some JS engines do.
+
+(module
+ (memory (data "\01\00\d0\7f"))
+
+ (func (export "f32.load") (result f32) (f32.load (i32.const 0)))
+ (func (export "i32.load") (result i32) (i32.load (i32.const 0)))
+ (func (export "f32.store") (f32.store (i32.const 0) (f32.const nan:0x500001)))
+ (func (export "i32.store") (i32.store (i32.const 0) (i32.const 0x7fd00001)))
+ (func (export "reset") (i32.store (i32.const 0) (i32.const 0)))
+)
+
+(assert_return (invoke "i32.load") (i32.const 0x7fd00001))
+(assert_return (invoke "f32.load") (f32.const nan:0x500001))
+(invoke "reset")
+(assert_return (invoke "i32.load") (i32.const 0x0))
+(assert_return (invoke "f32.load") (f32.const 0.0))
+(invoke "f32.store")
+(assert_return (invoke "i32.load") (i32.const 0x7fd00001))
+(assert_return (invoke "f32.load") (f32.const nan:0x500001))
+(invoke "reset")
+(assert_return (invoke "i32.load") (i32.const 0x0))
+(assert_return (invoke "f32.load") (f32.const 0.0))
+(invoke "i32.store")
+(assert_return (invoke "i32.load") (i32.const 0x7fd00001))
+(assert_return (invoke "f32.load") (f32.const nan:0x500001))
+
+(module
+ (memory (data "\01\00\00\00\00\00\fc\7f"))
+
+ (func (export "f64.load") (result f64) (f64.load (i32.const 0)))
+ (func (export "i64.load") (result i64) (i64.load (i32.const 0)))
+ (func (export "f64.store") (f64.store (i32.const 0) (f64.const nan:0xc000000000001)))
+ (func (export "i64.store") (i64.store (i32.const 0) (i64.const 0x7ffc000000000001)))
+ (func (export "reset") (i64.store (i32.const 0) (i64.const 0)))
+)
+
+(assert_return (invoke "i64.load") (i64.const 0x7ffc000000000001))
+(assert_return (invoke "f64.load") (f64.const nan:0xc000000000001))
+(invoke "reset")
+(assert_return (invoke "i64.load") (i64.const 0x0))
+(assert_return (invoke "f64.load") (f64.const 0.0))
+(invoke "f64.store")
+(assert_return (invoke "i64.load") (i64.const 0x7ffc000000000001))
+(assert_return (invoke "f64.load") (f64.const nan:0xc000000000001))
+(invoke "reset")
+(assert_return (invoke "i64.load") (i64.const 0x0))
+(assert_return (invoke "f64.load") (f64.const 0.0))
+(invoke "i64.store")
+(assert_return (invoke "i64.load") (i64.const 0x7ffc000000000001))
+(assert_return (invoke "f64.load") (f64.const nan:0xc000000000001))