Sei sulla pagina 1di 39

Binary Decision Diagrams

Theory, Implementation, Usage

Barukh Ziv Intel

B.Z.

Boolean Functions And Their Representations

B.Z.

Boolean Functions
Definition
A map that associates a Boolean value to each possible assignment of input variables

Widely Used in CAD Applications


Hardware synthesis Test generation Validation

Uniform Description in Model Checking

Describing the model (Transition Relation) Representing the Set of States

B.Z.

Representing Boolean Functions


Truth Table
Functions value for each assignment of inputs Formulas using basic Boolean operations Network of logical gates Each path in a graph represents one assignment of input variables

Boolean Expressions Boolean Circuits

Binary Decision Trees

B.Z.

Representing Boolean Functions: Examples

Truth Table
X 0 0 0 0 1 1 1 1 Y 0 0 1 1 0 0 1 1 Z 0 1 0 1 0 1 0 1 F 0 0 1 0 1 1 0 0

Binary Decision Tree


X Y Z 0 0 Z 1 0 1 Z 1 0 Y Z 0

Boolean Circuit
X Y Z
B.Z.

Boolean Expression F = XYZ |X Y

Good Representation: Requirements


Compactness
Grow not too fast with number of inputs

Efficient Logic Manipulation


Computing Boolean functions Performing equivalence check Finding Out the satisfying assignment

What are the values of input variables that evaluate the Boolean function to TRUE

B.Z.

Good Representation: Is It Possible?


Theoretical Fact
No good representation exists for all Boolean functions

The concern is with practically interesting cases


Human designed models are regular

B.Z.

Binary Decision Diagrams

B.Z.

Toward BDD: Key Ideas


Use Binary Decision Diagrams
Two edges of a node of function F point to functions F(x=0) and F(x=1) Basis for recursive manipulation On each path in Decision Diagram the order of variables is the same A step to canonical form Efficient comparison

Fix the Order of Input Variables Share All Equal Functions

B.Z.

Towards BDD: Key Ideas


Represent Only Essential Variables A-Ha! Shannon Expansion
Dont put variables on paths where they cannot change the value of a function Theoretical fact: F = xF(x=0) | xF(x = 1) If F(x=0) and F(x=1) are equal, value of F does not depend on variable x Delete a node whose both edges point to the same function

Reduction Rule

B.Z.

Reduced Ordered BDD


Binary Decision Diagram F
X
0-edge
F(X=0)

Fixed Variables Order


X
For every node: X < Y, X < Z

1-edge

F(X=1)

Sharing Equivalent Functions


F=G X Y
B.Z.

Reduction Rule
X Y
F F

X Z Y

X Z

BDD Features
Canonicity
If two functions are equal than their BDD graphs are isomorphic

Compactness
Constant Boolean functions are one-node BDD Some important functions grow linearly with number of input variables (e.g. Parity)

Equivalence Check
Equivalence check is done in constant time

B.Z.

BDD Features
Basic Boolean Operations
The size of result of operation like FG is bounded by a product of sizes of F and G Using Dynamic Programming techniques, the time is almost linear with the size The size of F is equal to size of F The time is linear with the size Advanced techniques (attributed edges) reduce the time to constant

Complement

B.Z.

BDD Features
Find Satisfying Assignment Shared BDD
The time is linear with the size of a BDD All features remain true for multiple boolean functions represented by BDD set

B.Z.

Compare The Representations

Size Boolean Operator Equality Satisfy Canonicity

Truth Expression Table Exponenial Linear Linear Linear Linear Yes Constant

Circuit Linear Constant

Decision Tree Exponential Linear Linear Linear Yes

BDD Linear to Exponential Linear to Polinomial Constant Linear Yes

Exponential Exponential Exponential Exponential No No

B.Z.

Building a BDD
Models Are Boolean Expressions/Circuits Nave Approach
Build a decision tree and then apply reduction rules Wont work: decision trees are too big

Build BDD From Expressions


Use bottom-up strategy Always start from atomic functions F = x

B.Z.

Logic Manipulation Algorithm


BinOp(F, G)
If (TerminalCase) Return Result If COMPUTED(F,G) Return Result x = MIN(F-variable,G-variable) F0 = F(x=0), F1 = F(x=1) G0 = G(x=0), G1 = G(x=1) R0 = BinOp(F0, G0) R1 = BinOp(F1, G1) Result = BDDnode(x, R0, R1) Insert COMPUTED(F,G,Result) Return Result
B.Z.

Terminal Case Examples:

F 1 = F, F F = 0

Underlined are dynamic programming usage BDDnode function applies reduction rules The scheme of algorithm may be applied to other logic manipulations

Variables Ordering
Good Order Is Crucial
Different variable orders may change the size of BDD from exponential to linear

Theoretical Fact
Finding an optimal order is really hard Best known algorithms have complexity O(3N)

B.Z.

Variables Ordering: Examples


MUX
Y1 F Y2N
X1 XN

COMPARATOR
X1 XN Y1 YN q If F

If Y-variables are put first, the BDD size is exponential


q
q If

X-variables are put before Y-variables, the size is exponential


q If

X-variables are put first, the BDD size is linear


B.Z.

order is interlaced (X1,Y1, ,XN,YN) the size is linear

Variables Ordering: Examples


MULTIPLIER
X1 XN Y1 YN F1 FN F2N

q For

function FN, every order creates a BDD with size exponential


B.Z.

Obtaining A Good Order


Static Ordering
Basic idea: analyze the models structure

Dynamic Reordering
One basic idea: perform local order changes
Swap adjacent variables Try a single variable at a time

B.Z.

Basic Reorder Operation: Swap


Before:
F X Y Y Potentially reduce
Local Change

X and Y are adjacent in the order


Shannon expansion on both X and Y variables Each atomic swap removes at most 2 nodes Swapping X- and Y-level nodes may reduce as much nodes as on Y-level

Correctness Proof

BDD Size Reduction


F00 F01 F10 F11

After:
Y X

F Potentially new X

F00 F10 F01 F11


B.Z.

Reordering Algorithm: Sifting


SiftVariable (X) WHILE OnTop(X) Swap(Prev(X),X); SAVE Optimal WHILE OnBottom(X) Swap(X,Succ(X)); SAVE Optimal MoveTo(X, Optimal) Sifting(Variables) Prioritize(Variables) FOREACH X in Variables SiftVariable(X) ConvergenceSifting(Variables) DO SiftingReorder(Variables) WHILE ReductionSize > Thresh
B.Z.

Performance

Complexity of SiftVariable is linear with the size of BDD Complexity of Sifting is linear with N times the size of BDD ConvergenceSifting is basically more powerful, but may be very expensive

Reordering Variables: Advanced


Selective Reordering
Reorder only variables which are important Reduces the reordering time

Grouping Variables
Choose variables upon certain criterion (symmetry, dependency) and stick them together in groups Reorder on the group level only Better BDD size reduction in some cases

B.Z.

BDD Package Implementation

B.Z.

Main Components
Unique Table
Imposes a uniqueness of each BDD node

Computed Table
Stores the results of previous computations (dynamic programming technique)

Garbage Collection
Remove no-more-in-use BDD nodes

B.Z.

Unique Table
Unique Table
x Finds BDD node (x, F0, F1) Each variable has a separate Hash Table
Allows more efficient manipulation

Hash Table

The hash table entry Key is function of (F0, F1, size[hash]) Advanced Techniques
Resize Hash Table for efficiency Different Collision Chain policies
Last Recently Used - first Ring chain

..

...

key

Collision Chain x
x x

B.Z.

Computed Table
Cache Table
Stores result of Op(Arg1,Arg2) Implementation: Hash-Based Cache Table
Collisions are not resolved - last result stored

..

key

..

Cache entry Key is function of (Op, Arg1, Arg2, size[cache]) Advanced Techniques
Resize Cache table for efficiency Split Cache table to avoid collisions of frequently used Ops

Cache Table Entry


Op Arg1 Arg2 Result

B.Z.

Garbage Collection
Remove Dead BDD Nodes
`Dead node is one which is no longer in use Reference Counts Explicit Marks Number of references to each BDD node is kept All nodes with RC equal to zero are removed More expensive but more flexible A standard approach in many commercial BDD packages

Identification Of Dead Nodes Approaches

Reference Counts (RC)

B.Z.

Garbage Collection
Explicit Marks
Functions that are in use are marked Only BDD nodes representing functions in-use are left Less expensive but less flexible
Garbage Collection can not be triggered until a function is not built

Garbage Collection And Reordering


Reordering is usually done after Garbage Collection Garbage Collection is sometimes needed during Reordering Use Reference Counts only when Reordering

B.Z.

Using BDD In Model Checking

B.Z.

Finite State Machines


Mathematical Model For Model Checking Concepts

Memory elements, Inputs Allowed initial assignments FSM State, Set Of States Transition Relation

Set of allowed transitions between states

B.Z.

Finite State Machines


More Concepts

Image Of Set Of States S

Set of states reachable in one transition from S

Pre-Image Of Set Of States S

Set of states from which S is reachable in one transition

B.Z.

BDD Representation Of FSM


Memory Element Or Input
Set of BDD variables V, V (current, next value)

FSM State
Assignment of Boolean values B to V

A Set Of States
BDD of Characteristic Function S(V) B belongs to set S(B) = 1

B.Z.

BDD Representation Of FSM


Operations On Sets
BDD Boolean operations Example: A B S(A) S(B)

Transition Relation
BDD of Characteristic Function N(V, V) <A, B> is legal N(A,B) = 1

B.Z.

BDD Representation Of FSM


Image/Pre-Image
BDD Boolean operator Relational Product Computes V [S(V) N(V,V)] The algorithm computes the result in one pass Complexity: square of product of operand sizes

B.Z.

BDD Based Model Checking


Hardware Model
Represented as an FSM

Initial states
Set of atomic init functions x0 = Ix(V)

Transition relation
Set of atomic next-state functions x = Nx(V,V)

Assumptions

B.Z.

BDD Operations Flow


assumptions

Initial States Comp


Ix [Build/Conjunct]

Exclude Dead-Ends
[Pre-Image]

-inc

TransRelation Bld
Nx [Build/Conjunct]

Reach States Comp


[Image]

spec
B.Z.

Spec Evaluation
[Pre-Image]

CountExmap Gen
[Image/Pre-Image]

Model Checking And Reordering


Stage/Action Specific Reordering Change Criteria Of Good Order Advanced Algorithms
Different algorithms for different stages Consider active variables small overall BDD size small size of BDD representing Transition Relation Convergence Sifting Automatic Variables Grouping

B.Z.

Potrebbero piacerti anche