This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Calculating cosinus/sinus
- From: jacob navia <jacob at jacob dot remcomp dot fr>
- To: Ondřej Bílka <neleai at seznam dot cz>
- Cc: Robert Dewar <dewar at adacore dot com>, gcc at gcc dot gnu dot org, Marc Glisse <marc dot glisse at inria dot fr>
- Date: Sat, 11 May 2013 17:20:20 +0200
- Subject: Re: Calculating cosinus/sinus
- References: <518E0C29 dot 6050204 at jacob dot remcomp dot fr> <alpine dot DEB dot 2 dot 02 dot 1305111128410 dot 3954 at laptop-mg dot saclay dot inria dot fr> <518E1299 dot 80609 at jacob dot remcomp dot fr> <518E48ED dot 70603 at adacore dot com> <20130511140159 dot GA7481 at domone dot kolej dot mff dot cuni dot cz>
- Reply-to: jacob at jacob dot remcomp dot fr
Le 11/05/13 16:01, OndÅej BÃlka a Ãcrit :
As 1) only way is measure that. Compile following an we will see who is
rigth.
cat "
#include <math.h>
int main(){ int i;
double x=0;
double ret=0;
double f;
for(i=0;i<10000000;i++){
ret+=sin(x);
x+=0.3;
}
return ret;
}
" > sin.c
OK I did a similar thing. I just compiled sin(argc) in main.
The results prove that you were right. The single fsin instruction
takes longer than several HUNDRED instructions (calls, jumps
table lookup what have you)
Gone are the times when an fsin would take 30 cycles or so.
Intel has destroyed the FPU.
But is this the case in real code?
The results are around 2 seconds for 100 million sin calculations
and 4 seconds for the same calculations doing fsin.
But the code used for the fsin solutions is just a few bytes,
compared to the several hundred bytes of the sin function,
not counting the table lookups.
In the benchmark code all that code/data is in the L1 cache.
In real life code you use the sin routine sometimes, and
the probability of it not being in the L1 cache is much higher,
I would say almost one if you do not do sin/cos VERY often.
For the time being I will go on generating the fsin code.
I will try to optimize Moshier's SIN function later on.
I suppose this group is for asking this kind of questions. I
thank everyone that answered.
Yours sincerely
Jacob, the developer of lcc-win
(http://www.cs.virginia.edu/~lcc-win32)