Uploaded by Md. Rezaul Islam

05-BDD

advertisement
ECE 474A/57A
Computer-Aided Logic Design
Lecture 11
Binary Decision Diagrams (BDDs)
ECE 474a/575a
Susan Lysecky
1 of 31
Boolean Logic Functions Representations
ƒ
Function can be represented in different ways
ƒ Truth table, equation, K-map, circuit, etc…
ƒ Some representations not unique (not canonical)
F
b
a
Equation 1: F(a,b) = a’b’ + a’b
a
b
F
0
0
1
0
1
1
1
0
0
1
1
0
0
1
0
1
1
1
0
0
a
Equation 2: F(a,b) = a’
b
F
Circuit 1
a
Truth table
The function F
F
Circuit 2
ECE 474a/575a
Susan Lysecky
2 of 31
Why BDDs
An Efficient Representation
ƒ
Synthesis, optimization, verification, and testing algorithms/tools manipulate
large Boolean functions
ƒ Important to have efficient way to represent these functions
ƒ Binary Decision Diagrams (BDDs) have emerged as a popular choice for representing
these functions
ƒ
BDDs
ƒ Graph representation similar to a binary tree (i.e. decision trees from previous
lectures)
ƒ Able to efficiently represent large functions
ƒ Some representations are canonical (unique)
ECE 474a/575a
Susan Lysecky
3 of 31
1
Mux Representation of Boolean Functions
MUX circuit to implement logic
function S
ƒ
1
0
x1
x2
x3
S
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
1
0
1
1
1
1
0
0
1
0
X3 (1)
0
1
0 1
x3
MUX
1
1
0 1
x2
0
0 1
MUX
MUX
0 1
x1
MUX
S(x1, x2, x3)
1
0
1
0 1
X3 (0)
0
x2 (0)
1
1
0
1
0
1
MUX
1
X3 (0)
MUX
0
x2 (1)
MUX
0
X1 (0)
0
0 1
X3 (1)
MUX
1
1
0
1
0
1
MUX
0
1
MUX
0
x2 (1)
MUX
0
X1 (1)
MUX
1
1
1
0
1
0
1
MUX
1
1
1
0 1
MUX
MUX
0
0
X1 (0)
MUX
S(1, 1, 1) = 0
MUX
x2 (0)
MUX
0 1
X1 (0)
MUX
S(0, 0, 0) = 1
1
0
0
1
MUX
S(0, 1, 0) = 1
S(0, 0, 1) = 0
ECE 474a/575a
Susan Lysecky
4 of 31
Mux Representation of Boolean Functions
Relation to BDDs
Corresponding BDD to implement function S
ƒ
ƒ One-to-one correspondence to the MUX gates in
the flipped circuit
x1
x2
x3
S
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
1
0
1
1
1
1
0
0
S(x1, x2, x3)
1
S(x1, x2, x3)
0
0 1
x3
1
x2
1
x1
MUX
x1
MUX
0 1
0
0 1
0 1
MUX
MUX
MUX
x2
x2
x2
1
0
MUX
0 1
0 1
x3
0 1
x1
1
MUX
x3
MUX
1
0
0 1
1
S(x1, x2, x3)
Same circuit, just
flipped
0
ECE 474a/575a
Susan Lysecky
Corresponding BDD
5 of 31
Binary Decision Diagram (BDD)
Example 1
How does it work?
ƒ
S(x1, x2, x3)
ƒ Line with bubble represent value = 0
ƒ Lines without bubble represent value = 1
x1
x2
x2
1
0
x3
x2
S(0, 0, 0)
S(1, 1, 1)
S(0, 1, 0)
x1
x1
x1
x2
x3
x2
x2
x3
1
0
x2
0
ECE 474a/575a
Susan Lysecky
x2
x3
S
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
1
0
1
1
1
1
0
0
S(0, 0, 1)
x1
x2
x3
1
x1
x2
x2
x3
1
0
1
0
6 of 31
2
Binary Decision Diagram (BDD)
Edge Notations
ƒ
Several ways to represent value = 1 and value = 0
Bubble vs. Non-bubble line
Dashed vs. Solid line
T (then) vs. E (else) labels
ƒ
ƒ
ƒ
ƒ
We will adopt T vs. E labels – consistent with most of the book (Hatchel) examples
S(x1, x2, x3)
S(x1, x2, x3)
x1
x1
S(x1, x2, x3)
x1
E
T
x2
x2
x2
x3
x2
x2
T
x3
x2
T
E
E
x3 E
T
1
0
1
0
1
0
ECE 474a/575a
Susan Lysecky
7 of 31
Binary Decision Diagram (BDD)
Example 2
ƒ
Let’s consider another function
f(a,b,c,d) = abc + b’d + c’d
f
f
a
c
T
E
b
T
b
E
T
E
E
E
T
f
a
T
d
b
T
c
c
T
T
1
b
E
E
d
T
0
T
E
E
E
T
a
T
E
1
c
c
T
T
E
b
T
b
E
T
E
E
E
T
0
1
c
T
d
E
E
0
What is the value of f(1,1,0,1)?
What is the value of f(1,0,1,0)?
Notice that if a=1 and b=0, the
function does not depend on a
value for c.
ECE 474a/575a
Susan Lysecky
8 of 31
Ordered Binary Decision Diagram (OBDD)
What is a OBDD?
ƒ Ordered binary decision diagrams ensure the variables appear in
the same order along all paths from the root to the leaves
f
f
a
a
E
T
T
c
E
c
b
T
T
E
E
b
c
T
E
c
T
E
E
1
1
Ordering : a ≤ c ≤ b
b
T
T
E
0
T
E
0
Not ordered
ECE 474a/575a
Susan Lysecky
9 of 31
3
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 function
ƒ Third ordering (b ≤ c ≤ a ≤ d) optimal because there is exactly one node for
each variable
f
f
a
c
E
b
E
E
T
d
E
b
T
c
E
E
a
E
E
T
d
T
c
E
T
1
T
T
E
c
T
b
E
T
E
T
E
E
c
E
d
T
d
T
E
T
b
T
b
T
f
a
T
0
1
1
Order : a ≤ b ≤ c ≤ d
E
T
0
0
Order : a ≤ d ≤ b ≤ c
Order : b ≤ c ≤ a ≤ d
ECE 474a/575a
Susan Lysecky
10 of 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
f
a
f
a
T
T
d
E
e
e
e
T
e
b
b
b
b
T
E
f
E
0
c
b
T
E
e
c
E
E
c
d
d
T
1
f
0
Order : a ≤ b ≤ c ≤ d ≤ e ≤ f
1
Order : a ≤ c ≤ e ≤ b ≤ d ≤ f
ECE 474a/575a
Susan Lysecky
11 of 31
BDDs for Basic Logic Functions
AND
NOT
a
F
0
1
1
0
NAND
F
a
b
F
a
b
F
a
b
F
0
1
0
1
0
0
0
1
0
0
1
1
0
1
0
1
0
1
1
1
0
0
1
1
0
1
0
1
0
1
1
0
0
0
1
1
0
1
0
1
1
1
1
0
f
1
XOR
b
f
a
E
OR
a
0
0
1
1
f
a
T
T
0
b E
1
T
E
T
0
f
a
T
T
1
f
a
E
b
b T
E
0
ECE 474a/575a
Susan Lysecky
a
E
T
E
b
E
T
E
b
T
E
1
0
1
0
12 of 31
4
Formal Definition of BDDs
ƒ
A BDD is a direct acyclic graph (DAG) representing a
multiple-output switching function F
ƒ
b
T
ƒ Function node
ƒ
ƒ
ƒ
Represents the function symbol (f)
Indegree = 0
Outdegree = 1
Function node
f
Nodes are partitioned into three subsets
Internal
nodes
c
T
a
E
E
E
T
d
T
E
ƒ Internal node
ƒ
ƒ
ƒ
Represents variable in function (a, b, c, d)
Indegree ≥ 1
Outdegree = 2
1
0
Terminal nodes
ƒ Terminal node
ƒ
ƒ
ƒ
Represents a value (1 or 0)
Indegree ≥ 1
Outdegree = 0
ECE 474a/575a
Susan Lysecky
13 of 31
Formal Definition of BDDs
ƒ
A BDD definition (cont’)
ƒ
f
Three types of edges
ƒ
Incoming edge
Incoming edge
b
ƒ From the function node and defines function
ƒ
E edge
ƒ From an internal node and represents when
the corresponding variable is 0
E
T edge
T edge
ƒ From an internal node and represents when
the corresponding variable is 1
ƒ
T
c
T
E
E edge
a
E
T
d
T
1
E
0
ECE 474a/575a
Susan Lysecky
14 of 31
Formal Definition of BDDs
ƒ
A BDD definition (cont’)
ƒ
f
The function f represented by a BDD is
defined as follows
ƒ
ƒ
ƒ
ƒ
ƒ
The function of the terminal node is a
constant value (1 or 0)
The function of a T edge is the function of
the head node
The function of a E edge is the complement
of the function of the node
The function of a node v is given by vfT +
v’fE, when fT is the function of the T edge and
fE is the function of the E edge
The function of the function node is the
function of it’s outgoing edge
Function of the function
node is the function of
it’s outgoing edge
b
T
c
T
a
E
Function of this
E edge is a’
E
E
T
d
T
E
Function of this
T edge is a
1
0
Function of this terminal
node is 0
Function of this terminal node is 1
ECE 474a/575a
Susan Lysecky
15 of 31
5
BDD Canonical Form
ƒ
f
BDDs are canonical (unique) for a representation of
F given a variable ordering if
ƒ
ƒ
ƒ
b
T
All internal nodes are descendants of some node
There are no isomorphic subgraphs
For every node fT ≠ fE
E
1
c
T
T
d
1
E
0
E
T
d
1
E
0
Isomorphic subgraphs
Isomorphic
Two graphs are isomorphic if there is a one-to-one correspondence between their vertices and there is an edge between
two vertices of one graph if and only if there is an edge between the two corresponding vertices in the other graph
English – same subgraph - all vertices the same, all edges between vertices the same
ECE 474a/575a
Susan Lysecky
16 of 31
Building BDDs For a Function F
ƒ
ƒ
How do I build a BDD given a function F ?
Recursive use of Shannon’s Expansion Theorem
ƒ
ƒ
F = aFa + a’Fa’
We can keep applying expansion theorem,
eventually we reach the unique canonical form ,
which uses only minterms
F = a’b + abc’ + a’b’c
F = a(bc’) + a’(b+b’c)
Fa’ = (b+b’c)
Fa = (bc’)
Fa also called the cofactor of F w.r.t.
(with respect to) a
F = a’b + abc’ + a’b’c
F = a’b + abc’ + a’b’c
F = bFb + b’Fb’
F = cFc + c’Fc’
F = b(a’+ ac’) + b’(a’c)
F = c(a’b + a’b’) + c’(a’b + ab)
F expanded w.r.t to b
F expanded w.r.t to c
ECE 474a/575a
Susan Lysecky
17 of 31
Building BDDs - Exercise 1
ƒ
ƒ
Build a BDD for f = abc + ab’c + a’bc’ + a’b’c’
Use the variable ordering a ≤ b ≤ c
f
partial expansion
with respect to a
Compute cofactors of f with respect
to a (first variable in ordering)
f
f = abc + ab’c + a’bc’ + a’b’c’
a
fa = bc + b’c
T
fa
fa’ = bc’ + b’c’
ECE 474a/575a
Susan Lysecky
E
fa’
18 of 31
6
Building BDDs - Exercise 1
ƒ
ƒ
Build a BDD for f = abc + ab’c + a’bc’ + a’b’c’
Use the variable ordering a ≤ b ≤ c
f
a
T
E
fa
fa’
partial expansion
with respect to b
Compute cofactors of fa and fa’ with respect to b
(second variable in ordering)
f
fa = bc + b’c
a
(fa)b = fab = c
T
E
b
(fa)b’ = fab’ = c
b
T
fab
fa’ = bc’ + b’c’
T
E
fab’
E
fa’b
fa’b’
(fa’)b = fa’b = c’
(fa’)b’ = fa’b’ = c’
ECE 474a/575a
Susan Lysecky
19 of 31
Building BDDs - Exercise 1
ƒ
ƒ
Build a BDD for f = abc + ab’c + a’bc’ + a’b’c’
Use the variable ordering a ≤ b ≤ c
f
a
T
E
b
T
Compute cofactors of fab, fab’, fa’b, fa’b’ with respect
to c (third variable in ordering)
b
T
E
fab
fab’
E
fa’b
fab = c
fa’b’
f
fabc = 1
a
fabc’ = 0
T
fab’ = c
E
b
fab’c = 1
fab’c’ = 0
T
E
c
c
fa’b = c’
fa’bc = 0
expansion with
respect to c, final
BDD
b
T
T
E
T
1
0
1
E
c
c
T
E
0
T
E
0
1
E
0
1
fa’bc’ = 1
fa’b’ = c’
fa’b’c = 0
fa’b’c’ = 1
ECE 474a/575a
Susan Lysecky
20 of 31
Building BDDs - Exercise 1
ƒ
f = abc + ab’c + a’bc’ + a’b’c’
a
0
0
0
0
1
1
1
1
b
0
0
1
1
0
0
1
1
c
0
1
0
1
0
1
0
1
f
1
0
1
0
0
1
0
1
f
a
T
E
b
T
b
T
E
c
c
T
E
T
1
0
1
E
c
c
E
0
T
0
E
1
T
0
E
1
Does it work?
ECE 474a/575a
Susan Lysecky
21 of 31
7
Building BDDs - Exercise 2
ƒ
ƒ
Build a BDD for f = abc + b’d + c’d
Use the variable ordering b ≤ c ≤ d ≤ a
f
partial expansion
with respect to b
Compute cofactors of f with respect
to b (first variable in ordering)
f
f = abc + b’d + c’d
b
T
fb = ac + c’d
E
fb
fb’ = d + c’d
fb’
ECE 474a/575a
Susan Lysecky
22 of 31
Building BDDs - Exercise 2
ƒ
ƒ
Build a BDD for f = abc + b’d + c’d
Use the variable ordering b ≤ c ≤ d ≤ a
f
b
T
E
fb
f
b
T
fb = ac + c’d
E
c
T
fbc = a
c
E
fbc
fbc’ = d
partial expansion
with respect to c
fb’
Compute cofactors of fb and fb’ with respect to c
(second variable in ordering)
T
fbc’
E
fb’c
fb’c’
equivalent
cofactors, we can
create a single
node (reduced)
f
fb’ = d + c’d
T
fb’c = d
c
T
fb’c’ = d
ECE 474a/575a
Susan Lysecky
b
E
E
fbc
fbc’ = fb’c = fb’c’
23 of 31
Building BDDs - Exercise 2
ƒ
ƒ
Build a BDD for f = abc + b’d + c’d
Use the variable ordering b ≤ c ≤ d ≤ a
f
T
c
T
Compute cofactors of fbc’, fb’c, and fb’c’ with
respect to d (third variable in ordering)
b
E
partial expansion
with respect to d
E
fbc
fbc’ = fb’c = fb’c’
f
fbc’ = fbc’ = fb’c’ = d
fbc’d = fbc’d = fb’c’d = 1
T
c
fbc’d’ = fbc’d’ = fb’c’d’ = 0
T
E
E
T
fbc
1
ECE 474a/575a
Susan Lysecky
b
d
E
0
24 of 31
8
Building BDDs - Exercise 2
ƒ
ƒ
Build a BDD for f = abc + b’d + c’d
Use the variable ordering b ≤ c ≤ d ≤ a
f
T
c
T
Compute cofactors of fbc with respect to a (fourth
variable in ordering)
b
E
E
T
fbc
fbc = a
1
d
E
0
expansion with
respect to a, final
BDD
f
fbca = 1
fbca’ = 0
T
c
T
a
T
b
E
E
T
E
1
d
E
0
ECE 474a/575a
Susan Lysecky
25 of 31
Building BDDs - Exercise 2
ƒ
Build a BDD for f = abc + b’d + c’d
a
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
b
0
0
0
0
1
1
1
1
0
0
0
0
1
1
1
1
c
0
0
1
1
0
0
1
1
0
0
1
1
0
0
1
1
d
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
f
0
1
0
1
0
1
0
0
0
1
0
1
0
1
1
1
f
T
c
T
a
T
b
E
E
d
T
E
1
E
0
Does it work?
ECE 474a/575a
Susan Lysecky
26 of 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
F = bca + bc’d + b’d
= cFc + c’Fc’
= c(a) + c’(d)
= ca + c’d
f
T
c
a
T
b
E
E
T
= aFa + a’Fa’
= a(1) + a(0)
=a+0
=a
= bFb + b’Fb’
= b(ca + c’d) + b’(d)
= bca + bc’d + b’d
T
E
d
E
=d
1
0
ECE 474a/575a
Susan Lysecky
27 of 31
9
BDD to Boolean Function – Exercise 2
Another Example
ƒ
F = abc’ + ab’ + a’
f
= bFb + b’Fb’
= b(c’) + b’(1)
= bc’ + b’
a
T
b
E
T
c
T
E
= aFa + a’Fa’
= a(bc’ + b’) + a’(1)
= abc’ + ab’ + a’
E
0
1
= c’
ECE 474a/575a
Susan Lysecky
28 of 31
Reducing BDDs
ƒ
When building BDDs, result not always reduced (Example 1 - slide 19)
ƒ
Transform a non-reduced BDD into a reduced BDD by iteratively applying
ƒ
ƒ
ƒ
We have isomorphic subgraphs, potential for reduction
Identify isomorphic subgraphs
Remove redundant nodes
A ordered reduced BDD (ROBDD) is unique so we have a canonical form
ƒ
f
f
a
T
b
T
b
T
E
c
c
T
E
T
1
0
1
0
0
T
E
c
1
0
b
E
1
T
E
c
c
T
E
a
T
E
b
c
T
E
f
a
T
E
T
E
T
1
0
1
T
E
c
T
E
0
E
c
c
E
0
E
b
1
T
E
T
1
0
1
c
T
E
0
E
0
1
Fb = Fb’
(redundant node)
isomorphic subgraphs
ECE 474a/575a
Susan Lysecky
29 of 31
Reducing BDDs
Example 2
Let’s try to reduce and OBDD
ƒ
ƒ Iterative apply
ƒ Identify isomorphic subgraphs
ƒ Remove redundant nodes
f
f
a
T
b
T
f
a
T
E
a
T
E
E
b
T
E
c
c
T
E
T
1
0
1
c
E
0
isomorphic subgraphs
T
0
E
c
E
1
T
1
c
c
E
0
T
0
E
1
T
1
c
E
0
T
0
E
1
Fb = Fb’
(redundant node)
ECE 474a/575a
Susan Lysecky
30 of 31
10
Summary, and then some…
ƒ
Binary Decision Diagrams (BDDs)
ƒ Efficient mechanism to representation of Boolean functions in terms of memory and
CPU
ƒ Translating function→BDD and BDD→function
ƒ Importance of variable ordering
ƒ Method to reduced OBDDs, getting a ROBDD
ƒ
We said that BDDs can be efficiently stored and manipulated – HOW?
ƒ Refer to handwritten notes
ƒ Supplemental materials attached
ECE 474a/575a
Susan Lysecky
31 of 31
ITE Operator
Two argument operators expressed in terms of ITE
Table
Name
Expression
Equivalent Form
0000
0
0
0
0001
AND(F, G)
FG
ITE(F, G, 0)
0010
F>G
FG’
ITE(F, G’, 0)
0011
F
F
F
0100
F<G
F’G
ITE(F, 0, G)
0101
G
G
G
0110
XOR(F, G)
F⊕G
ITE(F, G’, G)
0111
OR(F, G)
F+G
ITE(F, 1, G)
1000
NOR(F, G)
(F + G)’
ITE(F, 0, G’)
1001
XNOR(F, G)
(F ⊕ G)’
ITE(F, G, G’)
1010
NOT(G)
G’
ITE(G, 0, 1)
1011
F≥G
F + G’
ITE(F, 1, G’)
1100
NOT(F)
F’
ITE(F, 0, 1)
1101
F≤G
F’ + G
ITE(F, G, 1)
1110
NAND(F, G)
(FG)’
ITE(F, G’, 1)
1111
1
1
1
ECE 474a/575a
Susan Lysecky
32 of 31
ITE Algorithm
ƒ
ƒ
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(F, G, H) = FG + F’H
= v(FG + F’H)v + v’(FG + F’H)v’
= v(FvGv + F’vHv) + v’(Fv’Gv’ + F’v’Hv’)
= ITE( v, ITE(Fv, Gv, Hv), ITE(Fv’, Gv’, Hv’) )
ƒ
Terminal cases are as follows
ITE(1, F, G) = ITE(0, G, F) = ITE(F, 1, 0) = ITE(G, F, F) = F
ECE 474a/575a
Susan Lysecky
33 of 31
11
Pseduo-code of the ITE Algorithm
ITE(F, G, H){
(result, terminal_case) = TERMINAL_CASE(F, G, H)
// did we find a terminal case?
if (terminal_case) return (result)
(result, in_computed_table) = COMPUTED_TABLE_HAS_ENTRY(F, G, H)
// have we already calculated this value?
if (in_computed_table) return (result)
v = TOP_VARIABLE(F, G, H)
// recursively calculate this value
T = ITE(Fv, Gv, Hv)
E = ITE(Fv’, Gv’, Hv’)
R = FIND_OR_ADD_UNIQUE_TABLE(v, T, E)
// see if subtree already present
INSERT_COMPUTED_TABLE((F, G, H), R)
// record the calculated value
return (R)
}
ECE 474a/575a
Susan Lysecky
34 of 31
12
Download