[PATCH] alpha: Fix missing inexact-flag raising for lround/lrint

Carlos O'Donell carlos@redhat.com
Tue Sep 9 11:44:08 GMT 2025


On 9/6/25 6:23 PM, Adhemerval Zanella wrote:
> The l*[rint|round]f implements uses alpha 'cvtst/s', 'addt/suc',
> adn 'cvttq/svd' which are not not fully IEEE compliant w.r.t
> inexact-flag raising..  Use the software fallback implementation
> instead.
> 
> Checked on alpha-linux-gnu.
> 
> Tested-by: Michael Cree <mcree@orcon.net.nz>

LGTM.

I agree that at this point we should simplify support for architectures
like Alpha and make them work as expected for the ecosystem of software
packages. Maintaining custom code that is not quite conforming leads to
all kinds of odd behaviours.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>

> ---
>   sysdeps/alpha/Makefile                        |  6 ++-
>   ..._lrint.c => fix-fp-int-convert-overflow.h} | 32 ++++++---------
>   sysdeps/alpha/fpu/s_llrint.c                  |  1 -
>   sysdeps/alpha/fpu/s_llrintf.c                 |  1 -
>   sysdeps/alpha/fpu/s_llround.c                 |  1 -
>   sysdeps/alpha/fpu/s_llroundf.c                |  1 -
>   sysdeps/alpha/fpu/s_lrintf.c                  | 39 -------------------
>   sysdeps/alpha/fpu/s_lround.c                  | 38 ------------------
>   sysdeps/alpha/fpu/s_lroundf.c                 | 38 ------------------
>   9 files changed, 17 insertions(+), 140 deletions(-)
>   rename sysdeps/alpha/{fpu/s_lrint.c => fix-fp-int-convert-overflow.h} (55%)
>   delete mode 100644 sysdeps/alpha/fpu/s_llrint.c
>   delete mode 100644 sysdeps/alpha/fpu/s_llrintf.c
>   delete mode 100644 sysdeps/alpha/fpu/s_llround.c
>   delete mode 100644 sysdeps/alpha/fpu/s_llroundf.c
>   delete mode 100644 sysdeps/alpha/fpu/s_lrintf.c
>   delete mode 100644 sysdeps/alpha/fpu/s_lround.c
>   delete mode 100644 sysdeps/alpha/fpu/s_lroundf.c
> 
> diff --git a/sysdeps/alpha/Makefile b/sysdeps/alpha/Makefile
> index 5e143b335b..39dea0d72c 100644
> --- a/sysdeps/alpha/Makefile
> +++ b/sysdeps/alpha/Makefile
> @@ -38,9 +38,13 @@ CFLAGS-rtld.c = -mbuild-constants
>   endif
>   
>   ifeq ($(subdir),math)
> -# The fma routines rely on inexact being raised for correct results.
> +# The following routines rely on inexact being raised for correct results.

OK.

>   CFLAGS-s_fma.c = -mieee-with-inexact
>   CFLAGS-s_fmaf.c = -mieee-with-inexact
> +CFLAGS-s_llrintf.c += -mieee-with-inexact
> +CFLAGS-s_llrint.c += -mieee-with-inexact
> +CFLAGS-s_lrintf.c += -mieee-with-inexact
> +CFLAGS-s_lrint.c += -mieee-with-inexact

OK. Correct, round to nearest integer need inexact to correctly implement the glibc
expectations. In truth we might be able to get rid of those expectations, but it's
easier to just specify them here for Alpha (which doesn't support inexact unless
asked).

>   # This test tries to check for inexact being raised by arithmetic.
>   CFLAGS-test-misc.c += -mieee-with-inexact
>   # Avoid "conflicting types for built-in function" warnings
> diff --git a/sysdeps/alpha/fpu/s_lrint.c b/sysdeps/alpha/fix-fp-int-convert-overflow.h
> similarity index 55%
> rename from sysdeps/alpha/fpu/s_lrint.c
> rename to sysdeps/alpha/fix-fp-int-convert-overflow.h
> index 998918c839..a14a3d962b 100644
> --- a/sysdeps/alpha/fpu/s_lrint.c
> +++ b/sysdeps/alpha/fix-fp-int-convert-overflow.h
> @@ -1,4 +1,5 @@
> -/* Copyright (C) 2007-2025 Free Software Foundation, Inc.
> +/* Fix for conversion of floating point to integer overflow.  Alpha version.
> +   Copyright (C) 2025 Free Software Foundation, Inc.
>      This file is part of the GNU C Library.
>   
>      The GNU C Library is free software; you can redistribute it and/or
> @@ -12,27 +13,18 @@
>      Lesser General Public License for more details.
>   
>      You should have received a copy of the GNU Lesser General Public
> -   License along with the GNU C Library.  If not, see
> +   License along with the GNU C Library; if not, see
>      <https://www.gnu.org/licenses/>.  */
>   
> -#define __llrint	not___llrint
> -#define llrint		not_llrint
> -#include <math.h>
> -#include <math_ldbl_opt.h>
> -#include <libm-alias-double.h>
> -#undef __llrint
> -#undef llrint
> +#ifndef FIX_FP_INT_CONVERT_OVERFLOW_H
> +#define FIX_FP_INT_CONVERT_OVERFLOW_H	1
>   
> -long int
> -__lrint (double x)
> -{
> -  long ret;
> +#define FIX_FLT_LLONG_CONVERT_OVERFLOW 1
> +#define FIX_DBL_LLONG_CONVERT_OVERFLOW 1
> +#define FIX_LDBL_LLONG_CONVERT_OVERFLOW 1
>   
> -  __asm ("cvttq/svd %1,%0" : "=&f"(ret) : "f"(x));
> +#define FIX_FLT_LONG_CONVERT_OVERFLOW 1
> +#define FIX_DBL_LONG_CONVERT_OVERFLOW 1
> +#define FIX_LDBL_LONG_CONVERT_OVERFLOW 1
>   
> -  return ret;
> -}
> -
> -strong_alias (__lrint, __llrint)
> -libm_alias_double (__lrint, lrint)
> -libm_alias_double (__llrint, llrint)
> +#endif /* fix-fp-int-convert-overflow.h */
> diff --git a/sysdeps/alpha/fpu/s_llrint.c b/sysdeps/alpha/fpu/s_llrint.c
> deleted file mode 100644
> index 5db97be037..0000000000
> --- a/sysdeps/alpha/fpu/s_llrint.c
> +++ /dev/null
> @@ -1 +0,0 @@
> -/* In s_lrint.c */
> diff --git a/sysdeps/alpha/fpu/s_llrintf.c b/sysdeps/alpha/fpu/s_llrintf.c
> deleted file mode 100644
> index 18f2885ef7..0000000000
> --- a/sysdeps/alpha/fpu/s_llrintf.c
> +++ /dev/null
> @@ -1 +0,0 @@
> -/* In s_lrintf.c */
> diff --git a/sysdeps/alpha/fpu/s_llround.c b/sysdeps/alpha/fpu/s_llround.c
> deleted file mode 100644
> index b212fbd8e5..0000000000
> --- a/sysdeps/alpha/fpu/s_llround.c
> +++ /dev/null
> @@ -1 +0,0 @@
> -/* In s_lround.c.  */
> diff --git a/sysdeps/alpha/fpu/s_llroundf.c b/sysdeps/alpha/fpu/s_llroundf.c
> deleted file mode 100644
> index 73bdf3103f..0000000000
> --- a/sysdeps/alpha/fpu/s_llroundf.c
> +++ /dev/null
> @@ -1 +0,0 @@
> -/* In s_lroundf.c.  */
> diff --git a/sysdeps/alpha/fpu/s_lrintf.c b/sysdeps/alpha/fpu/s_lrintf.c
> deleted file mode 100644
> index 47894c9952..0000000000
> --- a/sysdeps/alpha/fpu/s_lrintf.c
> +++ /dev/null
> @@ -1,39 +0,0 @@
> -/* Copyright (C) 2007-2025 Free Software Foundation, Inc.
> -   This file is part of the GNU C Library.
> -
> -   The GNU C Library is free software; you can redistribute it and/or
> -   modify it under the terms of the GNU Lesser General Public
> -   License as published by the Free Software Foundation; either
> -   version 2.1 of the License, or (at your option) any later version.
> -
> -   The GNU C Library is distributed in the hope that it will be useful,
> -   but WITHOUT ANY WARRANTY; without even the implied warranty of
> -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> -   Lesser General Public License for more details.
> -
> -   You should have received a copy of the GNU Lesser General Public
> -   License along with the GNU C Library.  If not, see
> -   <https://www.gnu.org/licenses/>.  */
> -
> -#define __llrintf	not___llrintf
> -#define llrintf		not_llrintf
> -#include <math.h>
> -#include <libm-alias-float.h>
> -#undef __llrintf
> -#undef llrintf
> -
> -long int
> -__lrintf (float x)
> -{
> -  double tmp;
> -  long ret;
> -
> -  __asm ("cvtst/s %2,%1\n\tcvttq/svd %1,%0"
> -	 : "=&f"(ret), "=&f"(tmp) : "f"(x));
> -
> -  return ret;
> -}
> -
> -strong_alias (__lrintf, __llrintf)
> -libm_alias_float (__lrint, lrint)
> -libm_alias_float (__llrint, llrint)
> diff --git a/sysdeps/alpha/fpu/s_lround.c b/sysdeps/alpha/fpu/s_lround.c
> deleted file mode 100644
> index 25a5a5a2fc..0000000000
> --- a/sysdeps/alpha/fpu/s_lround.c
> +++ /dev/null
> @@ -1,38 +0,0 @@
> -/* Copyright (C) 2007-2025 Free Software Foundation, Inc.
> -   This file is part of the GNU C Library.
> -
> -   The GNU C Library is free software; you can redistribute it and/or
> -   modify it under the terms of the GNU Lesser General Public
> -   License as published by the Free Software Foundation; either
> -   version 2.1 of the License, or (at your option) any later version.
> -
> -   The GNU C Library is distributed in the hope that it will be useful,
> -   but WITHOUT ANY WARRANTY; without even the implied warranty of
> -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> -   Lesser General Public License for more details.
> -
> -   You should have received a copy of the GNU Lesser General Public
> -   License along with the GNU C Library.  If not, see
> -   <https://www.gnu.org/licenses/>.  */
> -
> -#define __llround	not___llround
> -#define llround		not_llround
> -#include <math.h>
> -#include <math_ldbl_opt.h>
> -#include <libm-alias-double.h>
> -#undef __llround
> -#undef llround
> -
> -long int
> -__lround (double x)
> -{
> -  double adj, y;
> -
> -  adj = copysign (0.5, x);
> -  asm("addt/suc %1,%2,%0" : "=&f"(y) : "f"(x), "f"(adj));
> -  return y;
> -}
> -
> -strong_alias (__lround, __llround)
> -libm_alias_double (__lround, lround)
> -libm_alias_double (__llround, llround)
> diff --git a/sysdeps/alpha/fpu/s_lroundf.c b/sysdeps/alpha/fpu/s_lroundf.c
> deleted file mode 100644
> index 300cd4613b..0000000000
> --- a/sysdeps/alpha/fpu/s_lroundf.c
> +++ /dev/null
> @@ -1,38 +0,0 @@
> -/* Copyright (C) 2007-2025 Free Software Foundation, Inc.
> -   This file is part of the GNU C Library.
> -
> -   The GNU C Library is free software; you can redistribute it and/or
> -   modify it under the terms of the GNU Lesser General Public
> -   License as published by the Free Software Foundation; either
> -   version 2.1 of the License, or (at your option) any later version.
> -
> -   The GNU C Library is distributed in the hope that it will be useful,
> -   but WITHOUT ANY WARRANTY; without even the implied warranty of
> -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> -   Lesser General Public License for more details.
> -
> -   You should have received a copy of the GNU Lesser General Public
> -   License along with the GNU C Library.  If not, see
> -   <https://www.gnu.org/licenses/>.  */
> -
> -#define __llroundf	not___llroundf
> -#define llroundf	not_llroundf
> -#include <math.h>
> -#include <libm-alias-float.h>
> -#undef __llroundf
> -#undef llroundf
> -
> -
> -long int
> -__lroundf (float x)
> -{
> -  float adj, y;
> -
> -  adj = copysignf (0.5f, x);
> -  asm("adds/suc %1,%2,%0" : "=&f"(y) : "f"(x), "f"(adj));
> -  return y;
> -}
> -
> -strong_alias (__lroundf, __llroundf)
> -libm_alias_float (__lround, lround)
> -libm_alias_float (__llround, llround)


-- 
Cheers,
Carlos.



More information about the Libc-alpha mailing list