Remove duplicated code from isinf/isnan tests
authorGraeme Leese <gleese@broadcom.com>
Tue, 11 Jun 2019 12:41:23 +0000 (13:41 +0100)
committerAlexander Galazin <Alexander.Galazin@arm.com>
Mon, 30 Mar 2020 10:07:37 +0000 (06:07 -0400)
Most of the checking code for IsNan and IsInf was written out twice,
once for each precision. Remove one of the copies.

Components: Vulkan
Affects: dEQP-VK.glsl.builtin.function.common.isinf.*
         dEQP-VK.glsl.builtin.function.common.isnan.*

Change-Id: I5c00e1757086b204a6797424c0d35eb84b3f99a8

external/vulkancts/modules/vulkan/shaderexecutor/vktShaderCommonFunctionTests.cpp

index c777ccd..28b304a 100644 (file)
@@ -576,36 +576,23 @@ public:
                const glu::Precision    precision               = m_spec.inputs[0].varType.getPrecision();
                const int                               scalarSize              = glu::getDataTypeScalarSize(type);
 
-               if (precision == glu::PRECISION_HIGHP)
-               {
-                       // Only highp is required to support inf/nan
-                       for (int compNdx = 0; compNdx < scalarSize; compNdx++)
-                       {
-                               const float             in0             = ((const float*)inputs[0])[compNdx];
-                               const bool              out0    = ((const deUint32*)outputs[0])[compNdx] != 0;
-                               const bool              ref             = tcu::Float32(in0).isNaN();
-
-                               if (out0 != ref)
-                               {
-                                       m_failMsg << "Expected [" << compNdx << "] = " << (ref ? "true" : "false");
-                                       return false;
-                               }
-                       }
-               }
-               else if (precision == glu::PRECISION_MEDIUMP || precision == glu::PRECISION_LOWP)
+               for (int compNdx = 0; compNdx < scalarSize; compNdx++)
                {
-                       // NaN support is optional, check that inputs that are not NaN don't result in true.
-                       for (int compNdx = 0; compNdx < scalarSize; compNdx++)
+                       const float             in0             = ((const float*)inputs[0])[compNdx];
+                       const bool              out0    = ((const deUint32*)outputs[0])[compNdx] != 0;
+                       const bool              ref             = tcu::Float32(in0).isNaN();
+                       bool                    ok;
+
+                       // NaN support only required for highp. Otherwise just check for false positives.
+                       if (precision == glu::PRECISION_HIGHP)
+                               ok = (out0 == ref);
+                       else
+                               ok = ref || !out0;
+
+                       if (!ok)
                        {
-                               const float             in0             = ((const float*)inputs[0])[compNdx];
-                               const bool              out0    = ((const deUint32*)outputs[0])[compNdx] != 0;
-                               const bool              ref             = tcu::Float32(in0).isNaN();
-
-                               if (!ref && out0)
-                               {
-                                       m_failMsg << "Expected [" << compNdx << "] = " << (ref ? "true" : "false");
-                                       return false;
-                               }
+                               m_failMsg << "Expected [" << compNdx << "] = " << (ref ? "true" : "false");
+                               return false;
                        }
                }
 
@@ -654,39 +641,30 @@ public:
                const glu::Precision    precision               = m_spec.inputs[0].varType.getPrecision();
                const int                               scalarSize              = glu::getDataTypeScalarSize(type);
 
-               if (precision == glu::PRECISION_HIGHP)
+               for (int compNdx = 0; compNdx < scalarSize; compNdx++)
                {
-                       // Only highp is required to support inf/nan
-                       for (int compNdx = 0; compNdx < scalarSize; compNdx++)
+                       const float             in0             = ((const float*)inputs[0])[compNdx];
+                       const bool              out0    = ((const deUint32*)outputs[0])[compNdx] != 0;
+                       bool                    ref;
+                       bool                    ok;
+                       if (precision == glu::PRECISION_HIGHP)
                        {
-                               const float             in0             = ((const float*)inputs[0])[compNdx];
-                               const bool              out0    = ((const deUint32*)outputs[0])[compNdx] != 0;
-                               const bool              ref             = tcu::Float32(in0).isInf();
-
-                               if (out0 != ref)
-                               {
-                                       m_failMsg << "Expected [" << compNdx << "] = " << HexBool(ref);
-                                       return false;
-                               }
+                               // Only highp is required to support inf/nan
+                               ref = tcu::Float32(in0).isInf();
+                               ok = (out0 == ref);
                        }
-               }
-               else if (precision == glu::PRECISION_MEDIUMP)
-               {
-                       // Inf support is optional, check that inputs that are not Inf in mediump don't result in true.
-                       for (int compNdx = 0; compNdx < scalarSize; compNdx++)
+                       else
                        {
-                               const float             in0             = ((const float*)inputs[0])[compNdx];
-                               const bool              out0    = ((const deUint32*)outputs[0])[compNdx] != 0;
-                               const bool              ref             = tcu::Float16(in0).isInf();
-
-                               if (!ref && out0)
-                               {
-                                       m_failMsg << "Expected [" << compNdx << "] = " << (ref ? "true" : "false");
-                                       return false;
-                               }
+                               // Inf support is optional, check that inputs that are not Inf in mediump don't result in true.
+                               ref = tcu::Float16(in0).isInf();
+                               ok = (out0 || !ref);
+                       }
+                       if (!ok)
+                       {
+                               m_failMsg << "Expected [" << compNdx << "] = " << HexBool(ref);
+                               return false;
                        }
                }
-               // else: no verification can be performed
 
                return true;
        }