Commit 54f0c404 authored by Shu-yu Guo's avatar Shu-yu Guo Committed by V8 LUCI CQ

Reinstate DoubleToInteger 0 special case for performance

Bug: chromium:1359950
Change-Id: I06a48ab940311481cb46486c766d179b30296415
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3877616
Auto-Submit: Shu-yu Guo <syg@chromium.org>
Reviewed-by: 's avatarJakob Linke <jgruber@chromium.org>
Commit-Queue: Jakob Linke <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83011}
parent dafcb538
......@@ -81,10 +81,11 @@ inline float DoubleToFloat32(double x) {
// #sec-tointegerorinfinity
inline double DoubleToInteger(double x) {
if (std::isnan(x)) return 0;
// ToIntegerOrInfinity normalizes -0 to +0. Special case 0 for performance.
if (std::isnan(x) || x == 0.0) return 0;
if (!std::isfinite(x)) return x;
// ToIntegerOrInfinity normalizes -0 to +0, so add 0.0.
return ((x >= 0) ? std::floor(x) : std::ceil(x)) + 0.0;
// Add 0.0 in the truncation case to ensure this doesn't return -0.
return ((x > 0) ? std::floor(x) : std::ceil(x)) + 0.0;
}
// Implements most of https://tc39.github.io/ecma262/#sec-toint32.
......
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