tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

baseline-bug1636235.js (3563B)


      1 // |jit-test| skip-if: !wasmSimdEnabled()
      2 
      3 // Bug 1636235: assorted corner case baseline SIMD bugs.
      4 
      5 function get(arr, loc, len) {
      6    let res = [];
      7    for ( let i=0; i < len; i++ ) {
      8        res.push(arr[loc+i]);
      9    }
     10    return res;
     11 }
     12 
     13 // Pass v128 along a control flow edge in br_table
     14 
     15 var ins = wasmEvalText(`
     16  (module
     17    (memory (export "mem") 1 1)
     18    (func (export "run") (param $k i32)
     19      (v128.store (i32.const 0) (call $f (local.get $k))))
     20    (func $f (param $k i32) (result v128)
     21      (block $B2 (result v128)
     22        (block $B1 (result v128)
     23          (v128.const i32x4 1 2 3 4)
     24          (br_table $B1 $B2 (local.get $k)))
     25        (drop)
     26        (v128.const i32x4 5 6 7 8))))`);
     27 
     28 var mem = new Int32Array(ins.exports.mem.buffer);
     29 ins.exports.run(0);
     30 assertDeepEq(get(mem, 0, 4), [5, 6, 7, 8]);
     31 
     32 ins.exports.run(1);
     33 assertDeepEq(get(mem, 0, 4), [1, 2, 3, 4]);
     34 
     35 // Materialize a ConstV128 off the value stack in popStackResults (also: check
     36 // that br passing v128 values works as it should).
     37 
     38 var ins = wasmEvalText(`
     39  (module
     40    (memory (export "mem") 1 1)
     41 
     42    (func (export "run") (param $k i32)
     43      (local $t0 v128) (local $t1 v128) (local $t2 v128)
     44      (call $f (local.get $k))
     45      (local.set $t2)
     46      (local.set $t1)
     47      (local.set $t0)
     48      (v128.store (i32.const 32) (local.get $t2))
     49      (v128.store (i32.const 16) (local.get $t1))
     50      (v128.store (i32.const 0) (local.get $t0)))
     51 
     52    (func $f (param $k i32) (result v128 v128 v128)
     53      (block $B2 (result v128 v128 v128)
     54        (if (local.get $k)
     55            (then 
     56              (br $B2 (v128.const i32x4 5 6 7 8)
     57                    (v128.const i32x4 9 10 11 12)
     58                    (v128.const i32x4 13 14 15 16)))
     59            (else
     60              (br $B2 (v128.const i32x4 -5 -6 -7 -8)
     61                    (v128.const i32x4 -9 -10 -11 -12)
     62                    (v128.const i32x4 -13 -14 -15 -16))))
     63        (unreachable))))`);
     64 
     65 var mem = new Int32Array(ins.exports.mem.buffer);
     66 ins.exports.run(0);
     67 assertDeepEq(get(mem, 0, 4), [-5, -6, -7, -8]);
     68 assertDeepEq(get(mem, 4, 4), [-9, -10, -11, -12]);
     69 assertDeepEq(get(mem, 8, 4), [-13, -14, -15, -16]);
     70 
     71 ins.exports.run(1);
     72 assertDeepEq(get(mem, 0, 4), [5, 6, 7, 8]);
     73 assertDeepEq(get(mem, 4, 4), [9, 10, 11, 12]);
     74 assertDeepEq(get(mem, 8, 4), [13, 14, 15, 16]);
     75 
     76 // Check that br_if passing v128 values works as it should.
     77 
     78 var ins = wasmEvalText(`
     79  (module
     80    (memory (export "mem") 1 1)
     81 
     82    (func (export "run") (param $k i32)
     83      (local $t0 v128) (local $t1 v128) (local $t2 v128)
     84      (call $f (local.get $k))
     85      (local.set $t2)
     86      (local.set $t1)
     87      (local.set $t0)
     88      (v128.store (i32.const 32) (local.get $t2))
     89      (v128.store (i32.const 16) (local.get $t1))
     90      (v128.store (i32.const 0) (local.get $t0)))
     91 
     92    (func $f (param $k i32) (result v128 v128 v128)
     93      (block $B2 (result v128 v128 v128)
     94        (v128.const i32x4 5 6 7 8)
     95        (v128.const i32x4 9 10 11 12)
     96        (v128.const i32x4 13 14 15 16)
     97        (br_if $B2 (local.get $k))
     98        drop drop drop
     99        (v128.const i32x4 -5 -6 -7 -8)
    100        (v128.const i32x4 -9 -10 -11 -12)
    101        (v128.const i32x4 -13 -14 -15 -16))))`);
    102 
    103 var mem = new Int32Array(ins.exports.mem.buffer);
    104 ins.exports.run(0);
    105 assertDeepEq(get(mem, 0, 4), [-5, -6, -7, -8]);
    106 assertDeepEq(get(mem, 4, 4), [-9, -10, -11, -12]);
    107 assertDeepEq(get(mem, 8, 4), [-13, -14, -15, -16]);
    108 
    109 ins.exports.run(1);
    110 assertDeepEq(get(mem, 0, 4), [5, 6, 7, 8]);
    111 assertDeepEq(get(mem, 4, 4), [9, 10, 11, 12]);
    112 assertDeepEq(get(mem, 8, 4), [13, 14, 15, 16]);