Avoid shifting by more than bit width
authorAri Suonpaa <ari.suonpaa@siru.fi>
Wed, 24 Nov 2021 13:52:28 +0000 (15:52 +0200)
committerMatthew Netsch <quic_mnetsch@quicinc.com>
Thu, 2 Dec 2021 21:03:34 +0000 (21:03 +0000)
Half float mantissa calculation was sometimes using
shift larger than a bit width. This change sets the
mantissa to zero in those cases.

VK-GL-CTS Issue: 3346
VK-GL-CTS Issue: 3349

Affects:

KHR-GLES*.core.internalformat.texture2d.*half_float*
KHR-GLES3.packed_pixels.*16f

Components: OpenGL ES
Change-Id: Ib91082fab530f6ff9e7cd5b6346ad7d433543a47

external/openglcts/modules/common/glcInternalformatTests.cpp
external/openglcts/modules/common/glcMisc.cpp

index 4304985..bbe119c 100644 (file)
@@ -662,7 +662,12 @@ GLhalf InternalformatCaseBase::floatToHalf(float f)
                // Store a denorm half-float value or zero
                exp = (HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP - exp) >> 23;
                mantissa |= (1 << 23);
-               mantissa >>= (14 + exp);
+
+               if (exp < 18)
+                       mantissa >>= (14 + exp);
+               else
+                       mantissa = 0;
+
                return (GLhalf)((((GLhalf)sign) << 15) | (GLhalf)(mantissa));
        }
 
index 8efd38f..b11bee4 100644 (file)
@@ -75,7 +75,12 @@ GLhalf floatToHalfFloat(float f)
                /* store a denorm half-float value or zero */
                exp = (HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP - exp) >> 23;
                mantissa |= (1 << 23);
-               mantissa >>= (14 + exp);
+
+               if (exp < 18)
+                       mantissa >>= (14 + exp);
+               else
+                       mantissa = 0;
+
                hf = (((GLhalf)sign) << 15) | (GLhalf)(mantissa);
        }
        else