From 03cb2be937af5670a9b1b8f12e1f167a4454780b Mon Sep 17 00:00:00 2001 From: Ari Suonpaa Date: Wed, 24 Nov 2021 15:52:28 +0200 Subject: [PATCH] Avoid shifting by more than bit width 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 | 7 ++++++- external/openglcts/modules/common/glcMisc.cpp | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/external/openglcts/modules/common/glcInternalformatTests.cpp b/external/openglcts/modules/common/glcInternalformatTests.cpp index 4304985..bbe119c 100644 --- a/external/openglcts/modules/common/glcInternalformatTests.cpp +++ b/external/openglcts/modules/common/glcInternalformatTests.cpp @@ -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)); } diff --git a/external/openglcts/modules/common/glcMisc.cpp b/external/openglcts/modules/common/glcMisc.cpp index 8efd38f..b11bee4 100644 --- a/external/openglcts/modules/common/glcMisc.cpp +++ b/external/openglcts/modules/common/glcMisc.cpp @@ -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 -- 2.7.4