Transcript Document

ECOE 560
Design Methodologies and Tools for
Software/Hardware Systems
Spring 2006
Serdar Taşıran
The Boolean Space B
•
•
n
B = { 0,1}
B2 = {0,1} X {0,1} = {00, 01, 10, 11}
Karnaugh Maps:
Boolean Cubes:
B0
B1
B2
B3
B4
2
Boolean Functions
Boolean Function: f ( x ) : B n  B
B  {0,1}
x  ( x1, x2 ,..., xn )  B n ; xi  B
- x1, x2 ,... are variables
- x1, x1, x2 , x2 ,... are literals
- essentially: f maps each vertex of B n to 0 or 1
x2
Example:
f  {(( x1  0, x2  0),0),(( x1  0, x2  1),1),
(( x1  1, x2  0), 1),(( x1  1, x2  1),0)}
x1
0 1
1 0
x2
x1
3
Boolean Functions
- The Onset of f is { x | f ( x )  1}  f 1(1)  f 1
- The Offset of f is { x | f ( x )  0}  f 1(0)  f 0
- if f 1  B n , f is the tautology. i.e. f  1
- if f 0  B n (f 1   ), f is not satisfyable, i.e. f  0
- if f ( x )  g ( x ) for all x  B n , then f and g are equivalent
- we say f instead of f 1
Literals:
A literal is a variable or its negation
x, x
and represents a logic function
4
Literals
A literal is a variable or its negation
y, y
It represents a logic function
Literal x1 represents the logic function f, where f = {x| x1 = 1}
Literal x1 represents the logic function g where g = {x| x1 = 0}
f = x1
f = x1
x3
x3
x2
x1
x2
x1
5
Set of Boolean Functions
•
Truth Table or Function table:
x3
x2
x1
•
•
x1x2x3
000
1
001
0
010
1
011
0
100 1
101
0
110
1
111
0
There are 2n vertices in input space Bn
n
There are 22 distinct logic functions.
– Each subset of vertices is a distinct logic function:
f  Bn
6
Representation of Boolean Functions
•
A Boolean formula is defined as an expression with the following
syntax:
formula ::=
|
|
|
|
‘(‘ formula ‘)’
<variable>
formula “+” formula
formula “” formula
^ formula
(OR operator)
(AND operator)
(complement)
Example:
f = (x1x2) + (x3) + ^^(x4  (^x1))
typically the “” is omitted and the ‘(‘ and ‘^’ are simply reduced by priority,
e.g.
f = x1x2 + x3 + x4^x1
7
Boolean Operations AND, OR, COMPLEMENT
Given two Boolean functions:
f : Bn  B
g : Bn  B
•
The AND operation h = f  g is defined as
h = {x | f(x)=1  g(x)=1}
•
The OR operation h = f + g is defined as
h = {x | f(x)=1  g(x)=1}
•
The COMPLEMENT operation h = ^f is defined as
h = {x | f(x) = 0}
8
Cubes
•
A cube is defined as the AND of a set of literal functions (“conjunction”
of literals).
Example:
C = x1x2x3
represents the following function
f = (x1=1)(x2=0)(x3=1)
c = x1
f = x1x2
x3
f = x1x2x3
x3
x3
x2
x1
x2
x1
x2
x1
9
Representation of Boolean Functions
•
Truth table (Function Table):
The truth table of a function f : Bn  B is a tabulation of its value at
each of the 2n vertices of Bn.
In other words the truth table lists all mintems
Example: f = abcd + abcd + abcd +
abcd + abcd + abcd +
abcd + abcd
The truth table representation is
- intractable for large n
- canonical
0
1
2
3
4
5
6
7
abcd
0000
0001
0010
0011
0100
0101
0110
0111
f
0
1
0
1
0
1
0
0
8
9
10
11
12
13
14
15
abcd
1000
1001
1010
1011
1100
1101
1110
1111
f
0
1
0
1
0
1
1
1
Canonical means that if two functions are the same, then the
canonical representations of each are isomorphic.
10
Representation of Boolean Functions
• Sum of Products:
•
A function can be represented by a sum of cubes (products):
f = ab + ac + bc
Since each cube is a product of literals, this is a “sum of products”
(SOP) representation
•
A SOP can be thought of as a set of cubes F
F = {ab, ac, bc}
•
A set of cubes that represents f is called a cover of f.
F1={ab, ac, bc} and F2={abc,abc,abc,abc,bc}
are covers of
f = ab + ac + bc.
11
SOP
ac
bc
= onset minterm
ab
c
b
a
•
•
Note that each onset minterm is
“covered” by at least one of the
cubes!
None of the offset minterms is
covered
Covers (SOP’s) can efficiently represent many practical logic functions
(i.e. for many, there exist small covers).
Two-level minimization seeks the minimum size cover (least number of
cubes)
12
Shannon (Boole) Cofactors
Let f : Bn  B be a Boolean function, and x= (x1, x2, …, xn) the
variables in the support of f.
The cofactor fa of f by a literal a=xi or a=xi is
fxi (x1, x2, …, xn) = f (x1, …, xi-1, 1, xi+1,…, xn)
fxi (x1, x2, …, xn) = f (x1, …, xi-1, 0, xi+1,…, xn)
The computation of the cofactor is a fundamental operation in Boolean
reasoning!!!!
Example:
f = abc + abc
fa = bc
c
c
b
a
b
a
13
Shannon Expansion
f : Bn  B
Theorem:
f  xi f xi + xi f xi
Theorem: F is a cover of f. Then
F  x i Fx i + x i Fx i
We say that f (F) is expanded about xi.
xi is called the splitting variable.
14
Shannon Expansion (cont.)
Example
F  ab + ac + bc
F  aFa + aFa  a(b + c + bc) + a(bc)
 ab + ac + abc + abc
ac
bc
ab
c
c
b
Cube bc got split ainto two cubes
b
a
15
Boolean Reasoning
• Fundamental mechanism to decide about synthesis and
verification steps
– Is a particular change to the circuit or code valid?
– Are two sub-circuits or pieces of code functionally identical?
– Is a particular path in my circuit or code sensitizable?
• Boolean reasoning requires an efficient representation and
manipulation of Boolean functions
– build a Boolean function
• AND, OR, NOT, …
– decide about tautology or satisfiability (SAT)
• f 0? f 1?
• E.g.: Are f and g functionally equivalent?  (f g) 0?
• Boolean reasoning algorithms also used for efficient set
manipulations
– sets of states, sets of simulation vectors, ...
16
Boolean Reasoning
• Two fundamental approaches:
– keep representation canonical with respect to the function
• tautology or SAT check is easy
• but representation may blow-up in space
• Example:
– BDDs and their derivatives
– keep representation non-canonical
• representation can remain compact
• tautology or SAT check is exponential (NP or co-NP complete)
• Example:
– Boolean formulas
– circuits (networks),
– list of cubes
– and anything in between
17
Binary Decision Tree
The recursive Shannon expansion corresponds to a binary decision tree
(binary recursion tree)
f  xf x + x f x
 x( yf xy + y f x y ) + x( yf xy + y f x y )
x1
1
(v)
1
1
0
0
1
x3
x
0
x2
y
1
0
f xy
y
0
1
fx y
f xy
0
fx y
v
Path (v) to node v corresponds to cube c(v)
Example: c(v) = x1 x2 x3
18
Binary Decision Tree
•
The root represents the original function f.
•
Each node v corresponds to fc(v).
•
Minterms represent complete path and are constants:
– fm(v) = 0 (1)
•
Reduction Rule:
– If all leafs of a subtree below node v have same constant c, replace v
by constant c
– i.e. if fc(v) = 1 or 0 we can terminate the tree and replace v by 1 or 0.
Such a node v becomes leaf.
19
Example
f  ab + ac
Splitting
variable
a
1
b
1
1
a
1
0
b
0
1
0
b
0
c
1
1
1
c
0
1
0
c
0
1
0
1
0
0
0
20
ROBDD’s
•
•
•
•
Directed acyclic graph (DAG)
one root node, two terminals 0, 1
each node, two children, and a variable
Shannon co-factoring tree, except reduced and ordered (ROBDD)
– Reduced:
• any node with two identical children is removed
• two nodes with isomorphic BDD’s are merged
– Ordered:
• Co-factoring variables (splitting variables) always follow the
same order along all paths
xi < xi < xi < … < xin
1
2
3
21
Variable Ordering
– Assign arbitrary total ordering to variables
• e.g., x1 < x2 < x3
– Variables must appear in ascending order along all paths
OK
x1
Not OK
x1
x2
x3
x3
x1
x2
x3
x1
x1
Properties


No conflicting variable assignments along path
Simplifies manipulation
22
Reduction Rule #1
Merge equivalent leaves
a
a
a
x1
x1
x2
x3
0
x2
x3
0
0
x2
x3
1
0
x3
1
0
x3
1
x2
x3
0
x3
x3
1
23
Reduction Rule #2
Merge isomorphic nodes
x
x
x
x
x
x
y
z
y
z
y
z
x1
x1
x2
x3
x2
x3
0
x3
x3
1
x2
x2
x3
x3
0
1
24
Reduction Rule #3
Eliminate Redundant Tests
x
y
y
x1
x1
x2
x2
x3
x3
0
1
x2
x3
0
1
25
Example OBDD
Initial Graph
Reduced Graph
x1
x1
x2
x3
0
•
0
0
x2
x2
x3
x3
1
0
x3
x3
1
(x1+x2)· x3
0
1
0
1
Canonical representation of Boolean function
 For given variable ordering
– Two functions equivalent if and only if graphs isomorphic
• Can be tested in linear time
– Desirable property: simplest form is canonical.
26
Example Functions
Constants
Variable
0
Unique unsatisfiable function
1
Unique tautology
Typical Function
x1
x2

(x1  x2 )  x4

No vertex labeled x3


x4
0
1
x
0
Treat variable
as function
1
Odd Parity
x1
x2
x2
x3
x3
x4
x4
0
1
independent of x3
Many subgraphs shared
Linear
representation
27
Representing Circuit Functions
•
Functions
S3
– All outputs of 4-bit adder
– Functions of data inputs
Cout
a3
a3
b3 b3
b3 b3
a2
a2
a2
b2 b 2
b2 b2
b2 b2
a1
a1
a1
b1 b 1
b1 b1
b1 b1
a0
a0
a0
S2
A
B
A
D
D
Cout
S
S1
S0
•
Shared Representation
– Graph with multiple roots
– 31 nodes for 4-bit adder
– 571 nodes for 64-bit adder
Linear growth
b0
0
b0
1
28
Effect of Variable Ordering
(a1  b1)  (a2  b2 )  (a3  b3 )
Good Ordering
Bad Ordering
a1
a1
b1
a2
a2
a3
a2
a3
a3
b2
b1 b1 b1 b1
a3
b2 b2
b3
0
a3
b3
1
Linear Growth
0
1
Exponential Growth
29
Onset is Given by all Paths to “1”
F = b’+a’c’ = ab’+a’cb’+a’c’ all paths to the 1 node
0
fa = cb’+c’
c
a
1
1
fa= b’
b
0
1
0
f
0
1
Notes:
• By tracing paths to the 1 node, we get a cover of pairwise disjoint cubes.
• BDDs can be used to efficiently represent sets
– interpret elements of the onset as elements of the set
– f is called the characteristic function of that set
30
ROBDD’s
•
•
•
Representation of a logic function as graph (DAG):
– many logic functions can be represented compactly - usually better than
SOP’s
Are canonical !!
Many logic operations can be performed efficiently on BDD’s:
– usually linear in size of result – tautology, satisfiability and complement are
constant time
31
Function is Given by Tracing
All Paths to 1
F = b’+a’c’ = ab’+a’cb’+a’c’ all paths to the 1 node
fa = cb’+c’
0
c
0
Notes:
0
a f
1
1
b
0
fa= b’
1
1
• By tracing paths to the 1 node, we get a cover of pairwise
disjoint cubes.
• The power of the BDD representation is that it does not
explicitly enumerate all paths; rather it represents paths by a
graph whose size is measures by its nodes and not paths.
• A DAG can represent an exponential number of paths with a
linear number of nodes.
• Each node is given by its Shannon representation:
f = afa + afa
32
Implementation
Variables are totally ordered: If v < w then v occurs “higher” up
in the ROBDD (call it BDD from now on).
Definition 1: Top variable of a function f is a variable
associated with its root node.
Example: f = ab + a’bc + a’bc’. Order is (a < b < c).
f
fa = b, fa = b
b is top variable of f
a
f does not depend on a,
since fa = fa .
reduced
b
0
b f
0
1
1
Each node is written as a triple: f = (v,g,h) where g = fv and
h = fv . We read this triple as:
f = if v then g else h = ite (v,g,h) = vg+v ’ h
f
v
1
0
g
h
v
mux
0
h
v is top variable of f
f
1
g
33
If-Then-Else Operation
Concept

Basic technique for building OBDD from logic network or
formula.
I  T, E
I
X
T
0


1
MUX
E
Arguments I, T, E
Result

Implementation


– 34 –
Functions over variables X
Represented as OBDDs

OBDD representing
composite function
(I T)  (I  E)
Combination of depth-first traversal and dynamic
programming.
Worst case complexity product of argument graph sizes.
If-Then-Else Execution Example
Argument I
A1 a
Argument T
Argument E
A2,B2
c A6
A3 d
1 A5

– 35 –
Dynamic programming
Early termination rules
A6,B2 A6,B5
c B5
B2 d
Optimizations

A1,B1
a B1
1
A2 b
A4 0
Recursive Calls
B3 0
A3,B2
A5,B2 A3,B4
1 B4 A4,B3 A5,B4
If-Then-Else Result Generation
Recursive Calls
Without Reduction
A1,B1
C5 b
b
C4
A6,B2 A6,B5

d
0
1
1
c
c
1
C3 d
C1 0
1 C2
Recursive calling structure implicitly defines unreduced BDD
Apply reduction rules bottom-up as return from recursive calls
 Generates reduced graph
– 36 –
c
A5,B2 A3,B4
A4,B3 A5,B4

a C6
a
A2,B2
A3,B2
With Reduction
Functional Composition
x1
x1
xi –1
1
x1
x1
xn
G
xi –1
xi +1
xn
F
xi +1
F
xn
F [xi =G]
1
MUX
0
x1
xi –1
0
xn
G
F
xi +1
xn


– 37 –
Create new function by composing functions F and G.
Useful for composing hierarchical modules.
Variable Quantification
x1
x1

xi –1
xi +1
1
F
xi –1
F
xi +1
xi F
xn
x1
xn
0
xi –1
F
xi +1
xn


– 38 –
Eliminate dependency on some argument through
quantification
Combine with AND for universal quantification.
ITE Operator
ite(f , g , h)  fg + f g
ite operator can implement any two variable logic function. There are
16 such functions corresponding to all subsets of vertices of B 2:
( f g , f g , f g , fg )
Table
Subset
Expression
Equivalent Form
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
0
AND(f, g)
f > g
f
f < g
g
XOR(f, g)
OR(f, g)
NOR(f, g)
XNOR(f, g)
NOT(g)
f  g
NOT(f)
f  g
NAND(f, g)
1
0
fg
fg
f
fg
g
f  g
f + g
f + g
f  g
g
f + g
f
f + g
fg
1
0
ite(f, g, 0)
ite(f,g, 0)
f
ite(f, 0, g)
g
ite(f,g, g)
ite(f, 1, g)
ite(f, 0,g)
ite(f, g,g)
ite(g, 0, 1)
ite(f, 1, g)
ite(f, 0, 1)
ite(f, g, 1)
ite(f, g, 1)
1
39
Unique Table - Hash Table
hash value
of key
collision
chain
Before a node (v, g, h ) is added to BDD data base, it is looked up in
the “unique-table”. If it is there, then existing pointer to node is
used to represent the logic function. Otherwise, a new node is
added to the unique-table and the new pointer returned.
Thus a strong canonical form is maintained. The node for f = (v, g, h )
exists iff(v, g, h ) is in the unique-table. There is only one pointer
for (v, g, h ) and that is the address to the unique-table entry.
Unique-table allows single multi-rooted DAG to represent all users’
functions:
40
Recursive Formulation of ITE
v = top-most variable among the three BDD’s f, g, h
ite( f , g , h)  fg + f h
 v( fg + f h)v + v( fg + f h)v
 v( f v g v + f v hv ) + v( f v g v + f v hv )
 ite(v, ite( f v , g v , hv ), ite( f v , g v , hv ))
 (v, ite( f v , g v , hv ), ite( f v , g v , hv ))
 ( v, f , g )  R
41
Recursive Formulation of ITE
Terminal cases: (0, g, f ) = (1, f, g) = f
ite (f, g, g) = g
ite(f, g, h)
if(terminal case) {
return result;
} else if(computed-table has entry (f, g, h )) {
return result;
} else {
let v be the top variable of (f, g, h );
f <- ite(fv , gv , hv );
g <- ite(fv , gv , hv );
if( f equals g ) return g;
R <- find_or_add_unique_table(v, f, g );
insert_computed_table( {f, g, h }, R);
return R; } }
The “insert_computed_table” is a cache table where ite results are
cached.
42
Example
1
1
F
a
0
b
1
1
B
0
0
C
1
1
1
c
G
a
0
0
0
1
0
1
H
b
0
d
1
1
D
0
0
C
1
I
a
0
d
1
0
J
0
D
F,G,H,I,J,B,C,D
are pointers
I = ite (F, G, H)
= (a, ite (Fa , Ga , Ha ), ite (Fa , Ga , Ha ))
= (a, ite (1, C , H ), ite(B, 0, H ))
= (a, C, (b , ite (Bb , 0b , Hb ), ite (Bb , 0b , Hb ))
= (a, C, (b , ite (1, 0, 1), ite (0, 0, D)))
= (a, C, (b , 0, D))
= (a, C, J)
Check:
F = a + b
G = ac
H = b + d
ite(F, G, H) = (a + b)(ac) +ab(b + d)
= ac + abd
43
Computed Table
Keep a record of (F, G, H ) triplets already computed by the ite
operator in a hash-based cache ( “cache” table). This means
that the collision chain is not used (if collision, old entry
thrown away ).
The above structure is wasteful since the BDD nodes and collision
44
chain can be merged.
Multivalued Decision Diagrams(MDD’s)
“BDD’s” for MV-functions
There is an equivalent theory (canonical etc.) for
MDD’s:
v
0
1
2
Pv = (0,1,2,3,4)
3
4
Typically, we encode the multi-valued variable with
log2(|Pv|) binary variables and use unused codes as
“don’t cares” in a particular way:
4
0
12
3
45
Sets and Graphs:
With MDDs we can represent and manipulate
general sets and graphs.
Set:  characteristic function of set
 ((f (v ) = 1)  (v S  Pv))
Graph: (set of edges)  ((f (x, y ) = 1)  (x, y )
is an edge in graph where x and y are multivalued variables representing nodes in the
graph.
46
Generating OBDD from Network
Task:
Represent output functions of gate network as OBDDs.
Network
A
Evaluation
A  new_var ("a");
B  new_var ("b");
C  new_var ("c");
T1  And (A, 0, B);
T2  And (B, C);
Out  Or (T1, T2);
T1
B
Out
C
T2
Out
Resulting Graphs
T1
0
– 47 –
A
B
C
a
b
c
1
0
1
0
a
b
b
1
0
a
T2
b
c
1
0
b
c
1
0
1
Checking Network Equivalence
Task: Do two networks compute same Boolean function?
Method: Compute OBDDs for both networks and compare
Alternate Network
A
Evaluation
T1  Or (A, C);
O2  And (T1, B);
if (O2 == Out)
then Equivalent
else Different
T1
C
O2
B
O2
Resulting Graphs
a
T1
0
– 48 –
A
B
C
a
b
c
1
0
1
0
b
a
c
1
0
b
c
1
0
1
Finite State System Analysis
Systems Represented as Finite State Machines



Sequential circuits
Communication protocols
Synchronization programs
Analysis Tasks



State reachability
State machine comparison
Temporal logic model checking
Traditional Methods Impractical for Large Machines



– 49 –
Polynomial in number of states
Number of states exponential in number of state variables.
Example: single 32-bit register has 4,294,967,296 states!
Characteristic Functions
Concept

A  {0,1}n
 Set of bit vectors of length n

Represent set A as Boolean
function A of n variables
A
0 /1
 X  A if and only if A(X ) = 1
Set Operations
Union
– 50 –
Intersection
A
A
B
B
Symbolic FSM Representation
Nondeterministic FSM
Symbolic Representation
n1
00
n2
01
o1
10

11
o2
o2
0
1
o1 ,o2 encoded
old state
n1 , n2 encoded
new state
Represent set of transitions as function (Old, New)
 Yields 1 if can have transition from state Old to state New

– 51 –
Represent as Boolean function
 Over variables encoding states
Reachability Analysis
Task



Compute set of states reachable from initial state Q0
Represent as Boolean function R(S)
Never enumerate states explicitly
Given
old state
Compute

state
0/1
new state
Initial
R0
=
Q0
– 52 –
R
0/1
Breadth-First Reachability Analysis
00
01
R0
10


11
01
R2 R3
10
Ri – set of states that can be reached in i transitions
Reach fixed point when Rn = Rn+1
 Guaranteed since finite state
– 53 –
00
00
R1
Iterative Computation
Ri

old
new
Ri +1

Ri

Ri +1 – set of states that can be reached i +1 transitions
 Either in Ri
 or single transition away from some element of Ri
– 54 –
Example: Computing R1 from R0
n1
n1
R0
n2
n2
o1
00
1
o2
o2
0
1
0
0
 Old [R0(Old)  (Old, New)]
R1
n1
n1
n2
1
1
– 55 –
0
0
0
00
01
Symbolic FSM Analysis Example

K. McMillan, E. Clarke (CMU) J. Schwalbe (Encore Computer)
Encore Gigamax Cache System



Distributed memory multiprocessor
Cache system to improve access time
Complex hardware and synchronization protocol.
Verification


Create “simplified” finite state model of system (109 states!)
Verify properties about set of reachable states
Bug Detected


– 56 – 
Sequence of 13 bus events leading to deadlock
With random simulations, would require 2 years to generate
failing case.
In real system, would yield MTBF < 1 day.
What’s Good about OBDDs
Powerful Operations


Creating, manipulating, testing
Each step polynomial complexity
 Graceful degradation

Maintain “closure” property
 Each operation produces form suitable for further operations
Generally Stay Small Enough


Especially for digital circuit applications
Given good choice of variable ordering
Weak Competition


– 57 –
No other method comes close in overall strength
Especially with quantification operations
What’s Not Good about OBDDs
Doesn’t Solve All Problems



Can’t do much with multipliers
Some problems just too big
Weak for search problems
Must be Careful

Choose good variable ordering
 Critical effect on efficiency
 Must have insights into problem characteristics
 Dynamic reordering most promising workaround

Some operations too hard
 Must work around limitations
– 58 –
Another Representation: Factored Forms
59
Factored Forms
Example: (ad+b’c)(c+d’(e+ac’))+(d+e)fg
Advantages
• good representative of logic complexity
f=ad+ae+bd+be+cd+ce
f’=a’b’c’+d’e’  f=(a+b+c)(d+e)
• in many designs (e.g. complex gate CMOS) the implementation of a
function corresponds directly to its factored form
• good estimator of logic implementation complexity
• doesn’t blow up easily
Disadvantages
• not as many algorithms available for manipulation
• hence often just convert into SOP before manipulation
60
Factored Forms
Note:
literal count  transistor count  area
• however, area also depends on
– wiring
– gate size etc.
• therefore very crude measure
61