This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Calculating cosinus/sinus


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)



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]