Commit 2f5e8310 authored by Ulan Degenbaev's avatar Ulan Degenbaev Committed by Commit Bot

Use the std version of copysign math function

This should have no effect unless the embedder uses an old version
of the standard library with missing overloads of <math.h> functions,
which causes such functions to perform implicit conversion to double.
In such cases, the CL removes the implicit conversion.

Change-Id: Ib90a461c81b1f354f7acdf32df88257bff20aca8
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1523549
Auto-Submit: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarSigurd Schneider <sigurds@chromium.org>
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60243}
parent eb1d2d70
...@@ -2967,7 +2967,7 @@ T Simulator::FPMulx(T op1, T op2) { ...@@ -2967,7 +2967,7 @@ T Simulator::FPMulx(T op1, T op2) {
if ((std::isinf(op1) && (op2 == 0.0)) || (std::isinf(op2) && (op1 == 0.0))) { if ((std::isinf(op1) && (op2 == 0.0)) || (std::isinf(op2) && (op1 == 0.0))) {
// inf * 0.0 returns +/-2.0. // inf * 0.0 returns +/-2.0.
T two = 2.0; T two = 2.0;
return copysign(1.0, op1) * copysign(1.0, op2) * two; return std::copysign(1.0, op1) * std::copysign(1.0, op2) * two;
} }
return FPMul(op1, op2); return FPMul(op1, op2);
} }
...@@ -2976,8 +2976,8 @@ template <typename T> ...@@ -2976,8 +2976,8 @@ template <typename T>
T Simulator::FPMulAdd(T a, T op1, T op2) { T Simulator::FPMulAdd(T a, T op1, T op2) {
T result = FPProcessNaNs3(a, op1, op2); T result = FPProcessNaNs3(a, op1, op2);
T sign_a = copysign(1.0, a); T sign_a = std::copysign(1.0, a);
T sign_prod = copysign(1.0, op1) * copysign(1.0, op2); T sign_prod = std::copysign(1.0, op1) * std::copysign(1.0, op2);
bool isinf_prod = std::isinf(op1) || std::isinf(op2); bool isinf_prod = std::isinf(op1) || std::isinf(op2);
bool operation_generates_nan = bool operation_generates_nan =
(std::isinf(op1) && (op2 == 0.0)) || // inf * 0.0 (std::isinf(op1) && (op2 == 0.0)) || // inf * 0.0
...@@ -3012,7 +3012,7 @@ T Simulator::FPMulAdd(T a, T op1, T op2) { ...@@ -3012,7 +3012,7 @@ T Simulator::FPMulAdd(T a, T op1, T op2) {
// Work around broken fma implementations for rounded zero results: If a is // Work around broken fma implementations for rounded zero results: If a is
// 0.0, the sign of the result is the sign of op1 * op2 before rounding. // 0.0, the sign of the result is the sign of op1 * op2 before rounding.
if ((a == 0.0) && (result == 0.0)) { if ((a == 0.0) && (result == 0.0)) {
return copysign(0.0, sign_prod); return std::copysign(0.0, sign_prod);
} }
return result; return result;
...@@ -3031,8 +3031,8 @@ T Simulator::FPDiv(T op1, T op2) { ...@@ -3031,8 +3031,8 @@ T Simulator::FPDiv(T op1, T op2) {
if (op2 == 0.0) { if (op2 == 0.0) {
FPProcessException(); FPProcessException();
if (!std::isnan(op1)) { if (!std::isnan(op1)) {
double op1_sign = copysign(1.0, op1); double op1_sign = std::copysign(1.0, op1);
double op2_sign = copysign(1.0, op2); double op2_sign = std::copysign(1.0, op2);
return static_cast<T>(op1_sign * op2_sign * kFP64PositiveInfinity); return static_cast<T>(op1_sign * op2_sign * kFP64PositiveInfinity);
} }
} }
...@@ -3050,7 +3050,7 @@ T Simulator::FPSqrt(T op) { ...@@ -3050,7 +3050,7 @@ T Simulator::FPSqrt(T op) {
FPProcessException(); FPProcessException();
return FPDefaultNaN<T>(); return FPDefaultNaN<T>();
} else { } else {
return sqrt(op); return std::sqrt(op);
} }
} }
...@@ -3059,7 +3059,8 @@ T Simulator::FPMax(T a, T b) { ...@@ -3059,7 +3059,8 @@ T Simulator::FPMax(T a, T b) {
T result = FPProcessNaNs(a, b); T result = FPProcessNaNs(a, b);
if (std::isnan(result)) return result; if (std::isnan(result)) return result;
if ((a == 0.0) && (b == 0.0) && (copysign(1.0, a) != copysign(1.0, b))) { if ((a == 0.0) && (b == 0.0) &&
(std::copysign(1.0, a) != std::copysign(1.0, b))) {
// a and b are zero, and the sign differs: return +0.0. // a and b are zero, and the sign differs: return +0.0.
return 0.0; return 0.0;
} else { } else {
...@@ -3084,7 +3085,8 @@ T Simulator::FPMin(T a, T b) { ...@@ -3084,7 +3085,8 @@ T Simulator::FPMin(T a, T b) {
T result = FPProcessNaNs(a, b); T result = FPProcessNaNs(a, b);
if (std::isnan(result)) return result; if (std::isnan(result)) return result;
if ((a == 0.0) && (b == 0.0) && (copysign(1.0, a) != copysign(1.0, b))) { if ((a == 0.0) && (b == 0.0) &&
(std::copysign(1.0, a) != std::copysign(1.0, b))) {
// a and b are zero, and the sign differs: return -0.0. // a and b are zero, and the sign differs: return -0.0.
return -0.0; return -0.0;
} else { } else {
...@@ -3516,7 +3518,7 @@ LogicVRegister Simulator::fabs_(VectorFormat vform, LogicVRegister dst, ...@@ -3516,7 +3518,7 @@ LogicVRegister Simulator::fabs_(VectorFormat vform, LogicVRegister dst,
dst.ClearForWrite(vform); dst.ClearForWrite(vform);
for (int i = 0; i < LaneCountFromFormat(vform); i++) { for (int i = 0; i < LaneCountFromFormat(vform); i++) {
T op = src.Float<T>(i); T op = src.Float<T>(i);
if (copysign(1.0, op) < 0.0) { if (std::copysign(1.0, op) < 0.0) {
op = -op; op = -op;
} }
dst.SetFloat(i, op); dst.SetFloat(i, op);
...@@ -3865,12 +3867,12 @@ T Simulator::FPRecipSqrtEstimate(T op) { ...@@ -3865,12 +3867,12 @@ T Simulator::FPRecipSqrtEstimate(T op) {
if (std::isnan(op)) { if (std::isnan(op)) {
return FPProcessNaN(op); return FPProcessNaN(op);
} else if (op == 0.0) { } else if (op == 0.0) {
if (copysign(1.0, op) < 0.0) { if (std::copysign(1.0, op) < 0.0) {
return kFP64NegativeInfinity; return kFP64NegativeInfinity;
} else { } else {
return kFP64PositiveInfinity; return kFP64PositiveInfinity;
} }
} else if (copysign(1.0, op) < 0.0) { } else if (std::copysign(1.0, op) < 0.0) {
FPProcessException(); FPProcessException();
return FPDefaultNaN<T>(); return FPDefaultNaN<T>();
} else if (std::isinf(op)) { } else if (std::isinf(op)) {
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "src/compiler/machine-operator-reducer.h" #include "src/compiler/machine-operator-reducer.h"
#include <cmath>
#include "src/base/bits.h" #include "src/base/bits.h"
#include "src/base/division-by-constant.h" #include "src/base/division-by-constant.h"
...@@ -323,7 +324,7 @@ Reduction MachineOperatorReducer::Reduce(Node* node) { ...@@ -323,7 +324,7 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
case IrOpcode::kFloat32Sub: { case IrOpcode::kFloat32Sub: {
Float32BinopMatcher m(node); Float32BinopMatcher m(node);
if (allow_signalling_nan_ && m.right().Is(0) && if (allow_signalling_nan_ && m.right().Is(0) &&
(copysign(1.0, m.right().Value()) > 0)) { (std::copysign(1.0, m.right().Value()) > 0)) {
return Replace(m.left().node()); // x - 0 => x return Replace(m.left().node()); // x - 0 => x
} }
if (m.right().IsNaN()) { // x - NaN => NaN if (m.right().IsNaN()) { // x - NaN => NaN
......
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