[PATCH 1/2] math: Add builtin support for (l)lround(f)
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Fri Oct 17 16:25:57 GMT 2025
On 16/10/25 15:09, wilco.dijkstra@arm.com wrote:
> From: Wilco Dijkstra <wilco.dijkstra@arm.com>
>
> Add builtin support for (l)lround(f) via the math-use-builtins
> header mechanism.
>
> OK for commit?
LGTM, thanks.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> ---
> sysdeps/generic/math-use-builtins-llround.h | 4 ++++
> sysdeps/generic/math-use-builtins-lround.h | 4 ++++
> sysdeps/generic/math-use-builtins.h | 2 ++
> sysdeps/ieee754/dbl-64/s_llround.c | 5 +++++
> sysdeps/ieee754/dbl-64/s_lround.c | 5 +++++
> sysdeps/ieee754/flt-32/s_llroundf.c | 6 +++++-
> sysdeps/ieee754/flt-32/s_lroundf.c | 6 +++++-
> 7 files changed, 30 insertions(+), 2 deletions(-)
> create mode 100644 sysdeps/generic/math-use-builtins-llround.h
> create mode 100644 sysdeps/generic/math-use-builtins-lround.h
>
> diff --git a/sysdeps/generic/math-use-builtins-llround.h b/sysdeps/generic/math-use-builtins-llround.h
> new file mode 100644
> index 0000000000..aa0f8c705d
> --- /dev/null
> +++ b/sysdeps/generic/math-use-builtins-llround.h
> @@ -0,0 +1,4 @@
> +#define USE_LLROUND_BUILTIN 0
> +#define USE_LLROUNDF_BUILTIN 0
> +#define USE_LLROUNDL_BUILTIN 0
> +#define USE_LLROUNDF128_BUILTIN 0
> diff --git a/sysdeps/generic/math-use-builtins-lround.h b/sysdeps/generic/math-use-builtins-lround.h
> new file mode 100644
> index 0000000000..b93c86ed75
> --- /dev/null
> +++ b/sysdeps/generic/math-use-builtins-lround.h
> @@ -0,0 +1,4 @@
> +#define USE_LROUND_BUILTIN 0
> +#define USE_LROUNDF_BUILTIN 0
> +#define USE_LROUNDL_BUILTIN 0
> +#define USE_LROUNDF128_BUILTIN 0
> diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
> index b373bde439..e069b161b1 100644
> --- a/sysdeps/generic/math-use-builtins.h
> +++ b/sysdeps/generic/math-use-builtins.h
> @@ -41,5 +41,7 @@
> #include <math-use-builtins-llrint.h>
> #include <math-use-builtins-logb.h>
> #include <math-use-builtins-ffs.h>
> +#include <math-use-builtins-lround.h>
> +#include <math-use-builtins-llround.h>
>
> #endif /* MATH_USE_BUILTINS_H */
> diff --git a/sysdeps/ieee754/dbl-64/s_llround.c b/sysdeps/ieee754/dbl-64/s_llround.c
> index 0a07722c23..e86d3dcb67 100644
> --- a/sysdeps/ieee754/dbl-64/s_llround.c
> +++ b/sysdeps/ieee754/dbl-64/s_llround.c
> @@ -27,10 +27,14 @@
> #include <math_private.h>
> #include <libm-alias-double.h>
> #include <fix-fp-int-convert-overflow.h>
> +#include <math-use-builtins.h>
>
> long long int
> __llround (double x)
> {
> +#if USE_LLROUND_BUILTIN
> + return __builtin_llround (x);
> +#else
> int32_t j0;
> int64_t i0;
> long long int result;
> @@ -71,6 +75,7 @@ __llround (double x)
> }
>
> return sign * result;
> +#endif /* ! USE_LLROUND_BUILTIN */
> }
>
> libm_alias_double (__llround, llround)
> diff --git a/sysdeps/ieee754/dbl-64/s_lround.c b/sysdeps/ieee754/dbl-64/s_lround.c
> index ba98b35b7c..e92fa5ceed 100644
> --- a/sysdeps/ieee754/dbl-64/s_lround.c
> +++ b/sysdeps/ieee754/dbl-64/s_lround.c
> @@ -23,6 +23,7 @@
> #include <math_private.h>
> #include <libm-alias-double.h>
> #include <fix-fp-int-convert-overflow.h>
> +#include <math-use-builtins.h>
>
> /* For LP64, lround is an alias for llround. */
> #ifndef _LP64
> @@ -30,6 +31,9 @@
> long int
> __lround (double x)
> {
> +#if USE_LROUND_BUILTIN
> + return __builtin_lround (x);
> +#else
> int32_t j0;
> int64_t i0;
> long int result;
> @@ -90,6 +94,7 @@ __lround (double x)
> }
>
> return sign * result;
> +#endif /* ! USE_LROUND_BUILTIN */
> }
>
> libm_alias_double (__lround, lround)
> diff --git a/sysdeps/ieee754/flt-32/s_llroundf.c b/sysdeps/ieee754/flt-32/s_llroundf.c
> index e19b3072fc..bb92acbc49 100644
> --- a/sysdeps/ieee754/flt-32/s_llroundf.c
> +++ b/sysdeps/ieee754/flt-32/s_llroundf.c
> @@ -23,11 +23,14 @@
> #include <math_private.h>
> #include <libm-alias-float.h>
> #include <fix-fp-int-convert-overflow.h>
> -
> +#include <math-use-builtins.h>
>
> long long int
> __llroundf (float x)
> {
> +#if USE_LLROUNDF_BUILTIN
> + return __builtin_llroundf (x);
> +#else
> int32_t j0;
> uint32_t i;
> long long int result;
> @@ -68,6 +71,7 @@ __llroundf (float x)
> }
>
> return sign * result;
> +#endif /* ! USE_LLROUNDF_BUILTIN */
> }
>
> libm_alias_float (__llround, llround)
> diff --git a/sysdeps/ieee754/flt-32/s_lroundf.c b/sysdeps/ieee754/flt-32/s_lroundf.c
> index 117e98d6c9..f31c53136a 100644
> --- a/sysdeps/ieee754/flt-32/s_lroundf.c
> +++ b/sysdeps/ieee754/flt-32/s_lroundf.c
> @@ -23,11 +23,14 @@
> #include <math_private.h>
> #include <libm-alias-float.h>
> #include <fix-fp-int-convert-overflow.h>
> -
> +#include <math-use-builtins.h>
>
> long int
> __lroundf (float x)
> {
> +#if USE_LROUNDF_BUILTIN
> + return __builtin_lroundf (x);
> +#else
> int32_t j0;
> uint32_t i;
> long int result;
> @@ -68,6 +71,7 @@ __lroundf (float x)
> }
>
> return sign * result;
> +#endif /* ! USE_LROUNDF_BUILTIN */
> }
>
> libm_alias_float (__lround, lround)
More information about the Libc-alpha
mailing list