Algorithm Search⌘K

Algorithmadvanced

Statistical static timing analysis

Also called SSTA.

Propagates delays as random variables, often linear in shared Gaussian sources of variation, through the timing graph by sum and statistical max.

Time
Θ((V + E) m) worst · average · best
Space
Θ(V m) extra
Where
E = the number of edges; V = the number of vertices (pins) of the timing graph; m = the number of global sources of variation
Properties
deterministicnot exactiterative
Origin
Chandu Visweswariah, Kaushik Ravindran, Kerim Kalafala, Steven G. Walker, Sambasivan Narayan, 2004

Statistical static timing analysis (SSTA) is static timing analysis in which the delays are random variables instead of numbers. Variations of the manufacturing process, such as the gate length or the oxide thickness, change all delays on a chip together, and random effects change each gate on its own. In the block-based method of Visweswariah and his colleagues (2004), each delay and each arrival time is a linear function of a few shared standard normal sources and one private normal term, the canonical form. The forward pass adds forms along the edges and combines the in-edges at a vertex by a statistical max, which uses Clark's (1961) formulas for the max of two Gaussians. The pass is linear in the size of the timing graph. The sum is exact. The max keeps the mean, the variance and the correlations, but the true max is not Gaussian, so the result is an approximation.

In plain words

Plain STA asks how late a signal can arrive. On a real chip, the delays change from chip to chip, and many of them change together. SSTA asks for the distribution of the arrival time: its mean, its spread and how it moves with each shared cause of variation.

Each delay is written as "mean plus some amount of each shared cause plus some private noise". Adding two delays adds these amounts. Taking the later of two arrivals is harder, because the later of two bell curves is not a bell curve. SSTA replaces it by the bell curve that has the same mean and the same spread, and that depends on each shared cause the same way. At the end, the distribution at an output gives the fraction of chips that meet the clock period.

The problem

The input is a timing graph G=(V,E)G = (V, E) that is a DAG, a canonical form for each edge delay and for the arrival time at each start point, all over the same global sources Z1,…,ZmZ_1, \ldots, Z_m. A canonical form is

X=μ+∑i=1maiZi+rR,X = \mu + \sum_{i=1}^m a_i Z_i + r R,

where the ZiZ_i and RR are independent standard normal variables, and RR is private: it is independent of the private term of every other form. So Var(X)=∑ai2+r2\mathrm{Var}(X) = \sum a_i^2 + r^2 and Cov(X,Zi)=ai\mathrm{Cov}(X, Z_i) = a_i. The sources often come from a principal component analysis of correlated parameters, which makes them independent.

The true arrival time at vv is the random variable max⁡P(AT0(s)+d(P))\max_P (AT_0(s) + d(P)) over all paths PP from a start point ss to vv, as in the longest path problem, but with random delays. The goal is its distribution, or at least its mean, its variance and its covariance with each ZiZ_i, and from these the timing yield P(AT(t)≤T)P(AT(t) \le T) at each endpoint tt for a clock period TT.

The algorithm

  1. SSTA(G, d, AT0)
  2. 1order ← a topological order of G (stop with an error if G has a cycle)
  3. 2for each vertex v in order do
  4. 3if v has no in-edge then AT(v) ← AT0(v)
  5. 4else for each in-edge (u, v), in a fixed order, do S ← ADD(AT(u), d(u, v))
  6. 5AT(v) ← S for the first in-edge, else MAX(AT(v), S)
  7. 6return AT
  8. ADD(A, B)
  9. 7c_i ← a_i + b_i for i = 1 .. m
  10. 8return (μ_A + μ_B, c, sqrt(r_A² + r_B²))
  11. MAX(A, B)
  12. 9if θ² = σ_A² + σ_B² − 2 Σ a_i b_i is 0 then
  13. 10return A if μ_A ≥ μ_B else B ▷ A − B is a constant
  14. 11θ ← sqrt(θ²); α ← (μ_A − μ_B) / θ
  15. 12T ← Φ(α) ▷ tightness probability P(A > B)
  16. 13μ ← μ_A T + μ_B (1 − T) + θ φ(α)
  17. 14s ← (μ_A² + σ_A²) T + (μ_B² + σ_B²)(1 − T) + (μ_A + μ_B) θ φ(α)
  18. 15c_i ← T a_i + (1 − T) b_i for i = 1 .. m
  19. 16r ← sqrt(s − μ² − Σ c_i²) ▷ the variance is matched
  20. 17return (μ, c, r)

Here Φ\Phi and φ\varphi are the standard normal distribution function and density. Line L13 is Clark's mean of max⁡(A,B)\max(A, B) and line L14 its second moment. Line L15 is the covariance of max⁡(A,B)\max(A, B) with ZiZ_i, which Clark's formula gives as the tightness-weighted mix of the two inputs. Line L16 puts the rest of the variance into the private term. The timing yield of an endpoint is Φ((T−μ)/σ)\Phi((T - \mu)/\sigma) for its form.

Example

Two independent standard normals. For A=BA = B in distribution, standard normal and independent (a=b=0a = b = 0, rA=rB=1r_A = r_B = 1): θ=2\theta = \sqrt 2, α=0\alpha = 0, T=1/2T = 1/2, and line L13 gives μ=2 φ(0)=1/π≈0.5642\mu = \sqrt 2 \, \varphi(0) = 1/\sqrt\pi \approx 0.5642. Line L14 gives s=1s = 1, so the variance is 1−1/π≈0.68171 - 1/\pi \approx 0.6817. These are the exact mean and variance of the max of two independent standard normals.

A diamond with one global source. Vertex 0 has arrival time 0 and two paths lead to vertex 3, through 1 and through 2. The edge delays are d(0,1)=3+0.4Z+0.3Rd(0,1) = 3 + 0.4 Z + 0.3 R, d(1,3)=2+0.2Z+0.2Rd(1,3) = 2 + 0.2 Z + 0.2 R, d(0,2)=2.6+0.1Z+0.5Rd(0,2) = 2.6 + 0.1 Z + 0.5 R and d(2,3)=2.5+0.3Z+0.2Rd(2,3) = 2.5 + 0.3 Z + 0.2 R, where each RR is a different private variable.

step form std. dev.
L4 on (1,3)(1, 3) A=5.0+0.6Z+0.3606RA = 5.0 + 0.6 Z + 0.3606 R 0.7
L4 on (2,3)(2, 3) B=5.1+0.4Z+0.5385RB = 5.1 + 0.4 Z + 0.5385 R 0.6708
L11 θ2=0.49+0.45−2⋅0.24=0.46\theta^2 = 0.49 + 0.45 - 2 \cdot 0.24 = 0.46, θ=0.6782\theta = 0.6782, α=−0.1474\alpha = -0.1474
L12 T=Φ(−0.1474)=0.4414T = \Phi(-0.1474) = 0.4414
L13 to L17 AT(3)=5.3235+0.4883Z+0.3961RAT(3) = 5.3235 + 0.4883 Z + 0.3961 R 0.6288

STA with the mean delays gives 5.1. The mean of the max is larger, 5.3235, because a max of random variables has a mean at least the max of the means (Jensen's inequality). Path AA is the later one with probability 0.44, although its mean is smaller, because it has the larger spread. Here only one max is taken, of two path sums with separate private terms, so the mean, the variance and the coefficient of ZZ are exact (see Correctness). A Monte Carlo run with 200000 samples (Python random.Random(7)) gives mean 5.3246 and standard deviation 0.6285, within its sampling error. The shape is not exact: the timing yield at T=5.5T = 5.5 is 0.6105 from the form and 0.6129 from Monte Carlo; at T=6.0T = 6.0 both are 0.859.

Correctness

The proof shows the following.

  • Clark's formulas. For jointly Gaussian AA and BB, lines L12 to L15 give exactly P(A>B)P(A > B), the mean and the second moment of max⁡(A,B)\max(A, B), and its covariance with every ZiZ_i.
  • The max form matches the first two moments. The value under the root in line L16 is never negative, by Bessel's inequality, and the form has the mean, the variance and the covariances with the ZiZ_i of the true max of its two inputs. If θ=0\theta = 0, the max is exact.
  • The sum is exact. ADD gives the exact joint distribution of A+BA + B and the ZiZ_i.
  • Chains are exact. If no vertex has two in-edges, every arrival time is exact.
  • No variation gives STA. With all coefficients 0, the algorithm is static timing analysis.

What is not proved is how close the result is on a general DAG. Two approximations add up there: each max is replaced by a Gaussian, and the private terms of later forms are taken as independent although they share earlier ones. As a measurement only: on 60 random DAGs with 4 to 8 vertices, 1 to 3 global sources and edge delays with means from 1 to 4 and coefficients up to 0.5 (seed 1), the mean of the endpoint form was within 0.05 standard deviations of a Monte Carlo estimate with 4000 samples, and its standard deviation within 0.04 standard deviations. The tests use a tolerance of 0.12 standard deviations with 3000 samples.

Proof: The canonical sum is exact, and Clark's statistical max keeps the mean, the variance and the covariance with each global source of the true max of two Gaussian inputsfull

Setting. Let Z1,…,ZmZ_1, \ldots, Z_m be independent standard normal variables (the global sources). A canonical form is a random variable

X=μ+∑i=1maiZi+rR,X = \mu + \sum_{i=1}^m a_i Z_i + r R,

where r≥0r \ge 0 and RR is a standard normal variable that is independent of Z1,…,ZmZ_1, \ldots, Z_m and of the private variables of all other canonical forms in use. Its variance is σ2=∑iai2+r2\sigma^2 = \sum_i a_i^2 + r^2, and Cov(X,Zi)=ai\mathrm{Cov}(X, Z_i) = a_i. For two canonical forms AA and BB with coefficients aia_i and bib_i, the pair (A,B)(A, B) is jointly Gaussian with Cov(A,B)=∑iaibi\mathrm{Cov}(A, B) = \sum_i a_i b_i. Write Φ\Phi and φ\varphi for the standard normal distribution function and density.

What is proved here is a statement about each operation on Gaussian inputs. The statement that the arrival times of a whole DAG are close to the true distributions is not proved; the algorithm page reports it as a measurement.

Lemma 1 (truncated moments). Let D=μD+θUD = \mu_D + \theta U with UU standard normal, θ>0\theta > 0, and let α=μD/θ\alpha = \mu_D / \theta. Then

P(D>0)=Φ(α),E[(D−μD)1{D>0}]=θφ(α),E[D21{D>0}]=(μD2+θ2)Φ(α)+μDθφ(α).P(D > 0) = \Phi(\alpha), \qquad E[(D - \mu_D) \mathbf{1}\{D > 0\}] = \theta \varphi(\alpha), \qquad E[D^2 \mathbf{1}\{D > 0\}] = (\mu_D^2 + \theta^2) \Phi(\alpha) + \mu_D \theta \varphi(\alpha).

Proof. D>0D > 0 if and only if U>−αU > -\alpha, which has probability 1−Φ(−α)=Φ(α)1 - \Phi(-\alpha) = \Phi(\alpha). Since φ′(u)=−uφ(u)\varphi'(u) = -u \varphi(u), we get E[U1{U>c}]=∫c∞uφ(u) du=φ(c)E[U \mathbf{1}\{U > c\}] = \int_c^\infty u \varphi(u) \, du = \varphi(c), and by parts E[U21{U>c}]=cφ(c)+1−Φ(c)E[U^2 \mathbf{1}\{U > c\}] = c \varphi(c) + 1 - \Phi(c). With c=−αc = -\alpha and the symmetry of φ\varphi, the first moment gives θφ(α)\theta \varphi(\alpha). For the second, E[D21{D>0}]=μD2Φ(α)+2μDθφ(α)+θ2(Φ(α)−αφ(α))E[D^2 \mathbf{1}\{D > 0\}] = \mu_D^2 \Phi(\alpha) + 2 \mu_D \theta \varphi(\alpha) + \theta^2 (\Phi(\alpha) - \alpha \varphi(\alpha)), and θ2α=μDθ\theta^2 \alpha = \mu_D \theta, which gives the formula. □\square

Lemma 2 (regression on DD). Let (Y,D)(Y, D) be jointly Gaussian with Var(D)=θ2>0\mathrm{Var}(D) = \theta^2 > 0. Then Y=μY+β(D−μD)+WY = \mu_Y + \beta (D - \mu_D) + W with β=Cov(Y,D)/θ2\beta = \mathrm{Cov}(Y, D) / \theta^2, where WW has mean 0 and is independent of DD. Consequently, for every function ff with E∣f(D)∣<∞E|f(D)| < \infty and E∣Df(D)∣<∞E|D f(D)| < \infty, Cov(f(D),Y)=β Cov(f(D),D)\mathrm{Cov}(f(D), Y) = \beta \, \mathrm{Cov}(f(D), D).

Proof. W=Y−μY−β(D−μD)W = Y - \mu_Y - \beta (D - \mu_D) is Gaussian with mean 0 and Cov(W,D)=Cov(Y,D)−βθ2=0\mathrm{Cov}(W, D) = \mathrm{Cov}(Y, D) - \beta \theta^2 = 0. Jointly Gaussian variables with covariance 0 are independent. Then Cov(f(D),W)=0\mathrm{Cov}(f(D), W) = 0, which gives the second claim. □\square

Lemma 3. With DD as in Lemma 1 and D+=max⁡(D,0)D^+ = \max(D, 0), Cov(D+,D)=θ2Φ(α)\mathrm{Cov}(D^+, D) = \theta^2 \Phi(\alpha).

Proof. Cov(D+,D)=E[D21{D>0}]−μDE[D1{D>0}]\mathrm{Cov}(D^+, D) = E[D^2 \mathbf{1}\{D > 0\}] - \mu_D E[D \mathbf{1}\{D > 0\}]. By Lemma 1, E[D1{D>0}]=μDΦ(α)+θφ(α)E[D \mathbf{1}\{D > 0\}] = \mu_D \Phi(\alpha) + \theta \varphi(\alpha). Subtracting μD\mu_D times this from the third formula of Lemma 1 leaves θ2Φ(α)\theta^2 \Phi(\alpha). □\square

Theorem 1 (Clark 1961). Let (A,B)(A, B) be jointly Gaussian with means μA,μB\mu_A, \mu_B, variances σA2,σB2\sigma_A^2, \sigma_B^2 and covariance cABc_{AB}, with θ2=σA2+σB2−2cAB>0\theta^2 = \sigma_A^2 + \sigma_B^2 - 2 c_{AB} > 0. Let α=(μA−μB)/θ\alpha = (\mu_A - \mu_B)/\theta, T=Φ(α)T = \Phi(\alpha) and M=max⁡(A,B)M = \max(A, B). Then T=P(A>B)T = P(A > B) and

E[M]=μAT+μB(1−T)+θφ(α),E[M] = \mu_A T + \mu_B (1 - T) + \theta \varphi(\alpha),
E[M2]=(μA2+σA2)T+(μB2+σB2)(1−T)+(μA+μB)θφ(α),E[M^2] = (\mu_A^2 + \sigma_A^2) T + (\mu_B^2 + \sigma_B^2)(1 - T) + (\mu_A + \mu_B) \theta \varphi(\alpha),

and for every YY such that (A,B,Y)(A, B, Y) is jointly Gaussian,

Cov(M,Y)=T Cov(A,Y)+(1−T) Cov(B,Y).\mathrm{Cov}(M, Y) = T \, \mathrm{Cov}(A, Y) + (1 - T) \, \mathrm{Cov}(B, Y).

Proof. Let D=A−BD = A - B, so μD=μA−μB\mu_D = \mu_A - \mu_B, Var(D)=θ2\mathrm{Var}(D) = \theta^2 and M=B+D+M = B + D^+. Then T=P(D>0)T = P(D > 0) by Lemma 1.

Mean: E[M]=μB+E[D+]=μB+μDT+θφ(α)E[M] = \mu_B + E[D^+] = \mu_B + \mu_D T + \theta \varphi(\alpha) by Lemma 1, which is the formula.

Covariance: Cov(M,Y)=Cov(B,Y)+Cov(D+,Y)\mathrm{Cov}(M, Y) = \mathrm{Cov}(B, Y) + \mathrm{Cov}(D^+, Y). By Lemmas 2 and 3, Cov(D+,Y)=Cov(D,Y)θ2θ2T=T(Cov(A,Y)−Cov(B,Y))\mathrm{Cov}(D^+, Y) = \frac{\mathrm{Cov}(D, Y)}{\theta^2} \theta^2 T = T (\mathrm{Cov}(A, Y) - \mathrm{Cov}(B, Y)). Adding Cov(B,Y)\mathrm{Cov}(B, Y) gives the formula.

Second moment: E[M2]=E[B2]+2E[BD+]+E[(D+)2]E[M^2] = E[B^2] + 2 E[B D^+] + E[(D^+)^2]. Here E[B2]=μB2+σB2E[B^2] = \mu_B^2 + \sigma_B^2. By the covariance formula with Y=BY = B applied to D+=M−BD^+ = M - B, Cov(B,D+)=T(cAB−σB2)\mathrm{Cov}(B, D^+) = T (c_{AB} - \sigma_B^2), so E[BD+]=T(cAB−σB2)+μB(μDT+θφ(α))E[B D^+] = T (c_{AB} - \sigma_B^2) + \mu_B (\mu_D T + \theta \varphi(\alpha)). By Lemma 1, E[(D+)2]=(μD2+θ2)T+μDθφ(α)E[(D^+)^2] = (\mu_D^2 + \theta^2) T + \mu_D \theta \varphi(\alpha). Collect terms. The terms with φ\varphi are (2μB+μD)θφ(α)=(μA+μB)θφ(α)(2 \mu_B + \mu_D) \theta \varphi(\alpha) = (\mu_A + \mu_B) \theta \varphi(\alpha). The terms with TT are TT times

2cAB−2σB2+2μBμD+μD2+σA2+σB2−2cAB=(μA2−μB2)+(σA2−σB2).2 c_{AB} - 2 \sigma_B^2 + 2 \mu_B \mu_D + \mu_D^2 + \sigma_A^2 + \sigma_B^2 - 2 c_{AB} = (\mu_A^2 - \mu_B^2) + (\sigma_A^2 - \sigma_B^2).

With μB2+σB2\mu_B^2 + \sigma_B^2 from E[B2]E[B^2], this is the formula. □\square

Theorem 2 (the canonical max). Let AA and BB be canonical forms with θ2>0\theta^2 > 0, and let C=MAX(A,B)C = \mathrm{MAX}(A, B) be the form built in lines L11 to L17: mean E[M]E[M] and second moment E[M2]E[M^2] from Theorem 1, coefficients ci=Tai+(1−T)bic_i = T a_i + (1 - T) b_i and r=E[M2]−E[M]2−∑ici2r = \sqrt{E[M^2] - E[M]^2 - \sum_i c_i^2}. Then the expression under the root is non-negative, and CC has the same mean, the same variance and the same covariance with each ZiZ_i as M=max⁡(A,B)M = \max(A, B). If θ=0\theta = 0, lines L9 and L10 return MM itself.

Proof. Each (A,B,Zi)(A, B, Z_i) is jointly Gaussian, so by Theorem 1 with Y=ZiY = Z_i, Cov(M,Zi)=Tai+(1−T)bi=ci\mathrm{Cov}(M, Z_i) = T a_i + (1 - T) b_i = c_i. The ZiZ_i are orthonormal in the space of square-integrable variables with the covariance as inner product, so Bessel's inequality gives ∑iCov(M,Zi)2≤Var(M)=E[M2]−E[M]2\sum_i \mathrm{Cov}(M, Z_i)^2 \le \mathrm{Var}(M) = E[M^2] - E[M]^2. So rr is real. Then E[C]=E[M]E[C] = E[M], Cov(C,Zi)=ci=Cov(M,Zi)\mathrm{Cov}(C, Z_i) = c_i = \mathrm{Cov}(M, Z_i) and Var(C)=∑ici2+r2=Var(M)\mathrm{Var}(C) = \sum_i c_i^2 + r^2 = \mathrm{Var}(M). If θ=0\theta = 0, then A−BA - B has variance 0, so it is the constant μA−μB\mu_A - \mu_B, and MM is AA when μA≥μB\mu_A \ge \mu_B and BB otherwise. □\square

The form CC is Gaussian and MM is not, unless θ=0\theta = 0 or one input almost surely exceeds the other. This is the only approximation of a single max step. A second one comes from the model: the private term of CC is treated as independent of all other private terms, although MM depends on the private terms of AA and BB. On a DAG with reconvergent paths, both effects add up, and no bound on the total error is proved here.

Theorem 3 (the sum). For canonical forms AA and BB, the form ADD(A,B)\mathrm{ADD}(A, B) of lines L7 and L8, with mean μA+μB\mu_A + \mu_B, coefficients ai+bia_i + b_i and private coefficient rA2+rB2\sqrt{r_A^2 + r_B^2}, has the same distribution as A+BA + B, and the same joint distribution with (Z1,…,Zm)(Z_1, \ldots, Z_m).

Proof. A+B=(μA+μB)+∑i(ai+bi)Zi+(rARA+rBRB)A + B = (\mu_A + \mu_B) + \sum_i (a_i + b_i) Z_i + (r_A R_A + r_B R_B). The last term is Gaussian with mean 0 and variance rA2+rB2r_A^2 + r_B^2, and independent of the ZiZ_i, so it has the same distribution as rA2+rB2 R\sqrt{r_A^2 + r_B^2} \, R for a new standard normal RR that is independent of the ZiZ_i. □\square

Theorem 4 (chains are exact). Suppose every vertex of the DAG has at most one in-edge, the start arrival times and the edge delays are canonical forms, and the private variables of all of them are independent. Then the arrival time that the algorithm computes at each vertex has the same joint distribution with (Z1,…,Zm)(Z_1, \ldots, Z_m) as the true arrival time, the sum of the delays on the unique path from a start point.

Proof. With one in-edge per vertex, line L5 never calls MAX. By induction along the topological order, the true arrival time at vv is AT(u)+d(u,v)AT(u) + d(u, v), where AT(u)AT(u) depends only on the private variables of the edges on the path to uu and of its start point, which are independent of the private variable of d(u,v)d(u, v). Theorem 3 applies at each step. □\square

The same argument shows that the algorithm is exact in mean, variance and covariance with each ZiZ_i at a vertex where only one max is taken, of two path sums whose private variables are disjoint, as in the diamond example of the algorithm page.

Theorem 5 (no variation gives STA). If all coefficients and all private terms are 0, the algorithm computes the arrival times of static timing analysis.

Proof. All forms are constants. ADD adds the means. In MAX, θ=0\theta = 0, so lines L9 and L10 return the input with the larger mean, which is the max of two numbers. So lines L2 to L5 are lines L2 to L4 of STA. □\square

Theorem 6 (running time). On a timing graph with VV vertices, EE edges and mm global sources, the algorithm takes Θ((V+E)⋅m)\Theta((V + E) \cdot m) arithmetic operations and evaluations of Φ\Phi, φ\varphi and the square root, and Θ(Vm)\Theta(V m) extra space for the forms.

Proof. The topological order takes Θ(V+E)\Theta(V + E). Each edge is used once in line L4 and at most once in line L5, and ADD and MAX each take Θ(m)\Theta(m) operations and a constant number of function evaluations. Each vertex stores one form of size m+2m + 2. □\square

■\blacksquare

Complexity

  • Time. Line L1 takes Θ(V+E)\Theta(V + E). Each edge causes one ADD and at most one MAX, each with Θ(m)\Theta(m) operations and a constant number of evaluations of Φ\Phi, φ\varphi and the square root. In total Θ((V+E)m)\Theta((V + E) m), compared with Θ(V+E)\Theta(V + E) for STA.
  • Space. One form of m+2m + 2 numbers per vertex, Θ(Vm)\Theta(V m).
  • Comparison with Monte Carlo. A Monte Carlo analysis runs STA once per sample, so NN samples cost Θ(N(V+E))\Theta(N (V + E)). Its error falls like 1/N1/\sqrt N, so thousands of samples are needed for the tails. SSTA does one pass.

Properties

  • Approximate, not a bound. The result is not an upper bound on the true distribution, and it is not exact on a DAG with reconvergent paths. In practice its error is small compared with the spread of the delays, as the measurement above shows.
  • Correlations are kept. Since each form keeps its coefficients of the global sources, reconvergent paths that share variation are not treated as independent, and the arrival times at different endpoints stay correlated. This is what makes the yield of a whole chip computable.
  • Order of the in-edges. MAX of three or more forms is done in pairs, and the result depends slightly on the order.
  • Block-based. Like STA, the cost does not depend on the number of paths, and the analysis can be updated incrementally after a change.

Variants and improvements

  • Required times and criticality. A backward pass with a statistical min gives required times and slacks as forms. The tightness probabilities of line L12, multiplied along paths, give the probability that each edge is on the critical path (the criticality), which guides optimization.
  • Path-based SSTA. Enumerate the worst paths of STA and compute the distribution of each path delay exactly as a sum, then the max over the few paths. This avoids the errors of repeated max steps but may miss paths.
  • Non-Gaussian and non-linear models. Quadratic canonical forms, or forms with non-Gaussian sources, follow strongly non-linear delays better, at a higher cost per operation.
  • Monte Carlo. Sampling the sources and running STA per sample is the reference method. It is exact in the limit and costly.
  • Statistical libraries. The coefficients of the cell delays come from libraries with sensitivities or standard deviations next to each table of a nonlinear delay model.

When to use it

  • When the variation of the delays is large compared with the margins, so that corner-based STA, which assumes every delay at its worst value at once, is too pessimistic or misses correlations.
  • To estimate the timing yield of a design and to find the edges that are most often critical.
  • Not when a guaranteed bound is required. Sign-off with STA at corners gives bounds under its assumptions, and SSTA gives an estimate of a distribution.

Pitfalls

  • Reading the result as exact. The max of Gaussians is not Gaussian. Far in the tails, where yield is decided, the error of the shape can matter even when the mean and the variance are right.
  • Ignoring correlation. Treating all delays as independent makes the variance of long paths far too small and the yield far too high. The global sources in the forms are there to prevent this.
  • Clamping. In exact arithmetic the value in line L16 is not negative. With rounding it can be a tiny negative number, so implementations clamp it at 0; a large negative value means a bug.
  • Mixing modes. The hold check needs a statistical min of early arrival times, with the same care about correlation, not the late forms.

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.

statistical_static_timing_analysis.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/statistical-static-timing-analysis/. The authors are listed in prov/XMR9Q0.jsonl.

import math
from collections import deque
from typing import Mapping, NamedTuple, Sequence


class Canonical(NamedTuple):
    """A delay or arrival time in first-order canonical form.

    The value is mean + sum(coeffs[i] * Z_i) + rand * R, where the Z_i are the
    shared (global) sources of variation and R is a private source. All of
    them are independent standard normal variables, and R is independent of
    the private source of every other canonical form.
    """

    mean: float
    coeffs: tuple
    rand: float

    def variance(self) -> float:
        return sum(c * c for c in self.coeffs) + self.rand * self.rand

    def std(self) -> float:
        return math.sqrt(self.variance())


def constant(value: float, m: int) -> Canonical:
    return Canonical(float(value), (0.0,) * m, 0.0)


def pdf(x: float) -> float:
    return math.exp(-0.5 * x * x) / math.sqrt(2.0 * math.pi)


def cdf(x: float) -> float:
    return 0.5 * (1.0 + math.erf(x / math.sqrt(2.0)))


def add(a: Canonical, b: Canonical) -> Canonical:
    """Sum of two canonical forms. Exact: means and coefficients add, and the
    private parts are independent, so their variances add."""
    coeffs = tuple(x + y for x, y in zip(a.coeffs, b.coeffs))  # @line L7
    return Canonical(a.mean + b.mean, coeffs, math.hypot(a.rand, b.rand))  # @line L8


def clark_max(a: Canonical, b: Canonical):
    """Statistical max of two canonical forms by Clark's formulas.

    Returns (c, t) where c is the canonical form and t the tightness
    probability P(A > B). The mean, the variance and the covariance with
    every global source are those of the true max(A, B) of the two Gaussian
    inputs; only the shape (Gaussian) is an approximation.
    """
    cov = sum(x * y for x, y in zip(a.coeffs, b.coeffs))
    va, vb = a.variance(), b.variance()
    theta2 = va + vb - 2.0 * cov
    if theta2 <= 1e-300:  # @line L9
        # A - B is a constant, so the max is exactly the one with the larger mean.
        return (a, 1.0) if a.mean >= b.mean else (b, 0.0)  # @line L10
    theta = math.sqrt(theta2)  # @line L11
    alpha = (a.mean - b.mean) / theta
    t = cdf(alpha)  # @line L12
    p = pdf(alpha)
    mean = a.mean * t + b.mean * (1.0 - t) + theta * p  # @line L13
    second = (a.mean ** 2 + va) * t + (b.mean ** 2 + vb) * (1.0 - t) + (a.mean + b.mean) * theta * p  # @line L14
    coeffs = tuple(t * x + (1.0 - t) * y for x, y in zip(a.coeffs, b.coeffs))  # @line L15
    rest = second - mean * mean - sum(c * c for c in coeffs)
    rand = math.sqrt(max(0.0, rest))  # @line L16
    return Canonical(mean, coeffs, rand), t  # @line L17


def topological_order(n: int, edges: Sequence[tuple]) -> list:
    """Kahn's algorithm. Raises ValueError if the graph has a cycle."""
    indeg = [0] * n
    out = [[] for _ in range(n)]
    for u, v, _ in edges:
        out[u].append(v)
        indeg[v] += 1
    queue = deque(v for v in range(n) if indeg[v] == 0)
    order = []
    while queue:
        u = queue.popleft()
        order.append(u)
        for v in out[u]:
            indeg[v] -= 1
            if indeg[v] == 0:
                queue.append(v)
    if len(order) != n:
        raise ValueError("the timing graph has a cycle")
    return order


def statistical_static_timing_analysis(
    n: int,
    edges: Sequence[tuple],
    at_start: Mapping[int, Canonical],
) -> list:
    """Block-based SSTA: the canonical arrival time of every vertex.

    The vertices are 0 .. n-1, each edge is (u, v, d) with d a Canonical, and
    at_start gives the canonical arrival time of every vertex with no in-edge.
    In-edges are combined in the order in which they appear in edges.
    """
    order = topological_order(n, edges)  # @line L1
    into = [[] for _ in range(n)]
    for u, v, d in edges:
        into[v].append((u, d))
    at = [None] * n
    for v in order:  # @line L2
        if not into[v]:
            if v not in at_start:
                raise ValueError("no arrival time for start point %d" % v)
            at[v] = at_start[v]  # @line L3
            continue
        x = None
        for u, d in into[v]:
            s = add(at[u], d)  # @line L4
            x = s if x is None else clark_max(x, s)[0]  # @line L5
        at[v] = x
    return at  # @line L6


def timing_yield(x: Canonical, deadline: float) -> float:
    """P(X <= deadline) under the Gaussian form of X."""
    sd = x.std()
    if sd == 0.0:
        return 1.0 if x.mean <= deadline else 0.0
    return cdf((deadline - x.mean) / sd)
test_statistical_static_timing_analysis.py 208 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/statistical-static-timing-analysis/. The authors are listed in prov/XMR9Q0.jsonl.

import math
import random

import pytest

from statistical_static_timing_analysis import (
    Canonical,
    add,
    cdf,
    clark_max,
    constant,
    pdf,
    statistical_static_timing_analysis,
    timing_yield,
)


def sample(x, z, rng):
    """One sample of canonical form x for the global values z and a fresh private value."""
    return x.mean + sum(c * zi for c, zi in zip(x.coeffs, z)) + x.rand * rng.gauss(0.0, 1.0)


def monte_carlo(n, edges, at_start, m, samples, rng, target):
    """Sample every delay and compute the exact longest path to target per sample.

    The vertices are numbered in topological order."""
    into = [[] for _ in range(n)]
    for u, v, d in edges:
        into[v].append((u, d))
    values = []
    for _ in range(samples):
        z = [rng.gauss(0.0, 1.0) for _ in range(m)]
        at = [0.0] * n
        for v in range(n):
            if not into[v]:
                at[v] = sample(at_start[v], z, rng)
            else:
                at[v] = max(at[u] + sample(d, z, rng) for u, d in into[v])
        values.append(at[target])
    mu = sum(values) / samples
    sd = math.sqrt(sum((x - mu) ** 2 for x in values) / (samples - 1))
    return mu, sd, values


def random_dag(rng, n, m, spread):
    edges = []
    for v in range(1, n):
        for u in rng.sample(range(v), min(v, rng.randint(1, 3))):
            d = Canonical(rng.uniform(1.0, 4.0), tuple(rng.uniform(0.0, spread) for _ in range(m)),
                          rng.uniform(0.0, spread))
            edges.append((u, v, d))
    return edges


def test_max_of_two_independent_standard_normals():
    c, t = clark_max(Canonical(0.0, (), 1.0), Canonical(0.0, (), 1.0))
    assert t == pytest.approx(0.5)
    assert c.mean == pytest.approx(1.0 / math.sqrt(math.pi), abs=1e-12)
    assert c.variance() == pytest.approx(1.0 - 1.0 / math.pi, abs=1e-12)


def test_max_with_itself_and_with_a_shift_is_exact():
    a = Canonical(2.0, (0.3, -0.4), 0.0)
    c, t = clark_max(a, a)
    assert c == a and t == 1.0
    b = Canonical(1.5, (0.3, -0.4), 0.0)  # a - b is the constant 0.5
    c, t = clark_max(b, a)
    assert c == a and t == 0.0


def test_clark_moments_and_covariance_against_monte_carlo():
    rng = random.Random(3)
    a = Canonical(1.0, (0.8, 0.1), 0.5)
    b = Canonical(1.2, (0.3, 0.6), 0.4)
    c, t = clark_max(a, b)
    samples = 100000
    xs, z0s = [], []
    for _ in range(samples):
        z = [rng.gauss(0.0, 1.0), rng.gauss(0.0, 1.0)]
        xs.append(max(sample(a, z, rng), sample(b, z, rng)))
        z0s.append(z[0])
    mu = sum(xs) / samples
    var = sum((x - mu) ** 2 for x in xs) / (samples - 1)
    cov0 = sum((x - mu) * z for x, z in zip(xs, z0s)) / (samples - 1)
    se = math.sqrt(var / samples)
    assert abs(c.mean - mu) < 4 * se
    assert abs(c.variance() - var) < 0.02 * var
    assert abs(c.coeffs[0] - cov0) < 0.02
    assert abs(c.coeffs[0] - (t * 0.8 + (1 - t) * 0.3)) < 1e-12


def test_residual_is_never_clamped():
    # Bessel's inequality: Var(max) >= sum of squared covariances with the
    # independent unit sources, so the private term needs no clamping.
    rng = random.Random(5)
    for _ in range(2000):
        m = rng.randint(0, 4)
        a = Canonical(rng.uniform(-2, 2), tuple(rng.uniform(-1, 1) for _ in range(m)), rng.uniform(0, 1))
        b = Canonical(rng.uniform(-2, 2), tuple(rng.uniform(-1, 1) for _ in range(m)), rng.uniform(0, 1))
        c, t = clark_max(a, b)
        cov = sum(x * y for x, y in zip(a.coeffs, b.coeffs))
        theta2 = a.variance() + b.variance() - 2 * cov
        if theta2 <= 1e-300:
            continue
        theta = math.sqrt(theta2)
        alpha = (a.mean - b.mean) / theta
        second = ((a.mean ** 2 + a.variance()) * cdf(alpha) + (b.mean ** 2 + b.variance()) * cdf(-alpha)
                  + (a.mean + b.mean) * theta * pdf(alpha))
        assert c.variance() == pytest.approx(second - c.mean ** 2, abs=1e-9)


def all_path_lengths(n, edges, v):
    """Brute force: lengths of all paths from a start point to v."""
    into = [[] for _ in range(n)]
    for u, w, d in edges:
        into[w].append((u, d))
    if not into[v]:
        return [0.0]
    return [x + d.mean for u, d in into[v] for x in all_path_lengths(n, edges, u)]


def test_deterministic_delays_give_the_longest_path():
    rng = random.Random(11)
    for _ in range(200):
        n = rng.randint(2, 8)
        m = rng.randint(0, 2)
        edges = []
        for v in range(1, n):
            for u in rng.sample(range(v), min(v, rng.randint(0, 3))):
                edges.append((u, v, constant(rng.randint(-3, 9), m)))
        rng.shuffle(edges)
        start = {v: constant(0, m) for v in range(n) if all(w != v for _, w, _ in edges)}
        at = statistical_static_timing_analysis(n, edges, start)
        for v in range(n):
            assert at[v].variance() == 0.0
            assert at[v].mean == max(all_path_lengths(n, edges, v))


def test_chain_is_exact():
    rng = random.Random(13)
    m = 2
    edges = [(k, k + 1, Canonical(rng.uniform(1, 3), (rng.uniform(0, 0.5), rng.uniform(-0.5, 0.5)),
                                  rng.uniform(0, 0.5))) for k in range(6)]
    at = statistical_static_timing_analysis(7, edges, {0: constant(1.0, m)})
    mean = 1.0 + sum(d.mean for _, _, d in edges)
    coeffs = [sum(d.coeffs[i] for _, _, d in edges) for i in range(m)]
    rand2 = sum(d.rand ** 2 for _, _, d in edges)
    assert at[6].mean == pytest.approx(mean, abs=1e-12)
    assert list(at[6].coeffs) == pytest.approx(coeffs, abs=1e-12)
    assert at[6].rand ** 2 == pytest.approx(rand2, abs=1e-12)
    mu, sd, _ = monte_carlo(7, edges, {0: constant(1.0, m)}, m, 20000, rng, 6)
    assert abs(mu - mean) < 4 * sd / math.sqrt(20000)
    assert abs(sd - at[6].std()) < 0.03 * sd


def test_diamond_example():
    edges = [(0, 1, Canonical(3.0, (0.4,), 0.3)), (0, 2, Canonical(2.6, (0.1,), 0.5)),
             (1, 3, Canonical(2.0, (0.2,), 0.2)), (2, 3, Canonical(2.5, (0.3,), 0.2))]
    at = statistical_static_timing_analysis(4, edges, {0: constant(0.0, 1)})
    out = at[3]
    assert out.mean == pytest.approx(5.3235, abs=1e-4)
    assert out.coeffs[0] == pytest.approx(0.4883, abs=1e-4)
    assert out.std() == pytest.approx(0.6288, abs=1e-4)
    # Only one max of two jointly Gaussian path delays: the moments are exact.
    rng = random.Random(7)
    mu, sd, values = monte_carlo(4, edges, {0: constant(0.0, 1)}, 1, 50000, rng, 3)
    assert abs(mu - out.mean) < 4 * sd / math.sqrt(50000)
    assert abs(sd - out.std()) < 0.02 * sd
    # The shape is not Gaussian, so the yield is close but not exact.
    for q in (5.5, 6.0, 6.5):
        empirical = sum(x <= q for x in values) / len(values)
        assert abs(empirical - timing_yield(out, q)) < 0.01


def test_random_dags_against_monte_carlo():
    # Measured tolerance, not a theorem: mean and standard deviation within
    # 0.12 standard deviations of a Monte Carlo estimate with 3000 samples.
    rng = random.Random(1)
    for _ in range(12):
        n = rng.randint(4, 8)
        m = rng.randint(1, 3)
        edges = random_dag(rng, n, m, 0.5)
        at = statistical_static_timing_analysis(n, edges, {0: constant(0.0, m)})
        mu, sd, _ = monte_carlo(n, edges, {0: constant(0.0, m)}, m, 3000, rng, n - 1)
        assert abs(at[-1].mean - mu) < 0.12 * sd
        assert abs(at[-1].std() - sd) < 0.12 * sd


def test_sum_and_yield():
    a = Canonical(1.0, (0.3, 0.4), 1.2)
    b = Canonical(2.0, (0.1, -0.4), 0.5)
    s = add(a, b)
    assert s.mean == 3.0 and s.coeffs == pytest.approx((0.4, 0.0))
    assert s.rand == pytest.approx(1.3)
    assert timing_yield(s, 3.0) == pytest.approx(0.5)
    assert timing_yield(constant(2.0, 2), 2.0) == 1.0
    assert timing_yield(constant(2.0, 2), 1.9) == 0.0


def test_errors():
    d = constant(1.0, 0)
    with pytest.raises(ValueError):
        statistical_static_timing_analysis(2, [(0, 1, d), (1, 0, d)], {})
    with pytest.raises(ValueError):
        statistical_static_timing_analysis(2, [(0, 1, d)], {})

History

Clark (1961) derived the mean and the variance of the max of two jointly normal variables, and the correlation of the max with a third normal variable, to analyse PERT networks with random activity times. Visweswariah, Ravindran, Kalafala, Walker and Narayan presented the first-order canonical form at DAC 2004, with the incremental analysis and the tightness probabilities, as a tool used at IBM. The journal version appeared in 2006.

References

  1. Chandu Visweswariah, Kaushik Ravindran, Kerim Kalafala, Steven G. Walker and Sambasivan Narayan, First-order incremental block-based statistical timing analysis, Proceedings of the 41st Design Automation Conference, 331 to 336, 2004, the canonical first-order form, the sum and the max operations, tightness probabilities and the incremental analysis
  2. Chandu Visweswariah, Kaushik Ravindran, Kerim Kalafala, Steven G. Walker, Sambasivan Narayan and others, First-order incremental block-based statistical timing analysis, IEEE Transactions on Computer-Aided Design of Integrated Circuits and Systems 25(10), from page 2170, 2006, the journal version, with the criticality probabilities and the results on IBM designs
  3. Charles E. Clark, The greatest of a finite set of random variables, Operations Research 9(2), 145 to 162, 1961, the mean and the variance of the max of two jointly normal variables, and its correlation with a third normal variable
  4. J. Bhasker and Rakesh Chadha, Static Timing Analysis for Nanometer Designs, A Practical Approach, Springer, 2009, Section 10.9, Statistical Static Timing Analysis

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 proofH1 sketch
  • a full proof of correctness
  • a full proof of time.average
  • a full proof of time.best
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example