Skip to content

Commit

Permalink
Fix clang 10 build errors (KhronosGroup#1387)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jlewis-austin authored Apr 19, 2022
1 parent d533472 commit 03da14d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 7 additions & 14 deletions test_common/harness/imageHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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,
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion test_common/harness/imageHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 03da14d

Please sign in to comment.