Commit ed898473 authored by bbudge's avatar bbudge Committed by Commit bot

V8: Add utility functions to check SameValue and SameValueZero.

Adds SameValue and SameValueZero functions for float and double.
These will be used for HeapNumber and SIMD values.

LOG=N
BUG=v8:4124

Review URL: https://codereview.chromium.org/1234073003

Cr-Commit-Position: refs/heads/master@{#29660}
parent 7b1d583d
......@@ -683,13 +683,7 @@ bool Object::SameValue(Object* other) {
// The object is either a number, a name, an odd-ball,
// a real JS object, or a Harmony proxy.
if (IsNumber() && other->IsNumber()) {
double this_value = Number();
double other_value = other->Number();
bool equal = this_value == other_value;
// SameValue(NaN, NaN) is true.
if (!equal) return std::isnan(this_value) && std::isnan(other_value);
// SameValue(0.0, -0.0) is false.
return (this_value != 0) || ((1 / this_value) == (1 / other_value));
return v8::internal::SameValue(Number(), other->Number());
}
if (IsString() && other->IsString()) {
return String::cast(this)->Equals(String::cast(other));
......@@ -704,11 +698,7 @@ bool Object::SameValueZero(Object* other) {
// The object is either a number, a name, an odd-ball,
// a real JS object, or a Harmony proxy.
if (IsNumber() && other->IsNumber()) {
double this_value = Number();
double other_value = other->Number();
// +0 == -0 is true
return this_value == other_value
|| (std::isnan(this_value) && std::isnan(other_value));
return v8::internal::SameValueZero(Number(), other->Number());
}
if (IsString() && other->IsString()) {
return String::cast(this)->Equals(String::cast(other));
......
......@@ -200,6 +200,27 @@ inline double Floor(double x) {
return std::floor(x);
}
// Implements the ES5 SameValue operation for floating point types.
// http://www.ecma-international.org/ecma-262/6.0/#sec-samevalue
template <typename T>
bool SameValue(T x, T y) {
// SameValue(NaN, NaN) is true.
if (x != y) return std::isnan(x) && std::isnan(y);
// SameValue(0, -0) is false.
if (std::signbit(x) != std::signbit(y)) return false;
return true;
}
// Implements the ES6 SameValueZero operation for floating point types.
// http://www.ecma-international.org/ecma-262/6.0/#sec-samevaluezero
template <typename T>
bool SameValueZero(T x, T y) {
if (x != y) return std::isnan(x) && std::isnan(y);
// SameValueZero doesn't distinguish between 0 and -0.
return true;
}
// TODO(svenpanne) Clean up the whole power-of-2 mess.
inline int32_t WhichPowerOf2Abs(int32_t x) {
......
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