[Bug math/17441] New: isnan() should use __builtin_isnan() in GCC
jzwinck at gmail dot com
sourceware-bugzilla@sourceware.org
Sun Sep 28 04:02:00 GMT 2014
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.
More information about the Glibc-bugs
mailing list