From: Michael Matz <matz@suse.de>
To: James Greenhalgh <james.greenhalgh@arm.com>
Cc: "pinskia@gmail.com" <pinskia@gmail.com>,
"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: [Patch match.pd] Add a simplify rule for x * copysign (1.0, y);
Date: Thu, 01 Oct 2015 15:43:00 -0000 [thread overview]
Message-ID: <alpine.LSU.2.20.1510011705500.1349@wotan.suse.de> (raw)
In-Reply-To: <20151001145126.GA3881@arm.com>
Hi,
On Thu, 1 Oct 2015, James Greenhalgh wrote:
> > > x * copysign (1.0, y)
> > >
> > > x ^ (y & (1 << sign_bit_position))
> >
> > Also I think this can only be done for finite and non trapping types.
>
> That may be well true, I swithered either way and went for no checks,
> but I'd happily go back on that and wrap this in something suitable
> restrictive if I need to.
I don't think that's necessary. copysign (1.0, y) is always 1.0 or -1.0,
even with y being a NaN or inf. Additionally copysign is allowed to not
signal even if y is a sNaN. That leaves only the form of x to doubt. If
x is inf all is well (multiplying by +-1.0 is defined and both sequences
get the same result), if x is NaN the result must be a NaN, and it is in
both cases. The catch is that strictly speaking (NaN * -1.0) needs to
deliver NaN, not -NaN (operations involving quiet NaNs need to provide
one of the input NaNs as result), and here both are not equivalent. OTOH
the sign of NaNs isn't specified, so I think we could reasonably decide to
not care about this case (it would have to be checked if the hardware
multiplication even follows that rule, otherwise it's moot anyway).
And yes, also on x86-64 cores the new sequence would be better (or at
least as good; the latency of xor[sp][sd] is less than or equal to mul),
but that only is the case if the arithmetic really happen in SSE
registers, not in integer ones, and this isn't the case right now. Hmpf.
Ciao,
Michael.
next prev parent reply other threads:[~2015-10-01 15:43 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-01 13:57 James Greenhalgh
2015-10-01 14:28 ` pinskia
2015-10-01 14:51 ` James Greenhalgh
2015-10-01 15:03 ` pinskia
2015-10-01 15:43 ` Michael Matz [this message]
2015-10-01 15:49 ` Jakub Jelinek
2015-10-01 16:09 ` Michael Matz
2015-10-01 15:59 ` Joseph Myers
2015-10-01 16:15 ` Michael Matz
2015-10-01 18:36 ` Jakub Jelinek
2015-10-02 8:18 ` Richard Biener
2015-10-02 9:04 ` Jakub Jelinek
2015-10-02 9:11 ` Richard Biener
2015-10-02 9:27 ` Jakub Jelinek
2015-10-02 9:45 ` Richard Biener
2015-10-02 9:58 ` Jakub Jelinek
2015-10-02 10:07 ` Marek Polacek
2015-10-02 10:24 ` James Greenhalgh
2015-10-02 10:29 ` Marek Polacek
2015-10-02 10:32 ` Richard Biener
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=alpine.LSU.2.20.1510011705500.1349@wotan.suse.de \
--to=matz@suse.de \
--cc=gcc-patches@gcc.gnu.org \
--cc=james.greenhalgh@arm.com \
--cc=pinskia@gmail.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).