This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: ::pow(T, n) vs std::pow(T, n) for non-constant n
- From: Paolo Carlini <pcarlini at suse dot de>
- To: Paolo Carlini <pcarlini at suse dot de>
- Cc: libstdc++ <libstdc++ at gcc dot gnu dot org>,Gabriel Dos Reis <gdr at integrable-solutions dot net>,Richard Guenther <rguenth at tat dot physik dot uni-tuebingen dot de>
- Date: Sun, 14 Mar 2004 13:27:09 +0100
- Subject: Re: ::pow(T, n) vs std::pow(T, n) for non-constant n
- References: <40544D54.6030306@suse.de>
... however, for the very same loop that I used at the beginning:
for (int i = 0; i < 100000000; ++i)
{
double a = M_PI * i;
int n = i % 10;
std::pow(a, n);
//::pow(a, n);
}
With -O2 -ffast-math <- IMPORTANT
::pow
-----
0.090u 0.000s 0:00.09 100.0% 0+0k 0+0io 149pf+0w
std::pow
--------
1.540u 0.000s 0:01.54 100.0% 0+0k 0+0io 149pf+0w
Therefore, in the situation displayed above, gcc + builtin pow,
when requested to do so (-ffast-math) is able to establish the
constness of the argument and use the fast optimized code!!!
For sure, in other, more complex, situations this will not happen,
but when, exactly?
The more I try out the behavior of gcc + builtin pow, the more I
become convinced that, for -ffast-math, is so faster than the current
v3 binary algorithm, otherwise, more accurate.
Paolo.