This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/50032] Bad optimization with sin/cos
- From: "rguenth at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 10 Aug 2011 09:03:53 +0000
- Subject: [Bug c/50032] Bad optimization with sin/cos
- Auto-submitted: auto-generated
- References: <bug-50032-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50032
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
--- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-08-10 09:03:53 UTC ---
GCC changes
floatvar = (float) cos ((double) floatvar));
to
floatvar = cosf (floatvar);
if your math library implementation has a slower cosf than cos it's
definitely broken ;)
Then GCC goes along and optimizes
x = cosf (ang)
y = sinf (ang)
to
sincosf (ang, &x, &y)
because again that's not slower (well ... unless you have a broken libm).
Thus, please report to Ubuntu that their sincosf is slower than sincos.
And no, the CPU definitely can do float math faster than double math.
You can disable the optimization via -fno-builtin-sincos
Btw,
float ang = i*j*2*M_PI/N;
is performed in double arithmetic as well, as M_PI is a double constant.
You'll likely get faster code with using
float ang = i*j*2*((float)M_PI)/N;
btw, you didn't specify if you are using 32bit or 64bit code.