tor-browser

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

unroll7.js (2043B)


      1 // |jit-test| skip-if: wasmCompileMode() != "ion"
      2 
      3 // Tests that unrolling actually transforms a loop into something new, by
      4 // unrolling a loop with just one FP mul and one FP add in it and checking that
      5 // the resulting assembly contains 4 FP muls and 4 FP adds.  Matching bits of
      6 // text in the disassembly is necessarily platform-dependent, but we don't care
      7 // about that since unrolling is done at the MIR level, so if it works for one
      8 // target, it works for all.
      9 //
     10 // Test inspired by simd/pmaddubsw-x64-ion-codegen.js.
     11 
     12 const isX64 = getBuildConfiguration("x64") && !getBuildConfiguration("simulator");
     13 
     14 if (hasDisassembler() && isX64) {
     15  let t = `
     16  (module
     17    (memory 1)
     18    (func (export "dot_product")
     19          (param $startA i32) (param $startB i32) (param $count i32)
     20      (local $sum f64)
     21      (if (i32.gt_u (local.get $count) (i32.const 0))
     22        (then
     23          (loop $cont
     24            (local.set $sum (f64.add (local.get $sum)
     25              (f64.mul (f64.load (local.get $startA))
     26                       (f64.load (local.get $startB)))))
     27            (local.set $startA (i32.add (local.get $startA) (i32.const 8)))
     28            (local.set $startB (i32.add (local.get $startB) (i32.const 8)))
     29            (local.set $count (i32.sub (local.get $count) (i32.const 1)))
     30            (br_if $cont (i32.gt_u (local.get $count) (i32.const 0)))
     31          )
     32        )
     33      )
     34    )
     35  )`;
     36 
     37  let i = new WebAssembly.Instance(
     38             new WebAssembly.Module(wasmTextToBinary(t)));
     39 
     40  const output = wasmDis(i.exports.dot_product, {tier:"ion", asString:true})
     41                 .replace(/^[0-9a-f]{8}  (?:[0-9a-f]{2} )+\n?\s+/gmi, "");
     42 
     43  // Find four "mulsd .. addsd" bits of text.  One pair for the peeled
     44  // iteration and 3 pairs for the 3 unrolled iterations.
     45 
     46  const re = /\bv?mulsd[^\n]+\nv?addsd /g;
     47  assertEq(re.exec(output) != null, true);
     48  assertEq(re.exec(output) != null, true);
     49  assertEq(re.exec(output) != null, true);
     50  assertEq(re.exec(output) != null, true);
     51  assertEq(re.exec(output) == null, true);
     52 }