shift-shr.js 1.25 KB
Newer Older
1 2 3 4
// 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.

5
// Flags: --allow-natives-syntax
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

// 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;
}

22
%PrepareFunctionForOptimization(test_shr);
23 24 25 26 27
assertEquals(0, test_shr(1));
%OptimizeFunctionOnNextCall(test_shr);
for (var i = 5; i >= -5; i--) {
  assertEquals(0, test_shr(i));
}
28 29 30 31 32 33 34 35 36 37


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

38
  %PrepareFunctionForOptimization(foo);
39 40 41 42 43 44 45 46 47 48 49 50 51 52
  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];
  }

53
  %PrepareFunctionForOptimization(foo);
54 55 56 57 58
  foo(111, true, new Array(42));
  foo(111, true, new Array(42));
  %OptimizeFunctionOnNextCall(foo);
  foo(111, true, new Array(42));
})();