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

[test] Also print hex representation of floats/doubles

In the CHECK_FLOAT_EQ and CHECK_DOUBLE_EQ wrappers, do also print hex
representations on failure. Otherwise, single bit flips might not be
visible in the output, like here:
Check failed: DoubleWrapper(x) == y (-2e+66 vs. -2e+66).

R=titzer@chromium.org

Change-Id: I2521706aedc6ff81c0dbb25259230f8e29ce9a3e
Reviewed-on: https://chromium-review.googlesource.com/1219630Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55799}
parent 9c67143f
......@@ -345,29 +345,37 @@ template <typename type>
struct FloatCompareWrapper {
type value;
explicit FloatCompareWrapper(type x) : value(x) {}
bool operator==(type other) const {
bool operator==(FloatCompareWrapper<type> other) const {
return std::isnan(value)
? std::isnan(other)
: value == other && std::signbit(value) == std::signbit(other);
? std::isnan(other.value)
: value == other.value &&
std::signbit(value) == std::signbit(other.value);
}
};
template <typename type>
std::ostream& operator<<(std::ostream& out, FloatCompareWrapper<type> wrapper) {
return out << wrapper.value;
uint8_t bytes[sizeof(type)];
memcpy(bytes, &wrapper.value, sizeof(type));
out << wrapper.value << " (0x";
const char* kHexDigits = "0123456789ABCDEF";
for (unsigned i = 0; i < sizeof(type); ++i) {
out << kHexDigits[bytes[i] >> 4] << kHexDigits[bytes[i] & 15];
}
return out << ")";
}
#define CHECK_FLOAT_EQ(lhs, rhs) \
do { \
using FloatWrapper = ::v8::internal::compiler::FloatCompareWrapper<float>; \
CHECK_EQ(FloatWrapper(lhs), rhs); \
CHECK_EQ(FloatWrapper(lhs), FloatWrapper(rhs)); \
} while (false)
#define CHECK_DOUBLE_EQ(lhs, rhs) \
do { \
using DoubleWrapper = \
::v8::internal::compiler::FloatCompareWrapper<double>; \
CHECK_EQ(DoubleWrapper(lhs), rhs); \
CHECK_EQ(DoubleWrapper(lhs), DoubleWrapper(rhs)); \
} while (false)
} // namespace compiler
......
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