<> <> <> <> <> DIRECTORY Basics, CD, CDBasics, CDCells, CDPinObjects, CDProperties, Properties, Real, Rope, Route, RoutePrivate, RouteChannel, RouteTechnology, RouteUtil; RouteUtilImpl: CEDAR PROGRAM IMPORTS CDBasics, CDCells, CDPinObjects, CDProperties, Properties, Real, Route, RouteChannel, RouteTechnology, RouteUtil EXPORTS RouteUtil = BEGIN LayerToRoutingLayer: PUBLIC PROC [routingArea: Route.RoutingArea, layer: Route.Layer] RETURNS [routingLayer: RoutePrivate.RoutingLayer] = BEGIN trunkLayer: Route.Layer _ routingArea.rules.trunkLayer; branchLayer: Route.Layer _ routingArea.rules.branchLayer; IF layer = trunkLayer THEN routingLayer _ trunk ELSE IF layer = branchLayer THEN routingLayer _ branch ELSE Route.Error[programmingError, "Invalid layer"]; END; RoutingLayerToLayer: PUBLIC PROC [routingArea: Route.RoutingArea, routingLayer: RoutePrivate.RoutingLayer] RETURNS [layer: Route.Layer] = BEGIN trunkLayer: Route.Layer _ routingArea.rules.trunkLayer; branchLayer: Route.Layer _ routingArea.rules.branchLayer; IF routingLayer = trunk THEN layer _ trunkLayer ELSE IF routingLayer = branch THEN layer _ branchLayer ELSE Route.Error[programmingError, "Invalid routing layer"]; END; GetNumberProp: PUBLIC PROC [properties: Route.PropList, key: ATOM, default: Route.Number] RETURNS [Route.Number] = BEGIN atomRef: REF ATOM _ NEW[ATOM _ key]; valRef: REF ANY _ Properties.GetProp[properties, atomRef]; IF valRef # NIL THEN default _ NARROW[valRef, REF Route.Number]^; RETURN [default]; END; PutNumberProp: PUBLIC PROC [properties: Route.PropList, key: ATOM, number: Route.Number] RETURNS [Route.PropList] = BEGIN keyRef: REF ATOM _ NEW[ATOM _ key]; valRef: REF Route.Number _ NEW[Route.Number _ number]; RETURN[Properties.PutProp[properties, keyRef, valRef]]; END; Length: PUBLIC PROC [pos1, pos2: Route.Position] RETURNS [length: Route.Number] = { <> <<>> length _ Real.RoundLI[Real.SqRt[Real.FAdd[Real.FMul[Real.FSub[pos1.x, pos2.x], Real.FSub[pos1.x, pos2.x]], Real.FMul[Real.FSub[pos1.y, pos2.y], Real.FSub[pos1.y, pos2.y]]]]]}; XYToPQ: PUBLIC PROC [routingArea: Route.RoutingArea, pos: Route.Position] RETURNS [pqPos: RoutePrivate.PQPosition] = <> <<>> BEGIN chanDirection: Route.Direction _ routingArea.rules.trunkDirection; SELECT chanDirection FROM horizontal => RETURN[[pos.x, pos.y]]; vertical => RETURN[[pos.y, pos.x]]; ENDCASE; END; PQToXY: PUBLIC PROC [routingArea: Route.RoutingArea, pqPos: RoutePrivate.PQPosition] RETURNS [pos: Route.Position] = <> <<>> BEGIN chanDirection: Route.Direction _ routingArea.rules.trunkDirection; SELECT chanDirection FROM horizontal => RETURN[[pqPos.p, pqPos.q]]; vertical => RETURN[[pqPos.q, pqPos.p]]; ENDCASE; END; SimpleCompare: PUBLIC PROCEDURE [result1, result2: Route.Number] RETURNS [result: Basics.Comparison] = { result _ IF result1 < result2 THEN less ELSE IF result1 > result2 THEN greater ELSE equal }; CompareResult: PUBLIC PROCEDURE [result1, result2: Route.RoutingResult] RETURNS [result: Basics.Comparison] = { result _ RouteUtil.SimpleCompare[result1.numIncompletes, result2.numIncompletes]; IF result # equal THEN RETURN; result _ RouteUtil.SimpleCompare[result1.numTrunkTracks, result2.numTrunkTracks]; IF result # equal THEN RETURN; result _ RouteUtil.SimpleCompare[result1.polyLength, result2.polyLength]; IF result # equal THEN RETURN; result _ RouteUtil.SimpleCompare[result1.polyToMetal, result2.polyToMetal]; IF result # equal THEN RETURN; result _ RouteUtil.SimpleCompare[result1.metalToMetal2, result2.metalToMetal2]; IF result # equal THEN RETURN; result _ RouteUtil.SimpleCompare[result1.metalLength, result2.metalLength]; IF result # equal THEN RETURN; result _ RouteUtil.SimpleCompare[result1.metal2Length, result2.metal2Length]; RETURN; }; -- CompareResult CreateCDPin: PUBLIC PROC [name: Rope.ROPE, rect: CD.Rect, lev: CD.Layer_CD.combined] RETURNS [cdPin: CD.Instance] = { <> <<>> r: CD.Rect _ CDBasics.NormalizeRect[rect]; cdPin _ CDPinObjects.CreatePinInstance[name, r, lev]}; GetPinWidth: PUBLIC PROC [routingArea: Route.RoutingArea, connections: Route.PinList, channelDirection: Route.Direction] RETURNS [widestBranchPin, widestTrunkPin: Route.Number _ 0] = { <> FOR list: Route.PinList _ connections, list.rest WHILE list # NIL DO old: Route.Pin _ list.first; oldWidth: Route.Number; chanSide: RouteChannel.ChanSide _ RouteChannel.ExtSideToIntSide[routingArea, old.side]; SELECT old.side FROM bottom, top => oldWidth _ old.pin.ob.size.x; left, right => oldWidth _ old.pin.ob.size.y; ENDCASE; SELECT chanSide FROM chanBottom, chanTop => widestBranchPin _ MAX[widestBranchPin, oldWidth]; chanLeft, chanRight => widestTrunkPin _ MAX[widestTrunkPin, oldWidth]; ENDCASE; ENDLOOP}; Include: PUBLIC PROC [cell: CD.Object_NIL, ob: CD.Object, position: CD.Position_[0, 0], orientation: CD.Orientation_0] RETURNS [application: CD.Instance] = { <> application _ CDCells.IncludeOb[design: NIL, cell: cell, ob: ob, position: position, orientation: orientation, cellCSystem: originCoords, obCSystem: originCoords, mode: dontPropagate].newInst}; AddPin: PUBLIC PROC [obj: Route.Object, pin: Route.Pin] = { pinLayer: Route.Layer _ CDPinObjects.GetLayer[pin.pin]; pinName: Rope.ROPE _ CDPinObjects.GetName[pin.pin]; pinObj: CD.Object _ CDPinObjects.CreatePinOb[pin.pin.ob.size]; application: CD.Instance _ RouteUtil.Include[obj, pinObj, pin.pin.location]; CDPinObjects.SetName[application, pinName]; CDPinObjects.SetLayer[application, pinLayer]}; AddVia: PUBLIC PROC [obj: Route.Object, name: Rope.ROPE, pos, size: Route.Position, layer1, layer2: Route.Layer] = { cell: Route.Object; minBigContact: Route.Object _ RouteTechnology.GetBigContact[[1, 1], layer1, layer2]; IF minBigContact = NIL THEN <> cell _ StitchVias[RouteTechnology.GetContact[layer1, layer2], size] ELSE { -- big contact exists, see if it is amall enough IF minBigContact.size.x <= size.x AND minBigContact.size.y <= size.y THEN cell _ RouteTechnology.GetBigContact[size, layer1, layer2] ELSE -- big contact too big, must do it with small ones cell _ StitchVias[RouteTechnology.GetContact[layer1, layer2], size] }; ReallyAddVia[obj, cell, name, pos] }; StitchVias: PROC [contact: Route.Object, size: Route.Position] RETURNS [obj: Route.Object _ CDCells.CreateEmptyCell[]] = { MakeXStrip: PROC [cell: Route.Object, size: Route.Position] RETURNS [obj: Route.Object _ CDCells.CreateEmptyCell[]] = { numXInts: Route.Number _ MAX[1, size.x/(cell.size.x*2)]; lastXLoc: Route.Number _ 0; FOR index: Route.Number IN [1 .. numXInts] DO [] _ RouteUtil.Include[obj, cell, [0, lastXLoc]]; lastXLoc _ lastXLoc + cell.size.x*2; ENDLOOP; [] _ CDCells.RepositionCell[obj, NIL]}; intermediate: Route.Object _ MakeXStrip[contact, size]; numYInts: Route.Number _ MAX[1, size.y/(intermediate.size.y*2)]; lastYLoc: Route.Number _ 0; FOR index: Route.Number IN [1 .. numYInts] DO [] _ RouteUtil.Include[obj, intermediate, [0, lastYLoc]]; lastYLoc _ lastYLoc + intermediate.size.y*2; ENDLOOP; [] _ CDCells.RepositionCell[obj, NIL]}; ReallyAddVia: PROC [obj: Route.Object, cell: Route.Object, name: Rope.ROPE, pos: Route.Position] = { position: CD.Position _ [pos.x - cell.size.x/2, pos.y - cell.size.y/2]; application: CD.Instance _ RouteUtil.Include[obj, cell, position]; CDProperties.PutPropOnInstance[application, $SignalName, name]}; LineToRect: PUBLIC PROC [pos1, pos2: Route.Position, width: Route.Number] RETURNS [position: CD.Position, size: CD.Position] = { <> SELECT TRUE FROM pos1.x = pos2.x => { -- line is vertical size _ [width, ABS[pos1.y - pos2.y]]; position _ [pos1.x - width/2, MIN[pos1.y, pos2.y]]}; pos1.y = pos2.y => { -- line is horizontal size _ [ABS[pos1.x - pos2.x], width]; position _ [MIN[pos1.x, pos2.x], pos1.y - width/2]}; ENDCASE => Route.Error[programmingError, "Diagional lines not allowed."]; }; END.