wa-lang.org/wazero@v1.0.2/internal/integration_test/spectest/v2/testdata/float_memory.wast (about)

     1  ;; Test that floating-point load and store are bit-preserving.
     2  
     3  ;; Test that load and store do not canonicalize NaNs as x87 does.
     4  
     5  (module
     6    (memory (data "\00\00\a0\7f"))
     7  
     8    (func (export "f32.load") (result f32) (f32.load (i32.const 0)))
     9    (func (export "i32.load") (result i32) (i32.load (i32.const 0)))
    10    (func (export "f32.store") (f32.store (i32.const 0) (f32.const nan:0x200000)))
    11    (func (export "i32.store") (i32.store (i32.const 0) (i32.const 0x7fa00000)))
    12    (func (export "reset") (i32.store (i32.const 0) (i32.const 0)))
    13  )
    14  
    15  (assert_return (invoke "i32.load") (i32.const 0x7fa00000))
    16  (assert_return (invoke "f32.load") (f32.const nan:0x200000))
    17  (invoke "reset")
    18  (assert_return (invoke "i32.load") (i32.const 0x0))
    19  (assert_return (invoke "f32.load") (f32.const 0.0))
    20  (invoke "f32.store")
    21  (assert_return (invoke "i32.load") (i32.const 0x7fa00000))
    22  (assert_return (invoke "f32.load") (f32.const nan:0x200000))
    23  (invoke "reset")
    24  (assert_return (invoke "i32.load") (i32.const 0x0))
    25  (assert_return (invoke "f32.load") (f32.const 0.0))
    26  (invoke "i32.store")
    27  (assert_return (invoke "i32.load") (i32.const 0x7fa00000))
    28  (assert_return (invoke "f32.load") (f32.const nan:0x200000))
    29  
    30  (module
    31    (memory (data "\00\00\00\00\00\00\f4\7f"))
    32  
    33    (func (export "f64.load") (result f64) (f64.load (i32.const 0)))
    34    (func (export "i64.load") (result i64) (i64.load (i32.const 0)))
    35    (func (export "f64.store") (f64.store (i32.const 0) (f64.const nan:0x4000000000000)))
    36    (func (export "i64.store") (i64.store (i32.const 0) (i64.const 0x7ff4000000000000)))
    37    (func (export "reset") (i64.store (i32.const 0) (i64.const 0)))
    38  )
    39  
    40  (assert_return (invoke "i64.load") (i64.const 0x7ff4000000000000))
    41  (assert_return (invoke "f64.load") (f64.const nan:0x4000000000000))
    42  (invoke "reset")
    43  (assert_return (invoke "i64.load") (i64.const 0x0))
    44  (assert_return (invoke "f64.load") (f64.const 0.0))
    45  (invoke "f64.store")
    46  (assert_return (invoke "i64.load") (i64.const 0x7ff4000000000000))
    47  (assert_return (invoke "f64.load") (f64.const nan:0x4000000000000))
    48  (invoke "reset")
    49  (assert_return (invoke "i64.load") (i64.const 0x0))
    50  (assert_return (invoke "f64.load") (f64.const 0.0))
    51  (invoke "i64.store")
    52  (assert_return (invoke "i64.load") (i64.const 0x7ff4000000000000))
    53  (assert_return (invoke "f64.load") (f64.const nan:0x4000000000000))
    54  
    55  ;; Test that unaligned load and store do not canonicalize NaNs.
    56  
    57  (module
    58    (memory (data "\00\00\00\a0\7f"))
    59  
    60    (func (export "f32.load") (result f32) (f32.load (i32.const 1)))
    61    (func (export "i32.load") (result i32) (i32.load (i32.const 1)))
    62    (func (export "f32.store") (f32.store (i32.const 1) (f32.const nan:0x200000)))
    63    (func (export "i32.store") (i32.store (i32.const 1) (i32.const 0x7fa00000)))
    64    (func (export "reset") (i32.store (i32.const 1) (i32.const 0)))
    65  )
    66  
    67  (assert_return (invoke "i32.load") (i32.const 0x7fa00000))
    68  (assert_return (invoke "f32.load") (f32.const nan:0x200000))
    69  (invoke "reset")
    70  (assert_return (invoke "i32.load") (i32.const 0x0))
    71  (assert_return (invoke "f32.load") (f32.const 0.0))
    72  (invoke "f32.store")
    73  (assert_return (invoke "i32.load") (i32.const 0x7fa00000))
    74  (assert_return (invoke "f32.load") (f32.const nan:0x200000))
    75  (invoke "reset")
    76  (assert_return (invoke "i32.load") (i32.const 0x0))
    77  (assert_return (invoke "f32.load") (f32.const 0.0))
    78  (invoke "i32.store")
    79  (assert_return (invoke "i32.load") (i32.const 0x7fa00000))
    80  (assert_return (invoke "f32.load") (f32.const nan:0x200000))
    81  
    82  (module
    83    (memory (data "\00\00\00\00\00\00\00\f4\7f"))
    84  
    85    (func (export "f64.load") (result f64) (f64.load (i32.const 1)))
    86    (func (export "i64.load") (result i64) (i64.load (i32.const 1)))
    87    (func (export "f64.store") (f64.store (i32.const 1) (f64.const nan:0x4000000000000)))
    88    (func (export "i64.store") (i64.store (i32.const 1) (i64.const 0x7ff4000000000000)))
    89    (func (export "reset") (i64.store (i32.const 1) (i64.const 0)))
    90  )
    91  
    92  (assert_return (invoke "i64.load") (i64.const 0x7ff4000000000000))
    93  (assert_return (invoke "f64.load") (f64.const nan:0x4000000000000))
    94  (invoke "reset")
    95  (assert_return (invoke "i64.load") (i64.const 0x0))
    96  (assert_return (invoke "f64.load") (f64.const 0.0))
    97  (invoke "f64.store")
    98  (assert_return (invoke "i64.load") (i64.const 0x7ff4000000000000))
    99  (assert_return (invoke "f64.load") (f64.const nan:0x4000000000000))
   100  (invoke "reset")
   101  (assert_return (invoke "i64.load") (i64.const 0x0))
   102  (assert_return (invoke "f64.load") (f64.const 0.0))
   103  (invoke "i64.store")
   104  (assert_return (invoke "i64.load") (i64.const 0x7ff4000000000000))
   105  (assert_return (invoke "f64.load") (f64.const nan:0x4000000000000))
   106  
   107  ;; Test that load and store do not canonicalize NaNs as some JS engines do.
   108  
   109  (module
   110    (memory (data "\01\00\d0\7f"))
   111  
   112    (func (export "f32.load") (result f32) (f32.load (i32.const 0)))
   113    (func (export "i32.load") (result i32) (i32.load (i32.const 0)))
   114    (func (export "f32.store") (f32.store (i32.const 0) (f32.const nan:0x500001)))
   115    (func (export "i32.store") (i32.store (i32.const 0) (i32.const 0x7fd00001)))
   116    (func (export "reset") (i32.store (i32.const 0) (i32.const 0)))
   117  )
   118  
   119  (assert_return (invoke "i32.load") (i32.const 0x7fd00001))
   120  (assert_return (invoke "f32.load") (f32.const nan:0x500001))
   121  (invoke "reset")
   122  (assert_return (invoke "i32.load") (i32.const 0x0))
   123  (assert_return (invoke "f32.load") (f32.const 0.0))
   124  (invoke "f32.store")
   125  (assert_return (invoke "i32.load") (i32.const 0x7fd00001))
   126  (assert_return (invoke "f32.load") (f32.const nan:0x500001))
   127  (invoke "reset")
   128  (assert_return (invoke "i32.load") (i32.const 0x0))
   129  (assert_return (invoke "f32.load") (f32.const 0.0))
   130  (invoke "i32.store")
   131  (assert_return (invoke "i32.load") (i32.const 0x7fd00001))
   132  (assert_return (invoke "f32.load") (f32.const nan:0x500001))
   133  
   134  (module
   135    (memory (data "\01\00\00\00\00\00\fc\7f"))
   136  
   137    (func (export "f64.load") (result f64) (f64.load (i32.const 0)))
   138    (func (export "i64.load") (result i64) (i64.load (i32.const 0)))
   139    (func (export "f64.store") (f64.store (i32.const 0) (f64.const nan:0xc000000000001)))
   140    (func (export "i64.store") (i64.store (i32.const 0) (i64.const 0x7ffc000000000001)))
   141    (func (export "reset") (i64.store (i32.const 0) (i64.const 0)))
   142  )
   143  
   144  (assert_return (invoke "i64.load") (i64.const 0x7ffc000000000001))
   145  (assert_return (invoke "f64.load") (f64.const nan:0xc000000000001))
   146  (invoke "reset")
   147  (assert_return (invoke "i64.load") (i64.const 0x0))
   148  (assert_return (invoke "f64.load") (f64.const 0.0))
   149  (invoke "f64.store")
   150  (assert_return (invoke "i64.load") (i64.const 0x7ffc000000000001))
   151  (assert_return (invoke "f64.load") (f64.const nan:0xc000000000001))
   152  (invoke "reset")
   153  (assert_return (invoke "i64.load") (i64.const 0x0))
   154  (assert_return (invoke "f64.load") (f64.const 0.0))
   155  (invoke "i64.store")
   156  (assert_return (invoke "i64.load") (i64.const 0x7ffc000000000001))
   157  (assert_return (invoke "f64.load") (f64.const nan:0xc000000000001))