]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
float128: Add signbit alternative for old compilers
authorGabriel F. T. Gomes <gftg@linux.vnet.ibm.com>
Thu, 29 Jun 2017 18:34:05 +0000 (15:34 -0300)
committerGabriel F. T. Gomes <gftg@linux.vnet.ibm.com>
Fri, 30 Jun 2017 21:34:29 +0000 (18:34 -0300)
In math/math.h, __MATH_TG will expand signbit to __builtin_signbit*,
e.g.: __builtin_signbitf128, before GCC 6.  However, there has never
been a __builtin_signbitf128 in GCC and the type-generic builtin is
only available since GCC 6.  For older GCC, this patch defines
__builtin_signbitf128 to __signbitf128, so that the internal function
is used instead of the non-existent builtin.

This patch also changes the implementation of __signbitf128, because
it was reusing the implementation of __signbitl from ldbl-128, which
calls __builtin_signbitl.  Using the long double version of the
builtin is not correct on machines where _Float128 is ABI-distinct
from long double (i.e.: ia64, powerpc64le, x86, x86_84).  The new
implementation does not rely on builtins when being built with GCC
versions older than 6.0.

The new code does not currently affect powerpc64le builds, because
only GCC 6.2 fulfills the requirements from configure.  It might
affect powerpc64le builds if those requirements are backported to
older versions of the compiler.  The new code affects x86_64 builds,
since glibc is supposed to build correctly with older versions of GCC.

Tested for powerpc64le and x86_64.

* include/math.h (__signbitf128): Define as hidden.
* sysdeps/ieee754/float128/s_signbitf128.c (__signbitf128):
Reimplement without builtins.
* sysdeps/ia64/bits/floatn.h [!__GNUC_PREREQ (6, 0)]
(__builtin_signbitf128): Define to __signbitf128.
* sysdeps/powerpc/bits/floatn.h: Likewise.
* sysdeps/x86/bits/floatn.h: Likewise.

ChangeLog
include/math.h
sysdeps/ia64/bits/floatn.h
sysdeps/ieee754/float128/s_signbitf128.c
sysdeps/powerpc/bits/floatn.h
sysdeps/x86/bits/floatn.h

index 08ff79318eb63951c6e2e7d71653bb79c56061dc..b6fe639d561d4d310b9ee0949b623f43ee1aa311 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2017-06-30  Gabriel F. T. Gomes  <gftg@linux.vnet.ibm.com>
+
+       * include/math.h (__signbitf128): Define as hidden.
+       * sysdeps/ieee754/float128/s_signbitf128.c (__signbitf128):
+       Reimplement without builtins.
+       * sysdeps/ia64/bits/floatn.h [!__GNUC_PREREQ (6, 0)]
+       (__builtin_signbitf128): Define to __signbitf128.
+       * sysdeps/powerpc/bits/floatn.h: Likewise.
+       * sysdeps/x86/bits/floatn.h: Likewise.
+
 2017-06-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
        * sysdeps/unix/sysv/linux/arm/fcntl.c: Remove file.
index a06968023353e5168adfc2ffa1e8ec3ea16f6fae..fdb43517e11fc79712a10b0e5f1dde127a77c2e1 100644 (file)
@@ -31,6 +31,7 @@ hidden_proto (__isnanl)
 hidden_proto (__finitef128)
 hidden_proto (__isinff128)
 hidden_proto (__isnanf128)
+hidden_proto (__signbitf128)
 #  endif
 # endif
 
index c7b1df6d2cf9acf0ab4a5ca47ef07844a6d643c1..dbb6eb23253667f7635431429d917ae28cbc74f9 100644 (file)
@@ -89,6 +89,14 @@ typedef __float128 _Float128;
 #  define __builtin_nansf128(x) ((_Float128) __builtin_nans (x))
 # endif
 
+/* In math/math.h, __MATH_TG will expand signbit to __builtin_signbit*,
+   e.g.: __builtin_signbitf128, before GCC 6.  However, there has never
+   been a __builtin_signbitf128 in GCC and the type-generic builtin is
+   only available since GCC 6.  */
+# if !__GNUC_PREREQ (6, 0)
+#  define __builtin_signbitf128 __signbitf128
+# endif
+
 #endif
 
 #endif /* _BITS_FLOATN_H */
index 71c1ca3a34d870948955610adcc8a631fb0ab749..4ea010365aae584d67543d1e7794391877393f2e 100644 (file)
@@ -1,2 +1,37 @@
+/* Return nonzero value if number is negative.
+   Copyright (C) 2017 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
+   <http://www.gnu.org/licenses/>.  */
+
 #include <float128_private.h>
-#include "../ldbl-128/s_signbitl.c"
+#include <math.h>
+#include <math_private.h>
+
+/* Once GCC >= 6.0 is required for building glibc, this implementation can
+   be removed and replaced with an inclusion of ldbl-128/s_signbitl.c.  */
+int
+__signbitf128 (_Float128 x)
+{
+#if __GNUC_PREREQ (6, 0)
+  return __builtin_signbit (x);
+#else
+  int64_t e;
+
+  GET_FLOAT128_MSW64 (e, x);
+  return e < 0;
+#endif
+}
+hidden_def (__signbitf128)
index be57e7015ff6ca4ad14b43bd1302a50335827445..0ce997c68cf5ecfdf4e7743deebf903df39a1fb6 100644 (file)
@@ -87,6 +87,14 @@ typedef __float128 _Float128;
 #  define __builtin_nansf128 __builtin_nansq
 # endif
 
+/* In math/math.h, __MATH_TG will expand signbit to __builtin_signbit*,
+   e.g.: __builtin_signbitf128, before GCC 6.  However, there has never
+   been a __builtin_signbitf128 in GCC and the type-generic builtin is
+   only available since GCC 6.  */
+# if !__GNUC_PREREQ (6, 0)
+#  define __builtin_signbitf128 __signbitf128
+# endif
+
 #endif
 
 #endif /* _BITS_FLOATN_H */
index 23f74782eae7f43318a37e7bdb85efc82212fb6c..f93a9f8dbb7856700564899e381795d986be84d2 100644 (file)
@@ -91,6 +91,14 @@ typedef __float128 _Float128;
 #  define __builtin_nansf128(x) ((_Float128) __builtin_nans (x))
 # endif
 
+/* In math/math.h, __MATH_TG will expand signbit to __builtin_signbit*,
+   e.g.: __builtin_signbitf128, before GCC 6.  However, there has never
+   been a __builtin_signbitf128 in GCC and the type-generic builtin is
+   only available since GCC 6.  */
+# if !__GNUC_PREREQ (6, 0)
+#  define __builtin_signbitf128 __signbitf128
+# endif
+
 #endif
 
 #endif /* _BITS_FLOATN_H */