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
This commit is contained in:
Jim Lewis
2022-04-19 11:57:15 -05:00
committed by GitHub
parent d533472c27
commit 03da14d6a9
3 changed files with 8 additions and 16 deletions

View File

@@ -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=cpp) # Allow #warning directive
add_cxx_flag_if_supported(-Wno-error=unknown-pragmas) # Issue #785 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=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, # -msse -mfpmath=sse to force gcc to use sse for float math,
# avoiding excess precision problems that cause tests like int2float # avoiding excess precision problems that cause tests like int2float

View File

@@ -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 // clamp overflow
if (v >= -(float)INT_MIN) return INT_MAX; if (v >= -(float)CL_INT_MIN) return CL_INT_MAX;
if (v <= (float)INT_MIN) return INT_MIN; if (v <= (float)CL_INT_MIN) return CL_INT_MIN;
// round fractional values to integer value // round fractional values to integer value
if (fabsf(v) < MAKE_HEX_FLOAT(0x1.0p23f, 0x1L, 23)) if (fabsf(v) < MAKE_HEX_FLOAT(0x1.0p23f, 0x1L, 23))
@@ -2640,7 +2640,7 @@ int round_to_even(float v)
v -= magicVal; v -= magicVal;
} }
return (int)v; return (cl_int)v;
} }
void pack_image_pixel(float *srcVector, const cl_image_format *imageFormat, 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: { case CL_SIGNED_INT32: {
cl_int *ptr = (cl_int *)outData; cl_int *ptr = (cl_int *)outData;
for (unsigned int i = 0; i < channelCount; i++) for (unsigned int i = 0; i < channelCount; i++)
ptr[i] = (int)CONVERT_INT( ptr[i] = round_to_even(srcVector[i]);
srcVector[i], MAKE_HEX_FLOAT(-0x1.0p31f, -1, 31),
MAKE_HEX_FLOAT(0x1.fffffep30f, 0x1fffffe, 30 - 23),
CL_INT_MAX);
break; break;
} }
case CL_UNSIGNED_INT8: { case CL_UNSIGNED_INT8: {
@@ -2932,12 +2929,8 @@ void pack_image_pixel_error(const float *srcVector,
case CL_SIGNED_INT32: { case CL_SIGNED_INT32: {
const cl_int *ptr = (const cl_int *)results; const cl_int *ptr = (const cl_int *)results;
for (unsigned int i = 0; i < channelCount; i++) for (unsigned int i = 0; i < channelCount; i++)
errors[i] = (cl_float)( errors[i] = (cl_float)((cl_long)ptr[i]
(cl_long)ptr[i] - (cl_long)round_to_even(srcVector[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));
break; break;
} }
case CL_UNSIGNED_INT8: { case CL_UNSIGNED_INT8: {

View File

@@ -63,7 +63,7 @@ typedef struct
bool normalized_coords; bool normalized_coords;
} image_sampler_data; } 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(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)) #define NORMALIZE_UNROUNDED(v, max) (v < 0 ? 0 : (v > 1.f ? max : v * max))