math-imul.js 1.97 KB
Newer Older
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
// 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: --allow-natives-syntax --opt

// Test Math.imul() with no inputs.
(function() {
  function foo() { return Math.imul(); }

  assertEquals(0, foo());
  assertEquals(0, foo());
  %OptimizeFunctionOnNextCall(foo);
  assertEquals(0, foo());
})();

// Test Math.imul() with only one input.
(function() {
  function foo(x) { return Math.imul(x); }

  assertEquals(0, foo(1));
  assertEquals(0, foo(2));
  %OptimizeFunctionOnNextCall(foo);
  assertEquals(0, foo(3));
})();

// Test Math.imul() with wrong types.
(function() {
  function foo(x, y) { return Math.imul(x, y); }

  assertEquals(0, foo(null, 1));
  assertEquals(0, foo(2, undefined));
  %OptimizeFunctionOnNextCall(foo);
  assertEquals(0, foo(null, 1));
  assertEquals(0, foo(2, undefined));
  %OptimizeFunctionOnNextCall(foo);
  assertEquals(0, foo(null, 1));
  assertEquals(0, foo(2, undefined));
  assertOptimized(foo);
})();

// Test Math.imul() with signed integers (statically known).
(function() {
  function foo(x, y) { return Math.imul(x|0, y|0); }

  assertEquals(1, foo(1, 1));
  assertEquals(2, foo(2, 1));
  %OptimizeFunctionOnNextCall(foo);
  assertEquals(1, foo(1, 1));
  assertEquals(2, foo(2, 1));
  assertOptimized(foo);
})();

// Test Math.imul() with unsigned integers (statically known).
(function() {
  function foo(x, y) { return Math.imul(x>>>0, y>>>0); }

  assertEquals(1, foo(1, 1));
  assertEquals(2, foo(2, 1));
  %OptimizeFunctionOnNextCall(foo);
  assertEquals(1, foo(1, 1));
  assertEquals(2, foo(2, 1));
  assertOptimized(foo);
})();

// Test Math.imul() with floating-point numbers.
(function() {
  function foo(x, y) { return Math.imul(x, y); }

  assertEquals(1, foo(1.1, 1.1));
  assertEquals(2, foo(2.1, 1.1));
  %OptimizeFunctionOnNextCall(foo);
  assertEquals(1, foo(1.1, 1.1));
  assertEquals(2, foo(2.1, 1.1));
  assertOptimized(foo);
})();