Reviewers: Dan Ehrenberg, jochen,
Message:
Will be used in https://codereview.chromium.org/1219943002/
Description:
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
Please review this at https://codereview.chromium.org/1234073003/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+20, -12 lines):
M src/objects.cc
M src/utils.h
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index
e53df91d0ba67f99ba9bb1f422a4b68ff9fed72d..97c8b65a465a7f25746301ded12ee29e239dd110
100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -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));
Index: src/utils.h
diff --git a/src/utils.h b/src/utils.h
index
582c5769936947698217cf5fd5ef219ab7e919eb..1cbcdf4aafb6677eac00ad5911f95bc149aaa129
100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -201,6 +201,24 @@ inline double Floor(double x) {
}
+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;
+}
+
+
+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) {
return (x == kMinInt) ? 31 : WhichPowerOf2(Abs(x));
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.