From: Michael Hudson-Doyle <michael.hudson@canonical.com>
To: Joseph Myers <joseph@codesourcery.com>
Cc: Wilco Dijkstra <Wilco.Dijkstra@arm.com>,
GNU C Library <libc-alpha@sourceware.org>
Subject: Re: [PATCH] Ensure calculations happen with desired rounding mode in y1lf128
Date: Wed, 17 Aug 2022 16:23:11 +1200 [thread overview]
Message-ID: <CAJ8wqtdtuvTO6Er7O+L_-E0PqPzVpCv+1rtQJWJsd+KTHzN8Xw@mail.gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.22.394.2208152055090.311521@digraph.polyomino.org.uk>
On Tue, 16 Aug 2022 at 09:00, Joseph Myers <joseph@codesourcery.com> wrote:
> On Fri, 12 Aug 2022, Wilco Dijkstra via Libc-alpha wrote:
>
> > All math functions using the SET_RESTORE_ROUND macros will need similar
> > barriers.
Sounds fun. Really, wrapping mode changes around a function call sounds
saner but also tedious in a different way.
> > Note that it is feasible to remove these macros altogether and fix
> > any issues (a slightly larger ULP is acceptable for non-nearest
> rounding).
>
Removing the rounding mode change entirely makes the errors quite a lot
worse, as the bug Joseph links to shows.
> > Given rounding mode changes are generally expensive, this also improves
> > performance (though that may not be important for 128-bit floats).
> This one is a case where SET_RESTORE_ROUND is used to reduce error
> accumulation to keep the errors within the bounds accepted by the
> testsuite (see bug 16824). In such cases, it may indeed be possible to
> change the algorithm to one that has less total error accumulation
> possible in any rounding mode so the results are sufficiently accurate
> independent of rounding mode without needing SET_RESTORE_ROUND.
>
> In other cases, the manipulation of the floating-point environment is
> needed for correctness, e.g. to avoid spurious exceptions or to implement
> round-to-odd for functions that must be correctly rounding, or it's
> because algorithms for higher internal precision are used (Dekker / Knuth)
> that are only correct in round-to-nearest most and much larger errors
> might occur if those are used in the wrong rounding mode.
>
It does seem likely that an algorithm that does not require setting a
rounding mode would in general be better than one that does but also that
this is not very realistic. But I guess my point is that SET_RESTORE_ROUND
without barriers is a footgun. I guess I should commit my patch and perhaps
see about writing some more for other uses of the macro?
Cheers,
mwh
next prev parent reply other threads:[~2022-08-17 4:23 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-12 12:28 Wilco Dijkstra
2022-08-15 20:59 ` Joseph Myers
2022-08-17 4:23 ` Michael Hudson-Doyle [this message]
2022-08-17 11:53 ` Wilco Dijkstra
2022-08-17 16:52 ` Joseph Myers
2022-08-22 12:28 ` Paul Zimmermann
-- strict thread matches above, loose matches on Subject: below --
2022-08-12 0:05 Michael Hudson-Doyle
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=CAJ8wqtdtuvTO6Er7O+L_-E0PqPzVpCv+1rtQJWJsd+KTHzN8Xw@mail.gmail.com \
--to=michael.hudson@canonical.com \
--cc=Wilco.Dijkstra@arm.com \
--cc=joseph@codesourcery.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).