summaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/compiler/shift-shr.js
blob: c52ad43ac5115e58dfdc2e637da369584cd67f58 (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
// Copyright 2014 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

// Check the results of `left >>> right`. The result is always unsigned (and
// therefore positive).
function test_shr(left) {
  var errors = 0;

  for (var i = 1; i < 1024; i++) {
    var temp = left >>> i;
    if (temp < 0) {
      errors++;
    }
  }

  return errors;
}

assertEquals(0, test_shr(1));
%OptimizeFunctionOnNextCall(test_shr);
for (var i = 5; i >= -5; i--) {
  assertEquals(0, test_shr(i));
}


(function () {
  function foo(x, b, array) {
    var y;
    x = x >>> 0;
    b ? (y = x | 0) : (y = x);
    return array[y];
  }

  foo(111, true, new Array(42));
  foo(111, true, new Array(42));
  %OptimizeFunctionOnNextCall(foo);
  foo(-111, true, new Array(42));
})();

(function () {
  function foo(x, b, array) {
    var y;
    x = x >>> 0;
    b ? (y = x | 0) : (y = x);
    return array[y];
  }

  foo(111, true, new Array(42));
  foo(111, true, new Array(42));
  %OptimizeFunctionOnNextCall(foo);
  foo(111, true, new Array(42));
})();