mirrored from https://chromium.googlesource.com/v8/v8.git
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[turbofan] Improve typing rule for NumberTrunc.
This extends the typing rule for NumberTrunc to deal with general number inputs properly, thus addressing a long-standing TODO. We also add test cases to ensure that the typing rule gets the corner cases for NaN and -0 right. Bug: v8:5267, v8:7109 Change-Id: Iedc541a0f4619f37da37ea36940f92472034cdf2 Reviewed-on: https://chromium-review.googlesource.com/792932 Reviewed-by: Yang Guo <yangguo@chromium.org> Commit-Queue: Benedikt Meurer <bmeurer@chromium.org> Cr-Commit-Position: refs/heads/master@{#49652}
- Loading branch information
Showing
2 changed files
with
42 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// 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 | ||
|
||
// Ensure that the typing rule for Math.trunc deals correctly with | ||
// inputs in the range (-1.0,0.0), which are mapped to -0. | ||
(function() { | ||
function foo(x) { | ||
// Arrange x such that TurboFan infers type PlainNumber \/ NaN. | ||
x = +x; | ||
x = Math.abs(x) - 1.0; | ||
return Object.is(-0, Math.trunc(x)); | ||
} | ||
|
||
assertFalse(foo(1.5)); | ||
assertTrue(foo(0.5)); | ||
%OptimizeFunctionOnNextCall(foo); | ||
assertFalse(foo(1.5)); | ||
assertTrue(foo(0.5)); | ||
})(); | ||
|
||
// Ensure that the typing rule for Math.trunc deals correctly with | ||
// NaN inputs, which are mapped to NaN. | ||
(function() { | ||
function foo(x) { | ||
// Arrange x such that TurboFan infers type PlainNumber \/ NaN. | ||
x = +x; | ||
x = Math.abs(x) - 1.0; | ||
return Object.is(NaN, Math.trunc(x)); | ||
} | ||
|
||
assertFalse(foo(1.5)); | ||
assertTrue(foo(NaN)); | ||
%OptimizeFunctionOnNextCall(foo); | ||
assertFalse(foo(1.5)); | ||
assertTrue(foo(NaN)); | ||
})(); |