From patchwork Fri Jun 30 20:21:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel F T Gomes X-Patchwork-Id: 21376 X-Patchwork-Delegate: joseph@codesourcery.com Received: (qmail 99850 invoked by alias); 30 Jun 2017 20:21:31 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 99814 invoked by uid 89); 30 Jun 2017 20:21:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=6.2 X-HELO: mx0a-001b2d01.pphosted.com From: "Gabriel F. T. Gomes" To: libc-alpha@sourceware.org Subject: [PATCH] float128: Add signbit alternative for old compilers Date: Fri, 30 Jun 2017 17:21:20 -0300 X-TM-AS-MML: disable x-cbid: 17063020-1523-0000-0000-000002B0B84F X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17063020-1524-0000-0000-00002A49BBAB Message-Id: <1498854080-14778-1-git-send-email-gftg@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-06-30_13:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=4 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1706300319 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, yet it doesn't harm builds with newer compilers, because __MATH_TG selects the builtin in those cases. 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 (__signbit): 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. --- include/math.h | 1 + sysdeps/ia64/bits/floatn.h | 8 ++++++++ sysdeps/ieee754/float128/s_signbitf128.c | 31 ++++++++++++++++++++++++++++++- sysdeps/powerpc/bits/floatn.h | 8 ++++++++ sysdeps/x86/bits/floatn.h | 8 ++++++++ 5 files changed, 55 insertions(+), 1 deletion(-) diff --git a/include/math.h b/include/math.h index a069680..fdb4351 100644 --- a/include/math.h +++ b/include/math.h @@ -31,6 +31,7 @@ hidden_proto (__isnanl) hidden_proto (__finitef128) hidden_proto (__isinff128) hidden_proto (__isnanf128) +hidden_proto (__signbitf128) # endif # endif diff --git a/sysdeps/ia64/bits/floatn.h b/sysdeps/ia64/bits/floatn.h index c7b1df6..dbb6eb2 100644 --- a/sysdeps/ia64/bits/floatn.h +++ b/sysdeps/ia64/bits/floatn.h @@ -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 */ diff --git a/sysdeps/ieee754/float128/s_signbitf128.c b/sysdeps/ieee754/float128/s_signbitf128.c index 71c1ca3..a05b41c 100644 --- a/sysdeps/ieee754/float128/s_signbitf128.c +++ b/sysdeps/ieee754/float128/s_signbitf128.c @@ -1,2 +1,31 @@ +/* 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 + +int +__signbitf128 (_Float128 x) +{ + int64_t e; + + GET_FLOAT128_MSW64 (e, x); + return e < 0; +} +hidden_def (__signbitf128) diff --git a/sysdeps/powerpc/bits/floatn.h b/sysdeps/powerpc/bits/floatn.h index be57e70..0ce997c 100644 --- a/sysdeps/powerpc/bits/floatn.h +++ b/sysdeps/powerpc/bits/floatn.h @@ -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 */ diff --git a/sysdeps/x86/bits/floatn.h b/sysdeps/x86/bits/floatn.h index 23f7478..f93a9f8 100644 --- a/sysdeps/x86/bits/floatn.h +++ b/sysdeps/x86/bits/floatn.h @@ -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 */