The idea: cover the logic with the cells the library really has

After synthesis and logic optimization, a circuit is still made of generic gates. A chip can only use the cells of its standard-cell library: INV, NAND2, NAND3, NOR2, AOI22 and a few hundred more, each with a known area and delay. Technology mapping picks which cells to use. It writes the logic as a graph of tiny nodes, writes every cell as a small pattern of the same nodes, and then covers the graph with patterns at the lowest total cost.

The subject graph of f = (ab + cd)': NAND n1 of a and b, NAND n2 of c and d, NAND n3 of n1 and n2, inverter n4. Cover 1 uses one cell per node, three NAND2 and an INV, area 7. Cover 2 uses one AOI22 for all four nodes, area 4
The same four nodes, covered two ways: four cells with area 7, or one AOI22 with area 4.

The canvas runs the classic method, tree covering by dynamic programming. The subject graph is on the left, the library and the cost table on the right. Press Next Node to handle one node, or Map All.

This page starts where other pages stop. From Verilog to Hardware shows the generic gates synthesis builds from code. Multilevel Logic shows why NAND and NOR are the natural CMOS gates and how bubble pushing turns AND-OR into NAND-NAND. Karnaugh maps minimize two-level logic by hand. None of them choose real cells.

The subject graph: NAND2 and INV only

First the logic is decomposed into a subject graph that has just two kinds of node: N, a 2-input NAND, and I, an inverter. Any function can be written this way. For f = (ab + cd)':

  • n1 = N(a, b) and n2 = N(c, d) are (ab)' and (cd)'.
  • n3 = N(n1, n2) = ab + cd, by De Morgan.
  • n4 = I(n3) = f.

With one cell per node this is 3 NAND2 + 1 INV, area 3 · 2 + 1 = 7. That is the baseline the mapper has to beat.

Library cells as pattern trees

Each cell is written in the same N and I nodes. The letters are the cell's inputs. A pattern matches at a node when its shape fits the subject graph there, with N on N and I on I. A 2-input N may match with its inputs in either order.

The pattern trees of the five cells: INV is one I node; NAND2 one N node; NAND3 is N of x and I of N of y and z; NOR2 is I of N of I of x and I of y; AOI22 is I of N of N of w and x and N of y and z
Five cells as N/I pattern trees. A bigger pattern swallows more nodes in one cell.
CellFunctionPatternAreaDelay
INVx'I(x)11 + 1·load
NAND2(xy)'N(x, y)22 + 2·load
NAND3(xyz)'N(x, I(N(y, z)))33 + 3·load
NOR2(x + y)'I(N(I(x), I(y)))22 + 2·load
AOI22(wx + yz)'I(N(N(w, x), N(y, z)))44 + 2·load

INV and NAND2 match every node, so a cover always exists. The other three cells are there to do better.

Tree covering by dynamic programming

The mapper visits the nodes from the inputs to the output. At each node it lists every match. The cost of a match is the cell's own cost plus the best costs already stored for the nodes that feed it. The node keeps only its cheapest match. A node higher up never looks below its inputs again: it just reads their stored numbers. That is dynamic programming, and on a tree it finds the cheapest cover in time linear in the number of nodes (times the number of patterns).

NodeMatches (area)Kept
n1NAND2: 2 + 0 = 2NAND2, 2
n2NAND2: 2 + 0 = 2NAND2, 2
n3NAND2: 2 + 2 + 2 = 6NAND2, 6
n4INV: 1 + 6 = 7; AOI22: 4 + 0 = 4AOI22, 4

AOI22 matches at n4 and swallows n1, n2 and n3; its inputs are the primary inputs a, b, c, d, which cost nothing. Then the cover is read back from the output: take n4's best match, then the best match of each node that match uses as an input. Here there is none: the netlist is a single AOI22, area 4 instead of 7. The panel checks the netlist against the subject graph on all 16 input rows. Demo: area, one AOI22 beats four gates.

Delay as the cost

The same DP works for delay. A node's number is now its arrival time: the latest arrival at the match's inputs, plus the cell's delay. On the page a cell's delay is p + k · load. Here p is the delay with no load, k is how weak its output is, and the load counts the gate inputs the net drives, plus the output pin's load. A complex gate has transistors in series, so a small AOI22 is a weak driver (k = 2), while an INV is strong (k = 1).

Output loadINV over three NAND2AOI22Chosen
18 + 1 + 1 = 100 + 4 + 2 = 6AOI22, delay 6, area 4
88 + 1 + 8 = 170 + 4 + 16 = 20NAND2 ×3 + INV, delay 17, area 7

With a light load the AOI22 is both smaller and faster. With a heavy load it pays 2 per unit of load, and the strong INV at the end wins, for more area. Same graph, same library, different cost, different netlist. Demo: delay, light load and Demo: delay, heavy load.

A deeper tree: NAND3 and NOR2

h = (c · d · (a + b)')' decomposes into 7 nodes; one cell each would cost area 10. At n4 the NOR2 pattern I(N(I(a), I(b))) swallows four nodes for area 2 instead of 5. At n7, the root, NAND3 matches as N(c, I(N(d, n4))): 3 + 2 = 5, against NAND2 over the rest at 2 + 5 = 7. The cover is NAND3(c, d, NOR2(a, b)): two cells, area 5. Demo: NAND3 and NOR2 cover h.

With output load 8 the NAND3, the weakest driver in the library (k = 3), loses at the root: 4 + 3 + 24 = 31 against 10 + 2 + 16 = 28 for a NAND2. The result is NAND2(c, INV(NAND2(d, NOR2(a, b)))), area 7, delay 28. Demo: h with a heavy load.

Fan-out cuts the DAG into trees

Real logic shares signals, so the subject graph is a DAG, not a tree. If f = (ab + cd)' and g = (abe)' both use n1 = N(a, b), n1 has a fan-out of 2. A pattern cannot swallow n1 inside f's cover, because g needs n1's output too. Tree covering therefore cuts the graph at every fan-out point. n1 becomes the root of its own tree, and a plain input for the trees that use it. Each tree is mapped alone.

Left, the DAG cut at n1 into trees T1, T2 and T3, mapped as NAND2, then NAND2 + NAND2 + INV, then INV + NAND2: area 2 + 5 + 3 = 10. Right, the same logic with NAND(a, b) copied into both cones: f is one AOI22 and g one NAND3, area 4 + 3 = 7
Cutting at the fan-out point loses the AOI22 and the NAND3: area 10. Copying the shared NAND would give 7.

On the page the three trees cost 2 + 5 + 3 = 10. AOI22 no longer matches at f, and NAND3 no longer matches at g, because both would have to reach inside n1's tree. Copying NAND(a, b) into both cones would allow area 4 + 3 = 7. So tree covering is optimal for each tree, but not for the whole circuit. Real mappers add tricks for this: they let patterns cross fan-out points and copy the logic, or match on the DAG directly. Demo: fan-out cuts the DAG into trees.

Where mapping sits in the flow

RTL is first turned into generic logic, as in From Verilog to Hardware. It is then optimized without any library in mind, for example by algebraic factoring, with binary decision diagrams used to check that nothing changed. Technology mapping comes next. After it, the netlist is sized (logical effort sizing), placed and routed, and checked with static timing analysis. The whole chain is on the ASIC design flow page.

The decomposition matters. A different NAND2/INV graph for the same function can allow different matches, so the mapper's result depends on the shape it is handed.

See also Binary Decision Diagrams for checking that a mapped netlist still computes the same function as the original.

See also Stuck-at Faults and Test Generation, which generates manufacturing tests for a mapped gate netlist.

See also Standard-Cell Place and Route, which places the mapped library cells in rows and routes the nets between them.

What the page leaves out

  • Real delay comes from tables indexed by input slew and output load, and the load of a net depends on the cells chosen above it. Mappers handle this with load bins or by mapping again after sizing; the page fixes the load of every inside net at 1.
  • Real libraries have hundreds of cells in several drive strengths (INV_X1, INV_X4, …), and also XOR, mux, OAI and flip-flop cells.
  • Duplication across fan-out points, DAG covering, and cut-based mapping as in ABC or FPGA LUT mappers are only mentioned.
  • The decomposition step is fixed here; tools try several decompositions and choose between them.
  • Placement, wire delay and power as a cost are not modelled.

On the mind map

Open the Computer Architecture mind mapComputerArchitectureAbstraction and numbers: layers and bit patternsAbstraction and numbersCombinational logic: output depends only on inputsCombinational logicSequential logic: state held by a clockSequential logicMIPS software: how C becomes machine wordsMIPS softwareThe processor: datapath plus controlThe processorPipelines and parallelism: more instructions at oncePipelines and parallelismMemory and I/O: small fast near, big slow farMemory and I/OLogic gatesLogic gatestruth table row picks the outputAdders, muxes, ALUAdders, muxes, ALUcritical path sets the delayMux, decoder, encoderMux, decoder, encoderSelect bits pick one input; decoder one lineBubble pushingBubble pushingDe Morgan: AND-OR becomes NAND-NANDAlgebraic factoringAlgebraic factoringShare kernels: 17 → 9 literalsTechnology mappingCheapest pattern per node, reused upwardFast arithmeticFast arithmeticlookahead carry beats ripple carryBCD and Gray CodesBCD and Gray CodesBCD adder: sum > 9 or carry → add 6Multiply/divide hardwareMultiply/divide hardwareadd or subtract, then shift, once per bitVerilog to hardwareVerilog to hardwareassign gives gates, always_ff gives flopsVerilog testbenchVerilog testbenchGolden model + check task say PASS/FAILASIC design flowASIC design flowRTL→netlist→DEF→GDSII; slack shrinksPlace and RoutePlace and RouteAnneal by HPWL, then Lee wave routesOpen the Computer Architecture mind mapComputer Architectureoutput depends only on inputsCombinational logicLogic gatesLogic gatestruth table row picks the outputAdders, muxes, ALUAdders, muxes, ALUcritical path sets the delayMux, decoder, encoderMux, decoder, encoderSelect bits pick one input; decoder one lineBubble pushingBubble pushingDe Morgan: AND-OR becomes NAND-NANDAlgebraic factoringAlgebraic factoringShare kernels: 17 → 9 literalsTechnology mappingCheapest pattern per node, reused upwardFast arithmeticFast arithmeticlookahead carry beats ripple carryBCD and Gray CodesBCD and Gray CodesBCD adder: sum > 9 or carry → add 6Multiply/divide hardwareMultiply/divide hardwareadd or subtract, then shift, once per bitVerilog to hardwareVerilog to hardwareassign gives gates, always_ff gives flopsVerilog testbenchVerilog testbenchGolden model + check task say PASS/FAILASIC design flowASIC design flowRTL→netlist→DEF→GDSII; slack shrinksPlace and RoutePlace and RouteAnneal by HPWL, then Lee wave routes
This page on the Computer Architecture mind map · 76 pages in 7 branches · open it to see the whole map and test yourself in recall mode.