Commit 563539a3 authored by ahaas's avatar ahaas Committed by Commit bot

[wasm] min/max does not return signaling NaNs anymore.

To avoid returning a signaling NaN the result is multiplied by 1.0.

R=titzer@chromium.org, binji@chromium.org

BUG=4733
LOG=Y

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

Cr-Commit-Position: refs/heads/master@{#33783}
parent 5c5ccd9d
......@@ -1035,8 +1035,12 @@ Node* WasmGraphBuilder::BuildF32Min(Node* left, Node* right) {
return left_le_right.Phi(
wasm::kAstF32, left,
right_lt_left.Phi(wasm::kAstF32, right,
left_is_not_nan.Phi(wasm::kAstF32, right, left)));
right_lt_left.Phi(
wasm::kAstF32, right,
left_is_not_nan.Phi(
wasm::kAstF32,
Binop(wasm::kExprF32Mul, right, Float32Constant(1.0)),
Binop(wasm::kExprF32Mul, left, Float32Constant(1.0)))));
}
......@@ -1052,8 +1056,12 @@ Node* WasmGraphBuilder::BuildF32Max(Node* left, Node* right) {
return left_ge_right.Phi(
wasm::kAstF32, left,
right_gt_left.Phi(wasm::kAstF32, right,
left_is_not_nan.Phi(wasm::kAstF32, right, left)));
right_gt_left.Phi(
wasm::kAstF32, right,
left_is_not_nan.Phi(
wasm::kAstF32,
Binop(wasm::kExprF32Mul, right, Float32Constant(1.0)),
Binop(wasm::kExprF32Mul, left, Float32Constant(1.0)))));
}
......@@ -1069,8 +1077,12 @@ Node* WasmGraphBuilder::BuildF64Min(Node* left, Node* right) {
return left_le_right.Phi(
wasm::kAstF64, left,
right_lt_left.Phi(wasm::kAstF64, right,
left_is_not_nan.Phi(wasm::kAstF64, right, left)));
right_lt_left.Phi(
wasm::kAstF64, right,
left_is_not_nan.Phi(
wasm::kAstF64,
Binop(wasm::kExprF64Mul, right, Float64Constant(1.0)),
Binop(wasm::kExprF64Mul, left, Float64Constant(1.0)))));
}
......@@ -1086,8 +1098,12 @@ Node* WasmGraphBuilder::BuildF64Max(Node* left, Node* right) {
return left_ge_right.Phi(
wasm::kAstF64, left,
right_gt_left.Phi(wasm::kAstF64, right,
left_is_not_nan.Phi(wasm::kAstF64, right, left)));
right_gt_left.Phi(
wasm::kAstF64, right,
left_is_not_nan.Phi(
wasm::kAstF64,
Binop(wasm::kExprF64Mul, right, Float64Constant(1.0)),
Binop(wasm::kExprF64Mul, left, Float64Constant(1.0)))));
}
......
......@@ -3138,6 +3138,74 @@ TEST(Run_Wasm_F64Max) {
}
}
// TODO(ahaas): Fix on arm and reenable.
#if !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_ARM64
TEST(Run_Wasm_F32Min_Snan) {
// Test that the instruction does not return a signalling NaN.
{
WasmRunner<float> r;
BUILD(r,
WASM_F32_MIN(WASM_F32(bit_cast<float>(0xff80f1e2)), WASM_F32(57.67)));
CHECK_EQ(0xffc0f1e2, bit_cast<uint32_t>(r.Call()));
}
{
WasmRunner<float> r;
BUILD(r,
WASM_F32_MIN(WASM_F32(45.73), WASM_F32(bit_cast<float>(0x7f80f1e2))));
CHECK_EQ(0x7fc0f1e2, bit_cast<uint32_t>(r.Call()));
}
}
TEST(Run_Wasm_F32Max_Snan) {
// Test that the instruction does not return a signalling NaN.
{
WasmRunner<float> r;
BUILD(r,
WASM_F32_MAX(WASM_F32(bit_cast<float>(0xff80f1e2)), WASM_F32(57.67)));
CHECK_EQ(0xffc0f1e2, bit_cast<uint32_t>(r.Call()));
}
{
WasmRunner<float> r;
BUILD(r,
WASM_F32_MAX(WASM_F32(45.73), WASM_F32(bit_cast<float>(0x7f80f1e2))));
CHECK_EQ(0x7fc0f1e2, bit_cast<uint32_t>(r.Call()));
}
}
TEST(Run_Wasm_F64Min_Snan) {
// Test that the instruction does not return a signalling NaN.
{
WasmRunner<double> r;
BUILD(r, WASM_F64_MIN(WASM_F64(bit_cast<double>(0xfff000000000f1e2)),
WASM_F64(57.67)));
CHECK_EQ(0xfff800000000f1e2, bit_cast<uint64_t>(r.Call()));
}
{
WasmRunner<double> r;
BUILD(r, WASM_F64_MIN(WASM_F64(45.73),
WASM_F64(bit_cast<double>(0x7ff000000000f1e2))));
CHECK_EQ(0x7ff800000000f1e2, bit_cast<uint64_t>(r.Call()));
}
}
TEST(Run_Wasm_F64Max_Snan) {
// Test that the instruction does not return a signalling NaN.
{
WasmRunner<double> r;
BUILD(r, WASM_F64_MAX(WASM_F64(bit_cast<double>(0xfff000000000f1e2)),
WASM_F64(57.67)));
CHECK_EQ(0xfff800000000f1e2, bit_cast<uint64_t>(r.Call()));
}
{
WasmRunner<double> r;
BUILD(r, WASM_F64_MAX(WASM_F64(45.73),
WASM_F64(bit_cast<double>(0x7ff000000000f1e2))));
CHECK_EQ(0x7ff800000000f1e2, bit_cast<uint64_t>(r.Call()));
}
}
#endif
#if WASM_64
TEST(Run_Wasm_F32SConvertI64) {
......
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