loop-rotation.js 2.08 KB
Newer Older
1 2 3 4 5 6
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Flags: --turbo-loop-rotation --noliftoff --nowasm-tier-up

7
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
8 9 10 11 12 13

(function TestTrivialLoop1() {
  print(arguments.callee.name);
  var builder = new WasmModuleBuilder();
  builder.addFunction("main", kSig_v_i)
    .addBody([
14
      kExprLoop, kWasmVoid,
15
        kExprLocalGet, 0,
16 17
        kExprI32Const, 1,
        kExprI32Sub,
18
        kExprLocalTee, 0,
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
        kExprBrIf, 0,
      kExprEnd,
    ])
    .exportFunc();
  let module = new WebAssembly.Module(builder.toBuffer());
  let instance = new WebAssembly.Instance(module);
  instance.exports.main(1);
  instance.exports.main(10);
  instance.exports.main(100);
})();

(function TestTrivialLoop2() {
  print(arguments.callee.name);
  var builder = new WasmModuleBuilder();
  builder.addFunction("main", kSig_v_i)
    .addBody([
35
      kExprLoop, kWasmVoid,
36
        kExprLocalGet, 0,
37 38
        kExprI32Const, 1,
        kExprI32Sub,
39
        kExprLocalTee, 0,
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
        kExprBrIf, 1,
        kExprBr, 0,
      kExprEnd,
    ])
    .exportFunc();
  let module = new WebAssembly.Module(builder.toBuffer());
  let instance = new WebAssembly.Instance(module);
  instance.exports.main(1);
  instance.exports.main(10);
  instance.exports.main(100);
})();

(function TestNonRotatedLoopWithStore() {
  print(arguments.callee.name);
  var builder = new WasmModuleBuilder();
  builder.addMemory(1, undefined, false);
  builder.addFunction("main", kSig_v_i)
    .addBody([
58
      kExprLoop, kWasmVoid,
59
        kExprLocalGet, 0,
60 61
        kExprI32Const, 1,
        kExprI32Sub,
62
        kExprLocalTee, 0,
63 64 65 66 67 68 69 70 71 72 73 74 75 76
      kExprBrIf, 1,
        kExprI32Const, 0,
        kExprI32Const, 0,
        kExprI32StoreMem, 0, 0,
        kExprBr, 0,
      kExprEnd,
    ])
    .exportFunc();
  let module = new WebAssembly.Module(builder.toBuffer());
  let instance = new WebAssembly.Instance(module);
  instance.exports.main(1);
  instance.exports.main(10);
  instance.exports.main(100);
})();