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.

Friday, May 12, 2006

Heaven for hobbiest

Recently, my order of some chips had arrived. One package was from Analog-Device Ltd., another one was from Maxim Electronics Ltd. These microchips (various chips, but majority are ADC/DAC) were sent by them for free (yes, it is totally free, including the shipping and handling) as samples.

I was so delighted and cannot wait more to try some projects using these chips. Oh, by the way, I also ordered some components from (this one is not free, of course, but yet they sell components with affordable prices). My first project is to build a parallel-port Oscilloscope.