annotate mc-switch.c @ 935:7672a37e7545 default tip

Raspbery PI ARM support begin
author kono
date Sat, 24 Dec 2016 03:02:57 +0000
parents 5313ed059cee
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
1 /* Micro-C Switch Code generation Part */
607
e055df7c1082 *** empty log message ***
kono
parents: 592
diff changeset
2
e055df7c1082 *** empty log message ***
kono
parents: 592
diff changeset
3 /************************************************************************
e055df7c1082 *** empty log message ***
kono
parents: 592
diff changeset
4 ** Copyright (C) 2006 Shinji Kono
e055df7c1082 *** empty log message ***
kono
parents: 592
diff changeset
5 ** 連絡先: 琉球大学情報工学科 河野 真治
e055df7c1082 *** empty log message ***
kono
parents: 592
diff changeset
6 ** (E-Mail Address: kono@ie.u-ryukyu.ac.jp)
e055df7c1082 *** empty log message ***
kono
parents: 592
diff changeset
7 **
e055df7c1082 *** empty log message ***
kono
parents: 592
diff changeset
8 ** このソースのいかなる複写,改変,修正も許諾します。ただし、
e055df7c1082 *** empty log message ***
kono
parents: 592
diff changeset
9 ** その際には、誰が貢献したを示すこの部分を残すこと。
e055df7c1082 *** empty log message ***
kono
parents: 592
diff changeset
10 ** 再配布や雑誌の付録などの問い合わせも必要ありません。
e055df7c1082 *** empty log message ***
kono
parents: 592
diff changeset
11 ** 営利利用も上記に反しない範囲で許可します。
e055df7c1082 *** empty log message ***
kono
parents: 592
diff changeset
12 ** バイナリの配布の際にはversion messageを保存することを条件とします。
e055df7c1082 *** empty log message ***
kono
parents: 592
diff changeset
13 ** このプログラムについては特に何の保証もしない、悪しからず。
e055df7c1082 *** empty log message ***
kono
parents: 592
diff changeset
14 **
e055df7c1082 *** empty log message ***
kono
parents: 592
diff changeset
15 ** Everyone is permitted to do anything on this program
e055df7c1082 *** empty log message ***
kono
parents: 592
diff changeset
16 ** including copying, modifying, improving,
e055df7c1082 *** empty log message ***
kono
parents: 592
diff changeset
17 ** as long as you don't try to pretend that you wrote it.
e055df7c1082 *** empty log message ***
kono
parents: 592
diff changeset
18 ** i.e., the above copyright notice has to appear in all copies.
e055df7c1082 *** empty log message ***
kono
parents: 592
diff changeset
19 ** Binary distribution requires original version messages.
e055df7c1082 *** empty log message ***
kono
parents: 592
diff changeset
20 ** You don't have to ask before copying, redistribution or publishing.
e055df7c1082 *** empty log message ***
kono
parents: 592
diff changeset
21 ** THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE.
e055df7c1082 *** empty log message ***
kono
parents: 592
diff changeset
22 ***********************************************************************/
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
23
327
da2e3f2d127d macro/codegen reorganization
kono
parents: 326
diff changeset
24 #include <stdio.h>
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
25 #include "mc.h"
327
da2e3f2d127d macro/codegen reorganization
kono
parents: 326
diff changeset
26 #include "mc-parse.h"
da2e3f2d127d macro/codegen reorganization
kono
parents: 326
diff changeset
27 #include "mc-codegen.h"
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
28 #include "mc-code.h"
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
29
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
30 #if CASE_CODE
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
31
299
3d260008c449 level 2 looks ok.
kono
parents: 298
diff changeset
32 extern void genswitch(int cslist,int cslabel);
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
33
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
34 /*
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
35 value label pair
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
36 cslist = list3(value,next,label) label==0 means skip
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
37 continuous cslist
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
38 chunks: list4(cslist,next,delta,list3(count,min,max))
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
39 mergeable chunks count list
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
40 merge: list4(continuous number of chunk,next,delta,case_count);
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
41 index list
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
42 index: list4(label,next,max,min);
645
595763d38ee7 *** empty log message ***
kono
parents: 623
diff changeset
43
595763d38ee7 *** empty log message ***
kono
parents: 623
diff changeset
44
595763d38ee7 *** empty log message ***
kono
parents: 623
diff changeset
45
595763d38ee7 *** empty log message ***
kono
parents: 623
diff changeset
46 A list of value label pair is generated in do_case, in sorted list.
595763d38ee7 *** empty log message ***
kono
parents: 623
diff changeset
47
595763d38ee7 *** empty log message ***
kono
parents: 623
diff changeset
48 The list is separated in continous cslists which has a same
595763d38ee7 *** empty log message ***
kono
parents: 623
diff changeset
49 delta in make_chunk(int cslist).
595763d38ee7 *** empty log message ***
kono
parents: 623
diff changeset
50
595763d38ee7 *** empty log message ***
kono
parents: 623
diff changeset
51 merge_chunk(int chunks) tries to findout possible merge of continous
595763d38ee7 *** empty log message ***
kono
parents: 623
diff changeset
52 cslist. If merge_chunk_p() accepts reasonably densed switch talbe,
595763d38ee7 *** empty log message ***
kono
parents: 623
diff changeset
53 the cslists are merged.
595763d38ee7 *** empty log message ***
kono
parents: 623
diff changeset
54
595763d38ee7 *** empty log message ***
kono
parents: 623
diff changeset
55 switch_index() makes hierachical indexed branches, using switch_leaf().
595763d38ee7 *** empty log message ***
kono
parents: 623
diff changeset
56 switch_leaf(). switch_leaf() generates table jump if it is suitable.
595763d38ee7 *** empty log message ***
kono
parents: 623
diff changeset
57 Otherwise it generates multi-stage cascading jump. siwtch_make_index()
595763d38ee7 *** empty log message ***
kono
parents: 623
diff changeset
58 generates multi-stage index in a recursive way.
595763d38ee7 *** empty log message ***
kono
parents: 623
diff changeset
59
595763d38ee7 *** empty log message ***
kono
parents: 623
diff changeset
60
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
61 */
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
62
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
63 #define chunk_max(chunks) caddr(cadddr(chunks))
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
64 #define chunk_min(chunks) cadr(cadddr(chunks))
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
65 #define index_max(index) caddr(index)
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
66 #define index_min(index) cadddr(index)
298
4ccacae1d2e6 switch index level=1 odd situation.
kono
parents: 297
diff changeset
67 #define index_label(index) car(index)
4ccacae1d2e6 switch index level=1 odd situation.
kono
parents: 297
diff changeset
68
300
86255dd7f148 table done. (?)
kono
parents: 299
diff changeset
69 #define CASE_TABLE_COUNT 10
302
bea7ab2fb218 switch table jump finished.
kono
parents: 300
diff changeset
70 #define CASE_INDEX_COUNT CASE_TABLE_COUNT // have to be equal
298
4ccacae1d2e6 switch index level=1 odd situation.
kono
parents: 297
diff changeset
71
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 327
diff changeset
72 static int djmp;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 327
diff changeset
73
93652cda75c7 minor speed up (macro/switch)
kono
parents: 327
diff changeset
74 static void
93652cda75c7 minor speed up (macro/switch)
kono
parents: 327
diff changeset
75 check_djmp()
93652cda75c7 minor speed up (macro/switch)
kono
parents: 327
diff changeset
76 {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 327
diff changeset
77 if (control && dlabel && djmp)
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
78 jmp(dlabel);
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 327
diff changeset
79 djmp = 0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 327
diff changeset
80 }
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
81
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
82 /*
326
e5d40f8c4cce bit-field continue.
kono
parents: 312
diff changeset
83 group continuous case value
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
84 */
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
85
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
86 static int
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
87 make_chunk(int cslist)
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
88 {
303
88e20739e64c register variable initialization fix
kono
parents: 302
diff changeset
89 register int delta,delta1,list,p,count;
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
90 // cslist is already sorted
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
91 delta = 0;
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
92 list = list4(cslist,0,1,list3(0,car(cslist) /* min */,0));
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
93 count=1;
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
94 for(p=0;cadr(cslist);cslist = cadr(cslist),count++) {
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
95 // compute new delta
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
96 delta1 = car(cadr(cslist))-car(cslist);
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
97 // empty case
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
98 if (!caddr(cslist)) count--;
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
99 if (delta==0) {
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
100 // 2nd element
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
101 caddr(list) = delta = delta1;
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
102 if (p) cadr(p)=0; // terminate previous chunk
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
103 } else if (delta1!=delta) {
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
104 // not contiguous, start new list
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
105 caddr(cadddr(list)) = car(cslist); // max
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
106 car(cadddr(list)) = count; count=0;
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
107 delta = 0;
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
108 list = list4(cadr(cslist),list,1,list3(0,0,0));
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
109 cadr(cadddr(list)) = car(cadr(cslist)); // min
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
110 // prepare terminate point for next turn
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
111 p=cslist;
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
112 }
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
113 }
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
114 if (p) cadr(p)=0; // terminate previous chunk
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
115 car(cadddr(list)) = count;
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
116 caddr(cadddr(list)) = car(cslist); // max
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
117 return list;
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
118 }
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
119
592
259a53737e25 a little tosop optimization.
kono
parents: 569
diff changeset
120 #define CASE_MERGE_RATE 50
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
121
303
88e20739e64c register variable initialization fix
kono
parents: 302
diff changeset
122 static int gcd(int i0,int j0)
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
123 {
303
88e20739e64c register variable initialization fix
kono
parents: 302
diff changeset
124 register int k,i=i0,j=j0;
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
125 if (i<j) { k=i; i=j; j=k;}
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
126 for(;;) {
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
127 if ((k=i%j)==0) return j;
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
128 i = j; j = k;
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
129 }
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
130 }
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
131
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
132 /*
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
133 check two chunks are mergeable or not.
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
134 */
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
135
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
136 static int
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
137 merge_chunk_p(int *delta,int max,int min,int *count,int delta1,int count1)
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
138 {
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
139 int range = max-min;
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
140 int g;
623
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 609
diff changeset
141 int c = 128*CASE_MERGE_RATE/100;
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
142 // compute possible merge delta
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
143 g = gcd(*delta,delta1);
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
144 g = gcd(g,range);
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
145 range /= g;
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
146 *count = count1 = count1+*count;
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
147 *delta = g;
311
38c9976863b7 swtich list fix. macro fix.
kono
parents: 303
diff changeset
148 #if 0
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
149 if (count1*128>(range*128*CASE_MERGE_RATE/100)) {
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
150 if (lsrc) printf("## min %d, max %d, count %d, delta %d, rate %g t=%d\n",
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
151 min,max,count1,g,
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
152 ((double)count1)*100.0/range,
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
153 count1*128>(range*128*CASE_MERGE_RATE/100)
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
154 );
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
155 }
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
156 #endif
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
157 // count/((max-min)/delta) > 0.8
623
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 609
diff changeset
158 return count1*128>(range*c);
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
159 }
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
160
311
38c9976863b7 swtich list fix. macro fix.
kono
parents: 303
diff changeset
161 static void
468
464e7480395c *** empty log message ***
kono
parents: 458
diff changeset
162 free_chunks(int chunks)
311
38c9976863b7 swtich list fix. macro fix.
kono
parents: 303
diff changeset
163 {
38c9976863b7 swtich list fix. macro fix.
kono
parents: 303
diff changeset
164 int p;
38c9976863b7 swtich list fix. macro fix.
kono
parents: 303
diff changeset
165 while(chunks) {
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
166 p = car(chunks);
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
167 chunks = cadr(chunks); // free_glist3 will destroy cadr
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
168 free_glist3(p);
311
38c9976863b7 swtich list fix. macro fix.
kono
parents: 303
diff changeset
169 }
38c9976863b7 swtich list fix. macro fix.
kono
parents: 303
diff changeset
170 }
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
171
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
172 static int
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
173 merge_chunk(int chunks)
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
174 {
303
88e20739e64c register variable initialization fix
kono
parents: 302
diff changeset
175 register int list = chunks;
88e20739e64c register variable initialization fix
kono
parents: 302
diff changeset
176 register int tail,last,max,min,i;
88e20739e64c register variable initialization fix
kono
parents: 302
diff changeset
177 register int c_count,p,widest;
88e20739e64c register variable initialization fix
kono
parents: 302
diff changeset
178 register int merge = 0;
88e20739e64c register variable initialization fix
kono
parents: 302
diff changeset
179 int count,delta=1;
88e20739e64c register variable initialization fix
kono
parents: 302
diff changeset
180
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
181 while(cadr(list)) {
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
182 p = cadddr(list);
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
183 c_count = count = car(p); max=caddr(p);
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
184 widest = 1; last = list;
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
185 delta = caddr(list);
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
186 // check possible merge against the end of the chunks
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
187 for(i=1,tail=cadr(list);cadr(tail); tail=cadr(tail),i++) {
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
188 p = cadddr(tail);
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
189 min = cadr(p);
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
190 if (merge_chunk_p(&delta,max,min,&count,caddr(tail),car(p))) {
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
191 // It is mergeable.
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
192 widest = i+1; last = tail; c_count=count;
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
193 }
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
194 }
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
195 merge = list4(widest,merge,delta,c_count);
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
196 // skip merged chunks
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
197 list = cadr(last);
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
198 }
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
199 // last one can remain.
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
200 if (list) merge = list4(1,merge,caddr(list),car(cadddr(list)));
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
201 return merge;
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
202 }
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
203
645
595763d38ee7 *** empty log message ***
kono
parents: 623
diff changeset
204 /*
595763d38ee7 *** empty log message ***
kono
parents: 623
diff changeset
205 Generates series of compare immideate. It is suitable for
595763d38ee7 *** empty log message ***
kono
parents: 623
diff changeset
206 small amount of jump and random value.
595763d38ee7 *** empty log message ***
kono
parents: 623
diff changeset
207 */
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
208 static int
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
209 cascade_compare(int count,int cslist)
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
210 {
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
211 int list;
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
212 for(;count-->0;cslist=cadr(cslist)) {
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
213 list = car(cslist);
609
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
214 #ifdef DEBUG_MERGE
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
215 if (lsrc) printf("## cascade cases delta=%d count=%d min=%d max=%d\n",
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
216 caddr(cslist),car(cadddr(cslist)),
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
217 cadr(cadddr(cslist)),caddr(cadddr(cslist))
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
218 );
609
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
219 #endif
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
220 for(;list; list=cadr(list)) {
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
221 if (caddr(list))
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
222 cmpdimm(car(list),csvalue1,caddr(list),0);
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
223 // value register label mode
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
224 }
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
225 }
302
bea7ab2fb218 switch table jump finished.
kono
parents: 300
diff changeset
226 // have to be fall thru
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
227 return cslist;
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
228 }
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
229
645
595763d38ee7 *** empty log message ***
kono
parents: 623
diff changeset
230 /*
595763d38ee7 *** empty log message ***
kono
parents: 623
diff changeset
231 Make table jump code, suitable for fixed delta and large size
595763d38ee7 *** empty log message ***
kono
parents: 623
diff changeset
232 table.
595763d38ee7 *** empty log message ***
kono
parents: 623
diff changeset
233 */
300
86255dd7f148 table done. (?)
kono
parents: 299
diff changeset
234 static int
86255dd7f148 table done. (?)
kono
parents: 299
diff changeset
235 table_jump(int count,int delta,int chunks)
86255dd7f148 table done. (?)
kono
parents: 299
diff changeset
236 {
86255dd7f148 table done. (?)
kono
parents: 299
diff changeset
237 int list,i;
569
1fcad06b264a gcc4 (ia32)
kono
parents: 468
diff changeset
238 int l,max=0,min;
382
832e1f6bba82 ARM wrote all code. Check compile error.
kono
parents: 361
diff changeset
239 if (!code_table_jump_p(delta))
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
240 return cascade_compare(count,chunks);
300
86255dd7f148 table done. (?)
kono
parents: 299
diff changeset
241
86255dd7f148 table done. (?)
kono
parents: 299
diff changeset
242 min=cadr(cadddr(chunks));
86255dd7f148 table done. (?)
kono
parents: 299
diff changeset
243 // find max
86255dd7f148 table done. (?)
kono
parents: 299
diff changeset
244 for(i=0,list=chunks;i<count;list=cadr(list),i++) {
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
245 max=caddr(cadddr(list));
300
86255dd7f148 table done. (?)
kono
parents: 299
diff changeset
246 }
86255dd7f148 table done. (?)
kono
parents: 299
diff changeset
247
652
f9d86da34600 *** empty log message ***
kono
parents: 645
diff changeset
248 if (lsrc) printf("## table count %d delta %d max %d min %d\n",
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
249 count,delta,max,min);
300
86255dd7f148 table done. (?)
kono
parents: 299
diff changeset
250
86255dd7f148 table done. (?)
kono
parents: 299
diff changeset
251 l = fwdlabel();
458
0bc9f3273aa7 *** empty log message ***
kono
parents: 456
diff changeset
252 if (car(csvalue1)!=REGISTER) error(-1);
0bc9f3273aa7 *** empty log message ***
kono
parents: 456
diff changeset
253 code_table_jump(l,cadr(csvalue1),delta,max,min,dlabel);
302
bea7ab2fb218 switch table jump finished.
kono
parents: 300
diff changeset
254 control=0;
300
86255dd7f148 table done. (?)
kono
parents: 299
diff changeset
255 code_table_open(l);
86255dd7f148 table done. (?)
kono
parents: 299
diff changeset
256 i = min;
86255dd7f148 table done. (?)
kono
parents: 299
diff changeset
257 for(;count-->0;chunks=cadr(chunks)) {
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
258 list = car(chunks);
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
259 for(;list; list=cadr(list)) {
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
260 if (caddr(list)) {
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
261 for(;i<car(list);i+=delta) {
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
262 code_table_value(dlabel,l);
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
263 }
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
264 code_table_value(caddr(list),l);
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
265 i+=delta;
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
266 }
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
267 }
300
86255dd7f148 table done. (?)
kono
parents: 299
diff changeset
268 }
86255dd7f148 table done. (?)
kono
parents: 299
diff changeset
269 code_table_close();
86255dd7f148 table done. (?)
kono
parents: 299
diff changeset
270 return chunks;
86255dd7f148 table done. (?)
kono
parents: 299
diff changeset
271 }
86255dd7f148 table done. (?)
kono
parents: 299
diff changeset
272
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
273
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
274 /*
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
275 generate index jmp
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
276 */
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
277
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
278 static void
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
279 switch_index_jmp(int index,int label)
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
280 {
298
4ccacae1d2e6 switch index level=1 odd situation.
kono
parents: 297
diff changeset
281 int value = index_min(index);
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
282 cmpdimm(value,csvalue1,label,LT);
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
283 // value register label mode
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
284 }
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
285
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
286 /*
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
287 generate leaf index branch
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
288 */
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
289
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
290 static int
298
4ccacae1d2e6 switch index level=1 odd situation.
kono
parents: 297
diff changeset
291 switch_make_index_leaf(int count,int index,int level)
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
292 {
298
4ccacae1d2e6 switch index level=1 odd situation.
kono
parents: 297
diff changeset
293 control=1;
652
f9d86da34600 *** empty log message ***
kono
parents: 645
diff changeset
294 if (lsrc) printf("## index leaf count=%d level=%d\n",count,level);
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
295 for(;count-- !=0 && cadr(index);index=cadr(index)) {
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
296 switch_index_jmp( cadr(index), index_label(index) );
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
297 }
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
298 if (!cadr(index)) {
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
299 // don't check max boundary
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
300 jmp(index_label(index));
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
301 return 0;
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
302 }
298
4ccacae1d2e6 switch index level=1 odd situation.
kono
parents: 297
diff changeset
303 if (count!= -1) error(-1);
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 327
diff changeset
304 djmp = 1;
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
305 return index;
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
306 }
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
307
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
308 /*
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
309 generate index switch branch (no table).
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
310 if necessary generate higher index.
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
311 */
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
312
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
313 static void
299
3d260008c449 level 2 looks ok.
kono
parents: 298
diff changeset
314 switch_make_index(int index0,int count,int cslabel,int gmax,int level)
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
315 {
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
316 int index=0;
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
317 int icount=0;
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
318 int l,min,max;
298
4ccacae1d2e6 switch index level=1 odd situation.
kono
parents: 297
diff changeset
319 control=1;
299
3d260008c449 level 2 looks ok.
kono
parents: 298
diff changeset
320 if (count <= CASE_INDEX_COUNT) {
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
321 check_djmp();
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
322 fwddef(cslabel);
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
323 switch_make_index_leaf(-1,index0,level);
299
3d260008c449 level 2 looks ok.
kono
parents: 298
diff changeset
324 } else {
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
325 // too large index, make hihger index
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
326 while (index0) {
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
327 check_djmp();
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
328 l = backdef();
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
329 min = index_min(index0);
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
330 index0=switch_make_index_leaf(CASE_INDEX_COUNT,index0,level);
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
331 if (index0) {
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
332 max = index_min(index0)-1;
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
333 } else {
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
334 max = gmax;
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
335 }
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
336 index = list4(l,index,max,min);
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
337 count-=CASE_INDEX_COUNT;
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
338 icount++;
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
339 }
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
340 // process higher indexes in a recursive way
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
341 switch_make_index(reverse0(index),icount,cslabel,gmax,level+1);
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
342 }
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
343 }
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
344
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
345 /*
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
346 generate leaf switch branch or table jump
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
347 */
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
348
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
349 static int
300
86255dd7f148 table done. (?)
kono
parents: 299
diff changeset
350 switch_leaf(int count,int merge,int chunks)
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
351 {
298
4ccacae1d2e6 switch index level=1 odd situation.
kono
parents: 297
diff changeset
352 control=1;
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
353 for(;count-- !=0 && merge;merge=cadr(merge)) {
609
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
354 #ifdef DEBUG_MERGE
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
355 if (lsrc) printf("## merge count %d delta %d c_count %d\n",
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
356 car(merge),caddr(merge),cadddr(merge));
609
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
357 #endif
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
358 if (cadddr(merge)>CASE_TABLE_COUNT) {
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
359 chunks = table_jump(car(merge),caddr(merge),chunks);
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
360 } else {
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
361 chunks = cascade_compare(car(merge),chunks);
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
362 }
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
363 }
302
bea7ab2fb218 switch table jump finished.
kono
parents: 300
diff changeset
364 // table_jump has no fall thru, but cascade_compare does.
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 327
diff changeset
365 if (control) djmp = 1;
300
86255dd7f148 table done. (?)
kono
parents: 299
diff changeset
366 return chunks;
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
367 }
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
368
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
369 /*
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
370 make index if necessary or
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
371 generate case branch or table jump
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
372 */
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
373
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
374 static void
299
3d260008c449 level 2 looks ok.
kono
parents: 298
diff changeset
375 switch_index(int merge,int chunks,int cslabel,int gmax)
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
376 {
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
377 int m,l,max,min;
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
378 int chnkcnt = 0;
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
379 int icount = 0;
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
380 int count = 0;
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
381 int index = 0;
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
382 for(m=merge;m;m=cadr(m)) {
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
383 if (!index && !cadr(m)) break; // no index for single chunk
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
384 chnkcnt++;
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
385 count += cadddr(m);
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
386 if (count > CASE_INDEX_COUNT || (index && !cadr(m))) {
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
387 // too large for single stage cascading or
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
388 // we already have indexies and this is the last one.
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
389 icount++;
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
390 min = car(car(chunks));
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
391 check_djmp();
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
392 l = backdef();
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
393 chunks= switch_leaf(chnkcnt,merge,chunks);
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
394 max = chunks?car(car(chunks)):gmax;
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
395 index = list4(l,index,max,min);
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
396 merge = cadr(m); count = 0; chnkcnt = 0;
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
397 }
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
398 }
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
399 if (index) {
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
400 // yes we have indexes
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
401 index = reverse0(index);
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
402 // check lower bound
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
403 // switch_index_jmp(index,dlabel?dlabel:blabel);
298
4ccacae1d2e6 switch index level=1 odd situation.
kono
parents: 297
diff changeset
404 // nonsense because no control here.
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
405 switch_make_index(index,icount,cslabel,gmax,0);
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
406 } else {
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
407 fwddef(cslabel);
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
408 switch_leaf(-1,merge,chunks);
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
409 }
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 327
diff changeset
410 if (control&&dlabel) djmp = 1;
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
411 }
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
412
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
413 /* generate switch table, index, cascading branch */
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
414
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
415
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
416 void
299
3d260008c449 level 2 looks ok.
kono
parents: 298
diff changeset
417 genswitch(int cslist,int cslabel)
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
418 {
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
419 int chunks,merge,gmax;
312
a93e619cf772 typeof, MIPS stdarg
kono
parents: 311
diff changeset
420 #if 0
311
38c9976863b7 swtich list fix. macro fix.
kono
parents: 303
diff changeset
421 int i;
38c9976863b7 swtich list fix. macro fix.
kono
parents: 303
diff changeset
422 int j;
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
423 for(i=cslist;i;i=cadr(i)) {
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
424 if (lsrc) printf("## case %d L_%d\n",car(i),caddr(i));
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
425 }
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
426 #endif
311
38c9976863b7 swtich list fix. macro fix.
kono
parents: 303
diff changeset
427 control=1;
456
b8f95294eb77 inline continue... if test passed.
kono
parents: 382
diff changeset
428 if (chk) return;
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
429 /* find stepwise chunks */
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
430 chunks=make_chunk(cslist);
311
38c9976863b7 swtich list fix. macro fix.
kono
parents: 303
diff changeset
431 #if 0
298
4ccacae1d2e6 switch index level=1 odd situation.
kono
parents: 297
diff changeset
432 j = 0;
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
433 for(i=cslist;i;i=cadr(i)) {
298
4ccacae1d2e6 switch index level=1 odd situation.
kono
parents: 297
diff changeset
434 j++;
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
435 }
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
436 #endif
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
437 /* possible merge of loose stepwise chunks */
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
438 merge = merge_chunk(chunks);
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
439 #if 0
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
440 // chunks: list3(widest,next,delta);
652
f9d86da34600 *** empty log message ***
kono
parents: 645
diff changeset
441 if (lsrc) printf("## chunks %d = sum ",j);
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
442 j = 0;
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
443 for(i=merge;i;i=cadr(i)) {
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
444 if (lsrc) printf(" %d/%d",car(i),caddr(i));
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
445 j+=car(i);
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
446 }
652
f9d86da34600 *** empty log message ***
kono
parents: 645
diff changeset
447 if (lsrc) printf(" sum = %d\n",j);
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
448 #endif
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
449 /* make index branch or table jump */
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
450 gmax = chunk_max(chunks);
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
451 chunks = reverse0(chunks);
299
3d260008c449 level 2 looks ok.
kono
parents: 298
diff changeset
452 if (!dlabel) dlabel = blabel;
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 327
diff changeset
453 djmp = 0;
299
3d260008c449 level 2 looks ok.
kono
parents: 298
diff changeset
454 switch_index(merge,chunks,cslabel,gmax);
311
38c9976863b7 swtich list fix. macro fix.
kono
parents: 303
diff changeset
455 free_chunks(chunks);
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 327
diff changeset
456 if (dlabel!=blabel)
880
5313ed059cee no tabs in source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 652
diff changeset
457 check_djmp();
297
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
458 }
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
459
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
460 #endif
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
461
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
462
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
463
0f79c95df73a switch index no compile error
kono
parents:
diff changeset
464 /* end */