Advertisement
stiansjogren

main.c

Jun 11th, 2016
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #include <stdio.h>
  2. #include "stdlib.h"
  3. #include "smmintrin.h"
  4. #include "emmintrin.h"
  5. #include "time.h"
  6. #include "time_meas.h"
  7. #include "math.h"
  8.  
  9. void m16_vv(int16_t *x, int16_t *y, int16_t *z, int N){
  10. __m128i *x128, *y128, *z128;
  11. x128 = (__m128i *)x;
  12. y128 = (__m128i *)y;
  13. z128 = (__m128i *)z;
  14. int i;
  15. for(i=0;i<(N>>3); i++){
  16. z128[i] = _mm_slli_epi16( _mm_mulhi_epi16(x128[i], y128[i]),1);
  17. }
  18. }
  19.  
  20.  
  21.  
  22.  
  23.  
  24. void m16_vv_mulhrs(int16_t *x, int16_t *y, int16_t *z, int N){
  25. __m128i *x128, *y128, *z128;
  26. x128 = (__m128i *)x;
  27. y128 = (__m128i *)y;
  28. z128 = (__m128i *)z;
  29. int i;
  30. for(i=0;i<(N>>3); i++){
  31. z128[i] = _mm_slli_epi16( _mm_mulhrs_epi16(x128[i], y128[i]),1);
  32. }
  33. }
  34.  
  35.  
  36.  
  37.  
  38.  
  39. int main() {
  40.  
  41.  
  42. int16_t x[2048]; int16_t y[2048]; int16_t z[2048];
  43. int i,j;
  44.  
  45.  
  46. time_t t;
  47. /* Intializes random number generator */
  48. srand((unsigned) time(&t));
  49. for( j = 0 ; j < 2048 ; j++ ){
  50. x[j] = rand()%1000;
  51. y[j] = rand()%1000;
  52. z[j] = 0;
  53. }
  54.  
  55. printf("x = [ ");
  56. for( j = 0 ; j < 2048 ; j++ ){
  57. printf("%d, ", x[j]);
  58.  
  59. }
  60. printf(" ] \n");
  61. printf("y = [ ");
  62.  
  63. for( j = 0 ; j < 2048 ; j++ ){
  64. printf("%d, ", y[j]);
  65. }
  66. printf("]\n");
  67.  
  68. m16_vv(x,y,z,2048);
  69. printf("z = [ ");
  70. for (i=0;i<16; i++){
  71. printf("%d, ", z[i]);
  72. }
  73.  
  74. printf(" ]\n");
  75.  
  76. printf("should be ");
  77.  
  78. printf(" = [ ");
  79. for (i=0;i<16; i++){
  80. printf("%d, ", (int)((x[i]*y[i])/pow(2,16)) *2 );
  81. }
  82. printf(" ]\n");
  83. time_stats_t ts;
  84. reset_meas (&ts);
  85. start_meas (&ts);
  86.  
  87. unsigned long long k;
  88. for(k=0;k< 4000000; k++){
  89. m16_vv(x,y,z,2048);
  90.  
  91. }
  92. stop_meas (&ts);
  93. printf("difference: %lld \n", ts.diff);
  94.  
  95. return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement