Math Performance(exp)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I am calling the exp function in a tight loop, a little over 238 million
times. As expected, it takes a while, but it seemed to take longer than
necessary, so I was looking into this. What I found was that if I call
exp as I am with a single precision floating point value:

exp( myFloat );

it takes a long time, but if I cast my single precision value to a
double:

exp( double(myFloat) );

it takes about 1/3 of the time to execute. This is fantastic, but I need
to know why this works so I can fix my code to use this as well as
updating any other code that might benefit from this change.

Here are the relevent build and link flags that I am using:

CLINTFLAGS=-Wstrict-prototypes -Wmissing-prototypes -Wbad-function-cast
-Wnested-externs
CXXLINTFLAGS=-W -Wpointer-arith -Wreturn-type -Wcast-qual
-Wwrite-strings -Wswitch -Wcast-align -Wuninitialized -Wchar-subscripts
-Wno-unused-parameter -Wno-comment

CFLAGS=-march=k8 -Winvalid-pch -Wall -fPIC -fopenmp -pipe
$(LOCAL_CFLAGS) $(INCLUDES) $(DEFINES)
C_OPT_FLAGS=-O3 -funroll-all-loops -fpeel-loops -fno-schedule-insns2 
CXXFLAGS=$(CFLAGS)
LD=$(CXX) $(CXXFLAGS)
LIBS=$(LIB_DIRS) $(LOCAL_LIBS) -lm -lstdc++


I did use gprof to profile this code. In both cases it claims that I am
calling std::exp(float). I doubt this can be correct. I have also tried
the -ffast-math flag to no effect. I am in the process of using readelf
and nm to try to find the exp function that I am actually linking to,
but that is going slowly, so any pointers would be great. Along these
lines, I believe that the fast exp may be from a non-standard library,
but I have not been able to find which one. readelf says that that I am
getting exp from GLIBC_2.2.5. It mentions exp, expf, ldexp and frexp. I
don't have any really good idea on what to do with this information just
yet.


GCC and kernel version:
gcc version 4.1.1 20070105 (Red Hat 4.1.1-53)
Red Hat Enterprise Linux 4 (2.6.9-55.0.2.ELsmp)
AMD Opteron

Any help would be greatly appriciated.

Thanks,

David Blankenship
KLA-Tencor


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux