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

     1  ;; Tests for the *_splat instructions
     2  
     3  (module
     4    (func (export "i8x16.splat") (param i32) (result v128) (i8x16.splat (local.get 0)))
     5    (func (export "i16x8.splat") (param i32) (result v128) (i16x8.splat (local.get 0)))
     6    (func (export "i32x4.splat") (param i32) (result v128) (i32x4.splat (local.get 0)))
     7    (func (export "f32x4.splat") (param f32) (result v128) (f32x4.splat (local.get 0)))
     8    (func (export "i64x2.splat") (param i64) (result v128) (i64x2.splat (local.get 0)))
     9    (func (export "f64x2.splat") (param f64) (result v128) (f64x2.splat (local.get 0)))
    10  )
    11  
    12  (assert_return (invoke "i8x16.splat" (i32.const 0)) (v128.const i8x16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0))
    13  (assert_return (invoke "i8x16.splat" (i32.const 5)) (v128.const i8x16 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5))
    14  (assert_return (invoke "i8x16.splat" (i32.const -5)) (v128.const i8x16 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5))
    15  (assert_return (invoke "i8x16.splat" (i32.const 257)) (v128.const i8x16 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1))
    16  (assert_return (invoke "i8x16.splat" (i32.const 0xff)) (v128.const i8x16 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1))
    17  (assert_return (invoke "i8x16.splat" (i32.const -128)) (v128.const i8x16 -128 -128 -128 -128 -128 -128 -128 -128 -128 -128 -128 -128 -128 -128 -128 -128))
    18  (assert_return (invoke "i8x16.splat" (i32.const 127)) (v128.const i8x16 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127))
    19  (assert_return (invoke "i8x16.splat" (i32.const -129)) (v128.const i8x16 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127))
    20  (assert_return (invoke "i8x16.splat" (i32.const 128)) (v128.const i8x16 -128 -128 -128 -128 -128 -128 -128 -128 -128 -128 -128 -128 -128 -128 -128 -128))
    21  (assert_return (invoke "i8x16.splat" (i32.const 0xff7f)) (v128.const i8x16 0x7f 0x7f 0x7f 0x7f 0x7f 0x7f 0x7f 0x7f 0x7f 0x7f 0x7f 0x7f 0x7f 0x7f 0x7f 0x7f))
    22  (assert_return (invoke "i8x16.splat" (i32.const 0x80)) (v128.const i8x16 0x80 0x80 0x80 0x80 0x80 0x80 0x80 0x80 0x80 0x80 0x80 0x80 0x80 0x80 0x80 0x80))
    23  (assert_return (invoke "i8x16.splat" (i32.const 0xAB)) (v128.const i32x4 0xABABABAB 0xABABABAB 0xABABABAB 0xABABABAB))
    24  
    25  (assert_return (invoke "i16x8.splat" (i32.const 0)) (v128.const i16x8 0 0 0 0 0 0 0 0))
    26  (assert_return (invoke "i16x8.splat" (i32.const 5)) (v128.const i16x8 5 5 5 5 5 5 5 5))
    27  (assert_return (invoke "i16x8.splat" (i32.const -5)) (v128.const i16x8 -5 -5 -5 -5 -5 -5 -5 -5))
    28  (assert_return (invoke "i16x8.splat" (i32.const 65537)) (v128.const i16x8 1 1 1 1 1 1 1 1))
    29  (assert_return (invoke "i16x8.splat" (i32.const 0xffff)) (v128.const i16x8 -1 -1 -1 -1 -1 -1 -1 -1))
    30  (assert_return (invoke "i16x8.splat" (i32.const -32768)) (v128.const i16x8 -32768 -32768 -32768 -32768 -32768 -32768 -32768 -32768))
    31  (assert_return (invoke "i16x8.splat" (i32.const 32767)) (v128.const i16x8 32767 32767 32767 32767 32767 32767 32767 32767))
    32  (assert_return (invoke "i16x8.splat" (i32.const -32769)) (v128.const i16x8 32767 32767 32767 32767 32767 32767 32767 32767))
    33  (assert_return (invoke "i16x8.splat" (i32.const 32768)) (v128.const i16x8 -32768 -32768 -32768 -32768 -32768 -32768 -32768 -32768))
    34  (assert_return (invoke "i16x8.splat" (i32.const 0xffff7fff)) (v128.const i16x8 0x7fff 0x7fff 0x7fff 0x7fff 0x7fff 0x7fff 0x7fff 0x7fff))
    35  (assert_return (invoke "i16x8.splat" (i32.const 0x8000)) (v128.const i16x8 0x8000 0x8000 0x8000 0x8000 0x8000 0x8000 0x8000 0x8000))
    36  (assert_return (invoke "i16x8.splat" (i32.const 0xABCD)) (v128.const i32x4 0xABCDABCD 0xABCDABCD 0xABCDABCD 0xABCDABCD))
    37  (assert_return (invoke "i16x8.splat" (i32.const 012345)) (v128.const i16x8 012_345 012_345 012_345 012_345 012_345 012_345 012_345 012_345))
    38  (assert_return (invoke "i16x8.splat" (i32.const 0x01234)) (v128.const i16x8 0x0_1234 0x0_1234 0x0_1234 0x0_1234 0x0_1234 0x0_1234 0x0_1234 0x0_1234))
    39  
    40  (assert_return (invoke "i32x4.splat" (i32.const 0)) (v128.const i32x4 0 0 0 0))
    41  (assert_return (invoke "i32x4.splat" (i32.const 5)) (v128.const i32x4 5 5 5 5))
    42  (assert_return (invoke "i32x4.splat" (i32.const -5)) (v128.const i32x4 -5 -5 -5 -5))
    43  (assert_return (invoke "i32x4.splat" (i32.const 0xffffffff)) (v128.const i32x4 -1 -1 -1 -1))
    44  (assert_return (invoke "i32x4.splat" (i32.const 4294967295)) (v128.const i32x4 -1 -1 -1 -1))
    45  (assert_return (invoke "i32x4.splat" (i32.const -2147483648)) (v128.const i32x4 0x80000000 0x80000000 0x80000000 0x80000000))
    46  (assert_return (invoke "i32x4.splat" (i32.const 2147483647)) (v128.const i32x4 0x7fffffff 0x7fffffff 0x7fffffff 0x7fffffff))
    47  (assert_return (invoke "i32x4.splat" (i32.const 2147483648)) (v128.const i32x4 0x80000000 0x80000000 0x80000000 0x80000000))
    48  (assert_return (invoke "i32x4.splat" (i32.const 01234567890)) (v128.const i32x4 012_3456_7890 012_3456_7890 012_3456_7890 012_3456_7890))
    49  (assert_return (invoke "i32x4.splat" (i32.const 0x012345678)) (v128.const i32x4 0x0_1234_5678 0x0_1234_5678 0x0_1234_5678 0x0_1234_5678))
    50  
    51  (assert_return (invoke "f32x4.splat" (f32.const 0.0)) (v128.const f32x4 0.0 0.0 0.0 0.0))
    52  (assert_return (invoke "f32x4.splat" (f32.const 1.1)) (v128.const f32x4 1.1 1.1 1.1 1.1))
    53  (assert_return (invoke "f32x4.splat" (f32.const -1.1)) (v128.const f32x4 -1.1 -1.1 -1.1 -1.1))
    54  (assert_return (invoke "f32x4.splat" (f32.const 1e38)) (v128.const f32x4 1e38 1e38 1e38 1e38))
    55  (assert_return (invoke "f32x4.splat" (f32.const -1e38)) (v128.const f32x4 -1e38 -1e38 -1e38 -1e38))
    56  (assert_return (invoke "f32x4.splat" (f32.const 0x1.fffffep127)) (v128.const f32x4 0x1.fffffep127 0x1.fffffep127 0x1.fffffep127 0x1.fffffep127))
    57  (assert_return (invoke "f32x4.splat" (f32.const -0x1.fffffep127)) (v128.const f32x4 -0x1.fffffep127 -0x1.fffffep127 -0x1.fffffep127 -0x1.fffffep127))
    58  (assert_return (invoke "f32x4.splat" (f32.const 0x1p127)) (v128.const f32x4 0x1p127 0x1p127 0x1p127 0x1p127))
    59  (assert_return (invoke "f32x4.splat" (f32.const -0x1p127)) (v128.const f32x4 -0x1p127 -0x1p127 -0x1p127 -0x1p127))
    60  (assert_return (invoke "f32x4.splat" (f32.const inf)) (v128.const f32x4 inf inf inf inf))
    61  (assert_return (invoke "f32x4.splat" (f32.const -inf)) (v128.const f32x4 -inf -inf -inf -inf))
    62  (assert_return (invoke "f32x4.splat" (f32.const nan)) (v128.const f32x4 nan nan nan nan))
    63  (assert_return (invoke "f32x4.splat" (f32.const nan:0x1)) (v128.const f32x4 nan:0x1 nan:0x1 nan:0x1 nan:0x1))
    64  (assert_return (invoke "f32x4.splat" (f32.const nan:0x7f_ffff)) (v128.const f32x4 nan:0x7f_ffff nan:0x7f_ffff nan:0x7f_ffff nan:0x7f_ffff))
    65  (assert_return (invoke "f32x4.splat" (f32.const 0123456789)) (v128.const f32x4 0123456789 0123456789 0123456789 0123456789))
    66  (assert_return (invoke "f32x4.splat" (f32.const 0123456789.)) (v128.const f32x4 0123456789. 0123456789. 0123456789. 0123456789.))
    67  (assert_return (invoke "f32x4.splat" (f32.const 0x0123456789ABCDEF)) (v128.const f32x4 0x0123456789ABCDEF 0x0123456789ABCDEF 0x0123456789ABCDEF 0x0123456789ABCDEF))
    68  (assert_return (invoke "f32x4.splat" (f32.const 0x0123456789ABCDEF.)) (v128.const f32x4 0x0123456789ABCDEF. 0x0123456789ABCDEF. 0x0123456789ABCDEF. 0x0123456789ABCDEF.))
    69  (assert_return (invoke "f32x4.splat" (f32.const 0123456789e019)) (v128.const f32x4 0123456789e019 0123456789e019 0123456789e019 0123456789e019))
    70  (assert_return (invoke "f32x4.splat" (f32.const 0123456789.e+019)) (v128.const f32x4 0123456789.e+019 0123456789.e+019 0123456789.e+019 0123456789.e+019))
    71  (assert_return (invoke "f32x4.splat" (f32.const 0x0123456789ABCDEFp019)) (v128.const f32x4 0x0123456789ABCDEFp019 0x0123456789ABCDEFp019 0x0123456789ABCDEFp019 0x0123456789ABCDEFp019))
    72  (assert_return (invoke "f32x4.splat" (f32.const 0x0123456789ABCDEF.p-019)) (v128.const f32x4 0x0123456789ABCDEF.p-019 0x0123456789ABCDEF.p-019 0x0123456789ABCDEF.p-019 0x0123456789ABCDEF.p-019))
    73  
    74  (assert_return (invoke "i64x2.splat" (i64.const 0)) (v128.const i64x2 0 0))
    75  (assert_return (invoke "i64x2.splat" (i64.const -0)) (v128.const i64x2 0 0))
    76  (assert_return (invoke "i64x2.splat" (i64.const 1)) (v128.const i64x2 1 1))
    77  (assert_return (invoke "i64x2.splat" (i64.const -1)) (v128.const i64x2 -1 -1))
    78  (assert_return (invoke "i64x2.splat" (i64.const -9223372036854775808)) (v128.const i64x2 -9223372036854775808 -9223372036854775808))
    79  (assert_return (invoke "i64x2.splat" (i64.const -9223372036854775808)) (v128.const i64x2 9223372036854775808 9223372036854775808))
    80  (assert_return (invoke "i64x2.splat" (i64.const 9223372036854775807)) (v128.const i64x2 9223372036854775807 9223372036854775807))
    81  (assert_return (invoke "i64x2.splat" (i64.const 18446744073709551615)) (v128.const i64x2 -1 -1))
    82  (assert_return (invoke "i64x2.splat" (i64.const 0x7fffffffffffffff)) (v128.const i64x2 0x7fffffffffffffff 0x7fffffffffffffff))
    83  (assert_return (invoke "i64x2.splat" (i64.const 0xffffffffffffffff)) (v128.const i64x2 -1 -1))
    84  (assert_return (invoke "i64x2.splat" (i64.const -0x8000000000000000)) (v128.const i64x2 -0x8000000000000000 -0x8000000000000000))
    85  (assert_return (invoke "i64x2.splat" (i64.const -0x8000000000000000)) (v128.const i64x2 0x8000000000000000 0x8000000000000000))
    86  (assert_return (invoke "i64x2.splat" (i64.const 01234567890123456789)) (v128.const i64x2 01_234_567_890_123_456_789 01_234_567_890_123_456_789))
    87  (assert_return (invoke "i64x2.splat" (i64.const 0x01234567890ABcdef)) (v128.const i64x2 0x0_1234_5678_90AB_cdef 0x0_1234_5678_90AB_cdef))
    88  
    89  (assert_return (invoke "f64x2.splat" (f64.const 0.0)) (v128.const f64x2 0.0 0.0))
    90  (assert_return (invoke "f64x2.splat" (f64.const -0.0)) (v128.const f64x2 -0.0 -0.0))
    91  (assert_return (invoke "f64x2.splat" (f64.const 1.1)) (v128.const f64x2 1.1 1.1))
    92  (assert_return (invoke "f64x2.splat" (f64.const -1.1)) (v128.const f64x2 -1.1 -1.1))
    93  (assert_return (invoke "f64x2.splat" (f64.const 0x0.0000000000001p-1022)) (v128.const f64x2 0x0.0000000000001p-1022 0x0.0000000000001p-1022))
    94  (assert_return (invoke "f64x2.splat" (f64.const -0x0.0000000000001p-1022)) (v128.const f64x2 -0x0.0000000000001p-1022 -0x0.0000000000001p-1022))
    95  (assert_return (invoke "f64x2.splat" (f64.const 0x1p-1022)) (v128.const f64x2 0x1p-1022 0x1p-1022))
    96  (assert_return (invoke "f64x2.splat" (f64.const -0x1p-1022)) (v128.const f64x2 -0x1p-1022 -0x1p-1022))
    97  (assert_return (invoke "f64x2.splat" (f64.const 0x1p-1)) (v128.const f64x2 0x1p-1 0x1p-1))
    98  (assert_return (invoke "f64x2.splat" (f64.const -0x1p-1)) (v128.const f64x2 -0x1p-1 -0x1p-1))
    99  (assert_return (invoke "f64x2.splat" (f64.const 0x1p+0)) (v128.const f64x2 0x1p+0 0x1p+0))
   100  (assert_return (invoke "f64x2.splat" (f64.const -0x1p+0)) (v128.const f64x2 -0x1p+0 -0x1p+0))
   101  (assert_return (invoke "f64x2.splat" (f64.const 0x1.921fb54442d18p+2)) (v128.const f64x2 0x1.921fb54442d18p+2 0x1.921fb54442d18p+2))
   102  (assert_return (invoke "f64x2.splat" (f64.const -0x1.921fb54442d18p+2)) (v128.const f64x2 -0x1.921fb54442d18p+2 -0x1.921fb54442d18p+2))
   103  (assert_return (invoke "f64x2.splat" (f64.const 0x1.fffffffffffffp+1023)) (v128.const f64x2 0x1.fffffffffffffp+1023 0x1.fffffffffffffp+1023))
   104  (assert_return (invoke "f64x2.splat" (f64.const -0x1.fffffffffffffp+1023)) (v128.const f64x2 -0x1.fffffffffffffp+1023 -0x1.fffffffffffffp+1023))
   105  (assert_return (invoke "f64x2.splat" (f64.const inf)) (v128.const f64x2 inf inf))
   106  (assert_return (invoke "f64x2.splat" (f64.const -inf)) (v128.const f64x2 -inf -inf))
   107  (assert_return (invoke "f64x2.splat" (f64.const nan)) (v128.const f64x2 nan nan))
   108  (assert_return (invoke "f64x2.splat" (f64.const -nan)) (v128.const f64x2 -nan -nan))
   109  (assert_return (invoke "f64x2.splat" (f64.const nan:0x4000000000000)) (v128.const f64x2 nan:0x4000000000000 nan:0x4000000000000))
   110  (assert_return (invoke "f64x2.splat" (f64.const -nan:0x4000000000000)) (v128.const f64x2 -nan:0x4000000000000 -nan:0x4000000000000))
   111  (assert_return (invoke "f64x2.splat" (f64.const 0123456789)) (v128.const f64x2 0123456789 0123456789))
   112  (assert_return (invoke "f64x2.splat" (f64.const 0123456789.)) (v128.const f64x2 0123456789. 0123456789.))
   113  (assert_return (invoke "f64x2.splat" (f64.const 0x0123456789ABCDEFabcdef)) (v128.const f64x2 0x0123456789ABCDEFabcdef 0x0123456789ABCDEFabcdef))
   114  (assert_return (invoke "f64x2.splat" (f64.const 0x0123456789ABCDEFabcdef.)) (v128.const f64x2 0x0123456789ABCDEFabcdef. 0x0123456789ABCDEFabcdef.))
   115  (assert_return (invoke "f64x2.splat" (f64.const 0123456789e019)) (v128.const f64x2 0123456789e019 0123456789e019))
   116  (assert_return (invoke "f64x2.splat" (f64.const 0123456789e+019)) (v128.const f64x2 0123456789e+019 0123456789e+019))
   117  (assert_return (invoke "f64x2.splat" (f64.const 0x0123456789ABCDEFabcdef.p019)) (v128.const f64x2 0x0123456789ABCDEFabcdef.p019 0x0123456789ABCDEFabcdef.p019))
   118  (assert_return (invoke "f64x2.splat" (f64.const 0x0123456789ABCDEFabcdef.p-019)) (v128.const f64x2 0x0123456789ABCDEFabcdef.p-019 0x0123456789ABCDEFabcdef.p-019))
   119  
   120  ;; Unknown operator
   121  
   122  (assert_malformed (module quote "(func (result v128) (v128.splat (i32.const 0)))") "unknown operator")
   123  
   124  
   125  ;; Type mismatched
   126  
   127  (assert_invalid (module (func (result v128) i8x16.splat (i64.const 0))) "type mismatch")
   128  (assert_invalid (module (func (result v128) i8x16.splat (f32.const 0.0))) "type mismatch")
   129  (assert_invalid (module (func (result v128) i8x16.splat (f64.const 0.0))) "type mismatch")
   130  (assert_invalid (module (func (result v128) i16x8.splat (i64.const 1))) "type mismatch")
   131  (assert_invalid (module (func (result v128) i16x8.splat (f32.const 1.0))) "type mismatch")
   132  (assert_invalid (module (func (result v128) i16x8.splat (f64.const 1.0))) "type mismatch")
   133  (assert_invalid (module (func (result v128) i32x4.splat (i64.const 2))) "type mismatch")
   134  (assert_invalid (module (func (result v128) i32x4.splat (f32.const 2.0))) "type mismatch")
   135  (assert_invalid (module (func (result v128) i32x4.splat (f64.const 2.0))) "type mismatch")
   136  (assert_invalid (module (func (result v128) f32x4.splat (i32.const 4))) "type mismatch")
   137  (assert_invalid (module (func (result v128) f32x4.splat (i64.const 4))) "type mismatch")
   138  (assert_invalid (module (func (result v128) f32x4.splat (f64.const 4.0))) "type mismatch")
   139  (assert_invalid (module (func (result v128) i64x2.splat (i32.const 0))) "type mismatch")
   140  (assert_invalid (module (func (result v128) i64x2.splat (f64.const 0.0))) "type mismatch")
   141  (assert_invalid (module (func (result v128) f64x2.splat (i32.const 0))) "type mismatch")
   142  (assert_invalid (module (func (result v128) f64x2.splat (f32.const 0.0))) "type mismatch")
   143  
   144  
   145  ;; V128 splat operators as the argument of other SIMD instructions
   146  
   147  ;; v128.store and v128.load
   148  (module (memory 1)
   149    (func (export "as-v128_store-operand-1") (param i32) (result v128)
   150      (v128.store (i32.const 0) (i8x16.splat (local.get 0)))
   151      (v128.load (i32.const 0)))
   152    (func (export "as-v128_store-operand-2") (param i32) (result v128)
   153      (v128.store (i32.const 0) (i16x8.splat (local.get 0)))
   154      (v128.load (i32.const 0)))
   155    (func (export "as-v128_store-operand-3") (param i32) (result v128)
   156      (v128.store (i32.const 0) (i32x4.splat (local.get 0)))
   157      (v128.load (i32.const 0)))
   158    (func (export "as-v128_store-operand-4") (param i64) (result v128)
   159      (v128.store (i32.const 0) (i64x2.splat (local.get 0)))
   160      (v128.load (i32.const 0)))
   161    (func (export "as-v128_store-operand-5") (param f64) (result v128)
   162      (v128.store (i32.const 0) (f64x2.splat (local.get 0)))
   163      (v128.load (i32.const 0)))
   164  )
   165  
   166  (assert_return (invoke "as-v128_store-operand-1" (i32.const 1)) (v128.const i8x16 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1))
   167  (assert_return (invoke "as-v128_store-operand-2" (i32.const 256)) (v128.const i16x8 0x100 0x100 0x100 0x100 0x100 0x100 0x100 0x100))
   168  (assert_return (invoke "as-v128_store-operand-3" (i32.const 0xffffffff)) (v128.const i32x4 -1 -1 -1 -1))
   169  (assert_return (invoke "as-v128_store-operand-4" (i64.const 1)) (v128.const i64x2 1 1))
   170  (assert_return (invoke "as-v128_store-operand-5" (f64.const -0x1p+0)) (v128.const f64x2 -0x1p+0 -0x1p+0))
   171  
   172  (module
   173    ;; Accessing lane
   174    (func (export "as-i8x16_extract_lane_s-operand-first") (param i32) (result i32)
   175      (i8x16.extract_lane_s 0 (i8x16.splat (local.get 0))))
   176    (func (export "as-i8x16_extract_lane_s-operand-last") (param i32) (result i32)
   177      (i8x16.extract_lane_s 15 (i8x16.splat (local.get 0))))
   178    (func (export "as-i16x8_extract_lane_s-operand-first") (param i32) (result i32)
   179      (i16x8.extract_lane_s 0 (i16x8.splat (local.get 0))))
   180    (func (export "as-i16x8_extract_lane_s-operand-last") (param i32) (result i32)
   181      (i16x8.extract_lane_s 7 (i16x8.splat (local.get 0))))
   182    (func (export "as-i32x4_extract_lane_s-operand-first") (param i32) (result i32)
   183      (i32x4.extract_lane 0 (i32x4.splat (local.get 0))))
   184    (func (export "as-i32x4_extract_lane_s-operand-last") (param i32) (result i32)
   185      (i32x4.extract_lane 3 (i32x4.splat (local.get 0))))
   186    (func (export "as-f32x4_extract_lane_s-operand-first") (param f32) (result f32)
   187      (f32x4.extract_lane 0 (f32x4.splat (local.get 0))))
   188    (func (export "as-f32x4_extract_lane_s-operand-last") (param f32) (result f32)
   189      (f32x4.extract_lane 3 (f32x4.splat (local.get 0))))
   190    (func (export "as-v8x16_swizzle-operands") (param i32) (param i32) (result v128)
   191      (i8x16.swizzle (i8x16.splat (local.get 0)) (i8x16.splat (local.get 1))))
   192    (func (export "as-i64x2_extract_lane-operand-first") (param i64) (result i64)
   193      (i64x2.extract_lane 0 (i64x2.splat (local.get 0))))
   194    (func (export "as-i64x2_extract_lane-operand-last") (param i64) (result i64)
   195      (i64x2.extract_lane 1 (i64x2.splat (local.get 0))))
   196    (func (export "as-f64x2_extract_lane-operand-first") (param f64) (result f64)
   197      (f64x2.extract_lane 0 (f64x2.splat (local.get 0))))
   198    (func (export "as-f64x2_extract_lane-operand-last") (param f64) (result f64)
   199      (f64x2.extract_lane 1 (f64x2.splat (local.get 0))))
   200  
   201    ;; Integer arithmetic
   202    (func (export "as-i8x16_add_sub-operands") (param i32 i32 i32) (result v128)
   203      (i8x16.add (i8x16.splat (local.get 0))
   204        (i8x16.sub (i8x16.splat (local.get 1)) (i8x16.splat (local.get 2)))))
   205    (func (export "as-i16x8_add_sub_mul-operands") (param i32 i32 i32 i32) (result v128)
   206      (i16x8.add (i16x8.splat (local.get 0))
   207        (i16x8.sub (i16x8.splat (local.get 1))
   208          (i16x8.mul (i16x8.splat (local.get 2)) (i16x8.splat (local.get 3))))))
   209    (func (export "as-i32x4_add_sub_mul-operands") (param i32 i32 i32 i32) (result v128)
   210      (i32x4.add (i32x4.splat (local.get 0))
   211        (i32x4.sub (i32x4.splat (local.get 1))
   212          (i32x4.mul (i32x4.splat (local.get 2)) (i32x4.splat (local.get 3))))))
   213  
   214    (func (export "as-i64x2_add_sub_mul-operands") (param i64 i64 i64 i64) (result v128)
   215      (i64x2.add (i64x2.splat (local.get 0))
   216        (i64x2.sub (i64x2.splat (local.get 1))
   217          (i64x2.mul (i64x2.splat (local.get 2)) (i64x2.splat (local.get 3))))))
   218    (func (export "as-f64x2_add_sub_mul-operands") (param f64 f64 f64 f64) (result v128)
   219      (f64x2.add (f64x2.splat (local.get 0))
   220        (f64x2.sub (f64x2.splat (local.get 1))
   221          (f64x2.mul (f64x2.splat (local.get 2)) (f64x2.splat (local.get 3))))))
   222  
   223    ;; Saturating integer arithmetic
   224    (func (export "as-i8x16_add_sat_s-operands") (param i32 i32) (result v128)
   225      (i8x16.add_sat_s (i8x16.splat (local.get 0)) (i8x16.splat (local.get 1))))
   226    (func (export "as-i16x8_add_sat_s-operands") (param i32 i32) (result v128)
   227      (i16x8.add_sat_s (i16x8.splat (local.get 0)) (i16x8.splat (local.get 1))))
   228    (func (export "as-i8x16_sub_sat_u-operands") (param i32 i32) (result v128)
   229      (i8x16.sub_sat_u (i8x16.splat (local.get 0)) (i8x16.splat (local.get 1))))
   230    (func (export "as-i16x8_sub_sat_u-operands") (param i32 i32) (result v128)
   231      (i16x8.sub_sat_u (i16x8.splat (local.get 0)) (i16x8.splat (local.get 1))))
   232  
   233    ;; Bit shifts
   234    (func (export "as-i8x16_shr_s-operand") (param i32 i32) (result v128)
   235      (i8x16.shr_s (i8x16.splat (local.get 0)) (local.get 1)))
   236    (func (export "as-i16x8_shr_s-operand") (param i32 i32) (result v128)
   237      (i16x8.shr_s (i16x8.splat (local.get 0)) (local.get 1)))
   238    (func (export "as-i32x4_shr_s-operand") (param i32 i32) (result v128)
   239      (i32x4.shr_s (i32x4.splat (local.get 0)) (local.get 1)))
   240  
   241    ;; Bitwise operantions
   242    (func (export "as-v128_and-operands") (param i32 i32) (result v128)
   243      (v128.and (i8x16.splat (local.get 0)) (i8x16.splat (local.get 1))))
   244    (func (export "as-v128_or-operands") (param i32 i32) (result v128)
   245      (v128.or (i16x8.splat (local.get 0)) (i16x8.splat (local.get 1))))
   246    (func (export "as-v128_xor-operands") (param i32 i32) (result v128)
   247      (v128.xor (i32x4.splat (local.get 0)) (i32x4.splat (local.get 1))))
   248  
   249    ;; Boolean horizontal reductions
   250    (func (export "as-i8x16_all_true-operand") (param i32) (result i32)
   251      (i8x16.all_true (i8x16.splat (local.get 0))))
   252    (func (export "as-i16x8_all_true-operand") (param i32) (result i32)
   253      (i16x8.all_true (i16x8.splat (local.get 0))))
   254    (func (export "as-i32x4_all_true-operand1") (param i32) (result i32)
   255      (i32x4.all_true (i32x4.splat (local.get 0))))
   256    (func (export "as-i32x4_all_true-operand2") (param i64) (result i32)
   257      (i32x4.all_true (i64x2.splat (local.get 0))))
   258  
   259    ;; Comparisons
   260    (func (export "as-i8x16_eq-operands") (param i32 i32) (result v128)
   261      (i8x16.eq (i8x16.splat (local.get 0)) (i8x16.splat (local.get 1))))
   262    (func (export "as-i16x8_eq-operands") (param i32 i32) (result v128)
   263      (i16x8.eq (i16x8.splat (local.get 0)) (i16x8.splat (local.get 1))))
   264    (func (export "as-i32x4_eq-operands1") (param i32 i32) (result v128)
   265      (i32x4.eq (i32x4.splat (local.get 0)) (i32x4.splat (local.get 1))))
   266    (func (export "as-i32x4_eq-operands2") (param i64 i64) (result v128)
   267      (i32x4.eq (i64x2.splat (local.get 0)) (i64x2.splat (local.get 1))))
   268    (func (export "as-f32x4_eq-operands") (param f32 f32) (result v128)
   269      (f32x4.eq (f32x4.splat (local.get 0)) (f32x4.splat (local.get 1))))
   270    (func (export "as-f64x2_eq-operands") (param f64 f64) (result v128)
   271      (f64x2.eq (f64x2.splat (local.get 0)) (f64x2.splat (local.get 1))))
   272  
   273    ;; Floating-point sign bit operations
   274    (func (export "as-f32x4_abs-operand") (param f32) (result v128)
   275      (f32x4.abs (f32x4.splat (local.get 0))))
   276  
   277    ;; Floating-point min
   278    (func (export "as-f32x4_min-operands") (param f32 f32) (result v128)
   279      (f32x4.min (f32x4.splat (local.get 0)) (f32x4.splat (local.get 1))))
   280  
   281    ;; Floating-point arithmetic
   282    (func (export "as-f32x4_div-operands") (param f32 f32) (result v128)
   283      (f32x4.div (f32x4.splat (local.get 0)) (f32x4.splat (local.get 1))))
   284  
   285    ;; Conversions
   286    (func (export "as-f32x4_convert_s_i32x4-operand") (param i32) (result v128)
   287      (f32x4.convert_i32x4_s (i32x4.splat (local.get 0))))
   288    (func (export "as-i32x4_trunc_s_f32x4_sat-operand") (param f32) (result v128)
   289      (i32x4.trunc_sat_f32x4_s (f32x4.splat (local.get 0))))
   290  )
   291  
   292  (assert_return (invoke "as-i8x16_extract_lane_s-operand-first" (i32.const 42)) (i32.const 42))
   293  (assert_return (invoke "as-i8x16_extract_lane_s-operand-last" (i32.const -42)) (i32.const -42))
   294  (assert_return (invoke "as-i16x8_extract_lane_s-operand-first" (i32.const 0xffff7fff)) (i32.const 32767))
   295  (assert_return (invoke "as-i16x8_extract_lane_s-operand-last" (i32.const 0x8000)) (i32.const -32768))
   296  (assert_return (invoke "as-i32x4_extract_lane_s-operand-first" (i32.const 0x7fffffff)) (i32.const 2147483647))
   297  (assert_return (invoke "as-i32x4_extract_lane_s-operand-last" (i32.const 0x80000000)) (i32.const -2147483648))
   298  (assert_return (invoke "as-f32x4_extract_lane_s-operand-first" (f32.const 1.5)) (f32.const 1.5))
   299  (assert_return (invoke "as-f32x4_extract_lane_s-operand-last" (f32.const -0.25)) (f32.const -0.25))
   300  (assert_return (invoke "as-v8x16_swizzle-operands" (i32.const 1) (i32.const -1)) (v128.const i8x16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0))
   301  (assert_return (invoke "as-i64x2_extract_lane-operand-last" (i64.const -42)) (i64.const -42))
   302  (assert_return (invoke "as-i64x2_extract_lane-operand-first" (i64.const 42)) (i64.const 42))
   303  (assert_return (invoke "as-f64x2_extract_lane-operand-first" (f64.const 1.5)) (f64.const 1.5))
   304  (assert_return (invoke "as-f64x2_extract_lane-operand-last" (f64.const -0x1p+0)) (f64.const -0x1p+0))
   305  
   306  (assert_return (invoke "as-i8x16_add_sub-operands" (i32.const 3) (i32.const 2) (i32.const 1)) (v128.const i8x16 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4))
   307  (assert_return (invoke "as-i16x8_add_sub_mul-operands" (i32.const 257) (i32.const 128) (i32.const 16) (i32.const 16)) (v128.const i16x8 129 129 129 129 129 129 129 129))
   308  (assert_return (invoke "as-i32x4_add_sub_mul-operands" (i32.const 65535) (i32.const 65537) (i32.const 256) (i32.const 256)) (v128.const i32x4 0x10000 0x10000 0x10000 0x10000))
   309  (assert_return (invoke "as-i64x2_add_sub_mul-operands" (i64.const 0x7fffffff) (i64.const 0x1_0000_0001) (i64.const 65536) (i64.const 65536)) (v128.const i64x2 0x8000_0000 0x8000_0000))
   310  (assert_return (invoke "as-f64x2_add_sub_mul-operands" (f64.const 0x1p-1) (f64.const 0.75) (f64.const 0x1p-1) (f64.const 0.5)) (v128.const f64x2 0x1p+0 0x1p+0))
   311  
   312  (assert_return (invoke "as-i8x16_add_sat_s-operands" (i32.const 0x7f) (i32.const 1)) (v128.const i8x16 0x7f 0x7f 0x7f 0x7f 0x7f 0x7f 0x7f 0x7f 0x7f 0x7f 0x7f 0x7f 0x7f 0x7f 0x7f 0x7f))
   313  (assert_return (invoke "as-i16x8_add_sat_s-operands" (i32.const 0x7fff) (i32.const 1)) (v128.const i16x8 0x7fff 0x7fff 0x7fff 0x7fff 0x7fff 0x7fff 0x7fff 0x7fff))
   314  (assert_return (invoke "as-i8x16_sub_sat_u-operands" (i32.const 0x7f) (i32.const 0xff)) (v128.const i8x16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0))
   315  (assert_return (invoke "as-i16x8_sub_sat_u-operands" (i32.const 0x7fff) (i32.const 0xffff)) (v128.const i16x8 0 0 0 0 0 0 0 0))
   316  
   317  (assert_return (invoke "as-i8x16_shr_s-operand" (i32.const 0xf0) (i32.const 3)) (v128.const i8x16 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2))
   318  (assert_return (invoke "as-i16x8_shr_s-operand" (i32.const 0x100) (i32.const 4)) (v128.const i16x8 16 16 16 16 16 16 16 16))
   319  (assert_return (invoke "as-i32x4_shr_s-operand" (i32.const -1) (i32.const 16)) (v128.const i32x4 -1 -1 -1 -1))
   320  
   321  (assert_return (invoke "as-v128_and-operands" (i32.const 0x11) (i32.const 0xff)) (v128.const i8x16 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17))
   322  (assert_return (invoke "as-v128_or-operands" (i32.const 0) (i32.const 0xffff)) (v128.const i16x8 0xffff 0xffff 0xffff 0xffff 0xffff 0xffff 0xffff 0xffff))
   323  (assert_return (invoke "as-v128_xor-operands" (i32.const 0xf0f0f0f0) (i32.const 0xffffffff)) (v128.const i32x4 0xf0f0f0f 0xf0f0f0f 0xf0f0f0f 0xf0f0f0f))
   324  
   325  (assert_return (invoke "as-i8x16_all_true-operand" (i32.const 0)) (i32.const 0))
   326  (assert_return (invoke "as-i16x8_all_true-operand" (i32.const 0xffff)) (i32.const 1))
   327  (assert_return (invoke "as-i32x4_all_true-operand1" (i32.const 0xf0f0f0f0)) (i32.const 1))
   328  (assert_return (invoke "as-i32x4_all_true-operand2" (i64.const -1)) (i32.const 1))
   329  
   330  (assert_return (invoke "as-i8x16_eq-operands" (i32.const 1) (i32.const 2)) (v128.const i8x16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0))
   331  (assert_return (invoke "as-i16x8_eq-operands" (i32.const -1) (i32.const 65535)) (v128.const i16x8 0xffff 0xffff 0xffff 0xffff 0xffff 0xffff 0xffff 0xffff))
   332  (assert_return (invoke "as-i32x4_eq-operands1" (i32.const -1) (i32.const 0xffffffff)) (v128.const i32x4 0xffffffff 0xffffffff 0xffffffff 0xffffffff))
   333  (assert_return (invoke "as-f32x4_eq-operands" (f32.const +0.0) (f32.const -0.0)) (v128.const i32x4 0xffffffff 0xffffffff 0xffffffff 0xffffffff))
   334  (assert_return (invoke "as-i32x4_eq-operands2" (i64.const 1) (i64.const 2)) (v128.const i64x2 0xffffffff00000000 0xffffffff00000000))
   335  (assert_return (invoke "as-f64x2_eq-operands" (f64.const +0.0) (f64.const -0.0)) (v128.const i64x2 -1 -1))
   336  
   337  (assert_return (invoke "as-f32x4_abs-operand" (f32.const -1.125)) (v128.const f32x4 1.125 1.125 1.125 1.125))
   338  (assert_return (invoke "as-f32x4_min-operands" (f32.const 0.25) (f32.const 1e-38)) (v128.const f32x4 1e-38 1e-38 1e-38 1e-38))
   339  (assert_return (invoke "as-f32x4_div-operands" (f32.const 1.0) (f32.const 8.0)) (v128.const f32x4 0.125 0.125 0.125 0.125))
   340  
   341  (assert_return (invoke "as-f32x4_convert_s_i32x4-operand" (i32.const 12345)) (v128.const f32x4 12345.0 12345.0 12345.0 12345.0))
   342  (assert_return (invoke "as-i32x4_trunc_s_f32x4_sat-operand" (f32.const 1.1)) (v128.const i32x4 1 1 1 1))
   343  
   344  
   345  ;; As the argument of control constructs and WASM instructions
   346  
   347  (module
   348    (global $g (mut v128) (v128.const f32x4 0.0 0.0 0.0 0.0))
   349    (func (export "as-br-value1") (param i32) (result v128)
   350      (block (result v128) (br 0 (i8x16.splat (local.get 0)))))
   351    (func (export "as-return-value1") (param i32) (result v128)
   352      (return (i16x8.splat (local.get 0))))
   353    (func (export "as-local_set-value1") (param i32) (result v128) (local v128)
   354      (local.set 1 (i32x4.splat (local.get 0)))
   355      (return (local.get 1)))
   356    (func (export "as-global_set-value1") (param f32) (result v128)
   357      (global.set $g (f32x4.splat (local.get 0)))
   358      (return (global.get $g)))
   359    (func (export "as-br-value2") (param i64) (result v128)
   360      (block (result v128) (br 0 (i64x2.splat (local.get 0)))))
   361    (func (export "as-return-value2") (param i64) (result v128)
   362      (return (i64x2.splat (local.get 0))))
   363    (func (export "as-local_set-value2") (param i64) (result v128) (local v128)
   364      (local.set 1 (i64x2.splat (local.get 0)))
   365      (return (local.get 1)))
   366    (func (export "as-global_set-value2") (param f64) (result v128)
   367      (global.set $g (f64x2.splat (local.get 0)))
   368      (return (global.get $g)))
   369  )
   370  
   371  (assert_return (invoke "as-br-value1" (i32.const 0xAB)) (v128.const i8x16 0xAB 0xAB 0xAB 0xAB 0xAB 0xAB 0xAB 0xAB 0xAB 0xAB 0xAB 0xAB 0xAB 0xAB 0xAB 0xAB))
   372  (assert_return (invoke "as-return-value1" (i32.const 0xABCD)) (v128.const i16x8 0xABCD 0xABCD 0xABCD 0xABCD 0xABCD 0xABCD 0xABCD 0xABCD))
   373  (assert_return (invoke "as-local_set-value1" (i32.const 0x10000)) (v128.const i32x4 0x10000 0x10000 0x10000 0x10000))
   374  (assert_return (invoke "as-global_set-value1" (f32.const 1.0)) (v128.const f32x4 1.0 1.0 1.0 1.0))
   375  (assert_return (invoke "as-br-value2" (i64.const 0xABCD)) (v128.const i64x2 0xABCD 0xABCD))
   376  (assert_return (invoke "as-return-value2" (i64.const 0xABCD)) (v128.const i64x2 0xABCD 0xABCD))
   377  (assert_return (invoke "as-local_set-value2" (i64.const 0x10000)) (v128.const i64x2 0x10000 0x10000))
   378  (assert_return (invoke "as-global_set-value2" (f64.const 1.0)) (v128.const f64x2 1.0 1.0))
   379  
   380  
   381  ;; Test operation with empty argument
   382  
   383  (assert_invalid
   384    (module
   385      (func $i8x16.splat-arg-empty (result v128)
   386        (i8x16.splat)
   387      )
   388    )
   389    "type mismatch"
   390  )
   391  (assert_invalid
   392    (module
   393      (func $i16x8.splat-arg-empty (result v128)
   394        (i16x8.splat)
   395      )
   396    )
   397    "type mismatch"
   398  )
   399  (assert_invalid
   400    (module
   401      (func $i32x4.splat-arg-empty (result v128)
   402        (i32x4.splat)
   403      )
   404    )
   405    "type mismatch"
   406  )
   407  (assert_invalid
   408    (module
   409      (func $f32x4.splat-arg-empty (result v128)
   410        (f32x4.splat)
   411      )
   412    )
   413    "type mismatch"
   414  )
   415  (assert_invalid
   416    (module
   417      (func $i64x2.splat-arg-empty (result v128)
   418        (i64x2.splat)
   419      )
   420    )
   421    "type mismatch"
   422  )
   423  (assert_invalid
   424    (module
   425      (func $f64x2.splat-arg-empty (result v128)
   426        (f64x2.splat)
   427      )
   428    )
   429    "type mismatch"
   430  )