Commit fa0e55e2 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[test] Fix CHECK_DOUBLE_EQ and CHECK_FLOAT_EQ

Both macros currently call a function with individual CHECKs, which
makes error messages only show that one part of the equality check (and
not the the actual float values), and hides the actual location of the
check.
This CL refactors this such that the actual value is shown (just as
with other CHECK_EQ macros) and it shows the right file name and line
number.

R=ahaas@chromium.org

Bug: v8:7570
Change-Id: I198e73c053178a09f14330a18069463760693f81
Reviewed-on: https://chromium-review.googlesource.com/1027879Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52832}
parent 903d8731
......@@ -350,36 +350,40 @@ class ValueHelper {
#define FOR_UINT32_SHIFTS(var) for (uint32_t var = 0; var < 32; var++)
// TODO(bmeurer): Drop this crap once we switch to GTest/Gmock.
static inline void CheckFloatEq(volatile float x, volatile float y) {
if (std::isnan(x)) {
CHECK(std::isnan(y));
} else {
CHECK_EQ(x, y);
CHECK_EQ(std::signbit(x), std::signbit(y));
template <typename type>
struct FloatCompareWrapper {
type value;
explicit FloatCompareWrapper(type x) : value(x) {}
bool operator==(type other) const {
return std::isnan(value)
? std::isnan(other)
: value == other && std::signbit(value) == std::signbit(other);
}
}
};
#define CHECK_FLOAT_EQ(lhs, rhs) \
do { \
volatile float tmp = lhs; \
::v8::internal::compiler::CheckFloatEq(tmp, rhs); \
} while (0)
static inline void CheckDoubleEq(volatile double x, volatile double y) {
if (std::isnan(x)) {
CHECK(std::isnan(y));
} else {
CHECK_EQ(x, y);
CHECK_EQ(std::signbit(x), std::signbit(y));
}
template <typename type>
std::ostream& operator<<(std::ostream& out, FloatCompareWrapper<type> wrapper) {
return out << wrapper.value;
}
#define CHECK_DOUBLE_EQ(lhs, rhs) \
do { \
volatile double tmp = lhs; \
::v8::internal::compiler::CheckDoubleEq(tmp, rhs); \
} while (0)
#define CHECK_FLOAT_EQ(lhs, rhs) \
do { \
using FloatWrapper = ::v8::internal::compiler::FloatCompareWrapper<float>; \
CHECK_EQ(FloatWrapper(lhs), rhs); \
} while (false)
#define CHECK_DOUBLE_EQ(lhs, rhs) \
do { \
using DoubleWrapper = \
::v8::internal::compiler::FloatCompareWrapper<double>; \
CHECK_EQ(DoubleWrapper(lhs), rhs); \
} while (false)
// TODO(all): Use CHECK_FLOAT_EQ to get error reported at the right location.
static inline void CheckFloatEq(float x, float y) { CHECK_FLOAT_EQ(x, y); }
// TODO(all): Use CHECK_DOUBLE_EQ to get error reported at the right location.
static inline void CheckDoubleEq(double x, double y) { CHECK_DOUBLE_EQ(x, y); }
} // namespace compiler
} // namespace internal
......
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