public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "svfuerst at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/44053] "benchmark" function attribute.
Date: Mon, 10 May 2010 22:45:00 -0000	[thread overview]
Message-ID: <20100510224454.25956.qmail@sourceware.org> (raw)
In-Reply-To: <bug-44053-18995@http.gcc.gnu.org/bugzilla/>



------- Comment #7 from svfuerst at gmail dot com  2010-05-10 22:44 -------
Perhaps an example usage helps:

The __float128 version of isnan() is rather slow.  Trying different
implmentations to see which is faster required some benchmarking.  However,
implementing the benchmark code requires an increasing number of work-arounds
as gcc will rightly optimize everything away if given the chance to do so. 
This required using the result of that function/macro in some way, the simplest
being to sum them, and print the result.  The problem is that for the faster
code, the overhead of the addition starts to perturb the results.  In addition,
an increasing number of function attributes are required to make sure the
function wasn't cloned/inlined/elided as gcc version number increases.

However, this isn't enough.  It is conceivable that eventually gcc will be
smart enough to completely understand the benchmarked function enough to
replace the summation loop + printf with a single puts("result");  This is
allowable since the internal state of the abstract machine is never used, only
its output.  For timing purposes, this is a disaster.  (This doesn't happen for
the isnan() currently, but does for other simpler functions.)

In short, it would be really nice if there was a way to tell gcc that there is
a hidden side effect of a function that is important: the total time taken due
to calling it.  Such an attribute may only be a combination of other
attributes, but given the history of the compiler, the number of component
attributes will increase with time, and is already an unwieldy number.

Anyway, the result of much benchmarking shows that:
#include <emmintrin.h>
static __attribute__((noinline)) int fastisnan(__float128 x)
{
        __m128i c1 = {0xffffffffffffffffull, 0x7fffffffffffffffull};
        __m128i c2 = {0x7fff7fff7fff7fffull, 0x00017fff7fff7fffull};
        __m128i x2 = *(__m128i *) &x;

        x2 &= c1;
        x2 = _mm_adds_epu16(c2, x2);
        return (_mm_movemask_epi8(x2) & 0xaaaa) > 0x8000;
}
is an order of magnitude faster than the current isnan() implementation for
__float128 on x86_64.  Similar improvements exist for isinf() and fpclassify()


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44053


  parent reply	other threads:[~2010-05-10 22:45 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-10  6:27 [Bug middle-end/44053] New: " svfuerst at gmail dot com
2010-05-10  6:36 ` [Bug middle-end/44053] " svfuerst at gmail dot com
2010-05-10  6:55 ` steven at gcc dot gnu dot org
2010-05-10  9:13 ` rguenth at gcc dot gnu dot org
2010-05-10 11:01 ` steven at gcc dot gnu dot org
2010-05-10 14:53 ` svfuerst at gmail dot com
2010-05-10 22:04 ` pinskia at gcc dot gnu dot org
2010-05-10 22:45 ` svfuerst at gmail dot com [this message]
2010-05-10 22:50 ` pinskia at gcc dot gnu dot org
2010-05-10 23:27 ` svfuerst at gmail dot com

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=20100510224454.25956.qmail@sourceware.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.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).