updated for gcc version
[libfirm] / ir / be / test / max.c
1 #include <stdio.h>
2
3 #define MAX 65536
4 #define MAX_CALC 64
5
6 void dump_field(short *field, int size, const char *name) {
7   int i;
8   printf("======== %s : START ========\n", name);
9   for(i = 0; i < size; i++){
10        printf("data[%i] = %i\n", i, field[i]);
11   }
12   printf("======== %s :  END  ========\n", name);
13 }
14
15 void dequant_h263_inter_c(short *data, const short *coeff, const unsigned int quant) {
16         const unsigned short quant_m_2 = quant << 1;
17         const unsigned short quant_add = (quant & 1 ? quant : quant - 1);
18         int i;
19
20         for (i = 0; i < MAX_CALC; i++) {
21                 short acLevel = coeff[i];
22
23                 if (acLevel == 0) {
24                         data[i] = 0;
25                 } else if (acLevel < 0) {
26                         acLevel = acLevel * quant_m_2 - quant_add;
27                         data[i] = (acLevel > 2048 ? acLevel : 2048);
28                 } else {
29                         acLevel = acLevel * quant_m_2 + quant_add;
30                         data[i] = (acLevel <= 2047 ? acLevel : 2047);
31                 }
32         }
33 }
34
35 int main(int argc){
36   short cur[MAX];
37   short ref[MAX];
38   int numofruns = 1000;
39   int i,ii;
40
41   for (i = 0; i < numofruns; i++){
42     /* Reset cache. Alles andere ist unrealistisch. */
43     for(ii = 0; ii < MAX_CALC; ii++){
44       cur[ii] = 0;
45       ref[ii] = (ii + i + 3) & 0xff;
46     }
47
48         if (i == 0 && argc == 1)
49           dump_field(ref, MAX_CALC, "ref");
50
51         dequant_h263_inter_c(cur, ref, 1024 * (i & 0x3));
52   }
53
54   if (argc == 1)
55     dump_field(cur, MAX_CALC, "cur");
56
57   return 0 ;
58 }