MMMMM 13
MMMMM 13
FSM Optimization
A. Sahu
Dept of Comp. Sc. & Engg.
Indian Institute of Technology Guwahati
http://jatinga.iitg.ac.in/~asahu/cs221/
1
Outline
• FSM Optimization: State Minimization
– Row Matching method
– Partitioning method
– Implication Chart
• FSM Optimization : State Encoding
– Binary/Sequential, Gray, One-hot
– Heuristic Based
Partitioning Methods
3
State Minimization: Partitioning
• Form an initial partition (P1) : that includes all the states.
• Form a 2nd partition (P2)
– By separating the states into two blocks based upon their output
values.
• Form a third partition (P3)
– by separating the states into blocks corresponding to the next
state values.
• Continue partitioning until
– Two successive partitions are the same (i.e. PN-1 = PN).
• All states in any one block are equivalent
– Equivalent states can be combined into a single state.
4
State Minimization: Previous Example
• Sequence Detector for 010 or 110
• After is asserted after each 3 bit input sequence if it consist
of 110 or 010
S0
0/0 1/0
S1 S2
0/0 1/0 0/0 1/0
S3 S4 S5 S6
1/0 1/0 1/0 1/0
0/0 0/1 0/0 0/1
State Minimization Example
Input PS NS OUTPUT
X=0 X=1 X=0 X=1
Reset S0 S1 S2 0 0 ( S0 S1 S2 S3 S4 S5 S6 )
0 S1 S3 S4 0 0
1 S2 S5 S6 0 0
00 S3 S0 S0 0 0
01 S4 S0 S0 1 0
10 S5 S0 S0 0 0
11 S6 S0 S0 1 0
State Minimization Example
Input PS NS OUTPUT
X=0 X=1 X=0 X=1
Reset S0 S1 S2 0 0 ( S0 S1 S2 S3 S4 S5 S6 )
0 S1 S3 S4 0 0
1 S2 S5 S6 0 0
00 S3 S0 S0 0 0
(S0 S1 S2 S3 S5) (S4 S6)
01 S4 S0 S0 1 0
10 S5 S0 S0 0 0
11 S6 S0 S0 1 0
State Minimization Example
Input PS NS OUTPUT
X=0 X=1 X=0 X=1
Reset S0 S1 S2 0 0 ( S0 S1 S2 S3 S4 S5 S6 )
0 S1 S3 S4 0 0
1 S2 S5 S6 0 0
00 S3 S0 S0 0 0 (S0 S1 S2 S3 S5) (S4 S6)
01 S4 S0 S0 1 0
10 S5 S0 S0 0 0
(S1 S2) (S0 S3 S5)
11 S6 S0 S0 1 0
(S0 S1 S2 S3 S5)
0 1
(S1 S3 S5 S0 S0) (S2 S4 S6 S0 S0)
State Minimization Example
Input PS NS OUTPUT
X=0 X=1 X=0 X=1
Reset S0 S1 S2 0 0
0 S1 S3 S4 0 0
( S0 S1 S2 S3 S4 S5 S6 )
1 S2 S5 S6 0 0
00 S3 S0 S0 0 0 (S0 S1 S2 S3 S5) (S4 S6)
01 S4 S0 S0 1 0
10 S5 S0 S0 0 0
11 S6 S0 S0 1 0 (S1 S2) (S0 S3 S5)
(S0 S3 S5)
0 1
(S1 S0 S0) (S2 S0 S0)
(S0) (S3 S5)
State Minimization Example
Input PS NS OUTPUT
X=0 X=1 X=0 X=1
Reset S0 S1 S2 0 0 ( S0 S1 S2 S3 S4 S5 S6 )
0 S1 S3 S4 0 0
1 S2 S5 S6 0 0
00 S3 S0 S0 0 0
(S0 S1 S2 S3 S5) (S4 S6)
01 S4 S0 S0 1 0
10 S5 S0 S0 0 0
(S1 S2) (S0 S3 S5)
11 S6 S0 S0 1 0
0/0 S1’
1/0
S3’ S4’
X/0 0/1 1/0
Row Matching Method : Fallacies
• Odd Parity Checker:
– Two alternative state diagrams
– Identical output behavior on all input strings
– FSMs are equivalent, but require different implementations
0 0
1 S0 [0]]
S0 [0] S1 [0] 0
1 1 1 1
Design state diagram
S1 [1] S2 [1] without concern for
# of states, Reduce
0 0 later 16
Partitioning Method
(S0S1S2)
Next State
Present State X=0 X=1 Output Based on output
(S0S2) (S1)
S0 S0 S1 0
S1 S1 S2 1
S2 S2 S1 0
Partitioning Methd
Next State
Present State X=0 X=1 Output
(S0S1S2)
S0 S0 S1 0
Based on output
S1 S1 S2 1
(S0S2) (S1)
S2 S2 S1 0
20
Sequence Detector Example
• Sequence Detector for 010 or 110
• After is asserted after each 3 bit input sequence if it consist of 110 or 010
S0
0/0 1/0
S1 S2
0/0 0/0
1/0 1/0
S3 S4 S5 S6
0/0 1/0 0/1 1/0 0/0 1/0 0/1 1/0
FSM :Tabular Form
Input PS NS OUTPUT
X=0 X=1 X=0 X=1
Reset S0 S1 S2 0 0
0 S1 S3 S4 0 0
1 S2 S5 S6 0 0
00 S3 S0 S0 0 0
01 S4 S0 S0 1 0
10 S5 S0 S0 0 0
11 S6 S0 S0 1 0 22
Implication Chart Method
Enumerate all possible combinations of states
taken two at a time
S0 S1
Next States
S1 S2
Under all S2 S3
Input S3 S4
Combinations S4 S5
S5 S6
S6 S0 S1 S2 S3 S4 S5
S0 S1 S2 S3 S4 S5 S6 Implication Chart
S4 Input PS NS OUTPUT
S1-S0 S3-S0 S5-S0 S0-S0 X=0 X=1 X=0 X=1
S5 S2-S0 S4-S0 S6-S0 S0-S0
S0-S0 Reset S0 S1 S2 0 0
S6 S0-S0
0 S1 S3 S4 0 0
S0 S1 S2 S3 S4 S5
1 S2 S5 S6 0 0
Starting Implication Chart
00 S3 S0 S0 0 0
01 S4 S0 S0 1 0
10 S5 S0 S0 0 0
28
11 S6 S0 S0 1 0
Implication Chart Method
S1-S3
S1 S2-S4
S1-S5 S3-S5
S2 and S4
S2 S2-S6 S4-S6 have
S3
S1-S0 S3-S0 S5-S0
S2-S0 S4-S0 S6-S0 different
I/O
S4
S1-S0 S3-S0 S5-S0 S0-S0
behavior
S5 S2-S0 S4-S0 S6-S0 S0-S0
S0-S0 This implies that
S6 S0-S0 S1 and S0 cannot
S0 S1 S2 S3 S4 S5 be combined
S4
S1-S0 S3-S0 S5-S0 S0-S0
S5 S2-S0 S4-S0 S6-S0 S0-S0
S6
S0-S0
S0-S0
This implies that
S1 and S0 cannot
S0 S1 S2 S3 S4 S5
be combined
S4
S1-S0 S3-S0 S5-S0 S0-S0
S5 S2-S0 S4-S0 S6-S0 S0-S0
S6
S0-S0
S0-S0
This implies that
S2 and S0 cannot
S0 S1 S2 S3 S4 S5
be combined
S4
S1-S0 S3-S0 S5-S0 S0-S0
S5 S2-S0 S4-S0 S6-S0 S0-S0
S0-S0
S6 S0-S0
S0 S1 S2 S3 S4 S5
33
Implication Chart Method
S1-S3
S1 S2-S4
S1-S5 S3-S5
S2 S2-S6 S4-S6 S1 S0 is already crossed
S1-S0 S3-S0 S5-S0
S3 S2-S0 S4-S0 S6-S0
So S3 S0
S4
S1-S0 S3-S0 S5-S0 S0-S0
S5 S2-S0 S4-S0 S6-S0 S0-S0
S0-S0
S6 S0-S0
S0 S1 S2 S3 S4 S5
34
Implication Chart Method
S1-S3
S1 S2-S4
S1-S5 S3-S5
S2 S2-S6 S4-S6 S4 S0 is already crossed
S1-S0 S3-S0 S5-S0
S3 S2-S0 S4-S0 S6-S0
So S3 S1
S4
S1-S0 S3-S0 S5-S0 S0-S0
S5 S2-S0 S4-S0 S6-S0 S0-S0
S0-S0
S6 S0-S0
S0 S1 S2 S3 S4 S5
35
Implication Chart Method
S1-S3
S1 S2-S4
S1-S5 S3-S5
S2 S2-S6 S4-S6 S6 S0 is already crossed
S1-S0 S3-S0 S5-S0
S3 S2-S0 S4-S0 S6-S0
So S3 S2
S4
S1-S0 S3-S0 S5-S0 S0-S0
S5 S2-S0 S4-S0 S6-S0 S0-S0
S0-S0
S6 S0-S0
S0 S1 S2 S3 S4 S5
36
Implication Chart Method
S1-S3
S1 S2-S4
S1-S5 S3-S5
S2 S2-S6 S4-S6 S2 S0 is already crossed
S1-S0 S3-S0 S5-S0
S3 S2-S0 S4-S0 S6-S0
So S5 S0
S4
S1-S0 S3-S0 S5-S0 S0-S0
S5 S2-S0 S4-S0 S6-S0 S0-S0
S0-S0
S6 S0-S0
S0 S1 S2 S3 S4 S5
37
Implication Chart Method
S1-S3
S1 S2-S4
S1-S5 S3-S5
S2 S2-S6 S4-S6 Similarly..
S1-S0 S3-S0 S5-S0
S3 S2-S0 S4-S0 S6-S0
S4
S1-S0 S3-S0 S5-S0 S0-S0
S5 S2-S0 S4-S0 S6-S0 S0-S0
S0-S0
S6 S0-S0
S0 S1 S2 S3 S4 S5
S4
S1-S0 S3-S0 S5-S0 S0-S0
S5 S2-S0 S4-S0 S6-S0 S0-S0
S0-S0
S6 S0-S0
S0 S1 S2 S3 S4 S5
Second Pass Adds No New Information
39
Implication Chart Method
S1-S3
S1 S2-S4
S1-S5 S3-S5
S3 and S5 are equivalent
S2 S2-S6 S4-S6 S4 and S6 are equivalent
S3
S1-S0 S3-S0 S5-S0 S1 and S2 are equivalent
S2-S0 S4-S0 S6-S0
S4
S1-S0 S3-S0 S5-S0 S0-S0
S5 S2-S0 S4-S0 S6-S0 S0-S0
S0-S0
S6 S0-S0
S0 S1 S2 S3 S4 S5
X/0
S1’ 1/0
0/0
S3’ S4’
0/1 1/0
X/0
Outline
• FSM Optimization: State Minimization
– Row Matching method
– Partitioning method
– Implication Chart
• FSM Optimization : State Encoding
– Binary/Sequential, Gray, One-hot
– Heuristic Based
State Encoding/Assignment
44
State assignment
• State encoding:
– Assigning unique binary value to each state
– So that we can implement FSM
• Since we don’t care about the actual flip-flop
values for each state
• We can assign each state to any binary number
we like as long as
– Each state is assigned a unique binary number
Example of FSM: 3 cycle Laser
• Require 4 States
• Assigning unique binary value/code to each state
• Options available : 4!
Outputs: x
x=0 clk ^ x=1 clk ^ x=1 clk ^ x=1
Off On1 On2 On3
clk ^
46
State Encoding Example
• Four states SL S0 S1 S2 S3 SL S0 S1 S2 S3
1 00 01 10 11 13 10 01 00 11
S0, S1, S2, S3 2 00 01 11 10 14 10 01 11 00
• 4! options 3
4
00
00
10
10
01
11
11
01
15
16
10
10
00
00
01
11
11
01
5 00 11 01 10 17 10 11 01 00
6 00 11 10 01 18 10 11 00 01
7 01 00 11 10 19 11 00 01 10
8 01 00 10 11 20 11 00 10 01
9 01 10 11 00 21 11 10 01 00
10 01 10 00 11 22 11 10 00 01
11 01 11 10 00 23 11 01 10 00
47
State assignment
• Since we don’t care about the actual flip-flop values for each
state we can assign each state to any binary number we like as
long as each state is assigned a unique binary number
• Suppose a FSM have 6 states: Modulo 6 Counter
• If we use 3 bits to encode the 6 states, we have
8 8!
6
6!(8 6)!
possible choosing the 6 states from 8 total state
– Than encodings
State Encoding
• The cost & delay of FSM implementation depends
on encoding of symbolic states.
– e.g., 4 states can be encoded in 4! = 24 different ways
• There are more than n! different encodings for n
states.
– Exploration of all encodings is impossible, therefore
heuristics are used
• Heuristics Used
– One-hot encoding, Minimum-bit change, Prioritized
adjacency
49
State assignment
state Encoding 1 Encoding 2 Encoding 3
(binary) (Gray)
51
One-hot encoding
• One flip-flop per state encoding
• Leads to greater number of flip-flops than
binary encoding but possibly to simpler
logic
State Assignment Problem
Some state assignments are better than others.
The state assignment influences the complexity of the
state machine.
The combinational logic required in the state machine
design is dependent on the state assignment.
Types of state assignment
Binary encoding: 2N states → N Flip-Flops
Gray-code encoding: 2N states → N Flip-Flops
One-hot encoding: N states → N Flip-Flops
53
FSM: State Assignment
Example
54
FSM: State Assignment
Input: 011101011011101…
Output: 001100001001100…
55
FSM: State Assignment
Reset w=1
w=0 w=1
S2/1
State Diagram
w=1
56
FSM: State Assignment
Present Next State Output
State
w=0 w=1
S0 S0 S1 0
S1 S0 S2 0
S2 S0 S2 1
State Table
57
FSM: State Assignment #1
State Assigned Table
Present State Next State Output
w=0 w=1
QA QB QA+ QB+ Q A+ QB+ z
S0 0 0 S0 0 0 S1 0 1 0
S1 0 1 S0 0 0 S2 1 0 0
S2 1 0 S0 0 0 S2 1 0 1
1 1 d d d d d
DB=wQ’AQB’
Using Binary Encoding DA=w(QA+QB)
for the State Assignment 58
FSM: State Assignment #2
State Assigned Table
Present State Next State Output
w=0 w=1
QA QB QA+ QB+ QA+ QB+ z
S0 0 0 S0 0 0 S1 0 1 0
S1 0 1 S0 0 0 S2 1 1 0
S2 1 1 S0 0 0 S2 1 1 1
1 0 d d d d d
DA=w.QB
Using Gray-code Encoding DB=W
for the State Assignment Z=QA 59
FSM: State Assignment #3
State Assigned Table
Present State Next State
w=0 w=1
QA QB QC QA+ QB+ QC+ QA+ QB+ QC+
S0 0 0 1 S0 0 0 1 S1 0 1 0
S1 0 1 0 S0 0 0 1 S2 1 0 0
S2 1 0 0 S0 0 0 1 S2 1 0 0
Using One-hot Encoding DA=w.Qc’
for the State Assignment
For each state only one flip-flop is set to 1.
DB=w.QC
D =w’ 60
State Encoding
# Binary Gray Johnson One-hot
62
Thanks
63