- fixed comment: bs cannot be NULL anymore (and was never NULL previously)
[libfirm] / ir / be / test / simd2.c
1 #include <stdio.h>
2
3 #define abs(X) (((X)>0)?(X):-(X))
4
5 unsigned int sad16_c(   const unsigned char * const cur,
6                         const unsigned char * const ref,
7                         const unsigned int stride,
8                         const unsigned int best_sad)
9 {
10
11         unsigned int sad = 0;
12         unsigned int j;
13         unsigned char const *ptr_cur = cur;
14         unsigned char const *ptr_ref = ref;
15
16         for (j = 0; j < 16; j++) {
17                         sad += abs(ptr_cur[0] - ptr_ref[0]);
18                         sad += abs(ptr_cur[1] - ptr_ref[1]);
19                         sad += abs(ptr_cur[2] - ptr_ref[2]);
20                         sad += abs(ptr_cur[3] - ptr_ref[3]);
21                         sad += abs(ptr_cur[4] - ptr_ref[4]);
22                         sad += abs(ptr_cur[5] - ptr_ref[5]);
23                         sad += abs(ptr_cur[6] - ptr_ref[6]);
24                         sad += abs(ptr_cur[7] - ptr_ref[7]);
25                         sad += abs(ptr_cur[8] - ptr_ref[8]);
26                         sad += abs(ptr_cur[9] - ptr_ref[9]);
27                         sad += abs(ptr_cur[10] - ptr_ref[10]);
28                         sad += abs(ptr_cur[11] - ptr_ref[11]);
29                         sad += abs(ptr_cur[12] - ptr_ref[12]);
30                         sad += abs(ptr_cur[13] - ptr_ref[13]);
31                         sad += abs(ptr_cur[14] - ptr_ref[14]);
32                         sad += abs(ptr_cur[15] - ptr_ref[15]);
33
34
35                         if (sad >= best_sad)
36                                 return sad;
37
38                         ptr_cur += stride;
39                         ptr_ref += stride;
40
41         }
42
43         return sad;
44
45 }
46
47 int main(int argc, char** argv){
48   unsigned char cur[65536];
49   unsigned char ref[65536];
50   int sum = 0;
51   int numofruns = 100;
52   int i,ii;
53
54   if(argc > 1) {
55           numofruns = atoi(argv[1]);
56   }
57
58   for (i=0;i < numofruns; i++){
59    // Reset cache. Alles andere ist unrealistisch.
60     for(ii = 0; ii<65536;ii++){
61       cur[ii]=ii&0xff;
62       ref[ii]=(ii+4)&0xff;
63     }
64     sum += sad16_c(cur, ref, 64, 100000);
65   }
66   printf("sum = %i\n", sum);
67   return 0 ;
68 }