Re: [PATCH v2 1/4] iee754: provide gcc builtins based generic sqrt functions

2020-06-02 Thread Adhemerval Zanella



On 01/06/2020 21:35, Vineet Gupta wrote:
> Reviewed-by: Adhemerval Zanella  

LGTM with the small nit below and the s390 fix pointed by Stefan.

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 ++--
>  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 */

Ok.

> 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.859990725855365213134618E-01,
>  rt1 = 4.495955425917856814202739E-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)

Ok.

> 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 
>  #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)0x8000;
>   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 */

Period and double space before '*/'.

> + 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)
> 

Ok.

___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


Re: [PATCH v2 1/4] iee754: provide gcc builtins based generic sqrt functions

2020-06-02 Thread Vineet Gupta
On 6/2/20 5:51 AM, Stefan Liebler via Libc-alpha wrote:
> On 6/2/20 2:35 AM, Vineet Gupta via Libc-alpha wrote:
>> 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 ++--
>>  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 */
> Please also update the current architecture specific math-use-builtins.h
> file: sysdeps/s390/fpu/math-use-builtins.h

Fixed. I should have added s390 to my list of arches to test.

Thx for taking a look.

-Vineet


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH v2 1/4] iee754: provide gcc builtins based generic sqrt functions

2020-06-01 Thread Vineet Gupta
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 ++--
 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 
 #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.859990725855365213134618E-01,
 rt1 = 4.495955425917856814202739E-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 
 #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)0x8000;
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