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
16 static void test_arith_reload_nextcode (SchroArith
*arith
)
21 fixup_range_ref (SchroArith
*arith
)
24 if ((arith
->range
[1] & (1<<15)) == (arith
->range
[0] & (1<<15))) {
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);
34 arith
->range
[0] <<= 1;
35 arith
->range
[1] <<= 1;
39 arith
->code
|= (arith
->nextcode
>> 31);
40 arith
->nextcode
<<= 1;
42 if (arith
->nextbits
== 0) {
43 test_arith_reload_nextcode(arith
);
49 fixup_range_1 (SchroArith
*arith
)
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;
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;
70 arith
->code
|= (arith
->nextcode
>> ((32-n
)&0x1f));
71 arith
->nextcode
<<= n
;
75 arith
->range
[0] ^= flip
;
76 arith
->range
[1] ^= flip
;
81 main (int argc
, char *argv
[])
84 SchroArith
*arith_orig
;
85 SchroArith
*arith_ref
;
86 SchroArith
*arith_test
;
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
++){
98 arith_orig
->nextcode
= 0xaaaa5555;
99 arith_orig
->nextbits
= 32;
103 if (b
<=a
) { int tmp
= b
;b
=a
;a
=tmp
; }
105 if (c
<=b
) { int tmp
= c
;c
=b
;b
=tmp
; }
106 if (b
<=a
) { int tmp
= b
;b
=a
;a
=tmp
; }
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],
124 printf("ref: %04x %04x %04x\n", arith_ref
->range
[0], arith_ref
->range
[1],
126 printf("test: %04x %04x %04x\n", arith_test
->range
[0], arith_test
->range
[1],