-
Notifications
You must be signed in to change notification settings - Fork 17
/
antenna.c
1372 lines (1172 loc) · 40.5 KB
/
antenna.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
/*--------------------------------------------------------------*/
/* antenna.c -- Compute the metal area to gate area for all */
/* routes and determine where antenna violations occur. Then, */
/* resolve the violations by routing from each violation to an */
/* antenna tap. */
/* */
/* To be done: If there are no antenna cells placed, or if */
/* the antenna route fails, or if the antenna violation is */
/* close to the limit, see if the route can be adjusted by */
/* moving the route to a higher layer near the gate. */
/*--------------------------------------------------------------*/
/* Written by Tim Edwards, May 2018 */
/*--------------------------------------------------------------*/
#include <ctype.h>
#include <stdio.h>
#include <math.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <regex.h>
#include <assert.h>
/* This entire file is dependent on the Tcl/Tk version */
#ifdef TCL_QROUTER
#include <tk.h>
#include "qrouter.h"
#include "qconfig.h"
#include "mask.h"
#include "maze.h"
#include "node.h"
#include "lef.h"
#include "def.h"
#include "point.h"
/* Node Hash Table routines taken from delay.c */
extern GATE FindGateNode(Tcl_HashTable *, NODE, int *);
extern void FreeNodeTable(Tcl_HashTable *);
extern int TotalRoutes;
/* Structure to hold information about an antenna error. */
typedef struct antennainfo_ *ANTENNAINFO;
struct antennainfo_ {
ANTENNAINFO next; /* Next antenna violation in the list. */
NET net; /* The net violating an antenna rule */
NODE node; /* A gate-end node that is in violation */
ROUTE route; /* A route that is part of the antenna */
int layer; /* Uppermost metal layer of the antenna */
};
/* Keep the list as a global variable so it can be accessed */
/* from doroute() (in qrouter.c) */
ANTENNAINFO AntennaList;
typedef struct annotateinfo_ *ANNOTATEINFO;
struct annotateinfo_ {
ANNOTATEINFO next;
NET net;
char *instance;
char *pin;
int flag; /* Flag for checking output status */
};
ANNOTATEINFO AnnotateList = NULL;
#define ANNO_INIT 0
#define ANNO_OUTPUT 1
/*----------------------------------------------------------------------*/
/* Report connection of a fixed antenna violation, given the net. */
/*----------------------------------------------------------------------*/
char *get_annotate_info(NET net, char **pinptr)
{
ANNOTATEINFO annotate;
for (annotate = AnnotateList; annotate; annotate = annotate->next) {
if (annotate->net->netnum == net->netnum) {
if (annotate->flag == ANNO_INIT) {
annotate->flag = ANNO_OUTPUT; /* Mark as having been output */
*pinptr = annotate->pin;
return annotate->instance;
}
}
}
*pinptr = NULL;
return NULL;
}
/*--------------------------------------------------------------*/
/* Regular expression matching of the given string in */
/* "antennacell" to the string "strtest". If the regular */
/* expression matches and the result is in the first character */
/* position of the string, then return TRUE (match), otherwise */
/* return FALSE (no match). */
/*--------------------------------------------------------------*/
u_char
string_match(char *antennacell, char *strtest)
{
regex_t regex;
regmatch_t pmatch;
int reti;
/* Compile regular expression */
reti = regcomp(®ex, antennacell, 0);
if (reti) {
/* Assume this is not a regular expression and just run */
/* a straight string match. */
if (!strcasecmp(antennacell, strtest))
return TRUE;
else
return FALSE;
}
/* Execute regular expression */
reti = regexec(®ex, strtest, 1, &pmatch, 0);
regfree(®ex);
if (!reti) {
if (pmatch.rm_so == 0) /* Must match beginning of string */
return TRUE;
else
return FALSE;
}
else
return FALSE;
}
/*--------------------------------------------------------------*/
/* Find free antenna cells, and collect all the antenna taps */
/* into a single net, much like VDD_NET or GND_NET. */
/* */
/* Return the number of free antenna taps available in the */
/* layout. */
/* */
/* If the name of the antennacell ends in '*', then assume a */
/* wildcard character and match to any string beginning with */
/* the substring of antennacell. */
/*--------------------------------------------------------------*/
void
find_free_antenna_taps(char *antennacell)
{
int numtaps;
GATE ginst;
GATE gateginfo;
NODE noderec;
int netnum, i;
if (antennacell == NULL) {
Fprintf(stderr, "No antenna cell defined!\n");
return;
}
numtaps = 0;
for (ginst = Nlgates; ginst; ginst = ginst->next) {
gateginfo = ginst->gatetype;
if (string_match(antennacell, gateginfo->gatename)) {
/* Find an unassigned node. If there is not one, */
/* this is probably a routed (not free) cell. */
for (i = 0; i < ginst->nodes; i++) {
netnum = ginst->netnum[i];
noderec = ginst->noderec[i];
if ((netnum == 0) && (noderec == NULL)) {
ginst->netnum[i] = ANTENNA_NET;
ginst->noderec[i] = (NODE)calloc(1, sizeof(struct node_));
ginst->noderec[i]->netnum = ANTENNA_NET;
}
}
}
}
}
/*--------------------------------------------------------------*/
/* Similar to the routine above, but just count the free taps. */
/*--------------------------------------------------------------*/
int
count_free_antenna_taps(char *antennacell)
{
int numtaps;
GATE ginst;
GATE gateginfo;
int netnum, i;
numtaps = 0;
for (ginst = Nlgates; ginst; ginst = ginst->next) {
gateginfo = ginst->gatetype;
if (string_match(antennacell, gateginfo->gatename)) {
/* Find an unassigned node. If there is not one, */
/* this is probably a routed (not free) cell. */
for (i = 0; i < ginst->nodes; i++) {
netnum = ginst->netnum[i];
if (netnum == ANTENNA_NET)
numtaps++;
}
}
}
return numtaps;
}
/*--------------------------------------------------------------*/
/* After routing, the free antenna taps are all marked with the */
/* net number of the net just routed. To make them free again, */
/* change all but the one that was routed back to ANTENNA_NET. */
/* Identify the unused taps by finding the OBSVAL record with */
/* net set to netnum but not connected to the same node. */
/*--------------------------------------------------------------*/
void revert_antenna_taps(int netnum, NODE node)
{
int x, y, lay;
PROUTE *Pr;
NODEINFO lnode = NULL;
/* Clear all targets except for the one just routed */
for (lay = 0; lay < Num_layers; lay++)
for (x = 0; x < NumChannelsX; x++)
for (y = 0; y < NumChannelsY; y++)
if ((OBSVAL(x, y, lay) & NETNUM_MASK) == netnum) {
Pr = &OBS2VAL(x, y, lay);
if (Pr->flags & PR_TARGET) {
lnode = NODEIPTR(x, y, lay);
if ((lnode == NULL) || (lnode->nodesav != node)) {
OBSVAL(x, y, lay) &= ~(NETNUM_MASK | ROUTED_NET);
OBSVAL(x, y, lay) |= ANTENNA_NET;
}
}
}
}
/*--------------------------------------------------------------*/
/* States to track nodes as they are processed: */
/* */
/* NOT_VISITED : Node has not yet been processed. */
/* VISITED : Node was counted on this pass. */
/* PROCESSED : Node was counted on a previous pass. */
/* ANCHOR : Node is a source/drain connection. */
/*--------------------------------------------------------------*/
enum visit_states {NOT_VISITED = 0, VISITED, PROCESSED, ANCHOR};
/* Forward declarations */
float get_route_area_reverse(NET, ROUTE, int, u_char *, u_char,
Tcl_HashTable *, struct routeinfo_ *);
float get_route_area_forward(NET, ROUTE, int, u_char *, u_char,
Tcl_HashTable *, struct routeinfo_ *);
float get_route_area_reverse_fromseg(NET, ROUTE, SEG, int, u_char *, u_char,
Tcl_HashTable *, struct routeinfo_ *);
/*--------------------------------------------------------------*/
/* Determine the amount of metal in the route, starting at the */
/* route start point, and not moving past any point that is */
/* above "layer". Check all other unvisited routes in net to */
/* see if any connect to "rt". If so, check if they connect */
/* to a point that is part of the subnet below or at "layer". */
/* If they do, recursively run get_route_area_forward on that */
/* route. When done, return the total area of the subnet. */
/*--------------------------------------------------------------*/
float
get_route_area_forward_fromseg(NET net, ROUTE rt, SEG nseg, int layer,
u_char *visited, u_char method, Tcl_HashTable *NodeTable,
struct routeinfo_ *iroute)
{
float area, length, width, thick;
int x, y, l, compat;
SEG seg, iseg, chkseg;
ROUTE rt2;
u_char found;
if (rt->flags & RT_VISITED) return 0.0;
rt->flags |= RT_VISITED;
area = 0.0;
/* If nseg is NULL then check from the beginning. */
if (nseg == NULL) nseg = rt->segments;
/* Check if the route beginning is a node */
if (nseg == rt->segments) {
if (rt->flags & RT_START_NODE) {
NODE node;
GATE g;
int i;
node = rt->start.node;
if (visited) {
/* If more than one route is connected to the node, */
/* then this node may have been visited already. */
if (visited[node->nodenum] == NOT_VISITED) {
g = FindGateNode(NodeTable, node, &i);
if (g->area[i] == 0.0) {
/* There's a diffusion diode here! */
visited[node->nodenum] = ANCHOR;
return 0.0;
} else {
/* Add this node to the list of nodes with gates */
/* attached to this antenna area. */
visited[node->nodenum] = VISITED;
}
}
}
else if ((method == ANTENNA_ROUTE) && (iroute != NULL)) {
set_node_to_net(node, PR_SOURCE, &iroute->glist[0], &iroute->bbox, 0);
}
/* Walk all other routes that start or end on this node */
for (rt2 = net->routes; rt2; rt2 = rt2->next) {
if (rt2->flags & RT_VISITED) continue;
if ((rt2->flags & RT_START_NODE) && (rt2->start.node == node)) {
/* The start point of rt2 connects to the same node */
area += get_route_area_forward(net, rt2, layer, visited,
method, NodeTable, NULL);
}
else if ((rt2->flags & RT_END_NODE) && (rt2->end.node == node)) {
/* The end point of rt2 connects to the same node */
for (iseg = rt2->segments; iseg && iseg->next; iseg = iseg->next);
area += get_route_area_reverse(net, rt2, layer, visited,
method, NodeTable, NULL);
}
}
}
}
for (seg = rt->segments; seg && (seg != nseg); seg = seg->next);
if (seg == NULL) return 0.0;
for (; seg; seg = seg->next) {
/* Once the layer goes above the current check layer, the search stops. */
if (method != ANTENNA_DISABLE)
if (seg->layer > layer) break;
/* Vias don't contribute to area, at least for now. */
if (seg->segtype & ST_VIA) continue;
/* For non-cumulative methods, only count area for */
/* those segments which are on the given check layer. */
if ((method == CALC_AREA) || (method == CALC_SIDEAREA))
if (seg->layer != layer)
continue;
/* method ANTENNA_ROUTE indicates that this routine was */
/* called as part of antenna routing. So set up this */
/* part of the route in a manner similar to the */
/* set_route_to_net() routine. */
if ((method == ANTENNA_ROUTE) && (iroute != NULL)) {
PROUTE *Pr;
POINT gpoint;
l = seg->layer;
x = seg->x1;
y = seg->y1;
while (1) {
Pr = &OBS2VAL(x, y, l);
Pr->flags = PR_SOURCE;
Pr->prdata.cost = 0;
if (~(Pr->flags & PR_ON_STACK)) {
Pr->flags |= PR_ON_STACK;
gpoint = allocPOINT();
gpoint->x1 = x;
gpoint->y1 = y;
gpoint->layer = l;
gpoint->next = iroute->glist[0];
iroute->glist[0] = gpoint;
}
if (x < iroute->bbox.x1) iroute->bbox.x1 = x;
if (x > iroute->bbox.x2) iroute->bbox.x2 = x;
if (y < iroute->bbox.y1) iroute->bbox.y1 = y;
if (y > iroute->bbox.y2) iroute->bbox.y2 = y;
// Move to next grid position in the segment
if (x == seg->x2 && y == seg->y2) break;
if (seg->x2 > seg->x1) x++;
else if (seg->x2 < seg->x1) x--;
if (seg->y2 > seg->y1) y++;
else if (seg->y2 < seg->y1) y--;
}
}
else if (method == ANTENNA_DISABLE) {
PROUTE *Pr;
l = seg->layer;
x = seg->x1;
y = seg->y1;
while (1) {
Pr = &OBS2VAL(x, y, l);
Pr->prdata.net = MAXNETNUM;
Pr->flags &= ~(PR_SOURCE | PR_TARGET | PR_COST);
// Move to next grid position in the segment
if (x == seg->x2 && y == seg->y2) break;
if (seg->x2 > seg->x1) x++;
else if (seg->x2 < seg->x1) x--;
if (seg->y2 > seg->y1) y++;
else if (seg->y2 < seg->y1) y--;
}
}
if ((method != ANTENNA_ROUTE) && (method != ANTENNA_DISABLE)) {
/* Note that one of x or y is zero, depending on segment orientation */
x = (seg->x2 - seg->x1);
y = (seg->y2 - seg->y1);
if (x < 0) x = -x;
if (y < 0) y = -y;
/* Note that "l" is a unitless grid dimension */
if (x == 0)
length = (float)y * (float)PitchY;
else
length = (float)x * (float)PitchX;
/* area is either the total top surface of the metal, */
/* or the total side surface of the metal (in um^2) */
width = LefGetRouteWidth(seg->layer);
if ((method == CALC_AREA) || (method == CALC_AGG_AREA))
area += (float)(length * width);
else if ((method == CALC_SIDEAREA) || (method == CALC_AGG_SIDEAREA)) {
thick = LefGetRouteThickness(seg->layer);
area += thick * 2.0 * (length + width);
}
}
}
/* Check other routes for intersection with this route */
for (rt2 = net->routes; rt2; rt2 = rt2->next) {
if (rt2->flags & RT_VISITED) continue;
if (!(rt2->flags & RT_START_NODE) && (rt2->start.route == rt)) {
/* The start point of rt2 connects somewhere on rt */
iseg = rt2->segments;
x = iseg->x1;
y = iseg->y1;
l = iseg->layer;
if (l > layer) continue;
}
else if (!(rt2->flags & RT_END_NODE) && (rt2->end.route == rt)) {
/* The end point of rt2 connects somewhere on rt */
for (iseg = rt2->segments; iseg && iseg->next; iseg = iseg->next);
x = iseg->x2;
y = iseg->y2;
l = iseg->layer;
if (l > layer) continue;
}
else
continue;
/* Must determine if rt2 intersects rt within the antenna area */
found = (u_char)0;
for (chkseg = rt->segments; chkseg && chkseg != seg; chkseg = chkseg->next) {
if (chkseg->segtype & ST_WIRE) {
if (iseg->segtype & ST_WIRE) {
compat = (l == chkseg->layer);
}
else {
compat = (l == chkseg->layer) || (l + 1 == chkseg->layer);
}
}
else {
if (iseg->segtype & ST_WIRE) {
compat = (l == chkseg->layer) || (l == chkseg->layer + 1);
}
else {
compat = (l == chkseg->layer) || (l == chkseg->layer + 1) ||
(l + 1 == chkseg->layer);
}
}
if (!compat) continue;
if (chkseg->segtype & ST_VIA) {
if ((chkseg->x1 == x) && (chkseg->y1 == y)) {
found = (u_char)1;
break;
}
}
else if (chkseg->x1 < chkseg->x2) {
if (chkseg->y1 == y) {
if ((chkseg->x1 <= x) && (chkseg->x2 >= x)) {
found = (u_char)1;
break;
}
}
}
else if (chkseg->x1 > chkseg->x2) {
if (chkseg->y1 == y) {
if ((chkseg->x1 >= x) && (chkseg->x2 <= x)) {
found = (u_char)1;
break;
}
}
}
else if (chkseg->y1 < chkseg->y2) {
if (chkseg->x1 == x) {
if ((chkseg->y1 <= y) && (chkseg->y2 >= y)) {
found = (u_char)1;
break;
}
}
}
else if (chkseg->y1 > chkseg->y2) {
if (chkseg->x1 == x) {
if ((chkseg->y1 >= y) && (chkseg->y2 <= y)) {
found = (u_char)1;
break;
}
}
}
}
if (found == (u_char)1) {
if (rt2->start.route == rt)
area += get_route_area_forward(net, rt2, layer, visited,
method, NodeTable, iroute);
else
area += get_route_area_reverse(net, rt2, layer, visited,
method, NodeTable, iroute);
}
}
/* The end of this route may be a node (so record it in visited) or */
/* a route (so walk it). */
if (seg == NULL) { /* If seg != NULL then we didn't reach the route end */
if (rt->flags & RT_END_NODE) {
NODE node;
GATE g;
int i;
node = rt->end.node;
/* Walk all other routes that start or end on this node */
for (rt2 = net->routes; rt2; rt2 = rt2->next) {
if (rt2->flags & RT_VISITED) continue;
if ((rt2->flags & RT_START_NODE) && (rt2->start.node == node)) {
/* The start point of rt2 connects to the same node */
area += get_route_area_forward(net, rt2, layer, visited,
method, NodeTable, NULL);
}
else if ((rt2->flags & RT_END_NODE) && (rt2->end.node == node)) {
/* The end point of rt2 connects to the same node */
for (iseg = rt2->segments; iseg && iseg->next; iseg = iseg->next);
area += get_route_area_reverse(net, rt2, layer, visited,
method, NodeTable, NULL);
}
}
g = FindGateNode(NodeTable, node, &i);
if (g == NULL) {
/* This should not happen */
Fprintf(stderr, "Error: net %s route end marked as node, but"
" no node found!\n", net->netname);
return 0.0;
}
if (g->area[i] == 0.0) {
/* There's a diffusion diode here! */
if (visited) visited[node->nodenum] = ANCHOR;
return 0.0;
} else {
/* Add this node to the list of nodes with gates */
/* attached to this antenna area. */
if (visited) visited[node->nodenum] = VISITED;
}
if ((method == ANTENNA_ROUTE) && (iroute != NULL)) {
set_node_to_net(node, PR_SOURCE, &iroute->glist[0], &iroute->bbox, 0);
}
}
else {
SEG rseg;
/* Back up seg to point to the last segment of the route */
for (seg = rt->segments; seg && seg->next; seg = seg->next);
x = seg->x2;
y = seg->y2;
l = seg->layer;
/* Find where on rt2 the segment lands, then search rt2 for */
/* antenna area forward and reverse from that segment. */
rt2 = rt->end.route;
assert( rt2 != NULL ) ;
for (rseg = rt2->segments; rseg; rseg = rseg->next) {
if (rseg->segtype & ST_WIRE) {
if (seg->segtype & ST_WIRE) {
compat = (l == rseg->layer);
}
else {
compat = (l == rseg->layer) || (l + 1 == rseg->layer);
}
}
else {
if (seg->segtype & ST_WIRE) {
compat = (l == rseg->layer) || (l == rseg->layer + 1);
}
else {
compat = (l == rseg->layer) || (l == rseg->layer + 1) ||
(l + 1 == rseg->layer);
}
}
if (compat) {
if (rseg->segtype & ST_VIA) {
if ((rseg->x2 == seg->x2) && (rseg->y2 == seg->y2))
break;
}
else if (rseg->x1 < rseg->x2) {
if (rseg->y2 == seg->y2) {
if ((rseg->x1 <= seg->x2) && (rseg->x2 >= seg->x2))
break;
}
}
else if (rseg->x1 > rseg->x2) {
if (rseg->y2 == seg->y2) {
if ((rseg->x1 >= seg->x2) && (rseg->x2 <= seg->x2))
break;
}
}
else if (rseg->y1 < rseg->y2) {
if (rseg->x2 == seg->x2) {
if ((rseg->y1 <= seg->y2) && (rseg->y2 >= seg->y2))
break;
}
}
else if (rseg->y1 > rseg->y2) {
if (rseg->x2 == seg->x2) {
if ((rseg->y1 >= seg->y2) && (rseg->y2 <= seg->y2))
break;
}
}
}
}
assert( rseg != NULL ) ;
if (rseg->next != NULL)
area += get_route_area_forward_fromseg(net, rt2, rseg->next,
layer, visited, method, NodeTable, iroute);
area += get_route_area_reverse_fromseg(net, rt2, rseg, layer,
visited, method, NodeTable, iroute);
}
}
return area;
}
/*--------------------------------------------------------------*/
/* Check route antenna forward from the beginning of the route. */
/*--------------------------------------------------------------*/
float
get_route_area_forward(NET net, ROUTE rt, int layer, u_char *visited,
u_char method, Tcl_HashTable *NodeTable, struct routeinfo_ *iroute)
{
float area;
area = get_route_area_forward_fromseg(net, rt, NULL, layer, visited,
method, NodeTable, iroute);
return area;
}
/*--------------------------------------------------------------*/
/* This is the same as get_route_area_forward_fromseg, but is */
/* searching the path from end to beginning, so reverse the */
/* route first and then call get_route_area_forward_fromseg(). */
/*--------------------------------------------------------------*/
float
get_route_area_reverse_fromseg(NET net, ROUTE rt, SEG nseg, int layer,
u_char *visited, u_char method, Tcl_HashTable *NodeTable,
struct routeinfo_ *iroute)
{
SEG seg, dseg, newseg, firstseg, saveseg;
NODE savestartnode, saveendnode;
float area;
u_char saveflags;
firstseg = NULL;
/* Reverse the route */
for (seg = rt->segments; seg; seg = seg->next) {
newseg = (SEG)malloc(sizeof(struct seg_));
newseg->layer = seg->layer;
newseg->x1 = seg->x2;
newseg->x2 = seg->x1;
newseg->y1 = seg->y2;
newseg->y2 = seg->y1;
newseg->segtype = seg->segtype;
newseg->next = firstseg;
firstseg = newseg;
}
saveseg = rt->segments;
/* Replace the route segment with the reversed route */
rt->segments = firstseg;
/* Reverse the endpoint information */
savestartnode = rt->start.node;
saveendnode = rt->end.node;
rt->start.node = saveendnode;
rt->end.node = savestartnode;
/* Reverse the start/end flags */
saveflags = rt->flags & (RT_START_NODE | RT_END_NODE);
rt->flags &= ~(RT_START_NODE | RT_END_NODE);
if (saveflags & RT_START_NODE) rt->flags |= RT_END_NODE;
if (saveflags & RT_END_NODE) rt->flags |= RT_START_NODE;
area = get_route_area_forward_fromseg(net, rt, nseg, layer, visited,
method, NodeTable, iroute);
/* Replace the route segment with the original route */
rt->segments = saveseg;
/* Revert the endpoint information */
rt->start.node = savestartnode;
rt->end.node = saveendnode;
/* Revert the start/end flags */
rt->flags &= ~(RT_START_NODE | RT_END_NODE);
rt->flags |= saveflags;
/* Free the reversed route */
for (seg = firstseg; seg; ) {
dseg = seg->next;
free(seg);
seg = dseg;
}
return area;
}
/*--------------------------------------------------------------*/
/* Walk a route in reverse from end to start. */
/*--------------------------------------------------------------*/
float
get_route_area_reverse(NET net, ROUTE rt, int layer, u_char *visited,
u_char method, Tcl_HashTable *NodeTable,
struct routeinfo_ *iroute)
{
float area;
area = get_route_area_reverse_fromseg(net, rt, NULL, layer, visited,
method, NodeTable, iroute);
return area;
}
/*--------------------------------------------------------------*/
/* Find all antenna violations at a specific metal layer */
/*--------------------------------------------------------------*/
int find_layer_antenna_violations(int layer, Tcl_HashTable *NodeTable)
{
int numerrors, n, nn, numroutes, i, j, new, neterrors;
u_char *visited, method;
float antenna_ratio, thick;
GATE g;
NET net;
ROUTE rt, saveroute;
NODEINFO nodeptr;
NODE node, tnode;
SEG seg;
ANTENNAINFO newantenna;
float gate_area, metal_area, ratio, save_gate, save_metal, max_ratio;
numerrors = 0;
/* Get the metal layer record for this layer and find the metal */
/* area ratio limit and the method to be used for calculating */
/* metal area. */
method = LefGetRouteAntennaMethod(layer);
if (method == CALC_NONE) return 0; /* No antenna information in tech */
antenna_ratio = (float)LefGetRouteAreaRatio(layer);
thick = (float)LefGetRouteThickness(layer);
if (((method == CALC_SIDEAREA) || (method == CALC_AGG_SIDEAREA)) && (thick == 0.0))
return 0; /* Insufficient antenna information in tech */
/* Make a pass through all nets to find antenna violations */
for (n = 0; n < Numnets; n++) {
net = Nlnets[n];
if ((net->netnum == VDD_NET) || (net->netnum == GND_NET) ||
(net->netnum == ANTENNA_NET)) continue;
/* Ignore nets with no routes */
numroutes = 0;
for (rt = net->routes; rt; rt = rt->next) numroutes++;
if (numroutes == 0) continue;
/* Consider each terminal as a separate sub-net calculation. */
/* But if multiple terminals belong to the same sub-net, they */
/* are marked visited and ignored on subsequent calculations. */
visited = (u_char *)malloc(net->numnodes * sizeof(u_char));
for (node = net->netnodes; node != NULL; node = node->next) {
nn = node->nodenum;
visited[nn] = NOT_VISITED;
}
/* Make a pass through all nodes of the net. Where they are */
/* not connected together at "layer", these are individual */
/* sub-nets. */
neterrors = 0;
max_ratio = 0.0; /* For diagnostics only */
for (node = net->netnodes; node != NULL; node = node->next) {
nn = node->nodenum;
if (visited[nn] >= PROCESSED) continue; /* Already seen */
/* Find the gate area of this node */
g = FindGateNode(NodeTable, node, &i);
metal_area = 0.0;
if (g->area[i] == 0.0) {
visited[nn] = ANCHOR; /* Mark as S/D connection */
continue; /* No gate, so no violation */
}
else
visited[nn] = VISITED;
/* Clear visited flags for routes */
for (rt = net->routes; rt; rt = rt->next)
rt->flags &= ~RT_VISITED;
/* Find the route or routes that connect to this node */
for (rt = net->routes; rt; rt = rt->next) {
if ((rt->flags & RT_START_NODE) && (rt->start.node == node)) {
saveroute = rt;
metal_area += get_route_area_forward(net, rt, layer, visited,
method, NodeTable, NULL);
}
else if ((rt->flags & RT_END_NODE) && (rt->end.node == node)) {
saveroute = rt;
metal_area += get_route_area_reverse(net, rt, layer, visited,
method, NodeTable, NULL);
}
else continue;
}
/* Gate area is combined area of gates visited */
gate_area = 0.0;
for (tnode = net->netnodes; tnode != NULL; tnode = tnode->next) {
j = tnode->nodenum;
if (visited[j] == VISITED) {
g = FindGateNode(NodeTable, tnode, &i);
if (g->area[i] == 0.0) {
visited[j] = ANCHOR;
gate_area = 0.0;
break;
}
else
gate_area += g->area[i];
}
}
if (gate_area > 0.0) {
ratio = metal_area / gate_area;
if (ratio > max_ratio) {
max_ratio = ratio;
save_gate = gate_area;
save_metal = metal_area;
}
if (ratio > antenna_ratio) {
/* Record and report the violation */
numerrors++;
neterrors++;
if (Verbose > 1) {
Fprintf(stderr,
"Antenna violation on node %d of net %s at metal%d\n",
nn, net->netname, layer + 1);
}
if (Verbose > 2) {
Fprintf(stderr, "Metal area = %f, Gate area = %f, Ratio = %f\n",
metal_area, gate_area, ratio);
}
newantenna = (ANTENNAINFO)malloc(sizeof(struct antennainfo_));
newantenna->net = net;
newantenna->node = node;
newantenna->layer = layer;
newantenna->route = saveroute;
newantenna->next = AntennaList;
AntennaList = newantenna;
}
}
/* Mark gates as visited on previous pass */
for (tnode = net->netnodes; tnode != NULL; tnode = tnode->next) {
j = tnode->nodenum;
if (visited[j] == VISITED) visited[j] = PROCESSED;
}
}
free(visited);
if (Verbose > 3) {
/* Diagnostic */
if (neterrors == 0) {
if (max_ratio > 0.0)
Fprintf(stderr, "Worst case: Metal area = %f, Gate area = %f, "
"Ratio = %f\n", save_metal, save_gate, max_ratio);
}
}
/* Clear route visited flags */
for (rt = net->routes; rt; rt = rt->next)
rt->flags &= ~RT_VISITED;
}
return numerrors;
}
/*--------------------------------------------------------------*/
/* This routine is a combination of set_node_to_net(), */
/* set_routes_to_net(), and disable_node_nets() (see qrouter.c */
/* and maze.c), but walks the routes in the same manner used */
/* for finding the antenna violations. Set the antenna part of */
/* the net as SOURCE, the free antenna taps as TARGET, and the */
/* non-antenna portion of the net to an unused net number, */
/* which can be converted back after routing. */
/*--------------------------------------------------------------*/
int set_antenna_to_net(int newflags, struct routeinfo_ *iroute,
u_char stage, ANTENNAINFO violation, Tcl_HashTable *NodeTable)
{
int x, y, lay, rval, layer;
PROUTE *Pr;
ROUTE rt, clrrt;
NODE node;
NET net;
/* Set the node and connected antenna metal routes to PR_SOURCE. */
rt = violation->route;
node = violation->node;
net = violation->net;
layer = violation->layer;
if ((rt->flags & RT_START_NODE) && (rt->start.node == node))
get_route_area_forward(net, rt, layer, NULL, ANTENNA_ROUTE, NodeTable,
iroute);
else if ((rt->flags & RT_END_NODE) && (rt->end.node == node))
get_route_area_reverse(net, rt, layer, NULL, ANTENNA_ROUTE, NodeTable,
iroute);
else {
/* This should not happen */
Fprintf(stderr, "Error: Antenna route and node do not connect!\n");
return 1;
}
/* Clear route visited flags for next pass */
for (clrrt = iroute->net->routes; clrrt; clrrt = clrrt->next)
clrrt->flags &= ~RT_VISITED;
/* Disable the remainder of the route */
if ((rt->flags & RT_START_NODE) && (rt->start.node == node))
get_route_area_forward(net, rt, layer, NULL, ANTENNA_DISABLE, NodeTable,
iroute);
else if ((rt->flags & RT_END_NODE) && (rt->end.node == node))
get_route_area_reverse(net, rt, layer, NULL, ANTENNA_DISABLE, NodeTable,
iroute);
else {
/* This should not happen */
Fprintf(stderr, "Error: Antenna route and node do not connect!\n");
return 1;
}
/* Done checking routes; clear route visited flags */
for (clrrt = iroute->net->routes; clrrt; clrrt = clrrt->next)
clrrt->flags &= ~RT_VISITED;
/* Set the antenna taps to the net number. */
/* Routine is similar to set_powerbus_to_net(). */