-
Notifications
You must be signed in to change notification settings - Fork 17
/
qrouter.c
2401 lines (2046 loc) · 68.5 KB
/
qrouter.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
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
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*--------------------------------------------------------------*/
/* qrouter.c -- general purpose autorouter */
/* Reads LEF libraries and DEF netlists, and generates an */
/* annotated DEF netlist as output. */
/*--------------------------------------------------------------*/
/* Written by Tim Edwards, June 2011, based on code by Steve */
/* Beccue, 2003 */
/*--------------------------------------------------------------*/
#include <ctype.h>
#include <stdio.h>
#include <math.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifdef TCL_QROUTER
#include <tk.h>
#endif
#include "qrouter.h"
#include "qconfig.h"
#include "point.h"
#include "node.h"
#include "maze.h"
#include "mask.h"
#include "output.h"
#include "lef.h"
#include "def.h"
#include "graphics.h"
int TotalRoutes = 0;
NET *Nlnets; // list of nets in the design
NET CurNet; // current net to route, used by 2nd stage
STRING DontRoute; // a list of nets not to route (e.g., power)
STRING CriticalNet; // list of critical nets to route first
GATE GateInfo; // standard cell macro information
GATE PinMacro; // macro definition for a pin
GATE Nlgates; // gate instance information
NETLIST FailedNets; // list of nets that failed to route
u_int *Obs[MAX_LAYERS]; // net obstructions in layer
PROUTE *Obs2[MAX_LAYERS]; // used for pt->pt routes on layer
ObsInfoRec *Obsinfo[MAX_LAYERS]; // temporary array used for detailed obstruction info
NODEINFO *Nodeinfo[MAX_LAYERS]; // nodes and stub information is here. . .
DSEG UserObs; // user-defined obstruction layers
u_int progress[3]; // analysis of behavior
u_char needblock[MAX_LAYERS];
char *vddnet = NULL;
char *gndnet = NULL;
char *antenna_cell = NULL;
int Numnets = 0;
int Pinlayers = 0;
u_int minEffort = 0; // Minimum effort applied from command line.
u_char Verbose = 3; // Default verbose level
u_char forceRoutable = FALSE;
u_char maskMode = MASK_AUTO;
u_char mapType = MAP_OBSTRUCT | DRAW_ROUTES;
u_char ripLimit = 10; // Fail net rather than rip up more than
// this number of other nets.
u_char unblockAll = FALSE;
char *DEFfilename = NULL;
char *delayfilename = NULL;
DPOINT testpoint = NULL; // used for debugging route problems
ScaleRec Scales; // record of input and output scales
/*--------------------------------------------------------------*/
/* Upate the output scale factor. It has to be a valid DEF */
/* scale factor and it has to be a multiple of the given scale */
/* factor. */
/*--------------------------------------------------------------*/
void
update_mscale(int mscale)
{
static int valid_mscales[] = {100, 200, 1000, 2000, 10000, 20000};
int nscales = sizeof(valid_mscales) / sizeof(valid_mscales[0]);
int mscale2, i;
if (mscale == 0) return;
if ((Scales.mscale % mscale) != 0) {
// Check valid scale values; if none is appropriate, don't update
for (i = 0; i < nscales; i++) {
mscale2 = valid_mscales[i];
if (mscale2 <= Scales.mscale) continue;
if ((mscale2 % mscale) == 0) {
Scales.mscale = mscale2;
break;
}
}
}
}
/*--------------------------------------------------------------*/
/* Check track pitch and set the number of channels (may be */
/* called from DefRead) */
/*--------------------------------------------------------------*/
int set_num_channels(void)
{
int i, glimitx, glimity;
NET net;
NODE node;
DPOINT ctap, ltap, ntap;
if (NumChannelsX != 0) return 0; /* Already been called */
if (PitchX == 0.0) {
Fprintf(stderr, "Have a 0 pitch for X direction. Exit.\n");
return (-3);
}
else if (PitchY == 0.0) {
Fprintf(stderr, "Have a 0 pitch for Y direction. Exit.\n");
return (-3);
}
NumChannelsX = (int)(1.5 + (Xupperbound - Xlowerbound) / PitchX);
NumChannelsY = (int)(1.5 + (Yupperbound - Ylowerbound) / PitchY);
if ((Verbose > 1) || (NumChannelsX <= 0))
Fprintf(stdout, "Number of x channels is %d\n", NumChannelsX);
if ((Verbose > 1) || (NumChannelsY <= 0))
Fprintf(stdout, "Number of y channels is %d\n", NumChannelsY);
if (NumChannelsX <= 0) {
Fprintf(stderr, "Something wrong with x bounds.\n");
return(-3);
}
if (NumChannelsY <= 0) {
Fprintf(stderr, "Something wrong with y bounds.\n");
return(-3);
}
Flush(stdout);
// Go through all nodes and remove any tap or extend entries that are
// out of bounds.
for (i = 0; i < Numnets; i++) {
net = Nlnets[i];
for (node = net->netnodes; node != NULL; node = node->next) {
ltap = NULL;
for (ctap = node->taps; ctap != NULL; ) {
ntap = ctap->next;
glimitx = NumChannelsX;
glimity = NumChannelsY;
if (ctap->gridx < 0 || ctap->gridx >= glimitx ||
ctap->gridy < 0 || ctap->gridy >= glimity) {
/* Remove ctap */
if (ltap == NULL)
node->taps = ntap;
else
ltap->next = ntap;
}
else
ltap = ctap;
ctap = ntap;
}
ltap = NULL;
for (ctap = node->extend; ctap != NULL; ) {
ntap = ctap->next;
glimitx = NumChannelsX;
glimity = NumChannelsY;
if (ctap->gridx < 0 || ctap->gridx >= glimitx ||
ctap->gridy < 0 || ctap->gridy >= glimity) {
/* Remove ctap */
if (ltap == NULL)
node->taps = ntap;
else
ltap->next = ntap;
}
else
ltap = ctap;
ctap = ntap;
}
}
}
if (recalc_spacing()) draw_layout();
return 0;
}
/*--------------------------------------------------------------*/
/* Allocate the Obs[] array (may be called from DefRead) */
/*--------------------------------------------------------------*/
int allocate_obs_array(void)
{
int i;
if (Obs[0] != NULL) return 0; /* Already been called */
for (i = 0; i < Num_layers; i++) {
Obs[i] = (u_int *)calloc(NumChannelsX * NumChannelsY,
sizeof(u_int));
if (!Obs[i]) {
Fprintf(stderr, "Out of memory 4.\n");
return(4);
}
}
return 0;
}
/*--------------------------------------------------------------*/
/* countlist --- */
/* Count the number of entries in a simple linked list */
/*--------------------------------------------------------------*/
int
countlist(NETLIST net)
{
NETLIST nptr = net;
int count = 0;
while (nptr != NULL) {
count++;
nptr = nptr->next;
}
return count;
}
/* Forward declaration */
static void helpmessage(void);
/*--------------------------------------------------------------*/
/* runqrouter - main program entry point, parse command line */
/* */
/* ARGS: argc (count) argv, command line */
/* RETURNS: to OS */
/* SIDE EFFECTS: */
/*--------------------------------------------------------------*/
int
runqrouter(int argc, char *argv[])
{
int i;
FILE *configFILEptr, *infoFILEptr;
static char configdefault[] = CONFIGFILENAME;
char *configfile = configdefault;
char *infofile = NULL;
char *dotptr;
char *Filename = NULL;
u_char readconfig = FALSE;
u_char doscript = FALSE;
Scales.iscale = 1;
Scales.mscale = 100;
/* Parse arguments */
for (i = 0; i < argc; i++) {
char optc, argsep = '\0';
char *optarg = NULL;
if (*argv[i] == '-') {
/* 1st pass---look for which options require an argument */
optc = *(argv[i] + 1);
switch (optc) {
case 'c':
case 'i':
case 'e':
case 'k':
case 'v':
case 'd':
case 'p':
case 'g':
case 'r':
case 's':
argsep = *(argv[i] + 2);
if (argsep == '\0') {
i++;
if (i < argc) {
optarg = argv[i];
if (*optarg == '-') {
Fprintf(stderr, "Option -%c needs an argument.\n", optc);
Fprintf(stderr, "Option not handled.\n");
continue;
}
}
else {
Fprintf(stderr, "Option -%c needs an argument.\n", optc);
Fprintf(stderr, "Option not handled.\n");
continue;
}
}
else
optarg = argv[i] + 2;
}
/* Now handle each option individually */
switch (optc) {
case 'c':
configfile = strdup(optarg);
break;
case 'v':
Verbose = atoi(optarg);
break;
case 'i':
infofile = strdup(optarg);
break;
case 'd':
if (delayfilename != NULL) free(delayfilename);
delayfilename = strdup(optarg);
break;
case 'p':
vddnet = strdup(optarg);
break;
case 'g':
gndnet = strdup(optarg);
break;
case 's':
// The "-s" argument is not handled here but is used
// to avoid generating a warning message.
doscript = TRUE;
break;
case 'r':
if (sscanf(optarg, "%d", &Scales.iscale) != 1) {
Fprintf(stderr, "Bad resolution scalefactor \"%s\", "
"integer expected.\n", optarg);
Scales.iscale = 1;
}
break;
case 'h':
helpmessage();
return 1;
break;
case 'f':
forceRoutable = TRUE;
break;
case 'k':
Fprintf(stdout, "Option \"k\" deprecated. Use \"effort\""
" in stage2 or stage3 command or -e option\n");
minEffort = 100 * atoi(optarg);
break;
case 'e':
minEffort = atoi(optarg);
break;
case 'n':
/* Ignore '-noc' or '-nog', handled elsewhere */
break;
case '\0':
/* Ignore '-' */
break;
case '-':
/* Ignore '--' */
break;
default:
Fprintf(stderr, "Bad option -%c, ignoring.\n", optc);
}
}
else {
/* Not an option or an option argument, so treat as a filename */
Filename = strdup(argv[i]);
}
}
if (infofile != NULL) {
infoFILEptr = fopen(infofile, "w" );
free(infofile);
}
else {
infoFILEptr = NULL;
#ifndef TCL_QROUTER
fprintf(stdout, "Qrouter detail maze router version %s.%s\n", VERSION, REVISION);
#endif
}
if (!doscript) {
configFILEptr = fopen(configfile, "r");
if (configFILEptr) {
read_config(configFILEptr, (infoFILEptr == NULL) ? FALSE : TRUE);
readconfig = TRUE;
}
else {
if (configfile != configdefault)
Fprintf(stderr, "Could not open %s\n", configfile );
else
Fprintf(stdout, "No .cfg file specified, continuing without.\n");
}
if (configfile != configdefault) free(configfile);
}
if (infoFILEptr != NULL) {
/* Print qrouter name and version number at the top */
#ifdef TCL_QROUTER
fprintf(infoFILEptr, "qrouter %s.%s.T\n", VERSION, REVISION);
#else
fprintf(infoFILEptr, "qrouter %s.%s\n", VERSION, REVISION);
#endif
/* Output database units expected by the technology LEF file */
/* Note that this comes from MANUFACTURINGGRID, not UNITS DATABASE */
fprintf(infoFILEptr, "units scale %d\n", Scales.mscale);
/* Resolve base horizontal and vertical pitches. */
post_config(TRUE);
/* Print information about route layers, and exit */
for (i = 0; i < Num_layers; i++) {
double pitch, width;
int vnum, hnum;
int o = LefGetRouteOrientation(i);
char *layername = LefGetRouteName(i);
check_variable_pitch(i, &hnum, &vnum);
if (layername != NULL) {
pitch = (o == 1) ? PitchY : PitchX,
width = LefGetRouteWidth(i);
if (pitch == 0.0 || width == 0.0) continue;
fprintf(infoFILEptr, "%s %g %g %g %s",
layername, pitch,
LefGetRouteOffset(i), width,
(o == 1) ? "horizontal" : "vertical");
if (o == 1 && vnum > 1)
fprintf(infoFILEptr, " %d", vnum);
else if (o == 0 && hnum > 1)
fprintf(infoFILEptr, " %d", hnum);
fprintf(infoFILEptr, "\n");
}
}
fclose(infoFILEptr);
return 1;
}
if (Filename != NULL) {
/* process last non-option string */
dotptr = strrchr(Filename, '.');
if (dotptr != NULL) *dotptr = '\0';
if (DEFfilename != NULL) free(DEFfilename);
DEFfilename = (char *)malloc(strlen(Filename) + 5);
sprintf(DEFfilename, "%s.def", Filename);
}
else if (readconfig) {
Fprintf(stdout, "No netlist file specified, continuing without.\n");
// Print help message but continue normally.
helpmessage();
}
Obs[0] = (u_int *)NULL;
NumChannelsX = 0; // This is so we can check if NumChannelsX/Y were
// set from within DefRead() due to reading in
// existing nets.
Scales.oscale = 1.0;
return 0;
}
/*--------------------------------------------------------------*/
/* remove_from_failed --- */
/* */
/* Remove one net from the list of failing nets. If "net" was */
/* in the list FailedNets, then return TRUE, otherwise return */
/* FALSE. */
/*--------------------------------------------------------------*/
u_char remove_from_failed(NET net)
{
NETLIST nl, lastnl;
lastnl = (NETLIST)NULL;
for (nl = FailedNets; nl; nl = nl->next) {
if (nl->net == net) {
if (lastnl == NULL)
FailedNets = nl->next;
else
lastnl->next = nl->next;
free(nl);
return TRUE;
}
lastnl = nl;
}
return FALSE;
}
/*--------------------------------------------------------------*/
/* remove_failed --- */
/* */
/* Free up memory in the list of route failures. */
/*--------------------------------------------------------------*/
void remove_failed()
{
NETLIST nl;
while (FailedNets) {
nl = FailedNets;
FailedNets = FailedNets->next;
free(nl);
}
}
/*--------------------------------------------------------------*/
/* Remove the first (top) route record from a net */
/*--------------------------------------------------------------*/
void remove_top_route(NET net)
{
ROUTE rt;
SEG seg;
rt = net->routes;
net->routes = net->routes->next;
while (rt->segments) {
seg = rt->segments;
rt->segments = rt->segments->next;
free(seg);
}
free(rt);
}
/*--------------------------------------------------------------*/
/* reinitialize --- */
/* */
/* Free up memory in preparation for reading another DEF file */
/*--------------------------------------------------------------*/
static void reinitialize()
{
int i, j;
NETLIST nl;
NET net;
ROUTE rt;
SEG seg;
DSEG obs, tap;
NODE node;
GATE gate;
DPOINT dpt;
// Free up all of the matrices
for (i = 0; i < Pinlayers; i++) {
for (j = 0; j < NumChannelsX * NumChannelsY; j++)
if (Nodeinfo[i][j])
free(Nodeinfo[i][j]);
free(Nodeinfo[i]);
Nodeinfo[i] = NULL;
}
for (i = 0; i < Num_layers; i++) {
free(Obs2[i]);
free(Obs[i]);
Obs2[i] = NULL;
Obs[i] = NULL;
}
if (RMask != NULL) {
free(RMask);
RMask = NULL;
}
// Free the netlist of failed nets (if there is one)
remove_failed();
// Free all net and route information
for (i = 0; i < Numnets; i++) {
net = Nlnets[i];
while (net->noripup) {
nl = net->noripup;
net->noripup = net->noripup->next;
free(nl);
}
while (net->routes)
remove_top_route(net);
while (net->netnodes) {
node = net->netnodes;
net->netnodes = net->netnodes->next;
while (node->taps) {
dpt = node->taps;
node->taps = node->taps->next;
free(dpt);
}
while (node->extend) {
dpt = node->extend;
node->extend = node->extend->next;
free(dpt);
}
// Note: node->netname is not allocated
// but copied from net record
free(node);
}
free (net->netname);
free (net);
}
free(Nlnets);
Nlnets = NULL;
Numnets = 0;
// Free all gates information
while (Nlgates) {
gate = Nlgates;
Nlgates = Nlgates->next;
while (gate->obs) {
obs = gate->obs;
gate->obs = gate->obs->next;
free(obs);
}
for (i = 0; i < gate->nodes; i++) {
while (gate->taps[i]) {
tap = gate->taps[i];
gate->taps[i] = gate->taps[i]->next;
free(tap);
}
// Note: gate->node[i] is not allocated
// but copied from cell record in GateInfo
// Likewise for gate->noderec[i]
}
free(gate->gatename);
}
Nlgates = NULL;
}
/*--------------------------------------------------------------*/
/* apply_drc_blocks() --- */
/* */
/* Use via and route width and spacing information to determine */
/* if blockages are needed in tracks adjacent to routed */
/* segments to avoid causing DRC errors in the output. */
/* */
/* If layer == -1, then determine values normally for all */
/* route layers. If layer >= 0, determine values for specified */
/* layer only. If via_except > 0, then adjust the value for */
/* a DRC violating distance for vias in adjacent tracks by that */
/* amount (in microns). If route_except > 0, then adjust the */
/* value for a DRC violating distance between a via and a route */
/* in adjacent tracks by that amount. */
/*--------------------------------------------------------------*/
void apply_drc_blocks(int layer, double via_except, double route_except)
{
int i;
double sreq1, sreq2, sreq2t;
// Fill in needblock bit fields, which are used by commit_proute
// when route layers are too large for the grid size, and grid points
// around a route need to be marked as blocked whenever something is
// routed on those layers.
// "ROUTEBLOCK" is set if the spacing is violated between a normal
// route and an adjacent via. "VIABLOCK" is set if the spacing is
// violated between two adjacent vias. It may be helpful to define
// a third category which is route-to-route spacing violation.
// There are up to four different via types per base layer with
// different geometries based on the permutation of rotations of
// the top and bottom layers, so we only register blocking behavior
// if all of the via types will generate spacing violations.
for (i = 0; i < Num_layers; i++) {
if ((layer >= 0) && (i != layer)) continue;
needblock[i] = FALSE;
sreq1 = LefGetRouteSpacing(i);
if (i < Num_layers - 1) {
sreq2 = LefGetXYViaWidth(i, i, 0, 0) + sreq1;
sreq2t = LefGetXYViaWidth(i, i, 0, 1) + sreq1;
if (sreq2t < sreq2) sreq2 = sreq2t;
sreq2t = LefGetXYViaWidth(i, i, 0, 2) + sreq1;
if (sreq2t < sreq2) sreq2 = sreq2t;
sreq2t = LefGetXYViaWidth(i, i, 0, 3) + sreq1;
if (sreq2t < sreq2) sreq2 = sreq2t;
sreq2 -= via_except;
if ((sreq2 - EPS) > PitchX) needblock[i] |= VIABLOCKX;
}
if (i != 0) {
sreq2 = LefGetXYViaWidth(i - 1, i, 0, 0) + sreq1;
sreq2t = LefGetXYViaWidth(i - 1, i, 0, 1) + sreq1;
if (sreq2t < sreq2) sreq2 = sreq2t;
sreq2t = LefGetXYViaWidth(i - 1, i, 0, 2) + sreq1;
if (sreq2t < sreq2) sreq2 = sreq2t;
sreq2t = LefGetXYViaWidth(i - 1, i, 0, 3) + sreq1;
if (sreq2t < sreq2) sreq2 = sreq2t;
sreq2 -= via_except;
if ((sreq2 - EPS) > PitchX) needblock[i] |= VIABLOCKX;
}
if (i < Num_layers - 1) {
sreq2 = LefGetXYViaWidth(i, i, 1, 0) + sreq1;
sreq2t = LefGetXYViaWidth(i, i, 1, 1) + sreq1;
if (sreq2t < sreq2) sreq2 = sreq2t;
sreq2t = LefGetXYViaWidth(i, i, 1, 2) + sreq1;
if (sreq2t < sreq2) sreq2 = sreq2t;
sreq2t = LefGetXYViaWidth(i, i, 1, 3) + sreq1;
if (sreq2t < sreq2) sreq2 = sreq2t;
sreq2 -= via_except;
if ((sreq2 - EPS) > PitchY) needblock[i] |= VIABLOCKY;
}
if (i != 0) {
sreq2 = LefGetXYViaWidth(i - 1, i, 1, 0) + sreq1;
sreq2t = LefGetXYViaWidth(i - 1, i, 1, 1) + sreq1;
if (sreq2t < sreq2) sreq2 = sreq2t;
sreq2t = LefGetXYViaWidth(i - 1, i, 1, 2) + sreq1;
if (sreq2t < sreq2) sreq2 = sreq2t;
sreq2t = LefGetXYViaWidth(i - 1, i, 1, 3) + sreq1;
if (sreq2t < sreq2) sreq2 = sreq2t;
sreq2 -= via_except;
if ((sreq2 - EPS) > PitchY) needblock[i] |= VIABLOCKY;
}
sreq1 += 0.5 * LefGetRouteWidth(i);
if (i < Num_layers - 1) {
sreq2 = sreq1 + 0.5 * LefGetXYViaWidth(i, i, 0, 0);
sreq2t = sreq1 + 0.5 * LefGetXYViaWidth(i, i, 0, 1);
if (sreq2t < sreq2) sreq2 = sreq2t;
sreq2t = sreq1 + 0.5 * LefGetXYViaWidth(i, i, 0, 2);
if (sreq2t < sreq2) sreq2 = sreq2t;
sreq2t = sreq1 + 0.5 * LefGetXYViaWidth(i, i, 0, 3);
if (sreq2t < sreq2) sreq2 = sreq2t;
sreq2 -= route_except;
if ((sreq2 - EPS) > PitchX) needblock[i] |= ROUTEBLOCKX;
}
if (i != 0) {
sreq2 = sreq1 + 0.5 * LefGetXYViaWidth(i - 1, i, 0, 0);
sreq2t = sreq1 + 0.5 * LefGetXYViaWidth(i - 1, i, 0, 1);
if (sreq2t < sreq2) sreq2 = sreq2t;
sreq2t = sreq1 + 0.5 * LefGetXYViaWidth(i - 1, i, 0, 2);
if (sreq2t < sreq2) sreq2 = sreq2t;
sreq2t = sreq1 + 0.5 * LefGetXYViaWidth(i - 1, i, 0, 3);
if (sreq2t < sreq2) sreq2 = sreq2t;
sreq2 -= route_except;
if ((sreq2 - EPS) > PitchX) needblock[i] |= ROUTEBLOCKX;
}
if (i < Num_layers - 1) {
sreq2 = sreq1 + 0.5 * LefGetXYViaWidth(i, i, 1, 0);
sreq2t = sreq1 + 0.5 * LefGetXYViaWidth(i, i, 1, 1);
if (sreq2t < sreq2) sreq2 = sreq2t;
sreq2t = sreq1 + 0.5 * LefGetXYViaWidth(i, i, 1, 2);
if (sreq2t < sreq2) sreq2 = sreq2t;
sreq2t = sreq1 + 0.5 * LefGetXYViaWidth(i, i, 1, 3);
if (sreq2t < sreq2) sreq2 = sreq2t;
sreq2 -= route_except;
if ((sreq2 - EPS) > PitchY) needblock[i] |= ROUTEBLOCKY;
}
if (i != 0) {
sreq2 = sreq1 + 0.5 * LefGetXYViaWidth(i - 1, i, 1, 0);
sreq2t = sreq1 + 0.5 * LefGetXYViaWidth(i - 1, i, 1, 1);
if (sreq2t < sreq2) sreq2 = sreq2t;
sreq2t = sreq1 + 0.5 * LefGetXYViaWidth(i - 1, i, 1, 2);
if (sreq2t < sreq2) sreq2 = sreq2t;
sreq2t = sreq1 + 0.5 * LefGetXYViaWidth(i - 1, i, 1, 3);
if (sreq2t < sreq2) sreq2 = sreq2t;
sreq2 -= route_except;
if ((sreq2 - EPS) > PitchY) needblock[i] |= ROUTEBLOCKY;
}
}
}
/*--------------------------------------------------------------*/
/* remove_tap_blocks */
/* */
/* Qrouter avoids routing directly over a tap point, blocking */
/* it, if there is a Nodeinfo[][]->nodeloc entry present. */
/* Remove this entry to remove the blockage (it can be */
/* replaced if needed by copying back the Nodeinfo[][]->nodesav */
/* pointer) */
/*--------------------------------------------------------------*/
void
remove_tap_blocks(int netnum)
{
int i, j;
NODE node;
for (i = 0; i < Pinlayers; i++) {
for (j = 0; j < NumChannelsX * NumChannelsY; j++) {
if (Nodeinfo[i][j]) {
node = Nodeinfo[i][j]->nodeloc;
if (node != (NODE)NULL)
if (node->netnum == netnum)
Nodeinfo[i][j]->nodeloc = (NODE)NULL;
}
}
}
}
/*--------------------------------------------------------------*/
/* post_def_setup --- */
/* */
/* Things to do after a DEF file has been read in, and the size */
/* of the layout, components, and nets are known. */
/*--------------------------------------------------------------*/
static int post_def_setup()
{
NET net;
ROUTE rt;
DPOINT tpoint;
int i;
if (DEFfilename == NULL) {
Fprintf(stderr, "No DEF file read, nothing to set up.\n");
return 1;
}
else {
if (Num_layers <= 0) {
Fprintf(stderr, "No routing layers defined, nothing to do.\n");
return 1;
}
}
for (i = 0; i < Numnets; i++) {
net = Nlnets[i];
find_bounding_box(net);
defineRouteTree(net);
}
create_netorder(0); // Choose ordering method (0 or 1)
set_num_channels(); // If not called from DefRead()
allocate_obs_array(); // If not called from DefRead()
initMask();
for (i = 0; i < Num_layers; i++) {
Obsinfo[i] = (ObsInfoRec *)calloc(NumChannelsX * NumChannelsY,
sizeof(ObsInfoRec));
if (!Obsinfo[i]) {
fprintf(stderr, "Out of memory 5.\n");
exit(5);
}
Nodeinfo[i] = (NODEINFO *)calloc(NumChannelsX * NumChannelsY,
sizeof(NODEINFO));
if (!Nodeinfo[i]) {
fprintf( stderr, "Out of memory 6.\n");
exit(6);
}
}
Flush(stdout);
if (Verbose > 1)
Fprintf(stderr, "Diagnostic: memory block is %d bytes\n",
(int)sizeof(u_int) * NumChannelsX * NumChannelsY);
/* If any watch points were made, make sure that they have */
/* the correct geometry values, since they were made before */
/* the DEF file was read. */
for (tpoint = testpoint; tpoint; tpoint = tpoint->next) {
if (tpoint->gridx < 0) {
/* Compute gridx,y from x,y */
tpoint->gridx = (int)(round((tpoint->x - Xlowerbound) / PitchX));
tpoint->gridy = (int)(round((tpoint->y - Xlowerbound) / PitchX));
}
else {
/* Compute x,y from gridx,y */
tpoint->x = (tpoint->gridx * PitchX) + Xlowerbound;
tpoint->y = (tpoint->gridy * PitchY) + Ylowerbound;
}
}
/* Be sure to create obstructions from gates first, since we don't */
/* want improperly defined or positioned obstruction layers to over- */
/* write our node list. */
expand_tap_geometry();
clip_gate_taps();
create_obstructions_from_gates();
create_obstructions_inside_nodes();
create_obstructions_outside_nodes();
tap_to_tap_interactions();
create_obstructions_from_variable_pitch();
adjust_stub_lengths();
find_route_blocks();
count_reachable_taps(unblockAll);
count_pinlayers();
// If any nets are pre-routed, calculate route endpoints, and
// place those routes.
for (i = 0; i < Numnets; i++) {
net = Nlnets[i];
for (rt = net->routes; rt; rt = rt->next)
route_set_connections(net, rt);
writeback_all_routes(net);
}
// Remove the Obsinfo array, which is no longer needed, and allocate
// the Obs2 array for costing information
for (i = 0; i < Num_layers; i++) free(Obsinfo[i]);
for (i = 0; i < Num_layers; i++) {
Obs2[i] = (PROUTE *)calloc(NumChannelsX * NumChannelsY,
sizeof(PROUTE));
if (!Obs2[i]) {
fprintf( stderr, "Out of memory 9.\n");
exit(9);
}
}
// Remove tap blocks from power, ground, and antenna nets, as these
// can take up large areas of the layout and will cause serious issues
// with routability if left blocked.
remove_tap_blocks(VDD_NET);
remove_tap_blocks(GND_NET);
remove_tap_blocks(ANTENNA_NET);
// Now we have netlist data, and can use it to get a list of nets.
FailedNets = (NETLIST)NULL;
Flush(stdout);
if (Verbose > 0)
Fprintf(stdout, "There are %d nets in this design.\n", Numnets);
return 0;
}
/*--------------------------------------------------------------*/
/* read_def --- */
/* */
/* Read in the DEF file in DEFfilename */
/* Return 0 on success, 1 on fatal error in DEF file. */
/*--------------------------------------------------------------*/
int read_def(char *filename)
{
float oscale;
double precis;
int result;
if ((filename == NULL) && (DEFfilename == NULL)) {
Fprintf(stderr, "No DEF file specified, nothing to read.\n");
return 1;
}
else if (filename != NULL) {
if (DEFfilename != NULL) {
reinitialize();
free(DEFfilename);
}
DEFfilename = strdup(filename);
}
else reinitialize();
oscale = (float)0.0;
result = DefRead(DEFfilename, &oscale);
precis = Scales.mscale / (double)oscale; // from LEF manufacturing grid
if (precis < 1.0) precis = 1.0;
precis *= (double)Scales.iscale; // user-defined extra scaling
Scales.iscale = (int)(precis + 0.5);
Scales.oscale = (double)(Scales.iscale * oscale);
if (Verbose > 0)
Fprintf(stdout, "Output scale = microns / %g, precision %g\n",
Scales.oscale / (double)Scales.iscale,
1.0 / (double)Scales.iscale);
post_def_setup();
return result;
}
/*--------------------------------------------------------------*/
/*--------------------------------------------------------------*/
int dofirststage(u_char graphdebug, int debug_netnum)
{
int i, failcount, remaining, result;
NET net;
NETLIST nl;
// Clear the lists of failed routes, in case first
// stage is being called more than once.
if (debug_netnum <= 0) remove_failed();
// Now find and route all the nets
remaining = Numnets;
for (i = (debug_netnum >= 0) ? debug_netnum : 0; i < Numnets; i++) {