Fix min/max signed zero and NaN handling.
Make min(x, y) equal to (x < y ? x : y) and max(x, y) equal to
(x > y ? x : y), including the behavior for signed zeros and NaNs.
This also enables optimizing them into min and max SSE2 instructions
on x86.
Bug swiftshader:19
Change-Id: I047b90e9da9f3c72657ab7c619bc91b92a700a45
Reviewed-on: https://swiftshader-review.googlesource.com/8771
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
Tested-by: Nicolas Capens <capn@google.com>
diff --git a/src/OpenGL/libGLESv2/libGLESv3.cpp b/src/OpenGL/libGLESv2/libGLESv3.cpp
index 4c86895..b91a451 100644
--- a/src/OpenGL/libGLESv2/libGLESv3.cpp
+++ b/src/OpenGL/libGLESv2/libGLESv3.cpp
@@ -52,7 +52,6 @@
return true;
}
-
static bool validateColorBufferFormat(GLenum textureFormat, GLenum colorbufferFormat)
{
GLenum validationError = ValidateCompressedFormat(textureFormat, egl::getClientVersion(), false);
diff --git a/src/Reactor/Main.cpp b/src/Reactor/Main.cpp
index 362200a..37a006a 100644
--- a/src/Reactor/Main.cpp
+++ b/src/Reactor/Main.cpp
@@ -460,8 +460,8 @@
EXPECT_EQ(out[0][0], 0x00000000);
EXPECT_EQ(out[0][1], 0x00000000);
- EXPECT_EQ(out[0][2], 0x80000000);
- EXPECT_EQ(out[0][3], 0x00000000);
+ EXPECT_EQ(out[0][2], 0x00000000);
+ EXPECT_EQ(out[0][3], 0x80000000);
EXPECT_EQ(out[1][0], 0x3F800000);
EXPECT_EQ(out[1][1], 0x3F800000);
diff --git a/src/Reactor/SubzeroReactor.cpp b/src/Reactor/SubzeroReactor.cpp
index e5208cf..30f4714 100644
--- a/src/Reactor/SubzeroReactor.cpp
+++ b/src/Reactor/SubzeroReactor.cpp
@@ -6040,11 +6040,11 @@
RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y)
{
Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
- auto cmp = Ice::InstFcmp::create(::function, Ice::InstFcmp::Ule, condition, x.value, y.value);
+ auto cmp = Ice::InstFcmp::create(::function, Ice::InstFcmp::Ogt, condition, x.value, y.value);
::basicBlock->appendInst(cmp);
Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
- auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
+ auto select = Ice::InstSelect::create(::function, result, condition, x.value, y.value);
::basicBlock->appendInst(select);
return RValue<Float4>(V(result));
@@ -6053,11 +6053,11 @@
RValue<Float4> Min(RValue<Float4> x, RValue<Float4> y)
{
Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
- auto cmp = Ice::InstFcmp::create(::function, Ice::InstFcmp::Ugt, condition, x.value, y.value);
+ auto cmp = Ice::InstFcmp::create(::function, Ice::InstFcmp::Olt, condition, x.value, y.value);
::basicBlock->appendInst(cmp);
Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
- auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
+ auto select = Ice::InstSelect::create(::function, result, condition, x.value, y.value);
::basicBlock->appendInst(select);
return RValue<Float4>(V(result));