From 8466ee1cb7c2041d8471dad0aa53af35ab599012 Mon Sep 17 00:00:00 2001 From: "Gabriel F. T. Gomes" Date: Thu, 29 Jun 2017 15:34:05 -0300 Subject: float128: Add signbit alternative for old compilers 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. --- sysdeps/ieee754/float128/s_signbitf128.c | 37 +++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'sysdeps/ieee754') diff --git a/sysdeps/ieee754/float128/s_signbitf128.c b/sysdeps/ieee754/float128/s_signbitf128.c index 71c1ca3a34..4ea010365a 100644 --- a/sysdeps/ieee754/float128/s_signbitf128.c +++ b/sysdeps/ieee754/float128/s_signbitf128.c @@ -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 + . */ + #include -#include "../ldbl-128/s_signbitl.c" +#include +#include + +/* 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) -- cgit 1.4.1