Commit a5d41888 authored by ahaas's avatar ahaas Committed by Commit bot

x87: fix the use of CheckFloatEq and CheckDoubleEq in test.

Instead of using CheckFloatEq and CheckDoubleEq directly, I introduced
a macro which first stores the expected result in a volatile variable.

Here are some comments of previous CLs:

The reason is same as the CL #31808 (issue 1430943002, X87: Change the test case for X87 float operations), please refer: https://codereview.chromium.org/1430943002/.

  Here is the key comments from CL #31808
  Some new test cases use CheckFloatEq(...) and CheckDoubleEq(...) function for result check. When GCC compiling the CheckFloatEq() and CheckDoubleEq() function,
  those inlined functions has different behavior comparing with GCC ia32 build and x87 build.
  The major difference is sse float register still has single precision rounding semantic. While X87 register has no such rounding precsion semantic when directly use register value.
  The V8 turbofan JITTed has exactly same result in both X87 and IA32 port.

  So we add the following sentence to do type cast to keep the same precision for RunCallInt64ToFloat32/RunCallInt64ToFloat64. Such as: volatile double expect = static_cast<float>(*i).

R=titzer@chromium.org, weiliang.lin@intel.com

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

Cr-Commit-Position: refs/heads/master@{#34534}
parent a917319a
......@@ -563,7 +563,7 @@ TEST(RunBinopTester) {
Float64BinopTester bt(&m);
bt.AddReturn(bt.param0);
FOR_FLOAT64_INPUTS(i) { CheckDoubleEq(*i, bt.call(*i, 9.0)); }
FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(*i, bt.call(*i, 9.0)); }
}
{
......@@ -571,7 +571,7 @@ TEST(RunBinopTester) {
Float64BinopTester bt(&m);
bt.AddReturn(bt.param1);
FOR_FLOAT64_INPUTS(i) { CheckDoubleEq(*i, bt.call(-11.25, *i)); }
FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(*i, bt.call(-11.25, *i)); }
}
}
......@@ -587,7 +587,7 @@ TEST(RunBufferedRawMachineAssemblerTesterTester) {
{
BufferedRawMachineAssemblerTester<double> m(MachineType::Float64());
m.Return(m.Parameter(0));
FOR_FLOAT64_INPUTS(i) { CheckDoubleEq(*i, m.Call(*i)); }
FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(*i, m.Call(*i)); }
}
{
BufferedRawMachineAssemblerTester<int64_t> m(MachineType::Int64(),
......@@ -647,7 +647,7 @@ TEST(RunBufferedRawMachineAssemblerTesterTester) {
m.Return(m.Int32Constant(0));
FOR_FLOAT64_INPUTS(i) {
m.Call(*i);
CheckDoubleEq(*i, result);
CHECK_DOUBLE_EQ(*i, result);
}
}
{
......
......@@ -237,13 +237,13 @@ TEST(RunChangeTaggedToFloat64) {
{
Handle<Object> number = t.factory()->NewNumber(input);
t.Call(*number);
CheckDoubleEq(input, result);
CHECK_DOUBLE_EQ(input, result);
}
{
Handle<HeapNumber> number = t.factory()->NewHeapNumber(input);
t.Call(*number);
CheckDoubleEq(input, result);
CHECK_DOUBLE_EQ(input, result);
}
}
}
......
......@@ -55,13 +55,13 @@ class RepresentationChangerTester : public HandleAndZoneScope,
void CheckFloat64Constant(Node* n, double expected) {
Float64Matcher m(n);
CHECK(m.HasValue());
CheckDoubleEq(expected, m.Value());
CHECK_DOUBLE_EQ(expected, m.Value());
}
void CheckFloat32Constant(Node* n, float expected) {
CHECK_EQ(IrOpcode::kFloat32Constant, n->opcode());
float fval = OpParameter<float>(n->op());
CheckDoubleEq(expected, fval);
CHECK_FLOAT_EQ(expected, fval);
}
void CheckHeapConstant(Node* n, HeapObject* expected) {
......@@ -74,7 +74,7 @@ class RepresentationChangerTester : public HandleAndZoneScope,
NumberMatcher m(n);
CHECK_EQ(IrOpcode::kNumberConstant, n->opcode());
CHECK(m.HasValue());
CheckDoubleEq(expected, m.Value());
CHECK_DOUBLE_EQ(expected, m.Value());
}
Node* Parameter(int index = 0) {
......
......@@ -23,7 +23,7 @@ void TestExternalReferenceRoundingFunction(
FOR_FLOAT64_INPUTS(i) {
parameter = *i;
m->Call();
CheckDoubleEq(comparison(*i), parameter);
CHECK_DOUBLE_EQ(comparison(*i), parameter);
}
}
......@@ -90,7 +90,7 @@ TEST(RunCallInt64ToFloat32) {
FOR_INT64_INPUTS(i) {
input = *i;
m.Call();
CheckFloatEq(static_cast<float>(*i), output);
CHECK_FLOAT_EQ(static_cast<float>(*i), output);
}
}
......@@ -218,7 +218,7 @@ TEST(RunCallInt64ToFloat64) {
FOR_INT64_INPUTS(i) {
input = *i;
m.Call();
CheckDoubleEq(static_cast<double>(*i), output);
CHECK_DOUBLE_EQ(static_cast<double>(*i), output);
}
}
......
This diff is collapsed.
......@@ -321,6 +321,12 @@ static inline void CheckFloatEq(volatile float x, volatile float y) {
}
}
#define CHECK_FLOAT_EQ(lhs, rhs) \
do { \
volatile float tmp = lhs; \
CheckFloatEq(tmp, rhs); \
} while (0)
static inline void CheckDoubleEq(volatile double x, volatile double y) {
if (std::isnan(x)) {
CHECK(std::isnan(y));
......@@ -329,6 +335,12 @@ static inline void CheckDoubleEq(volatile double x, volatile double y) {
}
}
#define CHECK_DOUBLE_EQ(lhs, rhs) \
do { \
volatile double tmp = lhs; \
CheckDoubleEq(tmp, rhs); \
} while (0)
} // namespace compiler
} // namespace internal
} // namespace v8
......
......@@ -2467,10 +2467,7 @@ TEST(Run_WasmCall_Float32Sub) {
BUILD(r, WASM_CALL_FUNCTION(index, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_FLOAT32_INPUTS(i) {
FOR_FLOAT32_INPUTS(j) {
volatile float expected = *i - *j;
CheckFloatEq(expected, r.Call(*i, *j));
}
FOR_FLOAT32_INPUTS(j) { CHECK_FLOAT_EQ(*i - *j, r.Call(*i, *j)); }
}
}
......@@ -2910,56 +2907,56 @@ TEST(Run_Wasm_F32Floor) {
WasmRunner<float> r(MachineType::Float32());
BUILD(r, WASM_F32_FLOOR(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) { CheckFloatEq(floorf(*i), r.Call(*i)); }
FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(floorf(*i), r.Call(*i)); }
}
TEST(Run_Wasm_F32Ceil) {
WasmRunner<float> r(MachineType::Float32());
BUILD(r, WASM_F32_CEIL(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) { CheckFloatEq(ceilf(*i), r.Call(*i)); }
FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(ceilf(*i), r.Call(*i)); }
}
TEST(Run_Wasm_F32Trunc) {
WasmRunner<float> r(MachineType::Float32());
BUILD(r, WASM_F32_TRUNC(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) { CheckFloatEq(truncf(*i), r.Call(*i)); }
FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(truncf(*i), r.Call(*i)); }
}
TEST(Run_Wasm_F32NearestInt) {
WasmRunner<float> r(MachineType::Float32());
BUILD(r, WASM_F32_NEARESTINT(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) { CheckFloatEq(nearbyintf(*i), r.Call(*i)); }
FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(nearbyintf(*i), r.Call(*i)); }
}
TEST(Run_Wasm_F64Floor) {
WasmRunner<double> r(MachineType::Float64());
BUILD(r, WASM_F64_FLOOR(WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) { CheckDoubleEq(floor(*i), r.Call(*i)); }
FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(floor(*i), r.Call(*i)); }
}
TEST(Run_Wasm_F64Ceil) {
WasmRunner<double> r(MachineType::Float64());
BUILD(r, WASM_F64_CEIL(WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) { CheckDoubleEq(ceil(*i), r.Call(*i)); }
FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(ceil(*i), r.Call(*i)); }
}
TEST(Run_Wasm_F64Trunc) {
WasmRunner<double> r(MachineType::Float64());
BUILD(r, WASM_F64_TRUNC(WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) { CheckDoubleEq(trunc(*i), r.Call(*i)); }
FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(trunc(*i), r.Call(*i)); }
}
TEST(Run_Wasm_F64NearestInt) {
WasmRunner<double> r(MachineType::Float64());
BUILD(r, WASM_F64_NEARESTINT(WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) { CheckDoubleEq(nearbyint(*i), r.Call(*i)); }
FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(nearbyint(*i), r.Call(*i)); }
}
TEST(Run_Wasm_F32Min) {
......@@ -2980,7 +2977,7 @@ TEST(Run_Wasm_F32Min) {
expected = *j;
}
CheckFloatEq(expected, r.Call(*i, *j));
CHECK_FLOAT_EQ(expected, r.Call(*i, *j));
}
}
}
......@@ -3004,7 +3001,7 @@ TEST(Run_Wasm_F64Min) {
expected = *j;
}
CheckDoubleEq(expected, r.Call(*i, *j));
CHECK_DOUBLE_EQ(expected, r.Call(*i, *j));
}
}
}
......@@ -3028,7 +3025,7 @@ TEST(Run_Wasm_F32Max) {
expected = *j;
}
CheckFloatEq(expected, r.Call(*i, *j));
CHECK_FLOAT_EQ(expected, r.Call(*i, *j));
}
}
}
......@@ -3052,7 +3049,7 @@ TEST(Run_Wasm_F64Max) {
expected = *j;
}
CheckDoubleEq(expected, r.Call(*i, *j));
CHECK_DOUBLE_EQ(expected, r.Call(*i, *j));
}
}
}
......@@ -3287,7 +3284,7 @@ TEST(Run_Wasm_F64CopySign) {
BUILD(r, WASM_F64_COPYSIGN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_FLOAT64_INPUTS(i) {
FOR_FLOAT64_INPUTS(j) { CheckDoubleEq(copysign(*i, *j), r.Call(*i, *j)); }
FOR_FLOAT64_INPUTS(j) { CHECK_DOUBLE_EQ(copysign(*i, *j), r.Call(*i, *j)); }
}
}
......@@ -3300,7 +3297,7 @@ TEST(Run_Wasm_F32CopySign) {
BUILD(r, WASM_F32_COPYSIGN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_FLOAT32_INPUTS(i) {
FOR_FLOAT32_INPUTS(j) { CheckFloatEq(copysign(*i, *j), r.Call(*i, *j)); }
FOR_FLOAT32_INPUTS(j) { CHECK_FLOAT_EQ(copysign(*i, *j), r.Call(*i, *j)); }
}
}
......
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