From 03da14d6a9a1525cc585f256404bbfc79ccc0e44 Mon Sep 17 00:00:00 2001 From: Jim Lewis Date: Tue, 19 Apr 2022 11:57:15 -0500 Subject: [PATCH] Fix clang 10 build errors (#1387) * Fix clang 10 build errors Lossy casts due to inexact float representation of CL_INT_MAX * Fix clang format * Remove implicit-const-int-float-conversion flag --- CMakeLists.txt | 1 - test_common/harness/imageHelpers.cpp | 21 +++++++-------------- test_common/harness/imageHelpers.h | 2 +- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b307a11..8f5f4472 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,7 +94,6 @@ if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?Clang" add_cxx_flag_if_supported(-Wno-error=cpp) # Allow #warning directive add_cxx_flag_if_supported(-Wno-error=unknown-pragmas) # Issue #785 add_cxx_flag_if_supported(-Wno-error=asm-operand-widths) # Issue #784 - add_cxx_flag_if_supported(-Wno-error=implicit-const-int-float-conversion) # Issue #1250 # -msse -mfpmath=sse to force gcc to use sse for float math, # avoiding excess precision problems that cause tests like int2float diff --git a/test_common/harness/imageHelpers.cpp b/test_common/harness/imageHelpers.cpp index 3a5c5533..c380c1f3 100644 --- a/test_common/harness/imageHelpers.cpp +++ b/test_common/harness/imageHelpers.cpp @@ -2624,11 +2624,11 @@ void pack_image_pixel(int *srcVector, const cl_image_format *imageFormat, } } -int round_to_even(float v) +cl_int round_to_even(float v) { // clamp overflow - if (v >= -(float)INT_MIN) return INT_MAX; - if (v <= (float)INT_MIN) return INT_MIN; + if (v >= -(float)CL_INT_MIN) return CL_INT_MAX; + if (v <= (float)CL_INT_MIN) return CL_INT_MIN; // round fractional values to integer value if (fabsf(v) < MAKE_HEX_FLOAT(0x1.0p23f, 0x1L, 23)) @@ -2640,7 +2640,7 @@ int round_to_even(float v) v -= magicVal; } - return (int)v; + return (cl_int)v; } void pack_image_pixel(float *srcVector, const cl_image_format *imageFormat, @@ -2765,10 +2765,7 @@ void pack_image_pixel(float *srcVector, const cl_image_format *imageFormat, case CL_SIGNED_INT32: { cl_int *ptr = (cl_int *)outData; for (unsigned int i = 0; i < channelCount; i++) - ptr[i] = (int)CONVERT_INT( - srcVector[i], MAKE_HEX_FLOAT(-0x1.0p31f, -1, 31), - MAKE_HEX_FLOAT(0x1.fffffep30f, 0x1fffffe, 30 - 23), - CL_INT_MAX); + ptr[i] = round_to_even(srcVector[i]); break; } case CL_UNSIGNED_INT8: { @@ -2932,12 +2929,8 @@ void pack_image_pixel_error(const float *srcVector, case CL_SIGNED_INT32: { const cl_int *ptr = (const cl_int *)results; for (unsigned int i = 0; i < channelCount; i++) - errors[i] = (cl_float)( - (cl_long)ptr[i] - - (cl_long)CONVERT_INT( - srcVector[i], MAKE_HEX_FLOAT(-0x1.0p31f, -1, 31), - MAKE_HEX_FLOAT(0x1.fffffep30f, 0x1fffffe, 30 - 23), - CL_INT_MAX)); + errors[i] = (cl_float)((cl_long)ptr[i] + - (cl_long)round_to_even(srcVector[i])); break; } case CL_UNSIGNED_INT8: { diff --git a/test_common/harness/imageHelpers.h b/test_common/harness/imageHelpers.h index e728a939..2cc8e68e 100644 --- a/test_common/harness/imageHelpers.h +++ b/test_common/harness/imageHelpers.h @@ -63,7 +63,7 @@ typedef struct bool normalized_coords; } image_sampler_data; -int round_to_even(float v); +cl_int round_to_even(float v); #define NORMALIZE(v, max) (v < 0 ? 0 : (v > 1.f ? max : round_to_even(v * max))) #define NORMALIZE_UNROUNDED(v, max) (v < 0 ? 0 : (v > 1.f ? max : v * max))