Guest User

Untitled

a guest
May 22nd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #include <emmintrin.h>
  2. #include <math.h>
  3. #include <stdio.h>
  4. #include <sys/time.h>
  5.  
  6.  
  7. long qftolsse(float f)
  8. {
  9. long retval;
  10.  
  11. __asm__ volatile
  12. (
  13. "cvttss2si %1, %0\n"
  14. : "=r" (retval)
  15. : "x" (f)
  16. );
  17.  
  18. return retval;
  19. }
  20.  
  21.  
  22.  
  23. int main(int argc, char** argv)
  24. {
  25. if (argc != 2)
  26. return 1;
  27. int N = atoi(argv[1]);
  28. float* a;
  29. posix_memalign((void**)&a, 16, N * sizeof(float));
  30.  
  31. //float* b;
  32. //posix_memalign((void**)&b, 16, N * sizeof(float));
  33.  
  34. long* res1 = malloc(N*sizeof(long));
  35. long* res2 = malloc(N*sizeof(long));
  36.  
  37.  
  38. for (int i = 0; i < N; ++i)
  39. a[i] = i + 0.5;
  40.  
  41. {
  42. struct timeval t1,t2;
  43. double timeuse;
  44. gettimeofday(&t1, NULL);
  45.  
  46. for (int i = 0; i < N; ++i)
  47. {
  48. res1[i] = qftolsse(a[i]);
  49. }
  50.  
  51. gettimeofday(&t2, NULL);
  52. timeuse = t2.tv_sec - t1.tv_sec + (t2.tv_usec - t1.tv_usec)/1000000.0;
  53. printf("qftolsse Use Time:%f\n", timeuse);
  54. }
  55. printf("res1[0]=%ld, res1[%d]=%ld\n", res1[0], N-1 ,res1[N-1]);
  56.  
  57.  
  58. {
  59. struct timeval t1,t2;
  60. double timeuse;
  61. gettimeofday(&t1, NULL);
  62. for (int i = 0; i < N; ++i)
  63. {
  64. res2[i] = (long)(a[i]);
  65. }
  66. gettimeofday(&t2, NULL);
  67. timeuse = t2.tv_sec - t1.tv_sec + (t2.tv_usec - t1.tv_usec)/1000000.0;
  68. printf("cast Use Time:%f\n", timeuse);
  69. }
  70.  
  71. printf("res2[0]=%ld, res2[%d]=%ld\n", res2[0], N-1 ,res2[N-1]);
  72.  
  73. }
Add Comment
Please, Sign In to add comment