regress-6700.js 2.4 KB
Newer Older
1 2 3 4 5 6
// Copyright 2017 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: --allow-natives-syntax

7 8
let kMinHeapSize = 4096;

9 10 11 12 13 14 15 16 17 18
(function TestLeftRight() {
  function Module(stdlib, foreign, heap) {
    "use asm";
    var HEAP32 = new stdlib.Int32Array(heap);
    function f(i) {
      i = i | 0;
      return HEAP32[i << 2 >> 2] | 0;
    }
    return { f:f }
  }
19
  var buffer = new ArrayBuffer(kMinHeapSize);
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
  var module = new Module(this, {}, buffer);
  assertTrue(%IsAsmWasmCode(Module));
  new Int32Array(buffer)[42] = 23;
  assertEquals(23, module.f(42));
})();

(function TestRightRight() {
  function Module(stdlib, foreign, heap) {
    "use asm";
    var HEAP32 = new stdlib.Int32Array(heap);
    function f(i) {
      i = i | 0;
      return HEAP32[i >> 2 >> 2] | 0;
    }
    return { f:f }
  }
36
  var buffer = new ArrayBuffer(kMinHeapSize);
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
  var module = new Module(this, {}, buffer)
  assertTrue(%IsAsmWasmCode(Module));
  new Int32Array(buffer)[42 >> 4] = 23;
  assertEquals(23, module.f(42));
})();

(function TestRightLeft() {
  function Module(stdlib, foreign, heap) {
    "use asm";
    var HEAP32 = new stdlib.Int32Array(heap);
    function f(i) {
      i = i | 0;
      return HEAP32[i >> 2 << 2] | 0;
    }
    return { f:f }
  }
53
  var buffer = new ArrayBuffer(kMinHeapSize);
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
  var module = new Module(this, {}, buffer)
  assertFalse(%IsAsmWasmCode(Module));
  new Int32Array(buffer)[42 & 0xfc] = 23;
  assertEquals(23, module.f(42));
})();

(function TestRightButNotImmediate() {
  function Module(stdlib, foreign, heap) {
    "use asm";
    var HEAP32 = new stdlib.Int32Array(heap);
    function f(i) {
      i = i | 0;
      return HEAP32[i >> 2 + 1] | 0;
    }
    return { f:f }
  }
70
  var buffer = new ArrayBuffer(kMinHeapSize);
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
  var module = new Module(this, {}, buffer)
  assertFalse(%IsAsmWasmCode(Module));
  new Int32Array(buffer)[42 >> 3] = 23;
  assertEquals(23, module.f(42));
})();

(function TestLeftOnly() {
  function Module(stdlib, foreign, heap) {
    "use asm";
    var HEAP32 = new stdlib.Int32Array(heap);
    function f(i) {
      i = i | 0;
      return HEAP32[i << 2] | 0;
    }
    return { f:f }
  }
87
  var buffer = new ArrayBuffer(kMinHeapSize);
88 89 90 91 92
  var module = new Module(this, {}, buffer)
  assertFalse(%IsAsmWasmCode(Module));
  new Int32Array(buffer)[42 << 2] = 23;
  assertEquals(23, module.f(42));
})();