From b59914e179a9e5930af37e7f7c0d8eafd682caff Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Fri, 23 Aug 2019 11:08:48 -0700 Subject: [PATCH] util: Add a _mesa_i64roundevenf() helper. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This always returns a int64_t, translating to _mesa_lroundevenf on systems where long is 64-bit, and llrintf where "long long" is needed. Fixes: 594fc0f8595 ("mesa: Replace F_TO_I() with _mesa_lroundevenf().") Reviewed-by: Marek Olšák Reviewed-by: Matt Turner --- src/util/rounding.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/util/rounding.h b/src/util/rounding.h index dfc691eaf13..fd343ab929b 100644 --- a/src/util/rounding.h +++ b/src/util/rounding.h @@ -129,4 +129,20 @@ _mesa_lroundeven(double x) #endif } +/** + * \brief Rounds \c x to the nearest integer, with ties to the even integer, + * and returns the value as an int64_t. + */ +static inline int64_t +_mesa_i64roundevenf(float x) +{ +#if LONG_MAX == INT64_MAX + return _mesa_lroundevenf(x); +#elif LONG_MAX == INT32_MAX + return llrintf(x); +#else +#error "Unsupported long size" +#endif +} + #endif -- 2.30.2