public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug math/17441] New: isnan() should use __builtin_isnan() in GCC
@ 2014-09-28  4:02 jzwinck at gmail dot com
  2014-09-28  4:03 ` [Bug math/17441] " jzwinck at gmail dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: jzwinck at gmail dot com @ 2014-09-28  4:02 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=17441

            Bug ID: 17441
           Summary: isnan() should use __builtin_isnan() in GCC
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: math
          Assignee: unassigned at sourceware dot org
          Reporter: jzwinck at gmail dot com

Today glibc's math.h defines isnan() this way:

#  define isnan(x) \
     (sizeof (x) == sizeof (float)                          \
      ? __isnanf (x)                                  \
      : sizeof (x) == sizeof (double)                          \
      ? __isnan (x) : __isnanl (x))

This works and is generic, but when compiling with GCC (and perhaps other
compilers) there is a better way:

#  define isnan(x) __builtin_isnan(x)

This is because GCC's builtin function generates a ucomisd+setp instruction
pair inline (on x86), instead of a jump to __isnan().  Given that isnan() is
often called in compute-bound mathematical operations such as loops over
matrices, this seems like a worthwhile optimization wherever __builtin__isnan()
is available.

The libstdc++ shipped with GCC already has <cmath> defining isnan() as a
trivial inline function calling __builtin_isnan().  Due to this, a C++ program
generates more efficient code if it does #include <cmath> than #include
<math.h>.

Some prior discussion of this issue is here:
http://stackoverflow.com/questions/26052640/why-does-gcc-implement-isnan-more-efficiently-for-c-cmath-than-c-math-h

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-09-18 16:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-28  4:02 [Bug math/17441] New: isnan() should use __builtin_isnan() in GCC jzwinck at gmail dot com
2014-09-28  4:03 ` [Bug math/17441] " jzwinck at gmail dot com
2014-09-29 14:49 ` joseph at codesourcery dot com
2015-02-13 21:58 ` jsm28 at gcc dot gnu.org
2015-03-21 10:51 ` jtaylor.debian at googlemail dot com
2015-09-18 15:40 ` cvs-commit at gcc dot gnu.org
2015-09-18 16:34 ` wdijkstr at arm dot com

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).