[BZ,#16824] Fix failing y1 due to too large ulps in downward/upward rounding mode.

Message ID li8la8$llb$1@ger.gmane.org
State Committed
Headers

Commit Message

Stefan Liebler April 11, 2014, 11:56 a.m. UTC
  Hi,

on s390 the y1 tests for long double fails due to too large ulps in 
downward / upward rounding mode (See Bug 16824).
According to Joseph Myers patch comment
(https://sourceware.org/ml/libc-alpha/2014-03/msg00620.html),
round-to-nearest is used internally to reduce error accumulation.
Tests on s390/s390x shows following ulps:
y1: 2
y1_downward: 4
y1_towardzero: 2
y1_upward: 5

Is this okay? On other architectures too?

Bye
---
2014-04-11  Stefan Liebler  <stli@linux.vnet.ibm.com>

	[BZ #16824]
	* sysdeps/ieee754/ldbl-128/e_j1l.c (__ieee754_y1l):
	Set round-to-nearest internally to reduce error accumulation.
---
  

Comments

Adhemerval Zanella Netto April 11, 2014, 12:50 p.m. UTC | #1
On 11-04-2014 08:56, Stefan Liebler wrote:
> Hi,
>
> on s390 the y1 tests for long double fails due to too large ulps in downward / upward rounding mode (See Bug 16824).
> According to Joseph Myers patch comment
> (https://sourceware.org/ml/libc-alpha/2014-03/msg00620.html),
> round-to-nearest is used internally to reduce error accumulation.
> Tests on s390/s390x shows following ulps:
> y1: 2
> y1_downward: 4
> y1_towardzero: 2
> y1_upward: 5
>
> Is this okay? On other architectures too?
>
> Bye
> ---
> 2014-04-11  Stefan Liebler  <stli@linux.vnet.ibm.com>
>
>     [BZ #16824]
>     * sysdeps/ieee754/ldbl-128/e_j1l.c (__ieee754_y1l):
>     Set round-to-nearest internally to reduce error accumulation.
> ---
>
> diff --git a/sysdeps/ieee754/ldbl-128/e_j1l.c b/sysdeps/ieee754/ldbl-128/e_j1l.c
> index 70a1c86..db96c94 100644
> --- a/sysdeps/ieee754/ldbl-128/e_j1l.c
> +++ b/sysdeps/ieee754/ldbl-128/e_j1l.c
> @@ -855,11 +855,14 @@ __ieee754_y1l (long double x)
>      return -TWOOPI / x;
>    if (xx <= 2.0L)
>      {
> +      int save_round = fegetround ();
> +      libc_fesetround (FE_TONEAREST);
>        /* 0 <= x <= 2 */
>        z = xx * xx;
>        p = xx * neval (z, Y0_2N, NY0_2N) / deval (z, Y0_2D, NY0_2D);
>        p = -TWOOPI / xx + p;
>        p = TWOOPI * __ieee754_logl (x) * __ieee754_j1l (x) + p;
> +      libc_fesetround (save_round);
>        return p;
>      }

Although s390 does not implemented the optimization to set/restore rounding mode only
when needed (check the x86_64 and powerpc fenv_private.h), the way to set/reset 
rounding mode should using SET_RESTORE_ROUND.
  
Siddhesh Poyarekar April 11, 2014, 1:08 p.m. UTC | #2
On Fri, Apr 11, 2014 at 01:56:55PM +0200, Stefan Liebler wrote:
> Hi,
> 
> on s390 the y1 tests for long double fails due to too large ulps in downward
> / upward rounding mode (See Bug 16824).
> According to Joseph Myers patch comment
> (https://sourceware.org/ml/libc-alpha/2014-03/msg00620.html),
> round-to-nearest is used internally to reduce error accumulation.
> Tests on s390/s390x shows following ulps:
> y1: 2
> y1_downward: 4
> y1_towardzero: 2
> y1_upward: 5
> 
> Is this okay? On other architectures too?
> 
> Bye
> ---
> 2014-04-11  Stefan Liebler  <stli@linux.vnet.ibm.com>
> 
> 	[BZ #16824]
> 	* sysdeps/ieee754/ldbl-128/e_j1l.c (__ieee754_y1l):
> 	Set round-to-nearest internally to reduce error accumulation.
> ---
> 
> diff --git a/sysdeps/ieee754/ldbl-128/e_j1l.c b/sysdeps/ieee754/ldbl-128/e_j1l.c
> index 70a1c86..db96c94 100644
> --- a/sysdeps/ieee754/ldbl-128/e_j1l.c
> +++ b/sysdeps/ieee754/ldbl-128/e_j1l.c
> @@ -855,11 +855,14 @@ __ieee754_y1l (long double x)
>      return -TWOOPI / x;
>    if (xx <= 2.0L)
>      {
> +      int save_round = fegetround ();
> +      libc_fesetround (FE_TONEAREST);

You'll find that the SET_RESTORE_ROUND macro would be a better fit
here since it does a save/restore only when needed.  Besides it makes
code more consistent with other functions.

Siddhesh.

>        /* 0 <= x <= 2 */
>        z = xx * xx;
>        p = xx * neval (z, Y0_2N, NY0_2N) / deval (z, Y0_2D, NY0_2D);
>        p = -TWOOPI / xx + p;
>        p = TWOOPI * __ieee754_logl (x) * __ieee754_j1l (x) + p;
> +      libc_fesetround (save_round);
>        return p;
>      }
>  
>
  

Patch

diff --git a/sysdeps/ieee754/ldbl-128/e_j1l.c b/sysdeps/ieee754/ldbl-128/e_j1l.c
index 70a1c86..db96c94 100644
--- a/sysdeps/ieee754/ldbl-128/e_j1l.c
+++ b/sysdeps/ieee754/ldbl-128/e_j1l.c
@@ -855,11 +855,14 @@  __ieee754_y1l (long double x)
     return -TWOOPI / x;
   if (xx <= 2.0L)
     {
+      int save_round = fegetround ();
+      libc_fesetround (FE_TONEAREST);
       /* 0 <= x <= 2 */
       z = xx * xx;
       p = xx * neval (z, Y0_2N, NY0_2N) / deval (z, Y0_2D, NY0_2D);
       p = -TWOOPI / xx + p;
       p = TWOOPI * __ieee754_logl (x) * __ieee754_j1l (x) + p;
+      libc_fesetround (save_round);
       return p;
     }