From 7d78bcd592de74966af044b5b30e06b6da0b31ce Mon Sep 17 00:00:00 2001 From: Vasu Penugonda Date: Wed, 4 Oct 2023 11:29:50 +0530 Subject: [PATCH] Add NaN check for all float types Use std::isnan for float/double types. Change-Id: I005bddccaa3f8490ac59b2aa431ed315733ad143 --- test_conformance/basic/test_explicit_s2v.cpp | 24 ++++++++------------ 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/test_conformance/basic/test_explicit_s2v.cpp b/test_conformance/basic/test_explicit_s2v.cpp index 473b82828..03d67e197 100644 --- a/test_conformance/basic/test_explicit_s2v.cpp +++ b/test_conformance/basic/test_explicit_s2v.cpp @@ -13,6 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. // +#include +#define isnan std::isnan #include "harness/compat.h" #include @@ -98,16 +100,6 @@ const char * kernel_explicit_s2v_set[NUM_VEC_TYPES][NUM_VEC_TYPES][5] = { // clang-format on -int IsFloatNaN(double x) -{ - union { - cl_float d; - cl_uint u; - } u; - u.d = (cl_float)x; - return ((u.u & 0x7fffffffU) > 0x7F800000U); -} - bool IsHalfNaN(cl_half v) { // Extract FP16 exponent and mantissa @@ -179,10 +171,14 @@ int test_explicit_s2v_function(cl_context context, cl_command_queue queue, { if( memcmp( convertedData, outPtr + destTypeSize * s, destTypeSize ) != 0 ) { - if ((srcType == kHalf) && (destType == kFloat) - && IsHalfNaN(*reinterpret_cast(inPtr)) - && IsFloatNaN(*reinterpret_cast( - outPtr + destTypeSize * s))) + bool isSrcNaN = (((srcType == kHalf) && IsHalfNaN(*reinterpret_cast(inPtr))) + || ((srcType == kFloat) && isnan(*reinterpret_cast(inPtr))) + || ((srcType == kDouble) && isnan(*reinterpret_cast(inPtr)))); + bool isDestNaN = (((destType == kHalf) && IsHalfNaN(*reinterpret_cast(outPtr + destTypeSize * s))) + || ((destType == kFloat) && isnan(*reinterpret_cast(outPtr + destTypeSize * s))) + || ((destType == kDouble) && isnan(*reinterpret_cast(outPtr + destTypeSize * s)))); + + if (isSrcNaN && isDestNaN) { continue; }