-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathgcrInit.c
398 lines (353 loc) · 9.49 KB
/
gcrInit.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
/* gcrInit.c -
*
* Initialization for the greedy 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/gcr/gcrInit.c,v 1.1.1.1 2008/02/03 20:43:50 tim Exp $";
#endif /* not lint */
#include <stdio.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 "router/router.h"
#include "gcr/gcr.h"
#include "utils/malloc.h"
int GCRSteadyNet =1; /*Values get imported from main*/
int GCREndDist =1;
int GCRMinJog =1;
int GCRsplitAt =0;
bool GcrShowResult =FALSE;
bool GcrNoCheck =TRUE;
bool GcrDebug =FALSE;
#ifndef lint
float GCRObstDist = 0.7;
#else
float GCRObstDist; /* Sun lint brain death */
#endif /* lint */
/* Forward declarations */
void gcrLinkPin();
/*
* ----------------------------------------------------------------------------
*
* gcrSetEndDist --
*
* Set the global variable specifying how soon the router starts to get
* nets into tracks for end connections.
*
* Get the number of end connections as a percentage of the width of
* the channel. Add extra for multipin end connections.
*
* Results:
* None.
*
* Side effects:
* Changes GCREndDist.
*
* ----------------------------------------------------------------------------
*/
void
gcrSetEndDist(ch)
GCRChannel *ch; /* The channel to be routed */
{
int rightTotal, multiTotal;
GCRNet *net;
GCRPin *pin;
int count;
/*
* Do this the easy way.
* Enumerate each net and look at its pins, starting
* from the rightmost.
*/
rightTotal = 0;
multiTotal = 0;
for (net = ch->gcr_nets; net; net = net->gcr_next)
{
count = 0;
for (pin = net->gcr_rPin; pin; pin = pin->gcr_pPrev, count++)
if (pin->gcr_x <= ch->gcr_length)
break;
rightTotal += count;
if (count > 1)
multiTotal++;
}
GCREndDist = (multiTotal/2 + rightTotal/4) * RtrEndConst;
if (GCREndDist < 1) GCREndDist = 1;
}
/*
* ----------------------------------------------------------------------------
*
* gcrBuildNets --
*
* Scan the top, bot, left, and right pin arrays, setting pointers to
* the left and right pins for each net. Sets pointers within the
* pin arrays to point to next and previous pins.
*
* Results:
* None.
*
* Side effects:
* Allocates and initializes storage for nets.
*
* ----------------------------------------------------------------------------
*/
void
gcrBuildNets(ch)
GCRChannel * ch;
{
HashTable ht;
int i;
/*
* Initialize the hash table that maps net ids to GCRNet structs.
* The table is keyed by 2 words: seg/net.
*/
HashInit(&ht, 256, 2);
for (i = 1; i <= ch->gcr_width; i++)
gcrLinkPin(&ch->gcr_lPins[i], &ht, ch);
for (i = 1; i <= ch->gcr_length; i++)
{
gcrLinkPin(&ch->gcr_bPins[i], &ht, ch);
gcrLinkPin(&ch->gcr_tPins[i], &ht, ch);
}
for (i = 1; i <= ch->gcr_width; i++)
gcrLinkPin(&ch->gcr_rPins[i], &ht, ch);
HashKill(&ht);
}
/*
* ----------------------------------------------------------------------------
*
* gcrLinkPin --
*
* Establish the forward and backward links for a pin on the edge of
* a channel.
*
* Results:
* None.
*
* Side effects:
* The pin is added to the end of the list for its net. A
* new net structure is created if one doesn't already
* exist.
*
* ----------------------------------------------------------------------------
*/
void
gcrLinkPin(pin, ht, ch)
GCRPin *pin;
HashTable *ht;
GCRChannel *ch;
{
GCRNet *net;
GCRNet *gcrNewNet();
HashEntry *hEntry;
/*
* GCR_BLOCKEDNETID means that the crossing was blocked.
* Restore these crossings to "empty".
*/
if (pin->gcr_pId == GCR_BLOCKEDNETID) pin->gcr_pId = (GCRNet *) NULL;
/* Skip empty pins */
if (pin->gcr_pId == (GCRNet *) NULL)
return;
/* Find the 2-word seg/net key */
hEntry = HashFind(ht, (char *) &(pin->gcr_pSeg));
net = (GCRNet *) HashGetValue(hEntry);
if (net == (GCRNet *) NULL)
{
/* New net */
net = (GCRNet *) mallocMagic((unsigned) (sizeof (GCRNet)));
HashSetValue(hEntry, (char *) net);
net->gcr_Id = (spointertype) pin->gcr_pId;
/* Link net onto channel net list */
net->gcr_next = ch->gcr_nets;
ch->gcr_nets = net;
/* Link pin onto net pin list */
net->gcr_lPin = net->gcr_rPin= pin;
pin->gcr_pPrev = (GCRPin *) NULL;
}
else
{
/* Old net. Add to end of net's list. */
net->gcr_rPin->gcr_pNext = pin;
pin->gcr_pPrev = net->gcr_rPin;
net->gcr_rPin = pin;
}
pin->gcr_pId = net;
pin->gcr_pNext = (GCRPin *) NULL;
}
/*
* ----------------------------------------------------------------------------
*
* gcrUnlinkPin --
*
* Remove a pin from the pin list for a net. The pin had better
* be the first pin of its net.
*
* Results:
* None.
*
* Side effects:
* The pin is removed from the list associated with its net.
*
* ----------------------------------------------------------------------------
*/
void
gcrUnlinkPin(pin)
GCRPin *pin;
{
GCRNet *net;
if ((net = pin->gcr_pId))
{
ASSERT(pin == net->gcr_lPin, "gcrUnlinkPin");
net->gcr_lPin = pin->gcr_pNext;
if (pin->gcr_pNext)
pin->gcr_pNext->gcr_pPrev = pin->gcr_pPrev;
}
}
/*
* ----------------------------------------------------------------------------
*
* gcrDensity --
*
* Determine the channel density at every column. Starting at the left
* end of the channel with density=0, the density of the next column is
* the current density plus the number of nets with first pin in the
* current column minus the number of nets with last pin in the previous
* column.
*
* Must be called AFTER gcrBuildNets.
*
* Results:
* Returns the maximum column density.
*
* Side effects:
* Allocates storage for the density array GCRDensity and stores densities.
*
* ----------------------------------------------------------------------------
*/
int
gcrDensity(ch)
GCRChannel *ch;
{
int density, i, last, maxVal;
unsigned lenWds;
last = 0;
density = 0;
for (i = 1; i <= ch->gcr_width; i++)
if (ch->gcr_lPins[i].gcr_pId)
{
if (Is1stPin(&ch->gcr_lPins[i])) density++;
if (IsLstPin(&ch->gcr_lPins[i])) last++;
}
lenWds = ch->gcr_length + 2;
if (ch->gcr_density == (int *) NULL)
{
ch->gcr_density = (int *) mallocMagic((unsigned) (lenWds * sizeof (int)));
}
ch->gcr_density[0] = maxVal = density;
for (i = 1; i <= ch->gcr_length; i++)
{
density = density - last;
last = 0;
if (ch->gcr_tPins[i].gcr_pId)
{
if (Is1stPin(&ch->gcr_tPins[i])) density++;
else if (IsLstPin(&ch->gcr_tPins[i])) last++;
}
if (ch->gcr_bPins[i].gcr_pId)
{
if (Is1stPin(&ch->gcr_bPins[i])) density++;
else if (IsLstPin(&ch->gcr_bPins[i]))
{
if (ch->gcr_tPins[i].gcr_pId == ch->gcr_bPins[i].gcr_pId)
density--;
else last++;
}
}
ch->gcr_density[i] = density;
if (density > maxVal)
maxVal = density;
}
return (maxVal);
}
/*
* ----------------------------------------------------------------------------
*
* gcrInitCol --
*
* Initialize the column structure to hold the configuration at
* the left side of the channel.
*
* Results:
* None.
*
* Side effects:
* Pointers are updated in the column data structure.
* Changes the track field of each net struct.
*
* ----------------------------------------------------------------------------
*/
void
gcrInitCol(ch, edgeArray)
GCRChannel *ch;
GCRPin *edgeArray; /* Nets at left edge of channel if non-NULL */
{
GCRNet *net;
GCRColEl *col;
int i, widWds;
col = ch->gcr_lCol;
/* Assign column tracks using an optionally provided pin array */
if (edgeArray)
{
col[0].gcr_h = (GCRNet *) NULL;
for (i = 1; i <= ch->gcr_width; i++)
{
col[i].gcr_h = edgeArray[i].gcr_pId;
/* Delete pin from net's pin list */
gcrUnlinkPin(&edgeArray[i]);
}
col[ch->gcr_width+1].gcr_h = (GCRNet *) NULL;
}
/* Initialize the hi and lo pointers for the column data structure */
for (net = ch->gcr_nets; net; net = net->gcr_next)
net->gcr_track = EMPTY;
widWds = ch->gcr_width + 1;
for (i = 0; i <= widWds; i++)
{
col[i].gcr_v = (GCRNet *) NULL;
col[i].gcr_hi = EMPTY;
col[i].gcr_lo = EMPTY;
col[i].gcr_hOk =FALSE;
col[i].gcr_lOk =FALSE;
col[i].gcr_wanted = (GCRNet *) NULL;
col[i].gcr_flags = 0;
net = col[i].gcr_h;
if (net)
{
if (net->gcr_track == EMPTY) /* 1st track */
col[i].gcr_h->gcr_track = i;
else
{
col[i].gcr_lo = net->gcr_track;
col[net->gcr_track].gcr_hi = i;
net->gcr_track = i;
}
}
}
/* Mark tracks needed to make some end connection */
for (i = 1; i <= ch->gcr_width; i++)
gcrWanted(ch, i, 0);
}