public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
To: Giuliano Augusto Faulin Belinassi <giuliano.belinassi@usp.br>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>,
	"giuliano.belinassi@gmail.com"	<giuliano.belinassi@gmail.com>,
	nd <nd@arm.com>, Jeff Law <law@redhat.com>
Subject: Re: [PATCH] Add sinh(tanh(x)) and cosh(tanh(x)) rules
Date: Fri, 19 Oct 2018 13:46:00 -0000	[thread overview]
Message-ID: <DB5PR08MB103010C39AAFAE5766A73F3A83F90@DB5PR08MB1030.eurprd08.prod.outlook.com> (raw)
In-Reply-To: <CAEFO=4CV1P23fmb_kAv8u=ubJ5PejVFC59gFGnbNm2TrO-P38Q@mail.gmail.com>

Hi,

>> Did you enable FMA? I'd expect 1 - x*x to be accurate with FMA, so the relative error
>> should be much better. If there is no FMA, 2*(1-fabs(x)) - (1-fabs(x))^2 should be
>> more accurate when abs(x)>0.5 and still much faster.
>
>No, but I will check how to enable it if FMA is available.
> I did a minor test with your formula and the precision improved a lot.

> But now I am puzzled about how did you come up with that formula :-).
> I am able to proof equality, but how did you know it was going to be
> more precise?

Basically when x is close to 1, x the top N bits in the mantissa will be ones.
Then x*x has one bits in the top 2*N bits in the mantissa. Ie. we lose N bits of
useful information in the multiply - problematic when N gets close to the number
of mantissa bits. In contrast FMA computes the fully accurate result due to
cancellation of the top 2*N one-bits in the subtract.

If we can use (1-x) instead of x in the evaluation, we avoid losing accuracy in the
multiply when x is close to 1. Then it's basic algebra to find an equivalent formula
that can produce 1-x^2 using 1-x. For example (1+x)*(1-x) will work fine too 
(using 1+x loses 1 low bit of x).

Note that these alternative evaluations lose accuracy close to 0 in exactly the
same way, so if no FMA is available you'd need to select between the 2 cases.

Wilco

  reply	other threads:[~2018-10-19 13:39 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-18 23:22 Wilco Dijkstra
2018-10-19 13:39 ` Giuliano Augusto Faulin Belinassi
2018-10-19 13:46   ` Wilco Dijkstra [this message]
2018-10-19 14:49     ` Jakub Jelinek
2018-10-19 15:35       ` Wilco Dijkstra
2018-10-19 14:03   ` Segher Boessenkool
2018-10-19 15:10     ` Giuliano Augusto Faulin Belinassi
2018-10-19 17:28       ` Wilco Dijkstra
2018-10-20 19:06         ` Giuliano Augusto Faulin Belinassi
2018-10-22 20:58           ` Jeff Law
2018-10-23  9:52             ` Richard Biener
2018-10-23 11:31               ` Wilco Dijkstra
2018-10-23 11:35                 ` Jakub Jelinek
2018-10-23 12:02                   ` Wilco Dijkstra
2018-11-07 22:21               ` Jeff Law
2018-11-07 22:34                 ` Wilco Dijkstra
2018-11-08  1:44                   ` Segher Boessenkool
2018-11-08 13:33                     ` Wilco Dijkstra
2018-11-09 20:04                       ` Jeff Law
2018-11-09 22:04                         ` Giuliano Augusto Faulin Belinassi
2018-11-10  5:36                         ` Segher Boessenkool
2018-11-12 14:17                           ` Richard Biener
2018-12-02 14:37                       ` Segher Boessenkool
  -- strict thread matches above, loose matches on Subject: below --
2018-08-07 20:00 Giuliano Augusto Faulin Belinassi
2018-08-07 20:29 ` Paul Koning
2018-08-07 20:42   ` Giuliano Augusto Faulin Belinassi
2018-08-08 13:59     ` Paul Koning
2018-08-08 18:57       ` Giuliano Augusto Faulin Belinassi
2018-08-08 19:55         ` Paul Koning
2018-10-12  4:55 ` Jeff Law
2018-10-12 14:55   ` Giuliano Augusto Faulin Belinassi
2018-10-16 21:16     ` Jeff Law
2018-10-17 21:43       ` Giuliano Augusto Faulin Belinassi
2018-10-17 22:45         ` Jeff Law
2018-10-18  5:38           ` Giuliano Augusto Faulin Belinassi
2018-10-18 17:10             ` Jeff Law
2018-10-18 22:46               ` Giuliano Belinassi

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=DB5PR08MB103010C39AAFAE5766A73F3A83F90@DB5PR08MB1030.eurprd08.prod.outlook.com \
    --to=wilco.dijkstra@arm.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=giuliano.belinassi@gmail.com \
    --cc=giuliano.belinassi@usp.br \
    --cc=law@redhat.com \
    --cc=nd@arm.com \
    /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).