From ae627867479f4a86108da1d8c8773b1ecfb5e7d3 Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Tue, 13 Jan 2026 11:19:29 -0300 Subject: [PATCH] Revert "x86: Do not use __builtin_fpclassify for _Float64x/long double" This reverts commit 50112103993b042f52fb6afb0e4eee24fe4cb9af. It breaks libstdc++ and other languages bootstrap. Reviewed-by: Carlos O'Donell --- bits/fp-builtin-denormal.h | 28 -------- math/Makefile | 1 - math/math.h | 89 +------------------------ sysdeps/x86/bits/fp-builtin-denormal.h | 25 ------- sysdeps/x86/fpu/Makefile | 1 - sysdeps/x86/fpu/test-builtin-denormal.c | 53 --------------- 6 files changed, 2 insertions(+), 195 deletions(-) delete mode 100644 bits/fp-builtin-denormal.h delete mode 100644 sysdeps/x86/bits/fp-builtin-denormal.h delete mode 100644 sysdeps/x86/fpu/test-builtin-denormal.c diff --git a/bits/fp-builtin-denormal.h b/bits/fp-builtin-denormal.h deleted file mode 100644 index 457ab0c97a..0000000000 --- a/bits/fp-builtin-denormal.h +++ /dev/null @@ -1,28 +0,0 @@ -/* Denormal number definitions. - Copyright (C) 2025-2026 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 - . */ - -#ifndef _MATH_H -# error "Never use directly; include instead." -#endif - -/* __FP_BUILTIN_FPCLASSIFY_DENORMAL is defined to 1 if compiler supports - handling pseudo-denormal numbers with fpclassify builtin. Pseudo-denormal - is a non-standard denormalized floating-point number only supported by - 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 diff --git a/math/Makefile b/math/Makefile index 69f80e143f..b546626f15 100644 --- a/math/Makefile +++ b/math/Makefile @@ -28,7 +28,6 @@ headers := \ bits/floatn-common.h \ bits/floatn.h \ bits/flt-eval-method.h \ - bits/fp-builtin-denormal.h \ bits/fp-fast.h \ bits/fp-logb.h \ bits/iscanonical.h \ diff --git a/math/math.h b/math/math.h index 77dfcdc36b..75830d7696 100644 --- a/math/math.h +++ b/math/math.h @@ -1064,86 +1064,6 @@ extern int signgam; : FUNC ## l ARGS) #endif - -/* Depending on the type of TG_ARG and extra DEFINE to check, either call the - BUILTIN with ARGS_B or an appropriately suffixed version of FUNC with - arguments (including parentheses) ARGS_B. The function call is used for - long double and/or _Float64x is the builtin can not be safely used on all - arguments (defined by DEFINE). */ - -#include - -#ifdef __NO_LONG_DOUBLE_MATH -# define __MATH_TG_BUILTIN_CLASSIFY(TG_ARG, BUILTIN, ARGS_B, FUNC, ARGS_F, \ - DEFINE) \ - BUILTIN ARGS_B -#elif __HAVE_DISTINCT_FLOAT128 -# if __HAVE_GENERIC_SELECTION -# if __HAVE_FLOATN_NOT_TYPEDEF && __HAVE_FLOAT32 -# define __MATH_TG_BUILTIN_CLASSIFY_F32(BUILTIN, ARGS_B, FUNC, ARGS_F, \ - DEFINE) \ - _Float32: BUILTIN ARGS_B, -# else -# define __MATH_TG_BUILTIN_CLASSIFY_F32(BUILTIN, ARGS_B, FUNC, ARGS_F, \ - DEFINE) -# endif -# define __MATH_TG_BUILTIN_CLASSIFY_LDOUBLE(BUILTIN, ARGS_B, FUNC, ARGS_F, \ - DEFINE) \ - long double: DEFINE ? BUILTIN ARGS_B : __ ## FUNC ## l ARGS_F, -# if __HAVE_FLOATN_NOT_TYPEDEF && __HAVE_FLOAT64X -# if __HAVE_FLOAT64X_LONG_DOUBLE -# define __MATH_TG_BUILTIN_CLASSIFY_F64X(BUILTIN, ARGS_B, FUNC, ARGS_F, \ - DEFINE) \ - _Float64x: DEFINE ? BUILTIN ARGS_B : __ ## FUNC ## l ARGS_F, -# else -# define __MATH_TG_BUILTIN_CLASSIFY_F64X(BUILTIN, ARGS_B, FUNC, ARGS_F, \ - DEFINE) \ - _Float64x: DEFINE ? BUILTIN ARGS_B : __ ## FUNC ## f128 ARGS_F, -# endif -# else -# define __MATH_TG_BUILTIN_CLASSIFY_F64X(BUILTIN, ARGS_B, FUNC, ARGS_F, \ - DEFINE) -# endif -# define __MATH_TG_BUILTIN_CLASSIFY_F128(BUILTIN, ARGS_B, FUNC, ARGS_F, \ - DEFINE) \ - _Float128: BUILTIN ARGS_B -# define __MATH_TG_BUILTIN_CLASSIFY(TG_ARG, BUILTIN, ARGS_B, FUNC, ARGS_F, \ - DEFINE) \ - _Generic ((TG_ARG), \ - float: BUILTIN ARGS_B, \ - __MATH_TG_BUILTIN_CLASSIFY_F32 (BUILTIN, ARGS_B, FUNC, ARGS_F, \ - DEFINE) \ - default: BUILTIN ARGS_B, \ - __MATH_TG_BUILTIN_CLASSIFY_LDOUBLE (BUILTIN, ARGS_B, FUNC, \ - ARGS_F, DEFINE) \ - __MATH_TG_BUILTIN_CLASSIFY_F64X (BUILTIN, ARGS_B, FUNC, ARGS_F,\ - DEFINE) \ - __MATH_TG_BUILTIN_CLASSIFY_F128 (BUILTIN, ARGS_B, FUNC, ARGS_F,\ - DEFINE)) -# else -# define __MATH_TG_BUILTIN_CLASSIFY(TG_ARG, BUILTIN, ARGS_B, FUNC, ARGS_F, \ - DEFINE) \ - __builtin_choose_expr \ - (__builtin_types_compatible_p (__typeof (TG_ARG), float), \ - __builtin ## BUILTIN ARGS_B, \ - __builtin_choose_expr \ - (__builtin_types_compatible_p (__typeof (TG_ARG), double), \ - __builtin ## BUILTIN ARGS_B, \ - __builtin_choose_expr \ - (__builtin_types_compatible_p (__typeof (TG_ARG), long double), \ - DEFINE ? BUILTIN ARGS_B : __ ## FUNC ## l ARGS_F, \ - BUILTIN ARGS_B))) -# endif -#else -# define __MATH_TG_BUILTIN_CLASSIFY(TG_ARG, BUILTIN, ARGS_B, FUNC, ARGS_F, \ - DEFINE) \ - (sizeof (TG_ARG) == sizeof (float) \ - ? BUILTIN ARGS_B \ - : sizeof (TG_ARG) == sizeof (double) \ - ? BUILTIN ARGS_B \ - : DEFINE ? BUILTIN ARGS_B : __ ## FUNC ## l ARGS_F) -#endif - /* ISO C99 defines some generic macros which work on any data type. */ #ifdef __USE_ISOC99 @@ -1181,13 +1101,8 @@ enum with -Os. No further use of this definition of fpclassify is expected in C++ mode, since libstdc++ provides its own version of fpclassify in cmath (which undefines fpclassify). */ -# define fpclassify(x) \ - __MATH_TG_BUILTIN_CLASSIFY ((x), \ - __builtin_fpclassify, (FP_NAN, FP_INFINITE, \ - FP_NORMAL, FP_SUBNORMAL, \ - FP_ZERO, x), \ - fpclassify, (x), \ - __FP_BUILTIN_FPCLASSIFY_DENORMAL) +# define fpclassify(x) __builtin_fpclassify (FP_NAN, FP_INFINITE, \ + FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x) # else # define fpclassify(x) __MATH_TG ((x), __fpclassify, (x)) # endif diff --git a/sysdeps/x86/bits/fp-builtin-denormal.h b/sysdeps/x86/bits/fp-builtin-denormal.h deleted file mode 100644 index 33549c876a..0000000000 --- a/sysdeps/x86/bits/fp-builtin-denormal.h +++ /dev/null @@ -1,25 +0,0 @@ -/* Define __FP_BUILTIN_DENORMAL. - Copyright (C) 2025-2026 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 - . */ - -#ifndef _MATH_H -# error "Never use directly; include instead." -#endif - -/* Neither GCC (bug 123161) nor clang (issue 172533) handles pseudo-normal - numbers correctly with fpclassify builtin. */ -#define __FP_BUILTIN_FPCLASSIFY_DENORMAL 0 diff --git a/sysdeps/x86/fpu/Makefile b/sysdeps/x86/fpu/Makefile index 8566d3c80f..91b2444f3a 100644 --- a/sysdeps/x86/fpu/Makefile +++ b/sysdeps/x86/fpu/Makefile @@ -4,7 +4,6 @@ CPPFLAGS += -I../soft-fp libm-support += powl_helper tests += \ - test-builtin-denormal \ test-fenv-clear-sse \ test-fenv-sse \ test-fenv-sse-2 \ diff --git a/sysdeps/x86/fpu/test-builtin-denormal.c b/sysdeps/x86/fpu/test-builtin-denormal.c deleted file mode 100644 index 6584ec339f..0000000000 --- a/sysdeps/x86/fpu/test-builtin-denormal.c +++ /dev/null @@ -1,53 +0,0 @@ -/* Ccheck if math.h optimizations to call compiler builtin - does not trigger FE_INVALID on x86 denormal numbers. - Copyright (C) 2025-2026 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 - . */ - -#include -#include -#include -#include -#include - -#define pseudo_inf { .parts = { 0x00000000, 0x00000000, 0x7fff }} -#define pseudo_zero { .parts = { 0x00000000, 0x00000000, 0x0100 }} -#define pseudo_qnan { .parts = { 0x00000001, 0x00000000, 0x7fff }} -#define pseudo_snan { .parts = { 0x00000001, 0x40000000, 0x7fff }} -#define pseudo_unnormal { .parts = { 0x00000001, 0x40000000, 0x0100 }} - -static const ieee_long_double_shape_type inputs[] = { - pseudo_inf, - pseudo_zero, - pseudo_qnan, - pseudo_snan, - pseudo_unnormal -}; - -static int -do_test (void) -{ - for (int i = 0; i < array_length (inputs); i++) - { - TEST_COMPARE (feclearexcept (FE_INVALID), 0); - TEST_COMPARE (fpclassify (inputs[i].value), FP_NAN); - TEST_COMPARE (fetestexcept (FE_INVALID), 0); - } - - return 0; -} - -#include