Heuristic Two-level Logic Optimization Giovanni De Micheli Integrated Systems Centre EPF Lausanne This presentation can be used for non-commercial purposes as long as this note and the copyright footers are not removed © Giovanni De Micheli – All rights reserved
(c) Giovanni De Micheli 2 Module 1 u Objective s Data structures for logic optimization s Data representation and encoding
(c) Giovanni De Micheli 3 Some more background u Function f ( x 1, x 2, …., x i, …., x n ) u Cofactor of f with respect to variable x i s f xi = f ( x 1, x 2, …., 1, …., x n ) u Cofactor of f with respect to variable x i ’ s f xi’ = f ( x 1, x 2, …., 0, …., x n ) u Boole’s expansion theorem: s f ( x 1, x 2, …., x i, …., x n ) = x i fx i + x i’ fx i ’ s Also credited to Claude Shannon
(c) Giovanni De Micheli 4 Example u Function: f = ab + bc + ac u Cofactors: s f a = b + c s f a’ = bc u Expansion: s f = a f a + a’f a’ = a(b + c) + a’bc
(c) Giovanni De Micheli 5 Unateness u Function f ( x 1, x 2, …., x i, …., x n ) u Positive unate in x i when: f xi ≥ f xi’ u Negative unate in x i when: f xi ≤ f xi’ u A function is positive/negative unate when positive/negative unate in all its variables
(c) Giovanni De Micheli 6 Operators u Function f ( x 1, x 2, …., x i, …., x n ) u Boolean difference of f w.r.t. variable x i : ∂f/∂x i ≡ f xi f xi’ u Consensus of f w.r.t. variable x i : C xi ≡ f xi. f xi’ u Smoothing of f w.r.t. variable x i : S xi ≡ f xi + f xi’
(c) Giovanni De Micheli 7 Example f = ab + bc + ac u The Boolean difference ∂f/∂a = f a f a’ = b’c + bc’ u The consensus C a = f a. f a’ = bc u The smoothing S a ≡ f a + f a’ = b + c b a c
(c) Giovanni De Micheli 8 Generalized expansion u Given: s A Boolean function f. s Orthonormal set of functions: i, i = 1, 2, …, k u Then: s f = ∑ i k i f i s Where f i is a generalized cofactor. u The generalized cofactor is not unique, but satisfies: s f i f I f + i ’
(c) Giovanni De Micheli 9 Example u Function: f = ab + bc + ac u Basis: 1 = ab and 2 = a’ + b’. u Bounds: s ab f 1 1 s a’bc + ab’c f 2 ab + bc + ac u Cofactors: f 1 = 1 and f 2 = a’bc + ab’c. f = 1 f 1 + 2 f 2 = ab1 + (a’ + b’)(a’bc + ab’c) = ab + bc + ac
(c) Giovanni De Micheli 10 Generalized expansion theorem u Given: s Two function f and g. s Orthonormal set of functions: i, i=1,2,…,k Boolean operator ⊙ u Then: f ⊙ g = ∑ i k i (f i ⊙ g i ) u Corollary: f ⊙ g = x i (f x i ⊙ g x i ) + x i ’ (f x i ’ ⊙ g x i ’ )
(c) Giovanni De Micheli 11 Matrix representation of logic covers u Representations used by logic minimizers u Different formats s Usually one row per implicant u Symbols: s 0, 1, *, … u Encoding:
(c) Giovanni De Micheli 12 Advantages of positional cube notation u Use binary values: s Two bits per symbols s More efficient than a byte (char) u Binary operations are applicable s Intersection – bitwise AND s Supercube – bitwise OR u Binary operations are very fast and can be parallelized
(c) Giovanni De Micheli 13 Example u f = a’d’ + a’b + ab’ + ac’d
(c) Giovanni De Micheli 14 Cofactor computation Cofactor of α w.r. to β Void when α does not intersect β s a 1 + b 1 ’ a 2 + b 2 ’ … a n + b n ’ Cofactor of a set C = { γ i } w.r. to β : Set of cofactors of γ i w.r. to β
(c) Giovanni De Micheli 15 Example f = a’b’ + ab u Cofactor w.r. to s First row – void s Second row – u Cofactor f a = b void
(c) Giovanni De Micheli 16 Multiple-valued-input functions u Input variables can take many values u Representations: s Literals: set of valid values s Function = sum of products of literals u Positional cube notation can be easily extended to mvi u Key fact s Multiple-output binary-valued functions represented as mvi single-output functions
(c) Giovanni De Micheli 17 Example u 2-input, 3-output function: s f 1 = a’b’ + ab s f 2 = ab s f 3 = ab’ + a’b u Mvi representation:
(c) Giovanni De Micheli 18 Module 2 u Objective s Operations on logic covers s Application of the recursive paradigm s Fundamental mechanisms used inside minimizers
(c) Giovanni De Micheli 19 Operations on logic covers u Recursive paradigm s Expand about a mv-variable s Apply operation to co-factors s Merge results u Unate heuristics s Operations on unate functions are simpler s Select variables so that cofactors become unate functions u Recursive paradigm is general and applicable to different data structures s Matrices and binary decision diagrams
(c) Giovanni De Micheli 20 Tautology u Check if a function is always TRUE u Recursive paradigm: s Expend about a mvi variable s If all cofactors are TRUE, then the function is a tautology u Unate heuristics s If cofactors are unate functions, additional criteria to determine tautology s Faster decision
(c) Giovanni De Micheli 21 Recursive tautology u TAUTOLOGY: s The cover matrix has a row of all 1s. (Tautology cube) u NO TAUTOLOGY: s The cover has a column of 0s. (A variable never takes a value) u TAUTOLOGY: s The cover depends on one variable, and there is no column of 0s in that field u Decomposition rule: s When a cover is the union of two subcovers that depend on disjoint sets of variables, then check tautology in both subcovers
(c) Giovanni De Micheli 22 Example f = ab + ac + ab’c’ + a’ u Select variable a u Cofactor w.r. to a’ is – Tautology. u Cofactor w.r. to a is: a b c
(c) Giovanni De Micheli Example (2) u Select variable b. u Cofactor w.r. to b’ is u No column of 0 - Tautology u Cofactor w.r. to b is: u Function is a TAUTOLOGY
(c) Giovanni De Micheli 24 Containment u Theorem: A cover F contains an implicant α if and only if F α is a tautology u Consequence: s Containment can be verified by the tautology algorithm
(c) Giovanni De Micheli 25 u Check covering of bc : u Take the cofactor: u Tautology – bc is contained by f. Example f = ab + ac + a’ a b c
(c) Giovanni De Micheli 26 Complementation u Recursive paradigm s f’ = x f’ x + x’ f’ x’ u Steps: s Select variable s Compute co-factors s Complement co-factors u Recur until cofactors can be complemented in a straightforward way
(c) Giovanni De Micheli 27 Termination rules u The cover F is void s Hence its complement is the universal cube u The cover F has a row of 1s s Hence F’ is a tautology and its complement is void u The cover F consists of one implicant. s Hence the complement is computed by DeMorgan’s law u All implicants of F depend on a single variable, and there is not a column of 0s. s The function is a tautology, and its complement is void
(c) Giovanni De Micheli 28 Unate functions u Theorem: s If f is positive unate in x, then t f’ = f’ x + x’ f’ x’ s If f is negative unate in x, then t f’ = x f’ x + f’ x’ u Consequence: t Complement computation is simpler t Follow only one branch in the recursion u Heuristics s Select variables to make the cofactor unate
(c) Giovanni De Micheli 29 Example f = ab + ac + a’ u Select binate variable a u Compute cofactors: s F a’ is a tautology, hence F’ a’ is void. s F a yields: a b c
(c) Giovanni De Micheli 30 Example (2) u Select unate variable b u Compute cofactors: s F ab is a tautology, hence F’ ab is void s F ab’ = and its complement is u Re-construct complement: s intersected with Cube (b’) = yields s intersected with Cube (a) = yields u Complement: F’ =
(c) Giovanni De Micheli 31 Example (3) u Recursive search: F a’ = TAUT COMP = ø F ab’ = c COMP = c’ F ab = TAUT COMP = ø a’ b b’ a Complement: a b’c’
(c) Giovanni De Micheli 32 Boolean cover manipulation summary u Recursive methods are efficient operators for logic covers s Applicable to matrix-oriented representations s Applicable to recursive data structures like BDDs u Good implementations of matrix-oriented recursive algorithms are still very competitive s Heuristics tuned to the matrix representations
(c) Giovanni De Micheli 33 Module 3 u Objectives s Heuristic two-level minimization s The algorithms of ESPRESSO
(c) Giovanni De Micheli 34 Heuristic logic minimization u Provide irredundant covers with “reasonably small” sizes u Fast and applicable to many functions s Much faster than exact minimization u Avoid bottlenecks of exact minimization s Prime generation and storage s Covering u Motivation s Use as internal engine within multi-level synthesis tools
(c) Giovanni De Micheli 35 Heuristic minimization -- principles u Start from initial cover s Provided by designer or extracted from hardware language model u Modify cover under consideration s Make it prime and irredundant s Perturb cover and re-iterate until a small irredundant cover is obtained u Typically the size of the cover decreases s Operations on limited-size covers are fast
(c) Giovanni De Micheli 36 Heuristic minimization - operators u Expand s Make implicants prime s Removed covered implicants u Reduce s Reduce size of each implicant while preserving cover u Reshape s Modify implicant pairs: enlarge one and reduce the other u Irredundant s Make cover irredundant
(c) Giovanni De Micheli 37 Example u Initial cover s (without positional cube notation)
(c) Giovanni De Micheli 38 Example u Set of primes a b c d α 0 * * 0 1 ζ * ε 1 * δ 1 0 * * 1 γ 0 1 * * 1 β * 0 *
(c) Giovanni De Micheli 39 Example of expansion Expand 0000 to α = 0**0. s Drop 0100, 0010, 0110 from the cover. Expand 1000 to β = *0*0. s Drop 1010 from the cover. Expand 0101 to γ = 01**. s Drop 0111 from the cover. Expand 1001 to δ = 10**. s Drop 1011 from the cover. Expand 1101 to ε = 1*01. Cover is: { α, β, γ, δ, ε }. a b c d
(c) Giovanni De Micheli 40 Example of reduction u Reduce 0**0 to nothing. Reduce β = *0*0 to β ’ = 00*0. Reduce ε = 1*01 to ε ’ = Cover is: { β ’, γ, δ, ε ’}. a b c d
(c) Giovanni De Micheli 41 Example of reshape Reshape { β ’, δ } to: { β, δ ’}. Where δ ’ = 10*1. Cover is: { β, γ, δ ’, ε ’}. a b c d
(c) Giovanni De Micheli 42 Example of second expansion Expand δ ’ = 10*1 to δ = 10**. Expand ε ’ = 1101 to ε = 1*01. a b c d
(c) Giovanni De Micheli 43 Example Summary of the steps taken by MINI u Expansion: Cover: { α, β, γ, δ, ε }. s Prime, redundant, minimal w.r. to scc. u Reduction: α eliminated. β = *0*0 reduced to β ’ = 00*0. ε = 1*01 reduced to ε ’ = Cover: { β ’, γ, δ, ε ’}. u Reshape: { β ’, δ } reshaped to: { β, δ ’} where δ ’ = 10*1. u Second expansion: Cover: { β, γ, δ, ε }. s Prime, irredundant.
(c) Giovanni De Micheli 44 Example Summary of the steps taken by ESPRESSO u Expansion: Cover: { α, β, γ, δ, ε }. s Prime, redundant, minimal w.r. to scc. u Irredundant: Cover: { β, γ, δ, ε }. s Prime, irredundant. a b c d
(c) Giovanni De Micheli 45 Rough comparison of minimizers u MINI s Iterate EXPAND, REDUCE, RESHAPE u Espresso s Iterate EXPAND, IRREDUNDANT, REDUCE u Espresso guarantees an irredundant cover s Because of the irredundant operator u MINI may return irredundant covers, but can guarantee only minimality w.r.to single implicant containment
(c) Giovanni De Micheli 46 Expand Naïve implementation u For each implicant s For each care literal t Raise it to don’t care if possible s Remove all implicants covered by expanded implicant u Issues s Validity check of expansion s Order of expansion
(c) Giovanni De Micheli 47 Validity check u Espresso, MINI s Check intersection of expanded implicant with OFF-set s Requires complementation u Presto s Check inclusion of expanded implicant in the union of the ON-set and DC-set s Reducible to recursive tautology check
(c) Giovanni De Micheli 48 Ordering heuristics u Expand the cubes that are unlikely to be covered by other cubes u Selection: s Compute vector of column sums s Weight : inner product of cube and vector s Sort implicants in ascending order of weight u Rationale: s Low weight correlates to having few 1s in densely populated columns
(c) Giovanni De Micheli 49 Example u f = a’b’c’ + ab’c’ + a’bc’ + a’b’c DC-set = abc’ u Ordering: s Vector: [ ] T s Weights: (9, 7, 7, 7) u Select second implicant
(c) Giovanni De Micheli 50 Example (2) b a c α δ γ β
(c) Giovanni De Micheli 51 Example (3) u OFF-set: u Expand : s valid. s valid. s invalid. u Update cover to:
(c) Giovanni De Micheli 52 Example (4) u Expand : s invalid. s invalid. s valid. u Expand cover:
(c) Giovanni De Micheli 53 Expand heuristics in ESPRESSO u Special heuristic to choose the order of literals u Rationale: s Raise literals to that expanded implicant t Covers a maximal set of cubes t Overlaps with a maximal set of cubes t The implicant is as large as possible u Intuitive argument s Pair implicant to be expanded with other implicants, to check the fruitful directions for expansion
(c) Giovanni De Micheli 54 Expand in Espresso u Compare implicant with OFF-set. s Determine possible and impossible directions of expansion u Detection of feasibly covered implicants If there is an implicant β whose supercube with α is feasible, expand α to that supercube and remove β Raise those literals of α to overlap a maximum number of implicants s It is likely that the uncovered part of those implicant is covered by some other expanded cube u Find the largest prime implicant s Formulate a covering problem and solve it heuristically
(c) Giovanni De Micheli 55 Reduce u Sort implicants s Heuristics: sort by descending weight s Opposite to the heurstic sorting for expand u Maximal reduction can be determine exactly u Theorem: Let α be in F and Q = F U D – { α } Then, the maximally reduced cube is: ά = α ∩ supercube (Q’ α )
(c) Giovanni De Micheli 56 Example u Expand cover: u Select first implicant: s Cannot be reduced. u Select second implicant: s Reduced to u Reduced cover:
(c) Giovanni De Micheli 57 Irredundant cover b a c α δ γ β ε
(c) Giovanni De Micheli 58 Irredundant cover u Relatively essential set E r s Implicants covering some minterms of the function not covered by other implicants s Important remark: we do not know all the primes! u Totally redundant set R t s Implicants covered by the relatively essentials u Partially redundant set R p s Remaining implicants
(c) Giovanni De Micheli 59 Irredundant cover u Find a subset of R p that, together with E r covers the function u Modification of the tautology algorithm s Each cube in R p is covered by other cubes s Find mutual covering relations u Reduces to a covering problem s Apply a heuristic algorithm. s Note that even by applying an exact algorithm, a minimum solution may not be found, because we do not have all primes.
(c) Giovanni De Micheli 60 Example E r = { α, ε } R t = ∅ R p = { β, γ, δ } α δ γ β ε
(c) Giovanni De Micheli 61 Example (2) u Covering relations: β is covered by { α, γ }. γ is covered by { β, δ }. δ is covered by { γ, ε }. Minimum cover: γ U E r
(c) Giovanni De Micheli 62 ESPRESSO algorithm in short u Compute the complement u Extract essentials u Iterate s Expand, irredundant and reduce u Cost functions: Cover cardinality φ 1 Weighted sum of cube and literal count φ 2
(c) Giovanni De Micheli 63 ESPRESSO algorithm in detail espresso(F,D) { R = complement(F U D); F = expand(F,R); F = irredundant(F,D); E = essentials(F,D); F = F – E; D = D U E; repeat { 2 = cost(F); repeat { 1 = |F |; F = reduce(F,D); F = expand(F,R); F = irredundant(F,D); } until (|F | ≥ 1 ); F = last_gasp(F,D,R); } until ( | F | ≥ 1 ); F = F U E; D = D – E; F = make_sparse(F,D,R); }
(c) Giovanni De Micheli 64 Heuristic two-level minimization Summary u Heuristic minimization is iterative u Few operators are applied to covers u Underlying mechanism s Cube operation s Unate recursive mechanism u Efficient algorithms