From 5f8addfd99d435a91daa8bff7b3338227a0661eb Mon Sep 17 00:00:00 2001 From: Mary Guillemard Date: Thu, 19 Dec 2024 12:09:16 +0100 Subject: [PATCH] util/bitpack_helpers: Make fixed packs CL safe We emulate roundf and llroundf for compatibility. Signed-off-by: Mary Guillemard Acked-by: Alyssa Rosenzweig Reviewed-by: Eric R. Smith Part-of: --- src/compiler/libcl/libcl.h | 13 +++++++++++++ src/util/bitpack_helpers.h | 2 -- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/compiler/libcl/libcl.h b/src/compiler/libcl/libcl.h index a20d6e6fbb5..265c863c278 100644 --- a/src/compiler/libcl/libcl.h +++ b/src/compiler/libcl/libcl.h @@ -210,6 +210,19 @@ uif(uint32_t ui) return as_float(ui); } +#define CL_FLT_EPSILON 1.1920928955078125e-7f + +/* OpenCL C lacks roundf and llroundf, we can emulate it */ +static inline float roundf(float x) +{ + return trunc(x + copysign(0.5f - 0.25f * CL_FLT_EPSILON, x)); +} + +static inline long long llroundf(float x) +{ + return roundf(x); +} + static inline uint16_t _mesa_float_to_half(float f) { diff --git a/src/util/bitpack_helpers.h b/src/util/bitpack_helpers.h index 25f3045ab49..bb1a094da47 100644 --- a/src/util/bitpack_helpers.h +++ b/src/util/bitpack_helpers.h @@ -119,7 +119,6 @@ util_bitpack_float_nonzero(float v) return util_bitpack_float(v); } -#ifndef __OPENCL_VERSION__ ALWAYS_INLINE static uint64_t util_bitpack_sfixed(float v, uint32_t start, uint32_t end, uint32_t fract_bits) @@ -211,6 +210,5 @@ util_bitpack_ufixed_nonzero(float v, uint32_t start, uint32_t end, assert(v != 0.0f); return util_bitpack_ufixed(v, start, end, fract_bits); } -#endif #endif /* UTIL_BITPACK_HELPERS_H */