From: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
To: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Cc: 'GNU C Library' <libc-alpha@sourceware.org>
Subject: [PATCH v2 3/9] math: Simplify hypotf implementation
Date: Thu, 28 Oct 2021 14:27:09 +0000 [thread overview]
Message-ID: <VE1PR08MB559962EBD2B3517D4C54515783869@VE1PR08MB5599.eurprd08.prod.outlook.com> (raw)
Hi Adhemerval,
+ if ((isinf (x) || isinf (y))
+ && !issignaling (x) && !issignaling (y))
+ return INFINITY;
+ if (isnan (x) || isnan (y))
+ return x + y;
These checks are inefficient. It's partly because GCC uses FP comparisons for
isinf/isnan when integer arithmetic is faster on almost all targets and more
correct for signaling NaNs. However GCC doesn't seem to treat these as
unlikely and so there are 3 comparisons and 3 taken branches before entering
the main code. If you change it to:
if (!isfinite (x) || !isfinite (y))
{
if ((isinf (x) || isinf (y))
&& !issignaling (x) && !issignaling (y))
return INFINITY;
return x + y;
}
then it uses only 2 comparisons and we fallthrough into the common case.
This gives a speedup of 10%.
Wilco
next reply other threads:[~2021-10-28 14:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-28 14:27 Wilco Dijkstra [this message]
-- strict thread matches above, loose matches on Subject: below --
2021-10-25 11:57 [PATCH v2 0/9] Improve hypot() Adhemerval Zanella
2021-10-25 11:57 ` [PATCH v2 3/9] math: Simplify hypotf implementation Adhemerval Zanella
2021-10-22 20:48 [PATCH v2 0/9] Improve hypot() Adhemerval Zanella
2021-10-22 20:48 ` [PATCH v2 3/9] math: Simplify hypotf implementation Adhemerval Zanella
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=VE1PR08MB559962EBD2B3517D4C54515783869@VE1PR08MB5599.eurprd08.prod.outlook.com \
--to=wilco.dijkstra@arm.com \
--cc=adhemerval.zanella@linaro.org \
--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).