summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/wasm/simd/baseline-bug1636235.js
blob: da1fb68e6ba8c82f7ce623807198cc382e8f842a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// |jit-test| skip-if: !wasmSimdEnabled()

// Bug 1636235: assorted corner case baseline SIMD bugs.

function get(arr, loc, len) {
    let res = [];
    for ( let i=0; i < len; i++ ) {
        res.push(arr[loc+i]);
    }
    return res;
}

// Pass v128 along a control flow edge in br_table

var ins = wasmEvalText(`
  (module
    (memory (export "mem") 1 1)
    (func (export "run") (param $k i32)
      (v128.store (i32.const 0) (call $f (local.get $k))))
    (func $f (param $k i32) (result v128)
      (block $B2 (result v128)
        (block $B1 (result v128)
          (v128.const i32x4 1 2 3 4)
          (br_table $B1 $B2 (local.get $k)))
        (drop)
        (v128.const i32x4 5 6 7 8))))`);

var mem = new Int32Array(ins.exports.mem.buffer);
ins.exports.run(0);
assertDeepEq(get(mem, 0, 4), [5, 6, 7, 8]);

ins.exports.run(1);
assertDeepEq(get(mem, 0, 4), [1, 2, 3, 4]);

// Materialize a ConstV128 off the value stack in popStackResults (also: check
// that br passing v128 values works as it should).

var ins = wasmEvalText(`
  (module
    (memory (export "mem") 1 1)

    (func (export "run") (param $k i32)
      (local $t0 v128) (local $t1 v128) (local $t2 v128)
      (call $f (local.get $k))
      (local.set $t2)
      (local.set $t1)
      (local.set $t0)
      (v128.store (i32.const 32) (local.get $t2))
      (v128.store (i32.const 16) (local.get $t1))
      (v128.store (i32.const 0) (local.get $t0)))

    (func $f (param $k i32) (result v128 v128 v128)
      (block $B2 (result v128 v128 v128)
        (if (local.get $k)
            (br $B2 (v128.const i32x4 5 6 7 8)
                    (v128.const i32x4 9 10 11 12)
                    (v128.const i32x4 13 14 15 16))
            (br $B2 (v128.const i32x4 -5 -6 -7 -8)
                    (v128.const i32x4 -9 -10 -11 -12)
                    (v128.const i32x4 -13 -14 -15 -16)))
        (unreachable))))`);

var mem = new Int32Array(ins.exports.mem.buffer);
ins.exports.run(0);
assertDeepEq(get(mem, 0, 4), [-5, -6, -7, -8]);
assertDeepEq(get(mem, 4, 4), [-9, -10, -11, -12]);
assertDeepEq(get(mem, 8, 4), [-13, -14, -15, -16]);

ins.exports.run(1);
assertDeepEq(get(mem, 0, 4), [5, 6, 7, 8]);
assertDeepEq(get(mem, 4, 4), [9, 10, 11, 12]);
assertDeepEq(get(mem, 8, 4), [13, 14, 15, 16]);

// Check that br_if passing v128 values works as it should.

var ins = wasmEvalText(`
  (module
    (memory (export "mem") 1 1)

    (func (export "run") (param $k i32)
      (local $t0 v128) (local $t1 v128) (local $t2 v128)
      (call $f (local.get $k))
      (local.set $t2)
      (local.set $t1)
      (local.set $t0)
      (v128.store (i32.const 32) (local.get $t2))
      (v128.store (i32.const 16) (local.get $t1))
      (v128.store (i32.const 0) (local.get $t0)))

    (func $f (param $k i32) (result v128 v128 v128)
      (block $B2 (result v128 v128 v128)
        (v128.const i32x4 5 6 7 8)
        (v128.const i32x4 9 10 11 12)
        (v128.const i32x4 13 14 15 16)
        (br_if $B2 (local.get $k))
        drop drop drop
        (v128.const i32x4 -5 -6 -7 -8)
        (v128.const i32x4 -9 -10 -11 -12)
        (v128.const i32x4 -13 -14 -15 -16))))`);

var mem = new Int32Array(ins.exports.mem.buffer);
ins.exports.run(0);
assertDeepEq(get(mem, 0, 4), [-5, -6, -7, -8]);
assertDeepEq(get(mem, 4, 4), [-9, -10, -11, -12]);
assertDeepEq(get(mem, 8, 4), [-13, -14, -15, -16]);

ins.exports.run(1);
assertDeepEq(get(mem, 0, 4), [5, 6, 7, 8]);
assertDeepEq(get(mem, 4, 4), [9, 10, 11, 12]);
assertDeepEq(get(mem, 8, 4), [13, 14, 15, 16]);