Algorithm Search⌘K

Problemadvanced

Scan chain ordering

Also called scan chain reordering, scan stitching.

Order the flip-flops of each scan chain after placement so that the scan wiring is shortest, a travelling salesman problem with ends and hold constraints.

Scan chain ordering chooses, after placement, the order in which the flip-flops of a scan design are linked into chains. For test, any order works: the tester shifts the patterns through whatever order is chosen. For the layout, the order fixes the scan wires, one from the scan-in pin to the first flip-flop, one from each flip-flop to the next, and one from the last to the scan-out pin. Making their total length least is a shortest Hamiltonian path between two fixed ends, so the problem is a form of the traveling salesman problem and is NP-hard even with Manhattan distances on a grid. Real instances add constraints: chains of equal length, flip-flops of one clock domain together, and no hold-time violation on any scan wire.

In plain words

After the chip is laid out, every storage cell that is part of a test chain sits at a fixed spot. The test chain must visit every cell once, start at the input pin and end at the output pin. The order does not matter for testing, so we pick the order whose wires are shortest. This is like a delivery route that must start at one depot, end at another and visit every customer once, with the customers being the cells. Finding the very best route is hard when there are many cells, so tools use good routes found quickly.

Definition

Input. Points ss (the scan-in pin), ee (the scan-out pin) and x1,…,xnx_1, \ldots, x_n (the placed scan flip-flops), and a distance d(p,q)≥0d(p, q) \ge 0 for the wire from pp to qq. On a chip dd is usually the Manhattan distance ∣px−qx∣+∣py−qy∣|p_x - q_x| + |p_y - q_y|, which is a lower bound on a routed two-pin wire.

Output. A permutation π\pi of {1,…,n}\{1, \ldots, n\}, the order of the chain.

Goal. Minimize the wire length

W(π)=d(s,xπ(1))+∑i=1n−1d(xπ(i),xπ(i+1))+d(xπ(n),e).W(\pi) = d(s, x_{\pi(1)}) + \sum_{i=1}^{n-1} d(x_{\pi(i)}, x_{\pi(i+1)}) + d(x_{\pi(n)}, e).

This is a shortest Hamiltonian path with fixed ends. Let GG be the complete graph on {s,e,x1,…,xn}\{s, e, x_1, \ldots, x_n\} with edge weights dd. A permutation π\pi is the same thing as a Hamiltonian path of GG from ss to ee, namely s,xπ(1),…,xπ(n),es, x_{\pi(1)}, \ldots, x_{\pi(n)}, e, since such a path visits each xix_i exactly once between its fixed ends, and W(π)W(\pi) is the weight of that path. So the orders of least wire length are exactly the shortest Hamiltonian ss-ee paths of GG.

And a traveling salesman tour. Merge ss and ee into one depot oo with the costs c(o,xi)=d(s,xi)c(o, x_i) = d(s, x_i) for leaving and c(xi,o)=d(xi,e)c(x_i, o) = d(x_i, e) for returning, and c(xi,xj)=d(xi,xj)c(x_i, x_j) = d(x_i, x_j). A tour o,xπ(1),…,xπ(n),oo, x_{\pi(1)}, \ldots, x_{\pi(n)}, o costs exactly W(π)W(\pi), and every tour has this form after rotating it to start at oo. So the problem is an asymmetric TSP on n+1n + 1 cities. A symmetric form keeps ss and ee apart and sets the weight of the edge ss-ee to −M-M for a large MM, so that every optimal tour uses that edge, and removing it leaves the path.

Variants

  • Several chains. With cc chains, each with its own pins, the flip-flops must also be split into cc groups. Test time grows with the longest chain, so the groups must have equal size, within one. This is close to the vehicle routing problem with equal loads.
  • Clock domains and edges. Flip-flops on different clocks, or on rising and falling edges of one clock, should be kept in separate chains or separate segments, with a lockup latch at each crossing. The order is then a path inside each group, plus an order of the groups.
  • Hold constraints. A scan wire has no logic, so a short wire between two flip-flops whose clocks arrive with skew can violate the hold constraint. Some pairs must not be neighbors, or need a delay buffer, which turns some edge weights into infinite or penalized ones.
  • Reordering with partial freedom. Some flip-flops must keep a fixed order, for example those of a shift register already wired in the logic, which are treated as one city with an entry and an exit point.
  • Routing congestion. The scan wires compete with the functional wires for routing tracks, so the cost may weight wires through crowded regions more.

Examples

Take the pins s=(0,0)s = (0, 0) and e=(10,0)e = (10, 0) and five flip-flops A=(2,3)A = (2, 3), B=(8,1)B = (8, 1), C=(5,4)C = (5, 4), D=(3,0)D = (3, 0) and E=(7,5)E = (7, 5), with Manhattan distance.

order wire lengths total
A,B,C,D,EA, B, C, D, E (the netlist order) 5 + 8 + 6 + 6 + 9 + 8 42
D,A,C,E,BD, A, C, E, B (the best) 3 + 4 + 4 + 3 + 5 + 3 22

Of the 5!=1205! = 120 orders, D,A,C,E,BD, A, C, E, B is the only one of length 22, and the worst one is 52. The netlist order, as written by synthesis, ignores the layout, so its wires cross the block several times.

Known algorithms

Bounds

  • Hardness. Deciding whether the wire length can be at most a given number is NP-complete, even when the points lie on an integer grid and dd is the Manhattan distance. Let HH be a grid graph, that is a finite set of grid points with edges between points at distance 1, and let u,vu, v be two of its points. Put s=us = u, e=ve = v and one flip-flop at every other point of HH. Every distance between distinct grid points is at least 1, and an order has n+1n + 1 wires, so W(π)≥n+1W(\pi) \ge n + 1, with equality exactly when every wire joins neighbors of HH, that is when the order is a Hamiltonian path of HH from uu to vv. A graph with at least 3 points has a Hamilton circuit exactly when, for some edge uvuv, it has a Hamiltonian path from uu to vv. Itai, Papadimitriou and Szwarcfiter (1982) showed that the Hamilton circuit problem is NP-complete for grid graphs, so a polynomial algorithm for scan ordering, run once per edge, would decide an NP-complete problem.
  • Lower bounds. The path s,xπ(1),…,xπ(n),es, x_{\pi(1)}, \ldots, x_{\pi(n)}, e is a spanning tree of all n+2n + 2 points, so W(π)W(\pi) is at least the weight of a minimum spanning tree of {s,e,x1,…,xn}\{s, e, x_1, \ldots, x_n\}. This bound is quick to compute and shows how far a heuristic order can be from the best.
  • Approximation. With a metric dd, Hoogeveen (1991) showed that Christofides' method adapted to a path with two fixed ends is within a factor 5/35/3, and Zenklusen (2019) gave a factor 3/23/2, as for tours. In practice, tools use local search, whose results are compared with the lower bound above.
  • Exact. Dynamic programming over subsets solves nn flip-flops in O(2nn2)O(2^n n^2) time, so only for small groups, such as the cells of one region after partitioning.

Reductions

  • Scan chain ordering is a shortest Hamiltonian path with fixed ends, and an asymmetric TSP with one depot, as shown in the definition. Every TSP method applies.
  • The Hamiltonian path problem in grid graphs reduces to it, as in the hardness bound, so it is not easier than general metric path TSP in the worst case.
  • With cc chains of equal length it contains a balanced partition of the points, as in vehicle routing.

Applications

  • Physical design flows. Synthesis inserts scan in an arbitrary order. After placement, the tool removes the scan connections, orders the flip-flops by region, and reconnects them. The result is checked again for hold time after clock tree synthesis.
  • Test compression. With scan compression, the chains are short and many, so ordering is mostly a partition of the flip-flops into nearby groups of equal size, with a short path inside each group.
  • Low-power test. Some methods order the flip-flops so that neighbors in the chain often hold equal values in the test patterns, which reduces switching during shift. The cost then mixes wire length with a count of transitions.

References

  1. Samy Makar, A layout-based approach for ordering scan chain flip-flops, Proceedings of the International Test Conference, 341 to 347, 1998, the ordering of scan flip-flops from their placed positions as a traveling salesman path, with heuristics and the constraints of clock domains
  2. M. Hirech, J. Beausang and X. Gu, A new approach to scan chain reordering using physical design information, Proceedings of the International Test Conference, 348 to 355, 1998, reordering scan chains after placement, with the scan-in and scan-out pins as fixed ends
  3. A. Itai, C. H. Papadimitriou and J. L. Szwarcfiter, Hamilton paths in grid graphs, SIAM Journal on Computing 11(4), 676 to 686, 1982, the NP-completeness of the Hamilton circuit problem for grid graphs
  4. Laung-Terng Wang, Cheng-Wen Wu and Xiaoqing Wen, VLSI Test Principles and Architectures, Morgan Kaufmann, 2006, the chapter on design for testability (scan chain stitching and reordering after placement)

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a known algorithm
  • a contract.yaml