From patchwork Tue Jun 2 21:32:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vineet Gupta X-Patchwork-Id: 1302638 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=HOkiw0fS; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49c4yC46Jcz9sT5 for ; Wed, 3 Jun 2020 07:32:35 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 95626383F850; Tue, 2 Jun 2020 21:32:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 95626383F850 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1591133548; bh=7EJO+bd2F04KVFZkNjrQ3tUcU5zTG86iy19T/fW2PRY=; 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=HOkiw0fSsaGybLhv9tvJDPMffC8kE7/e3BMTVahnSkMxv1TSvUc8wq6omeYeV2bHC 6r+he0x5A9gt4llKmtnm7Nsz/imLD2isATz4v6IWkyan/CnW3S0+4Z+M5YosQsjO7/ LVoSTzcvIOQCcbUdLL38+elTEV1rpcQzeZBZzye8= 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.73.133]) by sourceware.org (Postfix) with ESMTPS id 1DBBC383F84C for ; Tue, 2 Jun 2020 21:32:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1DBBC383F84C 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 401E740651; 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 E153DA00A0; Tue, 2 Jun 2020 21:32:22 +0000 (UTC) X-SNPS-Relay: synopsys.com To: libc-alpha@sourceware.org Subject: [PATCH v3 1/4] iee754: provide gcc builtins based generic sqrt functions Date: Tue, 2 Jun 2020 14:32:17 -0700 Message-Id: <20200602213220.6201-2-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.5 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 | 3 +++ sysdeps/ieee754/dbl-64/e_sqrt.c | 6 ++++++ sysdeps/ieee754/flt-32/e_sqrtf.c | 16 ++++++++++------ sysdeps/s390/fpu/math-use-builtins.h | 3 +++ 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h index 8a39ef58bc95..fc724c824a17 100644 --- a/sysdeps/generic/math-use-builtins.h +++ b/sysdeps/generic/math-use-builtins.h @@ -60,4 +60,7 @@ # define USE_COPYSIGNF128_BUILTIN 0 #endif +#define USE_SQRT_BUILTIN 0 +#define USE_SQRTF_BUILTIN 0 + #endif /* math-use-builtins.h */ diff --git a/sysdeps/ieee754/dbl-64/e_sqrt.c b/sysdeps/ieee754/dbl-64/e_sqrt.c index d42a1a4eb6e9..518a8ae5cdaf 100644 --- a/sysdeps/ieee754/dbl-64/e_sqrt.c +++ b/sysdeps/ieee754/dbl-64/e_sqrt.c @@ -41,6 +41,7 @@ #include #include #include +#include /*********************************************************************/ /* An ultimate sqrt routine. Given an IEEE double machine number x */ @@ -50,6 +51,10 @@ double __ieee754_sqrt (double x) { +#if USE_SQRT_BUILTIN + return __builtin_sqrt (x); +#else + /* Use generic implementation. */ static const double rt0 = 9.99999999859990725855365213134618E-01, rt1 = 4.99999999495955425917856814202739E-01, @@ -138,6 +143,7 @@ __ieee754_sqrt (double x) return (x - x) / (x - x); /* sqrt(-ve)=sNaN */ return 0x1p-256 * __ieee754_sqrt (x * 0x1p512); } +#endif /* ! USE_SQRT_BUILTIN */ } #ifndef __ieee754_sqrt libm_alias_finite (__ieee754_sqrt, __sqrt) diff --git a/sysdeps/ieee754/flt-32/e_sqrtf.c b/sysdeps/ieee754/flt-32/e_sqrtf.c index b339444301aa..177bf5dbdde2 100644 --- a/sysdeps/ieee754/flt-32/e_sqrtf.c +++ b/sysdeps/ieee754/flt-32/e_sqrtf.c @@ -16,12 +16,15 @@ #include #include #include - -static const float one = 1.0, tiny=1.0e-30; +#include float __ieee754_sqrtf(float x) { +#if USE_SQRTF_BUILTIN + return __builtin_sqrtf (x); +#else + /* Use generic implementation. */ float z; int32_t sign = (int)0x80000000; int32_t ix,s,q,m,t,i; @@ -70,10 +73,10 @@ __ieee754_sqrtf(float x) /* use floating add to find out rounding direction */ if(ix!=0) { - z = one-tiny; /* trigger inexact flag */ - if (z>=one) { - z = one+tiny; - if (z>one) + z = 0x1p0 - 0x1.4484cp-100; /* trigger inexact flag. */ + if (z >= 0x1p0) { + z = 0x1p0 + 0x1.4484cp-100; + if (z > 0x1p0) q += 2; else q += (q&1); @@ -83,6 +86,7 @@ __ieee754_sqrtf(float x) ix += (m <<23); SET_FLOAT_WORD(z,ix); return z; +#endif /* ! USE_SQRTF_BUILTIN */ } #ifndef __ieee754_sqrtf libm_alias_finite (__ieee754_sqrtf, __sqrtf) diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h index db00c3a69b89..eb87b6b0b16b 100644 --- a/sysdeps/s390/fpu/math-use-builtins.h +++ b/sysdeps/s390/fpu/math-use-builtins.h @@ -108,4 +108,7 @@ # define USE_COPYSIGNF128_BUILTIN 0 #endif +#define USE_SQRT_BUILTIN 0 +#define USE_SQRTF_BUILTIN 0 + #endif /* math-use-builtins.h */