610 likes | 715 Vues
ECOE 560 Design Methodologies and Tools for Software/Hardware Systems Spring 2006. Serdar Ta şı ran. The Boolean Space B n. B = { 0,1} B 2 = {0,1} X {0,1} = {00, 01, 10, 11}. Karnaugh Maps:. Boolean Cubes:. B 0. B 1. B 2. B 3. B 4. Boolean Functions. x 2. x 1. Boolean Functions.
E N D
ECOE 560Design Methodologies and Tools for Software/Hardware SystemsSpring 2006 Serdar Taşıran
The Boolean Space Bn • B = { 0,1} • B2 = {0,1} X {0,1} = {00, 01, 10, 11} Karnaugh Maps: Boolean Cubes: B0 B1 B2 B3 B4
Boolean Functions x2 x1
Literals Aliteral 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 x2 x1 x1
Set of Boolean Functions • Truth Table or Function table: • There are 2n vertices in input space Bn • There are 22n distinct logic functions. • Each subset of vertices is a distinct logic function: f Bn x1x2x3 0 0 0 1 0 0 1 0 0 1 0 1 0 1 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 1 1 0 x3 x2 x1
Representation of Boolean Functions • A Boolean formula is defined as an expression with the following syntax: formula ::= ‘(‘ formula ‘)’ | <variable> | formula “+” formula (OR operator) | formula “×” formula (AND operator) | ^ formula (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
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}
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 f = x1x2x3 x3 x3 x3 x2 x2 x2 x1 x1 x1
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 Canonical means that if two functions are the same, then the canonical representations of each are isomorphic. abcd f 0 0000 0 1 0001 1 2 0010 0 3 0011 1 4 0100 0 5 0101 1 6 0110 0 7 0111 0 abcd f 8 1000 0 9 1001 1 10 1010 0 11 1011 1 12 1100 0 13 1101 1 14 1110 1 15 1111 1
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.
SOP • 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) ac bc = onset minterm Note that each onset minterm is “covered” by at least one of the cubes! None of the offset minterms is covered ab c b a
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 b a a
Shannon Expansion f : Bn B Theorem: Theorem: F is a cover of f. Then We say that f (F) is expanded about xi. xi is called the splitting variable.
Shannon Expansion (cont.) Example Cube bc got split into two cubes ac bc ab c c b b a a
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, ...
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
Binary Decision Tree The recursive Shannon expansion corresponds to a binary decision tree (binary recursion tree) Path (v) to node v corresponds to cube c(v) Example: c(v) = x1 x2 x3 x x1 1 0 1 0 y x2 y 0 1 0 1 0 1 (v) x3 1 0 v
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.
Example Splitting variable a a 1 0 1 0 b b c b 0 0 1 0 1 0 1 1 1 1 0 1 0 0 c c 0 1 0 1
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 xi1 < xi2 < xi3 < … < xin
Variable Ordering • Assign arbitrary total ordering to variables • e.g., x1 < x2 < x3 • Variables must appear in ascending order along all paths OK Not OK Properties • No conflicting variable assignments along path • Simplifies manipulation
a a a Reduction Rule #1 Merge equivalent leaves
x x x x x x y z y z y z Reduction Rule #2 Merge isomorphic nodes
x y y Reduction Rule #3 Eliminate Redundant Tests
Example OBDD • 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. Initial Graph Reduced Graph
Constants Variable Unique unsatisfiable function Treat variable as function Unique tautology Typical Function Odd Parity • (x1 x2 ) x4 • No vertex labeled x3 • independent of x3 • Many subgraphs shared Linear representation Example Functions
Representing Circuit Functions • Functions • All outputs of 4-bit adder • Functions of data inputs • Shared Representation • Graph with multiple roots • 31 nodes for 4-bit adder • 571 nodes for 64-bit adder • Linear growth
Linear Growth Exponential Growth Effect of Variable Ordering Good Ordering Bad Ordering
Onset is Given by all Paths to “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 F = b’+a’c’ = ab’+a’cb’+a’c’ all paths to the 1 node f a 0 1 fa = cb’+c’ c 1 fa= b’ b 0 0 1 0 1
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
Function is Given by Tracing All Paths to 1 F = b’+a’c’ = ab’+a’cb’+a’c’ all paths to the 1 node f a Notes: • 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 0 1 fa = cb’+c’ c 1 fa= b’ b 0 1 0 0 1
f b is top variable of f a f b reduced b 0 1 0 1 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). fa = b, fa = b f does not depend on a, since fa = fa . Each node is written as a triple: f = (v,g,h) where g = fv and h = fv . We read this triple as: f = if v then g else h = ite(v,g,h) = vg+v ’ h v is top variable of f f f v 1 0 mux v 0 1 g h g h
If-Then-Else Operation • Concept • Basic technique for building OBDD from logic network or formula. Arguments I, T, E • Functions over variables X • Represented as OBDDs Result • OBDD representing composite function • (I T)(I E) Implementation • Combination of depth-first traversal and dynamic programming. • Worst case complexity product of argument graph sizes.
Recursive Calls If-Then-Else Execution Example Argument I Argument T Argument E • Optimizations • Dynamic programming • Early termination rules
If-Then-Else Result Generation • Recursive calling structure implicitly defines unreduced BDD • Apply reduction rules bottom-up as return from recursive calls • Generates reduced graph Recursive Calls Without Reduction With Reduction
Functional Composition • Create new function by composing functions F and G. • Useful for composing hierarchical modules.
Variable Quantification • Eliminate dependency on some argument through quantification • Combine with AND for universal quantification.
ITE Operator ite operator can implement any two variable logic function. There are 16 such functions corresponding to all subsets of vertices of B 2: Table Subset 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 fg 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
hash value of key collision chain Unique Table - Hash Table 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:
Recursive Formulation of ITE v = top-most variable among the three BDD’s f, g, h
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(fv , gv , hv ); 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.
Example G H I F a b a a 0 0 0 0 1 1 1 1 D J B C C d d c b 1 0 1 1 1 0 1 0 I = ite (F, G, H) = (a, ite (Fa, Ga , Ha ), ite (Fa , Ga , Ha )) = (a, ite (1, C, H), ite(B,0, H )) = (a, C, (b, ite (Bb , 0b , Hb ), ite (Bb ,0b , Hb)) = (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) +ab(b + d) = ac + abd 1 0 0 D 1 0 0 1 0 1 0 F,G,H,I,J,B,C,D are pointers
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 chain can be merged.
v 0 4 4 1 3 2 3 1 2 0 Multivalued Decision Diagrams(MDD’s) “BDD’s” for MV-functions There is an equivalent theory (canonical etc.) for MDD’s: Pv = (0,1,2,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:
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 multi-valued variables representing nodes in the graph.
Generating OBDD from Network Task:Represent output functions of gate network as OBDDs. • 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); Network Evaluation Resulting Graphs
a b b a b c c c 0 1 0 1 0 1 Checking Network Equivalence Task: Do two networks compute same Boolean function? Method: Compute OBDDs for both networks and compare Alternate Network Evaluation T1 Or (A, C); O2 And (T1, B); if (O2 == Out) then Equivalent else Different O2 Resulting Graphs T1 A B C a 0 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 • 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!
Union Intersection Characteristic Functions • Concept • A {0,1}n • Set of bit vectors of length n • Represent set A as Boolean function A of n variables • XA if and only if A(X ) = 1 Set Operations