11/02/2014 ENGG3190 Logic Synthesis “Binary Decision Diagrams” BDDs Winter 2014 S. Areibi School of Engineering University of Guelph Outline • Binary Decision Diagrams (BDDs) – Ordering – Reduction • • • • • Canonical Form Equivalency Usefulness of BDDs Operations on BDDs Applications 0 0 0 1 0 1 1 0 2 ROBDD’s BDD Construction – naïve way • • • • • Directed acyclic graph (DAG) One root node, two terminal nodes 0, 1 (sinks) Each node has exactly two children, associated with a variable Shannon co-factoring tree, except reduced and ordered (ROBDD) – Reduced: • any node with two identical children is removed • two nodes with isomorphic BDD’s are merged – Ordered: • Co-factoring variables (splitting variables) always follow the same order along all paths xi < xi < xi < … < xin 1 2 Ordered BDD a b c f 0 0 0 0 1 1 1 1 0 0 0 1 0 1 0 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 Truth table 3 3 f = ac + bc 1 edge 0 edge f a b b c 0 c 0 0 c 1 0 c 1 0 1 Decision tree 6 1 11/02/2014 Onset is Given by all Paths to “1” F = b’+a’c’ = ab’+a’cb’+a’c’ BDD encodes all paths to the 1 node 0 fa = cb’+c’ c a 1 1 fa= b’ b 0 1 0 f 0 1 Notes: • By tracing paths to the 1 node, we get a cover of pairwise disjoint cubes. • The power of the BDD representation is that it does not explicitly enumerate all paths; rather it represents paths by a graph whose size is measured by the number of the nodes, and not paths. A DAG can represent an exponential number of paths with a linear size (number of nodes) in terms of its variables. • 10 Binary Decision Diagrams (BDD) f a • Based on recursive Shannon expansion b f = a fa + a’ fa’ b c 0 c 0 0 c 1 0 c 1 0 1 • Compact data structure for Boolean logic – can represents sets of objects (states) encoded as Boolean functions Any reason why Order X1, X2, X3? • Canonical representation – reduced ordered BDDs (ROBDD) are canonical – essential for verification The lower tree is a different tree and that is going to be a PROBLEM!! 0 0 1 1 8 Theorem Theorem 1 (Bryant - 1986) ROBDD’s are canonical Thus two functions are the same iff their ROBDD’s are equivalent graphs (isomorphic). Of course must use same order for variables. 9 2 11/02/2014 BDD Example Root node f = ab+a’c+bc’d a a 1 c+bd c+bd c b c+d c b b c 0 d*b d c b b d d 0 1 0 1 Two different orderings, same function. 13 If we say we insist on x1, x2, x3 order, now what? Figure on Left is ok Figure on right is also ok (different but equivalent). Why? PROBLEM!! Even though they are equivalent they are not canonical Some Benefits of BDDs • Check for tautology is trivial. – BDD is a constant 1. • Complementation. – Given a BDD for a function f, the BDD for f’ can be obtained by interchanging the terminal nodes. Every path from the root to a leaf visits the variables in the SAME ORDER • Equivalence check. – Two functions f and g are equivalent if their BDDs (under the same variable ordering) are the same. BDDs: Reduction Rules Reduction Rules for BDDs. Reduced Ordered BDDs ROBDD. Wrong and Stupid! 3 11/02/2014 X Z Y We will reduce the Diagrams ROBDDs Idea #1: Hey lets use Decision Diagrams Idea #2: Lets impose a global variable ordering Idea #3: Reduction ROBDD Ordered BDD (OBDD): Input variables are ordered - each path from root to sink visits nodes with labels (variables) in the same order. X1 Not reduced ! a a ordered {a,c,b} not ordered X2 c c b b b c 0 1 0 X2 c X3 X3 1 1 0 Reduced Ordered BDD (ROBDD) - reduction rules: – if the two children of a node are the same, the node is eliminated: f = v f + v’ f – if two nodes have isomorphic (identical) graphs, they are replaced by one of them These two rules make it so that each node represents a distinct logic function. 20 BDD Reduction Rule -2 • Merge duplicate nodes (isomorphic subgraphs) • Nodes must be unique f1 a b c g We will use Reduction Rules: Rule #1 (simple) keep one copy of each constant leaf! So the result is we got rid of all the redundancy of the leaf nodes. But can we do better? We still have one X1 node, two X2 nodes, four X3 nodes!! f f2 a a h f1 = fa’ g(b) + fa h(c) = f2 g b h c f = f1 = f2 24 4 11/02/2014 BDD Construction – Example f f a f = (a+b)c a b b b a b b Y c c 0 c c 1 1. Merge terminal nodes c 0 c 1 2. Merge duplicate nodes c 0 1 3. Remove redundant nodes 28 BDD Reduction Rules -3 • Eliminate redundant nodes (with both edges pointing to same node) f a g We started with a Decision Diagram which is big We reduced it and have now ROBDD g b RESULT: ROBDD is a Canonical Form (data structure) for any Boolean Function! Great property to have, the simplest form of a graph is a canonical form b f = a g(b) + a’ g(b) = g(b) 26 … Reduced Binary Decision Diagrams … 5 11/02/2014 Reduced Binary Decision Diagrams … x1 xor x2 xor x3 xor x4 X1X4 + X2X4 v1 is the root; index(v1)=1 meaning that v1 is related to first variable in the order i.e. x1=a Make X1=1, X2=1, X3=1, X4=0 will lead to a 1 BDDs: Sharing Sharing in BDDs. Advantages of Sharing. G = x2x4 x3 xor x4 x3 xnor x4 x4‘ f x F points to 0 0 0 1 f F points to 1 1 • So far we showed how to construct a Reduced Ordered BDD • What can we do with it? Represent any Boolean Function • We can Share nodes in BDDs The big grey boxes of S3 and Cout are the same shared function (identical) Question: Do we have to build the grey stuff twice?? (BDD for S3 and BDD for Cout) The Answer should be NO since it is inefficient 6 11/02/2014 H S Cout F H G H shared We cannot implement and build BDDs flat! Not practical. Is there a better way? Always start with reduced ordered BDDs We use recursive methods (DIVIDE & CONQUER) BDD packages are implemented using different functions. • Simple calls to operators (AND, OR, …) creates the Binary Decision Diagram Incrementally • Can this work for more complicated networks? YES (using BDD Packages) • However, we have to think of “What are we going to do with variable ordering”? BDDs: Applications How are BDDs really implemented? Applications: Are two complicated logic circuits equivalent? If not, how are they different? How you can make a complicated Boolean function equal 1. How can ordering help? Shared BDDs F G What values for H which make it “1” Remember that Boolean functions represent different pieces of logic. Remember also that ROBDD are canonical . Since we are building shared BDDs they will be exactly the same, you get the same graph. What inputs make functions F, G different? In reality we can connect all variables to inputs of two blocks and the output connected to XOR 7 11/02/2014 Logic Manipulation using BDDs Application to Verification Useful operators • Equivalence Checking of combinational circuits • Canonicity property of BDDs: F = a’bc + abc + ab’c ≡ b a 1 (switch the terminal nodes) G = ac + bc 0 1 1 0 F(y) F(x,y) – Restrict: F|x=b = F(x=b) where b = const Restrict b c 0 F’ ¬ – Complement ¬ F = F’ – if F and G are equivalent, their BDDs are identical (for the same ordering of variables) a F • To restrict variable x to 1, reconnect all incoming edges to nodes x to their 1-nodes • To restrict variable x to 0, reconnect all incoming edges to nodes x to their 0-nodes c 0 0 x=b 1 0 1 1 43 46 Restrict Operator ( f (c=0, d=1) ) f = (a+d)(b+c)+a’d’bc fc’ = (a+d)b a a d f if X1=1, X2=don’t care, X3=don’t care, X4=1 1 b b c 0 b b b 1 0 1 b 1 0 Set c = 0 0 Set d = 1 1 Restricted BDD 47 Apply Operation Concept Functional test generation H – SAT, Boolean satisfiability analysis – to test for H = 1 (0), find a path in the BDD to terminal 1 (0) – the path, expressed in function variables, gives a satisfying solution (test vector) Basic technique for building OBDD from Boolean formula. A op B A op B a a a a ⇒ b b ab c | d 0 c • Problem:?? size explosion!!! fc’d = b c Original BDD Application to SAT • a d c d b If we can prove that the function F points to the 1 node then we can easily say it is a Tautology! How about statisfiability? In example on right hand side: Satisfiability is achieved if X1=1, X2=don’t care, X3=don’t care, X4=1 Or another path would be X1=0, X2=1, X3=don’t care and X4=1 Another operator in BDD package (satisfiability) fc’d= (a+1)b = b 0 ab’c 0 1 Arguments A, B, op A and B: Boolean Functions 1 Represented as OBDDs op: Boolean Operation (e.g., ^, &, |) 45 c d d 1 b c 0 1 Result OBDD representing composite function A op B – 48 – 8 11/02/2014 The APPLY Operation The ITE Operator Table This is the most important of all the operations that can be performed on the BDDs. Name The APPLY operation provides the basic method for creating the representation of a function according to the operators in a Boolean expression or logic gate network. APPLY takes graphs representing functions f1 and f2 , a binary operator <op> and produces a reduced graph representing the function f1 <op> f2 defined as : [f1 <op> f2 ] ( x1, x2, … , xn ) = f1(x1, x2, … , xn ) <op> f2 (x1, x2, … , xn ) The algorithm proceeds from the roots of the 2 argument graphs downward, creating vertices in the result graph at the branching points of the 2 argument graphs. The control structure of the algorithm is based on the Shannon’s expansion equation/theorem given below: f1 <op> f2 = ~xi . ( f1|xi = 0 <op> f2 |xi = 0 ) + xi . ( f1|xi = 1 <op> f2 |xi = 1 ) Expression Equivalent Form 0 0 AND(F,G) F.G ITE( F, G, 0 ) F >G F. ~G ITE( F, ~G, 0) 0 F F F F<G ~F . G ITE( F, 0 , G) G G G F (+) G ITE( F, ~G, G ) XOR( F, G ) OR( F, G ) F+G ITE( F, 1, G ) NOR( F, G ) ~( F + G ) ITE( F, 0 , ~G ) XNOR( F, G ) ~( F (+) G ) ITE( F, G, ~G ) NOT( G ) ~G ITE( G, 0, 1 ) F >= G F+ ~G ITE( F, 1, ~G ) NOT( F) ~F ITE( F, 0, 1 ) F <= G ~F + G ITE( F, G, 1 ) NAND( F, G ) ~(F.G ) ITE( F, ~G, 1 ) 1 1 1 – 49 – 52 APPLY* using ITE operator The ITE Operator An Example ITE operators are used as they give a straight forward implementation of the APPLY operation. This is based on the Shannon’s expansion theorem and this is called the ‘If-Then-Else’ operator. This is a ternary operator defined as follows: ITE( F, G, H ) = F.G + ~F.H where F, G , H are 3 arbitrary switching functions. Ex: We want to find ~( a.c ) + b.c using APPLY. Given F = ~(a.c) and G = b .c in the form of a BDD. ~( a . c ) A very important property of the ITE operator which is of great interest for this presentation, and for BDD in general, is that all two-argument operators can be expressed in terms of the ITE operator . + b.c a b The above mentioned property gives great power to manipulate switching functions and hence are used extensively in manipulating the BDD. c c 1 0 0 1 50 The ITE operator - Example 53 APPLY Example Contd.. Assume ordering is a < b < c. ITE( ~(a.c) , 1, bc ) ITE( F, G, H) = F.G + ~F.H For sake of simplicity, assume F = x and G = y as the input functions on which manipulations are to be done. Consider ITE( F, 1, G) : ITE( F, 1, G ) = F.1 + ~F.G = x + ~x . y = x+y Consider ITE( F,G,0 ): a 0 1 ITE( 1, 1 , bc ) = ( 1.1 + 0.bc ) ITE( ~c , 1, bc ) b ITE( F, G, 0 ) = F.G + ~F.0 = x.y + 0 = x.y 1 0 ITE( ~c, 1, c ) ITE( ~c, 1, 0 ) 1 c 0 ITE( 1, 1, 0 ) = ( 1.1. + 0.0 ) 1 0 ITE( 0, 1, 0 ) = ( 0.1 + 1.0 ) ITE( 1, 1, 0 ) = ( 1.1 + 0.0 ) 1 ITE( 0, 1, 1 ) = ( 0.1 + 1.1 ) The above 2 examples show the powerfulness of, and the simplicity with which ITE operator can be used to express 2 argument operators. 1 51 0 1 1 54 9 11/02/2014 linear growth O(n) Why too good to be true? Because you can say “I can take any complicated problem profoundly exponentially computer science problem and use BDDs to solve it”? Variable Ordering matters!!’ The figure on the left has linear growth O(n) But figure on the right is exponential (bad ordering) So BDD will have efficient solutions if you have good ordering. But that is not always the case! 1. Multipliers are not good candidates to make a BDD 2. Adders on the other hand are good candidates ai.bi can together determine the F() Worst Order! all a’s first then b’s!! This makes the Tree fatter and more complicated! 60 10 11/02/2014 Apply Execution Example Useful BDD Operators – Apply Operation Argument A • • Argument B A1 a Basic operator for efficient BDD manipulation (structural) Based on recursive Shannon expansion A2 b | A3,B2 B2 d A4 0 A6,B2 A6,B5 c B5 A3 d where <op> = binary operations: OR, AND, XOR, etc A1,B1 A2,B2 Operation c A6 F <op> G = x (Fx <op> Gx) + x’(Fx’ <op> Gx’) Recursive Calls a B1 1 A5 A5,B2 A3,B4 1 B4 A4,B3 A5 ,B4 B3 0 Optimizations Dynamic programming Early termination rules 61 Apply Result Generation APPLY Operator • Apply: F – 64 – G, any Boolean operation Recursive Calls (AND, OR, XOR, →) F F G 1 • G 0 0 A3,B2 1 c A5,B2 A3,B4 A4,B3 A5 ,B4 • Useful in constructing BDD for arbitrary Boolean logic • Any logic operation can be expressed using Apply (ITE) • Efficient algorithms, work directly on BDD graphs Apply Operation (cont’d) Apply: F • where d 1 0 1 1 Apply Operation - AND F • G = x (Fx • Gx) + x’(Fx’ • Gx’) stands for any Boolean operator (AND, OR, XOR, etc) F F G 0 1 • a AND c G ac = • a 2.3 a 2 0 = 1 0 1 c 3 AND • Any logic operation can be expressed using only Restrict and Apply • Efficient algorithms, work directly on BDDs • Apply can be used to construct a BDD bottom-up • 0 c c 1 – 65 – G • d Recursive calling structure implicitly defines unreduced BDD Apply reduction rules bottom-up as return from recursive calls 62 • a b b A6,B2 A6,B5 1 With Reduction a A2,B2 = • 0 Without Reduction A1,B1 0 1 0 1 1.3 0⋅3 1⋅0 c 1⋅1 a = c 0 1 From primary inputs, through internal logic gates, to output 63 66 11 11/02/2014 Apply Operation - OR F + G = x (Fx + Gx) + x’(Fx’ +Gx’) f = ac+bc ac bc a 4 OR c 0 1 b 6 5 c 0 a a 4+6 0+6 7 1 b 6+5 = 0+7 0+5 7+5 0+0 0 b c = 1 c 0 1 67 Some History Origins Lee 1959, Akers 1976 Idea of representing Boolean function as BDD Hopcroft, Fortune, Schmidt 1978 Recognized that ordered BDDs were like finite state machines Polynomial algorithm for equivalence Bryant 1986 Proposed as useful data structure + efficient algorithms McMillan 1993 Developed symbolic model checking Method for verifying complex sequential systems Bryant 1991 Proved that multiplication has exponential BDD No matter how variables are ordered – 68 – 12
© Copyright 2024