]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
math: Add math-use-builtins-fabs (BZ#29027)
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Fri, 1 Apr 2022 13:19:57 +0000 (10:19 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Mon, 23 May 2022 20:49:18 +0000 (17:49 -0300)
Both float, double, and _Float128 are assumed to be supported
(float and double already only uses builtins).  Only long double
is parametrized due GCC bug 29253 which prevents its usage on
powerpc.

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

On ia64 it also fixes the sNAN handling:

  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.

12 files changed:
sysdeps/generic/math-use-builtins-fabs.h [new file with mode: 0644]
sysdeps/generic/math-use-builtins.h
sysdeps/i386/fpu/s_fabsl.S [deleted file]
sysdeps/ia64/fpu/s_fabsl.S [deleted file]
sysdeps/ieee754/ldbl-128/s_fabsl.c
sysdeps/ieee754/ldbl-128ibm/s_fabsl.c
sysdeps/ieee754/ldbl-96/s_fabsl.c [moved from sysdeps/x86_64/fpu/s_fabsl.S with 78% similarity]
sysdeps/powerpc/fpu/math-use-builtins-fabs.h [new file with mode: 0644]
sysdeps/powerpc/powerpc32/fpu/s_fabsl.S [deleted file]
sysdeps/powerpc/powerpc64/fpu/s_fabsl.S [deleted file]
sysdeps/sparc/sparc32/fpu/s_fabsl.c [deleted file]
sysdeps/sparc/sparc64/fpu/s_fabsl.c [deleted file]

diff --git a/sysdeps/generic/math-use-builtins-fabs.h b/sysdeps/generic/math-use-builtins-fabs.h
new file mode 100644 (file)
index 0000000..531066b
--- /dev/null
@@ -0,0 +1,3 @@
+/* Generic implementations already assume builtin support for
+   float, double, and _Float128.  */
+#define USE_FABSL_BUILTIN 1
index 3ec15e59d49234288051aaf170195245cecd3c32..6bd424d9002868837793f5c4bae3e1cccd30fc3b 100644 (file)
@@ -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 (file)
index 6642ed4..0000000
+++ /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 (file)
index 07838b1..0000000
+++ /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)
index 7e08980252b379f439f7b9880dc5038aaab6a8f6..f22515fec61e7a6d1dc4ff53ea197a09784994ac 100644 (file)
@@ -24,11 +24,9 @@ static char rcsid[] = "$NetBSD: $";
 #include <math_private.h>
 #include <libm-alias-ldouble.h>
 
-_Float128 __fabsl(_Float128 x)
+_Float128
+__fabsl (_Float128 x)
 {
-       uint64_t hx;
-       GET_LDOUBLE_MSW64(hx,x);
-       SET_LDOUBLE_MSW64(x,hx&0x7fffffffffffffffLL);
-        return x;
+  return __builtin_fabsf128 (x);
 }
 libm_alias_ldouble (__fabs, fabs)
index cba7de6660e688898b5258f02b18658b4f22f066..7f26315e842c155f4c495636994ffb232ca2b3ed 100644 (file)
@@ -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);
similarity index 78%
rename from sysdeps/x86_64/fpu/s_fabsl.S
rename to sysdeps/ieee754/ldbl-96/s_fabsl.c
index cfcf01e027519b3e1895c2a1055a26c795c95175..0eceb0c9979274894b2bb27a7368e85053ce3b6f 100644 (file)
@@ -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
    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)
+{
+  return __builtin_fabsl (x);
+}
 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 (file)
index 0000000..8976d0b
--- /dev/null
@@ -0,0 +1,8 @@
+/* Generic implementations already assume builtin support for
+   float, double, and _Float128 .  */
+
+/* We can't enable it for long double due GCC Bugzilla Bug 29253
+   "expand_abs wrong default code for floating point" where it can
+   cause spurious "invalid" exceptions from comparisons with NaN in
+   the code sequence generated.  */
+#define USE_FABSL_BUILTIN 0
diff --git a/sysdeps/powerpc/powerpc32/fpu/s_fabsl.S b/sysdeps/powerpc/powerpc32/fpu/s_fabsl.S
deleted file mode 100644 (file)
index 8bdcdc8..0000000
+++ /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 (file)
index ec796a1..0000000
+++ /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/sparc32/fpu/s_fabsl.c b/sysdeps/sparc/sparc32/fpu/s_fabsl.c
deleted file mode 100644 (file)
index 411a2e1..0000000
+++ /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 (file)
index 72e1c51..0000000
+++ /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)