Algorithmcore
Tsay's exact zero-skew algorithm
Also called exact zero skew clock routing, exact zero skew.
Tsay's bottom-up merge of subtrees that puts each tapping point where the Elmore delays to both sides are equal, so the whole tree has zero skew.
- Solves
- Clock tree synthesis
- Time
- Θ(n) given_topology
- Space
- Θ(n) extra
- Where
- n = the number of clock sinks
- Model
- Real RAM
- Properties
- deterministicexactrecursive
- Evidence
- Full proofCode in 1 languages
- Origin
- Ren Song Tsay, 1991
Tsay's exact zero-skew algorithm is a clock routing algorithm: it builds a wire tree from a clock source to a set of sinks so that the Elmore delay from the root to every sink is exactly the same. It works bottom up over a given binary topology. To join two subtrees whose own skew is already zero, it computes the one point on the wire between their roots where the delays to both sides are equal, from a closed formula. When that point falls outside the wire, it puts the tap at the end of the slower subtree and makes the wire to the faster one longer than the distance. Ren-Song Tsay published it in 1991.
In plain words
A clock signal must reach every register at the same time. The clock wire forms a tree, and the delay to a register depends on the length of the wire and on the load that each piece of wire must charge.
Start with the registers as single points. Take two subtrees that the topology says to join. Each already has the same delay to all its own registers. Run a wire between their roots and find the point on it where the delay down to the left equals the delay down to the right. One formula gives this point. That point becomes the root of the joined subtree. If one side is much slower, even putting the point at its root is not enough, so the wire to the faster side is made longer, with a detour, until both match.
The problem
The input is a set of sinks with points in the plane and load capacitances , a full binary tree (the topology) whose leaves are the sinks, and the wire resistance and capacitance per unit length. Wires run horizontally and vertically, and a wire of length is modeled as an RC interconnect tree edge in the pi model: a resistor with at each end. The output is a point for each internal node of the topology and a wire length for each edge, such that the Elmore delay from the root to every sink is the same. This is the zero-skew case of clock tree synthesis.
Each subtree is summarized by its root point , its total capacitance and its delay from to each of its sinks. Two subtrees and with are merged at the tapping point at wire length from , where
The algorithm
ZERO-SKEW(topology T, sinks, r, c)- 1
if T is a sink s then - 2
return subtree with point p_s, capacitance c_s, delay 0 - 3
A ← ZERO-SKEW(left part of T); B ← ZERO-SKEW(right part of T) - 4
L ← L1 distance from p_A to p_B - 5
x ← (t_B − t_A + r L (C_B + c L / 2)) / (r L (c L + C_A + C_B)) - 6
if 0 ≤ x ≤ 1 then ℓ_A ← x L; ℓ_B ← (1 − x) L; p ← the point at length ℓ_A from p_A on a shortest path to p_B - 7
else if x < 0 then ℓ_A ← 0; ℓ_B ← the root ℓ ≥ 0 of t_B + r ℓ (c ℓ / 2 + C_B) = t_A; p ← p_A - 8
else ℓ_B ← 0; ℓ_A ← the root ℓ ≥ 0 of t_A + r ℓ (c ℓ / 2 + C_A) = t_B; p ← p_B - 9
return subtree with point p, capacitance C_A + C_B + c (ℓ_A + ℓ_B), delay t_A + r ℓ_A (c ℓ_A / 2 + C_A)
The root in line L7 is for . Lines L7 and L8 are the wire elongation cases: the wire is longer than the distance it spans, so it is routed with a detour. When the two roots coincide, and the implementation goes to line L7 or L8 by comparing and . The tapping point in line L6 is any point at those two distances; the implementation takes the path that runs horizontally first.
Example
Take four sinks with : with load 3, with load 2, with load 1 and with load 2, and the topology .
| merge | , | tapping point | ||||
|---|---|---|---|---|---|---|
| with | 10 | , | 15 | |||
| with | 6 | , | 9 | |||
| the two results | 4 | , | 28 |
In the first merge the tap is closer to , the sink with the larger load: from the delay is , and from it is . In the last merge the left subtree is slower ( against ), so the tap moves toward it: and . The Elmore delay from the root to each of the four sinks, summed as over the whole pi model tree, is . No merge needs elongation, and the total wire length is .
An elongation case: a subtree with and at and a sink with load at , with . Then , so the tap is at and the wire to the sink has length , twice the distance. Its delay is , as needed.
Correctness
The proof is in proofs/correctness.md. By the downstream form of the Elmore delay, a wire of length above a subtree whose skew is zero adds to the delay of all its sinks, so the joined subtree has zero skew if and only if the two sides balance at the tap. The skew as a function of the tap position is : the quadratic terms cancel, so it is linear and strictly increasing, with its only zero at . When the skew is positive over the whole wire, and the delay of the wire to grows without bound with its length, so a longer wire balances it.
Proof: Tsay's merge gives every subtree zero Elmore skew, and the tapping point formula is the unique balance pointfull
Wires have resistance and capacitance per unit length, in the pi model: a wire of length is a resistor with a capacitor at each end. Every sink has a load . A subtree has a root point , a total capacitance (all its sink loads and wire capacitances) and a delay . We say that is balanced when the Elmore delay from to every sink of equals . A single sink is balanced with and .
Lemma 1 (adding a wire above a subtree). Let be balanced, and connect a new point to by a wire of length . Then the Elmore delay from to every sink of is .
Proof. Use the downstream form of the Elmore delay: the delay from to a sink is the sum, over the resistors on the path from to , of the resistance times the capacitance below it. The first resistor is , and below it lie the capacitor at and all of , so it adds . Every later resistor lies inside , and the capacitance below it is the same as in alone, because the new capacitors sit at and at , which are above it. So the later resistors add the Elmore delay from to in , which is . The capacitor at is above the first resistor and adds nothing.
Lemma 2 (the skew is linear in the tap position). Let and be balanced, at L1 distance , and put the tapping point on a shortest rectilinear path between and , at wire length from and from , with . The skew , the delay from to the sinks of minus that to the sinks of , is
It is strictly increasing, and it is 0 only at with
Proof. By Lemma 1, . The terms in are . Collecting the rest: and , which gives the formula. The coefficient of is , since . Solving gives .
Lemma 3 (elongation). In Lemma 2, if , then for every , so no tapping point on a shortest path between the roots balances the merge. With the tap at and a wire of length
from to , the merge is balanced, and . The case is the mirror image, with the tap at .
Proof. means , and is increasing, so on . With the tap at , the sinks of have delay , and by Lemma 1 the sinks of have delay . The function is continuous and strictly increasing on , with and . So has one root . For the equation is , whose positive root is the formula, and for it is linear. A wire of length between two points at distance is possible as a detour (a snaked wire).
Theorem 1 (zero skew). Every subtree built by the algorithm is balanced, with the values and that the algorithm stores. So the whole tree has zero skew under the Elmore delay, and its delay from the root to every sink is at the root.
Proof. By induction on the topology. A sink is balanced. Let and be balanced and . If and , Lemma 2 puts the tap at , a point at distance from and from , and both sides have the same delay . If or , Lemma 3 gives the balanced merge with the stated wire lengths. If , the tap is the common point. When , the wire to gets the length of Lemma 3: the same argument holds, since , and when . The case is the mirror image. In all cases the new total capacitance is , which the algorithm stores.
Theorem 2 (wire use). When no merge needs elongation, each merge uses wire of length exactly , the least length that joins the two roots, so the total wire is the sum of these distances. The tree is not always the shortest zero skew tree for the topology, because the roots of the subtrees are fixed when they are merged; deferred-merge embedding delays this choice.
Proof. The tap lies on a shortest path between the roots, at distances and , which sum to . Any connected wiring that joins two points has length at least their L1 distance.
Theorem 3 (time). For sinks and a given binary topology the algorithm does merges, each with arithmetic operations and at most one square root, so it runs in time in the real RAM model.
Proof. A binary tree with leaves has internal nodes, and each merge uses a constant number of operations on the stored values of its two children.
Complexity
With the topology given, there are merges, each with a constant number of arithmetic operations and at most one square root, so the time is and the extra space is for the tree. Building the topology is a separate step; a recursive median split or a greedy pairing of near subtrees takes or more.
Properties
- Exact zero skew under the Elmore delay with the pi model, for every topology and every choice of sink loads.
- Each merge with uses exactly the distance between the two roots, the least wire that joins them.
- The tree is not of least wire length for the topology. The root of each subtree is fixed when it is built, but the next merge would often be shorter from another root with the same delays. Deferred-merge embedding keeps all such roots as a segment and picks one later.
Variants and improvements
- Linear delay. With the delay equal to the path length, the tap is at , the case that DME solves with least wire.
- Topology generation. Tsay's merge needs a topology. It can come from the recursive split of the method of means and medians, or from a greedy matching that pairs near subtrees with similar delays, which aims to avoid elongations.
- Bounded skew. If a small skew is allowed, the tap can be anywhere in an interval around , and the freedom can save wire in later merges.
- Buffered trees. Real clock trees insert buffers at some merge points. The same balance equation holds when each buffer starts a new stage, with the buffer delay added to and its input capacitance in place of .
When to use it
Use it for a clock net with a known topology when the Elmore delay of the wires is an acceptable model, for example to build a zero-skew tree on top of a placement, or as the merge step inside a larger clock tree synthesis flow. When wire length matters, use DME on the same topology instead, which also gives zero skew. For a regular grid of sinks, an H-tree gives equal path lengths with no computation.
Pitfalls
- The formula assumes that both subtrees already have zero skew. A subtree whose sinks have different delays must be fixed first.
- If is outside , clamping it to 0 or 1 without making the wire longer leaves a skew. The elongation of lines L7 and L8 is needed.
- An elongation wastes wire and capacitance. Many elongations mean a poor topology that pairs subtrees with very different delays.
- Zero Elmore skew is not zero real skew. The Elmore delay is an upper bound on the 50 percent delay, and the error differs from sink to sink.
- The elongated length involves a square root, so it is irrational in general. Rounding it leaves a small skew; exact checks need exact or high precision arithmetic.
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/tsay-zero-skew/. The authors are listed in prov/J8K07F.jsonl.
"""Tsay's exact zero-skew merge, bottom up over a given binary topology.
Wires have resistance r and capacitance c per unit length, in the pi model.
A sink is ((x, y), load capacitance). A topology is a sink index or a pair of
topologies. Each subtree is summarised by its root point, its total
capacitance C and its Elmore delay t from the root to every sink (the same
for all its sinks). Exact with Fractions, except when a wire must be longer
than the distance (elongation), where a square root appears: it is exact when
the number under the root is a square of a rational, else it is rounded to
about 60 decimal digits.
"""
from fractions import Fraction
from math import isqrt
class Node:
def __init__(self, pt, cap, t, kids, sink=None):
self.pt, self.cap, self.t, self.kids, self.sink = pt, cap, t, kids, sink
def l1(p, q):
return abs(p[0] - q[0]) + abs(p[1] - q[1])
def sqrt_fraction(v, bits=200):
"""Exact root of a rational square, else a rational within 2^-bits."""
v = Fraction(v)
n, d = v.numerator, v.denominator
rn, rd = isqrt(n), isqrt(d)
if rn * rn == n and rd * rd == d:
return Fraction(rn, rd)
scale = 1 << (2 * bits)
return Fraction(isqrt(n * scale // d), 1 << bits)
def point_along(p, q, s):
"""The point at L1 distance s from p on the path from p to q that runs
horizontally first, then vertically."""
dx = q[0] - p[0]
if s <= abs(dx):
return (p[0] + (s if dx >= 0 else -s), p[1])
dy = q[1] - p[1]
rest = s - abs(dx)
return (q[0], p[1] + (rest if dy >= 0 else -rest))
def elongated(r, c, cap, dt):
"""Wire length L' >= 0 with r L' (c L' / 2 + cap) = dt, for dt >= 0."""
if c == 0:
return Fraction(dt) / (r * cap)
disc = (r * cap) ** 2 + 2 * r * c * dt
return (sqrt_fraction(disc) - r * cap) / (r * c)
def merge(a, b, r, c):
"""Join subtrees a and b at the tapping point of zero skew."""
L = l1(a.pt, b.pt) # @line L4
if L > 0:
x = (b.t - a.t + r * L * (b.cap + c * L / 2)) / (r * L * (c * L + a.cap + b.cap)) # @line L5
else:
x = Fraction(0) if a.t >= b.t else Fraction(1)
if 0 <= x <= 1 and L > 0: # @line L6
la, lb = x * L, (1 - x) * L
pt = point_along(a.pt, b.pt, la)
elif x < 0 or (L == 0 and a.t >= b.t): # @line L7
la, lb = Fraction(0), elongated(r, c, b.cap, a.t - b.t)
pt = a.pt
else: # @line L8
la, lb = elongated(r, c, a.cap, b.t - a.t), Fraction(0)
pt = b.pt
t = a.t + r * la * (c * la / 2 + a.cap) # @line L9
return Node(pt, a.cap + b.cap + c * (la + lb), t, [(a, la), (b, lb)])
def zero_skew_tree(sinks, topo, r, c):
"""Return the root Node of the zero-skew tree on the given topology."""
if not isinstance(topo, tuple): # @line L1
(x, y), load = sinks[topo]
return Node((Fraction(x), Fraction(y)), Fraction(load), Fraction(0), [], sink=topo) # @line L2
left = zero_skew_tree(sinks, topo[0], r, c) # @line L3
right = zero_skew_tree(sinks, topo[1], r, c)
return merge(left, right, r, c)
def wirelength(node):
return sum(length + wirelength(k) for k, length in node.kids)
test_tsay_zero_skew.py 131 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/tsay-zero-skew/. The authors are listed in prov/J8K07F.jsonl.
import random
from fractions import Fraction
from tsay_zero_skew import Node, l1, merge, wirelength, zero_skew_tree
def elmore_to_sinks(root, r, c):
"""Elmore delay from the root to every sink as the sum of R_ik C_k over
the pi model of all wires, with no use of the subtree summaries."""
nodes, parent_path = [], {}
cap = {}
stack = [(root, ())]
while stack:
v, path = stack.pop()
nodes.append(v)
parent_path[id(v)] = path # resistances of the edges from the root
cap[id(v)] = cap.get(id(v), Fraction(0)) + (v.cap if v.sink is not None else 0)
for k, length in v.kids:
cap[id(v)] += c * length / 2
cap[id(k)] = c * length / 2
stack.append((k, path + ((id(k), r * length),)))
out = {}
for s in nodes:
if s.sink is None:
continue
ps = dict(parent_path[id(s)])
total = Fraction(0)
for k in nodes:
common = sum(res for e, res in parent_path[id(k)] if e in ps)
total += common * cap[id(k)]
out[s.sink] = total
return out
def random_topology(rng, items):
if len(items) == 1:
return items[0]
k = rng.randint(1, len(items) - 1)
return (random_topology(rng, items[:k]), random_topology(rng, items[k:]))
def merges_elongate(node, r, c):
"""Does some merge of the tree need a wire longer than the distance?"""
if not node.kids:
return False
(a, la), (b, lb) = node.kids
return la + lb != l1(a.pt, b.pt) or merges_elongate(a, r, c) or merges_elongate(b, r, c)
def test_zero_skew_exact(rng=random.Random(80701)):
exact_cases = 0
for _ in range(150):
n = rng.randint(1, 7)
sinks = [((rng.randint(0, 12), rng.randint(0, 12)), rng.randint(1, 4)) for _ in range(n)]
order = list(range(n))
rng.shuffle(order)
topo = random_topology(rng, order)
r, c = Fraction(rng.randint(1, 3)), Fraction(rng.randint(1, 3))
root = zero_skew_tree(sinks, topo, r, c)
delays = elmore_to_sinks(root, r, c)
assert set(delays) == set(range(n))
for s in delays:
if merges_elongate(root, r, c):
assert abs(delays[s] - root.t) < Fraction(1, 10**40)
else:
assert delays[s] == root.t
if not merges_elongate(root, r, c):
exact_cases += 1
# without elongation each merge uses exactly the distance between the roots
def check(v):
if v.kids:
(a, la), (b, lb) = v.kids
assert la + lb == l1(a.pt, b.pt)
assert l1(v.pt, a.pt) == la and l1(v.pt, b.pt) == lb
check(a)
check(b)
check(root)
assert wirelength(root) >= 0
assert exact_cases > 50
def test_tap_point_against_grid(rng=random.Random(12)):
# the skew at a tap s along the wire grows strictly with s, so a grid search
# sees one sign change, at the tap of Tsay's formula
for _ in range(200):
r, c = Fraction(rng.randint(1, 3)), Fraction(rng.randint(1, 3))
a = Node((Fraction(rng.randint(0, 9)), Fraction(rng.randint(0, 9))), Fraction(rng.randint(1, 9)), Fraction(rng.randint(0, 60)), [])
b = Node((Fraction(rng.randint(0, 9)), Fraction(rng.randint(0, 9))), Fraction(rng.randint(1, 9)), Fraction(rng.randint(0, 60)), [])
L = l1(a.pt, b.pt)
if L == 0:
continue
m = merge(a, b, r, c)
(_, la), (_, lb) = m.kids
def skew(s):
return (a.t + r * s * (c * s / 2 + a.cap)) - (b.t + r * (L - s) * (c * (L - s) / 2 + b.cap))
grid = [L * Fraction(j, 64) for j in range(65)]
signs = [skew(s) for s in grid]
assert all(x < y for x, y in zip(signs, signs[1:]))
if la + lb == L:
assert skew(la) == 0
assert all((s < la) == (skew(s) < 0) for s in grid if s != la)
else:
assert all(x > 0 for x in signs) or all(x < 0 for x in signs)
def test_exact_elongation():
r = c = Fraction(1)
a = Node((Fraction(0), Fraction(0)), Fraction(1), Fraction(4), [])
b = Node((Fraction(1), Fraction(0)), Fraction(1), Fraction(0), [])
m = merge(a, b, r, c)
(_, la), (_, lb) = m.kids
assert (la, lb, m.pt, m.t) == (0, 2, (0, 0), 4)
assert m.cap == 1 + 1 + 2
def test_example_of_the_page():
sinks = [((5, 7), 3), ((2, 0), 2), ((6, 2), 1), ((6, 8), 2)]
r, c = Fraction(1), Fraction(1)
root = zero_skew_tree(sinks, ((0, 1), (2, 3)), r, c)
(left, ll), (right, lr) = root.kids
assert left.pt == (2, Fraction(16, 3)) and left.t == Fraction(224, 9) and left.cap == 15
assert right.pt == (6, Fraction(16, 3)) and right.t == Fraction(80, 9) and right.cap == 9
assert (ll, lr, root.pt, root.t, root.cap) == (1, 3, (3, Fraction(16, 3)), Fraction(727, 18), 28)
assert wirelength(root) == 20
delays = elmore_to_sinks(root, r, c)
assert set(delays.values()) == {Fraction(727, 18)}
History
Ren-Song Tsay presented exact zero skew at ICCAD 1991 and in IEEE Transactions on Computer-Aided Design in 1993. Before it, clock routers such as the method of means and medians of Jackson, Srinivasan and Kuh (1990) balanced path lengths, which does not give zero skew in general. In 1992 Chao, Hsu, Ho, Boese and Kahng gave deferred-merge embedding, which keeps Tsay's balance and lowers the wire length for a fixed topology.
References
- Ren-Song Tsay, An exact zero-skew clock routing algorithm, IEEE Transactions on Computer-Aided Design 12(2), 242 to 249, 1993, the tapping point formula under the Elmore delay, the wire elongation when the point falls outside the segment, and the bottom-up merge
- Ren-Song Tsay, Exact zero skew, Proceedings of ICCAD 1991, 336 to 339, the conference version of the method
- Andrew B. Kahng, Jens Lienig, Igor L. Markov and Jin Hu, VLSI Physical Design, From Graph Partitioning to Timing Closure, Springer, 2011, Chapter 7, Specialized Routing, Section 7.5.1, Constructing Trees with Zero Global Skew (exact zero skew)
- Ting-Hai Chao, Yu-Chin Hsu, Jan-Ming Ho, Kenneth D. Boese and Andrew B. Kahng, Zero skew clock routing with minimum wirelength, IEEE Transactions on Circuits and Systems II 39(11), 799 to 814, 1992, the comparison with deferred-merge embedding, which keeps zero skew and uses less wire for the same topology
Where this leads
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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H2 full proof |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag J8K07F Edit this page History Report an error Markdown