Docsity

Reducing and Implementing Binary Decision Diagrams (BDDs) - Prof. Susan Lysecky, Study notes of Electrical and Electronics Engineering

Toggle sidebar
bg1
1
ECE 474a/575a
Susan Lysecky
1of 47
ECE 474A/57A
Computer-Aided Logic Design
Lecture 11
Binary Decision Diagrams (BDDs)
ECE 474a/575a
Susan Lysecky
2of 47
Boolean Logic Functions Representations
Function can be represented in different ways
Truth table, equation, K-map, circuit, etc…
Some representations not unique (not canonic al)
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) = a’b’ + a’b
11
01
00
0
1
Fb
a
ECE 474a/575a
Susan Lysecky
3of 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 ch oice 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)
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

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)