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