From patchwork Thu Aug 18 19:42:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paul E. Murphy" X-Patchwork-Id: 660522 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sFc2h2tgYz9t0p for ; Fri, 19 Aug 2016 05:43:08 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b=QEYcwYoL; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:in-reply-to:references :in-reply-to:references:message-id; q=dns; s=default; b=SIDF8hfD YydHcl+cmVphc0BOG4lSUa3lGuybWXogGDx6KPNMqM/ZrYtr/jXjT7nwqERpS0kK pmA7PBAETEkzvjLxFllaLaUkxTP5yTI/U9C9OwaGPRW3q4l4PbL7IOXTTNwLex05 yGIsSb+iB7BPYDs5NdDDNHORH/MlpoJHZEE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:in-reply-to:references :in-reply-to:references:message-id; s=default; bh=2lTs6byvilWOaR Ne9H6lDuZMz1E=; b=QEYcwYoLdWSE6Ztfzeaqi8C1WpkLPqIH9wXqWD9Xkh08mF F1iMY8GKT7F2Y3RsVwUFTdjmxewUarDlSHJPGzQVy8/eNYtA9F2/NOFzLUPglL67 8gN5lXsVmU2zBz1fye2iiQlt1w+sHxvpineZQ907yyHKrO0mHsVFFoOZKQVNU= Received: (qmail 28120 invoked by alias); 18 Aug 2016 19:42:51 -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 27949 invoked by uid 89); 18 Aug 2016 19:42:50 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=1.4 required=5.0 tests=AWL, BAYES_50, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW, RCVD_IN_SEMBACKSCATTER autolearn=no version=3.3.2 spammy=Compute, ldbl_mant_dig, LDBL_MANT_DIG, dbl_mant_dig X-HELO: mx0a-001b2d01.pphosted.com X-IBM-Helo: d03dlp01.boulder.ibm.com X-IBM-MailFrom: murphyp@linux.vnet.ibm.com From: "Paul E. Murphy" To: libc-alpha@sourceware.org Subject: [PATCHv2 1/5] Merge common usage of mul_split function Date: Thu, 18 Aug 2016 14:42:28 -0500 In-Reply-To: References: In-Reply-To: References: X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16081819-0004-0000-0000-0000102BF512 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00005613; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000181; SDB=6.00746528; UDB=6.00351972; IPR=6.00519063; BA=6.00004668; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00012381; XFM=3.00000011; UTC=2016-08-18 19:42:37 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16081819-0005-0000-0000-00007819822A Message-Id: <0ecf64fdd7715559d9d840d17ff081e6fc6a7f8a.1471548450.git.murphyp@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-08-18_09:, , 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-1604210000 definitions=main-1608180252 A number of files share identical code for the mul_split function. This moves the duplicated function mul_split into its own header, and refactors the fma usage into a single selection macro. Likewise, mul_split when used by a long double implementation is renamed mul_splitl for clarity. * sysdeps/ieee754/ldbl-128/gamma_productl.c: (mul_split) Remove, rename as mul_splitl, remove redundant float.h include, and include via mul_splitl.h * sysdeps/ieee754/ldbl-128/lgamma_productl.c: Likewise. * sysdeps/ieee754/ldbl-128/x2y2m1l.c: Likewise. * sysdeps/ieee754/ldbl-96/gamma_product.c: Likewise. * sysdeps/ieee754/ldbl-96/lgamma_product.c: Likewise. * sysdeps/ieee754/ldbl-96/x2y2m1.c: Likewise. * math/mul_splitl.h: New file. * sysdeps/ieee754/dbl-64/gamma_product.c (mul_split): Move into mul_split.h, and remove redundant float.h include. * sysdeps/ieee754/dbl-64/lgamma_product.c: Likewise. * sysdeps/ieee754/dbl-64/x2y2m1.c: Likewise. * sysdeps/ieee754/ldbl-128ibm/s_fmal.c: Likewise. * sysdeps/ieee754/ldbl-128ibm/x2y2m1.c: Likewise. * math/mul_split.h: New file. --- math/mul_split.h | 50 ++++++++++++++++++++++++++++++ math/mul_splitl.h | 50 ++++++++++++++++++++++++++++++ sysdeps/ieee754/dbl-64/gamma_product.c | 32 +------------------ sysdeps/ieee754/dbl-64/lgamma_product.c | 32 +------------------ sysdeps/ieee754/dbl-64/x2y2m1.c | 32 +------------------ sysdeps/ieee754/ldbl-128/gamma_productl.c | 34 ++------------------ sysdeps/ieee754/ldbl-128/lgamma_productl.c | 36 ++------------------- sysdeps/ieee754/ldbl-128/x2y2m1l.c | 37 +++------------------- sysdeps/ieee754/ldbl-128ibm/s_fmal.c | 27 +--------------- sysdeps/ieee754/ldbl-128ibm/x2y2m1l.c | 32 +------------------ sysdeps/ieee754/ldbl-96/gamma_productl.c | 34 ++------------------ sysdeps/ieee754/ldbl-96/lgamma_productl.c | 36 ++------------------- sysdeps/ieee754/ldbl-96/x2y2m1l.c | 36 ++------------------- 13 files changed, 122 insertions(+), 346 deletions(-) create mode 100644 math/mul_split.h create mode 100644 math/mul_splitl.h diff --git a/math/mul_split.h b/math/mul_split.h new file mode 100644 index 0000000..85038dc --- /dev/null +++ b/math/mul_split.h @@ -0,0 +1,50 @@ +/* Compute full X * Y for double type. + Copyright (C) 2013-2016 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 + . */ + +#ifndef _MUL_SPLIT_H +#define _MUL_SPLIT_H + +#include + +/* Calculate X * Y exactly and store the result in *HI + *LO. It is + given that the values are small enough that no overflow occurs and + large enough (or zero) that no underflow occurs. */ + +static void +mul_split (double *hi, double *lo, double x, double y) +{ +#ifdef __FP_FAST_FMA + /* Fast built-in fused multiply-add. */ + *hi = x * y; + *lo = __builtin_fma (x, y, -*hi); +#else + /* Apply Dekker's algorithm. */ + *hi = x * y; +# define C ((1 << (DBL_MANT_DIG + 1) / 2) + 1) + double x1 = x * C; + double y1 = y * C; +# undef C + x1 = (x - x1) + x1; + y1 = (y - y1) + y1; + double x2 = x - x1; + double y2 = y - y1; + *lo = (((x1 * y1 - *hi) + x1 * y2) + x2 * y1) + x2 * y2; +#endif +} + +#endif /* _MUL_SPLIT_H */ diff --git a/math/mul_splitl.h b/math/mul_splitl.h new file mode 100644 index 0000000..8a39ce0 --- /dev/null +++ b/math/mul_splitl.h @@ -0,0 +1,50 @@ +/* Compute full X * Y for long double type. + Copyright (C) 2013-2016 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 + . */ + +#ifndef _MUL_SPLITL_H +#define _MUL_SPLITL_H + +#include + +/* Calculate X * Y exactly and store the result in *HI + *LO. It is + given that the values are small enough that no overflow occurs and + large enough (or zero) that no underflow occurs. */ + +static inline void +mul_splitl (long double *hi, long double *lo, long double x, long double y) +{ +#ifdef __FP_FAST_FMAL + /* Fast built-in fused multiply-add. */ + *hi = x * y; + *lo = __builtin_fmal (x, y, -*hi); +#else + /* Apply Dekker's algorithm. */ + *hi = x * y; +# define C ((1LL << (LDBL_MANT_DIG + 1) / 2) + 1) + long double x1 = x * C; + long double y1 = y * C; +# undef C + x1 = (x - x1) + x1; + y1 = (y - y1) + y1; + long double x2 = x - x1; + long double y2 = y - y1; + *lo = (((x1 * y1 - *hi) + x1 * y2) + x2 * y1) + x2 * y2; +#endif +} + +#endif /* _MUL_SPLITL_H */ diff --git a/sysdeps/ieee754/dbl-64/gamma_product.c b/sysdeps/ieee754/dbl-64/gamma_product.c index 7ae144a..51407b1 100644 --- a/sysdeps/ieee754/dbl-64/gamma_product.c +++ b/sysdeps/ieee754/dbl-64/gamma_product.c @@ -18,37 +18,7 @@ #include #include -#include - -/* Calculate X * Y exactly and store the result in *HI + *LO. It is - given that the values are small enough that no overflow occurs and - large enough (or zero) that no underflow occurs. */ - -static void -mul_split (double *hi, double *lo, double x, double y) -{ -#ifdef __FP_FAST_FMA - /* Fast built-in fused multiply-add. */ - *hi = x * y; - *lo = __builtin_fma (x, y, -*hi); -#elif defined FP_FAST_FMA - /* Fast library fused multiply-add, compiler before GCC 4.6. */ - *hi = x * y; - *lo = __fma (x, y, -*hi); -#else - /* Apply Dekker's algorithm. */ - *hi = x * y; -# define C ((1 << (DBL_MANT_DIG + 1) / 2) + 1) - double x1 = x * C; - double y1 = y * C; -# undef C - x1 = (x - x1) + x1; - y1 = (y - y1) + y1; - double x2 = x - x1; - double y2 = y - y1; - *lo = (((x1 * y1 - *hi) + x1 * y2) + x2 * y1) + x2 * y2; -#endif -} +#include /* Compute the product of X + X_EPS, X + X_EPS + 1, ..., X + X_EPS + N - 1, in the form R * (1 + *EPS) where the return value R is an diff --git a/sysdeps/ieee754/dbl-64/lgamma_product.c b/sysdeps/ieee754/dbl-64/lgamma_product.c index d956575..fa89337 100644 --- a/sysdeps/ieee754/dbl-64/lgamma_product.c +++ b/sysdeps/ieee754/dbl-64/lgamma_product.c @@ -18,37 +18,7 @@ #include #include -#include - -/* Calculate X * Y exactly and store the result in *HI + *LO. It is - given that the values are small enough that no overflow occurs and - large enough (or zero) that no underflow occurs. */ - -static void -mul_split (double *hi, double *lo, double x, double y) -{ -#ifdef __FP_FAST_FMA - /* Fast built-in fused multiply-add. */ - *hi = x * y; - *lo = __builtin_fma (x, y, -*hi); -#elif defined FP_FAST_FMA - /* Fast library fused multiply-add, compiler before GCC 4.6. */ - *hi = x * y; - *lo = __fma (x, y, -*hi); -#else - /* Apply Dekker's algorithm. */ - *hi = x * y; -# define C ((1 << (DBL_MANT_DIG + 1) / 2) + 1) - double x1 = x * C; - double y1 = y * C; -# undef C - x1 = (x - x1) + x1; - y1 = (y - y1) + y1; - double x2 = x - x1; - double y2 = y - y1; - *lo = (((x1 * y1 - *hi) + x1 * y2) + x2 * y1) + x2 * y2; -#endif -} +#include /* Compute the product of 1 + (T / (X + X_EPS)), 1 + (T / (X + X_EPS + 1)), ..., 1 + (T / (X + X_EPS + N - 1)), minus 1. X is such that diff --git a/sysdeps/ieee754/dbl-64/x2y2m1.c b/sysdeps/ieee754/dbl-64/x2y2m1.c index 9607888..7505215 100644 --- a/sysdeps/ieee754/dbl-64/x2y2m1.c +++ b/sysdeps/ieee754/dbl-64/x2y2m1.c @@ -18,7 +18,7 @@ #include #include -#include +#include #include /* Calculate X + Y exactly and store the result in *HI + *LO. It is @@ -33,36 +33,6 @@ add_split (double *hi, double *lo, double x, double y) *lo = (x - *hi) + y; } -/* Calculate X * Y exactly and store the result in *HI + *LO. It is - given that the values are small enough that no overflow occurs and - large enough (or zero) that no underflow occurs. */ - -static void -mul_split (double *hi, double *lo, double x, double y) -{ -#ifdef __FP_FAST_FMA - /* Fast built-in fused multiply-add. */ - *hi = x * y; - *lo = __builtin_fma (x, y, -*hi); -#elif defined FP_FAST_FMA - /* Fast library fused multiply-add, compiler before GCC 4.6. */ - *hi = x * y; - *lo = __fma (x, y, -*hi); -#else - /* Apply Dekker's algorithm. */ - *hi = x * y; -# define C ((1 << (DBL_MANT_DIG + 1) / 2) + 1) - double x1 = x * C; - double y1 = y * C; -# undef C - x1 = (x - x1) + x1; - y1 = (y - y1) + y1; - double x2 = x - x1; - double y2 = y - y1; - *lo = (((x1 * y1 - *hi) + x1 * y2) + x2 * y1) + x2 * y2; -#endif -} - /* Compare absolute values of floating-point values pointed to by P and Q for qsort. */ diff --git a/sysdeps/ieee754/ldbl-128/gamma_productl.c b/sysdeps/ieee754/ldbl-128/gamma_productl.c index 849b57d..8ad0452 100644 --- a/sysdeps/ieee754/ldbl-128/gamma_productl.c +++ b/sysdeps/ieee754/ldbl-128/gamma_productl.c @@ -18,37 +18,7 @@ #include #include -#include - -/* Calculate X * Y exactly and store the result in *HI + *LO. It is - given that the values are small enough that no overflow occurs and - large enough (or zero) that no underflow occurs. */ - -static inline void -mul_split (long double *hi, long double *lo, long double x, long double y) -{ -#ifdef __FP_FAST_FMAL - /* Fast built-in fused multiply-add. */ - *hi = x * y; - *lo = __builtin_fmal (x, y, -*hi); -#elif defined FP_FAST_FMAL - /* Fast library fused multiply-add, compiler before GCC 4.6. */ - *hi = x * y; - *lo = __fmal (x, y, -*hi); -#else - /* Apply Dekker's algorithm. */ - *hi = x * y; -# define C ((1LL << (LDBL_MANT_DIG + 1) / 2) + 1) - long double x1 = x * C; - long double y1 = y * C; -# undef C - x1 = (x - x1) + x1; - y1 = (y - y1) + y1; - long double x2 = x - x1; - long double y2 = y - y1; - *lo = (((x1 * y1 - *hi) + x1 * y2) + x2 * y1) + x2 * y2; -#endif -} +#include /* Compute the product of X + X_EPS, X + X_EPS + 1, ..., X + X_EPS + N - 1, in the form R * (1 + *EPS) where the return value R is an @@ -68,7 +38,7 @@ __gamma_productl (long double x, long double x_eps, int n, long double *eps) { *eps += x_eps / (x + i); long double lo; - mul_split (&ret, &lo, ret, x + i); + mul_splitl (&ret, &lo, ret, x + i); *eps += lo / ret; } return ret; diff --git a/sysdeps/ieee754/ldbl-128/lgamma_productl.c b/sysdeps/ieee754/ldbl-128/lgamma_productl.c index de67cbe..9aa0137 100644 --- a/sysdeps/ieee754/ldbl-128/lgamma_productl.c +++ b/sysdeps/ieee754/ldbl-128/lgamma_productl.c @@ -18,37 +18,7 @@ #include #include -#include - -/* Calculate X * Y exactly and store the result in *HI + *LO. It is - given that the values are small enough that no overflow occurs and - large enough (or zero) that no underflow occurs. */ - -static void -mul_split (long double *hi, long double *lo, long double x, long double y) -{ -#ifdef __FP_FAST_FMAL - /* Fast built-in fused multiply-add. */ - *hi = x * y; - *lo = __builtin_fmal (x, y, -*hi); -#elif defined FP_FAST_FMAL - /* Fast library fused multiply-add, compiler before GCC 4.6. */ - *hi = x * y; - *lo = __fmal (x, y, -*hi); -#else - /* Apply Dekker's algorithm. */ - *hi = x * y; -# define C ((1LL << (LDBL_MANT_DIG + 1) / 2) + 1) - long double x1 = x * C; - long double y1 = y * C; -# undef C - x1 = (x - x1) + x1; - y1 = (y - y1) + y1; - long double x2 = x - x1; - long double y2 = y - y1; - *lo = (((x1 * y1 - *hi) + x1 * y2) + x2 * y1) + x2 * y2; -#endif -} +#include /* Compute the product of 1 + (T / (X + X_EPS)), 1 + (T / (X + X_EPS + 1)), ..., 1 + (T / (X + X_EPS + N - 1)), minus 1. X is such that @@ -65,11 +35,11 @@ __lgamma_productl (long double t, long double x, long double x_eps, int n) long double xi = x + i; long double quot = t / xi; long double mhi, mlo; - mul_split (&mhi, &mlo, quot, xi); + mul_splitl (&mhi, &mlo, quot, xi); long double quot_lo = (t - mhi - mlo) / xi - t * x_eps / (xi * xi); /* We want (1 + RET + RET_EPS) * (1 + QUOT + QUOT_LO) - 1. */ long double rhi, rlo; - mul_split (&rhi, &rlo, ret, quot); + mul_splitl (&rhi, &rlo, ret, quot); long double rpq = ret + quot; long double rpq_eps = (ret - rpq) + quot; long double nret = rpq + rhi; diff --git a/sysdeps/ieee754/ldbl-128/x2y2m1l.c b/sysdeps/ieee754/ldbl-128/x2y2m1l.c index 733742d..4e97885 100644 --- a/sysdeps/ieee754/ldbl-128/x2y2m1l.c +++ b/sysdeps/ieee754/ldbl-128/x2y2m1l.c @@ -18,9 +18,10 @@ #include #include -#include +#include #include + /* Calculate X + Y exactly and store the result in *HI + *LO. It is given that |X| >= |Y| and the values are small enough that no overflow occurs. */ @@ -33,36 +34,6 @@ add_split (long double *hi, long double *lo, long double x, long double y) *lo = (x - *hi) + y; } -/* Calculate X * Y exactly and store the result in *HI + *LO. It is - given that the values are small enough that no overflow occurs and - large enough (or zero) that no underflow occurs. */ - -static inline void -mul_split (long double *hi, long double *lo, long double x, long double y) -{ -#ifdef __FP_FAST_FMAL - /* Fast built-in fused multiply-add. */ - *hi = x * y; - *lo = __builtin_fmal (x, y, -*hi); -#elif defined FP_FAST_FMAL - /* Fast library fused multiply-add, compiler before GCC 4.6. */ - *hi = x * y; - *lo = __fmal (x, y, -*hi); -#else - /* Apply Dekker's algorithm. */ - *hi = x * y; -# define C ((1LL << (LDBL_MANT_DIG + 1) / 2) + 1) - long double x1 = x * C; - long double y1 = y * C; -# undef C - x1 = (x - x1) + x1; - y1 = (y - y1) + y1; - long double x2 = x - x1; - long double y2 = y - y1; - *lo = (((x1 * y1 - *hi) + x1 * y2) + x2 * y1) + x2 * y2; -#endif -} - /* Compare absolute values of floating-point values pointed to by P and Q for qsort. */ @@ -88,8 +59,8 @@ __x2y2m1l (long double x, long double y) { long double vals[5]; SET_RESTORE_ROUNDL (FE_TONEAREST); - mul_split (&vals[1], &vals[0], x, x); - mul_split (&vals[3], &vals[2], y, y); + mul_splitl (&vals[1], &vals[0], x, x); + mul_splitl (&vals[3], &vals[2], y, y); vals[4] = -1.0L; qsort (vals, 5, sizeof (long double), compare); /* Add up the values so that each element of VALS has absolute value diff --git a/sysdeps/ieee754/ldbl-128ibm/s_fmal.c b/sysdeps/ieee754/ldbl-128ibm/s_fmal.c index 177a048..1405763 100644 --- a/sysdeps/ieee754/ldbl-128ibm/s_fmal.c +++ b/sysdeps/ieee754/ldbl-128ibm/s_fmal.c @@ -22,6 +22,7 @@ #include #include #include +#include #include /* Calculate X + Y exactly and store the result in *HI + *LO. It is @@ -36,32 +37,6 @@ add_split (double *hi, double *lo, double x, double y) *lo = (x - *hi) + y; } -/* Calculate X * Y exactly and store the result in *HI + *LO. It is - given that the values are small enough that no overflow occurs and - large enough (or zero) that no underflow occurs. */ - -static void -mul_split (double *hi, double *lo, double x, double y) -{ -#ifdef __FP_FAST_FMA - /* Fast built-in fused multiply-add. */ - *hi = x * y; - *lo = __builtin_fma (x, y, -*hi); -#else - /* Apply Dekker's algorithm. */ - *hi = x * y; -# define C ((1 << (DBL_MANT_DIG + 1) / 2) + 1) - double x1 = x * C; - double y1 = y * C; -# undef C - x1 = (x - x1) + x1; - y1 = (y - y1) + y1; - double x2 = x - x1; - double y2 = y - y1; - *lo = (((x1 * y1 - *hi) + x1 * y2) + x2 * y1) + x2 * y2; -#endif -} - /* Value with extended range, used in intermediate computations. */ typedef struct { diff --git a/sysdeps/ieee754/ldbl-128ibm/x2y2m1l.c b/sysdeps/ieee754/ldbl-128ibm/x2y2m1l.c index da2e929..a8b4895 100644 --- a/sysdeps/ieee754/ldbl-128ibm/x2y2m1l.c +++ b/sysdeps/ieee754/ldbl-128ibm/x2y2m1l.c @@ -18,7 +18,7 @@ #include #include -#include +#include #include /* Calculate X + Y exactly and store the result in *HI + *LO. It is @@ -33,36 +33,6 @@ add_split (double *hi, double *lo, double x, double y) *lo = (x - *hi) + y; } -/* Calculate X * Y exactly and store the result in *HI + *LO. It is - given that the values are small enough that no overflow occurs and - large enough (or zero) that no underflow occurs. */ - -static inline void -mul_split (double *hi, double *lo, double x, double y) -{ -#ifdef __FP_FAST_FMA - /* Fast built-in fused multiply-add. */ - *hi = x * y; - *lo = __builtin_fma (x, y, -*hi); -#elif defined FP_FAST_FMA - /* Fast library fused multiply-add, compiler before GCC 4.6. */ - *hi = x * y; - *lo = __fma (x, y, -*hi); -#else - /* Apply Dekker's algorithm. */ - *hi = x * y; -# define C ((1 << (DBL_MANT_DIG + 1) / 2) + 1) - double x1 = x * C; - double y1 = y * C; -# undef C - x1 = (x - x1) + x1; - y1 = (y - y1) + y1; - double x2 = x - x1; - double y2 = y - y1; - *lo = (((x1 * y1 - *hi) + x1 * y2) + x2 * y1) + x2 * y2; -#endif -} - /* Compare absolute values of floating-point values pointed to by P and Q for qsort. */ diff --git a/sysdeps/ieee754/ldbl-96/gamma_productl.c b/sysdeps/ieee754/ldbl-96/gamma_productl.c index 849b57d..8ad0452 100644 --- a/sysdeps/ieee754/ldbl-96/gamma_productl.c +++ b/sysdeps/ieee754/ldbl-96/gamma_productl.c @@ -18,37 +18,7 @@ #include #include -#include - -/* Calculate X * Y exactly and store the result in *HI + *LO. It is - given that the values are small enough that no overflow occurs and - large enough (or zero) that no underflow occurs. */ - -static inline void -mul_split (long double *hi, long double *lo, long double x, long double y) -{ -#ifdef __FP_FAST_FMAL - /* Fast built-in fused multiply-add. */ - *hi = x * y; - *lo = __builtin_fmal (x, y, -*hi); -#elif defined FP_FAST_FMAL - /* Fast library fused multiply-add, compiler before GCC 4.6. */ - *hi = x * y; - *lo = __fmal (x, y, -*hi); -#else - /* Apply Dekker's algorithm. */ - *hi = x * y; -# define C ((1LL << (LDBL_MANT_DIG + 1) / 2) + 1) - long double x1 = x * C; - long double y1 = y * C; -# undef C - x1 = (x - x1) + x1; - y1 = (y - y1) + y1; - long double x2 = x - x1; - long double y2 = y - y1; - *lo = (((x1 * y1 - *hi) + x1 * y2) + x2 * y1) + x2 * y2; -#endif -} +#include /* Compute the product of X + X_EPS, X + X_EPS + 1, ..., X + X_EPS + N - 1, in the form R * (1 + *EPS) where the return value R is an @@ -68,7 +38,7 @@ __gamma_productl (long double x, long double x_eps, int n, long double *eps) { *eps += x_eps / (x + i); long double lo; - mul_split (&ret, &lo, ret, x + i); + mul_splitl (&ret, &lo, ret, x + i); *eps += lo / ret; } return ret; diff --git a/sysdeps/ieee754/ldbl-96/lgamma_productl.c b/sysdeps/ieee754/ldbl-96/lgamma_productl.c index de67cbe..9aa0137 100644 --- a/sysdeps/ieee754/ldbl-96/lgamma_productl.c +++ b/sysdeps/ieee754/ldbl-96/lgamma_productl.c @@ -18,37 +18,7 @@ #include #include -#include - -/* Calculate X * Y exactly and store the result in *HI + *LO. It is - given that the values are small enough that no overflow occurs and - large enough (or zero) that no underflow occurs. */ - -static void -mul_split (long double *hi, long double *lo, long double x, long double y) -{ -#ifdef __FP_FAST_FMAL - /* Fast built-in fused multiply-add. */ - *hi = x * y; - *lo = __builtin_fmal (x, y, -*hi); -#elif defined FP_FAST_FMAL - /* Fast library fused multiply-add, compiler before GCC 4.6. */ - *hi = x * y; - *lo = __fmal (x, y, -*hi); -#else - /* Apply Dekker's algorithm. */ - *hi = x * y; -# define C ((1LL << (LDBL_MANT_DIG + 1) / 2) + 1) - long double x1 = x * C; - long double y1 = y * C; -# undef C - x1 = (x - x1) + x1; - y1 = (y - y1) + y1; - long double x2 = x - x1; - long double y2 = y - y1; - *lo = (((x1 * y1 - *hi) + x1 * y2) + x2 * y1) + x2 * y2; -#endif -} +#include /* Compute the product of 1 + (T / (X + X_EPS)), 1 + (T / (X + X_EPS + 1)), ..., 1 + (T / (X + X_EPS + N - 1)), minus 1. X is such that @@ -65,11 +35,11 @@ __lgamma_productl (long double t, long double x, long double x_eps, int n) long double xi = x + i; long double quot = t / xi; long double mhi, mlo; - mul_split (&mhi, &mlo, quot, xi); + mul_splitl (&mhi, &mlo, quot, xi); long double quot_lo = (t - mhi - mlo) / xi - t * x_eps / (xi * xi); /* We want (1 + RET + RET_EPS) * (1 + QUOT + QUOT_LO) - 1. */ long double rhi, rlo; - mul_split (&rhi, &rlo, ret, quot); + mul_splitl (&rhi, &rlo, ret, quot); long double rpq = ret + quot; long double rpq_eps = (ret - rpq) + quot; long double nret = rpq + rhi; diff --git a/sysdeps/ieee754/ldbl-96/x2y2m1l.c b/sysdeps/ieee754/ldbl-96/x2y2m1l.c index 733742d..b86ba1c 100644 --- a/sysdeps/ieee754/ldbl-96/x2y2m1l.c +++ b/sysdeps/ieee754/ldbl-96/x2y2m1l.c @@ -18,7 +18,7 @@ #include #include -#include +#include #include /* Calculate X + Y exactly and store the result in *HI + *LO. It is @@ -33,36 +33,6 @@ add_split (long double *hi, long double *lo, long double x, long double y) *lo = (x - *hi) + y; } -/* Calculate X * Y exactly and store the result in *HI + *LO. It is - given that the values are small enough that no overflow occurs and - large enough (or zero) that no underflow occurs. */ - -static inline void -mul_split (long double *hi, long double *lo, long double x, long double y) -{ -#ifdef __FP_FAST_FMAL - /* Fast built-in fused multiply-add. */ - *hi = x * y; - *lo = __builtin_fmal (x, y, -*hi); -#elif defined FP_FAST_FMAL - /* Fast library fused multiply-add, compiler before GCC 4.6. */ - *hi = x * y; - *lo = __fmal (x, y, -*hi); -#else - /* Apply Dekker's algorithm. */ - *hi = x * y; -# define C ((1LL << (LDBL_MANT_DIG + 1) / 2) + 1) - long double x1 = x * C; - long double y1 = y * C; -# undef C - x1 = (x - x1) + x1; - y1 = (y - y1) + y1; - long double x2 = x - x1; - long double y2 = y - y1; - *lo = (((x1 * y1 - *hi) + x1 * y2) + x2 * y1) + x2 * y2; -#endif -} - /* Compare absolute values of floating-point values pointed to by P and Q for qsort. */ @@ -88,8 +58,8 @@ __x2y2m1l (long double x, long double y) { long double vals[5]; SET_RESTORE_ROUNDL (FE_TONEAREST); - mul_split (&vals[1], &vals[0], x, x); - mul_split (&vals[3], &vals[2], y, y); + mul_splitl (&vals[1], &vals[0], x, x); + mul_splitl (&vals[3], &vals[2], y, y); vals[4] = -1.0L; qsort (vals, 5, sizeof (long double), compare); /* Add up the values so that each element of VALS has absolute value