/* ** x87test.c Program to test x87 inlines. ** ** Willus.com, freely redistributable ** */ #include #include #include #include "x87inline.h" #define LOOPSINCOS(LABEL,XX) \ start=clock(); \ for (sum=0.,j=1;j<20000000;j++) \ { \ XX(5./j,&s,&c); \ sum += s+c; \ } \ stop=clock(); \ printf("%s:\n",LABEL); \ printf(" sum = %20.14e\n",sum); \ printf(" CPU time = %g seconds.\n",(double)(stop-start)/CLOCKS_PER_SEC) #define LOOP1ARG(LABEL,XX) \ start=clock(); \ for (sum=0.,j=10;j<50000000;j++) \ sum += XX(50./j); \ stop=clock(); \ printf("%s:\n",LABEL); \ printf(" sum = %20.14e\n",sum); \ printf(" CPU time = %g seconds.\n",(double)(stop-start)/CLOCKS_PER_SEC) #define LOOP2ARG(LABEL,XX) \ start=clock(); \ for (sum=0.,j=1;j<900;j++) \ for (i=100;i<20000;i++) \ sum += XX((double)j/500.,(double)(1000.-i)/10000.); \ stop=clock(); \ printf("%s:\n",LABEL); \ printf(" sum = %20.14e\n",sum); \ printf(" CPU time = %g seconds.\n",(double)(stop-start)/CLOCKS_PER_SEC) #ifdef exp #undef exp #endif #ifdef pow #undef pow #endif #ifdef sincos #undef sincos #define sincos(th,x,y) { (*(x))=sin(th); (*(y))=cos(th); } #endif #ifdef atan2 #undef atan2 #endif void main(void) { clock_t start,stop; int i,j; double sum,s,c; printf("sincos:\n"); LOOPSINCOS("Default",sincos); LOOPSINCOS("In-line",sincos_x87_inline); printf("\n"); printf("atan2:\n"); LOOP2ARG("Default",atan2); LOOP2ARG("In-line",atan2_x87_inline); printf("\n"); printf("exp:\n"); LOOP1ARG("Default",exp); LOOP1ARG("In-line",exp_x87_inline); printf("\n"); printf("pow:\n"); LOOP2ARG("Default",pow); LOOP2ARG("In-line",pow_x87_inline); }