05-BDD

download 05-BDD

of 12

Transcript of 05-BDD

  • 8/10/2019 05-BDD

    1/12

    ECE 474a/575aSusan Lysecky

    1of 31

    ECE 474A/57AComputer-Aided Logic Design

    Lecture 11Binary Decision Diagrams (BDDs)

    ECE 474a/575aSusan Lysecky

    2of 31

    Boolean Logic Functions Representations

    Function can be represented in different waysTruth table, equation, K-map, circuit, etcSome representations not unique (not canonical)

    a

    a

    b

    F

    F

    Circuit 1

    Circuit 2

    a

    0

    0

    1

    1

    b

    0

    1

    0

    1

    F

    1

    1

    0

    0

    The function F

    Truth table

    Equation 2: F(a,b) = a

    Equation 1: F(a,b) = ab+ ab

    1 1

    0 1

    0 0

    0

    1

    F ba

    ECE 474a/575aSusan Lysecky

    3of 31

    Why BDDs An Efficient Representation

    Synthesis, optimization, verification, and testing algorithms/tools manipulatelarge Boolean functions

    Important to have efficient way to represent these functionsBinary Decision Diagrams (BDDs) have emerged as a popular choice for representingthese functions

    BDDsGraph representation similar to a binary tree (i.e. decision trees from previouslectures)

    Able to efficiently represent large functionsSome representations are canonical (unique)

  • 8/10/2019 05-BDD

    2/12

    ECE 474a/575aSusan Lysecky

    4of 31

    Mux Representation of Boolean Functions

    MUX circuit to implement logicfunction S

    S(x1, x2, x3)

    x3

    x2

    x1

    10MUX

    01

    10MUX

    1

    10MUX

    01

    10MUX

    x3x2x1 S

    000 1100 0010 1110 1001 1101 1011 0111 0

    S(0, 0, 0) = 1

    X3 (0)

    x2 (0)

    X1 (0)

    10MUX

    01

    10MUX

    1

    10MUX

    01

    10MUX

    S(0, 0, 1) = 0

    X3 (1)

    x2 (0)

    X1 (0)

    10MUX

    01

    10MUX

    1

    10MUX

    01

    10MUX

    S(0, 1, 0) = 1

    X3 (0)

    x2 (1)

    X1 (0)

    10MUX

    01

    10MUX

    1

    10MUX

    01

    10MUX

    S(1, 1, 1) = 0

    X3 (1)

    x2 (1)

    X1 (1)

    10MUX

    01

    10MUX

    1

    10MUX

    01

    10MUX

    ECE 474a/575aSusan Lysecky

    5of 31

    Mux Representation of Boolean FunctionsRelation to BDDs

    Corresponding BDD to implement function SOne-to-one correspondence to the MUX gates inthe flipped circuit

    x3x2x1 S

    000 1100 0010 1110 1001 1101 1011 0111 0

    S(x1, x2, x3)

    x3

    x2

    x1

    10MUX

    01

    10MUX

    1

    10MUX

    01

    10MUX

    Same circuit, justflipped

    Corresponding BDD

    1 0

    x1

    x2x2

    x3

    S(x1, x2, x3)

    S(x1, x2, x3)

    x3

    x2

    x1

    10MUX

    01

    10MUX

    1

    10MUX

    01

    10MUX

    ECE 474a/575aSusan Lysecky

    6of 31

    Binary Decision Diagram (BDD)Example 1

    How does it work?Line with bubble represent value = 0Lines without bubble represent value = 1

    x3x2x1 S

    000 1100 0010 1110 1001 1101 1011 0111 0

    1 0

    x1

    x2x2

    x3

    S(x1, x2, x3)

    1 0

    x1

    x2x2

    x3

    S(0, 0, 0)

    1 0

    x1

    x2x2

    x3

    S(1, 1, 1)

    1 0

    x1

    x2x2

    x3

    S(0, 1, 0)

    1 0

    x1

    x2x2

    x3

    S(0, 0, 1)

  • 8/10/2019 05-BDD

    3/12

    ECE 474a/575aSusan Lysecky

    7of 31

    Binary Decision Diagram (BDD)Edge Notations

    Several ways to represent value = 1 and value = 0Bubble vs. Non-bubble lineDashed vs. Solid line

    T (then) vs. E (else) labelsWe will adopt T vs. E labels consistent with most of the book (Hatchel) examples

    1 0

    x1

    x2x2

    x3

    S(x1, x2, x3)

    1 0

    x1

    x2x2

    x3

    S(x1, x2, x3)

    1 0

    x1

    x2x2

    x3

    S(x1, x2, x3)

    T

    E

    TE

    T

    E

    T

    E

    ECE 474a/575aSusan Lysecky

    8of 31

    Binary Decision Diagram (BDD)Example 2

    Lets consider another functionf(a,b,c,d) = abc + bd + cd

    1 0

    a

    bb

    dT

    E

    T TE

    E

    T

    E

    f

    cc

    T T

    EE

    1 0

    a

    bb

    dT

    E

    T TE

    E

    T

    E

    f

    cc

    T T

    EE

    What is the value of f(1,0,1,0)?

    Notice that if a=1 and b=0, thefunction does not depend on a

    value for c.

    1 0

    a

    bb

    dT

    E

    T TE

    E

    T

    E

    f

    cc

    T T

    EE

    What is the value of f(1,1,0,1)?

    ECE 474a/575aSusan Lysecky

    9of 31

    Ordered Binary Decision Diagram (OBDD)What is a OBDD?

    Ordered binary decision diagrams ensure the variables appear inthe same order along all paths from the root to the leaves

    0 1

    a

    cc

    T

    T TE

    E

    E

    f

    bT

    E

    Ordering : a c b Not ordered

    1 0

    a

    cb

    T

    T

    T

    E

    E

    E

    f

    bc

    T

    TE

    E

  • 8/10/2019 05-BDD

    4/12

    ECE 474a/575aSusan Lysecky

    10of 31

    Ordered Binary Decision Diagram (OBDD)Different Ordering Lead to Different Complexity Example1

    Variable ordering important, may result in a more complex (or simple) BDD All three BDDs below represent the same functionThird ordering (b c a d) optimal because there is exactly one node foreach variable

    1 0

    b

    c

    dT

    E

    T

    E

    T

    E

    f

    a

    T

    E

    Order : b c a d

    1 0

    a

    bb

    dT

    E

    T TE

    E

    T

    E

    f

    cc

    T T

    EE

    Order : a b c d

    1 0

    a

    dd

    cT

    E

    T TE

    E

    T

    E

    f

    bb

    T TEE

    Order : a d b c

    cT

    E

    ECE 474a/575aSusan Lysecky

    11of 31

    Ordered Binary Decision Diagram (OBDD)Different Ordering Lead to Different Complexity Example 2

    Consider F = ab + cd + ef, again both BDDs represent same function Variable order has a large impact on resulting BDD, first variable ordering (a b c d e f) yields a much simpler BDD

    Order : a b c d e f Order : a c e b d f

    0 1

    a

    b

    e

    dT

    E

    TT

    E

    E

    T

    E

    f

    f

    c

    T

    T

    E

    E

    0

    a

    e

    c

    f

    bb

    c

    e e e

    bb

    d d

    f

    1

    ECE 474a/575aSusan Lysecky

    12of 31

    BDDs for Basic Logic Functions

    1 0

    aTE

    f

    NOTa F

    0 11 0

    ANDba F

    00 010 001 011 1

    1 0

    a

    b

    E

    T

    T

    E

    f

    ORba F

    00 010 101 111 1

    1 0

    a

    b

    E

    ET

    T

    f

    XORba F

    00 010 101 111 0

    1 0

    a

    bb

    E

    E E

    T

    T

    T

    f

    NANDba F

    00 110 101 111 0

    f

    01

    a

    b

    E

    T

    T

    E

  • 8/10/2019 05-BDD

    5/12

    ECE 474a/575aSusan Lysecky

    13of 31

    Formal Definition of BDDs

    A BDD is a direct acyclic graph (DAG) representing amultiple-output switching function F

    Nodes are partitioned into three subsets

    Function nodeRepresents the function symbol (f)Indegree = 0Outdegree = 1

    Internal nodeRepresents variable in function (a, b, c, d)Indegree 1Outdegree = 2

    Terminal nodeRepresents a value (1 or 0)Indegree 1Outdegree = 0

    1 0

    b

    c

    dT

    E

    T

    E

    T

    E

    f

    a

    T

    E

    Function node

    Internalnodes

    Terminal nodes

    ECE 474a/575aSusan Lysecky

    14of 31

    Formal Definition of BDDs

    A BDD definition (cont)Three types of edges

    Incoming edge

    From the function node and defines functionT edge

    From an internal node and represents whenthe corresponding variable is 1

    E edge

    From an internal node and represents whenthe corresponding variable is 0

    1 0

    b

    c

    dT

    E

    T

    E

    T

    E

    f

    a

    T

    E

    Incoming edge

    E edge

    T edge

    ECE 474a/575aSusan Lysecky

    15of 31

    Formal Definition of BDDs

    A BDD definition (cont)The function f represented by a BDD isdefined as follows

    The function of the terminal node is aconstant value (1 or 0)The function of a T edge is the function ofthe head nodeThe function of a E edge is the complementof the function of the nodeThe function of a node v is given by vf T +vf E, when f T is the function of the T edge andf E is the function of the E edgeThe function of the function node is thefunction of its outgoing edge

    1 0

    b

    c

    dT

    E

    T

    E

    T

    E

    f

    a

    T

    E

    Function of the functionnode is the function ofits outgoing edge

    Function of thisT edge is a

    Function of this terminal node is 1

    Function of this terminalnode is 0

    Function of thisE edge is a

  • 8/10/2019 05-BDD

    6/12

  • 8/10/2019 05-BDD

    7/12

    ECE 474a/575aSusan Lysecky

    19of 31

    Building BDDs - Exercise 1

    Build a BDD for f = abc+ abc + abc+ abc Use the variable ordering a b c

    f

    Compute cofactors of f a and f a with respect to b(second variable in ordering)

    f a = bc+ bc

    f a = bc+ bc

    (f a)b = f ab = c

    aET

    f

    partial expansionwith respect to b

    (f a)b = f ab = c

    bET

    f ab f ab

    (f a)b = f ab = c

    (f a)b = f ab = c

    bET

    f ab f ab

    aET

    f a f a

    ECE 474a/575aSusan Lysecky

    20of 31

    Building BDDs - Exercise 1

    Build a BDD for f = abc+ abc + abc+ abc Use the variable ordering a b c

    f

    Compute cofactors of f ab , f ab, f ab, f ab with respectto c (third variable in ordering)

    f ab = c

    f ab = c

    f ab

    = c

    f ab = c

    expansion withrespect to c, finalBDD

    f abc = 0

    f abc = 1a

    ET

    f

    bET

    bET

    cET

    1 0

    f abc = 1f abc = 0 c

    ET

    1 0f abc = 0

    f abc = 1

    cET

    0 1

    f abc = 0

    f abc = 1

    cET

    0 1

    aET

    bET

    f ab f ab

    bET

    f ab f ab

    ECE 474a/575aSusan Lysecky

    21of 31

    Building BDDs - Exercise 1

    f = abc + abc + abc + abc

    aET

    f

    bET

    bET

    cET

    cET

    cET

    cET

    1 0 1 0 0 1 0 1

    Does it work?

    f b00110011

    c01010101

    a00001111

    10100101

  • 8/10/2019 05-BDD

    8/12

    ECE 474a/575aSusan Lysecky

    22of 31

    Building BDDs - Exercise 2

    Build a BDD for f = abc+ bd + cdUse the variable ordering b c d a

    f

    Compute cofactors of f with respectto b (first variable in ordering)

    f = abc + bd+ cd

    f b = d + cd

    bET

    f

    f b f b

    partial expansionwith respect to b

    f b = ac + cd

    ECE 474a/575aSusan Lysecky

    23of 31

    Building BDDs - Exercise 2

    Build a BDD for f = abc+ bd + cdUse the variable ordering b c d a

    Compute cofactors of f b and f b with respect to c(second variable in ordering)

    f b = ac + cd

    f b = d + cd

    bET

    f

    f b f b

    bET

    f

    f bc

    cE

    T

    f bc = f bc = f bc

    equivalentcofactors, we cancreate a singlenode (reduced)

    f bc = d

    f bc = d

    f bc

    cET

    f bcf bc

    cET

    f bc

    bET

    f

    f bc = a

    f bc = d

    partial expansionwith respect to c

    ECE 474a/575aSusan Lysecky

    24of 31

    Building BDDs - Exercise 2

    Build a BDD for f = abc+ bd + cdUse the variable ordering b c d a

    Compute cofactors of f bc, f bc, and f bc withrespect to d (third variable in ordering)

    f bc = f bc = f bc = d

    bET

    f

    f bc

    cET

    f bc = f bc = f bc

    f bcd = f bcd = f bcd = 1

    f bcd = f bcd = f bcd = 0

    bET

    f

    f bc

    cET

    dET

    1 0

    partial expansionwith respect to d

  • 8/10/2019 05-BDD

    9/12

    ECE 474a/575aSusan Lysecky

    25of 31

    Building BDDs - Exercise 2

    Build a BDD for f = abc+ bd + cdUse the variable ordering b c d a

    Compute cofactors of f bc with respect to a (fourthvariable in ordering)

    bET

    f

    f bc

    c ET

    f bc = a

    dET

    1 0

    bET

    f

    cE

    T

    dET

    1 0

    f bca = 1

    f bca = 0

    aET

    expansion withrespect to a, finalBDD

    ECE 474a/575aSusan Lysecky

    26of 31

    Building BDDs - Exercise 2

    Build a BDD for f = abc + bd + cd

    Does it work?

    bET

    f

    cET

    dET

    1 0

    aET

    f b00001111

    c00110011

    d01010101

    a00000000

    0000111

    1

    0011001

    1

    0101010

    1

    1111111

    1

    010101000101011

    1

    ECE 474a/575aSusan Lysecky

    27of 31

    BDD to Boolean Function Exercise 1

    Can we go from a BDD to a Boolean function ?Sum all paths from function node to terminal nodes

    bET

    f

    cET

    dET

    1 0

    aET

    F = bca + bcd+ bd

    = aF a + aF a= a(1) + a(0)= a + 0= a

    = cF c + cF c= c(a) + c(d)= ca + cd

    = bF b + bF b= b(ca + cd) + b(d)

    = bca+ bcd + bd

    = d

  • 8/10/2019 05-BDD

    10/12

    ECE 474a/575aSusan Lysecky

    28of 31

    BDD to Boolean Function Exercise 2

    Another Example

    a ET

    f

    bE

    T

    0 1

    cET

    F = abc + ab+ a

    = c

    = bF b + bF b= b(c) + b(1)= bc+ b

    = aF a + aF a= a(bc + b) + a(1)= abc + ab+ a

    ECE 474a/575aSusan Lysecky

    29of 31

    Reducing BDDs

    aET

    f

    bET

    bET

    cET

    1 0

    cET

    1 0

    cET

    0 1

    cET

    0 1

    isomorphic subgraphs

    aET

    f

    bET

    bET

    cET

    1 0

    cET

    1 0

    cET

    0 1

    aET

    f

    bET

    cET

    1 0

    cET

    1 0

    cET

    0 1

    When building BDDs, result not always reduced (Example 1 - slide 19)We have isomorphic subgraphs, potential for reduction

    Transform a non-reduced BDD into a reduced BDD by iterativel y applyingIdentify isomorphic subgraphsRemove redundant nodes

    A ordered reduced BDD (ROBDD) is unique so we have a canonical form

    F b = F b(redundant node)

    ECE 474a/575aSusan Lysecky

    30of 31

    Reducing BDDsExample 2

    isomorphic subgraphs

    aT

    f

    bET

    cET

    1 0

    cET

    1 0

    E

    cET

    0 1

    aT

    f

    bET

    cET

    1 0

    E

    cET

    0 1

    aT

    f

    E

    cET

    0 1

    cET

    1 0

    Lets try to reduce and OBDDIterative apply

    Identify isomorphic subgraphsRemove redundant nodes

    Fb = F b(redundant node)

  • 8/10/2019 05-BDD

    11/12

    ECE 474a/575aSusan Lysecky

    31of 31

    Summary, and then some

    Binary Decision Diagrams (BDDs)Efficient mechanism to representation of Boolean functions in terms of memory andCPU

    Translating function BDD and BDD functionImportance of variable orderingMethod to reduced OBDDs, getting a ROBDD

    We said that BDDs can be efficiently stored and manipulated HOW? Refer to handwritten notes Supplem ental materials attached

    ECE 474a/575aSusan Lysecky

    32of 31

    ITE Operator Two argument operators expressed in terms of ITE

    FFF0011

    ITE(F, G, 0)FG F > G0010

    ITE(F, G, 0)FG AND(F, G)0001

    0000000

    GGG0101

    ITE(F, 0, G)FGF < G0100

    ITE(F, 1, G)F + GOR(F, G)0111

    ITE(F, G, G)F GXOR(F, G)0110

    ITE(F, G, G)(F G) XNOR(F, G)1001

    ITE(F, 0, G)(F + G) NOR(F, G)1000

    ITE(F, 1, G)F + G F G1011

    ITE(G, 0, 1)G NOT(G)1010

    ITE(F, G, 1)F+ GF G1101

    ITE(F, 0, 1)F NOT(F)1100

    ITE(F, G, 1)(FG) NAND(F, G)1110

    1111111

    Equivalent FormExpressionNameTable

    ECE 474a/575aSusan Lysecky

    33of 31

    ITE Algorithm

    ITE(F, G, H) = FG + FH

    = v(FG+ FH) v + v(FG+ FH) v

    = v(F vGv + F vHv) + v(F v Gv + F v Hv )

    = ITE( v, ITE(F v, G v, H v), ITE(F v , G v , H v ) )

    Terminal cases are as follows

    Most standard manipulation of BDDs can be done with ITE Algorithm recursive, based on formulation where v is the top variable of F, G, H

    ITE(1, F, G) = ITE(0, G, F) = ITE(F, 1, 0) = ITE(G, F, F) = F

  • 8/10/2019 05-BDD

    12/12

    ECE 474a/575aSusan Lysecky

    34of 31

    Pseduo-code of the ITE Algorithm

    ITE(F, G, H){

    (result , terminal_case ) = TERMINAL_CASE(F, G, H)

    if (terminal_case ) return ( result )

    (result , in_computed_table ) = COMPUTED_TABLE_HAS_ENTRY(F, G, H)

    if (in_computed_table ) return ( result )

    v = TOP_VARIABLE(F, G, H)

    T = ITE(F v, Gv, Hv)

    E = ITE(F v , Gv , H v )

    R = FIND_OR_ADD_UNIQUE_TABLE(v, T, E)

    INSERT_COMPUTED_TABLE((F, G, H), R)

    return (R)

    }

    // did we find a terminal case?

    // have we already calculated this value?

    // recursively calculate this value

    // see if subtreealready present

    // record the calculated value