[encoder] Added 1/8th pel MV refinement
[schroedinger/research-port.git] / testsuite / arith_fixup_shift.c
blob7427a5fa89d00cdaaa76c3d02aabd36f853a2c0f
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <schroedinger/schro.h>
6 #include <schroedinger/schroarith.h>
7 #include <schroedinger/schrotables.h>
9 #include <liboil/liboilprofile.h>
10 #include <liboil/liboilrandom.h>
12 #define BUFFER_SIZE 10000
14 int debug=1;
16 static void test_arith_reload_nextcode (SchroArith *arith)
20 static void
21 fixup_range_ref (SchroArith *arith)
23 do {
24 if ((arith->range[1] & (1<<15)) == (arith->range[0] & (1<<15))) {
25 /* do nothing */
26 } else if ((arith->range[0] & (1<<14)) && !(arith->range[1] & (1<<14))) {
27 arith->code ^= (1<<14);
28 arith->range[0] ^= (1<<14);
29 arith->range[1] ^= (1<<14);
30 } else {
31 break;
34 arith->range[0] <<= 1;
35 arith->range[1] <<= 1;
36 arith->range[1]++;
38 arith->code <<= 1;
39 arith->code |= (arith->nextcode >> 31);
40 arith->nextcode <<= 1;
41 arith->nextbits--;
42 if (arith->nextbits == 0) {
43 test_arith_reload_nextcode(arith);
45 } while (1);
48 static void
49 fixup_range_1 (SchroArith *arith)
51 int i;
52 int n;
53 int flip;
55 do {
56 //printf("got: %04x %04x %04x\n", arith->range[0], arith->range[1], arith->code);
57 i = ((arith->range[1]&0xf000)>>8) | ((arith->range[0]&0xf000)>>12);
58 //printf("i %02x\n", i);
60 n = schro_table_arith_shift[i] & 0xf;
61 if (n == 0) return;
62 flip = schro_table_arith_shift[i] & 0x8000;
63 //printf("n,flip %d %d\n", n, flip);
65 arith->range[0] <<= n;
66 arith->range[1] <<= n;
67 arith->range[1] |= (1<<n)-1;
69 arith->code <<= n;
70 arith->code |= (arith->nextcode >> ((32-n)&0x1f));
71 arith->nextcode <<= n;
72 arith->nextbits-=n;
74 arith->code ^= flip;
75 arith->range[0] ^= flip;
76 arith->range[1] ^= flip;
77 } while(n >= 3);
80 int
81 main (int argc, char *argv[])
83 int i;
84 SchroArith *arith_orig;
85 SchroArith *arith_ref;
86 SchroArith *arith_test;
87 int fail = 0;
89 schro_init();
91 arith_orig = schro_arith_new();
92 arith_ref = schro_arith_new();
93 arith_test = schro_arith_new();
95 for(i=0;i<1000000;i++){
96 int a,b,c;
98 arith_orig->nextcode = 0xaaaa5555;
99 arith_orig->nextbits = 32;
100 do {
101 a = rand() & 0xffff;
102 b = rand() & 0xffff;
103 if (b<=a) { int tmp = b;b=a;a=tmp; }
104 c = rand() & 0xffff;
105 if (c<=b) { int tmp = c;c=b;b=tmp; }
106 if (b<=a) { int tmp = b;b=a;a=tmp; }
107 } while (c-a < 1);
108 arith_orig->range[0] = a;
109 arith_orig->code = b;
110 arith_orig->range[1] = c;
112 memcpy (arith_ref, arith_orig, sizeof(*arith_orig));
113 fixup_range_ref (arith_ref);
115 memcpy (arith_test, arith_orig, sizeof(*arith_orig));
116 fixup_range_1 (arith_test);
118 if (arith_ref->range[0] != arith_test->range[0] ||
119 arith_ref->range[1] != arith_test->range[1] ||
120 arith_ref->code != arith_test->code ||
121 arith_ref->nextcode != arith_test->nextcode) {
122 printf("orig: %04x %04x %04x\n", arith_orig->range[0], arith_orig->range[1],
123 arith_orig->code);
124 printf("ref: %04x %04x %04x\n", arith_ref->range[0], arith_ref->range[1],
125 arith_ref->code);
126 printf("test: %04x %04x %04x\n", arith_test->range[0], arith_test->range[1],
127 arith_test->code);
128 fail = 1;
132 return fail;