diff mbox series

math: Add math-use-builtins-fabs

Message ID 20220404205805.701759-1-adhemerval.zanella@linaro.org
State New
Headers show
Series math: Add math-use-builtins-fabs | expand

Commit Message

Adhemerval Zanella Netto April 4, 2022, 8:58 p.m. UTC
Both float and double are assumed to be supported (since generic
implementation uses it without a fallback), only long double and
float128 are defined.

It allows to remove i686, ia64, x86_64, powerpc, and sparc arch
specific implementation.

On ia64 it also fixes:

  math/test-float64x-fabs
  math/test-ldouble-fabs

Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc-linux-gnu,
powerpc64-linux-gnu, sparc64-linux-gnu, and ia64-linux-gnu.
---
 sysdeps/generic/math-use-builtins-fabs.h      |  4 +
 sysdeps/generic/math-use-builtins.h           |  1 +
 sysdeps/i386/fpu/s_fabsl.S                    | 10 ---
 sysdeps/ia64/fpu/s_fabsl.S                    | 82 -------------------
 sysdeps/ia64/math-use-builtins-fabs.h         |  4 +
 sysdeps/ieee754/ldbl-128/s_fabsl.c            |  5 ++
 sysdeps/ieee754/ldbl-128ibm/s_fabsl.c         |  5 ++
 .../s_fabsl.S => ieee754/ldbl-96/s_fabsl.c}   | 22 +++--
 sysdeps/powerpc/fpu/math-use-builtins-fabs.h  |  9 ++
 sysdeps/powerpc/powerpc32/fpu/s_fabsl.S       | 52 ------------
 sysdeps/powerpc/powerpc64/fpu/s_fabsl.S       | 34 --------
 sysdeps/sparc/fpu/math-use-builtins-fabs.h    |  4 +
 sysdeps/sparc/sparc32/fpu/s_fabsl.c           |  9 --
 sysdeps/sparc/sparc64/fpu/s_fabsl.c           |  7 --
 sysdeps/x86/math-use-builtins-fabs.h          |  4 +
 15 files changed, 49 insertions(+), 203 deletions(-)
 create mode 100644 sysdeps/generic/math-use-builtins-fabs.h
 delete mode 100644 sysdeps/i386/fpu/s_fabsl.S
 delete mode 100644 sysdeps/ia64/fpu/s_fabsl.S
 create mode 100644 sysdeps/ia64/math-use-builtins-fabs.h
 rename sysdeps/{x86_64/fpu/s_fabsl.S => ieee754/ldbl-96/s_fabsl.c} (72%)
 create mode 100644 sysdeps/powerpc/fpu/math-use-builtins-fabs.h
 delete mode 100644 sysdeps/powerpc/powerpc32/fpu/s_fabsl.S
 delete mode 100644 sysdeps/powerpc/powerpc64/fpu/s_fabsl.S
 create mode 100644 sysdeps/sparc/fpu/math-use-builtins-fabs.h
 delete mode 100644 sysdeps/sparc/sparc32/fpu/s_fabsl.c
 delete mode 100644 sysdeps/sparc/sparc64/fpu/s_fabsl.c
 create mode 100644 sysdeps/x86/math-use-builtins-fabs.h

Comments

Joseph Myers April 4, 2022, 9:30 p.m. UTC | #1
On Mon, 4 Apr 2022, Adhemerval Zanella via Libc-alpha wrote:

> Both float and double are assumed to be supported (since generic
> implementation uses it without a fallback), only long double and
> float128 are defined.

The only case where built-in fabs (or copysign) may not work properly is 
IBM long double in the soft-float case (see 
sysdeps/powerpc/nofpu/Makefile).  I'd expect the default to be that it 
works with an override for long double fabs in that one soft-float case.

> On ia64 it also fixes:
> 
>   math/test-float64x-fabs
>   math/test-ldouble-fabs

If this is fixing a bug that was user-visible in a release, there should 
be a corresponding report in Bugzilla.
Adhemerval Zanella Netto April 4, 2022, 10 p.m. UTC | #2
On 04/04/2022 18:30, Joseph Myers wrote:
> On Mon, 4 Apr 2022, Adhemerval Zanella via Libc-alpha wrote:
> 
>> Both float and double are assumed to be supported (since generic
>> implementation uses it without a fallback), only long double and
>> float128 are defined.
> 
> The only case where built-in fabs (or copysign) may not work properly is 
> IBM long double in the soft-float case (see 
> sysdeps/powerpc/nofpu/Makefile).  I'd expect the default to be that it 
> works with an override for long double fabs in that one soft-float case.

I am adding a way to override float128 builtin support because I plan
to support building glibc with clang, which does not support inline
__builtin_fabsf128.  I change the patch to assume _Float128 support,
but set it on this patch makes the required further changes simpler.

> 
>> On ia64 it also fixes:
>>
>>   math/test-float64x-fabs
>>   math/test-ldouble-fabs
> 
> If this is fixing a bug that was user-visible in a release, there should 
> be a corresponding report in Bugzilla.
> 

Ack.
Joseph Myers April 4, 2022, 10:41 p.m. UTC | #3
On Mon, 4 Apr 2022, Adhemerval Zanella via Libc-alpha wrote:

> to support building glibc with clang, which does not support inline
> __builtin_fabsf128.  I change the patch to assume _Float128 support,

And also not under another name (cf. how sysdeps/x86/bits/floatn.h uses 
__builtin_fabsq before GCC 7)?
Adhemerval Zanella Netto April 5, 2022, 1:55 a.m. UTC | #4
On 04/04/2022 19:41, Joseph Myers wrote:
> On Mon, 4 Apr 2022, Adhemerval Zanella via Libc-alpha wrote:
> 
>> to support building glibc with clang, which does not support inline
>> __builtin_fabsf128.  I change the patch to assume _Float128 support,
> 
> And also not under another name (cf. how sysdeps/x86/bits/floatn.h uses 
> __builtin_fabsq before GCC 7)?
> 

It does not seems to, it issues an undefined builtin error.
Adhemerval Zanella Netto April 5, 2022, 11:50 a.m. UTC | #5
On 04/04/2022 22:55, Adhemerval Zanella wrote:
> 
> 
> On 04/04/2022 19:41, Joseph Myers wrote:
>> On Mon, 4 Apr 2022, Adhemerval Zanella via Libc-alpha wrote:
>>
>>> to support building glibc with clang, which does not support inline
>>> __builtin_fabsf128.  I change the patch to assume _Float128 support,
>>
>> And also not under another name (cf. how sysdeps/x86/bits/floatn.h uses 
>> __builtin_fabsq before GCC 7)?
>>
> 
> It does not seems to, it issues an undefined builtin error.

So do you prefer I just assume long double and _Float128 abs builtin
support or the patch is good as is?
Joseph Myers April 5, 2022, 3:53 p.m. UTC | #6
On Tue, 5 Apr 2022, Adhemerval Zanella via Libc-alpha wrote:

> On 04/04/2022 22:55, Adhemerval Zanella wrote:
> > 
> > 
> > On 04/04/2022 19:41, Joseph Myers wrote:
> >> On Mon, 4 Apr 2022, Adhemerval Zanella via Libc-alpha wrote:
> >>
> >>> to support building glibc with clang, which does not support inline
> >>> __builtin_fabsf128.  I change the patch to assume _Float128 support,
> >>
> >> And also not under another name (cf. how sysdeps/x86/bits/floatn.h uses 
> >> __builtin_fabsq before GCC 7)?
> >>
> > 
> > It does not seems to, it issues an undefined builtin error.
> 
> So do you prefer I just assume long double and _Float128 abs builtin
> support or the patch is good as is?

I think there are a few issues here:


1. If something is more conveniently implemented using a GCC feature 
(supported in all GCC versions supported for building glibc), you need a 
justification for why it's appropriate to complicate the glibc code with 
conditionals for compilers not supporting that feature, versus saying that 
building with clang would require a minimum version of clang that supports 
that feature.  I wouldn't expect __builtin_fabsf128 to be a problematic 
feature to add to clang (and likewise any other _Float128 built-in 
functions needed, on platforms where glibc supports _Float128 with a 
different format from long double) - so the starting point should be to 
require a clang version with that feature, and doing otherwise needs a 
specific justification.  And *any* case of working around the absence of a 
feature needs case-by-case justification for doing so.

This is different from the case where avoiding the feature also results in 
cleaner code in glibc, not in adding any conditionals - which has 
typically been the case for changes to avoid nested functions by making 
interfaces pass relevant state more explicitly, for example.


2. Where code in installed headers is involved, conditionals *are* 
appropriate - and that includes conditionals on different clang versions, 
to support older versions before whatever feature was added to clang.  
*But* while bits/floatn.h is an installed header, the conditional 
__builtin_fabsf128 definition there is only actually relevant when 
building glibc - nothing else in the installed headers uses 
__builtin_fabsf128 - so version conditionals for clang versions too old to 
build glibc aren't needed for it.  (This is different from the 
__builtin_signbitf128 definition in bits/floatn.h where 
__builtin_signbitf128 *is* used in installed math/math.h - though in that 
case, there's already a __glibc_clang_prereq (3,3) conditional in 
math/math.h.)


3. Given a requirement for a clang version supporting __builtin_fabsf128 
to build glibc on relevant platforms, built-in fabs conditionals should 
only be needed for the case of IBM long double for soft-float powerpc; no 
other case should need to have such a conditional or to include 
math-use-builtins-fabs.h at all, and only two copies of 
math-use-builtins-fabs.h should be needed.
Adhemerval Zanella Netto April 5, 2022, 4:43 p.m. UTC | #7
On 05/04/2022 12:53, Joseph Myers wrote:
> On Tue, 5 Apr 2022, Adhemerval Zanella via Libc-alpha wrote:
> 
>> On 04/04/2022 22:55, Adhemerval Zanella wrote:
>>>
>>>
>>> On 04/04/2022 19:41, Joseph Myers wrote:
>>>> On Mon, 4 Apr 2022, Adhemerval Zanella via Libc-alpha wrote:
>>>>
>>>>> to support building glibc with clang, which does not support inline
>>>>> __builtin_fabsf128.  I change the patch to assume _Float128 support,
>>>>
>>>> And also not under another name (cf. how sysdeps/x86/bits/floatn.h uses 
>>>> __builtin_fabsq before GCC 7)?
>>>>
>>>
>>> It does not seems to, it issues an undefined builtin error.
>>
>> So do you prefer I just assume long double and _Float128 abs builtin
>> support or the patch is good as is?
> 
> I think there are a few issues here:
> 
> 
> 1. If something is more conveniently implemented using a GCC feature 
> (supported in all GCC versions supported for building glibc), you need a 
> justification for why it's appropriate to complicate the glibc code with 
> conditionals for compilers not supporting that feature, versus saying that 
> building with clang would require a minimum version of clang that supports 
> that feature.  I wouldn't expect __builtin_fabsf128 to be a problematic 
> feature to add to clang (and likewise any other _Float128 built-in 
> functions needed, on platforms where glibc supports _Float128 with a 
> different format from long double) - so the starting point should be to 
> require a clang version with that feature, and doing otherwise needs a 
> specific justification.  And *any* case of working around the absence of a 
> feature needs case-by-case justification for doing so.

The issue even main branch does not support __builtin_fabs128 without routing
it to a libcall, so requiring a minimum clang version might not make much
sense.  I might make it work for next 15 version, but since it is not yet
release I think a workaround in glibc is justifiable. 

> 
> This is different from the case where avoiding the feature also results in 
> cleaner code in glibc, not in adding any conditionals - which has 
> typically been the case for changes to avoid nested functions by making 
> interfaces pass relevant state more explicitly, for example.

The idea is indeed simplify the code, so I think it would be better to just
assume gcc-only support and add the possible required clang changes in the
patchset itself.

> 
> 
> 2. Where code in installed headers is involved, conditionals *are* 
> appropriate - and that includes conditionals on different clang versions, 
> to support older versions before whatever feature was added to clang.  
> *But* while bits/floatn.h is an installed header, the conditional 
> __builtin_fabsf128 definition there is only actually relevant when 
> building glibc - nothing else in the installed headers uses 
> __builtin_fabsf128 - so version conditionals for clang versions too old to 
> build glibc aren't needed for it.  (This is different from the 
> __builtin_signbitf128 definition in bits/floatn.h where 
> __builtin_signbitf128 *is* used in installed math/math.h - though in that 
> case, there's already a __glibc_clang_prereq (3,3) conditional in 
> math/math.h.)
> 
> 
> 3. Given a requirement for a clang version supporting __builtin_fabsf128 
> to build glibc on relevant platforms, built-in fabs conditionals should 
> only be needed for the case of IBM long double for soft-float powerpc; no 
> other case should need to have such a conditional or to include 
> math-use-builtins-fabs.h at all, and only two copies of 
> math-use-builtins-fabs.h should be needed.
>
diff mbox series

Patch

diff --git a/sysdeps/generic/math-use-builtins-fabs.h b/sysdeps/generic/math-use-builtins-fabs.h
new file mode 100644
index 0000000000..8f3da3cf21
--- /dev/null
+++ b/sysdeps/generic/math-use-builtins-fabs.h
@@ -0,0 +1,4 @@ 
+/* Generic implementation already assume builtin support for
+   float and double.  */
+#define USE_FABSL_BUILTIN 0
+#define USE_FABSF128_BUILTIN 0
diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
index 3ec15e59d4..6bd424d900 100644
--- a/sysdeps/generic/math-use-builtins.h
+++ b/sysdeps/generic/math-use-builtins.h
@@ -36,5 +36,6 @@ 
 #include <math-use-builtins-fma.h>
 #include <math-use-builtins-fmax.h>
 #include <math-use-builtins-fmin.h>
+#include <math-use-builtins-fabs.h>
 
 #endif /* MATH_USE_BUILTINS_H  */
diff --git a/sysdeps/i386/fpu/s_fabsl.S b/sysdeps/i386/fpu/s_fabsl.S
deleted file mode 100644
index 6642ed4151..0000000000
--- a/sysdeps/i386/fpu/s_fabsl.S
+++ /dev/null
@@ -1,10 +0,0 @@ 
-#include <libm-alias-ldouble.h>
-#include <sysdep.h>
-
-	.text
-ENTRY(__fabsl)
-	fldt	4(%esp)
-	fabs
-	ret
-END(__fabsl)
-libm_alias_ldouble (__fabs, fabs)
diff --git a/sysdeps/ia64/fpu/s_fabsl.S b/sysdeps/ia64/fpu/s_fabsl.S
deleted file mode 100644
index 07838b1057..0000000000
--- a/sysdeps/ia64/fpu/s_fabsl.S
+++ /dev/null
@@ -1,82 +0,0 @@ 
-.file "fabsl.s"
-
-
-// Copyright (c) 2000 - 2003, Intel Corporation
-// All rights reserved.
-//
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-//
-// * Redistributions in binary form must reproduce the above copyright
-// notice, this list of conditions and the following disclaimer in the
-// documentation and/or other materials provided with the distribution.
-//
-// * The name of Intel Corporation may not be used to endorse or promote
-// products derived from this software without specific prior written
-// permission.
-
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
-// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
-// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
-// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-// Intel Corporation is the author of this code, and requests that all
-// problem reports or change requests be submitted to it directly at
-// http://www.intel.com/software/products/opensource/libraries/num.htm.
-//
-// History
-//==============================================================
-// 02/02/00 Initial version
-// 02/07/02 Added __libm_fabsl entry point to test in case compiler inlines
-// 05/20/02 Cleaned up namespace and sf0 syntax
-// 02/10/03 Reordered header: .section, .global, .proc, .align
-//
-// API
-//==============================================================
-// long double fabsl  (long double x)
-//
-// Overview of operation
-//==============================================================
-// returns absolute value of x
-
-// floating-point registers used: 1
-// f8, input
-
-.section .text
-.global __libm_fabsl#
-
-.proc __libm_fabsl#
-__libm_fabsl:
-.endp __libm_fabsl#
-
-GLOBAL_IEEE754_ENTRY(fabsl)
-
-// set invalid or denormal flags and take fault if
-// necessary
-
-{ .mfi
-      nop.m 999
-      fcmp.eq.unc.s0 p6,p7 = f8,f1
-      nop.i 999 ;;
-}
-
-{ .mfb
-      nop.m 999
-      fmerge.s       f8 = f0,f8
-      br.ret.sptk    b0 ;;
-}
-
-GLOBAL_IEEE754_END(fabsl)
-libm_alias_ldouble_other (__fabs, fabs)
diff --git a/sysdeps/ia64/math-use-builtins-fabs.h b/sysdeps/ia64/math-use-builtins-fabs.h
new file mode 100644
index 0000000000..facf3a6425
--- /dev/null
+++ b/sysdeps/ia64/math-use-builtins-fabs.h
@@ -0,0 +1,4 @@ 
+/* Generic implementation already assume builtin support for
+   float and double.  */
+#define USE_FABSL_BUILTIN 1
+#define USE_FABSF128_BUILTIN 1
diff --git a/sysdeps/ieee754/ldbl-128/s_fabsl.c b/sysdeps/ieee754/ldbl-128/s_fabsl.c
index 7e08980252..464d62fa1b 100644
--- a/sysdeps/ieee754/ldbl-128/s_fabsl.c
+++ b/sysdeps/ieee754/ldbl-128/s_fabsl.c
@@ -23,12 +23,17 @@  static char rcsid[] = "$NetBSD: $";
 #include <math.h>
 #include <math_private.h>
 #include <libm-alias-ldouble.h>
+#include <math-use-builtins.h>
 
 _Float128 __fabsl(_Float128 x)
 {
+#if USE_FABSF128_BUILTIN
+	return __builtin_fabsf128 (x);
+#else
 	uint64_t hx;
 	GET_LDOUBLE_MSW64(hx,x);
 	SET_LDOUBLE_MSW64(x,hx&0x7fffffffffffffffLL);
         return x;
+#endif
 }
 libm_alias_ldouble (__fabs, fabs)
diff --git a/sysdeps/ieee754/ldbl-128ibm/s_fabsl.c b/sysdeps/ieee754/ldbl-128ibm/s_fabsl.c
index cba7de6660..7f26315e84 100644
--- a/sysdeps/ieee754/ldbl-128ibm/s_fabsl.c
+++ b/sysdeps/ieee754/ldbl-128ibm/s_fabsl.c
@@ -24,9 +24,13 @@  static char rcsid[] = "$NetBSD: $";
 #include <math.h>
 #include <math_private.h>
 #include <math_ldbl_opt.h>
+#include <math-use-builtins.h>
 
 long double __fabsl(long double x)
 {
+#if USE_FABSL_BUILTIN
+	return __builtin_fabsl (x);
+#else
 	uint64_t hx, lx;
 	double xhi, xlo;
 
@@ -39,5 +43,6 @@  long double __fabsl(long double x)
 	INSERT_WORDS64 (xlo, lx);
 	x = ldbl_pack (xhi, xlo);
 	return x;
+#endif
 }
 long_double_symbol (libm, __fabsl, fabsl);
diff --git a/sysdeps/x86_64/fpu/s_fabsl.S b/sysdeps/ieee754/ldbl-96/s_fabsl.c
similarity index 72%
rename from sysdeps/x86_64/fpu/s_fabsl.S
rename to sysdeps/ieee754/ldbl-96/s_fabsl.c
index cfcf01e027..c8a6a50918 100644
--- a/sysdeps/x86_64/fpu/s_fabsl.S
+++ b/sysdeps/ieee754/ldbl-96/s_fabsl.c
@@ -1,5 +1,5 @@ 
-/* Absolute value of floating point number.
-   Copyright (C) 2002-2022 Free Software Foundation, Inc.
+/* Absolute value of floating-point number.
+   Copyright (C) 2022 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
@@ -16,13 +16,17 @@ 
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#include <sysdep.h>
+#include <math.h>
 #include <libm-alias-ldouble.h>
+#include <math-use-builtins.h>
 
-       .text
-ENTRY(__fabsl)
-       fldt    8(%rsp)
-       fabs
-       ret
-END(__fabsl)
+long double
+__fabsl (long double x)
+{
+#if USE_FABSL_BUILTIN
+  return __builtin_fabsl (x);
+#else
+# error "missing fabsl implementation for lbdl-96"
+#endif
+}
 libm_alias_ldouble (__fabs, fabs)
diff --git a/sysdeps/powerpc/fpu/math-use-builtins-fabs.h b/sysdeps/powerpc/fpu/math-use-builtins-fabs.h
new file mode 100644
index 0000000000..3100a004fe
--- /dev/null
+++ b/sysdeps/powerpc/fpu/math-use-builtins-fabs.h
@@ -0,0 +1,9 @@ 
+/* Generic implementation already assume builtin support for
+   float and double.  */
+#define USE_FABSL_BUILTIN 1
+/* This is not available for P8 or BE targets.  */
+#ifdef __FLOAT128__
+# define USE_FABSF128_BUILTIN 1
+#else
+# define USE_FABSF128_BUILTIN 0
+#endif
diff --git a/sysdeps/powerpc/powerpc32/fpu/s_fabsl.S b/sysdeps/powerpc/powerpc32/fpu/s_fabsl.S
deleted file mode 100644
index 8bdcdc8cfb..0000000000
--- a/sysdeps/powerpc/powerpc32/fpu/s_fabsl.S
+++ /dev/null
@@ -1,52 +0,0 @@ 
-/* Copy a sign bit between floating-point values.
-   IBM extended format long double version.
-   Copyright (C) 2004-2022 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/>.  */
-
-#include <sysdep.h>
-#include <math_ldbl_opt.h>
-
-ENTRY(__fabsl)
-/* long double [f1,f2] fabs (long double [f1,f2] x);
-   fabs(x,y) returns a value with the magnitude of x and
-   with the sign bit of y.  */
-#ifdef _ARCH_PPCGR
-	/* fsel available.  */
-	fmr	fp0,fp1
-#else
-	/* Use integer operations to test sign of high part to avoid
-	   exceptions on sNaNs.  */
-	stwu	r1,-16(r1)
-	cfi_adjust_cfa_offset (16)
-	stfd	fp1,8(r1)
-#endif
-	fabs	fp1,fp1
-#ifdef _ARCH_PPCGR
-	fneg	fp3,fp2
-	fsel	fp2,fp0,fp2,fp3
-#else
-	lwz	r3,8+HIWORD(r1)
-	cmpwi	cr6,r3,0
-	addi	r1,r1,16
-	cfi_adjust_cfa_offset (-16)
-	bgelr	cr6
-	fneg	fp2,fp2
-#endif
-	blr
-END (__fabsl)
-
-long_double_symbol (libm, __fabsl, fabsl)
diff --git a/sysdeps/powerpc/powerpc64/fpu/s_fabsl.S b/sysdeps/powerpc/powerpc64/fpu/s_fabsl.S
deleted file mode 100644
index ec796a1cd3..0000000000
--- a/sysdeps/powerpc/powerpc64/fpu/s_fabsl.S
+++ /dev/null
@@ -1,34 +0,0 @@ 
-/* Copy a sign bit between floating-point values.
-   IBM extended format long double version.
-   Copyright (C) 2004-2022 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/>.  */
-
-#include <sysdep.h>
-#include <math_ldbl_opt.h>
-
-ENTRY_TOCLESS (__fabsl)
-/* long double [f1,f2] fabs (long double [f1,f2] x);
-   fabs(x,y) returns a value with the magnitude of x and
-   with the sign bit of y.  */
-	fmr	fp0,fp1
-	fabs	fp1,fp1
-	fneg	fp3,fp2
-	fsel	fp2,fp0,fp2,fp3
-	blr
-END (__fabsl)
-
-long_double_symbol (libm, __fabsl, fabsl)
diff --git a/sysdeps/sparc/fpu/math-use-builtins-fabs.h b/sysdeps/sparc/fpu/math-use-builtins-fabs.h
new file mode 100644
index 0000000000..702229ddd4
--- /dev/null
+++ b/sysdeps/sparc/fpu/math-use-builtins-fabs.h
@@ -0,0 +1,4 @@ 
+/* Generic implementation already assume builtin support for
+   float and double.  */
+#define USE_FABSL_BUILTIN 1
+#define USE_FABSF128_BUILTIN 0
diff --git a/sysdeps/sparc/sparc32/fpu/s_fabsl.c b/sysdeps/sparc/sparc32/fpu/s_fabsl.c
deleted file mode 100644
index 411a2e1511..0000000000
--- a/sysdeps/sparc/sparc32/fpu/s_fabsl.c
+++ /dev/null
@@ -1,9 +0,0 @@ 
-#include <math.h>
-#include <math_ldbl_opt.h>
-#include <libm-alias-ldouble.h>
-
-long double __fabsl (long double x)
-{
-  return __builtin_fabsl (x);
-}
-libm_alias_ldouble (__fabs, fabs)
diff --git a/sysdeps/sparc/sparc64/fpu/s_fabsl.c b/sysdeps/sparc/sparc64/fpu/s_fabsl.c
deleted file mode 100644
index 72e1c51340..0000000000
--- a/sysdeps/sparc/sparc64/fpu/s_fabsl.c
+++ /dev/null
@@ -1,7 +0,0 @@ 
-#include <libm-alias-ldouble.h>
-
-long double __fabsl (long double x)
-{
-  return __builtin_fabsl (x);
-}
-libm_alias_ldouble (__fabs, fabs)
diff --git a/sysdeps/x86/math-use-builtins-fabs.h b/sysdeps/x86/math-use-builtins-fabs.h
new file mode 100644
index 0000000000..facf3a6425
--- /dev/null
+++ b/sysdeps/x86/math-use-builtins-fabs.h
@@ -0,0 +1,4 @@ 
+/* Generic implementation already assume builtin support for
+   float and double.  */
+#define USE_FABSL_BUILTIN 1
+#define USE_FABSF128_BUILTIN 1