forked from RTimothyEdwards/magic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrouteTest.c
599 lines (545 loc) · 14.4 KB
/
grouteTest.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
/*
* grouteTest.c --
*
* Testing code for the global router.
*
* *********************************************************************
* * Copyright (C) 1985, 1990 Regents of the University of California. *
* * Permission to use, copy, modify, and distribute this *
* * software and its documentation for any purpose and without *
* * fee is hereby granted, provided that the above copyright *
* * notice appear in all copies. The University of California *
* * makes no representations about the suitability of this *
* * software for any purpose. It is provided "as is" without *
* * express or implied warranty. Export of this software outside *
* * of the United States of America may require an export license. *
* *********************************************************************
*/
#ifndef lint
static char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magic-8.0/grouter/grouteTest.c,v 1.1.1.1 2008/02/03 20:43:50 tim Exp $";
#endif /* not lint */
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "utils/magic.h"
#include "utils/geometry.h"
#include "utils/hash.h"
#include "utils/heap.h"
#include "tiles/tile.h"
#include "database/database.h"
#include "utils/signals.h"
#include "textio/textio.h"
#include "debug/debug.h"
#include "gcr/gcr.h"
#include "router/router.h"
#include "grouter/grouter.h"
#include "graphics/graphics.h"
#include "windows/windows.h"
#include "dbwind/dbwind.h"
#include "textio/txcommands.h"
#include "utils/main.h"
#include "utils/utils.h"
#include "commands/commands.h"
#include "utils/malloc.h"
#include "utils/styles.h"
#include "utils/netlist.h"
bool glInitialized = FALSE;
ClientData glDebugID = 0;
int glDebAllPoints = 0;
int glDebChan = 0;
int glDebCross = 0;
int glDebFast = 0;
int glDebHeap = 0;
int glDebHisto = 0;
int glDebLog = 0;
int glDebGreedy = 0;
int glDebMaze = 0;
int glDebNet = 0;
int glDebNewHeaps = 0;
int glDebPen = 0;
int glDebShowPins = 0;
int glDebStemsOnly = 0;
int glDebStraight = 0;
int glDebTiles = 0;
int glDebVerbose = 0;
/* Statistics */
int glCrossingsSeen; /* Total crossings seen */
int glCrossingsAdded; /* Total crossings added to heap */
int glCrossingsExpanded; /* Total crossings expanded from */
int glCrossingsUsed; /* Total crossings used */
int glGoodRoutes; /* Good point to point routes */
int glBadRoutes; /* Bad point to point routes */
int glNoRoutes;
/* Used in debugging; if set, we only route a single net */
char *glOnlyNet = NULL;
/*
* Used to remember the number of frontier points visited, and the
* number of points removed from the top of the heap, for each two
* point net routed.
*/
GlNetHisto *glNetHistoList = NULL;
/* Forward declarations */
void GlInit();
void glShowCross();
/*
* ----------------------------------------------------------------------------
*
* GlTest --
*
* Command interface for testing the global router.
*
* Results:
* None.
*
* Side effects:
* Depends on the command; see below.
*
* ----------------------------------------------------------------------------
*/
void
GlTest(w, cmd)
MagWindow *w;
TxCommand *cmd;
{
int glDebugSides();
typedef enum { CLRDEBUG, ONLYNET, SETDEBUG, SHOWDEBUG, SIDES } cmdType;
Rect editArea;
int n;
static struct
{
char *cmd_name;
cmdType cmd_val;
} cmds[] = {
{"clrdebug", CLRDEBUG},
{"onlynet", ONLYNET},
{"setdebug", SETDEBUG},
{"showdebug", SHOWDEBUG},
{"sides", SIDES},
{0}
};
if (!glInitialized)
GlInit();
if (cmd->tx_argc == 1)
{
TxError("Must give subcommand\n");
goto badCmd;
}
n = LookupStruct(cmd->tx_argv[1], (LookupTable *) cmds, sizeof cmds[0]);
if (n < 0)
{
TxError("Unrecognized subcommand: %s\n", cmd->tx_argv[1]);
badCmd:
TxError("Valid subcommands:");
for (n = 0; cmds[n].cmd_name; n++)
TxError(" %s", cmds[n].cmd_name);
TxError("\n");
return;
}
switch (cmds[n].cmd_val)
{
case SETDEBUG:
DebugSet(glDebugID, cmd->tx_argc - 2, &cmd->tx_argv[2], TRUE);
break;
case CLRDEBUG:
DebugSet(glDebugID, cmd->tx_argc - 2, &cmd->tx_argv[2], FALSE);
break;
case SHOWDEBUG:
DebugShow(glDebugID);
break;
case SIDES:
if (!ToolGetEditBox(&editArea)) return;
n = -1;
if (cmd->tx_argc > 2)
{
if (!StrIsInt(cmd->tx_argv[2]))
{
TxError("Minimum channel width must be numeric\n");
break;
}
n = atoi(cmd->tx_argv[2]);
}
(void) rtrEnumSides(EditCellUse, &editArea, n,
glDebugSides, (ClientData) NULL);
case ONLYNET:
if (cmd->tx_argc == 2)
{
if (glOnlyNet)
TxPrintf("Routing only net: %s\n", glOnlyNet);
else
TxPrintf("Routing all nets.\n");
}
else if (cmd->tx_argc == 3)
{
if (strcmp(cmd->tx_argv[2], "-") == 0)
{
if (glOnlyNet)
{
freeMagic(glOnlyNet);
glOnlyNet = NULL;
}
TxPrintf("Routing all nets.\n");
}
else
{
(void) StrDup(&glOnlyNet, cmd->tx_argv[2]);
TxPrintf("Routing only net: %s\n", glOnlyNet);
}
}
else TxError("Usage: *groute onlynet [net | -]\n");
break;
}
}
int
glDebugSides(side)
Side *side;
{
char mesg[256];
CellDef *def = EditCellUse->cu_def;
Rect r;
GeoTransRect(&side->side_trans, &side->side_search, &r);
ShowRect(def, &r, STYLE_SOLIDHIGHLIGHTS);
(void) sprintf(mesg, "SEARCH %d %d %d %d\n",
r.r_xbot, r.r_ybot, r.r_xtop, r.r_ytop);
TxMore(mesg);
ShowRect(def, &r, STYLE_ERASEHIGHLIGHTS);
GeoTransRect(&side->side_trans, &side->side_used, &r);
ShowRect(def, &r, STYLE_MEDIUMHIGHLIGHTS);
(void) sprintf(mesg, "USED %d %d %d %d\n",
r.r_xbot, r.r_ybot, r.r_xtop, r.r_ytop);
TxMore(mesg);
ShowRect(def, &r, STYLE_ERASEHIGHLIGHTS);
(void) TxPrintf("--------\n");
return 0;
}
/*
* ----------------------------------------------------------------------------
*
* GlInit --
*
* One-time-only initialization for the global router.
* Called after technology initialization.
*
* Results:
* None.
*
* Side effects:
* Register ourself with the debug module and list all
* debugging flags.
*
* ----------------------------------------------------------------------------
*/
void
GlInit()
{
int n;
static struct
{
char *di_name;
int *di_id;
} dflags[] = {
{"allpoints", &glDebAllPoints},
{"chan", &glDebChan},
{"cross", &glDebCross},
{"fast", &glDebFast},
{"heap", &glDebHeap},
{"histo", &glDebHisto},
{"log", &glDebLog},
{"greedy", &glDebGreedy},
{"maze", &glDebMaze},
{"net", &glDebNet},
{"newheaps", &glDebNewHeaps},
{"penalties", &glDebPen},
{"showpins", &glDebShowPins},
{"stemsonly", &glDebStemsOnly},
{"straight", &glDebStraight},
{"tiles", &glDebTiles},
{"verbose", &glDebVerbose},
{0}
};
if (glInitialized)
return;
glInitialized = TRUE;
/* Register ourselves with the debugging module */
glDebugID = DebugAddClient("grouter", sizeof dflags/sizeof dflags[0]);
for (n = 0; dflags[n].di_name; n++)
*(dflags[n].di_id) = DebugAddFlag(glDebugID, dflags[n].di_name);
}
/*
* ----------------------------------------------------------------------------
*
* glShowPath --
*
* Display the crossing points along an entire path for debugging.
* The type of crossing point is indicated by 'kind'.
*
* Results:
* None.
*
* Side effects:
* Causes redisplay.
*
* ----------------------------------------------------------------------------
*/
void
glShowPath(dest, root, kind)
GlPoint *dest, *root;
int kind;
{
static NetId dummyId = { 0, 0 };
GlPoint *temp;
for (temp = dest; temp != root; temp = temp->gl_path)
glShowCross(temp->gl_pin, dummyId, kind);
}
/*
* ----------------------------------------------------------------------------
*
* glShowCross --
*
* Display a crossing point for debugging.
* Two kinds of crossing points can be shown: CROSS_TEMP, which
* is only being considered, and CROSS_PERM, which has been permanently
* assigned to a net. In addition, CROSS_ERASE will cause the crossing
* point to be erased.
*
* Results:
* None.
*
* Side effects:
* Causes redisplay.
*
* ----------------------------------------------------------------------------
*/
void
glShowCross(pin, netId, kind)
GCRPin *pin; /* Pin itself */
NetId netId; /* Identifies net and segment for this pin */
int kind; /* Determines kind of display; see above */
{
char *name, name1[1024], name2[1024];
int style;
Rect r;
switch (kind)
{
case CROSS_TEMP:
name = "temp";
style = STYLE_MEDIUMHIGHLIGHTS;
break;
case CROSS_PERM:
name = "PERM";
style = STYLE_SOLIDHIGHLIGHTS;
break;
case CROSS_ERASE:
name = (char *) NULL;
style = STYLE_ERASEHIGHLIGHTS;
break;
}
if (name && DebugIsSet(glDebugID, glDebMaze))
{
(void) strcpy(name1, NLNetName(pin->gcr_pId));
(void) strcpy(name2, NLNetName(netId.netid_net));
TxPrintf("%s (%d,%d), Net %s/%d->%s/%d, Ch %ld\n",
name, pin->gcr_point.p_x, pin->gcr_point.p_y,
name1, pin->gcr_pSeg, name2, netId.netid_seg, (intmax_t) pin->gcr_ch);
}
r.r_ll = r.r_ur = pin->gcr_point;
r.r_xtop += RtrMetalWidth;
r.r_ytop += RtrMetalWidth;
ShowRect(EditCellUse->cu_def, &r, style);
}
/*
* ----------------------------------------------------------------------------
*
* glHistoAdd --
*
* Remember the number of heap, frontier, and starting points
* used during a given route by adding them to the GlNetHisto
* list.
*
* Results:
* None.
*
* Side effects:
* Allocates memory; prepends a new entry to glNetHistoList.
*
* ----------------------------------------------------------------------------
*/
void
glHistoAdd(heapPtsBefore, frontierPtsBefore, startPtsBefore)
int heapPtsBefore, frontierPtsBefore, startPtsBefore;
{
GlNetHisto *gh;
gh = (GlNetHisto *) mallocMagic((unsigned) (sizeof (GlNetHisto)));
gh->glh_heap = glCrossingsExpanded - heapPtsBefore;
gh->glh_frontier = glCrossingsAdded - frontierPtsBefore;
gh->glh_start = startPtsBefore;
gh->glh_next = glNetHistoList;
glNetHistoList = gh;
}
/*
* ----------------------------------------------------------------------------
*
* glHistoDump --
*
* Dump the information accumulated by glHistoAdd() above
* to the file HISTO.out in the current directory.
*
* Results:
* None.
*
* Side effects:
* Creates HISTO.out.
*
* ----------------------------------------------------------------------------
*/
void
glHistoDump()
{
static char hname[] = "HISTO.out";
int lastsize, count, total;
GlNetHisto *gh;
Heap histoHeap;
HeapEntry entry;
FILE *fp;
fp = fopen(hname, "w");
if (fp == NULL)
{
perror(hname);
return;
}
/* Raw data */
fprintf(fp, "--------- raw data ---------\n");
fprintf(fp, "%9s %9s %9s\n", "HEAP", "FRONTIER", "START");
for (gh = glNetHistoList; gh; gh = gh->glh_next)
{
fprintf(fp, "%9d %9d %9d\n",
gh->glh_heap, gh->glh_frontier, gh->glh_start);
}
/* Output sorted by number of heap points */
fprintf(fp, "--------- by heap points ---------\n");
HeapInit(&histoHeap, 128, FALSE, FALSE);
for (gh = glNetHistoList; gh; gh = gh->glh_next)
HeapAddInt(&histoHeap, gh->glh_heap, (char *) gh);
count = lastsize = total = 0;
while (HeapRemoveTop(&histoHeap, &entry))
{
gh = (GlNetHisto *) entry.he_id;
if (gh->glh_heap != lastsize)
{
if (count > 0)
fprintf(fp, "%d: %d\n", lastsize, count);
lastsize = gh->glh_heap;
count = 0;
}
count++, total++;
}
HeapKill(&histoHeap, (void (*)()) NULL);
if (count > 0)
fprintf(fp, "%d: %d\n", lastsize, count);
fprintf(fp, "TOTAL: %d\n", total);
/* Output sorted by number of frontier points */
fprintf(fp, "--------- by frontier points ---------\n");
HeapInit(&histoHeap, 128, FALSE, FALSE);
for (gh = glNetHistoList; gh; gh = gh->glh_next)
HeapAddInt(&histoHeap, gh->glh_frontier, (char *) gh);
count = lastsize = total = 0;
while (HeapRemoveTop(&histoHeap, &entry))
{
gh = (GlNetHisto *) entry.he_id;
if (gh->glh_frontier != lastsize)
{
if (count > 0)
fprintf(fp, "%d: %d\n", lastsize, count);
lastsize = gh->glh_frontier;
count = 0;
}
count++, total++;
}
HeapKill(&histoHeap, (void (*)()) NULL);
if (count > 0)
fprintf(fp, "%d: %d\n", lastsize, count);
fprintf(fp, "TOTAL: %d\n", total);
/* Free memory */
for (gh = glNetHistoList; gh; gh = gh->glh_next)
freeMagic((char *) gh);
glNetHistoList = NULL;
/* Done */
(void) fclose(fp);
}
/*
* ----------------------------------------------------------------------------
*
* glStatsInit --
*
* Initialize statistics and debugging info for this
* global routing session.
*
* Results:
* None.
*
* Side effects:
* Zeroes lots of global counters.
* Zeroes glNetHistoList.
* May create the crossings log file ("CROSSINGS.log") and
* leave glLogFile pointing to the open file.
*
* ----------------------------------------------------------------------------
*/
void
glStatsInit()
{
char *logFileName = "CROSSINGS.log";
glCrossingsSeen = 0;
glCrossingsAdded = 0;
glCrossingsExpanded = 0;
glCrossingsUsed = 0;
glGoodRoutes = 0;
glBadRoutes = 0;
glNoRoutes = 0;
glNumTries = 0;
glNetHistoList = NULL;
if (DebugIsSet(glDebugID, glDebLog))
{
glLogFile = fopen(logFileName, "w");
if (glLogFile == (FILE *) NULL)
perror(logFileName);
}
}
/*
* ----------------------------------------------------------------------------
*
* glStatsDone --
*
* Print statistics accumulated during this routing session.
*
* Results:
* None.
*
* Side effects:
* Prints statistics.
*
* ----------------------------------------------------------------------------
*/
void
glStatsDone(numNets, numTerms)
int numNets;
int numTerms;
{
if (DebugIsSet(glDebugID, glDebVerbose))
{
TxPrintf("\n");
TxPrintf(" %d nets, %d terminals.\n", numNets, numTerms);
TxPrintf(" %d good, %d bad two-point routes,\n",
glGoodRoutes, glBadRoutes);
TxPrintf(" %d failed when considering penalties,\n", glNoRoutes);
TxPrintf(" %d total connections.\n", glGoodRoutes + glBadRoutes);
TxPrintf(" %d crossings seen, %d added to heap.\n",
glCrossingsSeen, glCrossingsAdded);
TxPrintf(" %d crossings %d used.\n",
glCrossingsExpanded, glCrossingsUsed);
}
if (DebugIsSet(glDebugID, glDebLog) && glLogFile)
(void) fclose(glLogFile);
if (DebugIsSet(glDebugID, glDebHisto))
glHistoDump();
}