syntax for inline assembly of x87 math instructions

syntax for inline assembly of x87 math instructions

What is the proper syntax in the Intel C++ Complier for Windows, integrated into VS.NET 2003, to create an inline function to get the results of FSINCOS?

In GCC syntax I would do something like--

inline float fGetSinCos(float fTheta, float &fSin, float &fCos)
asm ("fsincos" : "=t" (cos), "=u" (sin) : "0" (inp));

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

I would advise against using inline asm and instead call the Intel math library function:

Description: The sincos function returns both the sine and cosine of x measured in radians. Calling interface:

void sincos(double x, double *sinval, double *cosval);
void sincosl(long double x, long double *sinval, long double *cosval);
void sincosf(float x, float *sinval, float *cosval);

It should be optimized for your particular system (P3 or P4) and do a full range argument reduction.

My guess is the asm sequence you are interested in might look something like this:


void sincos(double, double*, double*);
double x,cosine,sine;
x = 0.0;
// Inline asm
fld QWORD PTR [x]
fstp QWORD PTR [cosine]
fstp QWORD PTR [sine]
printf("sin(%e) = %e, cos(%e) = %e
// Using math functions
printf("sin(%e) = %e, cos(%e) = %e

Good luck.

Leave a Comment

Please sign in to add a comment. Not a member? Join today