From: Vineet Gupta <Vineet.Gupta1@synopsys.com>
To: libc-alpha@sourceware.org
Cc: Vineet Gupta <Vineet.Gupta1@synopsys.com>,
linux-snps-arc@lists.infradead.org,
Adhemerval Zanella <adhemerval.zanella@linaro.org>
Subject: [PATCH v2 1/4] iee754: provide gcc builtins based generic sqrt functions
Date: Mon, 1 Jun 2020 17:35:38 -0700 [thread overview]
Message-ID: <20200602003541.21005-2-vgupta@synopsys.com> (raw)
In-Reply-To: <20200602003541.21005-1-vgupta@synopsys.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
---
sysdeps/generic/math-use-builtins.h | 3 +++
sysdeps/ieee754/dbl-64/e_sqrt.c | 6 ++++++
sysdeps/ieee754/flt-32/e_sqrtf.c | 16 ++++++++++------
3 files changed, 19 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 <math_private.h>
#include <fenv_private.h>
#include <libm-alias-finite.h>
+#include <math-use-builtins.h>
/*********************************************************************/
/* 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..d85a04162983 100644
--- a/sysdeps/ieee754/flt-32/e_sqrtf.c
+++ b/sysdeps/ieee754/flt-32/e_sqrtf.c
@@ -16,12 +16,15 @@
#include <math.h>
#include <math_private.h>
#include <libm-alias-finite.h>
-
-static const float one = 1.0, tiny=1.0e-30;
+#include <math-use-builtins.h>
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)
--
2.20.1
_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc
next prev parent reply other threads:[~2020-06-02 0:35 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-02 0:35 [PATCH v2 0/4] Enable generic math code for more arches Vineet Gupta
2020-06-02 0:35 ` Vineet Gupta [this message]
[not found] ` <5d912d39-f017-31fa-990b-e1c1b735e1ff@linux.ibm.com>
2020-06-02 16:54 ` [PATCH v2 1/4] iee754: provide gcc builtins based generic sqrt functions Vineet Gupta
2020-06-02 17:17 ` Adhemerval Zanella
2020-06-02 0:35 ` [PATCH v2 2/4] iee754: provide gcc builtins based generic fma functions Vineet Gupta
[not found] ` <34fc6c13-65e6-dcbb-42b1-1ba9f56b4dfd@linux.ibm.com>
2020-06-02 17:13 ` Vineet Gupta
[not found] ` <d6813e17-3847-7fd2-45e8-23576b62061d@linaro.org>
2020-06-03 0:20 ` Vineet Gupta
2020-06-03 6:29 ` Stefan Liebler
2020-06-02 17:28 ` Adhemerval Zanella
2020-06-02 0:35 ` [PATCH v2 3/4] aarch/fpu: use generic builtins based math functions Vineet Gupta
2020-06-02 17:31 ` Adhemerval Zanella
2020-06-02 19:14 ` Vineet Gupta
2020-06-02 0:35 ` [PATCH v2 4/4] powerpc/fpu: use generic fma functions Vineet Gupta
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200602003541.21005-2-vgupta@synopsys.com \
--to=vineet.gupta1@synopsys.com \
--cc=adhemerval.zanella@linaro.org \
--cc=libc-alpha@sourceware.org \
--cc=linux-snps-arc@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox