Commit 65276678 authored by Benedikt Meurer's avatar Benedikt Meurer Committed by Commit Bot

[turbofan] Add (missing) test coverage for Math.imul().

According to the coverage bot, there's some lack of test coverage for
corner cases of Math.imul(). Add the missing test coverage and also
add some coverage for the generally interesting cases.

Bug: v8:8015
Change-Id: I2a917283b4777510fb5db421a039ff0de9b2a25f
Reviewed-on: https://chromium-review.googlesource.com/1235577Reviewed-by: 's avatarSigurd Schneider <sigurds@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56077}
parent 44c24bf8
// 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);
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment