-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcrt_path.c
406 lines (371 loc) · 8.37 KB
/
crt_path.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
#include"crt_path.h"
void refine_crt_num(int * node, int * wire, int * buf, BUF_NODE ** OBUF){
int i = 0;
BUF_NODE * bf = (*(OBUF + 1))->next;
*buf = 0;
while ( bf != NULL){
i++;
(*buf) += bf->units;
bf = bf->next;
}
// *buf = i*6;
*node = 2 * i;
*wire = i ;
}
void cpy_buf_list( BUF_NODE * L1, BUF_NODE * L2){
if ( L2 == NULL)
return;
if ( L1 == NULL){
printf(" error copy , no list 1\n");
}
L1->x = L2->x;
L1->y = L2->y;
L1->buf_id = L2->buf_id;
L1->buf_type = L2->buf_type;
L1->units = L2->units;
L1->wire_type = L2->wire_type;;
// L1 = L1 -> next;
L2 = L2 -> next;
while ( L2 != NULL){
L1->next = (BUF_NODE *) malloc(sizeof(BUF_NODE));
L1 = L1->next;
L1->x = L2->x;
L1->y = L2->y;
L1->buf_id = L2->buf_id;
L1->buf_type = L2->buf_type;
L1->units = L2->units;
L1->wire_type = L2->wire_type;;
// L1 = L1 -> next;
L2 = L2 -> next;
}
}
void refine_crt_path(BUF_NODE ** OBUF, DME_TREE_NODE * OT, DME_TREE_NODE ** OTmap, int n, int w, int bu){
DME_TREE_NODE * lookson;
DME_TREE_NODE * Vroot = OT;
DME_TREE_NODE * Rroot = OT->ls;
DME_TREE_NODE * Oroot = (*OTmap);
BUF_NODE * store;
BUF_NODE * buflist;
BUF_NODE * st;
BUF_NODE * ex;
int succ = -1 ;
int head = 0 ;
int tail = 0 ;
int segnum = 2;
int * li_path_info;
int InterNum = Rroot->buf_num;
int i;
int bcode;
int btype;
int bnum;
ZERO->node_id = 0;
ZERO->x = 0;
ZERO->y = 0;
ZERO->sink_index = -1;
ZERO->ls = ZERO->rs = NULL;
/* if( Rroot->node_id != 1){
printf(" wrong, there is blk node this test \n");
exit(0);
}
*/
lookson = OT->ls;
while(lookson->is_blk == 1)
lookson = lookson->ls;
Rroot = lookson;
buflist = (*(OBUF+Rroot->node_id))->next;
store = (BUF_NODE *) malloc(sizeof(BUF_NODE));
cpy_buf_list(store,buflist);
st = store;
while ( st != NULL){
printf("*******************************\n");
if(st->next != NULL)
segnum++;
else if( ((int) st->x) == Rroot->x && ((int) st->y) == Rroot->y)
head = 1;
else
segnum++;
st = st->next;
}
printf(" seg num is %d\n", segnum);
printf(" head is %d\t tail is %d\n",head,tail);
st = store;
while (st != NULL){
printf("(%d %d)\t",(int)st->x,(int)st->y);
st = st->next;
}
// exit(0);
succ = critical_path(head,tail,segnum,&li_path_info,buflist,OBUF,Rroot,OTmap);
for(i=segnum-1;i>=0;i--){
printf("wire type is %d\n",li_path_info[2*i+1]);
bcode = li_path_info[2*i];
decode(bcode,&btype,&bnum);
printf("bcode is %d bnum is %d btype is %d\n",bcode,bnum,btype);
}
(*OTmap) = Oroot;
Rroot->fa = Oroot;
(*(OBUF+Rroot->node_id))->next = store;
st = store;
ex = st;
if ( succ > 0 ){
for( i=segnum-2; i>=0; i--){
if( i == 0){
Rroot->wire_type = li_path_info[2*i+1];
if (head == 0)
continue;
}
bcode = li_path_info[2*i];
decode(bcode,&btype,&bnum);
if(btype > -1 && bnum > -1){
st->buf_type = btype;
st->units = bnum;
st->wire_type = li_path_info[2*i+1];
ex = st;
st = st->next;
num_node += 2;
num_wire ++;
total_buf_num += bnum;
}
else{
ex->next = st->next;
free(st);
st = ex->next;
}
}
}
else {
num_node += n;
num_wire += w;
total_buf_num += bu;
printf("refine critical path by DP failed: recover\n");
}
return;
}
void quick_find(int head,int total_seg_num,int segnum,BUF_NODE *store, int * x, int * y,int *b){
int full = total_seg_num - 2;
full += head;
int passed = full - segnum ;
BUF_NODE * st = store;
// passed ++;
if ( passed == 0){
*x = 0;
*y = 0;
*b = -1;
return;
}
while(passed --){
// printf("pass is %d\n",passed);
if ( st == NULL ){
printf("quick found wrong, no such passed number\n");
exit(0);
}
*x = (int) st->x;
*y = (int) st->y;
*b = st->buf_id;
st = st->next;
}
return;
}
void decode(int bcode, int * btype, int *bnum){
if ( bcode < 0){
*btype = -1;
*bnum = -1;
}
else {
*bnum = bcode ;
// *btype = bcode %2 ;
*btype = 0;
}
}
int partial_path_CLR(int total_seg_num,int segnum, int * path_info, BUF_NODE * store, int head, BUF_NODE ** OBUF, DME_TREE_NODE * Rroot, DME_TREE_NODE ** Tmap,double * delay){
int err;
int i;
int x,y;
int wtype=-1;
int btype=-1;
int bnum=-1;
int b_id=-1;
int bcode;
double tempqian;
FILE * tfp;
FILE * ifp;
DME_TREE_NODE * Vroot = (DME_TREE_NODE *) malloc(sizeof(DME_TREE_NODE));
//DME_TREE_NODE * Rroot = (DME_TREE_NODE *) malloc(sizeof(DME_TREE_NODE));
BUF_NODE * newbuf = (BUF_NODE *) malloc(sizeof(BUF_NODE));
newbuf->next = NULL;
BUF_NODE * bf = newbuf;
BUF_NODE * b1, *b2;
new_num_node = 0;
new_num_wire = 0;
new_total_buf_num = 0 ;
new_num_total_nodes = 0;
printf("total segment is %d\n", total_seg_num);
printf("now is %d\n",segnum);
Vroot->x = 0;
Vroot->y = 0;
Vroot->node_id = 0;
for(i=segnum ; i>=0 ; i--){
if ( i == total_seg_num-1){
Vroot->x = 0;
Vroot->y = 0;
Vroot->node_id = LARGESTNODE;
Vroot->wire_type = 1;
Vroot->sink_index = -1;
Vroot->ls = Vroot->rs = NULL;
new_num_node++;
new_num_wire++;
continue;
}
if ( i == 0 ){
Rroot->wire_type = path_info[1];
if (head == 0)
continue;
}
quick_find(head,total_seg_num,i,store,&x,&y,&b_id);
if ( i== segnum){
Vroot->node_id = LARGESTNODE;
Vroot->x = x;
Vroot->y = y;
Vroot->wire_type = 1;
Vroot->ls = Vroot->rs = NULL;
new_num_node ++;
new_num_wire ++;
// new_num_total_nodes++;
Vroot->sink_index = -1;
// continue;
}
if ( i == 0 ){
Rroot->wire_type = path_info[1];
}
bcode = path_info[2*i];
printf("i is %d\n", i);
printf("bcode is %d\n", bcode);
decode(bcode,&btype,&bnum);
printf("bnum is %d\n",bnum);
// sleep(1);
if ( bnum > -1 && btype > -1){
if (bf->next != NULL){
printf("error: why not move to the last one \n");
exit(0);
}
new_num_node += 2;
new_num_wire ++;
new_total_buf_num+= bnum;
bf->next = (BUF_NODE *) malloc(sizeof(BUF_NODE));
bf = bf->next;
bf->x = (double)x;
bf->y = (double)y;
if (b_id == -1){
printf("error:this should not be buffer\n");
exit(0);
}
bf->buf_id = b_id;
bf->wire_type = path_info[2*i+1];
bf->buf_type = btype;
bf->units = bnum;
bf->next = NULL;
}
}
//Vroot->ls = Rroot;
//Rroot->fa = Vroot;
if(Vroot->node_id != 0){
ZERO->ls = Vroot;
ZERO->rs = NULL;
Vroot->fa = ZERO;
Vroot->ls = Rroot;
Rroot->fa = Vroot;
}
else {
ZERO->ls = Rroot;
ZERO->rs = NULL;
Rroot->fa = ZERO;
}
printf("root is %d\n",Rroot->node_id);
tfp = fopen("crtoutfile","w");
ifp = fopen("crtinfile","w");
num_node+=new_num_node ;
num_wire+=new_num_wire ;
total_buf_num+=new_total_buf_num;
num_total_nodes+=new_num_total_nodes;
(*(OBUF+Rroot->node_id))->next = newbuf->next;
(*Tmap) = ZERO;
gen_inputfile(ifp,ZERO,Tmap,1);
output_file(tfp,OBUF,ZERO,Tmap,0);
fclose(tfp);
fclose(ifp);
//(*(OBUF+Rroot->node_id))->next = NULL;
num_node-=new_num_node ;
num_wire-=new_num_wire ;
total_buf_num-=new_total_buf_num;
num_total_nodes-=new_num_total_nodes;
ZERO->ls = NULL;
b1 = newbuf;
while ( b1 != NULL ){
b2 = b1->next;
free(b1);
b1 = b2;
}
tempqian = 0.0;
if(segnum == total_seg_num -1)
err = crt_process(1, &tempqian);
else
err = crt_process(4,&tempqian);
printf("\n");
printf(" err is %d\n",err);
printf(" qian %f\n",tempqian);
printf("\n");
*delay = tempqian;
return err;
}
void add_buf_list(BUF_NODE * ol , BUF_NODE *ne){
BUF_NODE * bi;
if (ne == NULL)
return;
bi = ol;
if (bi == NULL){
printf(" error: the newlist not exist\n");
exit(0);
}
while ( bi->next != NULL)
bi = bi->next;
bi->next = ne;
}
void adjust_node_id(DME_TREE_NODE * OT, int loss){
if ( OT == NULL )
return;
if (OT->node_id != 0)
OT->node_id = OT->node_id - loss;
adjust_node_id(OT->ls,loss);
adjust_node_id(OT->rs,loss);
}
void trans_crt_path(BUF_NODE ** OBUF, DME_TREE_NODE * OT, DME_TREE_NODE ** OTmap){
DME_TREE_NODE * seg = OT->ls;
BUF_NODE * buflist , * newlist;
BUF_NODE * bf,* bt;
int i;
int nodenum = 0;
if( seg -> is_blk != 1)
return;
newlist = (BUF_NODE *)malloc(sizeof(BUF_NODE));
newlist->next = NULL;
//bf = newlist;
while (seg != NULL){
add_buf_list(newlist , (*(OBUF+seg->node_id))->next);
if(seg->is_blk != 1){
(*(OBUF+seg->node_id))->next = newlist->next;
OT->ls = seg;
seg->fa = OT;
break;
}
nodenum ++;
seg = seg->ls ;
}
num_node -= nodenum;
num_wire -= nodenum;
num_total_nodes -= nodenum;
adjust_node_id(OT,nodenum);
printf("nodenum is %d\n",nodenum);
for(i=1;i<=num_total_nodes-1;i++){
(*(OBUF+i))->next = (*(OBUF+i+nodenum))->next;
(*(OTmap+i)) = (*(OTmap+i+nodenum));
}
}