public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Michael Hudson-Doyle <michael.hudson@canonical.com>
To: libc-alpha@sourceware.org
Subject: [PATCH] Ensure calculations happen with desired rounding mode in y1lf128
Date: Fri, 12 Aug 2022 12:05:10 +1200	[thread overview]
Message-ID: <20220812000510.1595861-1-michael.hudson@canonical.com> (raw)

math/test-float128-y1 fails on x86_64 and ppc64el with gcc 12 and -O3,
because code inside a block guarded by SET_RESTORE_ROUNDL is being moved
after the rounding mode has been restored. Use math_force_eval to
prevent this (and insert some math_opt_barrier calls to prevent code
from being moved before the rounding mode is set).

Fixes #29463
---
I don't know if this patch should be committed as is, although it does
fix an observed failure for me.

My read of the discussion in the gcc bug I filed about this
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106574 is that every single
use of a SET_RESTORE_ROUND macro is vulnerable to this. I can't think of
a generic way to fix this -- I guess you could have a macro to call an
always_inline function with a rounding mode set? But that would uglify
the control flow in the code quite a bit.
---
 sysdeps/ieee754/ldbl-128/e_j1l.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/sysdeps/ieee754/ldbl-128/e_j1l.c b/sysdeps/ieee754/ldbl-128/e_j1l.c
index 54c457681a..9a9c5c6f00 100644
--- a/sysdeps/ieee754/ldbl-128/e_j1l.c
+++ b/sysdeps/ieee754/ldbl-128/e_j1l.c
@@ -869,10 +869,13 @@ __ieee754_y1l (_Float128 x)
     {
       /* 0 <= x <= 2 */
       SET_RESTORE_ROUNDL (FE_TONEAREST);
+      xx = math_opt_barrier (xx);
+      x = math_opt_barrier (x);
       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;
+      math_force_eval (p);
       return p;
     }
 
-- 
2.34.1


             reply	other threads:[~2022-08-12  0:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-12  0:05 Michael Hudson-Doyle [this message]
2022-08-12 12:28 Wilco Dijkstra
2022-08-15 20:59 ` Joseph Myers
2022-08-17  4:23   ` Michael Hudson-Doyle
2022-08-17 11:53     ` Wilco Dijkstra
2022-08-17 16:52       ` Joseph Myers
2022-08-22 12:28       ` Paul Zimmermann

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=20220812000510.1595861-1-michael.hudson@canonical.com \
    --to=michael.hudson@canonical.com \
    --cc=libc-alpha@sourceware.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).