code for generating mark bit tables
[IRC.git] / Robust / src / Runtime / bamboo / buildprefix.java
1 import java.io.*;
2
3 public class buildprefix {
4
5   public static void main(String xstr[]) {
6     buildprefix bf=new buildprefix();
7     bf.foo(Integer.valueOf(xstr[0]));
8   }
9   boolean prefix=true;
10   int skipbyte=42;
11   int allocunits=2;
12   int max;
13   int maxbits;
14   public void foo(int maxbit) {
15     maxbits=maxbit;
16     max=1<<maxbits;
17     int x[]=new int[max];
18     int value=0;
19     int lastcount=0;
20     int lastindex=0;
21     int lastvalue=0;
22     for(int count=0;count<max;count++) {
23       int numbits=bits(value);
24       int mask=mask(numbits);
25       if ((lastcount&mask)!=(count&mask))
26         value=increment(value);
27       else {
28         lastindex=count;
29         lastvalue=value;
30       }
31
32       x[count]=value;
33       lastcount=count;
34     }
35     System.out.println("lastindex="+lastindex+"   lastvalue="+lastvalue);
36     System.out.print("int markmappingarray[]={");
37     for(int count=0;count<max;count++) {
38       if (count!=0) {
39         System.out.print(", ");
40         
41         if ((count%16)==0) {
42           System.out.println("");
43           System.out.print("                    ");
44         }
45       }
46       System.out.print(x[count]);
47     }
48     System.out.println("};");
49     value=0;
50     for(int count=0;count<max;count++) {
51       if (x[count]>=value) {
52         System.out.println(value+": "+count);
53         if (value==0&&!prefix)
54           value=2;
55         else
56           value++;
57       }
58     }
59
60     System.out.print("int revmarkmappingarray[]={");
61     value=0;
62     int printed=0;
63     for(int count=0;count<max;count++) {
64       if (x[count]>=value) {
65         while(x[count]!=value) {
66           if (value!=0) {
67             System.out.print(", ");
68             if ((printed%16)==0) {
69               System.out.println("");
70               System.out.print("                       ");
71             }
72           }
73           System.out.print("0");
74           printed++;
75           value++;
76         }
77         if (value!=0) {
78           System.out.print(", ");
79
80           if ((printed%16)==0) {
81             System.out.println("");
82             System.out.print("                       ");
83           }
84         }
85         System.out.print(count);
86         printed++;
87         if (value==0&&!prefix)
88           value=2;
89         else
90           value++;
91       }
92     }
93     System.out.println("};");
94
95     System.out.print("int revmarkmappingarray[]={");
96     value=0;
97     printed=0;
98     for(int count=0;count<max;count++) {
99       if (x[count]>=value) {
100         while(x[count]!=value) {
101           if (value!=0) {
102             System.out.print(", ");
103             if ((printed%16)==0) {
104               System.out.println("");
105               System.out.print("                       ");
106             }
107           }
108           System.out.print("0x0");
109           printed++;
110           value++;
111         }
112         if (value!=0) {
113           System.out.print(", ");
114
115           if ((printed%16)==0) {
116             System.out.println("");
117             System.out.print("                       ");
118           }
119         }
120         long valcount=count;
121         System.out.print("0x"+Long.toHexString(valcount<<(32-maxbits)));
122         printed++;
123         if (value==0&&!prefix)
124           value=2;
125         else
126           value++;
127       }
128     }
129     System.out.println("};");
130   }
131
132   int mask(int x) {
133     return ((max-1)>>(maxbits-x))<<(maxbits-x);
134   }
135
136   int bits(int x) {
137     if (x<2)
138       return 2;
139     else {
140       x=x*allocunits;
141       if (x>maxbits)
142         return maxbits;
143       else return x;
144     }
145   }
146
147   int increment(int x) {
148     if (x==0&&!prefix)
149       return x+2;
150     if (x==skipbyte)
151       return x+2;
152     else
153       return x+1;
154   }
155 }