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: Number of literals Speed Testability ENEE 644 2 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. x 0 0 CS NS A C B C O 1 1 x 0 0 y1y2 Y1Y2 O 1 1 01 10 11 11 Assignment 1: A=01, B=10, C=11 Y1=…+x’y1’y2+…+x’y1y2’+… x y1y2 Y1Y2 O Y2=…+x’y1’y2+…+x’y1y2’+… 0 00 11 1 O=…+x’y1’y2+…+x’y1y2’+… 0 10 11 1 Assignment 2: A=00, B=10, C=11 Y1=…+x’y1’y2’+…+x’y1y2’+…=…+x’y2’+… ENEE 644 3 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 x a b CS NS A B A C O 1 1 Identify pairs that should receive adjacent codes. ENEE 644 4 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 5 Fanout-Oriented Algorithm State Transition Matrix S|s|x|s|: 0/0 Row: one per (current) state Column: one per (next) state Entry: (non-negative) number of arcs going from state si A 1/1 1/1 (row) to state sj (column) C Output Matrix Z|s|x|O|: 1/0 1 1 0 1 0 1 1 0 1 (row) with output zj (column) Let Nb be the number of encoding bits, then the 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 A 2 3 C B 0/0 Row: one per (current) state Column: one per output Entry: (non-negative) number of arcs going out of state si attraction between states si and sj is given by Nb•Si•SjT+Zi•ZjT 0/0 4 B 1 0 1 6 Fanin-Oriented Algorithm ^ State Transition Matrix S |s|x|s|: 0/0 Row: one per (next) state Column: one per (current) state Entry: (non-negative) number of arcs going from state sj A 1/1 1/1 (column) to state si (row) C Input Matrix X|s|x|I|: 1/0 1 1 1 1 0 0 0 1 1 (row) with input xj (column) Let Nb be the number of encoding bits, then the attraction between states si and sj is given ^ •S ^ T+X •X T by Nb•S i j i j ENEE 644 B 0/0 Row: one per (current) state Column: |I| per input Entry: (non-negative) number of arcs entering state si 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 0/0 A 3 7 C 1 B 2 1 0 1 1 1 7 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 8 Example: The Encoding Algorithm 0/0 A 1/1 1/1 C Fanout-Oriented Algorithm: 0/0 1/0 B 0/0 Fanin-Oriented Algorithm: 01 A A 2 3 C 4 00 B 2 3 C 00 A 4 3 7 B C 10 Y1=y1’y2x Y2=y1’y2x + y1y2’x’ + y1’y2’x Z = y1’x (13 literals) A 1 B 3 7 C 10 1 B 01 Y1=y1’y2x’ + y1’y2x Y2=y1’y2’x Z = y2’x (11 literals) ENEE 644 9 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 10 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 11 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 nontrivial 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 nontrivial S.P. partition, then it has a non-trivial serial decomposition. ENEE 644 12 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. 0 3 5 4 1 0 2 0 1 2 3 4 5 0 1 A B A 0 B A B 1 1 2 2 1 4 3 3 X Y Z 0 0 0 1 0 0 0 Z X Y 1 Z Z Y 0 0 1 G1 G2 ENEE 644 13 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 A 0 A 1 B 0 B 1 A 0 A 1 B 0 B 1 X X X Z X 1 0 1 1 Y Z Y Y Y 1 0 0 1 Z Y X - - 0 0 - - 1 2 3 4 5 A,X A,Y A,Z B,X B,Y 0 1 3 2 3 2 1 4 5 4 1 2 0 1 1 0 1 0 1 0 0 0 1 1 0 X Z Y Z Y 1 X Y X X Y 0 1 1 0 1 0 1 0 0 0 1 1 G1 G2 ENEE 644 14 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. 0 1 1 1 2 2 4 3 3 5 2 4 1 2 5 1 3 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 15 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 16