[PATCH 3/8] x86: Do not use __builtin_isinf_sign for _Float64x/long double

H.J. Lu hjl.tools@gmail.com
Thu Dec 18 23:39:46 GMT 2025


On Thu, Dec 18, 2025 at 8:39 PM Adhemerval Zanella Netto
<adhemerval.zanella@linaro.org> wrote:
>
>
>
> On 17/12/25 20:53, H.J. Lu wrote:
> > On Thu, Dec 18, 2025 at 1:56 AM Adhemerval Zanella
> > <adhemerval.zanella@linaro.org> wrote:
> >>
> >> Neither gcc [1] nor clang [2] handles pseudo-normal numbers correctly
> >> with the __builtin_isinf_sign, so disable its usage for _Float64x and
> >> long double types.
> >>
> >> This only affects x86, so add a new define __FP_BUILTIN_ISINF_SIGN_DENORMAL
> >> to gate long double and related types to the libc function instead.
> >>
> >> It fixes the regression on test-ldouble-isinf when built with clang:
> >
> > Why don't they fail with GCC?
>
> Similar to fpclassify, glibc builds the isinf tests with -fsignaling-nans.
> With gcc this defines __SUPPORT_SNAN__, which will always calls the glibc
> symbol.  The clang does not support the options, nor define __SUPPORT_SNAN__;
> and then will always use the builtin.

Please add some tests without -fsignaling-nans.

> >
> >> Failure: isinf (pseudo_zero): Exception "Invalid operation" set
> >> Failure: isinf (pseudo_inf): Exception "Invalid operation" set
> >> Failure: isinf (pseudo_qnan): Exception "Invalid operation" set
> >> Failure: isinf (pseudo_snan): Exception "Invalid operation" set
> >> Failure: isinf (pseudo_unnormal): Exception "Invalid operation" set
> >> Failure: isinf_downward (pseudo_zero): Exception "Invalid operation" set
> >> Failure: isinf_downward (pseudo_inf): Exception "Invalid operation" set
> >> Failure: isinf_downward (pseudo_qnan): Exception "Invalid operation" set
> >> Failure: isinf_downward (pseudo_snan): Exception "Invalid operation" set
> >> Failure: isinf_downward (pseudo_unnormal): Exception "Invalid operation" set
> >> Failure: isinf_towardzero (pseudo_zero): Exception "Invalid operation" set
> >> Failure: isinf_towardzero (pseudo_inf): Exception "Invalid operation" set
> >> Failure: isinf_towardzero (pseudo_qnan): Exception "Invalid operation" set
> >> Failure: isinf_towardzero (pseudo_snan): Exception "Invalid operation" set
> >> Failure: isinf_towardzero (pseudo_unnormal): Exception "Invalid operation" set
> >> Failure: isinf_upward (pseudo_zero): Exception "Invalid operation" set
> >> Failure: isinf_upward (pseudo_inf): Exception "Invalid operation" set
> >> Failure: isinf_upward (pseudo_qnan): Exception "Invalid operation" set
> >> Failure: isinf_upward (pseudo_snan): Exception "Invalid operation" set
> >> Failure: isinf_upward (pseudo_unnormal): Exception "Invalid operation" set
> >>
> >> Checked on x86_64-linux-gnu with gcc-15 and clang-18.
> >>
> >> [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123173
> >> [2] https://github.com/llvm/llvm-project/issues/172651
> >> ---
> >>  bits/fp-builtin-denormal.h             | 4 ++++
> >>  math/math.h                            | 5 ++++-
> >>  sysdeps/x86/bits/fp-builtin-denormal.h | 4 ++++
> >>  3 files changed, 12 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/bits/fp-builtin-denormal.h b/bits/fp-builtin-denormal.h
> >> index 77b7184975..5748eb86f0 100644
> >> --- a/bits/fp-builtin-denormal.h
> >> +++ b/bits/fp-builtin-denormal.h
> >> @@ -26,3 +26,7 @@
> >>      Intel double extended-precision (long double).  By default assume 1 to
> >>      enable the usage of compiler builtin on math.h.  */
> >>  #define __FP_BUILTIN_FPCLASSIFY_DENORMAL 1
> >> +
> >> +/* __FP_BUILTIN_ISINF_SIGN_DENORMAL is defined to 1 if compiler supports
> >> +   handling pseudo-dernormal numbers with isinf_sign builtin.  */
> >> +#define __FP_BUILTIN_ISINF_SIGN_DENORMAL 1
> >> diff --git a/math/math.h b/math/math.h
> >> index cbec2f406a..96b64379f7 100644
> >> --- a/math/math.h
> >> +++ b/math/math.h
> >> @@ -1249,7 +1249,10 @@ enum
> >>       ? __isinff128 (x) : __builtin_isinf_sign (x))
> >>  # elif (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \
> >>         || __glibc_clang_prereq (3,7)
> >> -#  define isinf(x) __builtin_isinf_sign (x)
> >> +#  define isinf(x) __MATH_TG_BUILTIN_CLASSIFY ((x),                          \
> >> +                                              __builtin_isinf_sign, (x),     \
> >> +                                              isinf, (x),                    \
> >> +                                              __FP_BUILTIN_ISINF_SIGN_DENORMAL)
> >>  # else
> >>  #  define isinf(x) __MATH_TG ((x), __isinf, (x))
> >>  # endif
> >> diff --git a/sysdeps/x86/bits/fp-builtin-denormal.h b/sysdeps/x86/bits/fp-builtin-denormal.h
> >> index bfb8f54237..2f9a5c7b66 100644
> >> --- a/sysdeps/x86/bits/fp-builtin-denormal.h
> >> +++ b/sysdeps/x86/bits/fp-builtin-denormal.h
> >> @@ -23,3 +23,7 @@
> >>  /* Neither GCC (bug 123161) nor clang (issue 172533) handles pseudo-normal
> >>     numbers correctly with fpclassify builtin.  */
> >>  #define __FP_BUILTIN_FPCLASSIFY_DENORMAL 0
> >> +
> >> +/* Neither GCC (bug 123173) nor clang (issue 172651) handles pseudo-normal
> >> +   numbers correctly with isinf_sign builtin.  */
> >> +#define __FP_BUILTIN_ISINF_SIGN_DENORMAL 0
> >> --
> >> 2.43.0
> >>
> >
> >
>


-- 
H.J.


More information about the Libc-alpha mailing list