diff --git a/resis/ResMain.c b/resis/ResMain.c index 400e3808..13190c44 100644 --- a/resis/ResMain.c +++ b/resis/ResMain.c @@ -23,20 +23,20 @@ static char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magic-8.0/ #include "textio/txcommands.h" #include "resis/resis.h" -CellUse *ResUse=NULL; /* Our use and def */ -CellDef *ResDef=NULL; +CellUse *ResUse = NULL; /* Our use and def */ +CellDef *ResDef = NULL; TileTypeBitMask ResConnectWithSD[NT]; /* A mask that goes from */ /* SD's to devices. */ TileTypeBitMask ResCopyMask[NT]; /* Indicates which tiles */ /* are to be copied. */ -resResistor *ResResList=NULL; /* Resistor list */ -resNode *ResNodeList=NULL; /* Processed Nodes */ -resDevice *ResDevList=NULL; /* Devices */ -ResContactPoint *ResContactList=NULL; /* Contacts */ -resNode *ResNodeQueue=NULL; /* Pending nodes */ -resNode *ResOriginNode=NULL; /* node where R=0 */ +resResistor *ResResList = NULL; /* Resistor list */ +resNode *ResNodeList = NULL; /* Processed Nodes */ +resDevice *ResDevList = NULL; /* Devices */ +ResContactPoint *ResContactList = NULL; /* Contacts */ +resNode *ResNodeQueue = NULL; /* Pending nodes */ +resNode *ResOriginNode = NULL; /* node where R=0 */ resNode *resCurrentNode; -int ResTileCount=0; /* Number of tiles rn_status */ +int ResTileCount = 0; /* Number of tiles rn_status */ extern Region *ResFirst(); extern Tile *FindStartTile(); extern int ResEachTile(); @@ -46,7 +46,6 @@ extern ResSimNode *ResInitializeNode(); extern HashTable ResNodeTable; - /* *-------------------------------------------------------------------------- * @@ -78,13 +77,13 @@ ResInitializeConn() for (diff = TT_TECHDEPBASE; diff < TT_MAXTYPES; diff++) { if TTMaskHasType(&(devptr->exts_deviceSDTypes[0]), diff) - TTMaskSetType(&ResConnectWithSD[diff],dev); + TTMaskSetType(&ResConnectWithSD[diff], dev); - if TTMaskHasType(&(devptr->exts_deviceSubstrateTypes),diff) - TTMaskSetType(&ResConnectWithSD[diff],dev); + if TTMaskHasType(&(devptr->exts_deviceSubstrateTypes), diff) + TTMaskSetType(&ResConnectWithSD[diff], dev); } } - TTMaskSetMask(&ResConnectWithSD[dev],&DBConnectTbl[dev]); + TTMaskSetMask(&ResConnectWithSD[dev], &DBConnectTbl[dev]); } } @@ -121,7 +120,6 @@ ResGetReCell() ResUse = DBCellNewUse(ResDef, (char *) NULL); DBSetTrans(ResUse, &GeoIdentityTransform); ResUse->cu_expandMask = CU_DESCEND_SPECIAL; - } /* @@ -172,7 +170,7 @@ ResDissolveContacts(contacts) } tp = ResDef->cd_planes[DBPlane(contacts->cp_type)]->pl_hint; - GOTOPOINT(tp,&(contacts->cp_rect.r_ll)); + GOTOPOINT(tp, &(contacts->cp_rect.r_ll)); #ifdef PARANOID if (TiGetTypeExact(tp) == contacts->cp_type) { @@ -325,46 +323,46 @@ ResAddBreakpointFunc(tile, node) void ResFindNewContactTiles(contacts) - ResContactPoint *contacts; + ResContactPoint *contacts; { - int pNum; - Tile *tile; - TileTypeBitMask mask; + int pNum; + Tile *tile; + TileTypeBitMask mask; - for (; contacts != (ResContactPoint *) NULL; contacts = contacts->cp_nextcontact) - { - DBFullResidueMask(contacts->cp_type, &mask); - for (pNum=PL_TECHDEPBASE; pNumcd_planes[pNum]->pl_hint; - GOTOPOINT(tile, &(contacts->cp_center)); + for (; contacts != (ResContactPoint *) NULL; contacts = contacts->cp_nextcontact) + { + DBFullResidueMask(contacts->cp_type, &mask); + for (pNum = PL_TECHDEPBASE; pNum < DBNumPlanes; pNum++) + { + tile = ResDef->cd_planes[pNum]->pl_hint; + GOTOPOINT(tile, &(contacts->cp_center)); #ifdef PARANOID - if (tile == (Tile *) NULL) - { - TxError("Error: setting contact tile to null\n"); - } + if (tile == (Tile *) NULL) + { + TxError("Error: setting contact tile to null\n"); + } #endif - if ((IsSplit(tile) && TTMaskHasType(&mask, TiGetRightType(tile))) + if ((IsSplit(tile) && TTMaskHasType(&mask, TiGetRightType(tile))) || TTMaskHasType(&mask, TiGetType(tile))) - { - tileJunk *j = (tileJunk *)tile->ti_client; - cElement *ce; + { + tileJunk *j = (tileJunk *)tile->ti_client; + cElement *ce; - ce = (cElement *) mallocMagic((unsigned) (sizeof(cElement))); - contacts->cp_tile[contacts->cp_currentcontact] = tile; - ce->ce_thisc = contacts; - ce->ce_nextc = j->contactList; - (contacts->cp_currentcontact) += 1; - j->contactList = ce; - } - } + ce = (cElement *) mallocMagic((unsigned) (sizeof(cElement))); + contacts->cp_tile[contacts->cp_currentcontact] = tile; + ce->ce_thisc = contacts; + ce->ce_nextc = j->contactList; + (contacts->cp_currentcontact) += 1; + j->contactList = ce; + } + } #ifdef PARANOID - if (contacts->cp_currentcontact > LAYERS_PER_CONTACT) - { - TxError("Error: Not enough space allocated for contact nodes\n"); - } + if (contacts->cp_currentcontact > LAYERS_PER_CONTACT) + { + TxError("Error: Not enough space allocated for contact nodes\n"); + } #endif - } + } } /* @@ -388,78 +386,77 @@ ResProcessTiles(goodies, origin) ResGlobalParams *goodies; { - Tile *startTile; - int tilenum,merged; - resNode *resptr2; - jElement *workingj; - cElement *workingc; - ResFixPoint *fix; - resNode *resptr; - int (*tilefunc)(); + Tile *startTile; + int tilenum, merged; + resNode *resptr2; + jElement *workingj; + cElement *workingc; + ResFixPoint *fix; + resNode *resptr; + int (*tilefunc)(); #ifdef LAPLACE - tilefunc = (ResOptionsFlags & ResOpt_DoLaplace)?ResLaplaceTile:ResEachTile; + tilefunc = (ResOptionsFlags & ResOpt_DoLaplace) ? ResLaplaceTile : ResEachTile; #else - tilefunc = ResEachTile; + tilefunc = ResEachTile; #endif if (ResOptionsFlags & ResOpt_Signal) { - startTile = FindStartTile(goodies, origin); - if (startTile == NULL) return(1); - resCurrentNode = NULL; - (void) (*tilefunc)(startTile, origin); + startTile = FindStartTile(goodies, origin); + if (startTile == NULL) return(1); + resCurrentNode = NULL; + (void) (*tilefunc)(startTile, origin); } #ifdef ARIEL else if (ResOptionsFlags & ResOpt_Power) { - for (fix = ResFixList; fix != NULL;fix=fix->fp_next) - { - Tile *tile = fix->fp_tile; - if (tile == NULL) - { + for (fix = ResFixList; fix != NULL; fix = fix->fp_next) + { + Tile *tile = fix->fp_tile; + if (tile == NULL) + { + tile = ResDef->cd_planes[DBPlane(fix->fp_ttype)]->pl_hint; + GOTOPOINT(tile, &(fix->fp_loc)); + if (TiGetTypeExact(tile) != TT_SPACE) + { + fix->fp_tile = tile; + } + else + { + tile = NULL; + } + } + if (tile != NULL) + { + int x = fix->fp_loc.p_x; + int y = fix->fp_loc.p_y; + resptr = (resNode *) mallocMagic((unsigned)(sizeof(resNode))); + InitializeNode(resptr, x, y, RES_NODE_ORIGIN); + resptr->rn_status = TRUE; + resptr->rn_noderes = 0; + ResAddToQueue(resptr, &ResNodeQueue); + fix->fp_node = resptr; + NEWBREAK(resptr, tile, x, y, NULL); + } + } + for (fix = ResFixList; fix != NULL; fix = fix->fp_next) + { + Tile *tile = fix->fp_tile; - tile = ResDef->cd_planes[DBPlane(fix->fp_ttype)]->pl_hint; - GOTOPOINT(tile, &(fix->fp_loc)); - if (TiGetTypeExact(tile) != TT_SPACE) - { - fix->fp_tile = tile; - } - else - { - tile = NULL; - } - } - if (tile != NULL) - { - int x = fix->fp_loc.p_x; - int y = fix->fp_loc.p_y; - resptr = (resNode *) mallocMagic((unsigned)(sizeof(resNode))); - InitializeNode(resptr, x, y, RES_NODE_ORIGIN); - resptr->rn_status = TRUE; - resptr->rn_noderes = 0; - ResAddToQueue(resptr, &ResNodeQueue); - fix->fp_node = resptr; - NEWBREAK(resptr, tile, x, y, NULL); - } - } - for (fix = ResFixList; fix != NULL; fix = fix->fp_next) - { - Tile *tile = fix->fp_tile; - - if (tile != NULL && (((tileJunk *)tile->ti_client)->tj_status & + if (tile != NULL && (((tileJunk *)tile->ti_client)->tj_status & RES_TILE_DONE) == 0) - { - resCurrentNode = fix->fp_node; - (void) (*tilefunc)(tile, (Point *)NULL); - } - } + { + resCurrentNode = fix->fp_node; + (void) (*tilefunc)(tile, (Point *)NULL); + } + } } #endif #ifdef PARANOID else { - TxError("Unknown analysis type in ResProcessTiles\n"); + TxError("Unknown analysis type in ResProcessTiles\n"); } #endif @@ -467,100 +464,100 @@ ResProcessTiles(goodies, origin) while (ResNodeQueue != NULL) { - /* - * merged keeps track of whether another node gets merged into - * the current one. If it does, then the node must be processed - * because additional junctions or contacts were added - */ + /* + * merged keeps track of whether another node gets merged into + * the current one. If it does, then the node must be processed + * because additional junctions or contacts were added + */ - resptr2 = ResNodeQueue; - merged = FALSE; + resptr2 = ResNodeQueue; + merged = FALSE; - /* Process all junctions associated with node */ + /* Process all junctions associated with node */ - for (workingj = resptr2->rn_je; workingj != NULL; workingj = workingj->je_nextj) - { - ResJunction *rj = workingj->je_thisj; - if (rj->rj_status == FALSE) - { - for (tilenum = 0; tilenum < TILES_PER_JUNCTION; tilenum++) - { - Tile *tile = rj->rj_Tile[tilenum]; - tileJunk *j = (tileJunk *) tile->ti_client; + for (workingj = resptr2->rn_je; workingj != NULL; workingj = workingj->je_nextj) + { + ResJunction *rj = workingj->je_thisj; + if (rj->rj_status == FALSE) + { + for (tilenum = 0; tilenum < TILES_PER_JUNCTION; tilenum++) + { + Tile *tile = rj->rj_Tile[tilenum]; + tileJunk *j = (tileJunk *)tile->ti_client; - if ((j->tj_status & RES_TILE_DONE) == 0) + if ((j->tj_status & RES_TILE_DONE) == 0) + { + resCurrentNode = resptr2; + merged |= (*tilefunc)(tile,(Point *)NULL); + } + if (merged & ORIGIN) break; + } + if (merged & ORIGIN) break; + rj->rj_status = TRUE; + } + } + + /* Next, Process all contacts. */ + + for (workingc = resptr2->rn_ce;workingc != NULL;workingc = workingc->ce_nextc) + { + ResContactPoint *cp = workingc->ce_thisc; + + if (merged & ORIGIN) break; + if (cp->cp_status == FALSE) + { + int newstatus = TRUE; + for (tilenum = 0; tilenum < cp->cp_currentcontact; tilenum++) + { + Tile *tile = cp->cp_tile[tilenum]; + tileJunk *j = (tileJunk *) tile->ti_client; + + if ((j->tj_status & RES_TILE_DONE) == 0) + { + if (cp->cp_cnode[tilenum] == resptr2) { - resCurrentNode = resptr2; - merged |= (*tilefunc)(tile,(Point *)NULL); + resCurrentNode = resptr2; + merged |= (*tilefunc)(tile,(Point *)NULL); } - if (merged & ORIGIN) break; - } - if (merged & ORIGIN) break; - rj->rj_status = TRUE; - } - } - - /* Next, Process all contacts. */ - - for (workingc = resptr2->rn_ce;workingc != NULL;workingc = workingc->ce_nextc) - { - ResContactPoint *cp = workingc->ce_thisc; - - if (merged & ORIGIN) break; - if (cp->cp_status == FALSE) - { - int newstatus = TRUE; - for (tilenum = 0; tilenum < cp->cp_currentcontact; tilenum++) - { - Tile *tile = cp->cp_tile[tilenum]; - tileJunk *j = (tileJunk *) tile->ti_client; - - if ((j->tj_status & RES_TILE_DONE) == 0) + else { - if (cp->cp_cnode[tilenum] == resptr2) - { - resCurrentNode = resptr2; - merged |= (*tilefunc)(tile,(Point *)NULL); - } - else - { - newstatus = FALSE; - } + newstatus = FALSE; } - if (merged & ORIGIN) break; - } - if (merged & ORIGIN) break; - cp->cp_status = newstatus; - } - } + } + if (merged & ORIGIN) break; + } + if (merged & ORIGIN) break; + cp->cp_status = newstatus; + } + } - /* - * If nothing new has been added via a merge, then the node is - * finished. It is removed from the pending queue, added to the - * done list, cleaned up, and passed to ResDoneWithNode - */ + /* + * If nothing new has been added via a merge, then the node is + * finished. It is removed from the pending queue, added to the + * done list, cleaned up, and passed to ResDoneWithNode + */ - if (merged == FALSE) - { - ResRemoveFromQueue(resptr2,&ResNodeQueue); - resptr2->rn_more = ResNodeList; - resptr2->rn_less = NULL; - resptr2->rn_status &= ~PENDING; - resptr2->rn_status |= FINISHED | MARKED; - if (ResNodeList != NULL) - { - ResNodeList->rn_less = resptr2; - } - if (resptr2->rn_noderes == 0) - { - ResOriginNode=resptr2; - } - ResNodeList = resptr2; - ResCleanNode(resptr2, FALSE, &ResNodeList, &ResNodeQueue); - ResDoneWithNode(resptr2); - } - } - return(0); + if (merged == FALSE) + { + ResRemoveFromQueue(resptr2, &ResNodeQueue); + resptr2->rn_more = ResNodeList; + resptr2->rn_less = NULL; + resptr2->rn_status &= ~PENDING; + resptr2->rn_status |= FINISHED | MARKED; + if (ResNodeList != NULL) + { + ResNodeList->rn_less = resptr2; + } + if (resptr2->rn_noderes == 0) + { + ResOriginNode=resptr2; + } + ResNodeList = resptr2; + ResCleanNode(resptr2, FALSE, &ResNodeList, &ResNodeQueue); + ResDoneWithNode(resptr2); + } + } + return(0); } /*------------------------------------------------------------------------- @@ -599,7 +596,7 @@ ResExtractNet(startlist, goodies, cellname) ResContactList = NULL; ResOriginNode = NULL; - /* Pass back network pointers */ + /* Pass back network pointers */ goodies->rg_maxres = 0; goodies->rg_tilecount = 0; @@ -608,9 +605,9 @@ ResExtractNet(startlist, goodies, cellname) if (first) { - ResInitializeConn(); - first = 0; - ResGetReCell(); + ResInitializeConn(); + first = 0; + ResGetReCell(); } /* Initialize Cell */ @@ -618,7 +615,7 @@ ResExtractNet(startlist, goodies, cellname) if (cellname) { CellDef *def = DBCellLookDef(cellname); - if (def == (CellDef *) NULL) + if (def == (CellDef *)NULL) { TxError("Error: No such cell \"%s\"\n", cellname); return TRUE; @@ -629,8 +626,8 @@ ResExtractNet(startlist, goodies, cellname) } else { - MagWindow *w = ToolGetBoxWindow(&scx.scx_area, (int *) NULL); - if (w == (MagWindow *) NULL) + MagWindow *w = ToolGetBoxWindow(&scx.scx_area, (int *)NULL); + if (w == (MagWindow *)NULL) { TxError("Sorry, the box must appear in one of the windows.\n"); return TRUE; @@ -646,45 +643,45 @@ ResExtractNet(startlist, goodies, cellname) lasttile = NULL; for (fix = startlist; fix != NULL; fix = fix->fp_next) { - ResDevTile *newdevtiles, *tmp; + ResDevTile *newdevtiles, *tmp; #ifdef ARIEL - if ((ResOptionsFlags & ResOpt_Power) && + if ((ResOptionsFlags & ResOpt_Power) && strcmp(fix->fp_name, goodies->rg_name) != 0) continue; #endif - scx.scx_area.r_ll.p_x = fix->fp_loc.p_x-2; - scx.scx_area.r_ll.p_y = fix->fp_loc.p_y-2; - scx.scx_area.r_ur.p_x = fix->fp_loc.p_x+2; - scx.scx_area.r_ur.p_y = fix->fp_loc.p_y+2; - startpoint = fix->fp_loc; + scx.scx_area.r_ll.p_x = fix->fp_loc.p_x-2; + scx.scx_area.r_ll.p_y = fix->fp_loc.p_y-2; + scx.scx_area.r_ur.p_x = fix->fp_loc.p_x+2; + scx.scx_area.r_ur.p_y = fix->fp_loc.p_y+2; + startpoint = fix->fp_loc; - /* Because fix->fp_ttype might come from a label with a sticky type - * that does not correspond exactly to the layer underneath, include - * all connecting types. - */ - TTMaskZero(&FirstTileMask); - TTMaskSetMask(&FirstTileMask, &DBConnectTbl[fix->fp_ttype]); + /* Because fix->fp_ttype might come from a label with a sticky type + * that does not correspond exactly to the layer underneath, include + * all connecting types. + */ + TTMaskZero(&FirstTileMask); + TTMaskSetMask(&FirstTileMask, &DBConnectTbl[fix->fp_ttype]); - newdevtiles = DBTreeCopyConnectDCS(&scx, &FirstTileMask, 0, + newdevtiles = DBTreeCopyConnectDCS(&scx, &FirstTileMask, 0, ResCopyMask, &TiPlaneRect, ResUse); - for (tmp = newdevtiles; tmp && tmp->nextDev; tmp = tmp->nextDev); - if (newdevtiles) - { - if (DevTiles) - lasttile->nextDev = newdevtiles; - else - DevTiles = newdevtiles; - lasttile = tmp; - } + for (tmp = newdevtiles; tmp && tmp->nextDev; tmp = tmp->nextDev); + if (newdevtiles) + { + if (DevTiles) + lasttile->nextDev = newdevtiles; + else + DevTiles = newdevtiles; + lasttile = tmp; + } } ExtResetTiles(scx.scx_use->cu_def, extUnInit); - /* find all contacts in design and note their position */ + /* Find all contacts in design and note their position */ - ResContactList = (ResContactPoint *) ExtFindRegions(ResUse->cu_def, + ResContactList = (ResContactPoint *)ExtFindRegions(ResUse->cu_def, &(ResUse->cu_def->cd_bbox), &DBAllButSpaceAndDRCBits, ResConnectWithSD, extUnInit, ResFirst, @@ -702,16 +699,16 @@ ResExtractNet(startlist, goodies, cellname) for (pNum = PL_TECHDEPBASE; pNum < DBNumPlanes; pNum++) { - Plane *plane = ResUse->cu_def->cd_planes[pNum]; - Rect *rect = &ResUse->cu_def->cd_bbox; - ResFracture(plane, rect); - (void) DBSrPaintClient((Tile *) NULL,plane,rect, + Plane *plane = ResUse->cu_def->cd_planes[pNum]; + Rect *rect = &ResUse->cu_def->cd_bbox; + ResFracture(plane, rect); + (void) DBSrPaintClient((Tile *) NULL, plane, rect, &DBAllButSpaceAndDRCBits, (ClientData) CLIENTDEFAULT, ResAddPlumbing, (ClientData) &ResDevList); } - /* Finish preprocessing. */ + /* Finish preprocessing. */ ResMakePortBreakpoints(ResUse->cu_def); ResMakeLabelBreakpoints(ResUse->cu_def); @@ -721,24 +718,24 @@ ResExtractNet(startlist, goodies, cellname) #ifdef LAPLACE if (ResOptionsFlags & ResOpt_DoLaplace) { - for (pNum = PL_TECHDEPBASE; pNum < DBNumPlanes; pNum++) - { - Plane *plane = ResUse->cu_def->cd_planes[pNum]; - Rect *rect = &ResUse->cu_def->cd_bbox; - Res1d(plane,rect); - } + for (pNum = PL_TECHDEPBASE; pNum < DBNumPlanes; pNum++) + { + Plane *plane = ResUse->cu_def->cd_planes[pNum]; + Rect *rect = &ResUse->cu_def->cd_bbox; + Res1d(plane, rect); + } } #endif #ifdef ARIEL if (ResOptionsFlags & ResOpt_Power) { - for (fix = startlist; fix != NULL;fix=fix->fp_next) - { - fix->fp_tile = ResUse->cu_def->cd_planes[DBPlane(fix->fp_ttype)]->pl_hint; - GOTOPOINT(fix->fp_tile,&fix->fp_loc); - if (TiGetTypeExact(fix->fp_tile) == TT_SPACE) fix->fp_tile = NULL; - } + for (fix = startlist; fix != NULL; fix = fix->fp_next) + { + fix->fp_tile = ResUse->cu_def->cd_planes[DBPlane(fix->fp_ttype)]->pl_hint; + GOTOPOINT(fix->fp_tile, &fix->fp_loc); + if (TiGetTypeExact(fix->fp_tile) == TT_SPACE) fix->fp_tile = NULL; + } } #endif @@ -766,25 +763,24 @@ void ResCleanUpEverything() { - int pNum; - resResistor *oldRes; - resDevice *oldDev; - ResContactPoint *oldCon; + int pNum; + resResistor *oldRes; + resDevice *oldDev; + ResContactPoint *oldCon; - /* check integrity of internal database. Free up lists. */ + /* Check integrity of internal database. Free up lists. */ for (pNum = PL_TECHDEPBASE; pNum < DBNumPlanes; pNum++) { - (void) DBSrPaintClient((Tile *) NULL,ResUse->cu_def->cd_planes[pNum], - &(ResUse->cu_def->cd_bbox),&DBAllButSpaceAndDRCBits, - (ClientData) CLIENTDEFAULT,ResRemovePlumbing, - (ClientData) NULL); - + (void) DBSrPaintClient((Tile *)NULL, ResUse->cu_def->cd_planes[pNum], + &(ResUse->cu_def->cd_bbox), &DBAllButSpaceAndDRCBits, + (ClientData)CLIENTDEFAULT, ResRemovePlumbing, + (ClientData)NULL); } while (ResNodeList != NULL) { - ResCleanNode(ResNodeList,TRUE,&ResNodeList,&ResNodeQueue); + ResCleanNode(ResNodeList, TRUE, &ResNodeList, &ResNodeQueue); } while (ResContactList != NULL) { @@ -808,12 +804,9 @@ ResCleanUpEverything() freeMagic((char *)oldDev); } } - DBCellClearDef(ResUse->cu_def); } - - /* *------------------------------------------------------------------------- * @@ -935,54 +928,55 @@ FindStartTile(goodies, SourcePoint) t1 = TiGetType(tile); devptr = ExtCurStyle->exts_device[t1]; + /* left */ - for (tp = BL(tile); BOTTOM(tp) < TOP(tile); tp=RT(tp)) + for (tp = BL(tile); BOTTOM(tp) < TOP(tile); tp = RT(tp)) { t2 = TiGetRightType(tp); - if (TTMaskHasType(&(devptr->exts_deviceSDTypes[0]),t2)) + if (TTMaskHasType(&(devptr->exts_deviceSDTypes[0]), t2)) { SourcePoint->p_x = LEFT(tile); - SourcePoint->p_y = (MIN(TOP(tile),TOP(tp))+ - MAX(BOTTOM(tile),BOTTOM(tp)))>>1; + SourcePoint->p_y = (MIN(TOP(tile),TOP(tp)) + + MAX(BOTTOM(tile), BOTTOM(tp))) >> 1; return(tp); } } /* right */ - for (tp = TR(tile); TOP(tp) > BOTTOM(tile); tp=LB(tp)) + for (tp = TR(tile); TOP(tp) > BOTTOM(tile); tp = LB(tp)) { t2 = TiGetLeftType(tp); - if (TTMaskHasType(&(devptr->exts_deviceSDTypes[0]),t2)) + if (TTMaskHasType(&(devptr->exts_deviceSDTypes[0]), t2)) { SourcePoint->p_x = RIGHT(tile); - SourcePoint->p_y = (MIN(TOP(tile),TOP(tp))+ - MAX(BOTTOM(tile),BOTTOM(tp)))>>1; + SourcePoint->p_y = (MIN(TOP(tile), TOP(tp))+ + MAX(BOTTOM(tile), BOTTOM(tp))) >> 1; return(tp); } } /* top */ - for (tp = RT(tile); RIGHT(tp) > LEFT(tile); tp=BL(tp)) + for (tp = RT(tile); RIGHT(tp) > LEFT(tile); tp = BL(tp)) { t2 = TiGetBottomType(tp); - if (TTMaskHasType(&(devptr->exts_deviceSDTypes[0]),t2)) + if (TTMaskHasType(&(devptr->exts_deviceSDTypes[0]), t2)) { SourcePoint->p_y = TOP(tile); - SourcePoint->p_x = (MIN(RIGHT(tile),RIGHT(tp))+ - MAX(LEFT(tile),LEFT(tp)))>>1; + SourcePoint->p_x = (MIN(RIGHT(tile),RIGHT(tp)) + + MAX(LEFT(tile), LEFT(tp))) >> 1; return(tp); } } /* bottom */ - for (tp = LB(tile); LEFT(tp) < RIGHT(tile); tp=TR(tp)) + for (tp = LB(tile); LEFT(tp) < RIGHT(tile); tp = TR(tp)) { t2 = TiGetTopType(tp); - if (TTMaskHasType(&(devptr->exts_deviceSDTypes[0]),t2)) + if (TTMaskHasType(&(devptr->exts_deviceSDTypes[0]), t2)) { SourcePoint->p_y = BOTTOM(tile); - SourcePoint->p_x = (MIN(RIGHT(tile),RIGHT(tp))+ - MAX(LEFT(tile),LEFT(tp)))>>1; + SourcePoint->p_x = (MIN(RIGHT(tile), RIGHT(tp)) + + MAX(LEFT(tile), LEFT(tp))) >> 1; return(tp); } } @@ -1006,36 +1000,36 @@ FindStartTile(goodies, SourcePoint) resDevice * ResGetDevice(pt) - Point *pt; + Point *pt; { - Point workingPoint; - Tile *tile; - int pnum; + Point workingPoint; + Tile *tile; + int pnum; - workingPoint.p_x = (*pt).p_x; - workingPoint.p_y = (*pt).p_y; + workingPoint.p_x = (*pt).p_x; + workingPoint.p_y = (*pt).p_y; - for (pnum= PL_TECHDEPBASE; pnum < DBNumPlanes; pnum++) - { - if (TTMaskIntersect(&ExtCurStyle->exts_deviceMask,&DBPlaneTypes[pnum]) == 0) - { - continue; - } - /*start at hint tile for device plane */ - tile = ResUse->cu_def->cd_planes[pnum]->pl_hint; - GOTOPOINT(tile,&workingPoint); + for (pnum = PL_TECHDEPBASE; pnum < DBNumPlanes; pnum++) + { + if (TTMaskIntersect(&ExtCurStyle->exts_deviceMask, &DBPlaneTypes[pnum]) == 0) + continue; - if (IsSplit(tile)) - { - if (TTMaskHasType(&ExtCurStyle->exts_deviceMask, TiGetLeftType(tile)) + /* Start at hint tile for device plane */ + + tile = ResUse->cu_def->cd_planes[pnum]->pl_hint; + GOTOPOINT(tile, &workingPoint); + + if (IsSplit(tile)) + { + if (TTMaskHasType(&ExtCurStyle->exts_deviceMask, TiGetLeftType(tile)) || TTMaskHasType(&ExtCurStyle->exts_deviceMask, TiGetRightType(tile))) - return(((tileJunk *)tile->ti_client)->deviceList); - } - else if (TTMaskHasType(&ExtCurStyle->exts_deviceMask, TiGetType(tile))) - { - return(((tileJunk *)tile->ti_client)->deviceList); - } - } - return (NULL); + return (((tileJunk *)tile->ti_client)->deviceList); + } + else if (TTMaskHasType(&ExtCurStyle->exts_deviceMask, TiGetType(tile))) + { + return (((tileJunk *)tile->ti_client)->deviceList); + } + } + return NULL; } diff --git a/resis/ResMerge.c b/resis/ResMerge.c index db328065..4882dbde 100644 --- a/resis/ResMerge.c +++ b/resis/ResMerge.c @@ -29,9 +29,10 @@ extern void ResFixBreakPoint(); /* *------------------------------------------------------------------------- * - * ResDoneWithNode--After all connections to node are made, ResDoneWithNode - * is called. It checks for parallel, series, loop, triangle, - * and single conections, and simplifies the network where possible. + * ResDoneWithNode-- + * After all connections to node are made, ResDoneWithNode is + * called. It checks for parallel, series, loop, triangle, and + * single conections, and simplifies the network where possible. * * Results: none * @@ -56,10 +57,7 @@ ResDoneWithNode(resptr) /* are there any resistors? */ - if (resptr->rn_re == NULL) - { - return; - } + if (resptr->rn_re == NULL) return; /* Special handling for geometry option */ @@ -73,10 +71,10 @@ ResDoneWithNode(resptr) rr1 = rcell1->re_thisEl; if (rr1->rr_connection1 == rr1->rr_connection2) { - ResDeleteResPointer(resptr,rr1); - ResDeleteResPointer(resptr,rr1); + ResDeleteResPointer(resptr, rr1); + ResDeleteResPointer(resptr, rr1); resptr->rn_float.rn_area += rr1->rr_float.rr_area; - ResEliminateResistor(rr1,&ResResList); + ResEliminateResistor(rr1, &ResResList); status = LOOP; ResDoneWithNode(resptr); break; @@ -84,8 +82,8 @@ ResDoneWithNode(resptr) } else if (rr1->rr_value == 0) { - ResDeleteResPointer(rr1->rr_connection1,rr1); - ResDeleteResPointer(rr1->rr_connection2,rr1); + ResDeleteResPointer(rr1->rr_connection1, rr1); + ResDeleteResPointer(rr1->rr_connection2, rr1); if (rr1->rr_connection1 == resptr) { resptr2 = rr1->rr_connection2; @@ -93,9 +91,9 @@ ResDoneWithNode(resptr) { resptr2 = rr1->rr_connection1; } - ResMergeNodes(resptr2,resptr,&ResNodeQueue,&ResNodeList); + ResMergeNodes(resptr2, resptr, &ResNodeQueue, &ResNodeList); resptr2->rn_float.rn_area += rr1->rr_float.rr_area; - ResEliminateResistor(rr1,&ResResList); + ResEliminateResistor(rr1, &ResResList); if ((resptr2->rn_status & TRUE) == TRUE) { resptr2->rn_status &= ~TRUE; @@ -106,23 +104,20 @@ ResDoneWithNode(resptr) break; } } + if (status != UNTOUCHED) return; /* resptr may be invalid */ /* Eliminations that can be only if there are no devices connected */ - /* to node. Series and dangling connections fall in this group. */ + /* to node. Series and dangling connections fall in this group. */ if ((resptr->rn_te == NULL) && (resptr->rn_why != RES_NODE_ORIGIN) && (status == UNTOUCHED)) - { status = ResSeriesCheck(resptr); - } + if ((status == UNTOUCHED) && (resptr->rn_why != RES_NODE_ORIGIN)) - { status = ResParallelCheck(resptr); - } + if ((status == UNTOUCHED) && (resptr->rn_why != RES_NODE_ORIGIN)) - { status = ResTriangleCheck(resptr); - } } @@ -141,20 +136,24 @@ ResDoneWithNode(resptr) */ void -ResFixRes(resptr,resptr2,resptr3,elimResis,newResis) - resNode *resptr,*resptr2,*resptr3; - resResistor *elimResis, *newResis; +ResFixRes(resptr, resptr2, resptr3, elimResis, newResis) + resNode *resptr, *resptr2, *resptr3; + resResistor *elimResis, *newResis; { resElement *thisREl; - resptr3->rn_float.rn_area += newResis->rr_value*resptr->rn_float.rn_area/((float)(newResis->rr_value+elimResis->rr_value)); - resptr2->rn_float.rn_area += elimResis->rr_value*resptr->rn_float.rn_area/((float)(newResis->rr_value+elimResis->rr_value)); + resptr3->rn_float.rn_area += newResis->rr_value*resptr->rn_float.rn_area + / ((float)(newResis->rr_value + elimResis->rr_value)); + resptr2->rn_float.rn_area += elimResis->rr_value*resptr->rn_float.rn_area + / ((float)(newResis->rr_value + elimResis->rr_value)); newResis->rr_value += elimResis->rr_value; - ASSERT(newResis->rr_value > 0,"series"); + ASSERT(newResis->rr_value > 0, "series"); newResis->rr_float.rr_area += elimResis->rr_float.rr_area; + #ifdef ARIEL - if (elimResis->rr_csArea && elimResis->rr_csArea < newResis->rr_csArea || newResis->rr_csArea == 0) + if (elimResis->rr_csArea && elimResis->rr_csArea < newResis->rr_csArea + || newResis->rr_csArea == 0) { newResis->rr_csArea = elimResis->rr_csArea; newResis->rr_tt = elimResis->rr_tt; @@ -170,10 +169,10 @@ ResFixRes(resptr,resptr2,resptr3,elimResis,newResis) } if (thisREl == NULL) TxError("Resistor not found in duo\n"); - ResDeleteResPointer(resptr,elimResis); - ResDeleteResPointer(resptr,newResis); + ResDeleteResPointer(resptr, elimResis); + ResDeleteResPointer(resptr, newResis); ResEliminateResistor(elimResis, &ResResList); - ResCleanNode(resptr, TRUE,&ResNodeList,&ResNodeQueue); + ResCleanNode(resptr, TRUE, &ResNodeList, &ResNodeQueue); } /* @@ -191,36 +190,36 @@ ResFixRes(resptr,resptr2,resptr3,elimResis,newResis) */ void -ResFixParallel(elimResis,newResis) - resResistor *elimResis,*newResis; +ResFixParallel(elimResis, newResis) + resResistor *elimResis, *newResis; { - if ((newResis->rr_value+elimResis->rr_value) != 0) + if ((newResis->rr_value + elimResis->rr_value) != 0) { - newResis->rr_value = (((float) newResis->rr_value)* - ((float)elimResis->rr_value))/ - ((float)(newResis->rr_value+ + newResis->rr_value = (((float) newResis->rr_value) * + ((float)elimResis->rr_value)) / + ((float)(newResis->rr_value + elimResis->rr_value)); - ASSERT(newResis->rr_value >= 0,"parallel"); + ASSERT(newResis->rr_value >= 0, "parallel"); } else { - newResis->rr_value =0; + newResis->rr_value = 0; } newResis->rr_float.rr_area += elimResis->rr_float.rr_area; #ifdef ARIEL newResis->rr_csArea += elimResis->rr_csArea; #endif - ResDeleteResPointer(elimResis->rr_connection1,elimResis); - ResDeleteResPointer(elimResis->rr_connection2,elimResis); - ResEliminateResistor(elimResis,&ResResList); + ResDeleteResPointer(elimResis->rr_connection1, elimResis); + ResDeleteResPointer(elimResis->rr_connection2, elimResis); + ResEliminateResistor(elimResis, &ResResList); } /* *------------------------------------------------------------------------- * * ResSeriesCheck -- for nodes with no devices, sees if a series - or loop combination is possible. + * or loop combination is possible. * * Results: returns SINGLE,LOOP,or SERIES if succesful. * @@ -231,175 +230,177 @@ ResFixParallel(elimResis,newResis) int ResSeriesCheck(resptr) - resNode *resptr; + resNode *resptr; { - resResistor *rr1,*rr2; - resNode *resptr2,*resptr3; - int status=UNTOUCHED; - resElement *res_next; + resResistor *rr1,*rr2; + resNode *resptr2, *resptr3; + int status = UNTOUCHED; + resElement *res_next; - rr1 = resptr->rn_re->re_thisEl; - res_next = resptr->rn_re->re_nextEl; + rr1 = resptr->rn_re->re_thisEl; + res_next = resptr->rn_re->re_nextEl; - if (res_next == NULL) - /* node with only one connection */ - { - resptr2 = (rr1->rr_connection1 == resptr)?rr1->rr_connection2: + if (res_next == NULL) + /* node with only one connection */ + { + resptr2 = (rr1->rr_connection1 == resptr) ? rr1->rr_connection2: rr1->rr_connection1; - ResDeleteResPointer(rr1->rr_connection1,rr1); - ResDeleteResPointer(rr1->rr_connection2,rr1); - resptr2->rn_float.rn_area += rr1->rr_float.rr_area+ + ResDeleteResPointer(rr1->rr_connection1, rr1); + ResDeleteResPointer(rr1->rr_connection2, rr1); + resptr2->rn_float.rn_area += rr1->rr_float.rr_area + resptr->rn_float.rn_area; - ResEliminateResistor(rr1,&ResResList); - ResCleanNode(resptr,TRUE,&ResNodeList,&ResNodeQueue); - status = SINGLE; - if (resptr2->rn_status & TRUE) - { - resptr2->rn_status &= ~TRUE; - ResDoneWithNode(resptr2); - } - resptr2 = NULL; - } - else if (res_next->re_nextEl == NULL) - { - rr2 = res_next->re_thisEl; - if (!TTMaskHasType(ResNoMergeMask+rr1->rr_tt,rr2->rr_tt)) - { - if (rr1->rr_connection1 == resptr) + ResEliminateResistor(rr1, &ResResList); + ResCleanNode(resptr, TRUE, &ResNodeList, &ResNodeQueue); + status = SINGLE; + if (resptr2->rn_status & TRUE) + { + resptr2->rn_status &= ~TRUE; + ResDoneWithNode(resptr2); + } + resptr2 = NULL; + } + else if (res_next->re_nextEl == NULL) + { + rr2 = res_next->re_thisEl; + if (!TTMaskHasType(ResNoMergeMask + rr1->rr_tt, rr2->rr_tt)) + { + if (rr1->rr_connection1 == resptr) + { + if (rr2->rr_connection1 == resptr) { - - if (rr2->rr_connection1 == resptr) - { - resptr2 = rr1->rr_connection2; - if (rr1->rr_connection2 == - rr2->rr_connection2) - { - status = LOOP; - ResDeleteResPointer(rr1->rr_connection1,rr1); - ResDeleteResPointer(rr1->rr_connection2,rr1); - ResDeleteResPointer(rr2->rr_connection1,rr2); - ResDeleteResPointer(rr2->rr_connection2,rr2); - resptr2->rn_float.rn_area += rr1->rr_float.rr_area + resptr2 = rr1->rr_connection2; + if (rr1->rr_connection2 == rr2->rr_connection2) + { + status = LOOP; + ResDeleteResPointer(rr1->rr_connection1, rr1); + ResDeleteResPointer(rr1->rr_connection2, rr1); + ResDeleteResPointer(rr2->rr_connection1, rr2); + ResDeleteResPointer(rr2->rr_connection2, rr2); + resptr2->rn_float.rn_area += rr1->rr_float.rr_area + rr2->rr_float.rr_area + resptr->rn_float.rn_area; - ResEliminateResistor(rr1,&ResResList); - ResEliminateResistor(rr2,&ResResList); - ResCleanNode(resptr,TRUE,&ResNodeList,&ResNodeQueue); - }else - { - status = SERIES; - resptr3 = rr2->rr_connection2; - rr1->rr_connection1 = rr2->rr_connection2; - ResFixRes(resptr,resptr2,resptr3,rr2,rr1); - } - if ((resptr2->rn_status & TRUE) == TRUE) - { - resptr2->rn_status &= ~TRUE; - ResDoneWithNode(resptr2); - } - resptr2 = NULL; - }else - { - resptr2 = rr1->rr_connection2; - if (rr1->rr_connection2 == rr2->rr_connection1) - { - status = LOOP; - ResDeleteResPointer(rr1->rr_connection1,rr1); - ResDeleteResPointer(rr1->rr_connection2,rr1); - ResDeleteResPointer(rr2->rr_connection1,rr2); - ResDeleteResPointer(rr2->rr_connection2,rr2); - resptr2->rn_float.rn_area += rr1->rr_float.rr_area - + rr2->rr_float.rr_area - + resptr->rn_float.rn_area; - ResEliminateResistor(rr1,&ResResList); - ResEliminateResistor(rr2,&ResResList); - ResCleanNode(resptr,TRUE,&ResNodeList,&ResNodeQueue); - }else - { - status = SERIES; - resptr3 = rr2->rr_connection1; - rr1->rr_connection1 = rr2->rr_connection1; - ResFixRes(resptr,resptr2,resptr3,rr2,rr1); - } - if ((resptr2->rn_status & TRUE) == TRUE) - { - resptr2->rn_status &= ~TRUE; - ResDoneWithNode(resptr2); - } - resptr2 = NULL; - } - }else - { - if (rr2->rr_connection1 == resptr) - { - resptr2 = rr1->rr_connection1; - if (rr1->rr_connection1 == rr2->rr_connection2) - { - status = LOOP; - ResDeleteResPointer(rr1->rr_connection1,rr1); - ResDeleteResPointer(rr1->rr_connection2,rr1); - ResDeleteResPointer(rr2->rr_connection1,rr2); - ResDeleteResPointer(rr2->rr_connection2,rr2); - resptr2->rn_float.rn_area += rr1->rr_float.rr_area - + rr2->rr_float.rr_area - + resptr->rn_float.rn_area; - ResEliminateResistor(rr1,&ResResList); - ResEliminateResistor(rr2,&ResResList); - ResCleanNode(resptr,TRUE,&ResNodeList,&ResNodeQueue); - }else - { - status = SERIES; - resptr3 = rr2->rr_connection2; - rr1->rr_connection2 = - rr2->rr_connection2; - ResFixRes(resptr,resptr2,resptr3,rr2,rr1); - } - if ((resptr2->rn_status & TRUE) == TRUE) - { - resptr2->rn_status &= ~TRUE; - ResDoneWithNode(resptr2); - } - resptr2 = NULL; - }else - { - resptr2 = rr1->rr_connection1; - if (rr1->rr_connection1 == rr2->rr_connection1) - { - status = LOOP; - ResDeleteResPointer(rr1->rr_connection1,rr1); - ResDeleteResPointer(rr1->rr_connection2,rr1); - ResDeleteResPointer(rr2->rr_connection1,rr2); - ResDeleteResPointer(rr2->rr_connection2,rr2); - resptr2->rn_float.rn_area += rr1->rr_float.rr_area - + rr2->rr_float.rr_area - + resptr->rn_float.rn_area; - ResEliminateResistor(rr1,&ResResList); - ResEliminateResistor(rr2,&ResResList); - ResCleanNode(resptr,TRUE,&ResNodeList,&ResNodeQueue); - }else - { - status = SERIES; - resptr3 = rr2->rr_connection1; - rr1->rr_connection2 = - rr2->rr_connection1; - ResFixRes(resptr,resptr2,resptr3,rr2,rr1); - } - if ((resptr2->rn_status & TRUE) == TRUE) - { - resptr2->rn_status &= ~TRUE; - ResDoneWithNode(resptr2); - } - resptr2 = NULL; - } + ResEliminateResistor(rr1, &ResResList); + ResEliminateResistor(rr2, &ResResList); + ResCleanNode(resptr, TRUE, &ResNodeList, &ResNodeQueue); + } + else + { + status = SERIES; + resptr3 = rr2->rr_connection2; + rr1->rr_connection1 = rr2->rr_connection2; + ResFixRes(resptr, resptr2, resptr3, rr2, rr1); + } + if ((resptr2->rn_status & TRUE) == TRUE) + { + resptr2->rn_status &= ~TRUE; + ResDoneWithNode(resptr2); + } + resptr2 = NULL; } - } - } - return status; + else + { + resptr2 = rr1->rr_connection2; + if (rr1->rr_connection2 == rr2->rr_connection1) + { + status = LOOP; + ResDeleteResPointer(rr1->rr_connection1, rr1); + ResDeleteResPointer(rr1->rr_connection2, rr1); + ResDeleteResPointer(rr2->rr_connection1, rr2); + ResDeleteResPointer(rr2->rr_connection2, rr2); + resptr2->rn_float.rn_area += rr1->rr_float.rr_area + + rr2->rr_float.rr_area + + resptr->rn_float.rn_area; + ResEliminateResistor(rr1, &ResResList); + ResEliminateResistor(rr2, &ResResList); + ResCleanNode(resptr, TRUE, &ResNodeList, &ResNodeQueue); + } + else + { + status = SERIES; + resptr3 = rr2->rr_connection1; + rr1->rr_connection1 = rr2->rr_connection1; + ResFixRes(resptr, resptr2, resptr3, rr2, rr1); + } + if ((resptr2->rn_status & TRUE) == TRUE) + { + resptr2->rn_status &= ~TRUE; + ResDoneWithNode(resptr2); + } + resptr2 = NULL; + } + } + else + { + if (rr2->rr_connection1 == resptr) + { + resptr2 = rr1->rr_connection1; + if (rr1->rr_connection1 == rr2->rr_connection2) + { + status = LOOP; + ResDeleteResPointer(rr1->rr_connection1, rr1); + ResDeleteResPointer(rr1->rr_connection2, rr1); + ResDeleteResPointer(rr2->rr_connection1, rr2); + ResDeleteResPointer(rr2->rr_connection2, rr2); + resptr2->rn_float.rn_area += rr1->rr_float.rr_area + + rr2->rr_float.rr_area + + resptr->rn_float.rn_area; + ResEliminateResistor(rr1, &ResResList); + ResEliminateResistor(rr2, &ResResList); + ResCleanNode(resptr, TRUE, &ResNodeList, &ResNodeQueue); + } + else + { + status = SERIES; + resptr3 = rr2->rr_connection2; + rr1->rr_connection2 = rr2->rr_connection2; + ResFixRes(resptr, resptr2, resptr3, rr2, rr1); + } + if ((resptr2->rn_status & TRUE) == TRUE) + { + resptr2->rn_status &= ~TRUE; + ResDoneWithNode(resptr2); + } + resptr2 = NULL; + } + else + { + resptr2 = rr1->rr_connection1; + if (rr1->rr_connection1 == rr2->rr_connection1) + { + status = LOOP; + ResDeleteResPointer(rr1->rr_connection1, rr1); + ResDeleteResPointer(rr1->rr_connection2, rr1); + ResDeleteResPointer(rr2->rr_connection1, rr2); + ResDeleteResPointer(rr2->rr_connection2, rr2); + resptr2->rn_float.rn_area += rr1->rr_float.rr_area + + rr2->rr_float.rr_area + + resptr->rn_float.rn_area; + ResEliminateResistor(rr1, &ResResList); + ResEliminateResistor(rr2, &ResResList); + ResCleanNode(resptr, TRUE, &ResNodeList, &ResNodeQueue); + } + else + { + status = SERIES; + resptr3 = rr2->rr_connection1; + rr1->rr_connection2 = rr2->rr_connection1; + ResFixRes(resptr, resptr2, resptr3, rr2, rr1); + } + if ((resptr2->rn_status & TRUE) == TRUE) + { + resptr2->rn_status &= ~TRUE; + ResDoneWithNode(resptr2); + } + resptr2 = NULL; + } + } + } + } + return status; } - /* *------------------------------------------------------------------------- * @@ -414,49 +415,49 @@ ResSeriesCheck(resptr) int ResParallelCheck(resptr) - resNode *resptr; + resNode *resptr; { - resResistor *r1,*r2; - resNode *resptr2,*resptr3; - int status=UNTOUCHED; - resElement *rcell1,*rcell2; + resResistor *r1,*r2; + resNode *resptr2,*resptr3; + int status = UNTOUCHED; + resElement *rcell1, *rcell2; - for (rcell1 = resptr->rn_re; - rcell1->re_nextEl != NULL; rcell1 = rcell1->re_nextEl) - { - r1 = rcell1->re_thisEl; + for (rcell1 = resptr->rn_re; rcell1->re_nextEl != NULL; + rcell1 = rcell1->re_nextEl) + { + r1 = rcell1->re_thisEl; - for (rcell2 = rcell1->re_nextEl; - rcell2 != NULL; rcell2 = rcell2->re_nextEl) + for (rcell2 = rcell1->re_nextEl; rcell2 != NULL; + rcell2 = rcell2->re_nextEl) - { - r2 = rcell2->re_thisEl; - if (TTMaskHasType(ResNoMergeMask+r1->rr_tt,r2->rr_tt)) continue; - if (((r1->rr_connection1 == r2->rr_connection1) && - (r1->rr_connection2 == r2->rr_connection2))|| + { + r2 = rcell2->re_thisEl; + if (TTMaskHasType(ResNoMergeMask+r1->rr_tt,r2->rr_tt)) continue; + if (((r1->rr_connection1 == r2->rr_connection1) && + (r1->rr_connection2 == r2->rr_connection2))|| ((r1->rr_connection1 == r2->rr_connection2) && - (r1->rr_connection2 == r2->rr_connection1))) - { - resptr3 = (r1->rr_connection1 == resptr) ? + (r1->rr_connection2 == r2->rr_connection1))) + { + resptr3 = (r1->rr_connection1 == resptr) ? r1->rr_connection2 : r1->rr_connection1; - ResFixParallel(r1,r2); - status = PARALLEL; - resptr2 = NULL; - if (resptr3->rn_status & TRUE) - { - resptr2 = resptr3; - resptr2->rn_status &= ~TRUE; - } - ResDoneWithNode(resptr); - if (resptr2 != NULL) ResDoneWithNode(resptr2); - break; - } - } - if (status == PARALLEL) break; - } - return status; + ResFixParallel(r1, r2); + status = PARALLEL; + resptr2 = NULL; + if (resptr3->rn_status & TRUE) + { + resptr2 = resptr3; + resptr2->rn_status &= ~TRUE; + } + ResDoneWithNode(resptr); + if (resptr2 != NULL) ResDoneWithNode(resptr2); + break; + } + } + if (status == PARALLEL) break; + } + return status; } @@ -474,151 +475,143 @@ ResParallelCheck(resptr) int ResTriangleCheck(resptr) - resNode *resptr; + resNode *resptr; { - resResistor *rr1,*rr2,*rr3; - int status=UNTOUCHED; - float r1,r2,r3,denom; - resNode *n1,*n2,*n3; - resElement *rcell1,*rcell2,*rcell3,*element; + resResistor *rr1, *rr2, *rr3; + int status = UNTOUCHED; + float r1, r2, r3, denom; + resNode *n1, *n2, *n3; + resElement *rcell1, *rcell2, *rcell3, *element; - for (rcell1 = resptr->rn_re; - rcell1->re_nextEl != NULL; rcell1 = rcell1->re_nextEl) - { - rr1 = rcell1->re_thisEl; - n1 = (rr1->rr_connection1 == resptr)?rr1->rr_connection2: - rr1->rr_connection1; + for (rcell1 = resptr->rn_re; rcell1->re_nextEl != NULL; + rcell1 = rcell1->re_nextEl) + { + rr1 = rcell1->re_thisEl; + n1 = (rr1->rr_connection1 == resptr) ? rr1->rr_connection2: + rr1->rr_connection1; - for (rcell2 = rcell1->re_nextEl; - rcell2 != NULL; rcell2 = rcell2->re_nextEl) - { - rr2 = rcell2->re_thisEl; - if (TTMaskHasType(ResNoMergeMask + rr1->rr_tt, rr2->rr_tt)) - continue; - n2 = (rr2->rr_connection1 == resptr) ? rr2->rr_connection2 : + for (rcell2 = rcell1->re_nextEl; rcell2 != NULL; + rcell2 = rcell2->re_nextEl) + { + rr2 = rcell2->re_thisEl; + if (TTMaskHasType(ResNoMergeMask + rr1->rr_tt, rr2->rr_tt)) + continue; + n2 = (rr2->rr_connection1 == resptr) ? rr2->rr_connection2 : rr2->rr_connection1; - for (rcell3 = n1->rn_re; - rcell3 != NULL; rcell3 = rcell3->re_nextEl) - { - rr3 = rcell3->re_thisEl; - if (TTMaskHasType(ResNoMergeMask+rr1->rr_tt,rr3->rr_tt)) - continue; - if (TTMaskHasType(ResNoMergeMask+rr2->rr_tt,rr3->rr_tt)) - continue; + for (rcell3 = n1->rn_re; rcell3 != NULL; + rcell3 = rcell3->re_nextEl) + { + rr3 = rcell3->re_thisEl; + if (TTMaskHasType(ResNoMergeMask + rr1->rr_tt, rr3->rr_tt)) + continue; + if (TTMaskHasType(ResNoMergeMask + rr2->rr_tt, rr3->rr_tt)) + continue; - if (((rr3->rr_connection1 != n1) || - (rr3->rr_connection2 != n2)) && + if (((rr3->rr_connection1 != n1) || + (rr3->rr_connection2 != n2)) && ((rr3->rr_connection2 != n1) || - (rr3->rr_connection1 != n2))) continue; + (rr3->rr_connection1 != n2))) continue; - status = TRIANGLE; - if ((denom=rr1->rr_value+rr2->rr_value+rr3->rr_value) != 0.0) - { - denom = 1.0/denom; - /*calculate new values for resistors */ - r1 = (((float) rr1->rr_value)* - ((float) rr2->rr_value))*denom; + status = TRIANGLE; + if ((denom = rr1->rr_value + rr2->rr_value + rr3->rr_value) != 0.0) + { + denom = 1.0 /denom; + /* calculate new values for resistors */ + r1 = (((float)rr1->rr_value) * ((float)rr2->rr_value)) * denom; - r2 = (((float) rr2->rr_value)* - ((float) rr3->rr_value))*denom; + r2 = (((float)rr2->rr_value) * ((float)rr3->rr_value)) * denom; - r3 = (((float) rr1->rr_value)* - ((float) rr3->rr_value))*denom; + r3 = (((float)rr1->rr_value) * ((float)rr3->rr_value)) * denom; - rr1->rr_value = r1+0.5; - rr2->rr_value = r2+0.5; - rr3->rr_value = r3+0.5; - ASSERT(rr1->rr_value >= 0,"Triangle"); - ASSERT(rr2->rr_value >= 0,"Triangle"); - ASSERT(rr3->rr_value >= 0,"Triangle"); - } - else - { - rr1->rr_value = 0; - rr2->rr_value = 0; - rr3->rr_value = 0; - } - n3 = (resNode *) mallocMagic((unsigned) (sizeof(resNode))); - /* Where should the new node be `put'? It */ - /* is arbitrarily assigned to the location */ - /* occupied by the first node. */ + rr1->rr_value = r1 + 0.5; + rr2->rr_value = r2 + 0.5; + rr3->rr_value = r3 + 0.5; + ASSERT(rr1->rr_value >= 0, "Triangle"); + ASSERT(rr2->rr_value >= 0, "Triangle"); + ASSERT(rr3->rr_value >= 0, "Triangle"); + } + else + { + rr1->rr_value = 0; + rr2->rr_value = 0; + rr3->rr_value = 0; + } + n3 = (resNode *)mallocMagic((unsigned)(sizeof(resNode))); - InitializeNode(n3,resptr->rn_loc.p_x,resptr->rn_loc.p_y,TRIANGLE); - n3->rn_status = FINISHED | TRUE | MARKED; + /* Where should the new node be `put'? It */ + /* is arbitrarily assigned to the location */ + /* occupied by the first node. */ - n3->rn_less = NULL; - n3->rn_more = ResNodeList; - ResNodeList->rn_less = n3; - ResNodeList = n3; - if (resptr == rr1->rr_connection1) - { - ResDeleteResPointer(rr1->rr_connection2,rr1); - rr1->rr_connection2 = n3; - } - else - { - ResDeleteResPointer(rr1->rr_connection1,rr1); - rr1->rr_connection1 = n3; - } - if (n2 == rr2->rr_connection1) - { - ResDeleteResPointer(rr2->rr_connection2,rr2); - rr2->rr_connection2 = n3; - } - else - { - ResDeleteResPointer(rr2->rr_connection1,rr2); - rr2->rr_connection1 = n3; - } - if (n1 == rr3->rr_connection1) - { - ResDeleteResPointer(rr3->rr_connection2,rr3); - rr3->rr_connection2 = n3; - } - else - { - ResDeleteResPointer(rr3->rr_connection1,rr3); - rr3->rr_connection1 = n3; - } - element = (resElement *) mallocMagic((unsigned)(sizeof(resElement))); - element->re_nextEl = NULL; - element->re_thisEl = rr1; - n3->rn_re = element; - element = (resElement *) mallocMagic((unsigned)(sizeof(resElement))); - element->re_nextEl = n3->rn_re; - element->re_thisEl = rr2; - n3->rn_re = element; - element = (resElement *) mallocMagic((unsigned)(sizeof(resElement))); - element->re_nextEl = n3->rn_re; - element->re_thisEl = rr3; - n3->rn_re = element; - if ((n1->rn_status & TRUE) == TRUE) - { - n1->rn_status &= ~TRUE; - } - else - { - n1 = NULL; - } - if ((n2->rn_status & TRUE) == TRUE) - { - n2->rn_status &= ~TRUE; - } - else - { - n2 = NULL; - } - ResDoneWithNode(resptr); - if (n1 != NULL) ResDoneWithNode(n1); - if (n2 != NULL) ResDoneWithNode(n2); - break; - } - if (status == TRIANGLE) break; - } - if (status == TRIANGLE) break; - } - return status; + InitializeNode(n3, resptr->rn_loc.p_x, resptr->rn_loc.p_y, TRIANGLE); + n3->rn_status = FINISHED | TRUE | MARKED; + + n3->rn_less = NULL; + n3->rn_more = ResNodeList; + ResNodeList->rn_less = n3; + ResNodeList = n3; + if (resptr == rr1->rr_connection1) + { + ResDeleteResPointer(rr1->rr_connection2, rr1); + rr1->rr_connection2 = n3; + } + else + { + ResDeleteResPointer(rr1->rr_connection1, rr1); + rr1->rr_connection1 = n3; + } + if (n2 == rr2->rr_connection1) + { + ResDeleteResPointer(rr2->rr_connection2, rr2); + rr2->rr_connection2 = n3; + } + else + { + ResDeleteResPointer(rr2->rr_connection1, rr2); + rr2->rr_connection1 = n3; + } + if (n1 == rr3->rr_connection1) + { + ResDeleteResPointer(rr3->rr_connection2, rr3); + rr3->rr_connection2 = n3; + } + else + { + ResDeleteResPointer(rr3->rr_connection1, rr3); + rr3->rr_connection1 = n3; + } + element = (resElement *)mallocMagic((unsigned)(sizeof(resElement))); + element->re_nextEl = NULL; + element->re_thisEl = rr1; + n3->rn_re = element; + element = (resElement *)mallocMagic((unsigned)(sizeof(resElement))); + element->re_nextEl = n3->rn_re; + element->re_thisEl = rr2; + n3->rn_re = element; + element = (resElement *)mallocMagic((unsigned)(sizeof(resElement))); + element->re_nextEl = n3->rn_re; + element->re_thisEl = rr3; + n3->rn_re = element; + if ((n1->rn_status & TRUE) == TRUE) + n1->rn_status &= ~TRUE; + else + n1 = NULL; + + if ((n2->rn_status & TRUE) == TRUE) + n2->rn_status &= ~TRUE; + else + n2 = NULL; + + ResDoneWithNode(resptr); + if (n1 != NULL) ResDoneWithNode(n1); + if (n2 != NULL) ResDoneWithNode(n2); + break; + } + if (status == TRIANGLE) break; + } + if (status == TRIANGLE) break; + } + return status; } /* @@ -636,174 +629,156 @@ ResTriangleCheck(resptr) */ void -ResMergeNodes(node1,node2,pendingList,doneList) - resNode *node1,*node2,**pendingList,**doneList; +ResMergeNodes(node1, node2, pendingList, doneList) + resNode *node1, *node2; + resNode **pendingList, **doneList; +{ + resElement *workingRes, *tRes; + tElement *workingDev, *tDev; + jElement *workingJunc, *tJunc; + cElement *workingCon, *tCon; + Tile *tile; + int i; - { - resElement *workingRes,*tRes; - tElement *workingDev,*tDev; - jElement *workingJunc,*tJunc; - cElement *workingCon,*tCon; - Tile *tile; - int i; + /* sanity check */ + if (node1 == node2) return; - /* sanity check */ - if (node1 == node2) return; - if (node1 == NULL || node2 == NULL) - { - TxError("Attempt to merge NULL node\n"); - return; - } + if (node1 == NULL || node2 == NULL) + { + TxError("Attempt to merge NULL node\n"); + return; + } - /* don't want to merge away startpoint */ - if (node2->rn_why & RES_NODE_ORIGIN) - { - node1->rn_why = RES_NODE_ORIGIN; - } + /* don't want to merge away startpoint */ + if (node2->rn_why & RES_NODE_ORIGIN) + node1->rn_why = RES_NODE_ORIGIN; - /* set node resistance */ - if (node1->rn_noderes >node2->rn_noderes) - { - node1->rn_noderes = node2->rn_noderes; - if ((node1->rn_status & FINISHED) != FINISHED) - { - ResRemoveFromQueue(node1,pendingList); - ResAddToQueue(node1,pendingList); - } - } - node1->rn_float.rn_area += node2->rn_float.rn_area; + /* set node resistance */ + if (node1->rn_noderes > node2->rn_noderes) + { + node1->rn_noderes = node2->rn_noderes; + if ((node1->rn_status & FINISHED) != FINISHED) + { + ResRemoveFromQueue(node1, pendingList); + ResAddToQueue(node1, pendingList); + } + } + node1->rn_float.rn_area += node2->rn_float.rn_area; + /* combine relevant flags */ + node1->rn_status |= (node2->rn_status & RN_MAXTDI); - /* combine relevant flags */ - node1->rn_status |= (node2->rn_status & RN_MAXTDI); + /* merge device lists */ + workingDev = node2->rn_te; + while (workingDev != NULL) + { + if (workingDev->te_thist->rd_status & RES_DEV_PLUG) + { + ResPlug *plug = (ResPlug *) workingDev->te_thist; + if (plug->rpl_node == node2) + plug->rpl_node = node1; + else + { + TxError("Bad plug node: is (%d %d), should be (%d %d)\n", + plug->rpl_node->rn_loc, node2->rn_loc); + plug->rpl_node = NULL; + } + } + else + { + int j; - /*merge device lists */ - workingDev = node2->rn_te; - while (workingDev != NULL) - { - if (workingDev->te_thist->rd_status & RES_DEV_PLUG) - { - ResPlug *plug = (ResPlug *) workingDev->te_thist; - if (plug->rpl_node == node2) - { - plug->rpl_node = node1; - } - else - { - TxError("Bad plug node: is (%d %d), should be (%d %d)\n", - plug->rpl_node->rn_loc,node2->rn_loc); - plug->rpl_node = NULL; - } - } - else - { - int j; - - for (j = 0; j != workingDev->te_thist->rd_nterms; j++) + for (j = 0; j != workingDev->te_thist->rd_nterms; j++) if (workingDev->te_thist->rd_terminals[j] == node2) - { - workingDev->te_thist->rd_terminals[j] = node1; - } - } - tDev = workingDev; - workingDev = workingDev->te_nextt; - tDev->te_nextt = node1->rn_te; - node1->rn_te = tDev; - } + workingDev->te_thist->rd_terminals[j] = node1; + } + tDev = workingDev; + workingDev = workingDev->te_nextt; + tDev->te_nextt = node1->rn_te; + node1->rn_te = tDev; + } - /* append junction lists */ - workingJunc = node2->rn_je; - while (workingJunc != NULL) - { - tJunc = workingJunc; - for (i=0; irn_je; + while (workingJunc != NULL) + { + tJunc = workingJunc; + for (i = 0; i < TILES_PER_JUNCTION; i++) + { + tileJunk *junk; + + tile = tJunc->je_thisj->rj_Tile[i]; + junk = (tileJunk *) tile->ti_client; + + if ((junk->tj_status & RES_TILE_DONE) == FALSE) + ResFixBreakPoint(&junk->breakList, node2, node1); + } + tJunc->je_thisj->rj_jnode = node1; + workingJunc = workingJunc->je_nextj; + tJunc->je_nextj = node1->rn_je; + node1->rn_je = tJunc; + } + + /* Append connection lists */ + workingCon = node2->rn_ce; + while (workingCon != NULL) + { + tCon = workingCon; + for (i = 0; i < workingCon->ce_thisc->cp_currentcontact; i++) + { + if (workingCon->ce_thisc->cp_cnode[i] == node2) + { tileJunk *junk; - tile =tJunc->je_thisj->rj_Tile[i]; + workingCon->ce_thisc->cp_cnode[i] = node1; + tile =tCon->ce_thisc->cp_tile[i]; junk = (tileJunk *) tile->ti_client; - if ((junk->tj_status & RES_TILE_DONE) == FALSE) - { - ResFixBreakPoint(&junk->breakList,node2,node1); - } - } - tJunc->je_thisj->rj_jnode = node1; - workingJunc = workingJunc->je_nextj; - tJunc->je_nextj = node1->rn_je; - node1->rn_je = tJunc; - } + ResFixBreakPoint(&junk->breakList, node2, node1); + } + } + workingCon = workingCon->ce_nextc; + tCon->ce_nextc = node1->rn_ce; + node1->rn_ce = tCon; + } - /* Append connection lists */ - workingCon = node2->rn_ce; - while (workingCon != NULL) - { - tCon = workingCon; - for (i=0; i ce_thisc->cp_currentcontact;i++) - { - if (workingCon->ce_thisc->cp_cnode[i] == node2) - { - tileJunk *junk; + /* Moves resistors to new node */ - workingCon->ce_thisc->cp_cnode[i] = node1; - tile =tCon->ce_thisc->cp_tile[i]; - junk = (tileJunk *) tile->ti_client; - if ((junk->tj_status & RES_TILE_DONE) == FALSE) - { - ResFixBreakPoint(&junk->breakList,node2,node1); - } - } - } - workingCon = workingCon->ce_nextc; - tCon->ce_nextc = node1->rn_ce; - node1->rn_ce = tCon; - } + workingRes = node2->rn_re; + while (workingRes != NULL) + { + if (workingRes->re_thisEl->rr_connection1 == node2) + workingRes->re_thisEl->rr_connection1 = node1; + else if (workingRes->re_thisEl->rr_connection2 == node2) + workingRes->re_thisEl->rr_connection2 = node1; + else + TxError("Resistor not found.\n"); - /* Moves resistors to new node */ - workingRes = node2->rn_re; - while (workingRes != NULL) - { - if (workingRes->re_thisEl->rr_connection1 == node2) - { - workingRes->re_thisEl->rr_connection1 = node1; - } - else if (workingRes->re_thisEl->rr_connection2 == node2) - { - workingRes->re_thisEl->rr_connection2 = node1; - } - else - { - TxError("Resistor not found.\n"); - } - tRes = workingRes; - workingRes = workingRes->re_nextEl; - tRes->re_nextEl = node1->rn_re; - node1->rn_re = tRes; - } - if ((node2->rn_status & FINISHED) == FINISHED) - { - ResRemoveFromQueue(node2,doneList); - } - else - { - ResRemoveFromQueue(node2,pendingList); - } - if (node2->rn_client != (ClientData)NULL) - { - freeMagic((char *)node2->rn_client); - node2->rn_client = (ClientData)NULL; - } - { - node2->rn_re = (resElement *) CLIENTDEFAULT; - node2->rn_ce = (cElement *) CLIENTDEFAULT; - node2->rn_je = (jElement *) CLIENTDEFAULT; - node2->rn_te = (tElement *) CLIENTDEFAULT; - node2->rn_more = (resNode *) CLIENTDEFAULT; - node2->rn_less = (resNode *) CLIENTDEFAULT; - } - freeMagic((char *)node2); - } + tRes = workingRes; + workingRes = workingRes->re_nextEl; + tRes->re_nextEl = node1->rn_re; + node1->rn_re = tRes; + } + if ((node2->rn_status & FINISHED) == FINISHED) + ResRemoveFromQueue(node2, doneList); + else + ResRemoveFromQueue(node2, pendingList); + if (node2->rn_client != (ClientData)NULL) + { + freeMagic((char *)node2->rn_client); + node2->rn_client = (ClientData)NULL; + } + + node2->rn_re = (resElement *)CLIENTDEFAULT; + node2->rn_ce = (cElement *)CLIENTDEFAULT; + node2->rn_je = (jElement *)CLIENTDEFAULT; + node2->rn_te = (tElement *)CLIENTDEFAULT; + node2->rn_more = (resNode *)CLIENTDEFAULT; + node2->rn_less = (resNode *)CLIENTDEFAULT; + freeMagic((char *)node2); +} /* *------------------------------------------------------------------------- @@ -820,42 +795,38 @@ ResMergeNodes(node1,node2,pendingList,doneList) void ResDeleteResPointer(node,resistor) - resNode *node; - resResistor *resistor; + resNode *node; + resResistor *resistor; { - resElement *rcell1,*rcell2; - int notfound=TRUE; + resElement *rcell1, *rcell2; + int notfound = TRUE; - rcell1 = NULL; - rcell2 = node->rn_re; - while (rcell2 != NULL) - { - if (rcell2->re_thisEl == resistor) - { - notfound=FALSE; - if (rcell1 != NULL) - { - rcell1->re_nextEl = rcell2->re_nextEl; - }else - { - node->rn_re = rcell2->re_nextEl; - } - /* Set fields to null just in case there are any stray */ - /* pointers to structure. */ - rcell2->re_thisEl = NULL; - rcell2->re_nextEl = NULL; - freeMagic((char *)rcell2); - break; - } - rcell1 = rcell2; - rcell2 = rcell2->re_nextEl; - } - if (notfound) - { - TxError("Missing rptr at (%d %d).\n", - node->rn_loc.p_x,node->rn_loc.p_y); - } + rcell1 = NULL; + rcell2 = node->rn_re; + while (rcell2 != NULL) + { + if (rcell2->re_thisEl == resistor) + { + notfound = FALSE; + if (rcell1 != NULL) + rcell1->re_nextEl = rcell2->re_nextEl; + else + node->rn_re = rcell2->re_nextEl; + + /* Set fields to null just in case there are any stray */ + /* pointers to structure. */ + rcell2->re_thisEl = NULL; + rcell2->re_nextEl = NULL; + freeMagic((char *)rcell2); + break; + } + rcell1 = rcell2; + rcell2 = rcell2->re_nextEl; + } + if (notfound) + TxError("Missing rptr at (%d %d).\n", + node->rn_loc.p_x, node->rn_loc.p_y); } @@ -873,32 +844,28 @@ ResDeleteResPointer(node,resistor) */ void -ResEliminateResistor(resistor,homelist) - resResistor *resistor,**homelist; +ResEliminateResistor(resistor, homelist) + resResistor *resistor, **homelist; { - if (resistor->rr_lastResistor == NULL) - { - *homelist = resistor->rr_nextResistor; - }else - { - resistor->rr_lastResistor->rr_nextResistor = resistor->rr_nextResistor; - } - if (resistor->rr_nextResistor != NULL) - { - resistor->rr_nextResistor->rr_lastResistor = resistor->rr_lastResistor; - } + if (resistor->rr_lastResistor == NULL) + *homelist = resistor->rr_nextResistor; + else + resistor->rr_lastResistor->rr_nextResistor = resistor->rr_nextResistor; - /* set everything to null so that any stray pointers will cause */ - /* immediate death instead of a slow lingering one. */ - resistor->rr_nextResistor = NULL; - resistor->rr_lastResistor = NULL; - resistor->rr_connection1 = NULL; - resistor->rr_connection2 = NULL; - freeMagic((char *)resistor); + if (resistor->rr_nextResistor != NULL) + resistor->rr_nextResistor->rr_lastResistor = resistor->rr_lastResistor; + + /* set everything to null so that any stray pointers will cause */ + /* immediate death instead of a slow lingering one. */ + + resistor->rr_nextResistor = NULL; + resistor->rr_lastResistor = NULL; + resistor->rr_connection1 = NULL; + resistor->rr_connection2 = NULL; + freeMagic((char *)resistor); } - /* *------------------------------------------------------------------------- * @@ -915,83 +882,73 @@ ResEliminateResistor(resistor,homelist) */ void -ResCleanNode(resptr,junk,homelist1,homelist2) - resNode *resptr; - int junk; - resNode **homelist1; - resNode **homelist2; +ResCleanNode(resptr, junk, homelist1, homelist2) + resNode *resptr; + int junk; + resNode **homelist1; + resNode **homelist2; { - resElement *rcell; - cElement *ccell; - jElement *jcell; - tElement *tcell; + resElement *rcell; + cElement *ccell; + jElement *jcell; + tElement *tcell; - /* free up contact and junction lists */ - while (resptr->rn_ce != NULL) - { - ccell = resptr->rn_ce; - resptr->rn_ce = resptr->rn_ce->ce_nextc; - freeMagic((char *)ccell); - } - while (resptr->rn_je != NULL) - { - jcell = resptr->rn_je; - resptr->rn_je = resptr->rn_je->je_nextj; - freeMagic((char *)jcell->je_thisj); - freeMagic((char *)jcell); - } - if (junk == TRUE) - { - if (resptr->rn_client != (ClientData)NULL) - { - freeMagic((char *)resptr->rn_client); - resptr->rn_client = (ClientData)NULL; - } - while (resptr->rn_te != NULL) - { - tcell = resptr->rn_te; - resptr->rn_te = resptr->rn_te->te_nextt; - freeMagic((char *)tcell); - } - while (resptr->rn_re != NULL) - { - rcell = resptr->rn_re; - resptr->rn_re = resptr->rn_re->re_nextEl; - freeMagic((char *)rcell); - } - if (resptr->rn_less != NULL) - { - resptr->rn_less->rn_more = resptr->rn_more; - }else - { - if (*homelist1 == resptr) - { - *homelist1 = resptr->rn_more; - } - else if (*homelist2 == resptr) - { - *homelist2 = resptr->rn_more; - } - else - { - TxError("Error: Attempted to eliminate node from wrong list.\n"); - } - } - if (resptr->rn_more != NULL) - { - resptr->rn_more->rn_less = resptr->rn_less; - } + /* free up contact and junction lists */ + while (resptr->rn_ce != NULL) + { + ccell = resptr->rn_ce; + resptr->rn_ce = resptr->rn_ce->ce_nextc; + freeMagic((char *)ccell); + } + while (resptr->rn_je != NULL) + { + jcell = resptr->rn_je; + resptr->rn_je = resptr->rn_je->je_nextj; + freeMagic((char *)jcell->je_thisj); + freeMagic((char *)jcell); + } + if (junk == TRUE) + { + if (resptr->rn_client != (ClientData)NULL) + { + freeMagic((char *)resptr->rn_client); + resptr->rn_client = (ClientData)NULL; + } + while (resptr->rn_te != NULL) + { + tcell = resptr->rn_te; + resptr->rn_te = resptr->rn_te->te_nextt; + freeMagic((char *)tcell); + } + while (resptr->rn_re != NULL) + { + rcell = resptr->rn_re; + resptr->rn_re = resptr->rn_re->re_nextEl; + freeMagic((char *)rcell); + } + if (resptr->rn_less != NULL) + resptr->rn_less->rn_more = resptr->rn_more; + else + { + if (*homelist1 == resptr) + *homelist1 = resptr->rn_more; + else if (*homelist2 == resptr) + *homelist2 = resptr->rn_more; + else + TxError("Error: Attempted to eliminate node from wrong list.\n"); + } + if (resptr->rn_more != NULL) + resptr->rn_more->rn_less = resptr->rn_less; - { - resptr->rn_re = (resElement *) CLIENTDEFAULT; - resptr->rn_ce = (cElement *) CLIENTDEFAULT; - resptr->rn_je = (jElement *) CLIENTDEFAULT; - resptr->rn_te = (tElement *) CLIENTDEFAULT; - resptr->rn_more = (resNode *) CLIENTDEFAULT; - resptr->rn_less = (resNode *) CLIENTDEFAULT; - } - freeMagic((char *)resptr); - } + resptr->rn_re = (resElement *) CLIENTDEFAULT; + resptr->rn_ce = (cElement *) CLIENTDEFAULT; + resptr->rn_je = (jElement *) CLIENTDEFAULT; + resptr->rn_te = (tElement *) CLIENTDEFAULT; + resptr->rn_more = (resNode *) CLIENTDEFAULT; + resptr->rn_less = (resNode *) CLIENTDEFAULT; + + freeMagic((char *)resptr); + } } @@ -1010,54 +967,49 @@ ResCleanNode(resptr,junk,homelist1,homelist2) */ void -ResFixBreakPoint(sourcelist,origNode,newNode) - Breakpoint **sourcelist; - resNode *origNode,*newNode; +ResFixBreakPoint(sourcelist, origNode, newNode) + Breakpoint **sourcelist; + resNode *origNode, *newNode; { - Breakpoint *bp,*bp2,*bp3,*bp4; - int alreadypresent; + Breakpoint *bp, *bp2, *bp3, *bp4; + int alreadypresent; - alreadypresent = FALSE; - for (bp4 = *sourcelist; bp4 != NULL; bp4 = bp4->br_next) - { - if (bp4->br_this == newNode) - { - alreadypresent = TRUE; - break; - } - } - bp2 = NULL; - bp = *sourcelist; - while (bp != NULL) - { - if (bp->br_this == origNode) - { - if (alreadypresent) - { - if (bp2 == NULL) - { - *sourcelist = bp->br_next; - }else - { - bp2->br_next = bp->br_next; - } - bp3 = bp; - bp = bp->br_next; + alreadypresent = FALSE; + for (bp4 = *sourcelist; bp4 != NULL; bp4 = bp4->br_next) + { + if (bp4->br_this == newNode) + { + alreadypresent = TRUE; + break; + } + } + bp2 = NULL; + bp = *sourcelist; + while (bp != NULL) + { + if (bp->br_this == origNode) + { + if (alreadypresent) + { + if (bp2 == NULL) + *sourcelist = bp->br_next; + else + bp2->br_next = bp->br_next; - if (bp3->br_crect != NULL && bp4->br_crect == NULL) - { - bp4->br_crect = bp3->br_crect; - } - freeMagic((char *)bp3); - continue; - }else - { - (bp->br_this = newNode); - } - } - bp2 = bp; - bp = bp->br_next; - } + bp3 = bp; + bp = bp->br_next; + if (bp3->br_crect != NULL && bp4->br_crect == NULL) + bp4->br_crect = bp3->br_crect; + + freeMagic((char *)bp3); + continue; + } + else + bp->br_this = newNode; + } + bp2 = bp; + bp = bp->br_next; + } } diff --git a/resis/ResPrint.c b/resis/ResPrint.c index a2dc6b8e..48eb8192 100644 --- a/resis/ResPrint.c +++ b/resis/ResPrint.c @@ -171,16 +171,25 @@ ResPrintExtDev(outextfile, devices) else fprintf(outextfile, " \"%s\"", subsName); - fprintf(outextfile, " \"%s\" %d %s \"%s\" %d %s \"%s\" %d %s\n", - devices->gate->name, - devices->layout->rd_length * 2, - devices->rs_gattr, - devices->source->name, - devices->layout->rd_width, - devices->rs_sattr, - devices->drain->name, - devices->layout->rd_width, - devices->rs_dattr); + if (devices->gate != NULL) + fprintf(outextfile, " \"%s\" %d %s", + devices->gate->name, + devices->layout->rd_length * 2, + devices->rs_gattr); + + if (devices->source != NULL) + fprintf(outextfile, " \"%s\" %d %s", + devices->source->name, + devices->layout->rd_width, + devices->rs_sattr); + + if (devices->drain != NULL) + fprintf(outextfile, " \"%s\" %d %s", + devices->drain->name, + devices->layout->rd_width, + devices->rs_dattr); + + fprintf(outextfile, "\n"); } } } diff --git a/resis/ResReadSim.c b/resis/ResReadSim.c index 3d31f0bb..a969404d 100644 --- a/resis/ResReadSim.c +++ b/resis/ResReadSim.c @@ -92,12 +92,12 @@ ResFixPoint *ResFixList; ResNodeList = n;\ (n)->rn_te = NULL;\ (n)->rn_re = NULL;\ - (n)->rn_je=NULL;\ - (n)->rn_ce=NULL;\ - (n)->rn_noderes=RES_INFINITY;\ - (n)->location.p_x=MINFINITY;\ - (n)->location.p_y=MINFINITY;\ - (n)->rn_why=0;\ + (n)->rn_je = NULL;\ + (n)->rn_ce = NULL;\ + (n)->rn_noderes = RES_INFINITY;\ + (n)->location.p_x = MINFINITY;\ + (n)->location.p_y = MINFINITY;\ + (n)->rn_why = 0;\ (n)->rn_status = TRUE;\ } @@ -105,7 +105,6 @@ ResFixPoint *ResFixList; extern void ResSimProcessDrivePoints(); - /* *------------------------------------------------------------------------- * @@ -120,93 +119,104 @@ extern void ResSimProcessDrivePoints(); int ResReadSim(simfile, fetproc, capproc, resproc, attrproc, mergeproc, subproc) - char *simfile; - int (*fetproc)(), (*capproc)(), (*resproc)(); - int (*attrproc)(), (*mergeproc)(), (*subproc)(); + char *simfile; + int (*fetproc)(), (*capproc)(), (*resproc)(); + int (*attrproc)(), (*mergeproc)(), (*subproc)(); { - char line[MAXLINE][MAXTOKEN]; - int result,fettype,extfile; - FILE *fp, *fopen(); + char line[MAXLINE][MAXTOKEN]; + int result, fettype, extfile; + FILE *fp, *fopen(); - fp = PaOpen(simfile,"r",".sim",".",(char *) NULL, (char **) NULL); - if (fp == NULL) - { - TxError("Cannot open file %s%s\n",simfile,".sim"); - return(1); - } - extfile = 0; + fp = PaOpen(simfile, "r", ".sim", ".", (char *)NULL, (char **)NULL); + if (fp == NULL) + { + TxError("Cannot open file %s%s\n", simfile, ".sim"); + return 1; + } + extfile = 0; - /*read in file */ - while (gettokens(line,fp) != 0) - { - fettype = MINFINITY; - switch(line[0][0]) - { - case '|': - if (strcmp(line[NODEUNITS],"units:") == 0) - { - resscale = (float)atof(line[NODELAMBDA]); - if (resscale == 0.0) resscale = 1.0; - } - result=0; - break; - case 'e': fettype = DBTechNameType("efet"); - break; - case 'd': fettype = DBTechNameType("dfet"); - break; - case 'n': fettype = DBTechNameType("nfet"); - break; - case 'p': fettype = DBTechNameType("pfet"); - break; - case 'b': fettype = DBTechNameType("bnpn"); - break; - case 'C': if (capproc) result = (*capproc)(line); - break; - case 'R': if (resproc)result = (*resproc)(line); - break; - case '=': if (mergeproc)result = (*mergeproc)(line); - break; - case 'A': if (attrproc) result = - (*attrproc)(line[ATTRIBUTENODENAME], - line[ATTRIBUTEVALUE], - simfile, &extfile); - break; - case 'x': fettype = DBNumTypes; - break; - case 'D': - case 'c': - case 'r': break; - default: result = 1; - (void)fclose(fp); - break; - } - if (fettype == -1) - { - TxError("Error in Reading device line of sim file.\n"); - result = 1; - } - else if (fettype == DBNumTypes) - { - result = (*subproc)(line); - } - else if (fettype != MINFINITY) - { - float sheetr; - ExtDevice *devptr; + /* Read in file */ + while (gettokens(line, fp) != 0) + { + fettype = MINFINITY; + switch(line[0][0]) + { + case '|': + if (strcmp(line[NODEUNITS],"units:") == 0) + { + resscale = (float)atof(line[NODELAMBDA]); + if (resscale == 0.0) resscale = 1.0; + } + result=0; + break; + case 'e': + fettype = DBTechNameType("efet"); + break; + case 'd': + fettype = DBTechNameType("dfet"); + break; + case 'n': + fettype = DBTechNameType("nfet"); + break; + case 'p': + fettype = DBTechNameType("pfet"); + break; + case 'b': + fettype = DBTechNameType("bnpn"); + break; + case 'C': + if (capproc) result = (*capproc)(line); + break; + case 'R': + if (resproc) result = (*resproc)(line); + break; + case '=': + if (mergeproc) result = (*mergeproc)(line); + break; + case 'A': + if (attrproc) + result = (*attrproc)(line[ATTRIBUTENODENAME], + line[ATTRIBUTEVALUE], simfile, &extfile); + break; + case 'x': + fettype = DBNumTypes; + break; + case 'D': + case 'c': + case 'r': + break; + default: + result = 1; + fclose(fp); + break; + } + if (fettype == -1) + { + TxError("Error in Reading device line of sim file.\n"); + result = 1; + } + else if (fettype == DBNumTypes) + { + result = (*subproc)(line); + } + else if (fettype != MINFINITY) + { + float sheetr; + ExtDevice *devptr; - devptr = ExtCurStyle->exts_device[fettype]; - sheetr=(float)devptr->exts_linearResist; - result = (*fetproc)(line,sheetr,fettype); - } - if (result != 0) - { - TxError("Error in sim file %s\n",line[0]); - return(1); - } - } - (void)fclose(fp); - return(result); + devptr = ExtCurStyle->exts_device[fettype]; + sheetr = (float)devptr->exts_linearResist; + result = (*fetproc)(line, sheetr, fettype); + } + if (result != 0) + { + TxError("Error in sim file %s\n", line[0]); + return 1; + } + } + fclose(fp); + return(result); } @@ -225,8 +235,7 @@ ResReadSim(simfile, fetproc, capproc, resproc, attrproc, mergeproc, subproc) int ResReadNode(nodefile) - char *nodefile; - + char *nodefile; { char line[MAXLINE][MAXTOKEN]; FILE *fp, *fopen(); @@ -235,15 +244,15 @@ ResReadNode(nodefile) char *cp; float lambda; - fp = PaOpen(nodefile,"r",".nodes",".", (char *) NULL, (char **) NULL); + fp = PaOpen(nodefile, "r", ".nodes", ".", (char *)NULL, (char **)NULL); if (fp == NULL) { - TxError("Cannot open file %s%s\n",nodefile,".nodes"); - return(1); + TxError("Cannot open file %s%s\n", nodefile, ".nodes"); + return 1; } while (gettokens(line,fp) != 0) { - entry = HashFind(&ResNodeTable,line[NODES_NODENAME]); + entry = HashFind(&ResNodeTable, line[NODES_NODENAME]); node = ResInitializeNode(entry); node->location.p_x = atoi(line[NODES_NODEX]); @@ -259,14 +268,15 @@ ResReadNode(nodefile) if (node->type == -1) { - TxError("Bad tile type name in %s.nodes file for node %s\n",nodefile,node->name); + TxError("Bad tile type name in %s.nodes file for node %s\n", + nodefile, node->name); TxError("Did you use the newest version of ext2sim?\n"); - (void)fclose(fp); - return(1); + fclose(fp); + return 1; } } - (void)fclose(fp); - return(0); + fclose(fp); + return 0; } /* @@ -283,39 +293,38 @@ ResReadNode(nodefile) */ int -gettokens(line,fp) - char line[][MAXTOKEN]; - FILE *fp; - +gettokens(line, fp) + char line[][MAXTOKEN]; + FILE *fp; { - int i=0,j=0; - int c; + int i = 0, j = 0; + int c; - while ((c = getc(fp)) != EOF && c != '\n') - { - switch(c) - { - case ' ': - case ' ' : line[i++][j] = '\0'; - j=0; - break; - default: line[i][j++] = c; - break; - } - } - if (c == '\n') - { - line[i++][j] = '\0'; - j=0; - } - for(j=i;j < MAXLINE;j++) - { - line[j][0] = '\0'; - } - return(i); + while ((c = getc(fp)) != EOF && c != '\n') + { + switch(c) + { + case ' ': + case ' ' : + line[i++][j] = '\0'; + j = 0; + break; + default: + line[i][j++] = c; + break; + } + } + if (c == '\n') + { + line[i++][j] = '\0'; + j = 0; + } + for (j = i; j < MAXLINE; j++) + line[j][0] = '\0'; + + return i; } - /* *------------------------------------------------------------------------- * @@ -359,6 +368,7 @@ ResSimSubckt(line) ResRDevList = device; device->layout = NULL; + device->source = device->drain = device->gate = device->subs = NULL; /* The last argument is the name of the device */ for (i = 1; line[i][0] != '\0'; i++); @@ -460,97 +470,106 @@ ResSimSubckt(line) int ResSimDevice(line, rpersquare, ttype) - char line[][MAXTOKEN]; - float rpersquare; - TileType ttype; + char line[][MAXTOKEN]; + float rpersquare; + TileType ttype; { - RDev *device; - int rvalue,i,j,k; - char *newattr,tmpattr[MAXTOKEN]; - static int nowarning = TRUE; - float lambda; + RDev *device; + int rvalue, i, j, k; + char *newattr, tmpattr[MAXTOKEN]; + static int nowarning = TRUE; + float lambda; - device = (RDev *) mallocMagic((unsigned) (sizeof(RDev))); - if ((line[RDEV_WIDTH][0] == '\0') || (line[RDEV_LENGTH][0] == '\0')) - { + if ((line[RDEV_WIDTH][0] == '\0') || (line[RDEV_LENGTH][0] == '\0')) + { TxError("error in input file:\n"); - return(1); - } - else - { - if (nowarning && rpersquare == 0) - { - TxError("Warning- FET resistance not included or set to zero in technology file-\n"); - TxError("All driven nodes will be extracted\n"); - nowarning = FALSE; - } - if (MagAtof(line[RDEV_WIDTH]) != 0) - device->resistance = MagAtof(line[RDEV_LENGTH]) * rpersquare/MagAtof(line[RDEV_WIDTH]); - else - device->resistance = 0; - } - device->status = FALSE; - device->nextDev = ResRDevList; + return 1; + } - lambda = (float)ExtCurStyle->exts_unitsPerLambda / resscale; - device->location.p_x = (int)((float)atof(line[RDEV_DEVX]) / lambda); - device->location.p_y = (int)((float)atof(line[RDEV_DEVY]) / lambda); + device = (RDev *)mallocMagic((unsigned)(sizeof(RDev))); + if (nowarning && rpersquare == 0) + { + TxError("Warning: FET resistance not included or " + "set to zero in technology file-\n"); + TxError("All driven nodes will be extracted\n"); + nowarning = FALSE; + } + if (MagAtof(line[RDEV_WIDTH]) != 0) + device->resistance = MagAtof(line[RDEV_LENGTH]) * rpersquare / + MagAtof(line[RDEV_WIDTH]); + else + device->resistance = 0; - device->rs_gattr=RDEV_NOATTR; - device->rs_sattr=RDEV_NOATTR; - device->rs_dattr=RDEV_NOATTR; - device->rs_ttype = ttype; + device->status = FALSE; + device->nextDev = ResRDevList; - /* sim attributes look like g=a1,a2 */ - /* ext attributes are "a1","a2" */ - /* do conversion from one to the other here */ + lambda = (float)ExtCurStyle->exts_unitsPerLambda / resscale; + device->location.p_x = (int)((float)atof(line[RDEV_DEVX]) / lambda); + device->location.p_y = (int)((float)atof(line[RDEV_DEVY]) / lambda); - for (i=RDEV_ATTR;i < RDEV_ATTR+RDEV_NUM_ATTR;i++) - { - if (line[i][0] == '\0') break; - k=0; - tmpattr[k++]='"'; - for (j=2;line[i][j] != '\0';j++) - { - if (line[i][j] == ',') - { - tmpattr[k++] = '"'; - tmpattr[k++] = ','; - tmpattr[k++] = '"'; - } - else - { - tmpattr[k++] = line[i][j]; - } - } - tmpattr[k++]='"'; - tmpattr[k++]='\0'; - newattr = (char *) mallocMagic((unsigned) k); - strncpy(newattr,tmpattr,k); - switch (line[i][0]) - { - case 'g': device->rs_gattr = newattr; break; - case 's': device->rs_sattr = newattr; break; - case 'd': device->rs_dattr = newattr; break; - default: TxError("Bad fet attribute\n"); - break; - } - } - ResRDevList = device; - device->layout = NULL; - rvalue = ResSimNewNode(line[GATE],GATE,device) + - ResSimNewNode(line[SOURCE],SOURCE,device) + - ResSimNewNode(line[DRAIN],DRAIN,device); + device->rs_gattr=RDEV_NOATTR; + device->rs_sattr=RDEV_NOATTR; + device->rs_dattr=RDEV_NOATTR; + device->rs_ttype = ttype; - return(rvalue); + device->gate = device->source = device->drain = device->subs = NULL; + + /* sim attributes look like g=a1,a2 */ + /* ext attributes are "a1","a2" */ + /* do conversion from one to the other here */ + + for (i = RDEV_ATTR; i < RDEV_ATTR + RDEV_NUM_ATTR; i++) + { + if (line[i][0] == '\0') break; + k = 0; + tmpattr[k++] = '"'; + for (j = 2; line[i][j] != '\0'; j++) + { + if (line[i][j] == ',') + { + tmpattr[k++] = '"'; + tmpattr[k++] = ','; + tmpattr[k++] = '"'; + } + else + { + tmpattr[k++] = line[i][j]; + } + } + tmpattr[k++] = '"'; + tmpattr[k++] = '\0'; + newattr = (char *)mallocMagic((unsigned)k); + strncpy(newattr, tmpattr, k); + switch (line[i][0]) + { + case 'g': + device->rs_gattr = newattr; + break; + case 's': + device->rs_sattr = newattr; + break; + case 'd': + device->rs_dattr = newattr; + break; + default: + TxError("Bad fet attribute\n"); + break; + } + } + ResRDevList = device; + device->layout = NULL; + rvalue = ResSimNewNode(line[GATE], GATE, device) + + ResSimNewNode(line[SOURCE], SOURCE, device) + + ResSimNewNode(line[DRAIN], DRAIN, device); + + return rvalue; } - /* *------------------------------------------------------------------------- * - * ResSimNewNode-- Adds a new node to the Node Hash Table. + * ResSimNewNode-- Adds a new node to the Node Hash Table. * * Results: returns zero if node is added correctly, one otherwise. * @@ -561,44 +580,48 @@ ResSimDevice(line, rpersquare, ttype) int ResSimNewNode(line, type, device) - char line[]; - int type; - RDev *device; + char line[]; + int type; + RDev *device; { - HashEntry *entry; - ResSimNode *node; - devPtr *tptr; + HashEntry *entry; + ResSimNode *node; + devPtr *tptr; - if (line[0] == '\0') - { - TxError("Missing device connection\n"); - return(1); - } - entry = HashFind(&ResNodeTable, line); - node = ResInitializeNode(entry); - tptr = (devPtr *) mallocMagic((unsigned) (sizeof(devPtr))); - tptr->thisDev = device; - tptr->nextDev = node->firstDev; - node->firstDev = tptr; - tptr->terminal = type; - switch(type) - { - case GATE: device->gate = node; - break; - case SOURCE: device->source = node; - break; - case DRAIN: device->drain = node; - break; - case SUBS: device->subs = node; - break; - default: TxError("Bad Terminal Specifier\n"); - break; - } - return(0); + if (line[0] == '\0') + { + TxError("Missing device connection\n"); + return 1; + } + entry = HashFind(&ResNodeTable, line); + node = ResInitializeNode(entry); + tptr = (devPtr *)mallocMagic((unsigned)(sizeof(devPtr))); + tptr->thisDev = device; + tptr->nextDev = node->firstDev; + node->firstDev = tptr; + tptr->terminal = type; + switch(type) + { + case GATE: + device->gate = node; + break; + case SOURCE: + device->source = node; + break; + case DRAIN: + device->drain = node; + break; + case SUBS: + device->subs = node; + break; + default: + TxError("Bad Terminal Specifier\n"); + break; + } + return 0; } - /* *------------------------------------------------------------------------- * @@ -616,58 +639,57 @@ ResSimNewNode(line, type, device) int ResSimCapacitor(line) - char line[][MAXTOKEN]; + char line[][MAXTOKEN]; { - HashEntry *entry1,*entry2; - ResSimNode *node1,*node2; - - if (line[COUPLETERMINAL1][0] == 0 || line[COUPLETERMINAL2][0] == 0) - { - TxError("Bad Capacitor\n"); - return(1); - } - entry1 = HashFind(&ResNodeTable,line[COUPLETERMINAL1]); - node1 = ResInitializeNode(entry1); - if (ResOptionsFlags & ResOpt_Signal) - { - node1->capacitance += MagAtof(line[COUPLEVALUE]); - if (strcmp(line[COUPLETERMINAL2],"GND") == 0 || - strcmp(line[COUPLETERMINAL2],"Vdd") == 0) - { - return(0); - } - entry2 = HashFind(&ResNodeTable,line[COUPLETERMINAL2]); - node2 = ResInitializeNode(entry2); - node2->capacitance += MagAtof(line[COUPLEVALUE]); - return(0); - } - if (strcmp(line[COUPLETERMINAL2],"GND") == 0 ) - { - node1->capacitance += MagAtof(line[COUPLEVALUE]); - return(0); - } - if (strcmp(line[COUPLETERMINAL2],"Vdd") == 0 ) - { - node1->cap_vdd += MagAtof(line[COUPLEVALUE]); - return(0); - } - entry2 = HashFind(&ResNodeTable,line[COUPLETERMINAL2]); - node2 = ResInitializeNode(entry2); - if (strcmp(line[COUPLETERMINAL1],"GND") == 0 ) - { - node2->capacitance += MagAtof(line[COUPLEVALUE]); - return(0); - } - if (strcmp(line[COUPLETERMINAL1],"Vdd") == 0 ) - { - node2->cap_vdd += MagAtof(line[COUPLEVALUE]); - return(0); - } - node1->cap_couple += MagAtof(line[COUPLEVALUE]); - node2->cap_couple += MagAtof(line[COUPLEVALUE]); - return(0); + HashEntry *entry1, *entry2; + ResSimNode *node1, *node2; + if (line[COUPLETERMINAL1][0] == 0 || line[COUPLETERMINAL2][0] == 0) + { + TxError("Bad Capacitor\n"); + return(1); + } + entry1 = HashFind(&ResNodeTable, line[COUPLETERMINAL1]); + node1 = ResInitializeNode(entry1); + if (ResOptionsFlags & ResOpt_Signal) + { + node1->capacitance += MagAtof(line[COUPLEVALUE]); + if (strcmp(line[COUPLETERMINAL2], "GND") == 0 || + strcmp(line[COUPLETERMINAL2], "Vdd") == 0) + { + return 0; + } + entry2 = HashFind(&ResNodeTable, line[COUPLETERMINAL2]); + node2 = ResInitializeNode(entry2); + node2->capacitance += MagAtof(line[COUPLEVALUE]); + return 0; + } + if (strcmp(line[COUPLETERMINAL2], "GND") == 0) + { + node1->capacitance += MagAtof(line[COUPLEVALUE]); + return 0; + } + if (strcmp(line[COUPLETERMINAL2], "Vdd") == 0) + { + node1->cap_vdd += MagAtof(line[COUPLEVALUE]); + return 0; + } + entry2 = HashFind(&ResNodeTable, line[COUPLETERMINAL2]); + node2 = ResInitializeNode(entry2); + if (strcmp(line[COUPLETERMINAL1], "GND") == 0) + { + node2->capacitance += MagAtof(line[COUPLEVALUE]); + return 0; + } + if (strcmp(line[COUPLETERMINAL1], "Vdd") == 0) + { + node2->cap_vdd += MagAtof(line[COUPLEVALUE]); + return 0; + } + node1->cap_couple += MagAtof(line[COUPLEVALUE]); + node2->cap_couple += MagAtof(line[COUPLEVALUE]); + return 0; } @@ -687,30 +709,27 @@ ResSimCapacitor(line) int ResSimResistor(line) - char line[][MAXTOKEN]; - + char line[][MAXTOKEN]; { - HashEntry *entry; - ResSimNode *node; + HashEntry *entry; + ResSimNode *node; - if (line[RESNODENAME][0] == 0) - { - TxError("Bad Resistor\n"); - return(1); - } - entry = HashFind(&ResNodeTable,line[RESNODENAME]); - node = ResInitializeNode(entry); - if (node->resistance != 0) - { + if (line[RESNODENAME][0] == 0) + { + TxError("Bad Resistor\n"); + return 1; + } + entry = HashFind(&ResNodeTable, line[RESNODENAME]); + node = ResInitializeNode(entry); + if (node->resistance != 0) + { TxError("Duplicate Resistance Entries\n"); - return(1); - } - node->resistance = MagAtof(line[NODERESISTANCE]); - return(0); + return 1; + } + node->resistance = MagAtof(line[NODERESISTANCE]); + return(0); } - - /* *------------------------------------------------------------------------- * @@ -727,95 +746,95 @@ ResSimResistor(line) */ int -ResSimAttribute(aname,avalue,rootname,readextfile) - char *aname,*avalue,*rootname; - int *readextfile; +ResSimAttribute(aname, avalue, rootname, readextfile) + char *aname, *avalue, *rootname; + int *readextfile; { - HashEntry *entry; - ResSimNode *node; - char digit[MAXDIGIT]; - int i; - static int notwarned=TRUE; + HashEntry *entry; + ResSimNode *node; + char digit[MAXDIGIT]; + int i; + static int notwarned=TRUE; - if (aname[0] == 0) - { - TxError("Bad Resistor\n"); - return(1); - } - entry = HashFind(&ResNodeTable,aname); - node = ResInitializeNode(entry); - if (strncmp(avalue,"res:skip",8) == 0) - { - if (node->status & FORCE) - { - TxError("Warning: Node %s is both forced and skipped\n",aname); - } - else - { - node->status |= SKIP; - } - } - else if (strncmp(avalue,"res:force",9) == 0) - { - if (node->status & SKIP) - { - TxError("Warning: Node %s is both skipped and forced \n",aname); - } - else - { - node->status |= FORCE; - } - } - else if (strncmp(avalue,"res:min=",8) == 0) - { - node->status |= MINSIZE; - for(i=0,avalue += 8; *avalue != '\0' && *avalue != ','; avalue++) - { - digit[i++] = *avalue; - } - digit[i++]='\0'; - node->minsizeres=MagAtof(digit); - } - else if (strncmp(avalue,"res:drive",9) == 0 && + if (aname[0] == 0) + { + TxError("Bad Resistor\n"); + return 1; + } + entry = HashFind(&ResNodeTable, aname); + node = ResInitializeNode(entry); + if (strncmp(avalue, "res:skip", 8) == 0) + { + if (node->status & FORCE) + { + TxError("Warning: Node %s is both forced and skipped\n", aname); + } + else + { + node->status |= SKIP; + } + } + else if (strncmp(avalue, "res:force", 9) == 0) + { + if (node->status & SKIP) + { + TxError("Warning: Node %s is both skipped and forced \n", aname); + } + else + { + node->status |= FORCE; + } + } + else if (strncmp(avalue, "res:min=", 8) == 0) + { + node->status |= MINSIZE; + for (i = 0, avalue += 8; *avalue != '\0' && *avalue != ','; avalue++) + { + digit[i++] = *avalue; + } + digit[i++] = '\0'; + node->minsizeres = MagAtof(digit); + } + else if (strncmp(avalue, "res:drive", 9) == 0 && (ResOptionsFlags & ResOpt_Signal)) - { - if (*readextfile == 0) - { - ResSimProcessDrivePoints(rootname); - *readextfile = 1; - } - /* is the attribute in root.ext? */ - if (node->drivepoint.p_x != INFINITY) - { - node->status |= DRIVELOC; - } - else - { - if (notwarned) - TxError("Drivepoint for %s not defined in %s.ext; is it defined in a child cell?\n",node->name,rootname); - notwarned = FALSE; - } - } + { + if (*readextfile == 0) + { + ResSimProcessDrivePoints(rootname); + *readextfile = 1; + } + /* is the attribute in root.ext? */ + if (node->drivepoint.p_x != INFINITY) + { + node->status |= DRIVELOC; + } + else + { + if (notwarned) + TxError("Drivepoint for %s not defined in %s.ext; is it " + "defined in a child cell?\n", node->name, rootname); + notwarned = FALSE; + } + } #ifdef ARIEL - else if (strncmp(avalue,"res:fix",7) == 0 && + else if (strncmp(avalue, "res:fix", 7) == 0 && (ResOptionsFlags & ResOpt_Power)) - { - if (*readextfile == 0) - { - ResSimProcessFixPoints(rootname); - *readextfile = 1; - } - } + { + if (*readextfile == 0) + { + ResSimProcessFixPoints(rootname); + *readextfile = 1; + } + } #endif - if (avalue = strchr(avalue,',')) - { - (void) ResSimAttribute(aname,avalue+1,rootname,readextfile); - } - return(0); + if (avalue = strchr(avalue, ',')) + { + ResSimAttribute(aname, avalue + 1, rootname, readextfile); + } + return 0; } - /* *------------------------------------------------------------------------- * @@ -836,34 +855,34 @@ ResSimAttribute(aname,avalue,rootname,readextfile) void ResSimProcessDrivePoints(filename) - char *filename; + char *filename; { - char line[MAXLINE][MAXTOKEN]; - FILE *fp; - HashEntry *entry; - ResSimNode *node; + char line[MAXLINE][MAXTOKEN]; + FILE *fp; + HashEntry *entry; + ResSimNode *node; - fp = PaOpen(filename,"r",".ext",".",(char *) NULL,(char **) NULL); - if (fp == NULL) - { - TxError("Cannot open file %s%s\n",filename,".ext"); - return; - } - while (gettokens(line,fp) != 0) - { - if (strncmp(line[RES_EXT_ATTR],"attr",4) != 0 || - strncmp(line[RES_EXT_ATTR_TEXT],"\"res:drive\"",11) != 0) continue; + fp = PaOpen(filename, "r", ".ext", ".", (char *)NULL, (char **)NULL); + if (fp == NULL) + { + TxError("Cannot open file %s%s\n", filename, ".ext"); + return; + } + while (gettokens(line,fp) != 0) + { + if (strncmp(line[RES_EXT_ATTR], "attr", 4) != 0 || + strncmp(line[RES_EXT_ATTR_TEXT], "\"res:drive\"", 11) != 0) + continue; - entry = HashFind(&ResNodeTable,line[RES_EXT_ATTR_NAME]); - node = ResInitializeNode(entry); - node->drivepoint.p_x = atoi(line[RES_EXT_ATTR_X]); - node->drivepoint.p_y = atoi(line[RES_EXT_ATTR_Y]); - node->rs_ttype = DBTechNoisyNameType(line[RES_EXT_ATTR_TILE]); - } + entry = HashFind(&ResNodeTable, line[RES_EXT_ATTR_NAME]); + node = ResInitializeNode(entry); + node->drivepoint.p_x = atoi(line[RES_EXT_ATTR_X]); + node->drivepoint.p_y = atoi(line[RES_EXT_ATTR_Y]); + node->rs_ttype = DBTechNoisyNameType(line[RES_EXT_ATTR_TILE]); + } } - /* *------------------------------------------------------------------------- * @@ -884,46 +903,47 @@ ResSimProcessDrivePoints(filename) void ResSimProcessFixPoints(filename) - char *filename; + char *filename; { - char line[MAXLINE][MAXTOKEN],*label,*c; - FILE *fp; - ResFixPoint *thisfix; + char line[MAXLINE][MAXTOKEN], *label, *c; + FILE *fp; + ResFixPoint *thisfix; - fp = PaOpen(filename,"r",".ext",".",(char *) NULL,(char **) NULL); - if (fp == NULL) - { - TxError("Cannot open file %s%s\n",filename,".ext"); - return; - } - while (gettokens(line,fp) != 0) - { - if (strncmp(line[RES_EXT_ATTR],"attr",4) != 0 || - strncmp(line[RES_EXT_ATTR_TEXT],"\"res:fix",8) != 0) continue; - label = line[RES_EXT_ATTR_TEXT]; - label += 8; - if (*label == ':') label++; - if ((c=strrchr(label,'"')) != NULL) *c='\0'; - else if (*label == '\0'); - else - { - TxError("Bad res:fix attribute label %s\n", + fp = PaOpen(filename, "r", ".ext", ".", (char *)NULL, (char **)NULL); + if (fp == NULL) + { + TxError("Cannot open file %s%s\n", filename, ".ext"); + return; + } + while (gettokens(line, fp) != 0) + { + if (strncmp(line[RES_EXT_ATTR], "attr", 4) != 0 || + strncmp(line[RES_EXT_ATTR_TEXT], "\"res:fix", 8) != 0) + continue; + label = line[RES_EXT_ATTR_TEXT]; + label += 8; + if (*label == ':') label++; + if ((c=strrchr(label, '"')) != NULL) *c = '\0'; + else if (*label != '\0') + { + TxError("Bad res:fix attribute label %s\n", line[RES_EXT_ATTR_TEXT]); - *label ='\0'; - } - thisfix = (ResFixPoint *) mallocMagic((unsigned) (sizeof(ResFixPoint)+strlen(label))); - thisfix->fp_next = ResFixList; - ResFixList = thisfix; - thisfix->fp_loc.p_x = atoi(line[RES_EXT_ATTR_X]); - thisfix->fp_loc.p_y = atoi(line[RES_EXT_ATTR_Y]); - thisfix->fp_ttype = DBTechNoisyNameType(line[RES_EXT_ATTR_TILE]); - thisfix->fp_tile=NULL; - strcpy(thisfix->fp_name,label); - } + *label ='\0'; + } + thisfix = (ResFixPoint *)mallocMagic((unsigned)(sizeof(ResFixPoint) + + strlen(label))); + thisfix->fp_next = ResFixList; + ResFixList = thisfix; + thisfix->fp_loc.p_x = atoi(line[RES_EXT_ATTR_X]); + thisfix->fp_loc.p_y = atoi(line[RES_EXT_ATTR_Y]); + thisfix->fp_ttype = DBTechNoisyNameType(line[RES_EXT_ATTR_TILE]); + thisfix->fp_tile = NULL; + strcpy(thisfix->fp_name, label); + } } - /* +/* *------------------------------------------------------------------------- * * ResSimMerge-- Processes = line in sim file @@ -939,30 +959,30 @@ ResSimProcessFixPoints(filename) int ResSimMerge(line) - char line[][MAXTOKEN]; + char line[][MAXTOKEN]; { - ResSimNode *node; - devPtr *ptr; + ResSimNode *node; + devPtr *ptr; - if ((line[ALIASNAME][0] == '\0') || (line[REALNAME][0] == '\0')) - { - TxError("Bad node alias line\n"); - return(1); - } - node = ResInitializeNode(HashFind(&ResNodeTable,line[ALIASNAME])); - node->status |= FORWARD; - node->forward = ResInitializeNode(HashFind(&ResNodeTable,line[REALNAME])); - node->forward->resistance += node->resistance; - node->forward->capacitance += node->capacitance; - while (node->firstDev != NULL) - { - ptr=node->firstDev; - node->firstDev = node->firstDev->nextDev; - ptr->nextDev = node->forward->firstDev; - node->forward->firstDev = ptr; - } - return(0); + if ((line[ALIASNAME][0] == '\0') || (line[REALNAME][0] == '\0')) + { + TxError("Bad node alias line\n"); + return(1); + } + node = ResInitializeNode(HashFind(&ResNodeTable, line[ALIASNAME])); + node->status |= FORWARD; + node->forward = ResInitializeNode(HashFind(&ResNodeTable, line[REALNAME])); + node->forward->resistance += node->resistance; + node->forward->capacitance += node->capacitance; + while (node->firstDev != NULL) + { + ptr = node->firstDev; + node->firstDev = node->firstDev->nextDev; + ptr->nextDev = node->forward->firstDev; + node->forward->firstDev = ptr; + } + return 0; } /* @@ -980,36 +1000,36 @@ ResSimMerge(line) ResSimNode * ResInitializeNode(entry) - HashEntry *entry; + HashEntry *entry; { - ResSimNode *node; + ResSimNode *node; - if ((node = (ResSimNode *) HashGetValue(entry)) == NULL) - { - node = (ResSimNode *) mallocMagic((unsigned)(sizeof(ResSimNode))); - HashSetValue(entry,(char *) node); - node->nextnode = ResOriginalNodes; - ResOriginalNodes = node; - node->status = FALSE; - node->forward = (ResSimNode *) NULL; - node->capacitance = 0; - node->cap_vdd = 0; - node->cap_couple = 0; - node->resistance = 0; - node->type = 0; - node->firstDev = NULL; - node->name = entry->h_key.h_name; - node->oldname = NULL; - node->drivepoint.p_x = INFINITY; - node->drivepoint.p_y = INFINITY; - node->location.p_x = INFINITY; - node->location.p_y = INFINITY; - node->rs_sublist[0]=NULL; - node->rs_sublist[1]=NULL; - } - while (node->status & FORWARD) - { - node = node->forward; - } - return(node); + if ((node = (ResSimNode *) HashGetValue(entry)) == NULL) + { + node = (ResSimNode *)mallocMagic((unsigned)(sizeof(ResSimNode))); + HashSetValue(entry, (char *) node); + node->nextnode = ResOriginalNodes; + ResOriginalNodes = node; + node->status = FALSE; + node->forward = (ResSimNode *) NULL; + node->capacitance = 0; + node->cap_vdd = 0; + node->cap_couple = 0; + node->resistance = 0; + node->type = 0; + node->firstDev = NULL; + node->name = entry->h_key.h_name; + node->oldname = NULL; + node->drivepoint.p_x = INFINITY; + node->drivepoint.p_y = INFINITY; + node->location.p_x = INFINITY; + node->location.p_y = INFINITY; + node->rs_sublist[0] = NULL; + node->rs_sublist[1] = NULL; + } + while (node->status & FORWARD) + { + node = node->forward; + } + return node; } diff --git a/resis/ResRex.c b/resis/ResRex.c index 90f90cdc..8b34acd4 100644 --- a/resis/ResRex.c +++ b/resis/ResRex.c @@ -203,7 +203,7 @@ CmdExtResis(win, cmd) TxCommand *cmd; { int i, j, k, option, value, saveFlags; - static int init=1; + static int init = 1; static float tolerance, tdiTolerance, fhFrequency; CellDef *mainDef; CellUse *selectedUse; @@ -264,6 +264,17 @@ typedef enum { init = 0; } + /* Initialize ResGlobalParams */ + gparams.rg_ttype = TT_SPACE; + gparams.rg_Tdi = 0.0; + gparams.rg_nodecap = 0.0; + gparams.rg_maxres = 0.0; + gparams.rg_bigdevres = 0; + gparams.rg_tilecount = 0; + gparams.rg_status = 0; + gparams.rg_devloc = NULL; + gparams.rg_name = NULL; + option = (cmd->tx_argc > 1) ? Lookup(cmd->tx_argv[1], cmdExtresisCmd) : RES_RUN; @@ -979,7 +990,7 @@ ResCheckSimNodes(celldef, resisdata) t1->drain != t2->source)) break; /* do parallel combination */ - if (cumRes != 0.0 && t2->resistance != 0.0) + if ((cumRes != 0.0) && (t2->resistance != 0.0)) { cumRes = (cumRes * t2->resistance) / (cumRes + t2->resistance); @@ -1016,32 +1027,32 @@ ResCheckSimNodes(celldef, resisdata) gparams.rg_devloc = &node->drivepoint; gparams.rg_status |= DRIVEONLY; } - if (node->status & PORTNODE) + if (node->status & PORTNODE) { /* The node is a port, not a device, so make */ - /* sure rg_ttype is set accordingly. */ + /* sure rg_ttype is set accordingly. */ gparams.rg_ttype = node->rs_ttype; } } - if (gparams.rg_devloc == NULL && node->status & FORCE) + if ((gparams.rg_devloc == NULL) && (node->status & FORCE)) { TxError("Node %s has force label but no drive point or " "driving device\n",node->name); } - if (minRes == FLT_MAX || gparams.rg_devloc == NULL) + if ((minRes == FLT_MAX) || (gparams.rg_devloc == NULL)) { continue; } - gparams.rg_bigdevres = (int)minRes*OHMSTOMILLIOHMS; - if (rctol == 0.0 || tol == 0.0) + gparams.rg_bigdevres = (int)minRes * OHMSTOMILLIOHMS; + if ((rctol == 0.0) || (tol == 0.0)) { ftolerance = 0.0; rctolerance = 0.0; } else { - ftolerance = minRes/tol; - rctolerance = minRes/rctol; + ftolerance = minRes / tol; + rctolerance = minRes / rctol; } /* @@ -1049,7 +1060,7 @@ ResCheckSimNodes(celldef, resisdata) * resistance? If so, extract net. */ - if (node->resistance > ftolerance || node->status & FORCE || + if ((node->resistance > ftolerance) || (node->status & FORCE) || (ResOpt_ExtractAll & ResOptionsFlags)) { ResFixPoint fp; @@ -1200,7 +1211,7 @@ ResFixUpConnections(simDev, layoutDev, simNode, nodename) if (simDev->gate == simNode) { - if ((gate=layoutDev->rd_fet_gate) != NULL) + if ((gate = layoutDev->rd_fet_gate) != NULL) { /* Cosmetic addition: If the layout device already has a */ /* name, the new one won't be used, so we decrement resNodeNum */ diff --git a/resis/ResSimple.c b/resis/ResSimple.c index 0011125d..698ba573 100644 --- a/resis/ResSimple.c +++ b/resis/ResSimple.c @@ -40,16 +40,14 @@ static char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magic-8.0/ void ResSetPathRes(); void resPathNode(); void resPathRes(); -Heap ResistorHeap; -int resRemoveLoops = FALSE; +Heap ResistorHeap; +int resRemoveLoops = FALSE; /* Forward declarations */ extern void ResMoveDevices(); extern void ResAddResistorToList(); - - /* *------------------------------------------------------------------------- * @@ -65,318 +63,301 @@ extern void ResAddResistorToList(); */ void -ResSimplifyNet(nodelist,biglist,reslist,tolerance) - resNode **nodelist,**biglist; - resResistor **reslist; - float tolerance; +ResSimplifyNet(nodelist, biglist, reslist, tolerance) + resNode **nodelist, **biglist; + resResistor **reslist; + float tolerance; { - resElement *resisptr; - resNode *node,*otherNode,*node1,*node2; - resResistor *resistor1 = NULL,*resistor2 = NULL; - int numdrive = 0, numreceive = 0; - int MarkedReceivers,UnMarkedReceivers,NumberOfDrivers,PendingReceivers; + resElement *resisptr; + resNode *node, *otherNode, *node1, *node2; + resResistor *resistor1 = NULL, *resistor2 = NULL; + int numdrive = 0, numreceive = 0; + int MarkedReceivers, UnMarkedReceivers; + int NumberOfDrivers, PendingReceivers; - if (*nodelist == NULL) return; - node = *nodelist; - node->rn_status |= MARKED | FINISHED; - *nodelist = node->rn_more; - if (node->rn_more != NULL) - { - node->rn_more->rn_less = (resNode *) NULL; - } - node->rn_more = *biglist; - if (*biglist != (resNode *) NULL) - { - (*biglist)->rn_less = node; - } - *biglist = node; + if (*nodelist == NULL) return; + node = *nodelist; + node->rn_status |= MARKED | FINISHED; + *nodelist = node->rn_more; + if (node->rn_more != NULL) + node->rn_more->rn_less = (resNode *) NULL; - /* - Walk though resistors. Mark uninitialized ones and assign them - A direction. Keep track of the number of resistors pointing in - each direction. + node->rn_more = *biglist; + if (*biglist != (resNode *) NULL) + (*biglist)->rn_less = node; + + *biglist = node; + + /* + * Walk though resistors. Mark uninitialized ones and assign them + * a direction. Keep track of the number of resistors pointing in + * each direction. */ - for (resisptr = node->rn_re; resisptr != NULL; resisptr = resisptr->re_nextEl) - { + for (resisptr = node->rn_re; resisptr != NULL; resisptr = resisptr->re_nextEl) + { if (((resisptr->re_thisEl->rr_status & RES_MARKED) == RES_MARKED) && - (resisptr->re_thisEl->rr_connection2 == node)) + (resisptr->re_thisEl->rr_connection2 == node)) { - if (resistor1 == NULL) - { - resistor1 = resisptr->re_thisEl; - } - else - { - resistor2 = resisptr->re_thisEl; - } - numdrive++; + if (resistor1 == NULL) + resistor1 = resisptr->re_thisEl; + else + resistor2 = resisptr->re_thisEl; + + numdrive++; } else { - /* - Resistor direction is from node1 to node2. If the resistor - is not marked, mark it and make sure the direction is - set properly. + /* + * Resistor direction is from node1 to node2. If the resistor + * is not marked, mark it and make sure the direction is + * set properly. */ - if ((resisptr->re_thisEl->rr_status & RES_MARKED) != RES_MARKED) - { - if (resisptr->re_thisEl->rr_connection2 == node) - { - resisptr->re_thisEl->rr_connection2 = resisptr->re_thisEl->rr_connection1; - resisptr->re_thisEl->rr_connection1 = node; - } - resisptr->re_thisEl->rr_status |= RES_MARKED; - } - if (resistor1 == NULL) - { - resistor1 = resisptr->re_thisEl; - } - else - { - resistor2 = resisptr->re_thisEl; - } - numreceive++; - } - } + if ((resisptr->re_thisEl->rr_status & RES_MARKED) != RES_MARKED) + { + if (resisptr->re_thisEl->rr_connection2 == node) + { + resisptr->re_thisEl->rr_connection2 = + resisptr->re_thisEl->rr_connection1; + resisptr->re_thisEl->rr_connection1 = node; + } + resisptr->re_thisEl->rr_status |= RES_MARKED; + } + if (resistor1 == NULL) + resistor1 = resisptr->re_thisEl; + else + resistor2 = resisptr->re_thisEl; - /* - Is the node reached by one resistor? If it is, check the resistor's - other end. Check the number of drivers at the other end. If it is - more than 1, delete the current resistor to break the deadlock. + numreceive++; + } + } + + /* + * Is the node reached by one resistor? If it is, check the resistor's + * other end. Check the number of drivers at the other end. If it is + * more than 1, delete the current resistor to break the deadlock. */ - if (numreceive == 0 && numdrive == 1 && node->rn_why != RES_NODE_ORIGIN) - { + + if (numreceive == 0 && numdrive == 1 && node->rn_why != RES_NODE_ORIGIN) + { resistor1->rr_status |= RES_DEADEND; if (resistor1->rr_value < tolerance) { - otherNode = (resistor1->rr_connection1 == node) ? resistor1->rr_connection2 : resistor1->rr_connection1; - MarkedReceivers = 0; - UnMarkedReceivers = 0; - NumberOfDrivers = 0; - PendingReceivers = 0; - resistor2 = resistor1; - for (resisptr = otherNode->rn_re; resisptr != NULL; resisptr=resisptr->re_nextEl) - { - if (resisptr->re_thisEl->rr_connection1 == otherNode) - { - if ((resisptr->re_thisEl->rr_connection2->rn_status & MARKED) != MARKED) - { - PendingReceivers++; - } - if (resisptr->re_thisEl->rr_status & RES_DEADEND || - resisptr->re_thisEl->rr_value > tolerance) - { - MarkedReceivers++; - resistor2 = (resisptr->re_thisEl->rr_value >= resistor2->rr_value) ? resisptr->re_thisEl : resistor2; - } - else - { - UnMarkedReceivers++; - } - } - else - { - NumberOfDrivers++; - } - } - /* other recievers at far end? If so, reschedule other node; - deadlock will be settled from that node. + otherNode = (resistor1->rr_connection1 == node) ? + resistor1->rr_connection2 : resistor1->rr_connection1; + MarkedReceivers = 0; + UnMarkedReceivers = 0; + NumberOfDrivers = 0; + PendingReceivers = 0; + resistor2 = resistor1; + for (resisptr = otherNode->rn_re; resisptr != NULL; + resisptr = resisptr->re_nextEl) + { + if (resisptr->re_thisEl->rr_connection1 == otherNode) + { + if ((resisptr->re_thisEl->rr_connection2->rn_status & MARKED) + != MARKED) + { + PendingReceivers++; + } + if (resisptr->re_thisEl->rr_status & RES_DEADEND || + resisptr->re_thisEl->rr_value > tolerance) + { + MarkedReceivers++; + resistor2 = (resisptr->re_thisEl->rr_value >= + resistor2->rr_value) ? resisptr->re_thisEl : resistor2; + } + else + UnMarkedReceivers++; + } + else + NumberOfDrivers++; + } + /* other recievers at far end? If so, reschedule other node; + * deadlock will be settled from that node. */ - if ((MarkedReceivers+UnMarkedReceivers+NumberOfDrivers == 2) || - (UnMarkedReceivers == 0 && MarkedReceivers > 1 && resistor2 == resistor1 && PendingReceivers == 0)) - { - if (otherNode->rn_status & MARKED) - { - otherNode->rn_status &= ~MARKED; - ResRemoveFromQueue(otherNode,biglist); - otherNode->rn_less= NULL; - otherNode->rn_more = *nodelist; - if (*nodelist != NULL) - { - (*nodelist)->rn_less = otherNode; - } - *nodelist = otherNode; - } - return; - } + if ((MarkedReceivers+UnMarkedReceivers+NumberOfDrivers == 2) || + (UnMarkedReceivers == 0 && MarkedReceivers > 1 && + resistor2 == resistor1 && PendingReceivers == 0)) + { + if (otherNode->rn_status & MARKED) + { + otherNode->rn_status &= ~MARKED; + ResRemoveFromQueue(otherNode, biglist); + otherNode->rn_less = NULL; + otherNode->rn_more = *nodelist; + if (*nodelist != NULL) + (*nodelist)->rn_less = otherNode; - /* - Break loop here. More than one driver indicates a loop; - remove deadend, allowing drivers to be merged + *nodelist = otherNode; + } + return; + } + + /* + * Break loop here. More than one driver indicates a loop; + * remove deadend, allowing drivers to be merged */ - else if (UnMarkedReceivers == 0 && (MarkedReceivers == 1 && NumberOfDrivers > 1 || resistor2 != resistor1)) + else if (UnMarkedReceivers == 0 && (MarkedReceivers == 1 && + NumberOfDrivers > 1 || resistor2 != resistor1)) - { - otherNode->rn_float.rn_area += resistor1->rr_float.rr_area; - otherNode->rn_status &= ~RES_DONE_ONCE; - ResDeleteResPointer(resistor1->rr_connection1,resistor1); - ResDeleteResPointer(resistor1->rr_connection2,resistor1); - ResEliminateResistor(resistor1,reslist); - ResMergeNodes(otherNode,node,nodelist,biglist); - if (otherNode->rn_status & MARKED) - { - otherNode->rn_status &= ~MARKED; - ResRemoveFromQueue(otherNode,biglist); - otherNode->rn_less= NULL; - otherNode->rn_more = *nodelist; - if (*nodelist != NULL) - { - (*nodelist)->rn_less = otherNode; - } - *nodelist = otherNode; - } - ResDoneWithNode(otherNode); - } + { + otherNode->rn_float.rn_area += resistor1->rr_float.rr_area; + otherNode->rn_status &= ~RES_DONE_ONCE; + ResDeleteResPointer(resistor1->rr_connection1, resistor1); + ResDeleteResPointer(resistor1->rr_connection2, resistor1); + ResEliminateResistor(resistor1, reslist); + ResMergeNodes(otherNode, node, nodelist, biglist); + if (otherNode->rn_status & MARKED) + { + otherNode->rn_status &= ~MARKED; + ResRemoveFromQueue(otherNode, biglist); + otherNode->rn_less= NULL; + otherNode->rn_more = *nodelist; + if (*nodelist != NULL) + (*nodelist)->rn_less = otherNode; + + *nodelist = otherNode; + } + ResDoneWithNode(otherNode); + } } - - } - /* - Two resistors in series? Combine them and move devices to - appropriate end. + } + /* + * Two resistors in series? Combine them and move devices to + * appropriate end. */ - else if (numdrive+numreceive == 2 && - (resistor1->rr_value < tolerance && resistor2->rr_value < tolerance)) - { - if ((resistor1->rr_status & RES_MARKED) == 0 && (resistor1->rr_connection2 == node)) - { - resistor1->rr_connection2 = resistor1->rr_connection1; - resistor1->rr_connection1 = node; - } - resistor1->rr_status |= RES_MARKED; - if ((resistor2->rr_status & RES_MARKED) == 0 && (resistor2->rr_connection2 == node)) - { - resistor2->rr_connection2 = resistor2->rr_connection1; - resistor2->rr_connection1 = node; - } - resistor2->rr_status |= RES_MARKED; - node1 = (resistor1->rr_connection1 == node) ? resistor1->rr_connection2 : resistor1->rr_connection1; - node2 = (resistor2->rr_connection1 == node) ? resistor2->rr_connection2 : resistor2->rr_connection1; - otherNode = (resistor1->rr_status & RES_DEADEND && + else if (numdrive+numreceive == 2 && (resistor1->rr_value < tolerance && + resistor2->rr_value < tolerance)) + { + if ((resistor1->rr_status & RES_MARKED) == 0 && + (resistor1->rr_connection2 == node)) + { + resistor1->rr_connection2 = resistor1->rr_connection1; + resistor1->rr_connection1 = node; + } + resistor1->rr_status |= RES_MARKED; + if ((resistor2->rr_status & RES_MARKED) == 0 && + (resistor2->rr_connection2 == node)) + { + resistor2->rr_connection2 = resistor2->rr_connection1; + resistor2->rr_connection1 = node; + } + resistor2->rr_status |= RES_MARKED; + node1 = (resistor1->rr_connection1 == node) ? resistor1->rr_connection2 : + resistor1->rr_connection1; + node2 = (resistor2->rr_connection1 == node) ? resistor2->rr_connection2 : + resistor2->rr_connection1; + otherNode = (resistor1->rr_status & RES_DEADEND && resistor1->rr_value < tolerance / 2) || ((resistor2->rr_status & RES_DEADEND) == 0 && resistor1->rr_value < resistor2->rr_value) ? node1 : node2; + /* + * Make one big resistor out of two little ones, eliminating + * the current node. Devices connected to this node are + * moved to either end depending on their resistance. + */ + ResMoveDevices(node,otherNode); + otherNode->rn_noderes = MIN(node->rn_noderes, otherNode->rn_noderes); + node2->rn_float.rn_area += resistor1->rr_value * node->rn_float.rn_area / + (resistor1->rr_value + resistor2->rr_value); + node1->rn_float.rn_area += resistor2->rr_value * node->rn_float.rn_area / + (resistor1->rr_value + resistor2->rr_value); + resistor1->rr_value += resistor2->rr_value; + resistor1->rr_float.rr_area +=resistor2->rr_float.rr_area; + if (resistor1 == *reslist) + *reslist = resistor1->rr_nextResistor; + else + resistor1->rr_lastResistor->rr_nextResistor = resistor1->rr_nextResistor; - /* - make one big resistor out of two little ones, eliminating - the current node. Devices connected to this node are - moved to either end depending on their resistance. - */ - ResMoveDevices(node,otherNode); - otherNode->rn_noderes = MIN(node->rn_noderes,otherNode->rn_noderes); - node2->rn_float.rn_area += resistor1->rr_value*node->rn_float.rn_area/(resistor1->rr_value+resistor2->rr_value); - node1->rn_float.rn_area += resistor2->rr_value*node->rn_float.rn_area/(resistor1->rr_value+resistor2->rr_value); - resistor1->rr_value += resistor2->rr_value; - resistor1->rr_float.rr_area +=resistor2->rr_float.rr_area; - if (resistor1 == *reslist) - { - *reslist = resistor1->rr_nextResistor; - } - else - { - resistor1->rr_lastResistor->rr_nextResistor = resistor1->rr_nextResistor; - } - if (resistor1->rr_nextResistor != NULL) - { - resistor1->rr_nextResistor->rr_lastResistor = resistor1->rr_lastResistor; - } - ResAddResistorToList(resistor1,reslist); - ResDeleteResPointer(node,resistor1); - ResDeleteResPointer(node,resistor2); - ResDeleteResPointer(node2,resistor2); - if (resistor1->rr_connection1 == node) - { - resistor1->rr_connection1 = node2; - } - else - { - resistor1->rr_connection2 = node2; - } - resisptr = (resElement *) mallocMagic((unsigned)(sizeof(resElement))); - resisptr->re_thisEl = resistor1; - resisptr->re_nextEl = node2->rn_re; - node2->rn_re = resisptr; - ResEliminateResistor(resistor2,reslist); - otherNode->rn_status |= (node->rn_status & RN_MAXTDI); - ResCleanNode(node,TRUE,biglist,nodelist); - node1->rn_status &= ~RES_DONE_ONCE; - if (node1->rn_status & MARKED) - { - node1->rn_status &= ~MARKED; - ResRemoveFromQueue(node1,biglist); - node1->rn_less= NULL; - node1->rn_more = *nodelist; - if (*nodelist != NULL) - { - (*nodelist)->rn_less = node1; - } - *nodelist = node1; - } - node2->rn_status &= ~RES_DONE_ONCE; - if (node2->rn_status & MARKED) - { - node2->rn_status &= ~MARKED; - ResRemoveFromQueue(node2,biglist); - node2->rn_less= NULL; - node2->rn_more = *nodelist; - if (*nodelist != NULL) - { - (*nodelist)->rn_less = node2; - } - *nodelist = node2; - } - ResDoneWithNode(node1); - } + if (resistor1->rr_nextResistor != NULL) + resistor1->rr_nextResistor->rr_lastResistor = resistor1->rr_lastResistor; - /* - Last resort- keep propagating down the tree. To avoid looping, - mark each node when it is reached. Don't reschedule node if - none of the connections to it have changed since it was marked + ResAddResistorToList(resistor1, reslist); + ResDeleteResPointer(node, resistor1); + ResDeleteResPointer(node, resistor2); + ResDeleteResPointer(node2, resistor2); + if (resistor1->rr_connection1 == node) + resistor1->rr_connection1 = node2; + else + resistor1->rr_connection2 = node2; + + resisptr = (resElement *)mallocMagic((unsigned)(sizeof(resElement))); + resisptr->re_thisEl = resistor1; + resisptr->re_nextEl = node2->rn_re; + node2->rn_re = resisptr; + ResEliminateResistor(resistor2, reslist); + otherNode->rn_status |= (node->rn_status & RN_MAXTDI); + ResCleanNode(node, TRUE, biglist, nodelist); + node1->rn_status &= ~RES_DONE_ONCE; + if (node1->rn_status & MARKED) + { + node1->rn_status &= ~MARKED; + ResRemoveFromQueue(node1, biglist); + node1->rn_less = NULL; + node1->rn_more = *nodelist; + if (*nodelist != NULL) + (*nodelist)->rn_less = node1; + *nodelist = node1; + } + node2->rn_status &= ~RES_DONE_ONCE; + if (node2->rn_status & MARKED) + { + node2->rn_status &= ~MARKED; + ResRemoveFromQueue(node2, biglist); + node2->rn_less = NULL; + node2->rn_more = *nodelist; + if (*nodelist != NULL) + (*nodelist)->rn_less = node2; + *nodelist = node2; + } + ResDoneWithNode(node1); + } + + /* + * Last resort- keep propagating down the tree. To avoid looping, + * mark each node when it is reached. Don't reschedule node if + * none of the connections to it have changed since it was marked */ - else if (numreceive > 0 && (node->rn_status & RES_DONE_ONCE) == 0) - { - node->rn_status |= RES_DONE_ONCE; - for (resisptr = node->rn_re; resisptr != NULL; resisptr = resisptr->re_nextEl) - { - if (resisptr->re_thisEl->rr_connection1 == node) + else if (numreceive > 0 && (node->rn_status & RES_DONE_ONCE) == 0) + { + node->rn_status |= RES_DONE_ONCE; + for (resisptr = node->rn_re; resisptr != NULL; resisptr = resisptr->re_nextEl) + { + if (resisptr->re_thisEl->rr_connection1 == node) + { + /* + * Elements with a resistance greater than the + * tolerance should only be propagated past once- + * loops may occur otherwise. + */ + if (resisptr->re_thisEl->rr_status & RES_DONE_ONCE) + continue; + + if (resisptr->re_thisEl->rr_connection2->rn_status & MARKED) { - /* - elements with a resistance greater than the - tolerance should only be propagated past once- - loops may occur otherwise. - */ - if (resisptr->re_thisEl->rr_status & RES_DONE_ONCE) - { - continue; - } - if (resisptr->re_thisEl->rr_connection2->rn_status & MARKED) - { - /* - mark big resistors so we only process them - once. - */ - if (resisptr->re_thisEl->rr_value > tolerance) - { - resisptr->re_thisEl->rr_status |= RES_DONE_ONCE; - } - resisptr->re_thisEl->rr_connection2->rn_status &= ~MARKED; - ResRemoveFromQueue(resisptr->re_thisEl->rr_connection2,biglist); - resisptr->re_thisEl->rr_connection2->rn_less= NULL; - resisptr->re_thisEl->rr_connection2->rn_more = *nodelist; - if (*nodelist != NULL) - { - (*nodelist)->rn_less = resisptr->re_thisEl->rr_connection2; - } - *nodelist = resisptr->re_thisEl->rr_connection2; - } + /* + * Mark big resistors so we only process them + * once. + */ + if (resisptr->re_thisEl->rr_value > tolerance) + resisptr->re_thisEl->rr_status |= RES_DONE_ONCE; + + resisptr->re_thisEl->rr_connection2->rn_status &= ~MARKED; + ResRemoveFromQueue(resisptr->re_thisEl->rr_connection2, biglist); + resisptr->re_thisEl->rr_connection2->rn_less= NULL; + resisptr->re_thisEl->rr_connection2->rn_more = *nodelist; + if (*nodelist != NULL) + (*nodelist)->rn_less = resisptr->re_thisEl->rr_connection2; + + *nodelist = resisptr->re_thisEl->rr_connection2; } - } - } + } + } + } } - - /* *------------------------------------------------------------------------- * @@ -390,56 +371,44 @@ ResSimplifyNet(nodelist,biglist,reslist,tolerance) */ void -ResMoveDevices(node1,node2) - resNode *node1,*node2; +ResMoveDevices(node1, node2) + resNode *node1, *node2; { - tElement *devptr,*oldptr; - resDevice *device; + tElement *devptr, *oldptr; + resDevice *device; - devptr = node1->rn_te; - while (devptr != NULL) - { - device = devptr->te_thist; - oldptr = devptr; - devptr = devptr->te_nextt; - if (device->rd_status & RES_DEV_PLUG) - { - if (((ResPlug *)(device))->rpl_node == node1) - { - ((ResPlug *)(device))->rpl_node = node2; - } - else - { - TxError("Bad node connection in plug\n"); - } - } - else - { - if (device->rd_fet_gate == node1) - { - device->rd_fet_gate = node2; - } - else if (device->rd_fet_source == node1) - { - device->rd_fet_source = node2; - } - else if (device->rd_fet_drain == node1) - { - device->rd_fet_drain = node2; - } - else - { - TxError("Missing Device connection in squish routines at %d, %d\n",node1->rn_loc.p_x,node1->rn_loc.p_y); - } - } - oldptr->te_nextt = node2->rn_te; - node2->rn_te = oldptr; - } - node1->rn_te = NULL; + devptr = node1->rn_te; + while (devptr != NULL) + { + device = devptr->te_thist; + oldptr = devptr; + devptr = devptr->te_nextt; + if (device->rd_status & RES_DEV_PLUG) + { + if (((ResPlug *)(device))->rpl_node == node1) + ((ResPlug *)(device))->rpl_node = node2; + else + TxError("Bad node connection in plug\n"); + } + else + { + if (device->rd_fet_gate == node1) + device->rd_fet_gate = node2; + else if (device->rd_fet_source == node1) + device->rd_fet_source = node2; + else if (device->rd_fet_drain == node1) + device->rd_fet_drain = node2; + else + TxError("Missing Device connection in squish routines" + " at %d, %d\n", node1->rn_loc.p_x, node1->rn_loc.p_y); + } + oldptr->te_nextt = node2->rn_te; + node2->rn_te = oldptr; + } + node1->rn_te = NULL; } - /* *------------------------------------------------------------------------- * @@ -457,146 +426,137 @@ ResMoveDevices(node1,node2) */ void -ResScrunchNet(reslist,pendingList,biglist,tolerance) - resResistor **reslist; - resNode **pendingList,**biglist; - float tolerance; +ResScrunchNet(reslist, pendingList, biglist, tolerance) + resResistor **reslist; + resNode **pendingList, **biglist; + float tolerance; { - resResistor *locallist=NULL,*current,*working; - resNode *node1,*node2; - resElement *rcell1; - int c1,c2; + resResistor *locallist = NULL, *current, *working; + resNode *node1, *node2; + resElement *rcell1; + int c1, c2; - /* sort resistors by size */ - current = *reslist; - while (current != NULL) - { - working = current; - current = current->rr_nextResistor; - if (working == *reslist) - { - *reslist = current; - } - else - { - working->rr_lastResistor->rr_nextResistor = current; - } - if (current != NULL) - { - current->rr_lastResistor = working->rr_lastResistor; - } - ResAddResistorToList(working,&locallist); - } + /* Sort resistors by size */ + current = *reslist; + while (current != NULL) + { + working = current; + current = current->rr_nextResistor; + if (working == *reslist) + *reslist = current; + else + working->rr_lastResistor->rr_nextResistor = current; + if (current != NULL) + current->rr_lastResistor = working->rr_lastResistor; - *reslist = locallist; - while (*reslist != NULL && (*reslist)->rr_value < tolerance) - { - current = *reslist; - if (current->rr_nextResistor == NULL) - { - break; - } - working = NULL; - c1=0; - c2=0; + ResAddResistorToList(working, &locallist); + } - /* search for next smallest adjoining resistor */ - for (rcell1 = current->rr_connection1->rn_re; rcell1 != NULL; rcell1 = rcell1->re_nextEl) - { - if (rcell1->re_thisEl != current) - { - c1++; - if (working == NULL) + *reslist = locallist; + while (*reslist != NULL && (*reslist)->rr_value < tolerance) + { + current = *reslist; + if (current->rr_nextResistor == NULL) + break; + + working = NULL; + c1 = 0; + c2 = 0; + + /* Search for next smallest adjoining resistor */ + for (rcell1 = current->rr_connection1->rn_re; rcell1 != NULL; + rcell1 = rcell1->re_nextEl) + { + if (rcell1->re_thisEl != current) + { + c1++; + if (working == NULL) + { + working = rcell1->re_thisEl; + node1 = current->rr_connection1; + } + else + { + if (working->rr_value > rcell1->re_thisEl->rr_value) { - working = rcell1->re_thisEl; - node1 = current->rr_connection1; + node1 = current->rr_connection1; + working = rcell1->re_thisEl; } - else + } + } + } + for (rcell1 = current->rr_connection2->rn_re; rcell1 != NULL; + rcell1 = rcell1->re_nextEl) + { + if (rcell1->re_thisEl != current) + { + c2++; + if (working == NULL) + { + working = rcell1->re_thisEl; + node1 = current->rr_connection2; + } + else + { + if (working->rr_value > rcell1->re_thisEl->rr_value) { - if (working->rr_value > rcell1->re_thisEl->rr_value) - { - node1 = current->rr_connection1; - working = rcell1->re_thisEl; - } - } - } - } - for (rcell1 = current->rr_connection2->rn_re; rcell1 != NULL; rcell1 = rcell1->re_nextEl) - { - if (rcell1->re_thisEl != current) - { - c2++; - if (working == NULL) - { - working = rcell1->re_thisEl; - node1 = current->rr_connection2; - } - else - { - if (working->rr_value > rcell1->re_thisEl->rr_value) - { - node1 = current->rr_connection2; - working = rcell1->re_thisEl; - } - } - } - } - /* - if the current resistor isn't a deadend, add its value and - area to that of the next smallest one. If it is a deadend, - simply add its area to its node. - */ - if (c1 != 0 && c2 != 0) - { - working->rr_value += current->rr_value; - working->rr_float.rr_area += current->rr_float.rr_area; - } - else - { - node1->rn_float.rn_area += current->rr_float.rr_area; - } - /* - Move everything from from one end of the ressistor to the - other and eliminate the resistor. - */ - node2 = (current->rr_connection1 == node1) ? current->rr_connection2 : current->rr_connection1; - ResDeleteResPointer(current->rr_connection1,current); - ResDeleteResPointer(current->rr_connection2,current); - working->rr_lastResistor->rr_nextResistor = working->rr_nextResistor; - if (working->rr_nextResistor != NULL) - { - working->rr_nextResistor->rr_lastResistor = working->rr_lastResistor; - } - ResEliminateResistor(current,reslist); - ResAddResistorToList(working,reslist); - if (node2->rn_why & RES_NODE_ORIGIN) - { - ResMergeNodes(node2,node1,pendingList,biglist); - node1 = node2; - } - else - { - ResMergeNodes(node1,node2,pendingList,biglist); - } + node1 = current->rr_connection2; + working = rcell1->re_thisEl; + } + } + } + } + /* + * If the current resistor isn't a deadend, add its value and + * area to that of the next smallest one. If it is a deadend, + * simply add its area to its node. + */ + if (c1 != 0 && c2 != 0) + { + working->rr_value += current->rr_value; + working->rr_float.rr_area += current->rr_float.rr_area; + } + else + { + node1->rn_float.rn_area += current->rr_float.rr_area; + } + /* + * Move everything from from one end of the ressistor to the + * other and eliminate the resistor. + */ + node2 = (current->rr_connection1 == node1) ? current->rr_connection2 : + current->rr_connection1; + ResDeleteResPointer(current->rr_connection1, current); + ResDeleteResPointer(current->rr_connection2, current); + working->rr_lastResistor->rr_nextResistor = working->rr_nextResistor; + if (working->rr_nextResistor != NULL) + working->rr_nextResistor->rr_lastResistor = working->rr_lastResistor; - /* - Try further simplification on net using ResDoneWithNode and - ResSimplifyNet. - */ - ResRemoveFromQueue(node1,biglist); - ResAddToQueue(node1,pendingList); - node1->rn_status &= ~(RES_DONE_ONCE | FINISHED); - ResDoneWithNode(node1); - while (*pendingList != NULL) - { - ResSimplifyNet(pendingList,biglist,reslist,tolerance); - } - } + ResEliminateResistor(current, reslist); + ResAddResistorToList(working, reslist); + if (node2->rn_why & RES_NODE_ORIGIN) + { + ResMergeNodes(node2, node1, pendingList, biglist); + node1 = node2; + } + else + ResMergeNodes(node1,node2,pendingList,biglist); + + /* + * Try further simplification on net using ResDoneWithNode and + * ResSimplifyNet. + */ + ResRemoveFromQueue(node1, biglist); + ResAddToQueue(node1, pendingList); + node1->rn_status &= ~(RES_DONE_ONCE | FINISHED); + ResDoneWithNode(node1); + while (*pendingList != NULL) + ResSimplifyNet(pendingList,biglist,reslist,tolerance); + } } - /* *------------------------------------------------------------------------- * @@ -611,52 +571,46 @@ ResScrunchNet(reslist,pendingList,biglist,tolerance) */ void -ResAddResistorToList(resistor,locallist) - resResistor *resistor,**locallist; +ResAddResistorToList(resistor, locallist) + resResistor *resistor, **locallist; { - resResistor *local,*last=NULL; + resResistor *local,*last=NULL; - for (local = *locallist; local != NULL; local = local->rr_nextResistor) - { - if (local->rr_value >= resistor->rr_value) - { - break; - } - last = local; - } - if (local != NULL) - { - resistor->rr_nextResistor = local; - resistor->rr_lastResistor = local->rr_lastResistor; - if (local->rr_lastResistor == NULL) - { - *locallist = resistor; - } - else - { - local->rr_lastResistor->rr_nextResistor = resistor; - } - local->rr_lastResistor = resistor; + for (local = *locallist; local != NULL; local = local->rr_nextResistor) + { + if (local->rr_value >= resistor->rr_value) + break; + last = local; + } + if (local != NULL) + { + resistor->rr_nextResistor = local; + resistor->rr_lastResistor = local->rr_lastResistor; + if (local->rr_lastResistor == NULL) + *locallist = resistor; + else + local->rr_lastResistor->rr_nextResistor = resistor; + + local->rr_lastResistor = resistor; } else { - if (last != NULL) - { - last->rr_nextResistor = resistor; - resistor->rr_lastResistor = last; - resistor->rr_nextResistor = NULL; - } - else - { - resistor->rr_nextResistor = NULL; - resistor->rr_lastResistor = NULL; - *locallist = resistor; + if (last != NULL) + { + last->rr_nextResistor = resistor; + resistor->rr_lastResistor = last; + resistor->rr_nextResistor = NULL; + } + else + { + resistor->rr_nextResistor = NULL; + resistor->rr_lastResistor = NULL; + *locallist = resistor; } } } - /* *------------------------------------------------------------------------- * @@ -673,40 +627,34 @@ ResAddResistorToList(resistor,locallist) */ void -ResDistributeCapacitance(nodelist,totalcap) - resNode *nodelist; - float totalcap; +ResDistributeCapacitance(nodelist, totalcap) + resNode *nodelist; + float totalcap; { - float totalarea=0,capperarea; - resNode *workingNode; - resElement *rptr; + float totalarea = 0, capperarea; + resNode *workingNode; + resElement *rptr; - for (workingNode = nodelist; workingNode != NULL; workingNode=workingNode->rn_more) - { - for (rptr = workingNode->rn_re; rptr != NULL; rptr=rptr->re_nextEl) - { - if (rptr->re_thisEl->rr_float.rr_area != 0.0) - { - TxError("Nonnull resistor area\n"); - } -/* workingNode->rn_float.rn_area += rptr->re_thisEl->rr_float.rr_area/2; */ - } - totalarea += workingNode->rn_float.rn_area; - } - if (totalarea == 0) - { - TxError("Error: Node with no area.\n"); - return; - } - capperarea = FEMTOTOATTO*totalcap/totalarea; - for (workingNode = nodelist; workingNode != NULL; workingNode=workingNode->rn_more) - { - workingNode->rn_float.rn_area *= capperarea; - } + for (workingNode = nodelist; workingNode != NULL; workingNode = workingNode->rn_more) + { + for (rptr = workingNode->rn_re; rptr != NULL; rptr=rptr->re_nextEl) + if (rptr->re_thisEl->rr_float.rr_area != 0.0) + TxError("Nonnull resistor area\n"); + + totalarea += workingNode->rn_float.rn_area; + } + if (totalarea == 0) + { + TxError("Error: Node with no area.\n"); + return; + } + capperarea = FEMTOTOATTO * totalcap / totalarea; + + for (workingNode = nodelist; workingNode != NULL; workingNode=workingNode->rn_more) + workingNode->rn_float.rn_area *= capperarea; } - /* *------------------------------------------------------------------------- * @@ -723,74 +671,69 @@ ResDistributeCapacitance(nodelist,totalcap) float ResCalculateChildCapacitance(me) - resNode *me; + resNode *me; { - RCDelayStuff *myC; - resElement *workingRes; - resDevice *dev; - float childcap; - tElement *tptr; - int t; - ExtDevice *devptr; + RCDelayStuff *myC; + resElement *workingRes; + resDevice *dev; + float childcap; + tElement *tptr; + int t; + ExtDevice *devptr; + if (me->rn_client != (ClientData) NULL) /* we have a loop */ + return(-1); - if (me->rn_client != (ClientData) NULL) /* we have a loop */ - { - return(-1); - } - myC = (RCDelayStuff *) mallocMagic((unsigned) (sizeof(RCDelayStuff))); - me->rn_client = (ClientData) myC; + myC = (RCDelayStuff *) mallocMagic((unsigned) (sizeof(RCDelayStuff))); + me->rn_client = (ClientData) myC; - /* This following assumes that ResDistributeCapacitance has been run */ - /* and the the resulting capacitance value is stored in the area field */ - myC->rc_Cdownstream = me->rn_float.rn_area; + /* This following assumes that ResDistributeCapacitance has been run */ + /* and the the resulting capacitance value is stored in the area field */ + myC->rc_Cdownstream = me->rn_float.rn_area; + myC->rc_Tdi = 0.0; - /* get capacitance for all connected gates */ - for (tptr = me->rn_te; tptr != NULL; tptr = tptr->te_nextt) - { - dev = tptr->te_thist; - /* Hack for non-Manhattan geometry. Only one side of a split */ - /* tile should correspond to a device type. */ - if (IsSplit(dev->rd_tile)) - { - t = TiGetLeftType(dev->rd_tile); - if (ExtCurStyle->exts_device[t] == NULL) - t = TiGetRightType(dev->rd_tile); - } - else - t = TiGetType(dev->rd_tile); - if (dev->rd_fet_gate == me) - { - devptr = ExtCurStyle->exts_device[t]; - myC->rc_Cdownstream += - dev->rd_length* - dev->rd_width* - devptr->exts_deviceGateCap+ - (dev->rd_width+dev->rd_width)* + /* get capacitance for all connected gates */ + for (tptr = me->rn_te; tptr != NULL; tptr = tptr->te_nextt) + { + dev = tptr->te_thist; + /* Hack for non-Manhattan geometry. Only one side of a split */ + /* tile should correspond to a device type. */ + if (IsSplit(dev->rd_tile)) + { + t = TiGetLeftType(dev->rd_tile); + if (ExtCurStyle->exts_device[t] == NULL) + t = TiGetRightType(dev->rd_tile); + } + else + t = TiGetType(dev->rd_tile); + if (dev->rd_fet_gate == me) + { + devptr = ExtCurStyle->exts_device[t]; + myC->rc_Cdownstream += dev->rd_length * dev->rd_width * + devptr->exts_deviceGateCap + + (dev->rd_width + dev->rd_width) * devptr->exts_deviceSDCap; - } - } + } + } - /* Calculate child Capacitance */ - for (workingRes = me->rn_re; workingRes != NULL; workingRes=workingRes->re_nextEl) - { - if (workingRes->re_thisEl->rr_connection1 == me && - (workingRes->re_thisEl->rr_status & RES_TDI_IGNORE) == 0) - { - childcap = ResCalculateChildCapacitance(workingRes->re_thisEl->rr_connection2); - if (childcap == -1) - { - return(-1); - } - myC->rc_Cdownstream +=childcap; - } - } - return(myC->rc_Cdownstream); + /* Calculate child Capacitance */ + for (workingRes = me->rn_re; workingRes != NULL; workingRes=workingRes->re_nextEl) + { + if (workingRes->re_thisEl->rr_connection1 == me && + (workingRes->re_thisEl->rr_status & RES_TDI_IGNORE) == 0) + { + childcap = ResCalculateChildCapacitance(workingRes->re_thisEl->rr_connection2); + if (childcap == -1) + return(-1); + + myC->rc_Cdownstream += childcap; + } + } + return (myC->rc_Cdownstream); } - /* *------------------------------------------------------------------------- * @@ -805,40 +748,35 @@ ResCalculateChildCapacitance(me) */ void -ResCalculateTDi(node,resistor,resistorvalue) - resNode *node; - resResistor *resistor; - int resistorvalue; +ResCalculateTDi(node, resistor, resistorvalue) + resNode *node; + resResistor *resistor; + int resistorvalue; { - resElement *workingRes; - RCDelayStuff *rcd = (RCDelayStuff *)node->rn_client; - RCDelayStuff *rcd2; + resElement *workingRes; + RCDelayStuff *rcd = (RCDelayStuff *)node->rn_client; + RCDelayStuff *rcd2; - ASSERT(rcd != NULL,"ResCalculateTdi"); - if (resistor == NULL) - { - rcd->rc_Tdi = rcd->rc_Cdownstream*(float)resistorvalue; - } - else - { - rcd2 = (RCDelayStuff *)resistor->rr_connection1->rn_client; - ASSERT(rcd2 != NULL,"ResCalculateTdi"); - rcd->rc_Tdi=rcd->rc_Cdownstream*(float)resistor->rr_value + - rcd2->rc_Tdi; + ASSERT(rcd != NULL, "ResCalculateTdi"); + if (resistor == NULL) + rcd->rc_Tdi = rcd->rc_Cdownstream*(float)resistorvalue; + else + { + rcd2 = (RCDelayStuff *)resistor->rr_connection1->rn_client; + ASSERT(rcd2 != NULL,"ResCalculateTdi"); + rcd->rc_Tdi = rcd->rc_Cdownstream * (float)resistor->rr_value + + rcd2->rc_Tdi; + } - } - - for (workingRes = node->rn_re; workingRes != NULL; workingRes=workingRes->re_nextEl) - { - if (workingRes->re_thisEl->rr_connection1 == node && - (workingRes->re_thisEl->rr_status & RES_TDI_IGNORE) == 0) - { - ResCalculateTDi(workingRes->re_thisEl->rr_connection2, - workingRes->re_thisEl, - workingRes->re_thisEl->rr_value); - } - } + for (workingRes = node->rn_re; workingRes != NULL; workingRes = workingRes->re_nextEl) + { + if (workingRes->re_thisEl->rr_connection1 == node && + (workingRes->re_thisEl->rr_status & RES_TDI_IGNORE) == 0) + ResCalculateTDi(workingRes->re_thisEl->rr_connection2, + workingRes->re_thisEl, + workingRes->re_thisEl->rr_value); + } } /* @@ -856,71 +794,77 @@ ResCalculateTDi(node,resistor,resistorvalue) */ void -ResPruneTree(node,minTdi,nodelist1,nodelist2,resistorlist) - resNode *node,**nodelist1,**nodelist2; - float minTdi; - resResistor **resistorlist; +ResPruneTree(node, minTdi, nodelist1, nodelist2, resistorlist) + resNode *node, **nodelist1, **nodelist2; + float minTdi; + resResistor **resistorlist; { - resResistor *currentRes; - resElement *current; + resResistor *currentRes; + resElement *current; - current = node->rn_re; - while(current != NULL) - { - currentRes = current->re_thisEl; - current = current->re_nextEl; - /* if branch points outward, call routine on subtrees */ - if (currentRes->rr_connection1 == node) - { - ResPruneTree(currentRes->rr_connection2, minTdi,nodelist1,nodelist2,resistorlist); - } - } - /* We eliminate this branch if */ - /* 1. It is a terminal node, i.e. it is the connected */ - /* to only one resistor. */ - /* 2. The direction of this resistor is toward the node */ - /* (This prevents the root from being eliminated */ - /* 3. The time constant TDI is less than the tolerance. */ - if (node->rn_re != NULL && - node->rn_re->re_nextEl == NULL && - node->rn_re->re_thisEl->rr_connection2 == node) - { - if (node->rn_client == (ClientData)NULL) - { - TxError("Internal Error in Tree Pruning: Missing TDi value.\n"); - } - else if (((RCDelayStuff *)(node->rn_client))->rc_Tdi < minTdi) - { - currentRes = node->rn_re->re_thisEl; - ResDeleteResPointer(currentRes->rr_connection1,currentRes); - ResDeleteResPointer(currentRes->rr_connection2,currentRes); - ResMergeNodes(currentRes->rr_connection1,currentRes->rr_connection2,nodelist2,nodelist1); /* Patched 7/5/94 */ - ResEliminateResistor(currentRes,resistorlist); - } - } + current = node->rn_re; + while(current != NULL) + { + currentRes = current->re_thisEl; + current = current->re_nextEl; + /* if branch points outward, call routine on subtrees */ + if (currentRes->rr_connection1 == node) + ResPruneTree(currentRes->rr_connection2, minTdi, nodelist1, + nodelist2, resistorlist); + } + + /* We eliminate this branch if: + * 1. It is a terminal node, i.e. it is the connected + * to only one resistor. + * 2. The direction of this resistor is toward the node + * (This prevents the root from being eliminated + * 3. The time constant TDI is less than the tolerance. + */ + + if (node->rn_re != NULL && + node->rn_re->re_nextEl == NULL && + node->rn_re->re_thisEl->rr_connection2 == node) + { + if (node->rn_client == (ClientData)NULL) + { + TxError("Internal Error in Tree Pruning: Missing TDi value.\n"); + } + else if (((RCDelayStuff *)(node->rn_client))->rc_Tdi < minTdi) + { + currentRes = node->rn_re->re_thisEl; + ResDeleteResPointer(currentRes->rr_connection1, currentRes); + ResDeleteResPointer(currentRes->rr_connection2, currentRes); + ResMergeNodes(currentRes->rr_connection1, currentRes->rr_connection2, + nodelist2, nodelist1); + ResEliminateResistor(currentRes, resistorlist); + } + } } +/* + *------------------------------------------------------------------------- + * + *------------------------------------------------------------------------- + */ + int -ResDoSimplify(tolerance,rctol,goodies) - float tolerance; - float rctol; - ResGlobalParams *goodies; +ResDoSimplify(tolerance, rctol, goodies) + float tolerance; + float rctol; + ResGlobalParams *goodies; { - resNode *node,*slownode; + resNode *node, *slownode; float bigres = 0; float millitolerance; float totalcap; resResistor *res; - resRemoveLoops = FALSE; ResSetPathRes(); for (node = ResNodeList; node != NULL; node = node->rn_more) - { bigres = MAX(bigres,node->rn_noderes); - } bigres /= OHMSTOMILLIOHMS; /* convert from milliohms to ohms */ goodies->rg_maxres = bigres; @@ -936,238 +880,237 @@ ResDoSimplify(tolerance,rctol,goodies) (void) ResDistributeCapacitance(ResNodeList,goodies->rg_nodecap); - if ((tolerance > bigres || (ResOptionsFlags &ResOpt_Simplify)==0) && - (ResOptionsFlags &ResOpt_DoLumpFile)==0) - { - return(0); - } + if (((tolerance > bigres) || ((ResOptionsFlags & ResOpt_Simplify) == 0)) && + ((ResOptionsFlags & ResOpt_DoLumpFile) == 0)) + return 0; + res = ResResList; while (res) { - resResistor *oldres = res; + resResistor *oldres = res; - res = res->rr_nextResistor; - oldres->rr_status &= ~RES_HEAP; - if (oldres->rr_status & RES_TDI_IGNORE) - { - ResDeleteResPointer(oldres->rr_node[0],oldres); - ResDeleteResPointer(oldres->rr_node[1],oldres); - ResEliminateResistor(oldres,&ResResList); - } + res = res->rr_nextResistor; + oldres->rr_status &= ~RES_HEAP; + if (oldres->rr_status & RES_TDI_IGNORE) + { + ResDeleteResPointer(oldres->rr_node[0], oldres); + ResDeleteResPointer(oldres->rr_node[1], oldres); + ResEliminateResistor(oldres, &ResResList); + } } - if (ResOptionsFlags & ResOpt_Tdi) - { - if (goodies->rg_nodecap != -1 && + if (ResOptionsFlags & ResOpt_Tdi) + { + if (goodies->rg_nodecap != -1 && (totalcap = ResCalculateChildCapacitance(ResOriginNode)) != -1) - { - RCDelayStuff *rc = (RCDelayStuff *) ResNodeList->rn_client; + { + RCDelayStuff *rc = (RCDelayStuff *) ResNodeList->rn_client; - goodies->rg_nodecap = totalcap; - ResCalculateTDi(ResOriginNode,(resResistor *)NULL, + goodies->rg_nodecap = totalcap; + ResCalculateTDi(ResOriginNode, (resResistor *)NULL, goodies->rg_bigdevres); - if (rc != (RCDelayStuff *)NULL) - goodies->rg_Tdi = rc->rc_Tdi; - else - goodies->rg_Tdi = 0; + if (rc != (RCDelayStuff *)NULL) + goodies->rg_Tdi = rc->rc_Tdi; + else + goodies->rg_Tdi = 0; - slownode = ResNodeList; - for (node = ResNodeList; node != NULL; node = node->rn_more) - { - rc = (RCDelayStuff *)node->rn_client; - if (rc && (goodies->rg_Tdi < rc->rc_Tdi)) - { - slownode = node; - goodies->rg_Tdi = rc->rc_Tdi; - } - } - slownode->rn_status |= RN_MAXTDI; - } - else - { - goodies->rg_Tdi = -1; - } + slownode = ResNodeList; + for (node = ResNodeList; node != NULL; node = node->rn_more) + { + rc = (RCDelayStuff *)node->rn_client; + if ((rc != NULL) && (goodies->rg_Tdi < rc->rc_Tdi)) + { + slownode = node; + goodies->rg_Tdi = rc->rc_Tdi; + } + } + slownode->rn_status |= RN_MAXTDI; + } + else + goodies->rg_Tdi = -1; } else - { goodies->rg_Tdi = 0; - } - if ((rctol+1)*goodies->rg_bigdevres*goodies->rg_nodecap > - rctol*goodies->rg_Tdi && - (ResOptionsFlags & ResOpt_Tdi) && - goodies->rg_Tdi != -1) - { - return(0); - } + + if ((rctol+1) * goodies->rg_bigdevres * goodies->rg_nodecap > + rctol * goodies->rg_Tdi && + (ResOptionsFlags & ResOpt_Tdi) && + goodies->rg_Tdi != -1) + return 0; + /* Simplify network; resistors are still in milliohms, so use - millitolerance. - */ + * millitolerance. + */ if (ResOptionsFlags & ResOpt_Simplify) { + millitolerance = tolerance * MILLIOHMSPEROHM; - millitolerance = tolerance*MILLIOHMSPEROHM; - - /* - Start simplification at driver (R=0). Remove it from the done list - and add it to the pending list. Call ResSimplifyNet as long as nodes - remain in the pending list. + /* + * Start simplification at driver (R=0). Remove it from the done list + * and add it to the pending list. Call ResSimplifyNet as long as + * nodes remain in the pending list. */ - for (node = ResNodeList; node != NULL ;node = node->rn_more) - { - if (node->rn_noderes == 0) - { - ResOriginNode = node; - } - node->rn_status |= FINISHED; - } - if (ResOriginNode != NULL) - { + for (node = ResNodeList; node != NULL; node = node->rn_more) + { + if (node->rn_noderes == 0) + ResOriginNode = node; - /* if Tdi is enabled, prune all branches whose end nodes have */ - /* time constants less than the tolerance. */ + node->rn_status |= FINISHED; + } + if (ResOriginNode != NULL) + { - if ((ResOptionsFlags & ResOpt_Tdi) && + /* if Tdi is enabled, prune all branches whose end nodes */ + /* have time constants less than the tolerance. */ + + if ((ResOptionsFlags & ResOpt_Tdi) && goodies->rg_Tdi != -1 && rctol != 0) - { - ResPruneTree(ResOriginNode, - (rctol+1)*goodies->rg_bigdevres*goodies->rg_nodecap/rctol, - &ResNodeList,&ResNodeQueue,&ResResList); - } - ResOriginNode->rn_status &= ~MARKED; - if (ResOriginNode->rn_less == NULL) - { - ResNodeList = ResOriginNode->rn_more; - } - else - { - ResOriginNode->rn_less->rn_more = ResOriginNode->rn_more; - } - if (ResOriginNode->rn_more != NULL) - { - ResOriginNode->rn_more->rn_less = ResOriginNode->rn_less; - } - ResOriginNode->rn_more = NULL; - ResOriginNode->rn_less = NULL; - ResNodeQueue = ResOriginNode; - while (ResNodeQueue != NULL) - { - ResSimplifyNet(&ResNodeQueue,&ResNodeList,&ResResList,millitolerance); - } + { + ResPruneTree(ResOriginNode, (rctol + 1) * + goodies->rg_bigdevres * goodies->rg_nodecap / rctol, + &ResNodeList, &ResNodeQueue, &ResResList); + } + ResOriginNode->rn_status &= ~MARKED; + if (ResOriginNode->rn_less == NULL) + ResNodeList = ResOriginNode->rn_more; + else + ResOriginNode->rn_less->rn_more = ResOriginNode->rn_more; - /* - Call ResScrunchNet to eliminate any remaining under tolerance - resistors. + if (ResOriginNode->rn_more != NULL) + ResOriginNode->rn_more->rn_less = ResOriginNode->rn_less; + + ResOriginNode->rn_more = NULL; + ResOriginNode->rn_less = NULL; + ResNodeQueue = ResOriginNode; + while (ResNodeQueue != NULL) + ResSimplifyNet(&ResNodeQueue,&ResNodeList,&ResResList,millitolerance); + + /* + * Call ResScrunchNet to eliminate any remaining under tolerance + * resistors. */ - ResScrunchNet(&ResResList,&ResNodeQueue,&ResNodeList,millitolerance); - } - } - return(0); - + ResScrunchNet(&ResResList,&ResNodeQueue,&ResNodeList,millitolerance); + } + } + return 0; } +/* + *------------------------------------------------------------------------- + * + *------------------------------------------------------------------------- + */ + void ResSetPathRes() - { - HeapEntry he; - resNode *node; - static int init=1; + HeapEntry he; + resNode *node; + static int init = 1; - if (init) - { - init = 0; - HeapInit(&ResistorHeap,128,FALSE,FALSE); - } + if (init) + { + init = 0; + HeapInit(&ResistorHeap, 128, FALSE, FALSE); + } - for (node = ResNodeList; node != NULL ;node = node->rn_more) - { - if (node->rn_noderes == 0) - { - ResOriginNode = node; - node->rn_status |= FINISHED; - } - else - { - node->rn_noderes = RES_INFINITY; - node->rn_status &= ~FINISHED; - } - } - if (ResOriginNode == NULL) - { - resDevice *res = ResGetDevice(gparams.rg_devloc); - ResOriginNode = res->rd_fet_source; - ResOriginNode->rn_why = RES_NODE_ORIGIN; - ResOriginNode->rn_noderes = 0; - } - ASSERT(ResOriginNode != NULL,"ResDoSimplify"); - resPathNode(ResOriginNode); - while (HeapRemoveTop(&ResistorHeap,&he)) - { - resPathRes((resResistor *) he.he_id); - } + for (node = ResNodeList; node != NULL; node = node->rn_more) + { + if (node->rn_noderes == 0) + { + ResOriginNode = node; + node->rn_status |= FINISHED; + } + else + { + node->rn_noderes = RES_INFINITY; + node->rn_status &= ~FINISHED; + } + } + if (ResOriginNode == NULL) + { + resDevice *res = ResGetDevice(gparams.rg_devloc); + ResOriginNode = res->rd_fet_source; + ResOriginNode->rn_why = RES_NODE_ORIGIN; + ResOriginNode->rn_noderes = 0; + } + ASSERT(ResOriginNode != NULL, "ResDoSimplify"); + resPathNode(ResOriginNode); + while (HeapRemoveTop(&ResistorHeap,&he)) + resPathRes((resResistor *)he.he_id); } +/* + *------------------------------------------------------------------------- + * + *------------------------------------------------------------------------- + */ + void resPathNode(node) - resNode *node; + resNode *node; { - resElement *re; + resElement *re; - node->rn_status |= FINISHED; - for (re = node->rn_re;re;re=re->re_nextEl) - { - resResistor *res = re->re_thisEl; - resNode *node2; + node->rn_status |= FINISHED; + for (re = node->rn_re; re; re = re->re_nextEl) + { + resResistor *res = re->re_thisEl; + resNode *node2; - if (res->rr_status & RES_HEAP) continue; - if ((node2=res->rr_node[0]) == node) node2 = res->rr_node[1]; - if ((node2->rn_status & FINISHED) == 0) - { - HeapAddInt(&ResistorHeap, node->rn_noderes + res->rr_value, + if (res->rr_status & RES_HEAP) continue; + if ((node2 = res->rr_node[0]) == node) node2 = res->rr_node[1]; + if ((node2->rn_status & FINISHED) == 0) + HeapAddInt(&ResistorHeap, node->rn_noderes + res->rr_value, (char *)res); - } - } + } } +/* + *------------------------------------------------------------------------- + * + *------------------------------------------------------------------------- + */ + void resPathRes(res) - resResistor *res; + resResistor *res; { - resNode *node0,*node1; - int flag0,flag1; + resNode *node0, *node1; + int flag0, flag1; - res->rr_status |= RES_HEAP; - res->rr_status &= ~RES_MARKED; - node0 = res->rr_node[0]; - node1 = res->rr_node[1]; - flag0 = node0->rn_status & FINISHED; - flag1 = node1->rn_status & FINISHED; - if (flag0 && flag1) - { - res->rr_status |= RES_TDI_IGNORE; - if (resRemoveLoops) - { - ResDeleteResPointer(node0,res); - ResDeleteResPointer(node1,res); - ResEliminateResistor(res,&ResResList); - } - } - else if (flag0) - { - node1->rn_noderes = node0->rn_noderes+res->rr_value; - resPathNode(node1); - } - else - { - ASSERT(flag1,"ResPathRes"); - res->rr_node[0] = node1; - res->rr_node[1] = node0; - node0->rn_noderes = node1->rn_noderes+res->rr_value; - resPathNode(node0); - } + res->rr_status |= RES_HEAP; + res->rr_status &= ~RES_MARKED; + node0 = res->rr_node[0]; + node1 = res->rr_node[1]; + flag0 = node0->rn_status & FINISHED; + flag1 = node1->rn_status & FINISHED; + if (flag0 && flag1) + { + res->rr_status |= RES_TDI_IGNORE; + if (resRemoveLoops) + { + ResDeleteResPointer(node0, res); + ResDeleteResPointer(node1, res); + ResEliminateResistor(res, &ResResList); + } + } + else if (flag0) + { + node1->rn_noderes = node0->rn_noderes + res->rr_value; + resPathNode(node1); + } + else + { + ASSERT(flag1, "ResPathRes"); + res->rr_node[0] = node1; + res->rr_node[1] = node0; + node0->rn_noderes = node1->rn_noderes + res->rr_value; + resPathNode(node0); + } } diff --git a/utils/heap.c b/utils/heap.c index 7666ed94..c2797c54 100644 --- a/utils/heap.c +++ b/utils/heap.c @@ -417,11 +417,12 @@ HeapAdd(heap, pKey, id) { /* If odd then new entry is the right half of a pair */ cmp = i; - if (i & 1) + if ((i & 1) && (i != 1)) KEY_LE_COND(keyType, list, i, i-1, cmp = i-1); /* Find parent. If 0 then at the root so quit */ if ((i >>= 1) == 0) return; + KEY_LE_COND(keyType, list, cmp, i, return); list[0] = list[cmp]; list[cmp] = list[i]; list[i] = list[0]; heapify(heap, cmp); @@ -434,11 +435,12 @@ HeapAdd(heap, pKey, id) { /* If odd then new entry is the right half of a pair */ cmp = i; - if (i & 1) + if ((i & 1) && (i != 1)) KEY_GE_COND(keyType, list, i, i-1, cmp = i-1); /* Find parent. If 0 then at the root so quit */ if ((i >>= 1) == 0) return; + KEY_GE_COND(keyType, list, cmp, i, return); list[0] = list[cmp]; list[cmp] = list[i]; list[i] = list[0]; heapify(heap, cmp);