#include "defs.h" /* estimate extra length of wire required to interchange * chips c1 and c2. To move c1 to c2 add delx and dely to * to the coordinates of c1. c2 may be zero. * return immediately that it is obvious that the extra length * will be grater than lim. * Returned value is the estimated extra length. */ PIN nvec[2*MAXPIN]; /* pointers to heads of nets */ L_INT netl(c1, c2, delx, dely, lim) CHP c1, c2; INT delx, dely; L_INT lim; { REG PIN pp, opp; PIN p, hd, lopin, hipin; CHP ca, cb; PIN1 root; INT nd, psum, i; PIN *np; REG INT od; L_INT sum; ca = c1; cb = c2; sum = 0; np = nvec; for (i = 0; i < 2; i++) { if (cb) { lopin = cb->pins; hipin = &cb->pins[cb->siz]; } else { /* no restriction on scan */ lopin = Enets; hipin = nets; } if (ca) for (p = ca->pins; p < &ca->pins[ca->siz]; p++) { pp = p; hd = 0; *np = 0; do { if ((pp->x & UNPLAC) == 0) { opp = pp; if (hd == 0 && pp != p) hd = pp; } pp = CHAIN(pp); if (pp >= lopin && pp < hipin) goto ignore; if (HEAD(pp)) *np = (pp == p)? hd : pp; } while (pp != p); if ((pp = hd) == 0) goto ignore; if (pp == opp && (p->x & UNPLAC) == 0) { sum += twodist(pp->x-p->x,pp->y-p->y,delx,dely); goto ignore; } if ((p->x & UNPLAC) == 0) { od = (HEAD(p)) ? 0 : wdist(p,opp); if (HEAD(pp) == 0) { od += wdist(p, pp); if (HEAD(p) == 0) od -= wdist(opp, pp); } sum -= od; } np++; continue; ignore: *np++ = 0; } ca = c2; cb = c1; delx = -delx; dely = -dely; } if (sum >= lim) goto out; ca = c1; np = nvec; for (i = 0; i < 2; i++) { if (ca) for (p = ca->pins; p < &ca->pins[ca->siz]; p++) { opp = hd = *np++; if (opp == 0) continue; root->x = p->x + delx; root->y = p->y + dely; od = psum = wdist(opp, root); for (pp = CHAIN(opp); pp != hd; pp = CHAIN(pp)) { if (p == pp || pp->x & UNPLAC) continue; nd = wdist(root, pp); od = od + nd - wdist(pp, opp); if (od < psum) psum = od; od = nd; opp = pp; } if (psum < od) od = psum; sum += od; if (sum >= lim) goto out; } ca = c2; delx = -delx; dely = -dely; } out: return(sum); }