Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <emmintrin.h>
- #include <math.h>
- #include <stdio.h>
- #include <sys/time.h>
- long qftolsse(float f)
- {
- long retval;
- __asm__ volatile
- (
- "cvttss2si %1, %0\n"
- : "=r" (retval)
- : "x" (f)
- );
- return retval;
- }
- int main(int argc, char** argv)
- {
- if (argc != 2)
- return 1;
- int N = atoi(argv[1]);
- float* a;
- posix_memalign((void**)&a, 16, N * sizeof(float));
- //float* b;
- //posix_memalign((void**)&b, 16, N * sizeof(float));
- long* res1 = malloc(N*sizeof(long));
- long* res2 = malloc(N*sizeof(long));
- for (int i = 0; i < N; ++i)
- a[i] = i + 0.5;
- {
- struct timeval t1,t2;
- double timeuse;
- gettimeofday(&t1, NULL);
- for (int i = 0; i < N; ++i)
- {
- res1[i] = qftolsse(a[i]);
- }
- gettimeofday(&t2, NULL);
- timeuse = t2.tv_sec - t1.tv_sec + (t2.tv_usec - t1.tv_usec)/1000000.0;
- printf("qftolsse Use Time:%f\n", timeuse);
- }
- printf("res1[0]=%ld, res1[%d]=%ld\n", res1[0], N-1 ,res1[N-1]);
- {
- struct timeval t1,t2;
- double timeuse;
- gettimeofday(&t1, NULL);
- for (int i = 0; i < N; ++i)
- {
- res2[i] = (long)(a[i]);
- }
- gettimeofday(&t2, NULL);
- timeuse = t2.tv_sec - t1.tv_sec + (t2.tv_usec - t1.tv_usec)/1000000.0;
- printf("cast Use Time:%f\n", timeuse);
- }
- printf("res2[0]=%ld, res2[%d]=%ld\n", res2[0], N-1 ,res2[N-1]);
- }
Add Comment
Please, Sign In to add comment