Download Reducing and Implementing Binary Decision Diagrams (BDDs) - Prof. Susan Lysecky and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!
ECE 474a/575a Susan Lysecky
1 of 47
ECE 474A/57A
Computer-Aided Logic Design
Lecture 11
Binary Decision Diagrams (BDDs)
ECE 474a/575a Susan Lysecky
2 of 47
Boolean Logic Functions Representations
Function can be represented in different ways
Truth table, equation, K-map, circuit, etc…
Some 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
The function F
Truth table
Equation 2: F(a,b) = a’
Equation 1: F(a,b) = a’b’ + a’b
F b a
ECE 474a/575a Susan Lysecky
3 of 47
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
4 of 47
Mux Representation of Boolean Functions
MUX circuit to implement logic
function S
S(x1, x2, x3)
x
x
x
MUX
MUX
MUX
MUX
x1 x2x3 S 0 0 0 1 0 01 0 0 10 1 0 11 1 1 00 1 1 01 1 1 10 0 1 1 1 0
S(0, 0, 0) = 1
X3 (0)
x2 (0)
X1 (0)
01 MUX
10
01 MUX
1
01 MUX
10
01 MUX
S(0, 0, 1) = 0
X3 (1)
x2 (0)
X1 (0)
01 MUX
10
01 MUX
1
01 MUX
10
01 MUX
S(0, 1, 0) = 1
X3 (0)
x2 (1)
X1 (0)
01 MUX
10
01 MUX
1
01 MUX
10
01 MUX
S(1, 1, 1) = 0
X3 (1)
x2 (1)
X1 (1)
01 MUX
10
01 MUX
1
01 MUX
10
01 MUX
ECE 474a/575a Susan Lysecky
5 of 47
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 1 0 01 0 0 10 1 0 11 1 1 00 1 1 01 1 1 10 0 1 1 1 0
S(x1, x2, x3)
x
x
x
MUX
MUX
MUX
MUX
Same circuit, just
flipped
Corresponding BDD
x
x2 x
x
S(x1, x2, x3)
S(x1, x2, x3)
x
x
x
MUX
MUX
MUX
MUX
ECE 474a/575a Susan Lysecky
6 of 47
Binary Decision Diagram (BDD)
Example 1
How does it work?
Line with bubble represent value = 0
Lines without bubble represent value = 1
x1 x2 x3 S 0 0 0 1 0 01 0 0 10 1 0 11 1 1 00 1 1 01 1 1 10 0 1 1 1 0
x
x2 x
x
S(x1, x2, x3)
x
x2 x
x
S(0, 0, 0)
x
x2 x
x
S(1, 1, 1)
x
x2 x
x
S(0, 1, 0)
x
x2 x
x
S(0, 0, 1)
ECE 474a/575a Susan Lysecky
10 of 47
Ordered Binary Decision Diagram (OBDD)
Different Ordering Lead to Different Complexity – Example
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
b
c
d T
E
T
E
T
E
f
a
T
E
Order : b ≤ c ≤ a ≤ d
a
b b
d T
E
T (^) E T
E
T
E
f
c c
T T
E E
Order : a ≤ b ≤ c ≤ d
a
d d
c T
E
T T E
E
T
E
f
b b
T T
E E
Order : a ≤ d ≤ b ≤ c
c T
E
ECE 474a/575a Susan Lysecky
11 of 47
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
a
b
e
d T
E
T T E E
T E
f
f
c
T
T
E
E
a
e
c
f
b b
c
e e e
b b
d d
f
ECE 474a/575a Susan Lysecky
12 of 47
BDDs for Basic Logic Functions
a E T
f
NOT
a F 0 1 1 0
AND
a b F 0 0 0 0 1 0 1 0 0 1 1 1
a
b
E
T
T
E
f
OR
a b F 0 0 0 0 1 1 1 0 1 1 1 1
a
b
E
E T
T
f
XOR
a b F 0 0 0 0 1 1 1 0 1 1 1 0
a
b b
E
E E
T
T
T
f
NAND
a b F 0 0 1 0 1 1 1 0 1 1 1 0
f
a
b
E
T
T
E
ECE 474a/575a Susan Lysecky
13 of 47
Formal Definition of BDDs
A BDD is a direct acyclic graph (DAG) representing a
multiple-output switching function F
Nodes are partitioned into three subsets
Function node
Represents the function symbol (f)
Indegree = 0
Outdegree = 1
Internal node
Represents variable in function (a, b, c, d)
Indegree ≥ 1
Outdegree = 2(actually we can optimize ≤ 2)
Terminal node
Represents a value (1 or 0)
Indegree ≥ 1
Outdegree = 0
b
c
d T
E
T
E
T
E
f
a T
E
Function node
Internal nodes
Terminal nodes
ECE 474a/575a Susan Lysecky
14 of 47
Formal Definition of BDDs
A BDD definition (cont’)
Three types of edges
Incoming edge
From the function node and defines function
T edge
From an internal node and represents when
the corresponding variable is 1
E edge
From an internal node and represents when
the corresponding variable is 0
b
c
d T
E
T
E
T
E
f
a
T
E
Incoming edge
E edge
T edge
ECE 474a/575a Susan Lysecky
15 of 47
Formal Definition of BDDs
A BDD definition (cont’)
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 vf T +
v’f E, when f T is the function of the T edge and
f E is the function of the E edge
The function of the function node is the
function of it’s outgoing edge
b
c
d T
E
T
E
T
E
f
a T
E
Function of the function node is the function of it’s outgoing edge
Function of this T edge is a
Function of this terminal node is 1
Function of this terminal node is 0
Function of this E edge is a’
ECE 474a/575a Susan Lysecky
19 of 47
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
Compute cofactors of f
a
and f
a’
with respect to b
(second variable in ordering)
f a = bc + b’c
f
a’
= bc’ + b’c’
(fa ) b’ = fab’ = c
a T E
f
partial expansion with respect to b
(fa ) b = f ab = c
b T E
f
ab
f
ab’
(f
a’
b’
= f
a’b’
= c’
(f
a’
b
= f
a’b
= c’
b T E
f
a’b
f
a’b’
a T E
f
a
f
a’
ECE 474a/575a Susan Lysecky
20 of 47
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
Compute cofactors of f ab , fab’, f a’b, fa’b’ with respect
to c (third variable in ordering)
f ab’ = c
f ab = c
f a’b’ = c’
f a’b = c’
expansion with respect to c, final BDD
f
abc’
f abc = 1
a T E
f
b T E
b T E
c T E
1 0
f ab’c = 1
f
ab’c’
c T E
f a’bc = 0 1 0
f
a’bc’
c T E
0 1
f a’b’c = 0
f a’b’c’ = 1
c T E
0 1
a T E
b T E
f
ab
f
ab’
b T E
f
a’b
f
a’b’
ECE 474a/575a Susan Lysecky
21 of 47
Building BDDs - Exercise 1
f = abc + ab’c + a’bc’ + a’b’c’
a T E
f
b T E
b T E
c T E
c T E
c T E
c T E
1 0 1 0 0 1 0 1
Does it work?
b f
c
a
ECE 474a/575a Susan Lysecky
22 of 47
Building BDDs - Exercise 2
Build a BDD for f = abc + b’d + c’d
Use the variable ordering b ≤ c ≤ d ≤ a
f
Compute cofactors of f with respect
to b (first variable in ordering)
f = abc + b’d + c’d
f b’ = d + c’d
b T E
f
f
b
f
b’
partial expansion with respect to b
f
b
= ac + c’d
ECE 474a/575a Susan Lysecky
23 of 47
Building BDDs - Exercise 2
Build a BDD for f = abc + b’d + c’d
Use 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 + c’d
f b’ = d + c’d
b T E
f
f b f b’
b T E
f
f
bc
c T E
f
bc’
= f
b’c
= f
b’c’
equivalent cofactors, we can create a single node (reduced)
f b’c = d
f b’c’ = d
f b’c
c T E
f bc f b’c’
c T E
f bc’
b T E
f
f
bc
= a
f
bc’
= d
partial expansion with respect to c
ECE 474a/575a Susan Lysecky
24 of 47
Building BDDs - Exercise 2
Build a BDD for f = abc + b’d + c’d
Use the variable ordering b ≤ c ≤ d ≤ a
Compute cofactors of f bc’, f b’c , and fb’c’ with
respect to d (third variable in ordering)
f
bc’
= f
bc’
= f
b’c’
= d
b T E
f
f bc
c T E
f bc’ = f b’c = f b’c’
f bc’d = f bc’d = fb’c’d = 1
f bc’d’ = fbc’d’ = f b’c’d’ = 0
b T E
f
f bc
c T E
d T E
partial expansion with respect to d
ECE 474a/575a Susan Lysecky
28 of 47
BDD to Boolean Function – Exercise 2
Another Example
a T E
f
b E T
c T E
F = abc’ + ab’ + a’
= c’
= bF b + b’F b’
= b(c’) + b’(1)
= bc’ + b’
= aF
a
+ a’F
a’
= a(bc’ + b’) + a’(1)
= abc’ + ab’ + a’
ECE 474a/575a Susan Lysecky
29 of 47
Reducing BDDs
a T E
f
b T E
b T E
c T E
1 0
c T E
1 0
c T E
0 1
c T E
0 1
isomorphic subgraphs
a T E
f
b T E
b T E
c T E
1 0
c T E
1 0
c T E
0 1
a T E
f
b T E
c T E
1 0
c T E
1 0
c T E
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 iteratively applying
Identify isomorphic subgraphs
Remove redundant nodes
A ordered reduced BDD (ROBDD) is unique so we have a canonical form
F b = Fb’
(redundant node)
ECE 474a/575a Susan Lysecky
30 of 47
Reducing BDDs
Example 2
isomorphic subgraphs
a T
f
b T E
c T E
1 0
c T E
1 0
E
c T E
0 1
a T
f
b T E
c T E
1 0
E
c T E
0 1
a T
f
E
c T E
0 1
c T E
1 0
Let’s try to reduce and OBDD
Iterative apply
Identify isomorphic subgraphs
Remove redundant nodes
F b = Fb’
(redundant node)
ECE 474a/575a Susan Lysecky
31 of 47
Representing BDDs
We said that BDDs can be efficiently implemented
Efficient in terms of memory and CPU
Many BDD Packages Available
ABCD, BuDDy, CMU BDD, CrocoPat, CUDD, JavaBDD, Berkeley CAL package, TUD
BDD, JDD, JBDD, BDD-PROJECT, BFunc, DDD
We’ll look at high-level design considerations only
ECE 474a/575a Susan Lysecky
32 of 47
Shared BDDs
Each node has a function associated with it
Possible for multiple functions to represent same subexpression
Multiple roots sharing same DAG
Efficient use of memory
f
b
T E
c
T E
f1 = b + c
f2 = a + b + c
a T E
f
b
T E
c
T E
a T E
f
b
T E
c
T E
f
f1 = b + c
f2 = a + b + c
ECE 474a/575a Susan Lysecky
33 of 47
Unique Table
Want reduced BDDs
Option 1 - Build non-reduced BDD then reduce them in a second pass
Option 2 – As we build BDDs guarantee at any time there an no isomorphic
subgraphs or redundant nodes in a multi-rooted BDD
Unique Table
Check for existence of node representing desired function before new nodes
are added
Create dictionary of functions represented in DAC (directed acyclic graph)
Implemented as hash table
ECE 474a/575a Susan Lysecky
37 of 47
Directed Address Table
Works well when universe of keys are relatively small
Depending on actual keys, we may waste space in memory (lots of empty cells)
5 Simpson, L. 92%
99008 Rodriguez, B. 97%
MAX_SIZE/
13 Fry, P. 55%
1 Smith, J. 85%
U
(universe of keys)
K
(Actual keys)
T
KEY SATILLITE DATA
ECE 474a/575a Susan Lysecky
38 of 47
Hash Table
Hash Table
Instead of storing key k into slot k, store at h(k) where h is the hashing function
Design hashing function to reduce number of array indices that must be handled
What happens when 2 keys map to same slot? Collisions!
Avoid collisions by designing hash functions to make sure keys map to different locations, if
|U| > size of table difficult if not impossible to do this
Chaining – okay to map keys to same slot, put all elements into a linked list
U
(universe of keys)
K
(Actual keys)
k
k
k
k
k
k
k
k
/
T
h(k8) = h(k6)
h(k3)
h(k5) = h(k2) = h(k7)
h(k1) = h(k4) k
k
k
k4 /
k2 k7 /
k
k
ECE 474a/575a Susan Lysecky
39 of 47
Hashing Function
A hash function maps a key to an index within in a range
Desirable properties
Simple and quick to calculate
Even distribution, avoid collision as much as possible
/
/
/
/
/
/
T
/
/
/
/
/
/
T
ECE 474a/575a Susan Lysecky
40 of 47
Hashing Function
Division Method
h(k) = k mod m // m = size of T
key mapped by finding remainder
Multiplication Method
h(k) = m(k A mod 1)
key multiplied by constant value of A (0<A<1)
fractional part of kA is multiplied by m
floor taken to remove fraction part
Universal Hashing Method
Previous methods based on key
Given bad set of keys, functions may still not
provide uniform hashing
Select hashing function from class of hash
functions randomly at run time
Many other hashing methods exist
m = 12; k = 100
h(100) = 100 mod 12
h(100) = 4
m = 1000; k = 123456; A=0.
h(123456) = 1000( (123456)(0.61803) mod 1))
h(123456) = 1000( 76299.51168 mod 1))
h(123456) = 1000( 0.51168 mod 1))
h(123456) = 511.
h(123456) = 511
ECE 474a/575a Susan Lysecky
41 of 47
Unique Table Represented as Hash Table
BDD Package needed a Unique Table
Use the hash table
Each node in BDD is the triple (F, G, H)
If F then G else H
Just like Shannon Expansion, F = xFx + x’Fx’
Check for existence of node representing desired function before new nodes are added -
look in hash table for matching index
UT
index then else pointer
index then else pointer
index then else pointer
index then else pointer
Unique Table and BDD DAC (collision chain hash table)
ECE 474a/575a Susan Lysecky
42 of 47
Strong Canonicity
Using the unique table, two equivalent functions share the same subgraph
Checking for equivalence is as simple as checking that pointers associated
with two functions are identical
Benefit is constant-time equivalence check
ECE 474a/575a Susan Lysecky
46 of 47
Memory Management
Garbage Collection
Typical application builds and disposes of many BDDs
Must efficiently utilize memory
Instead of immediately freeing nodes no longer utilized, periodically traverse
data structure to recover unused memory
Dynamic Re-ordering
BDDs tend to grow as they are manipulated
May run out of memory
Variable ordering matters!
Don’t know best ordering ahead of time so try dynamic re-ordering of BDD variables
to see if we can reduce size
ECE 474a/575a Susan Lysecky
47 of 47
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
Hash tables
What about algorithms to manipulating BDDs?
See handwritten notes (Lecture 11B)