|
- #include <stdio.h>
- #include <math.h>
- #include <sys/time.h>
- int main()
- {
- struct timeval tv1, tv2;
- int timediff;
- int i;
- double x = 0.0,tmp;
- gettimeofday(&tv1, NULL);
- for(i=1;i<20000000;i++){
- tmp = sin(i);
- x += tmp;
- }
- gettimeofday(&tv2, NULL);
- timediff = (tv2.tv_sec - tv1.tv_sec) * 1000000 + (tv2.tv_usec - tv1.tv_usec);
- printf("sse2: x=%e, time = %dn", x, timediff);
- x=0.0;
- gettimeofday(&tv1, NULL);
- asm("finit");
- for(i=1;i<20000000;i++){
- tmp = (double)i;
- asm("fsin" : "=t" (tmp) : "0" (tmp));
- x += tmp;
- }
- gettimeofday(&tv2, NULL);
- timediff = (tv2.tv_sec - tv1.tv_sec) * 1000000 + (tv2.tv_usec - tv1.tv_usec);
- printf("fsin: x=%e, time = %dn", x, timediff);
- return 0;
- }
- [xxxxxx@xxxxxx-desk test]$ icc -O3 -xT -static sin_test2.cpp -o sin2.icc
- sin_test2.cpp(13): (col. 5) remark: LOOP WAS VECTORIZED.
- [xxxxxx@xxxxx-desk test]$ ./sin2.icc
- sse2: x=7.052914e-01, time = 387135
- fsin: x=7.052914e-01, time = 786659
- [xxx@xx-desk ~]$ cat /proc/cpuinfo
- ............
- model name : Intel(R) Core(TM)2 CPU 6700 @ 2.66GHz
- ............
复制代码 :whistling:
[ 本帖最后由 Prescott 于 2007-12-19 16:06 编辑 ] |
|