From patchwork Tue Jun 2 21:32:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vineet Gupta X-Patchwork-Id: 39426 Return-Path: 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 23485383E800; Tue, 2 Jun 2020 21:32:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 23485383E800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1591133550; bh=1aTGIVqSMoU8yo7RDnFt5dZh2lphkRnrlLFzwIYLZLg=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Xat3Ne3JoZGlwGCpdvT9bfxIeXuo6MXFk74n4/4nrZzZH80QZg95u0zdF/G19Wxks myApNYhGB+XbKkVu3gqeAsVqSHpO2dhXMMLRX3URrOeq35q2c+4TbiNgjmzdnCHsnZ bIwXTUUtrvgD0jfAWdA56dEMDKVFDVl0pbR81x5Q= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by sourceware.org (Postfix) with ESMTPS id F3DC9383F850 for ; Tue, 2 Jun 2020 21:32:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org F3DC9383F850 Received: from mailhost.synopsys.com (sv2-mailhost2.synopsys.com [10.205.2.134]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id B0A7AC041E; Tue, 2 Jun 2020 21:32:23 +0000 (UTC) Received: from vineetg-Latitude-7400.internal.synopsys.com (unknown [10.13.183.89]) by mailhost.synopsys.com (Postfix) with ESMTP id 4AC98A00A2; Tue, 2 Jun 2020 21:32:23 +0000 (UTC) X-SNPS-Relay: synopsys.com To: libc-alpha@sourceware.org Subject: [PATCH v3 2/4] iee754: provide gcc builtins based generic fma functions Date: Tue, 2 Jun 2020 14:32:18 -0700 Message-Id: <20200602213220.6201-3-vgupta@synopsys.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200602213220.6201-1-vgupta@synopsys.com> References: <20200602213220.6201-1-vgupta@synopsys.com> MIME-Version: 1.0 X-Spam-Status: No, score=-15.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Vineet Gupta via Libc-alpha From: Vineet Gupta Reply-To: Vineet Gupta Cc: Vineet Gupta , linux-snps-arc@lists.infradead.org Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Reviewed-by: Adhemerval Zanella --- sysdeps/generic/math-use-builtins.h | 5 +++++ sysdeps/ieee754/dbl-64/s_fma.c | 6 ++++++ sysdeps/ieee754/dbl-64/s_fmaf.c | 6 ++++++ sysdeps/ieee754/float128/float128_private.h | 2 ++ sysdeps/ieee754/ldbl-128/s_fma.c | 5 +++++ sysdeps/ieee754/ldbl-128/s_fmal.c | 5 +++++ sysdeps/s390/fpu/math-use-builtins.h | 5 +++++ 7 files changed, 34 insertions(+) diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h index fc724c824a17..cf25ed8a2138 100644 --- a/sysdeps/generic/math-use-builtins.h +++ b/sysdeps/generic/math-use-builtins.h @@ -63,4 +63,9 @@ #define USE_SQRT_BUILTIN 0 #define USE_SQRTF_BUILTIN 0 +#define USE_FMA_BUILTIN 0 +#define USE_FMAF_BUILTIN 0 +#define USE_FMAL_BUILTIN 0 +#define USE_FMAF128_BUILTIN 0 + #endif /* math-use-builtins.h */ diff --git a/sysdeps/ieee754/dbl-64/s_fma.c b/sysdeps/ieee754/dbl-64/s_fma.c index 876df6e78bdc..9dc5b132b9ee 100644 --- a/sysdeps/ieee754/dbl-64/s_fma.c +++ b/sysdeps/ieee754/dbl-64/s_fma.c @@ -25,6 +25,7 @@ #include #include #include +#include /* This implementation uses rounding to odd to avoid problems with double rounding. See a paper by Boldo and Melquiond: @@ -33,6 +34,10 @@ double __fma (double x, double y, double z) { +#if USE_FMA_BUILTIN + return __builtin_fma (x, y, z); +#else + /* Use generic implementation. */ union ieee754_double u, v, w; int adjust = 0; u.d = x; @@ -292,6 +297,7 @@ __fma (double x, double y, double z) v.ieee.mantissa1 |= j; return v.d * 0x1p-108; } +#endif /* ! USE_FMA_BUILTIN */ } #ifndef __fma libm_alias_double (__fma, fma) diff --git a/sysdeps/ieee754/dbl-64/s_fmaf.c b/sysdeps/ieee754/dbl-64/s_fmaf.c index 57329d0a87fe..93b8660d5242 100644 --- a/sysdeps/ieee754/dbl-64/s_fmaf.c +++ b/sysdeps/ieee754/dbl-64/s_fmaf.c @@ -23,6 +23,7 @@ #include #include #include +#include /* This implementation relies on double being more than twice as precise as float and uses rounding to odd in order to avoid problems @@ -33,6 +34,10 @@ float __fmaf (float x, float y, float z) { +#if USE_FMAF_BUILTIN + return __builtin_fmaf (x, y, z); +#else + /* Use generic implementation. */ fenv_t env; /* Multiplication is always exact. */ @@ -60,6 +65,7 @@ __fmaf (float x, float y, float z) /* And finally truncation with round to nearest. */ return (float) u.d; +#endif /* ! USE_FMAF_BUILTIN */ } #ifndef __fmaf libm_alias_float (__fma, fma) diff --git a/sysdeps/ieee754/float128/float128_private.h b/sysdeps/ieee754/float128/float128_private.h index f97463d9dc1b..ab6fc9f3c9cf 100644 --- a/sysdeps/ieee754/float128/float128_private.h +++ b/sysdeps/ieee754/float128/float128_private.h @@ -154,6 +154,8 @@ #define USE_ROUNDL_BUILTIN USE_ROUNDF128_BUILTIN #undef USE_COPYSIGNL_BUILTIN #define USE_COPYSIGNL_BUILTIN USE_COPYSIGNF128_BUILTIN +#undef USE_FMAL_BUILTIN +#define USE_FMAL_BUILTIN USE_FMAF128_BUILTIN /* IEEE function renames. */ #define __ieee754_acoshl __ieee754_acoshf128 diff --git a/sysdeps/ieee754/ldbl-128/s_fma.c b/sysdeps/ieee754/ldbl-128/s_fma.c index 13f8ed3b87eb..0feff0a71cd1 100644 --- a/sysdeps/ieee754/ldbl-128/s_fma.c +++ b/sysdeps/ieee754/ldbl-128/s_fma.c @@ -21,6 +21,7 @@ #include #include #include +#include /* This implementation relies on long double being more than twice as precise as double and uses rounding to odd in order to avoid problems @@ -31,6 +32,9 @@ double __fma (double x, double y, double z) { +#if USE_FMA_BUILTIN + return __builtin_fma (x, y, z); +#else fenv_t env; /* Multiplication is always exact. */ long double temp = (long double) x * (long double) y; @@ -50,6 +54,7 @@ __fma (double x, double y, double z) feupdateenv (&env); /* And finally truncation with round to nearest. */ return (double) u.d; +#endif /* ! USE_FMA_BUILTIN */ } #ifndef __fma libm_alias_double (__fma, fma) diff --git a/sysdeps/ieee754/ldbl-128/s_fmal.c b/sysdeps/ieee754/ldbl-128/s_fmal.c index 7475015bcec6..a610499e47c7 100644 --- a/sysdeps/ieee754/ldbl-128/s_fmal.c +++ b/sysdeps/ieee754/ldbl-128/s_fmal.c @@ -25,6 +25,7 @@ #include #include #include +#include /* This implementation uses rounding to odd to avoid problems with double rounding. See a paper by Boldo and Melquiond: @@ -33,6 +34,9 @@ _Float128 __fmal (_Float128 x, _Float128 y, _Float128 z) { +#if USE_FMAL_BUILTIN + return __builtin_fmal (x, y, z); +#else union ieee854_long_double u, v, w; int adjust = 0; u.d = x; @@ -296,5 +300,6 @@ __fmal (_Float128 x, _Float128 y, _Float128 z) v.ieee.mantissa3 |= j; return v.d * L(0x1p-228); } +#endif /* ! USE_FMAL_BUILTIN */ } libm_alias_ldouble (__fma, fma) diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h index eb87b6b0b16b..3a80f86b2e29 100644 --- a/sysdeps/s390/fpu/math-use-builtins.h +++ b/sysdeps/s390/fpu/math-use-builtins.h @@ -111,4 +111,9 @@ #define USE_SQRT_BUILTIN 0 #define USE_SQRTF_BUILTIN 0 +#define USE_FMA_BUILTIN 0 +#define USE_FMAF_BUILTIN 0 +#define USE_FMAL_BUILTIN 0 +#define USE_FMAF128_BUILTIN 0 + #endif /* math-use-builtins.h */