160 likes | 330 Views
Sequential System Synthesis -- State Encoding. The State Encoding Problem. Goal: Given n states, assign a unique code (of length of at least log n) to each state such that the cost of binary logic level implementation is minimized. ( state assignment problem ) Cost of the implementation:
E N D
The State Encoding Problem • Goal: Given n states, assign a unique code (of length of at least log n) to each state such that the cost of binary logic level implementation is minimized. (state assignment problem) • Cost of the implementation: • Number of literals • Speed • Testability ENEE 644
x CS NS O 0 A C 1 x y1y2 O Y1Y2 0 B C 1 0 01 11 1 0 10 11 1 x y1y2 O Y1Y2 0 00 11 1 0 10 11 1 Example: Why State Encoding Matters? • Consider a fragment of the cube table for an FSM: • Let y1y2 and Y1Y2 be the current state and next state. We want to represent Y1,Y2, and output O as a function of y1,y2, and input x. • Assignment 1: A=01, B=10, C=11 Y1=…+x’y1’y2+…+x’y1y2’+… Y2=…+x’y1’y2+…+x’y1y2’+… O=…+x’y1’y2+…+x’y1y2’+… • Assignment 2: A=00, B=10, C=11 Y1=…+x’y1’y2’+…+x’y1y2’+…=…+x’y2’+… ENEE 644
x CS NS O a A B 1 b A C 1 Lessons We Have Learned • Two codes are adjacent if they only differ in one bit. (e.g. 00 and 01 are adjacent, 01 and 10 are not.) • Any k-bit code has k adjacent codes. • If two states are given adjacent codes, we will be able to extract common cubes from the next state and output functions. • Common fanout (next) state • Common fanin (current) state • Identify pairs that should receive adjacent codes. ENEE 644
Attraction Graph • The attraction graph of a FSM is a weighted, undirected, complete graph that represents the attraction between each pair of states. • Node: state • Edge: the attraction between the two states • If two states share a common fanout/fanin state, their attraction should increase. • Two states that have a strong attraction should be assigned adjacent codes. • How to measure the attraction quantitatively? ENEE 644
0/0 A 1/1 1/1 0/0 C B 1/0 0/0 A 2 3 B C 4 Fanout-Oriented Algorithm • State Transition Matrix S|s|x|s|: • Row: one per (current) state • Column: one per (next) state • Entry: (non-negative) number of arcs going from state si (row) to state sj (column) • Output Matrix Z|s|x|O|: • Row: one per (current) state • Column: one per output • Entry: (non-negative) number of arcs going out of state si (row) with output zj (column) • Let Nb be the number of encoding bits, then the attraction between states si and sj is given by Nb•Si•SjT+Zi•ZjT • W(1,2) = 2(1 1 0)(1 0 1)T+(1)(0)T=2 • W(1,3) = 2(1 1 0)(1 0 1)T+(1)(1)T=3 • W(2,3) = 2(1 0 1)(1 0 1)T+(0)(1)T=4 ENEE 644
0/0 A 1/1 1/1 0/0 C B 1/0 0/0 ^ ^ A 3 7 B C 1 Fanin-Oriented Algorithm ^ • State Transition Matrix S|s|x|s|: • Row: one per (next) state • Column: one per (current) state • Entry: (non-negative) number of arcs going from state sj (column) to state si (row) • Input Matrix X|s|x|I|: • Row: one per (current) state • Column: |I| per input • Entry: (non-negative) number of arcs entering state si (row) with input xj (column) • Let Nb be the number of encoding bits, then the attraction between states si and sj is given by Nb•Si•SjT+Xi•XjT • W(1,2) = 2(1 1 1)(1 0 0)T+(2 1)(0 1)T=3 • W(1,3) = 2(1 1 1)(0 1 1)T+(2 1)(1 1)T=7 • W(2,3) = 2(1 0 0)(0 1 1)T+(0 1)(1 1)T=1 ENEE 644
The Encoding Algorithm • Given the attraction graph (matrix W(i,j)), assign a unique Nb-bit code to each state. • For each node si, find the Nb largest attractions W(i,j) and sum them up; • Pick the one with the largest sum and assign it code 0…0; • Assign the Nb adjacent codes of 0…0 to the Nb neighbor states that have the Nb largest attractions; • Remove the Nb+1 node and repeat until all nodes get a Nb-bit code; ENEE 644
0/0 A 1/1 1/1 0/0 C B 1/0 0/0 01 00 A A A A 2 3 3 2 3 7 3 7 10 00 10 01 B B B B C C C C 1 4 1 4 Example: The Encoding Algorithm Fanout-Oriented Algorithm: Fanin-Oriented Algorithm: Y1=y1’y2x Y2=y1’y2x + y1y2’x’ + y1’y2’x Z = y1’x (13 literals) Y1=y1’y2x’ + y1’y2x Y2=y1’y2’x Z = y2’x (11 literals) ENEE 644
Decomposition and Encoding:Motivation • There are many different ways to encode a FSM with four states: {A,B,C,D}. • If we know that pairs (A,B),(C,D); (A,C),(B,D) should receive adjacent codes, then there are only 8 different assignments: • A=00, B=01, C=10, D=11 • A=00, B=10, C=01, D=11 • A=01, B=00, C=11, D=10 • A=01, B=11, C=00, D=10 • A=10, B=11, C=00, D=01 • A=10, B=00, C=11, D=01 • A=11, B=01, C=10, D=00 • A=11, B=10, C=01, D=00 ENEE 644
Notations on Partitions • A partition on a set S is a collection of disjoint subsets (called blocks) of S whose union is S. • ={(1,2),(3,4,6),(5,8),(7)} is a partition of S={1,2,3,4,5,6,7,8} • 0={(1),(2),(3)} and 1={(1,2,3)} are two trivial partitions of S={1,2,3} • For s,t S, st () means that they belong to the same block of partition • For two partitions 1 and 2, their meet 1•2 is also a partition where st (1•2) iff st (1) and st (2); their join 1+2 is the partition where st (1+2) iff there exists a sequence in S: s=s0,s1,…,sn=t, such that for all i=0,…n-1, either si si+1(1) or si si+1(2). • Given 1={(1,2),(3,4,6),(5,8),(7)}, 2={(1,6),(2,5,8),(3,4,7)}, 1•2={(1),(2),(3,4),(5,8),(6),(7)}, 1+2={(1,2,3,4,5,6,7,8)} ENEE 644
Substitution Property • A partition on set S of machine M=<I,S,,S0,O,> has the substitution property (S.P.) iff st() implies that (s,a)(t,a)() for all aI. • Theorem. A sequential machine M has a non-trivial parallel decomposition of its states iff there exist two non-trivial S.P. partitions 1 and 2 on M such that meet 1•2=0. • Theorem. IF a sequential machine has one non-trivial S.P. partition, then it has a non-trivial serial decomposition. ENEE 644
0 0 0 1 1 1 0 3 2 0 X Z Z 0 1 5 2 0 A B A 0 2 4 1 0 Y X Z 0 3 1 4 1 B A B 1 4 0 3 0 Z Y Y 1 5 2 3 0 G1 G2 Parallel Decomposition • 1 = {(0,1,2),(3,4,5)} and 2={(0,5),(1,4),(2,3)} are two S.P. partitions and 1•2=0. • Let A=(0,1,2), B=(3,4,5), and X=(0,5),Y=(1,4),Z=(2,3), we can build two machines. • The output, in this case, is the product of the outputs of the two newly built machines. ENEE 644
0 1 0 1 1 1 4 1 0 2 3 5 1 0 0 1 0 1 3 2 4 0 0 A,X X X 1 0 A,Y Z Y 1 0 A,Z Y X 0 0 4 3 1 1 1 A 0 A 1 B 0 B 1 A 0 A 1 B 0 B 1 B,X Z X 1 1 B,Y Y Y 0 1 5 2 2 0 1 X X X Z X 1 0 1 1 G1 Y Z Y Y Y 1 0 0 1 G2 Z Y X - - 0 0 - - Serial Decomposition • 1 = {(1,2,3),(4,5)} is the only S.P. partition. • We choose another partition 2={(1,4),(2,5),(3)} s.t. 1•2=0. • Let A=(1,2,3), B=(4,5), and X=(1,4),Y=(2,5),Z=(3), we can rebuild this machine as ENEE 644
0 1 1 1 2 2 4 3 3 5 2 4 1 2 5 1 3 Computation of the S.P. Partition • Recall that “A partition on set S of machine M=<I,S,,S0,O,> has the substitution property (S.P.) iff st() implies that (s,a)(t,a)() for all aI.” • So S.P. partition is independent of output. • If (1,2)(1,4),(2,3)(1,2,3,4) (transitivity){(1,2,3,4,5)} trivial. • If (1,3)(1,5)(1,3,5)(2,3)(1,2,3,5) (1,2,3,4,5) trivial. • If (1,4), form a block. • If (2,3) (4,5) (1,4,5) {(1,4,5),(2,3)} • If (2,5) (1,4) {(1,4),(2,5),(3)} • If (2) • if (3,5) (1,5),(2,3), contradiction. • If (3) {(1,4),(2),(3),(5)} • Another partition: {(1),((2,3),(4,5)} ENEE 644
Decomposition and State Encoding • We need two bits xy to encode a sequential state machine M with four states: A,B,C,D. • Suppose 1={(A,B), (C,D)} and 2={(A,C),(B,D)} are two non-trivial S.P. partitions. • Clearly 1•2=0 so we have a non-trivial parallel decomposition, M1={ab,cd} and M2={ac,bd}, both with only two states. • If we use bit x to encode M1 and bit y to encode M2 as ab=0, cd=1; and ac=0, bd=1. • Then M can be encoded as A=00,B=01,C=10,D=11. • SE problem becomes finding S.P. partitions and applying parallel/serial decompositions. ENEE 644