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
|
/*--------------------------------------------------------------*/
/* qconfig.c -- .cfg file read/write for route */
/*--------------------------------------------------------------*/
/* Written by Steve Beccue 2003 */
/*--------------------------------------------------------------*/
/* Modified by Tim Edwards, June 2011. The route.cfg file is */
/* no longer the main configuration file but is supplementary */
/* to the LEF and DEF files. Various configuration items that */
/* do not appear in the LEF and DEF formats, such as route */
/* costing, appear in this file, as well as a filename pointer */
/* to the LEF file with information on standard cell macros. */
/*--------------------------------------------------------------*/
#define _GNU_SOURCE // for strcasestr(), see man page
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "qrouter.h"
#include "qconfig.h"
#include "lef.h"
int CurrentPin = 0;
int Firstcall = TRUE;
int PinNumber = 0;
int Num_layers = MAX_LAYERS; // layers to use to route
double PathWidth[MAX_LAYERS]; // width of the paths
int GDSLayer[MAX_LAYERS]; // GDS layer number
int GDSCommentLayer = 1; // for dummy wires, etc.
char CIFLayer[MAX_LAYERS][50]; // CIF layer name
double PitchX[MAX_LAYERS]; // Horizontal wire pitch of layer
double PitchY[MAX_LAYERS]; // Vertical wire pitch of layer
int NumChannelsX[MAX_LAYERS]; // number of wire channels in X on layer
int NumChannelsY[MAX_LAYERS]; // number of wire channels in Y on layer
int Vert[MAX_LAYERS]; // 1 if vertical, 0 if horizontal
int Numpasses = 10; // number of times to iterate in route_segs
char StackedContacts = MAX_LAYERS; // Value is number of contacts that may
// be stacked on top of each other.
char ViaPattern = VIA_PATTERN_NONE; // Patterning to be used for vias based
// on grid position (i.e., checkerboarding)
double Xlowerbound=0.0; // Bounding Box of routes, in microns
double Xupperbound=0.0;
double Ylowerbound=10.0;
double Yupperbound=10.0;
int SegCost = 1; // Route cost of a segment
int ViaCost = 5; // Cost of via between adjacent layers
int JogCost = 10; // Cost of 1 grid off-direction jog
int XverCost = 4; // Cost of a crossover
int BlockCost = 25; // Cost of a crossover when node has
// only one tap point
int ConflictCost = 50; // Cost of shorting another route
// during the rip-up and reroute stage
char *ViaX[MAX_LAYERS];
char *ViaY[MAX_LAYERS];
/*--------------------------------------------------------------*/
/* post_config --- */
/* */
/* The following code ensures that the layer grids align. */
/* For now, all PitchX[i] and PitchY[i] should be the same */
/* for all layers. Hopefully this restriction can be lifted */
/* sometime, but it will necessarily be a royal pain. */
/*--------------------------------------------------------------*/
void
post_config()
{
int i, h, v;
// Make sure that Num_layers does not exceed the number of
// routing layers defined by the LEF file (or the config
// file).
i = LefGetMaxLayer();
if (i < Num_layers) Num_layers = i;
h = v = -1;
for (i = 0; i < Num_layers; i++) {
if (!Vert[i]) {
h = i;
PitchY[i] = PitchX[i];
PitchX[i] = 0.0;
}
else
v = i;
}
// In case all layers are listed as horizontal or all
// as vertical, we should still handle it gracefully
if (h == -1) h = v;
else if (v == -1) v = h;
for (i = 0; i < Num_layers; i++) {
if (PitchX[i] != 0.0 && PitchX[i] != PitchX[v])
Fprintf(stderr, "Multiple vertical route layers at different"
" pitches. I cannot handle this! Using pitch %g\n",
PitchX[v]);
PitchX[i] = PitchX[v];
if (PitchY[i] != 0.0 && PitchY[i] != PitchY[h])
Fprintf(stderr, "Multiple horizontal route layers at different"
" pitches. I cannot handle this! Using pitch %g\n",
PitchY[h]);
PitchY[i] = PitchY[h];
}
} /* post_config() */
/*--------------------------------------------------------------*/
/* read_config - read in the config file */
/* */
/* ARGS: the filename (normally route.cfg) */
/* RETURNS: number of lines successfully read */
/* SIDE EFFECTS: loads Global configuration variables */
/*--------------------------------------------------------------*/
int read_config(FILE *fconfig)
{
int count, lines, i, OK;
int iarg, iarg2;
char carg;
double darg, darg2, darg3, darg4;
char sarg[MAX_LINE_LEN];
size_t len = 0;
char line[MAX_LINE_LEN];
char *lineptr;
STRING dnr; // Do Not Route nets
STRING cn; // critical nets
STRING strl;
GATE gateinfo; // gate information, pin location, etc
DSEG grect, drect;
if (Firstcall) {
for (i = 0; i < MAX_LAYERS; i++) {
sprintf(line, "via%d%d", i + 1, i + 2);
ViaX[i] = strdup(line);
ViaY[i] = NULL;
}
DontRoute = (STRING)NULL;
CriticalNet = (STRING)NULL;
GateInfo = (GATE)NULL;
Nlgates = (GATE)NULL;
UserObs = (DSEG)NULL;
for (i = 0; i < MAX_LAYERS; i++)
PitchX[i] = PitchY[i] = 0.0;
Firstcall = 0;
}
if (!fconfig) return -1;
count = 0;
lines = 0;
while (!feof(fconfig)) {
fgets(line, MAX_LINE_LEN, fconfig);
lines++;
lineptr = line;
while (isspace(*lineptr)) lineptr++;
if (!strncasecmp(lineptr, "lef", 3) || !strncmp(lineptr, "read_lef", 8)) {
if ((i = sscanf(lineptr, "%*s %s\n", sarg)) == 1) {
// Argument is a filename of a LEF file from which we
// should get the information about gate pins & obstructions
OK = 1;
LefRead(sarg);
}
}
// The remainder of the statements is not case sensitive.
for (i = 0; line[i] && i < MAX_LINE_LEN - 1; i++) {
line[i] = (char)tolower(line[i]);
}
if ((i = sscanf(lineptr, "num_layers %d", &iarg)) == 1) {
OK = 1; Num_layers = iarg;
}
else if ((i = sscanf(lineptr, "layers %d", &iarg)) == 1) {
OK = 1; Num_layers = iarg;
}
if ((i = sscanf(lineptr, "layer_%d_name %s", &iarg2, sarg)) == 2) {
if (iarg2 > 0 && iarg2 < 10) {
OK = 1; strcpy(CIFLayer[iarg2 - 1], sarg);
}
}
if ((i = sscanf(lineptr, "gds_layer_%d %d", &iarg2, &iarg)) == 2) {
if (iarg2 > 0 && iarg2 < 10) {
OK = 1; GDSLayer[iarg2 - 1] = iarg;
}
}
if ((i = sscanf(lineptr, "gds_comment_layer %d", &iarg)) == 1) {
OK = 1; GDSCommentLayer = iarg;
}
if ((i = sscanf(lineptr, "layer_1_width %lf", &darg)) == 1) {
OK = 1; PathWidth[0] = darg;
}
if ((i = sscanf(lineptr, "layer_2_width %lf", &darg)) == 1) {
OK = 1; PathWidth[1] = darg;
}
if ((i = sscanf(lineptr, "layer_3_width %lf", &darg)) == 1) {
OK = 1; PathWidth[2] = darg;
}
if ((i = sscanf(lineptr, "layer_4_width %lf", &darg)) == 1) {
OK = 1; PathWidth[3] = darg;
}
if ((i = sscanf(lineptr, "layer_5_width %lf", &darg)) == 1) {
OK = 1; PathWidth[4] = darg;
}
if ((i = sscanf(lineptr, "layer_6_width %lf", &darg)) == 1) {
OK = 1; PathWidth[5] = darg;
}
if ((i = sscanf(lineptr, "layer_7_width %lf", &darg)) == 1) {
OK = 1; PathWidth[6] = darg;
}
if ((i = sscanf(lineptr, "layer_8_width %lf", &darg)) == 1) {
OK = 1; PathWidth[7] = darg;
}
if ((i = sscanf(lineptr, "layer_9_width %lf", &darg)) == 1) {
OK = 1; PathWidth[8] = darg;
}
if ((i = sscanf(lineptr, "x lower bound %lf", &darg)) == 1) {
OK = 1; Xlowerbound = darg;
}
if ((i = sscanf(lineptr, "x upper bound %lf", &darg)) == 1) {
OK = 1; Xupperbound = darg;
}
if ((i = sscanf(lineptr, "y lower bound %lf", &darg)) == 1) {
OK = 1; Ylowerbound = darg;
}
if ((i = sscanf(lineptr, "y upper bound %lf", &darg)) == 1) {
OK = 1; Yupperbound = darg;
}
if ((i = sscanf(lineptr, "layer %d wire pitch %lf\n", &iarg, &darg)) == 2) {
OK = 1; PitchX[iarg-1] = darg;
}
else if (i == 1) {
if ((i = sscanf(lineptr, "layer %*d vertical %d\n", &iarg2)) == 1) {
OK = 1; Vert[iarg - 1] = iarg2;
}
else if ((i = sscanf(lineptr, "layer %*d %c\n", &carg)) == 1) {
if (tolower(carg) == 'v') {
OK = 1; Vert[iarg - 1] = 1;
}
else if (tolower(carg) == 'h') {
OK = 1; Vert[iarg - 1] = 0;
}
}
}
if ((i = sscanf(lineptr, "num passes %d\n", &iarg)) == 1) {
OK = 1;
Numpasses = iarg;
}
else if ((i = sscanf(lineptr, "passes %d\n", &iarg)) == 1) {
OK = 1;
Numpasses = iarg;
}
if ((i = sscanf(lineptr, "route segment cost %d", &iarg)) == 1) {
OK = 1; SegCost = iarg;
}
if ((i = sscanf(lineptr, "route via cost %d", &iarg)) == 1) {
OK = 1; ViaCost = iarg;
}
if ((i = sscanf(lineptr, "route jog cost %d", &iarg)) == 1) {
OK = 1; JogCost = iarg;
}
if ((i = sscanf(lineptr, "route crossover cost %d", &iarg)) == 1) {
OK = 1; XverCost = iarg;
}
if ((i = sscanf(lineptr, "route block cost %d", &iarg)) == 1) {
OK = 1; BlockCost = iarg;
}
if ((i = sscanf(lineptr, "do not route node %s\n", sarg)) == 1) {
OK = 1;
dnr = (STRING)malloc(sizeof(struct string_));
dnr->name = strdup(sarg);
if (DontRoute != NULL) {
for (strl = DontRoute; strl->next; strl = strl->next);
strl->next = dnr;
}
else {
dnr->next = NULL;
DontRoute = dnr;
}
}
if ((i = sscanf(lineptr, "route priority %s\n", sarg)) == 1) {
OK = 1;
cn = (STRING)malloc(sizeof(struct string_));
cn->name = strdup(sarg);
if (CriticalNet != NULL) {
for (strl = CriticalNet; strl->next; strl = strl->next);
strl->next = cn;
}
else {
cn->next = NULL;
CriticalNet = cn;
}
}
if ((i = sscanf(lineptr, "critical net %s\n", sarg)) == 1) {
OK = 1;
cn = (STRING)malloc(sizeof(struct string_));
cn->name = strdup(sarg);
if (CriticalNet != NULL) {
for (strl = CriticalNet; strl->next; strl = strl->next);
strl->next = cn;
}
else {
cn->next = NULL;
CriticalNet = cn;
}
}
// Search for "no stack". This allows variants like "no stacked
// contacts", "no stacked vias", or just "no stacking", "no stacks",
// etc.
if (strcasestr(lineptr, "no stack") != NULL) {
OK = 1; StackedContacts = 1;
}
// Search for "stack N", where "N" is the largest number of vias
// that can be stacked upon each other. Values 0 and 1 are both
// equivalent to specifying "no stack".
if ((i = sscanf(lineptr, "stack %d", &iarg)) == 1) {
OK = 1; StackedContacts = iarg;
// Can't let StackedContacts be zero because qrouter would
// believe that all contacts are disallowed, leading to a
// lot of wasted processing time while it determines that's
// not possible. . .
if (StackedContacts == 0) StackedContacts = 1;
}
else if ((i = sscanf(lineptr, "via stack %d", &iarg)) == 1) {
OK = 1; StackedContacts = iarg;
if (StackedContacts == 0) StackedContacts = 1;
}
// Look for via patterning specifications
if (strcasestr(lineptr, "via pattern") != NULL) {
if (strcasestr(lineptr + 12, "normal") != NULL)
ViaPattern = VIA_PATTERN_NORMAL;
else if (strcasestr(lineptr + 12, "invert") != NULL)
ViaPattern = VIA_PATTERN_INVERT;
}
if ((i = sscanf(lineptr, "obstruction %lf %lf %lf %lf %s\n",
&darg, &darg2, &darg3, &darg4, sarg)) == 5) {
OK = 1;
drect = (DSEG)malloc(sizeof(struct dseg_));
drect->x1 = darg;
drect->y1 = darg2;
drect->x2 = darg3;
drect->y2 = darg4;
drect->layer = LefFindLayerNum(sarg);
if (drect->layer < 0) {
if ((i = sscanf(sarg, "%lf", &darg)) == 1) {
i = (int)(darg + EPS);
if (i >= 0 && i < Num_layers) {
drect->layer = i;
}
}
}
if (drect->layer >= 0) {
drect->next = UserObs;
UserObs = drect;
}
else {
free(drect);
}
}
if ((i = sscanf(lineptr, "gate %s %lf %lf\n", sarg, &darg, &darg2)) == 3) {
OK = 1;
CurrentPin = 0;
gateinfo = (GATE)malloc(sizeof(struct gate_));
gateinfo->gatename = strdup(sarg);
gateinfo->gatetype = NULL;
gateinfo->width = darg;
gateinfo->height = darg2;
gateinfo->placedX = 0.0; // implicit cell origin
gateinfo->placedY = 0.0;
gateinfo->next = GateInfo; // prepend to linked gate list
GateInfo = gateinfo;
}
if ((i = sscanf(lineptr, "endgate %s\n", sarg)) == 1) {
OK = 1;
gateinfo->nodes = CurrentPin;
// This syntax does not include declaration of obstructions
gateinfo->obs = (DSEG)NULL;
CurrentPin = 0;
}
if ((i = sscanf(lineptr, "pin %s %lf %lf\n", sarg, &darg, &darg2)) == 3) {
OK = 1;
gateinfo->node[CurrentPin] = strdup(sarg);
// These style gates have only one tap per gate; LEF file reader
// allows multiple taps per gate node.
drect = (DSEG)malloc(sizeof(struct dseg_));
gateinfo->taps[CurrentPin] = drect;
drect->x1 = drect->x2 = darg;
drect->y1 = drect->y2 = darg2;
// This syntax always defines pins on layer 0; LEF file reader
// allows pins on all layers.
drect->layer = 0;
drect->next = (DSEG)NULL;
CurrentPin++;
}
if (OK == 0) {
if (!(lineptr[0] == '\n' || lineptr[0] == '#' || lineptr[0] == 0)) {
Fprintf(stderr, "line not understood: %s\n", line);
}
}
OK = 0;
line[0] = line[1] = '\0';
}
post_config();
return count;
} /* read_config() */
|