Message ID | 20210301175140.29109-1-rzinsly@linux.ibm.com |
---|---|
State | Superseded |
Headers |
Return-Path: <libc-alpha-bounces@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B2C36384800F; Mon, 1 Mar 2021 17:51:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B2C36384800F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1614621108; bh=UCuXRDw5lrs04WCkPFoJQJWEZYcN1T5NBWHqgydHH+0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=rn/qoFMeLXvn1f4YL5Pr3JuEoSf+vbppkkGv/6rNlALgV3dAqAHwZS3swpAAd1HY0 fIW5qx3eRE3BVXMmsDQk3nVqyABxWh1pF+/VRBIs+jmnRqAXrWWGwUBUGXywEeoQx9 GVZw7UN750pHIctjeqcSjSbrZLgfOVI+jS9OWdB8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 4D800386185F for <libc-alpha@sourceware.org>; Mon, 1 Mar 2021 17:51:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4D800386185F Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 121HY8mZ090329 for <libc-alpha@sourceware.org>; Mon, 1 Mar 2021 12:51:46 -0500 Received: from ppma01wdc.us.ibm.com (fd.55.37a9.ip4.static.sl-reverse.com [169.55.85.253]) by mx0b-001b2d01.pphosted.com with ESMTP id 370td0yp14-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for <libc-alpha@sourceware.org>; Mon, 01 Mar 2021 12:51:45 -0500 Received: from pps.filterd (ppma01wdc.us.ibm.com [127.0.0.1]) by ppma01wdc.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 121HnI1e013492 for <libc-alpha@sourceware.org>; Mon, 1 Mar 2021 17:51:45 GMT Received: from b01cxnp23032.gho.pok.ibm.com (b01cxnp23032.gho.pok.ibm.com [9.57.198.27]) by ppma01wdc.us.ibm.com with ESMTP id 36ydq8rvqt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for <libc-alpha@sourceware.org>; Mon, 01 Mar 2021 17:51:45 +0000 Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 121HpiqI28770724 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 1 Mar 2021 17:51:44 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D7E19112062; Mon, 1 Mar 2021 17:51:44 +0000 (GMT) Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3D6C6112061; Mon, 1 Mar 2021 17:51:44 +0000 (GMT) Received: from localhost (unknown [9.160.75.103]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTP; Mon, 1 Mar 2021 17:51:43 +0000 (GMT) To: libc-alpha@sourceware.org Subject: [PATCH v2 1/3] powerpc: Add optimized ilogb* for POWER9 Date: Mon, 1 Mar 2021 14:51:38 -0300 Message-Id: <20210301175140.29109-1-rzinsly@linux.ibm.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.369, 18.0.761 definitions=2021-03-01_11:2021-03-01, 2021-03-01 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 clxscore=1015 adultscore=0 suspectscore=0 priorityscore=1501 phishscore=0 malwarescore=0 mlxlogscore=910 impostorscore=0 bulkscore=0 mlxscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103010140 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list <libc-alpha.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=subscribe> From: Raphael Moreira Zinsly via Libc-alpha <libc-alpha@sourceware.org> Reply-To: Raphael Moreira Zinsly <rzinsly@linux.ibm.com> Cc: murphyp@linux.ibm.com, tuliom@linux.ibm.com, Raphael Moreira Zinsly <rzinsly@linux.ibm.com> Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" <libc-alpha-bounces@sourceware.org> |
Series |
[v2,1/3] powerpc: Add optimized ilogb* for POWER9
|
|
Commit Message
Raphael M Zinsly
March 1, 2021, 5:51 p.m. UTC
Changes since v1: - Move the builtins definitions to powerpc's math_private.h. - Check if the correct GCC version is used. --8<--- The instructions xsxexpdp and xsxexpqp introduced on POWER9 extract the exponent from a double-precision and quad-precision floating-point respectively, thus they can be used to improve ilogb, ilogbf and ilogbf128. --- sysdeps/powerpc/fpu/math_private.h | 20 +++++++++++- .../powerpc64/le/fpu/w_ilogb_template.c | 31 +++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c
Comments
On Mon, Mar 01, 2021 at 02:51:38PM -0300, Raphael Moreira Zinsly via Libc-alpha wrote: > Changes since v1: > - Move the builtins definitions to powerpc's math_private.h. > - Check if the correct GCC version is used. > > --8<--- > > The instructions xsxexpdp and xsxexpqp introduced on POWER9 extract > the exponent from a double-precision and quad-precision floating-point > respectively, thus they can be used to improve ilogb, ilogbf and ilogbf128. > --- > sysdeps/powerpc/fpu/math_private.h | 20 +++++++++++- > .../powerpc64/le/fpu/w_ilogb_template.c | 31 +++++++++++++++++++ > 2 files changed, 50 insertions(+), 1 deletion(-) > create mode 100644 sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c > > diff --git a/sysdeps/powerpc/fpu/math_private.h b/sysdeps/powerpc/fpu/math_private.h > index 91b1361749..accc28d091 100644 > --- a/sysdeps/powerpc/fpu/math_private.h > +++ b/sysdeps/powerpc/fpu/math_private.h > @@ -25,7 +25,23 @@ > > #include_next <math_private.h> > > -#if defined _ARCH_PWR9 && __HAVE_DISTINCT_FLOAT128 > +#ifdef _ARCH_PWR9 > + > +#define __builtin_test_dc_ilogbf __builtin_test_dc_ilogb > +#define __builtin_ilogbf __builtin_ilogb > + > +#define __builtin_test_dc_ilogbl __builtin_test_dc_ilogbf128 > +#define __builtin_ilogbl __builtin_ilogbf128 > + > +#define __builtin_test_dc_ilogb(x, y) \ > + __builtin_vsx_scalar_test_data_class_dp(x, y) > +#define __builtin_ilogb(x) __builtin_vsx_scalar_extract_exp(x) - 0x3ff > + > +#define __builtin_test_dc_ilogbf128(x, y) \ > + __builtin_vsx_scalar_test_data_class_qp(x, y) > +#define __builtin_ilogbf128(x) __builtin_vsx_scalar_extract_expq(x) - 0x3fff > + > +#if __HAVE_DISTINCT_FLOAT128 > extern __always_inline _Float128 > __ieee754_sqrtf128 (_Float128 __x) > { > @@ -35,4 +51,6 @@ __ieee754_sqrtf128 (_Float128 __x) > } > #endif > > +#endif /* _ARCH_PWR9 */ > + > #endif /* _PPC_MATH_PRIVATE_H_ */ > diff --git a/sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c b/sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c > new file mode 100644 > index 0000000000..17ac7809e1 > --- /dev/null > +++ b/sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c > @@ -0,0 +1,31 @@ > +/* The builtins used are only available with GCC 8.0 or newer. */ > +#if defined _ARCH_PWR9 && __GNUC_PREREQ (8, 0) I wonder if it would be better to use __glibc_has_builtin () for the builtins on which you depend, rather than testing for a specific GCC level. (Same for patch 2/3.) PC > +#include <math.h> > +#include <errno.h> > +#include <limits.h> > +#include <math_private.h> > +#include <fenv.h> > + > +int > +M_DECL_FUNC (__ilogb) (FLOAT x) > +{ > + int r; > + /* Check for exceptional cases. */ > + if (! M_SUF(__builtin_test_dc_ilogb) (x, 0x7f)) > + r = M_SUF (__builtin_ilogb) (x); > + else > + /* Fallback to the generic ilogb if x is NaN, Inf or subnormal. */ > + r = M_SUF (__ieee754_ilogb) (x); > + if (__builtin_expect (r == FP_ILOGB0, 0) > + || __builtin_expect (r == FP_ILOGBNAN, 0) > + || __builtin_expect (r == INT_MAX, 0)) > + { > + __set_errno (EDOM); > + __feraiseexcept (FE_INVALID); > + } > + return r; > +} > +declare_mgen_alias (__ilogb, ilogb) > +#else > +#include <math/w_ilogb_template.c> > +#endif > -- > 2.29.2 >
On 3/1/21 11:51 AM, Raphael Moreira Zinsly wrote: > Changes since v1: > - Move the builtins definitions to powerpc's math_private.h. > - Check if the correct GCC version is used. > > --8<--- > > The instructions xsxexpdp and xsxexpqp introduced on POWER9 extract > the exponent from a double-precision and quad-precision floating-point > respectively, thus they can be used to improve ilogb, ilogbf and ilogbf128. > --- > sysdeps/powerpc/fpu/math_private.h | 20 +++++++++++- > .../powerpc64/le/fpu/w_ilogb_template.c | 31 +++++++++++++++++++ > 2 files changed, 50 insertions(+), 1 deletion(-) > create mode 100644 sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c > > diff --git a/sysdeps/powerpc/fpu/math_private.h b/sysdeps/powerpc/fpu/math_private.h > index 91b1361749..accc28d091 100644 > --- a/sysdeps/powerpc/fpu/math_private.h > +++ b/sysdeps/powerpc/fpu/math_private.h > @@ -25,7 +25,23 @@ > > #include_next <math_private.h> > > -#if defined _ARCH_PWR9 && __HAVE_DISTINCT_FLOAT128 > +#ifdef _ARCH_PWR9 > + > +#define __builtin_test_dc_ilogbf __builtin_test_dc_ilogb > +#define __builtin_ilogbf __builtin_ilogb > + > +#define __builtin_test_dc_ilogbl __builtin_test_dc_ilogbf128 > +#define __builtin_ilogbl __builtin_ilogbf128 I suspect this converting an ibm128 value to float128. Can you verify whether this is the case, and if so, exclude ibm long doubles from this optimization? (Note, libm should be building long double == ibm128) Otherwise, LGTM. > + > +#define __builtin_test_dc_ilogb(x, y) \ > + __builtin_vsx_scalar_test_data_class_dp(x, y) > +#define __builtin_ilogb(x) __builtin_vsx_scalar_extract_exp(x) - 0x3ff > + > +#define __builtin_test_dc_ilogbf128(x, y) \ > + __builtin_vsx_scalar_test_data_class_qp(x, y) > +#define __builtin_ilogbf128(x) __builtin_vsx_scalar_extract_expq(x) - 0x3fff > + > +#if __HAVE_DISTINCT_FLOAT128 > extern __always_inline _Float128 > __ieee754_sqrtf128 (_Float128 __x) > { > @@ -35,4 +51,6 @@ __ieee754_sqrtf128 (_Float128 __x) > } > #endif > > +#endif /* _ARCH_PWR9 */ > + > #endif /* _PPC_MATH_PRIVATE_H_ */ > diff --git a/sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c b/sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c > new file mode 100644 > index 0000000000..17ac7809e1 > --- /dev/null > +++ b/sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c > @@ -0,0 +1,31 @@ > +/* The builtins used are only available with GCC 8.0 or newer. */ > +#if defined _ARCH_PWR9 && __GNUC_PREREQ (8, 0) > +#include <math.h> > +#include <errno.h> > +#include <limits.h> > +#include <math_private.h> > +#include <fenv.h> > + > +int > +M_DECL_FUNC (__ilogb) (FLOAT x) > +{ > + int r; > + /* Check for exceptional cases. */ > + if (! M_SUF(__builtin_test_dc_ilogb) (x, 0x7f)) > + r = M_SUF (__builtin_ilogb) (x); > + else > + /* Fallback to the generic ilogb if x is NaN, Inf or subnormal. */ > + r = M_SUF (__ieee754_ilogb) (x); > + if (__builtin_expect (r == FP_ILOGB0, 0) > + || __builtin_expect (r == FP_ILOGBNAN, 0) > + || __builtin_expect (r == INT_MAX, 0)) > + { > + __set_errno (EDOM); > + __feraiseexcept (FE_INVALID); > + } > + return r; > +} > +declare_mgen_alias (__ilogb, ilogb) > +#else > +#include <math/w_ilogb_template.c> > +#endif >
On 01/03/2021 22:27, Paul A. Clarke wrote: > On Mon, Mar 01, 2021 at 02:51:38PM -0300, Raphael Moreira Zinsly via Libc-alpha wrote: >> Changes since v1: >> - Move the builtins definitions to powerpc's math_private.h. >> - Check if the correct GCC version is used. >> >> --8<--- >> >> The instructions xsxexpdp and xsxexpqp introduced on POWER9 extract >> the exponent from a double-precision and quad-precision floating-point >> respectively, thus they can be used to improve ilogb, ilogbf and ilogbf128. >> --- >> sysdeps/powerpc/fpu/math_private.h | 20 +++++++++++- >> .../powerpc64/le/fpu/w_ilogb_template.c | 31 +++++++++++++++++++ >> 2 files changed, 50 insertions(+), 1 deletion(-) >> create mode 100644 sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c >> >> diff --git a/sysdeps/powerpc/fpu/math_private.h b/sysdeps/powerpc/fpu/math_private.h >> index 91b1361749..accc28d091 100644 >> --- a/sysdeps/powerpc/fpu/math_private.h >> +++ b/sysdeps/powerpc/fpu/math_private.h >> @@ -25,7 +25,23 @@ >> >> #include_next <math_private.h> >> >> -#if defined _ARCH_PWR9 && __HAVE_DISTINCT_FLOAT128 >> +#ifdef _ARCH_PWR9 >> + >> +#define __builtin_test_dc_ilogbf __builtin_test_dc_ilogb >> +#define __builtin_ilogbf __builtin_ilogb >> + >> +#define __builtin_test_dc_ilogbl __builtin_test_dc_ilogbf128 >> +#define __builtin_ilogbl __builtin_ilogbf128 >> + >> +#define __builtin_test_dc_ilogb(x, y) \ >> + __builtin_vsx_scalar_test_data_class_dp(x, y) >> +#define __builtin_ilogb(x) __builtin_vsx_scalar_extract_exp(x) - 0x3ff >> + >> +#define __builtin_test_dc_ilogbf128(x, y) \ >> + __builtin_vsx_scalar_test_data_class_qp(x, y) >> +#define __builtin_ilogbf128(x) __builtin_vsx_scalar_extract_expq(x) - 0x3fff >> + >> +#if __HAVE_DISTINCT_FLOAT128 >> extern __always_inline _Float128 >> __ieee754_sqrtf128 (_Float128 __x) >> { >> @@ -35,4 +51,6 @@ __ieee754_sqrtf128 (_Float128 __x) >> } >> #endif >> >> +#endif /* _ARCH_PWR9 */ >> + >> #endif /* _PPC_MATH_PRIVATE_H_ */ >> diff --git a/sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c b/sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c >> new file mode 100644 >> index 0000000000..17ac7809e1 >> --- /dev/null >> +++ b/sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c >> @@ -0,0 +1,31 @@ >> +/* The builtins used are only available with GCC 8.0 or newer. */ >> +#if defined _ARCH_PWR9 && __GNUC_PREREQ (8, 0) > > I wonder if it would be better to use __glibc_has_builtin () for the > builtins on which you depend, rather than testing for a specific GCC level. > I didn't find a __glibc_has_builtin definition, do you mean the preprocessor's __has_builtin()? I believe it's not available on GCC 8.0. > (Same for patch 2/3.) > > PC
On Wed, Mar 03, 2021 at 01:23:43PM -0300, Raphael M Zinsly via Libc-alpha wrote: > On 01/03/2021 22:27, Paul A. Clarke wrote: > > On Mon, Mar 01, 2021 at 02:51:38PM -0300, Raphael Moreira Zinsly via Libc-alpha wrote: > > > Changes since v1: > > > - Move the builtins definitions to powerpc's math_private.h. > > > - Check if the correct GCC version is used. > > > > > > --8<--- > > > > > > The instructions xsxexpdp and xsxexpqp introduced on POWER9 extract > > > the exponent from a double-precision and quad-precision floating-point > > > respectively, thus they can be used to improve ilogb, ilogbf and ilogbf128. > > > --- > > > sysdeps/powerpc/fpu/math_private.h | 20 +++++++++++- > > > .../powerpc64/le/fpu/w_ilogb_template.c | 31 +++++++++++++++++++ > > > 2 files changed, 50 insertions(+), 1 deletion(-) > > > create mode 100644 sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c > > > > > > diff --git a/sysdeps/powerpc/fpu/math_private.h b/sysdeps/powerpc/fpu/math_private.h > > > index 91b1361749..accc28d091 100644 > > > --- a/sysdeps/powerpc/fpu/math_private.h > > > +++ b/sysdeps/powerpc/fpu/math_private.h > > > @@ -25,7 +25,23 @@ > > > > > > #include_next <math_private.h> > > > > > > -#if defined _ARCH_PWR9 && __HAVE_DISTINCT_FLOAT128 > > > +#ifdef _ARCH_PWR9 > > > + > > > +#define __builtin_test_dc_ilogbf __builtin_test_dc_ilogb > > > +#define __builtin_ilogbf __builtin_ilogb > > > + > > > +#define __builtin_test_dc_ilogbl __builtin_test_dc_ilogbf128 > > > +#define __builtin_ilogbl __builtin_ilogbf128 > > > + > > > +#define __builtin_test_dc_ilogb(x, y) \ > > > + __builtin_vsx_scalar_test_data_class_dp(x, y) > > > +#define __builtin_ilogb(x) __builtin_vsx_scalar_extract_exp(x) - 0x3ff > > > + > > > +#define __builtin_test_dc_ilogbf128(x, y) \ > > > + __builtin_vsx_scalar_test_data_class_qp(x, y) > > > +#define __builtin_ilogbf128(x) __builtin_vsx_scalar_extract_expq(x) - 0x3fff > > > + > > > +#if __HAVE_DISTINCT_FLOAT128 > > > extern __always_inline _Float128 > > > __ieee754_sqrtf128 (_Float128 __x) > > > { > > > @@ -35,4 +51,6 @@ __ieee754_sqrtf128 (_Float128 __x) > > > } > > > #endif > > > > > > +#endif /* _ARCH_PWR9 */ > > > + > > > #endif /* _PPC_MATH_PRIVATE_H_ */ > > > diff --git a/sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c b/sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c > > > new file mode 100644 > > > index 0000000000..17ac7809e1 > > > --- /dev/null > > > +++ b/sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c > > > @@ -0,0 +1,31 @@ > > > +/* The builtins used are only available with GCC 8.0 or newer. */ > > > +#if defined _ARCH_PWR9 && __GNUC_PREREQ (8, 0) > > > > I wonder if it would be better to use __glibc_has_builtin () for the > > builtins on which you depend, rather than testing for a specific GCC level. > > > > I didn't find a __glibc_has_builtin definition, do you mean the > preprocessor's __has_builtin()? I believe it's not available on GCC 8.0. misc/sys/cdefs.h: -- /* Compilers that lack __has_attribute may object to #if defined __has_attribute && __has_attribute (...) even though they do not need to evaluate the right-hand side of the &&. Similarly for __has_builtin, etc. */ [...] #ifdef __has_builtin # define __glibc_has_builtin(name) __has_builtin (name) #else # define __glibc_has_builtin(name) 0 #endif -- ... so, it covers pre-GCC8 by always saying "nope". PC
diff --git a/sysdeps/powerpc/fpu/math_private.h b/sysdeps/powerpc/fpu/math_private.h index 91b1361749..accc28d091 100644 --- a/sysdeps/powerpc/fpu/math_private.h +++ b/sysdeps/powerpc/fpu/math_private.h @@ -25,7 +25,23 @@ #include_next <math_private.h> -#if defined _ARCH_PWR9 && __HAVE_DISTINCT_FLOAT128 +#ifdef _ARCH_PWR9 + +#define __builtin_test_dc_ilogbf __builtin_test_dc_ilogb +#define __builtin_ilogbf __builtin_ilogb + +#define __builtin_test_dc_ilogbl __builtin_test_dc_ilogbf128 +#define __builtin_ilogbl __builtin_ilogbf128 + +#define __builtin_test_dc_ilogb(x, y) \ + __builtin_vsx_scalar_test_data_class_dp(x, y) +#define __builtin_ilogb(x) __builtin_vsx_scalar_extract_exp(x) - 0x3ff + +#define __builtin_test_dc_ilogbf128(x, y) \ + __builtin_vsx_scalar_test_data_class_qp(x, y) +#define __builtin_ilogbf128(x) __builtin_vsx_scalar_extract_expq(x) - 0x3fff + +#if __HAVE_DISTINCT_FLOAT128 extern __always_inline _Float128 __ieee754_sqrtf128 (_Float128 __x) { @@ -35,4 +51,6 @@ __ieee754_sqrtf128 (_Float128 __x) } #endif +#endif /* _ARCH_PWR9 */ + #endif /* _PPC_MATH_PRIVATE_H_ */ diff --git a/sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c b/sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c new file mode 100644 index 0000000000..17ac7809e1 --- /dev/null +++ b/sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c @@ -0,0 +1,31 @@ +/* The builtins used are only available with GCC 8.0 or newer. */ +#if defined _ARCH_PWR9 && __GNUC_PREREQ (8, 0) +#include <math.h> +#include <errno.h> +#include <limits.h> +#include <math_private.h> +#include <fenv.h> + +int +M_DECL_FUNC (__ilogb) (FLOAT x) +{ + int r; + /* Check for exceptional cases. */ + if (! M_SUF(__builtin_test_dc_ilogb) (x, 0x7f)) + r = M_SUF (__builtin_ilogb) (x); + else + /* Fallback to the generic ilogb if x is NaN, Inf or subnormal. */ + r = M_SUF (__ieee754_ilogb) (x); + if (__builtin_expect (r == FP_ILOGB0, 0) + || __builtin_expect (r == FP_ILOGBNAN, 0) + || __builtin_expect (r == INT_MAX, 0)) + { + __set_errno (EDOM); + __feraiseexcept (FE_INVALID); + } + return r; +} +declare_mgen_alias (__ilogb, ilogb) +#else +#include <math/w_ilogb_template.c> +#endif