Sunday, May 14, 2006

Some Superfast Inline functions

The following functions are snippets to calculate trigonometry functions Sine and Cosine using GCC 3.1 or newer. fSinCos calculates sine and cosine simultaneously using FP assembly fsincos.


double fSin(double angle)
{
double _res;
asm ("fld %[angle]\nfsin"
: [output] "=&t" (_res)
: [angle] "0" (angle));
return _res;
}

void fSinCos(double angle, double *rsin, double *rcos)
{
double _arg = angle;
double _rsin, _rcos;
/*
asm ("fsinx %[angle],%[output]"
: [output] "=&t" (result)
: [angle] "f" (angle));
*/
// asm volatile("fld %[angle]" : "=t" (_rsin): [angle] "0" (angle));
asm volatile ("fsincos" : "=%&t" (_rcos), "=%&u" (_rsin) : "0" (angle));
*rsin = _rsin;
*rcos = _rcos;
}

But somehow, the fSinCos function stalls for some numbers. Dunno what it happened. Will post it later once I find the solution.

No comments:

Post a Comment