-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathio.old
executable file
·454 lines (382 loc) · 10.9 KB
/
io.old
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
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
#include "ds.h"
#include "bufplace.h"
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
// okay 1, fault 0
extern BOX frame ;
extern SOURCE source ;
extern SINK sink ;
extern WIRELIB wirelib;
extern BUFLIB buflib ;
extern VDDLIB vddlib ;
extern int SlewLimit;
extern int CapLimit ;
extern BLOCKAGE blockage;
extern int num_node ;
extern int num_buffer;
extern int num_wire ;
extern int num_sinknode ;
extern int num_total_nodes ;
extern int highway_extra_buf ;
extern int * sink_alt_array;
extern int mid_sink_num;
extern int total_buf_num;
int InputFile(FILE *ifp){
char buf[SMALL_BUF_SIZE] ;
char prefix1[SMALL_BUF_SIZE];
char prefix2[SMALL_BUF_SIZE];
int i,j ;
int x1,y1,x2,y2;
double d1 = 0.0;
double d2 = 0.0;
if (ifp == NULL){
printf("No such input file: IO ERROR 1\n");
return 0 ;
}
// frame
fgets(buf,SMALL_BUF_SIZE,ifp);
sscanf(buf,"%d %d %d %d",&x1,&y1,&x2,&y2);
frame.ll.x = x1 ;
frame.ll.y = y1 ;
frame.ur.x = x2 ;
frame.ur.y = y2 ;
fgets(buf,SMALL_BUF_SIZE,ifp);
// source
sscanf(buf,"%s %d %d %d %d",prefix1,&x1,&y1,&x2,&y2);
if ( strcmp(prefix1,"source")){
printf("No source node: IO ERROR 2\n");
return 0;
}
source.name = x1 ;
source.location.x = y1 ;
source.location.y = x2 ;
source.bufname = y2 ;
// sink
fgets(buf,SMALL_BUF_SIZE,ifp);
sscanf(buf,"%s %s %d",prefix1,prefix2,&x1);
if ( strcmp(prefix1,"num")){
printf("Wrong num of sink: IO ERROR 3\n");
return 0;
}
if ( strcmp(prefix2,"sink")){
printf("Wrong num of sink: IO ERROR 4\n");
return 0;
}
sink.num = x1 ;
sink.pool = (SNODE *) malloc(sizeof(SNODE) * sink.num) ;
for(i = 0; i< sink.num; i++){
fgets(buf,SMALL_BUF_SIZE,ifp);
sscanf(buf,"%d %d %d %d", &x1,&y1,&x2,&y2);
sink.pool[i].index = x1 ;
sink.pool[i].x = y1 ;
sink.pool[i].y = x2 ;
sink.pool[i].lc = y2 ;
}
fgets(buf,SMALL_BUF_SIZE,ifp);
sscanf(buf,"%s %s %d",prefix1,prefix2, &x1);
// wirelib
if ( strcmp(prefix1,"num")){
printf("Wrong num of wirelib: IO ERROR 5\n");
return 0;
}
if ( strcmp(prefix2,"wirelib")){
printf("Wrong num of wirelib: IO ERROR 6\n");
return 0;
}
if ( x1 != 2 ){
printf("Wrong num of wirelib: IO ERROR 7\n");
return 0;
}
wirelib.num = x1 ;
wirelib.lib = (WIRE *)malloc(sizeof(WIRE) * wirelib.num) ;
for ( i = 0 ; i < wirelib.num ; i++){
fgets(buf,SMALL_BUF_SIZE,ifp);
sscanf(buf,"%d %lf %lf",&x1,&d1,&d2);
wirelib.lib[i].wiretype = x1;
wirelib.lib[i].r = d1;
wirelib.lib[i].c = d2;
}
// buflib
fgets(buf,SMALL_BUF_SIZE,ifp);
sscanf(buf,"%s %s %d",prefix1,prefix2,&x1);
if ( strcmp(prefix1,"num")){
printf("Wrong num of buflib: IO ERROR 8\n");
return 0;
}
if ( strcmp(prefix2,"buflib")){
printf("Wrong num of buflib: IO ERROR 9\n");
return 0;
}
buflib.num = x1;
buflib.lib = (BUFFER *) malloc (sizeof(BUFFER) * buflib.num);
for(i = 0 ; i < buflib.num; i++){
fgets(buf,SMALL_BUF_SIZE,ifp);
sscanf(buf,"%d %s %d %lf %lf %lf",&x1,prefix1,&y1,&(buflib.lib[i].icap),&(buflib.lib[i].ocap),&(buflib.lib[i].ores));
buflib.lib[i].buf_id = x1 ;
buflib.lib[i].spice_subckt = (char *)malloc(sizeof(char)*SMALL_BUF_SIZE);
strcpy(buflib.lib[i].spice_subckt, prefix1);
buflib.lib[i].inverted = y1;
/* buflib.lib[i].icap = x2;
buflib.lib[i].ocap = y2;*/
;
}
// vdd
fgets(buf,SMALL_BUF_SIZE,ifp);
sscanf(buf,"%s %s %d %lf",&prefix1,&prefix2,&x1,&d2);
d1 = (double)x1 ;
if ( strcmp(prefix1,"simulation")){
printf("Wrong simulation vdd: IO ERROR 10\n");
return 0;
}
if ( strcmp(prefix2,"vdd")){
printf("Wrong simulation vdd: IO ERROR 11\n");
return 0;
}
vddlib.num = 2 ;
vddlib.lib = (double *) malloc(sizeof(double)*vddlib.num);
vddlib.lib[0] = d1 ;
vddlib.lib[1] = d2 ;
fgets(buf,SMALL_BUF_SIZE,ifp);
sscanf(buf,"%s %s %d",&prefix1,&prefix2,&x1);
SlewLimit = x1;
fgets(buf,SMALL_BUF_SIZE,ifp);
sscanf(buf,"%s %s %d",&prefix1,&prefix2,&x1);
CapLimit = x1;
// blockage
fgets(buf,SMALL_BUF_SIZE,ifp);
sscanf(buf,"%s %s %d",prefix1,prefix2,&x1);
if ( strcmp(prefix1,"num")){
printf("Wrong num of blockage: IO ERROR 12\n");
return 0;
}
if ( strcmp(prefix2,"blockage")){
printf("Wrong num of blockage: IO ERROR 13\n");
return 0;
}
blockage.num = x1;
blockage.pool = (BOX *) malloc (sizeof(BOX) * blockage.num);
for(i = 0 ; i < blockage.num; i++){
fgets(buf,SMALL_BUF_SIZE,ifp);
sscanf(buf,"%d %d %d %d",&x1,&y1,&x2,&y2);
blockage.pool[i].ll.x = x1 ;
blockage.pool[i].ll.y = y1;
blockage.pool[i].ur.x = x2;
blockage.pool[i].ur.y = y2;
}
return 1;
}
int check_input(){
int i ;
printf("check input\n");
printf("%d,%d,%d,%d\n",frame.ll.x,frame.ll.y,frame.ur.x,frame.ur.y);
printf("source %d %d %d %d\n", source.name, source.location.x,source.location.y,source.bufname);
printf("num sink %d\n",sink.num);
for(i=0;i<sink.num; i++){
printf("%d %d %d %d\n", sink.pool[i].index,sink.pool[i].x, sink.pool[i].y, sink.pool[i].lc);
}
printf("num wirelib %d\n", wirelib.num);
for(i=0;i<wirelib.num;i++)
printf("%d %f %f\n",wirelib.lib[i].wiretype,wirelib.lib[i].r,wirelib.lib[i].c);
printf("num buflib %d\n", buflib.num);
for(i=0;i<buflib.num;i++)
printf("%d %s %d %f %f %f\n",buflib.lib[i].buf_id,buflib.lib[i].spice_subckt,buflib.lib[i].inverted, buflib.lib[i].icap,buflib.lib[i].ocap,buflib.lib[i].ores);
printf("simulation vdd %f %f\n",vddlib.lib[0],vddlib.lib[1]);
printf("limit slew %d\n", SlewLimit);
printf("limit cap %d\n", CapLimit);
printf("num blockage %d\n", blockage.num);
for(i=0;i<blockage.num;i++){
printf("%d %d %d %d\n",blockage.pool[i].ll.x,blockage.pool[i].ll.y,blockage.pool[i].ur.x,blockage.pool[i].ur.y);
}
return 0 ;
}
int constradict(int x,int y, BOX * blk){
int x1 = blk->ll.x;
int y1 = blk->ll.y;
int x2 = blk->ur.x;
int y2 = blk->ur.y;
if( x>x1 && x<x2 && y > y1 && y < y2){
printf("error, blk is in the blockage\n");
exit(0);
}
else if ( x < x1 || x > x2 || y < y1 || y > y2)
return 0;
else {
if ( x == x1 && y >= y1 && y <= y2){
if (frame.ll.x < x1)
return 3;
}
else if ( y == y1 && x >= x1 && x <= x2){
if (frame.ll.y < y1)
return 2;
}
else if ( x == x2 && y >= y1 && y <= y2){
if (frame.ur.x > x2)
return 4;
}
else if ( y == y2 && x >= x1 && x <= x2){
if (frame.ur.y > y2)
return 1;
}
else {
printf(" wrong type of node\n");
exit(0);
}
}
printf(" another wrong type of node\n");
exit(0);
}
void check_buf_node(BUF_NODE *bt,BLOCKAGE *block,int num,int *direct){
int x = (int) bt->x;
int y = (int) bt->y;
int i;
for ( i = 0 ; i < num ; i++){
if(((*direct)=constradict(x,y,(block->pool + i))) > 0 ){
return;
}
}
}
void check_point_node(DME_TREE_NODE *bt,BLOCKAGE *block,int num,int *direct){
int x = (int) bt->x;
int y = (int) bt->y;
int i;
for ( i = 0 ; i < num ; i++){
if(((*direct)=constradict(x,y,(block->pool + i))) > 0 ){
return;
}
}
}
void adjust_buf_node(BUF_NODE * bt, BLOCKAGE * block,int num){
int direct = -1;
check_buf_node(bt,block,num,&direct);
switch(direct){
case 1:
(bt->y) += 0.1;
break;
case 2:
(bt->y) -= 0.1;
break;
case 3:
(bt->x) -= 0.1;
break;
case 4:
(bt->x) += 0.1;
break;
default:
break;
}
return;
}
void adjust_point_node(DME_TREE_NODE * tr, BLOCKAGE * block,int num){
int direct = -1;
check_point_node(tr,block,num,&direct);
switch(direct){
case 1:
(tr->y) += 1;
break;
case 2:
(tr->y) -= 1;
break;
case 3:
(tr->x) -= 1;
break;
case 4:
(tr->x) += 1;
break;
default:
break;
}
return;
}
void adjust_buf(BUF_NODE ** OBUF, BLOCKAGE * block){
int num = block->num;
BUF_NODE * bf;
int i;
if ( num <= 0 )
return;
for(i=0;i<num_total_nodes;i++){
bf = (*(OBUF+i))->next;
while(bf!=NULL){
adjust_buf_node(bf,block,num);
bf = bf->next;
}
}
}
void adjust_point(DME_TREE_NODE ** Tmap, BLOCKAGE * block){
int num = block->num;
BUF_NODE * bf;
int i;
if ( num <= 0 )
return;
for(i=0;i<num_total_nodes;i++){
adjust_point_node((*(Tmap+i)),block,num);
}
}
void output_file(FILE *fp, BUF_NODE ** OBUF, DME_TREE_NODE * OT, DME_TREE_NODE ** OTmap, int label){
if ( fp == NULL) {
printf(" error input file name \n");
return ;
}
if (label == 1)
print_fig_3(OT,OTmap);
fprintf(fp,"sourcenode 0 0\n");
fprintf(fp,"num node %d\n", num_node);
Out_put_files_coordinate(fp,OBUF,OT);
fprintf(fp,"num sinknode %d\n", num_sinknode);
Out_put_files_sink(fp, OT) ;
fprintf(fp,"num wire %d\n", num_wire);
Out_put_files_connect(fp,OBUF, OT);
//fprintf(fp,"num buffer %d\n",num_buffer*2+highway_extra_buf*HIGHWAY);
fprintf(fp,"num buffer %d\n",total_buf_num);
Out_put_files_buf(fp, num_total_nodes, OBUF, OTmap);
}
void get_init_delay(DME_NODE *L){
int i;
int x;
double y;
char buf[SMALL_BUF_SIZE] ;
FILE * ifp = fopen( "initDelay.txt", "r") ;
double * tmp = (double *) malloc (sizeof(double)*sink.num);
for(i=0;i<sink.num*4; i++){
fgets(buf,SMALL_BUF_SIZE,ifp);
sscanf(buf,"%d %lf",&x,&y);
// printf("%d %f\n",x,y);
tmp[x-1] += y;
}
for(i=0;i<sink.num; i++){
tmp[i] /= 4.0f;
L[i].to_sink_delay = tmp[i];
// printf("%d %f\n",i,L[i].to_sink_delay);
}
fclose(ifp);
}
void fprint_sink(FILE *fp, DME_TREE_NODE * Troot){
if ( Troot == NULL)
return ;
if ( Troot->sink_index != -1)
fprintf(fp,"%d %d %d %f\n",Troot->sink_index,Troot->x,Troot->y,Troot->capacitance);
fprint_sink(fp,Troot->ls);
fprint_sink(fp,Troot->rs);
}
void gen_inputfile(FILE * ifp,DME_TREE_NODE * Troot, DME_TREE_NODE ** map){
int i;
int x1,y1,x2,y2;
x1 = frame.ll.x ; y1 = frame.ll.y;
x2 = frame.ur.x ; y2 = frame.ur.y;
fprintf(ifp,"%d %d %d %d\n", x1,y1,x2,y2);
fprintf(ifp,"source %d %d %d %d\n",source.name,source.location.x,source.location.y,source.bufname);
fprintf(ifp,"num sink %d\n",mid_sink_num);
fprint_sink(ifp,Troot);
fprintf(ifp,"num wirelib %d\n",wirelib.num);
for(i = 0 ; i < wirelib.num; i++)
fprintf(ifp,"%d %f %f\n",wirelib.lib[i].wiretype,wirelib.lib[i].r,wirelib.lib[i].c);
fprintf(ifp,"num buflib %d\n",buflib.num);
// for(i=0; i< buflib.num; i++)
fprintf(ifp,"%d %s %d %f %f %f\n",buflib.lib[0].buf_id,buflib.lib[0].spice_subckt,buflib.lib[0].inverted,35.0,buflib.lib[0].ocap,buflib.lib[0].ores);
fprintf(ifp,"%d %s %d %f %f %f\n",buflib.lib[1].buf_id,buflib.lib[1].spice_subckt,buflib.lib[1].inverted,4.2,buflib.lib[1].ocap,buflib.lib[1].ores);
fprintf(ifp,"simulation vdd %.1f %.1f\n",vddlib.lib[0],vddlib.lib[1]);
fprintf(ifp,"limit slew %d\n",SlewLimit);
fprintf(ifp,"limit cap %d\n",CapLimit);
fprintf(ifp,"num blockage %d\n", 0);
}