-
Notifications
You must be signed in to change notification settings - Fork 17
/
node.c
3605 lines (3190 loc) · 111 KB
/
node.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
/*--------------------------------------------------------------*/
/* node.c -- Generation of detailed network and obstruction */
/* information on the routing grid based on the geometry of the */
/* layout of the standard cell macros. */
/* */
/*--------------------------------------------------------------*/
/* Written by Tim Edwards, June, 2011, based on work by Steve */
/* Beccue. */
/*--------------------------------------------------------------*/
#include <stdio.h>
#include <math.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include "qrouter.h"
#include "node.h"
#include "qconfig.h"
#include "lef.h"
#include "def.h"
#include "output.h"
/*--------------------------------------------------------------*/
/* SetNodeinfo -- */
/* Allocate a NODEINFO record and put it in the Nodeinfo */
/* array at position (gridx, gridy, d->layer). Return the */
/* pointer to the location. */
/*--------------------------------------------------------------*/
NODEINFO
SetNodeinfo(int gridx, int gridy, int layer, NODE node)
{
DPOINT dp;
NODEINFO *lnodeptr;
lnodeptr = &NODEIPTR(gridx, gridy, layer);
if (*lnodeptr == NULL) {
*lnodeptr = (NODEINFO)calloc(1, sizeof(struct nodeinfo_));
/* Make sure this position is in the list of node's taps. Add */
/* it if it is not there. */
for (dp = (DPOINT)node->taps; dp; dp = dp->next)
if (dp->gridx == gridx && dp->gridy == gridy && dp->layer == layer)
break;
if (dp == NULL)
for (dp = (DPOINT)node->extend; dp; dp = dp->next)
if (dp->gridx == gridx && dp->gridy == gridy && dp->layer == layer)
break;
if (dp == NULL) {
dp = (DPOINT)malloc(sizeof(struct dpoint_));
dp->gridx = gridx;
dp->gridy = gridy;
dp->layer = layer;
dp->x = (gridx * PitchX) + Xlowerbound;
dp->y = (gridy * PitchY) + Ylowerbound;
dp->next = node->extend;
node->extend = dp;
}
}
return *lnodeptr;
}
/*--------------------------------------------------------------*/
/* FreeNodeinfo -- */
/* Free a NODEINFO record at array Nodeinfo position */
/* (gridx, gridy, d->layer). Set the position pointer to */
/* NULL. */
/*--------------------------------------------------------------*/
void
FreeNodeinfo(int gridx, int gridy, int layer)
{
NODEINFO *lnodeptr;
lnodeptr = &NODEIPTR(gridx, gridy, layer);
if (*lnodeptr != NULL) {
free(*lnodeptr);
*lnodeptr = NULL;
}
}
/*--------------------------------------------------------------*/
/* count_reachable_taps() */
/* */
/* For each grid point in the layout, find if it corresponds */
/* to a node and is unobstructed. If so, increment the node's */
/* count of reachable taps. Then work through the list of */
/* nodes and determine if any are completely unreachable. If */
/* so, then unobstruct any position that is inside tap */
/* geometry that can contain a via. */
/* */
/* NOTE: This routine should check for tap rectangles that */
/* may combine to form an area large enough to place a via; */
/* also, it should check for tap points that are routable */
/* by a wire and not a tap. However, those conditions are */
/* rare and are left unhandled for now. */
/* */
/* If "unblock_all" is 1, then unblock all grid points that */
/* are cleanly routable by being completely inside a pin with */
/* available margins for placing a via, regardless of whether */
/* or not the pin has other available tap points. This should */
/* only be used if obstructions are drawn in the style where */
/* they can abut pins (e.g., part of the pin has been marked */
/* as an obstruction). */
/*--------------------------------------------------------------*/
void
count_reachable_taps(u_char unblock_all)
{
NODE node;
NODEINFO lnode;
GATE g;
DSEG ds;
int l, i, j, orient;
int gridx, gridy;
double deltax, deltay;
double dx, dy;
for (l = 0; l < Num_layers; l++) {
for (j = 0; j < NumChannelsX * NumChannelsY; j++) {
if (Nodeinfo[l][j]) {
node = Nodeinfo[l][j]->nodeloc;
if (node != NULL) {
// Redundant check; if Obs has NO_NET set, then
// Nodeinfo->nodeloc for that position should already
// be NULL
if (!(Obs[l][j] & NO_NET))
node->numtaps++;
}
}
}
}
for (g = Nlgates; g; g = g->next) {
for (i = 0; i < g->nodes; i++) {
node = g->noderec[i];
if (node == NULL) continue;
if (node->numnodes == 0) continue; // e.g., vdd or gnd bus
if ((node->numtaps == 0) || (unblock_all == TRUE)) {
/* Will try more than one via if available */
for (orient = 0; orient < 4; orient += 2) {
for (ds = g->taps[i]; ds; ds = ds->next) {
deltax = 0.5 * LefGetXYViaWidth(ds->layer, ds->layer, 0, orient);
deltay = 0.5 * LefGetXYViaWidth(ds->layer, ds->layer, 1, orient);
gridx = (int)((ds->x1 - Xlowerbound) / PitchX) - 1;
if (gridx < 0) gridx = 0;
while (1) {
dx = (gridx * PitchX) + Xlowerbound;
if (dx > ds->x2 || gridx >= NumChannelsX) break;
if (((dx - ds->x1 + EPS) > deltax) &&
((ds->x2 - dx + EPS) > deltax)) {
gridy = (int)((ds->y1 - Ylowerbound)
/ PitchY) - 1;
if (gridy < 0) gridy = 0;
while (1) {
dy = (gridy * PitchY) + Ylowerbound;
if (dy > ds->y2 || gridy >= NumChannelsY)
break;
if (((dy - ds->y1 + EPS) > deltay) &&
((ds->y2 - dy + EPS) > deltay)) {
if ((ds->layer == Num_layers - 1) ||
!(OBSVAL(gridx, gridy, ds->layer + 1)
& NO_NET)) {
// Grid position is clear for placing a via
if ((orient == 0) && (Verbose > 1))
Fprintf(stdout, "Tap position (%g, %g)"
" appears to be technically routable"
" so it is being forced routable.\n",
dx, dy);
else if (Verbose > 1)
Fprintf(stdout, "Tap position (%g, %g)"
" appears to be technically routable"
" with alternate via, so it is being"
" forced routable.\n", dx, dy);
OBSVAL(gridx, gridy, ds->layer) =
(OBSVAL(gridx, gridy, ds->layer)
& BLOCKED_MASK)
| (u_int)node->netnum;
lnode = SetNodeinfo(gridx, gridy, ds->layer,
node);
lnode->nodeloc = node;
lnode->nodesav = node;
/* If we got to orient = 2, mark NI_NO_VIAX */
if (orient == 2) lnode->flags |= NI_NO_VIAX;
/* This is a bit harsh, but should work */
else lnode->flags |= NI_NO_VIAY;
node->numtaps++;
}
}
gridy++;
}
}
gridx++;
}
}
/* If there's a solution, don't go looking at other vias */
if (node->numtaps > 0) break;
}
}
if (node->numtaps == 0) {
/* Node wasn't cleanly within tap geometry when centered */
/* on a grid point. But if the via can be offset and is */
/* cleanly within the tap geometry, then allow it. */
double dist, mindist;
int dir, mask, tapx, tapy, tapl;
/* Will try more than one via if available */
for (orient = 0; orient < 4; orient += 2) {
/* Initialize mindist to a large value */
mask = 0;
mindist = PitchX + PitchY;
dir = 0; /* Indicates no solution found */
for (ds = g->taps[i]; ds; ds = ds->next) {
deltax = 0.5 * LefGetXYViaWidth(ds->layer, ds->layer, 0, orient);
deltay = 0.5 * LefGetXYViaWidth(ds->layer, ds->layer, 1, orient);
gridx = (int)((ds->x1 - Xlowerbound) / PitchX) - 1;
if (gridx < 0) gridx = 0;
while (1) {
dx = (gridx * PitchX) + Xlowerbound;
if (dx > ds->x2 || gridx >= NumChannelsX) break;
if (((dx - ds->x1 + EPS) > -deltax) &&
((ds->x2 - dx + EPS) > -deltax)) {
gridy = (int)((ds->y1 - Ylowerbound) / PitchY) - 1;
if (gridy < 0) gridy = 0;
while (1) {
dy = (gridy * PitchY) + Ylowerbound;
if (dy > ds->y2 || gridy >= NumChannelsY)
break;
// Check that the grid position is inside the
// tap rectangle.
// NOTE: If the point above the grid is blocked,
// then a via cannot be placed here, so skip it.
// This currently looks only for completely
// obstructed positions. To do: For directionally
// obstructed positions, see if the obstruction
// is in the opposite direction of the via's
// offset and at least the same distance.
// Otherwise, it won't clear.
if (((ds->layer == Num_layers - 1) ||
!(OBSVAL(gridx, gridy, ds->layer + 1)
& (NO_NET || OBSTRUCT_MASK))) &&
((dy - ds->y1 + EPS) > -deltay) &&
((ds->y2 - dy + EPS) > -deltay)) {
// Grid point is inside tap geometry.
// Since it did not pass the simple insideness
// test previously, it can be assumed that
// one of the edges is closer to the grid point
// than 1/2 via width. Find that edge and use
// it to determine the offset.
// Check right edge
if ((ds->x2 - dx + EPS) < deltax) {
dist = deltax - ds->x2 + dx;
// Confirm other edges
if ((dx - dist - deltax + EPS > ds->x1) &&
(dy - deltay + EPS > ds->y1) &&
(dy + deltay - EPS < ds->y2)) {
if (dist < fabs(mindist)) {
mindist = dist;
mask = STUBROUTE;
dir = NI_STUB_EW;
tapx = gridx;
tapy = gridy;
tapl = ds->layer;
}
}
}
// Check left edge
if ((dx - ds->x1 + EPS) < deltax) {
dist = deltax - dx + ds->x1;
// Confirm other edges
if ((dx + dist + deltax - EPS < ds->x2) &&
(dy - deltay + EPS > ds->y1) &&
(dy + deltay - EPS < ds->y2)) {
if (dist < fabs(mindist)) {
mindist = -dist;
mask = STUBROUTE;
dir = NI_STUB_EW;
tapx = gridx;
tapy = gridy;
tapl = ds->layer;
}
}
}
// Check top edge
if ((ds->y2 - dy + EPS) < deltay) {
dist = deltay - ds->y2 + dy;
// Confirm other edges
if ((dx - deltax + EPS > ds->x1) &&
(dx + deltax - EPS < ds->x2) &&
(dy - dist - deltay + EPS > ds->y1)) {
if (dist < fabs(mindist)) {
mindist = -dist;
mask = STUBROUTE;
dir = NI_STUB_NS;
tapx = gridx;
tapy = gridy;
tapl = ds->layer;
}
}
}
// Check bottom edge
if ((dy - ds->y1 + EPS) < deltay) {
dist = deltay - dy + ds->y1;
// Confirm other edges
if ((dx - deltax + EPS > ds->x1) &&
(dx + deltax - EPS < ds->x2) &&
(dy + dist + deltay - EPS < ds->y2)) {
if (dist < fabs(mindist)) {
mindist = dist;
mask = STUBROUTE;
dir = NI_STUB_NS;
tapx = gridx;
tapy = gridy;
tapl = ds->layer;
}
}
}
}
gridy++;
}
}
gridx++;
}
}
/* Was a solution found? */
if (mask != 0) {
// Grid position is clear for placing a via
if (Verbose > 1)
Fprintf(stdout, "Tap position (%d, %d) appears to be"
" technically routable with an offset, so"
" it is being forced routable.\n",
tapx, tapy);
OBSVAL(tapx, tapy, tapl) =
(OBSVAL(tapx, tapy, tapl) & BLOCKED_MASK)
| mask | (u_int)node->netnum;
lnode = SetNodeinfo(tapx, tapy, tapl, node);
lnode->nodeloc = node;
lnode->nodesav = node;
lnode->stub = dist;
lnode->flags |= dir;
/* If we got to orient = 2 then mark NI_NO_VIAX */
if (orient == 2) lnode->flags |= NI_NO_VIAX;
node->numtaps++;
}
/* If there's a solution, don't go looking at other vias */
if (node->numtaps > 0) break;
}
}
}
}
/* Last pass to output error messages for any taps that were not */
/* handled by the code above. */
for (g = Nlgates; g; g = g->next) {
for (i = 0; i < g->nodes; i++) {
node = g->noderec[i];
if (node == NULL) continue;
if (node->numnodes == 0) continue; // e.g., vdd or gnd bus
if (node->numtaps == 0) {
Fprintf(stderr, "Error: Node %s of net \"%s\" has no taps!\n",
print_node_name(node), node->netname);
Fprintf(stderr, "Qrouter will not be able to completely"
" route this net.\n");
if (Verbose > 1) {
int found_inside, found_inrange;
Fprintf(stderr, "Tap position blockage analysis:\n");
/* Unreachable taps are the most common problem with */
/* new processes or buggy code, so make a detailed */
/* report of blockages affecting routing for debugging. */
found_inside = found_inrange = 0;
for (ds = g->taps[i]; ds; ds = ds->next) {
unsigned char is_inside, is_inrange;
deltax = 0.5 * LefGetXYViaWidth(ds->layer, ds->layer, 0, 0);
deltay = 0.5 * LefGetXYViaWidth(ds->layer, ds->layer, 1, 0);
Fprintf(stderr, "Tap geometry (%g %g) to (%g %g):\n",
ds->x1, ds->y1, ds->x2, ds->y2);
gridx = (int)(((ds->x1 - 1) - Xlowerbound) / PitchX) - 1;
if (gridx < 0) gridx = 0;
while (1) {
dx = (gridx * PitchX) + Xlowerbound;
if (dx > (ds->x2 + 1) || gridx >= NumChannelsX) break;
gridy = (int)(((ds->y1 - 1) - Ylowerbound) / PitchY) - 1;
if (gridy < 0) gridy = 0;
while (1) {
dy = (gridy * PitchY) + Ylowerbound;
if (dy > (ds->y2 + 1) || gridy >= NumChannelsY)
break;
is_inside = (dx >= ds->x1 && dx <= ds->x2 &&
dy >= ds->y1 && dy <= ds->y2) ? 1 : 0;
is_inrange = (dx > ds->x1 - deltax &&
dx < ds->x2 + deltax &&
dy > ds->y1 - deltay &&
dy < ds->y2 + deltay) ? 1 : 0;
if (is_inrange) {
Fprintf(stderr, "Grid position (%d %d) at (%g %g) "
"layer %d is %s tap geometry.\n",
gridx, gridy, dx, dy, ds->layer,
(is_inside == 1) ? "inside" : "outside");
print_grid_information(gridx, gridy, ds->layer);
found_inrange++;
if (is_inside) found_inside++;
}
gridy++;
}
gridx++;
}
}
if (found_inrange == 0) Fprintf(stderr, "No positions analyzed.\n");
Fprintf(stderr, "%d grid position%s found "
"inside tap geometry\n", found_inside,
((found_inside == 1) ? " was" : "s were"));
Fprintf(stderr, "%d grid position%s found "
"nearby tap geometry\n", found_inrange,
((found_inrange == 1) ? " was" : "s were"));
}
}
}
}
}
/*--------------------------------------------------------------*/
/* check_variable_pitch() */
/* */
/* This routine is used by the routine below it to generate */
/* obstructions that force routes to be placed in 1-of-N */
/* tracks. However, it is also used to determine the same */
/* information for the .info file, so that the effective */
/* pitch is output, not the pitch copied from the LEF file. */
/* Output is the vertical and horizontal pitch multipliers, */
/* passed back through pointers. */
/*--------------------------------------------------------------*/
void check_variable_pitch(int l, int *hptr, int *vptr)
{
int o, hnum, vnum;
double vpitch, hpitch, wvia, wviax, wviay;
o = LefGetRouteOrientation(l);
// Note that when "horizontal" (o = 1) is passed to LefGetXYViaWidth,
// it returns the via width top-to-bottom (orient meaning is
// reversed for LefGetXYViaWidth), which is what we want. . .
// Try both via orientations and choose the best, assuming that it is
// a lot easier to rotate and shift vias around than it is to lose
// half the routing grid.
if (l == 0) {
wviax = LefGetXYViaWidth(l, l, o, 0);
wviay = LefGetXYViaWidth(l, l, o, 3);
}
else {
wviax = LefGetXYViaWidth(l - 1, l, o, 0);
wviay = LefGetXYViaWidth(l - 1, l, o, 3);
}
wvia = (wviax < wviay) ? wviax : wviay;
if (o == 1) { // Horizontal route
vpitch = LefGetRoutePitch(l);
// Changed: routes must be able to accomodate the placement
// of a via in the track next to it.
// hpitch = LefGetRouteWidth(l) + LefGetRouteSpacing(l);
hpitch = 0.5 * (LefGetRouteWidth(l) + wvia) + LefGetRouteSpacing(l);
}
else { // Vertical route
hpitch = LefGetRoutePitch(l);
// vpitch = LefGetRouteWidth(l) + LefGetRouteSpacing(l);
vpitch = 0.5 * (LefGetRouteWidth(l) + wvia) + LefGetRouteSpacing(l);
}
vnum = (int)((vpitch / PitchY) - EPS) + 1;
hnum = (int)((hpitch / PitchX) - EPS) + 1;
// To mark blockages, either none of (hnum & vnum) should be
// larger than 1, or both of them should be. Further info in
// create_obstructions_from_variable_pitch(), below.
if (vnum > 1 && hnum == 1) hnum++;
if (hnum > 1 && vnum == 1) vnum++;
*vptr = vnum;
*hptr = hnum;
}
/*--------------------------------------------------------------*/
/* create_obstructions_from_variable_pitch() */
/* */
/* Although it would be nice to have an algorithm that would */
/* work with any arbitrary pitch, qrouter will work around */
/* having larger pitches on upper metal layers by selecting */
/* 1 out of every N tracks for routing, and placing */
/* obstructions in the interstices. This makes the possibly */
/* unwarranted assumption that the contact down to the layer */
/* below does not cause spacing violations to neighboring */
/* tracks. If that assumption fails, this routine will have */
/* to be revisited. */
/*--------------------------------------------------------------*/
void create_obstructions_from_variable_pitch(void)
{
int l, vnum, hnum, hoff, voff, x, y;
NODEINFO lnode;
TRACKS tracksinfo, tracksinfoother;
for (l = 0; l < Num_layers; l++) {
// check_variable_pitch() guarantees that either hnum
// and vnum are both one, or both are larger than 1.
check_variable_pitch(l, &hnum, &vnum);
if (hnum == 1 && vnum == 1) continue; // No obstructions needed
// Compute the offset of the tracks to mark obstructions
tracksinfo = DefGetTracks(l);
if (tracksinfo == NULL) {
// Should look at standard cell placement and LEF offset
// to determine offset here. For now, just use 0.
hoff = voff = 0;
}
else {
// Use the start position relative to lowerbound to determine
// the offset. use the offset of the higher or lower layer
// for determining the offset in the opposite direction of
// the current layer orientation.
if (l < Num_layers - 1) {
// If not the top layer, then use the upper layer as the other layer
tracksinfoother = DefGetTracks(l + 1);
}
else if (l > 0) {
// Otherwise, use the lower layer
tracksinfoother = DefGetTracks(l - 1);
}
else {
// Should not happen, as it means routing is done with one layer. . .
tracksinfoother = (TRACKS)NULL;
}
if (Vert[l]) {
hoff = (int)((tracksinfo->start - Xlowerbound) / PitchX + 0.5);
voff = (tracksinfoother == (TRACKS)NULL) ?
0 : (int)((tracksinfoother->start - Ylowerbound) / PitchY + 0.5);
}
else {
voff = (int)((tracksinfo->start - Ylowerbound) / PitchY + 0.5);
hoff = (tracksinfoother == (TRACKS)NULL) ?
0 : (int)((tracksinfoother->start - Xlowerbound) / PitchX + 0.5);
}
}
// This could be better handled by restricting
// access from specific directions rather than
// marking a position as NO_NET. Since the
// routine below will mark no positions restricted
// if either hnum is 1 or vnum is 1, regardless of
// the other value, then we force both values to
// be at least 2.
if (vnum > 1 || hnum > 1) {
for (x = 0; x < NumChannelsX; x++) {
if ((x - hoff) % hnum == 0) continue;
for (y = 0; y < NumChannelsY; y++) {
if ((y - voff) % vnum == 0) continue;
// If the grid position itself is a node, don't restrict
// routing based on variable pitch.
if (((lnode = NODEIPTR(x, y, l)) != NULL) && (lnode->nodeloc != NULL))
continue;
// If there is a node in an adjacent grid then allow
// routing from that direction.
if ((x > 0) && ((lnode = NODEIPTR(x - 1, y, l)) != NULL) &&
(lnode->nodeloc != NULL))
OBSVAL(x, y, l) = BLOCKED_MASK & ~BLOCKED_W;
else if ((y > 0) && ((lnode = NODEIPTR(x , y - 1, l)) != NULL) &&
(lnode->nodeloc != NULL))
OBSVAL(x, y, l) = BLOCKED_MASK & ~BLOCKED_S;
else if ((x < NumChannelsX - 1)
&& ((lnode = NODEIPTR(x + 1, y, l)) != NULL) &&
(lnode->nodeloc != NULL))
OBSVAL(x, y, l) = BLOCKED_MASK & ~BLOCKED_E;
else if ((y < NumChannelsY - 1)
&& ((lnode = NODEIPTR(x, y + 1, l)) != NULL) &&
(lnode->nodeloc != NULL))
OBSVAL(x, y, l) = BLOCKED_MASK & ~BLOCKED_N;
else
OBSVAL(x, y, l) = NO_NET;
}
}
}
}
}
/*--------------------------------------------------------------*/
/* disable_gridpos() --- */
/* Render the position at (x, y, lay) unroutable by */
/* setting its Obs[] entry to NO_NET and removing it from */
/* the Nodeinfo->nodeloc and Nodeinfo->nodesav records. */
/*--------------------------------------------------------------*/
static void
disable_gridpos(int x, int y, int lay)
{
int apos = OGRID(x, y);
Obs[lay][apos] = (u_int)(NO_NET | OBSTRUCT_MASK);
if (Nodeinfo[lay][apos]) {
free(Nodeinfo[lay][apos]);
Nodeinfo[lay][apos] = NULL;
}
}
/*--------------------------------------------------------------*/
/* count_pinlayers()--- */
/* Check which layers have non-NULL Nodeinfo entries. */
/* Then set "Pinlayers" and free all the unused layers. */
/* This saves a lot of memory, especially when the number */
/* of routing layers becomes large. */
/*--------------------------------------------------------------*/
void
count_pinlayers(void)
{
int j, l;
Pinlayers = 0;
for (l = 0; l < Num_layers; l++) {
for (j = 0; j < NumChannelsX * NumChannelsY; j++) {
if (Nodeinfo[l][j]) {
Pinlayers = l + 1;
break;
}
}
}
for (l = Pinlayers; l < Num_layers; l++) {
free(Nodeinfo[l]);
Nodeinfo[l] = NULL;
}
}
/*--------------------------------------------------------------*/
/* check_obstruct()--- */
/* Called from create_obstructions_from_gates(), this */
/* routine takes a grid point at (gridx, gridy) (physical */
/* position (dx, dy)) and an obstruction defined by the */
/* rectangle "ds", and sets flags and fills the Obsinfo */
/* array to reflect how the obstruction affects routing to */
/* the grid position. */
/*--------------------------------------------------------------*/
static void
check_obstruct(int gridx, int gridy, DSEG ds, double dx, double dy, double delta)
{
ObsInfoRec *obsinfoptr;
u_int *obsptr;
u_int origmask;
float distx, disty;
obsptr = &(OBSVAL(gridx, gridy, ds->layer));
// Grid point is inside obstruction + halo.
*obsptr |= NO_NET;
// Completely inside obstruction?
if (dy > ds->y1 && dy < ds->y2 && dx > ds->x1 && dx < ds->x2)
*obsptr |= OBSTRUCT_MASK;
else {
// Make more detailed checks in each direction. If obstructions
// are in multiple directions in X and Y, then mark both. The
// Obsinfo array keeps information on one obstruction distance
// in X and one in Y. If obstructions are on both X sides or
// both Y sides, then the position is marked completely unroutable.
// Note that an obstruction at a corner which blocks from two sides is
// very different from two obstructions that block from the two sides.
// As there is no mechanism in qrouter to offset a tap in both the
// X and Y direction, the second case is unroutable. It needs to be
// detected and marked blocked if so. Then all other code may assume
// that any blockage marked from two directions is catecorner to the
// grid position, and the tap may be moved in either direction to
// avoid the obstruction.
obsinfoptr = &(OBSINFO(gridx, gridy, ds->layer));
// Check for pre-existing conditions
disty = obsinfoptr->yoffset;
distx = obsinfoptr->xoffset;
origmask = *obsptr & OBSTRUCT_MASK;
if (dy <= ds->y1) {
if ((origmask & ~OBSTRUCT_N) == 0) {
if ((disty == 0) || ((ds->y1 - dy) < disty))
obsinfoptr->yoffset = ds->y1 - dy;
*obsptr |= OBSTRUCT_N;
}
else *obsptr |= OBSTRUCT_MASK;
}
else if (dy >= ds->y2) {
if ((origmask & ~OBSTRUCT_S) == 0) {
if ((disty == 0) || ((dy - ds->y2) < disty))
obsinfoptr->yoffset = dy - ds->y2;
*obsptr |= OBSTRUCT_S;
}
else *obsptr |= OBSTRUCT_MASK;
}
if (dx <= ds->x1) {
if ((origmask & ~OBSTRUCT_E) == 0) {
if ((distx == 0) || ((ds->x1 - dx) < distx))
obsinfoptr->xoffset = ds->x1 - dx;
*obsptr |= OBSTRUCT_E;
}
else *obsptr |= OBSTRUCT_MASK;
}
else if (dx >= ds->x2) {
if ((origmask & ~OBSTRUCT_W) == 0) {
if ((distx == 0) || ((dx - ds->x2) < distx))
obsinfoptr->xoffset = dx - ds->x2;
*obsptr |= OBSTRUCT_W;
}
else *obsptr |= OBSTRUCT_MASK;
}
}
}
/*--------------------------------------------------------------*/
/* Find the amount of clearance needed between an obstruction */
/* and a route track position. This takes into consideration */
/* whether the obstruction is wide or narrow metal, if the */
/* spacing rules are graded according to metal width, and if a */
/* via placed at the position is or is not symmetric in X and Y */
/* "orient" is the via orientation, of which there are four; */
/* however, as this only concerns the via bottom layer, the */
/* two orientations are represented by orient = 0 and 2. */
/*--------------------------------------------------------------*/
static double get_via_clear(int lay, int horiz, int orient, DSEG rect) {
double vdelta, v2delta, mdelta, mwidth;
vdelta = LefGetXYViaWidth(lay, lay, 1 - horiz, orient);
if (lay > 0) {
v2delta = LefGetXYViaWidth(lay - 1, lay, 1 - horiz, orient);
if (v2delta > vdelta) vdelta = v2delta;
}
vdelta = vdelta / 2.0;
// Spacing rule is determined by the minimum metal width,
// either in X or Y, regardless of the position of the
// metal being checked.
mwidth = MIN(rect->x2 - rect->x1, rect->y2 - rect->y1);
mdelta = LefGetRouteWideSpacing(lay, mwidth);
return vdelta + mdelta;
}
/*--------------------------------------------------------------*/
/* Find the distance from an obstruction to a grid point, */
/* considering only routes which are placed at the position, */
/* not vias. */
/*--------------------------------------------------------------*/
static double get_route_clear(int lay, DSEG rect) {
double rdelta, mdelta, mwidth;
rdelta = LefGetRouteWidth(lay);
rdelta = rdelta / 2.0;
// Spacing rule is determined by the minimum metal width,
// either in X or Y, regardless of the position of the
// metal being checked.
mwidth = MIN(rect->x2 - rect->x1, rect->y2 - rect->y1);
mdelta = LefGetRouteWideSpacing(lay, mwidth);
return rdelta + mdelta;
}
/*--------------------------------------------------------------*/
/* Truncate gates to the set of tracks. Warn about any gates */
/* with nodes that are clipped entirely outside the routing */
/* area. */
/*--------------------------------------------------------------*/
void clip_gate_taps(void)
{
NET net;
NODE node;
DPOINT dp, dpl;
int i, lay;
for (i = 0; i < Numnets; i++) {
net = Nlnets[i];
for (node = net->netnodes; node; node = node->next) {
dpl = NULL;
for (dp = (DPOINT)node->taps; dp; ) {
lay = dp->layer;
if (dp->gridx < 0 || dp->gridy < 0 ||
dp->gridx >= NumChannelsX ||
dp->gridy >= NumChannelsY) {
Fprintf(stderr, "Tap of port of node %d of net %s"
" is outside of route area\n",
node->nodenum, node->netname);
if (dpl == NULL)
node->taps = dp->next;
else
dpl->next = dp->next;
free(dp);
dp = (dpl == NULL) ? node->taps : dpl->next;
}
else {
dpl = dp;
dp = dp->next;
}
}
}
}
}
/*--------------------------------------------------------------*/
/* create_obstructions_from_gates() */
/* */
/* Fills in the Obs[][] grid from obstructions that were */
/* defined for each macro in the technology LEF file and */
/* translated into a list of grid coordinates in each */
/* instance. */
/* */
/* Also, fills in the Obs[][] grid with obstructions that */
/* are defined by nodes of the gate that are unconnected in */
/* this netlist. */
/*--------------------------------------------------------------*/
void create_obstructions_from_gates(void)
{
GATE g;
DSEG ds;
int i, gridx, gridy, orient;
double deltax, deltay, delta[MAX_LAYERS];
double dx, dy, deltaxy;
// Give a single net number to all obstructions, over the range of the
// number of known nets, so these positions cannot be routed through.
// If a grid position is not wholly inside an obstruction, then we
// maintain the direction of the nearest obstruction in Obs and the
// distance to it in Obsinfo. This indicates that a route can avoid
// the obstruction by moving away from it by the amount in Obsinfo
// plus spacing clearance. If another obstruction is found that
// prevents such a move, then all direction flags will be set, indicating
// that the position is not routable under any condition.
for (g = Nlgates; g; g = g->next) {
orient = 0;
for (ds = g->obs;; ds = ds->next) {
// Run through ds list twice, checking against horizontally and
// vertically oriented vias.
if (ds == NULL) {
if (orient == 2)
break;
else {
orient = 2;
ds = g->obs;
if (ds == NULL) break;
}
}
deltax = get_via_clear(ds->layer, 1, orient, ds);
gridx = (int)((ds->x1 - Xlowerbound - deltax) / PitchX) - 1;
while (1) {
dx = (gridx * PitchX) + Xlowerbound;
if ((dx + EPS) > (ds->x2 + deltax)
|| gridx >= NumChannelsX) break;
else if ((dx - EPS) > (ds->x1 - deltax) && gridx >= 0) {
deltay = get_via_clear(ds->layer, 0, orient, ds);
gridy = (int)((ds->y1 - Ylowerbound - deltay) / PitchY) - 1;
while (1) {
dy = (gridy * PitchY) + Ylowerbound;
if ((dy + EPS) > (ds->y2 + deltay)
|| gridy >= NumChannelsY) break;
if ((dy - EPS) > (ds->y1 - deltay) && gridy >= 0) {
double s, edist, xp, yp;
// Check Euclidean distance measure
s = LefGetRouteSpacing(ds->layer);
if (dx < (ds->x1 + s - deltax)) {
xp = dx + deltax - s;
edist = (ds->x1 - xp) * (ds->x1 - xp);
}
else if (dx > (ds->x2 - s + deltax)) {
xp = dx - deltax + s;
edist = (xp - ds->x2) * (xp - ds->x2);
}
else edist = 0;
if ((edist > 0) && (dy < (ds->y1 + s - deltay))) {
yp = dy + deltay - s;
edist += (ds->y1 - yp) * (ds->y1 - yp);
}
else if ((edist > 0) && (dy > (ds->y2 - s + deltay))) {
yp = dy - deltay + s;
edist += (yp - ds->y2) * (yp - ds->y2);
}
else edist = 0;
if ((edist + EPS) < (s * s)) {
check_obstruct(gridx, gridy, ds, dx, dy, s);
if (is_testpoint(gridx, gridy, g, -1, ds) != NULL)
Fprintf(stderr, " Position blocked by gate obstruction.\n");
}
else
edist = 0; // diagnostic break
}
gridy++;
}
}
gridx++;
}
}
for (i = 0; i < g->nodes; i++) {
if (g->netnum[i] == 0) { /* Unconnected node */
// Diagnostic, and power bus handling
if (g->node[i]) {
// Should we flag a warning if we see something that looks
// like a power or ground net here?
if (Verbose > 1)
Fprintf(stdout, "Gate instance %s unconnected node %s\n",
g->gatename, g->node[i]);
}
else {
if (Verbose > 1)
Fprintf(stdout, "Gate instance %s unconnected node (%d)\n",
g->gatename, i);
}
for (ds = g->taps[i]; ds; ds = ds->next) {
deltax = get_via_clear(ds->layer, 1, orient, ds);
gridx = (int)((ds->x1 - Xlowerbound - deltax) / PitchX) - 1;
while (1) {
dx = (gridx * PitchX) + Xlowerbound;
if (dx > (ds->x2 + deltax)
|| gridx >= NumChannelsX) break;
else if (dx >= (ds->x1 - deltax) && gridx >= 0) {
deltay = get_via_clear(ds->layer, 0, orient, ds);
gridy = (int)((ds->y1 - Ylowerbound - deltay) / PitchY) - 1;
while (1) {
dy = (gridy * PitchY) + Ylowerbound;
if ((dy + EPS) > (ds->y2 + deltay)
|| gridy >= NumChannelsY) break;
if ((dy - EPS) >= (ds->y1 - deltay) && gridy >= 0) {
double s, edist = 0.0, xp, yp;