Download presentation
Presentation is loading. Please wait.
1
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 1 Sequential Logic Optimization zState Minimization yAlgorithms for State Minimization zState, Input, and Output Encodings yMinimize the Next State and Output logic
2
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 2 Optimization in Context zUnderstand the word specification zDraw a picture zDerive a state diagram and Symbolic State Table zDetermine an implementation approach (e.g., gate logic, ROM, FPGA, etc.) zPerform STATE MINIMIZATION zPerform STATE ASSIGNMENT zMap Symbolic State Table to Encoded State Tables for implementation (INPUT and OUTPUT encodings)
3
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 3 Finite State Machine Optimization zState Minimization yFewer states require fewer state bits yFewer bits require fewer logic equations xIn general, one equation per output bit BUT xWhat counts are literals, not numbers of equations zEncodings: State, Inputs, Outputs yState encoding with fewer bits has fewer equations to implement xHowever, each may be more complex yState encoding with more bits (e.g., one-hot) has simpler equations xComplexity directly related to complexity of state diagram yInput/output encoding may or may not be under designer control
4
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 4 Input Next State Output SequencePresent StateX=0X=1X=0X=1 ResetS0S1S200 0S1S3S400 1S2S5S600 00S3S0S000 01S4S0S010 10S5S0S000 11S6S0S010 State Minimization Example zSequence Detector for 010 or 110 S0 S3 S2S1 S5S6S4 1/00/0 1/0 0/1 0/01/00/0 1/0 0/0 1/0 0/1 1/0 0/0 These two states must be identical – why?
5
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 5 Input Next State Output SequencePresent StateX=0X=1X=0X=1 ResetS0S1S200 0S1S3S400 1S2S5S600 00S3S0S000 01S4S0S010 10S5S0S000 11S6S0S010 State Minimization Example zSequence Detector for 010 or 110 S0 S3 S2S1 S5S6S4 1/00/0 1/0 0/1 0/01/00/0 1/0 0/0 1/0 0/1 1/0 0/0 States S3, S5 are identical because can’t detect from here, next step is always S0 States S4, S6 are identical because they detect on 0, next step is always S0
6
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 6 Input Next State Output SequencePresent StateX=0X=1X=0X=1 ResetS0S1S200 0S1S3/5S4/600 1S2S3/5S4/600 00/11S3/5S0S000 01/10S4/6S0S010 State Minimization Example zSequence Detector for 010 or 110 S0 S3/5 S2S1 S4/6 1/00/0 1/00/0 1/0 0/0 1/0 0/1 1/0 0/0 These states are identical – why?
7
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 7 Input Next State Output SequencePresent StateX=0X=1X=0X=1 ResetS0S1/2S1/200 0/1S1/2S3/5S4/600 00/11S3/5S0S000 01/10S4/6S0S010 State Minimization Example zSequence Detector for 010 or 110 S0 S3/5 S1/2 S4/6 0,1/0 1/0 0/0 1/0 0/1 1/0 0/0
8
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 8 Algorithmic Approach to State Minimization zGoal – identify and combine states that have equivalent behavior zEquivalent States: ySame output yFor all input combinations, states transition to same or equivalent states zAlgorithm Sketch y1. Place all states in one set y2. Initially partition set based on output behavior y3. Successively partition resulting subsets based on next state transitions y4. Repeat (3) until no further partitioning is required xstates left in the same set are equivalent yPolynomial time procedure (in size of state set)
9
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 9 Input Next State Output SequencePresent StateX=0X=1X=0X=1 ResetS0S1S200 0S1S3S400 1S2S5S600 00S3S0S000 01S4S0S010 10S5S0S000 11S6S0S010 State Minimization Example zSequence Detector for 010 or 110 S0 S3 S2S1 S5S6S4 1/00/0 1/0 0/1 0/01/00/0 1/0 0/0 1/0 0/1 1/0 0/0
10
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 10 ( S0 S1 S2 S3 S4 S5 S6 ) ( S0 S1 S2 S3 S5 ) ( S4 S6 ) ( S0 S3 S5 ) ( S1 S2 ) ( S4 S6 ) ( S0 ) ( S1 S2 ) ( S3 S5 ) ( S4 S6 ) Input Next State Output SequencePresent StateX=0X=1X=0X=1 ResetS0S1S200 0S1S3S400 1S2S5S600 00S3S0S000 01S4S0S010 10S5S0S000 11S6S0S010 S1 is equivalent to S2 S3 is equivalent to S5 S4 is equivalent to S6 Method of Successive Partitions
11
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 11 Input Next State Output SequencePresent StateX=0X=1X=0X=1 ResetS0S1'S1'00 0 + 1S1'S3'S4'00 X0S3'S0S000 X1S4'S0S010 Minimized FSM zState minimized sequence detector for 010 or 110 S0 S1’ S3’ S4’ X/0 1/0 0/1 0/0 X/0 7 States reduced to 4 States 3 bit encoding replaced by 2 bit encoding
12
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 12 Another Example z4-Bit Sequence Detector: output 1 after each 4-bit input sequence consisting of the binary strings 0110 or 1010
13
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 13 State Transition Table zGroup states with same next state and same outputs S’ 10
14
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 14 Iterate the Row Matching Algorithm S’ 7
15
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 15 Iterate One Last Time S’ 3 S’ 4
16
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 16 Final Reduced State Machine 15 states (min 4 FFs) reduced to 7 states (min 3 FFs)
17
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 17 symbolic state transition table present next state output state00011011 S0S0S1S2S31 S1S0S3S1S40 S2S1S3S2S41 S3S1S0S4S50 S4S0S1S2S51 S5S1S4S0S50 inputs here More Complex State Minimization zMultiple input example 10 01 11 00 01 11 10 01 11 00 10 00 11 00 11 10 01 10 11 01 00 S0 [1] S2 [1] S4 [1] S1 [0] S3 [0] S5 [0] 01
18
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 18 S0-S1 S1-S3 S2-S2 S3-S4 S0-S0 S1-S1 S2-S2 S3-S5 S0-S1 S3-S0 S1-S4 S4-S5 S0-S1 S3-S4 S1-S0 S4-S5 S1-S0 S3-S1 S2-S2 S4-S5 S4-S0 S5-S5 S1-S1 S0-S4 minimized state table (S0==S4) (S3==S5) present next state output state00011011 S0'S0'S1S2S3'1 S1S0'S3'S1S3'0 S2S1S3'S2S0'1 S3'S1S0'S0'S3'0 Minimized FSM zImplication Chart Method yCross out incompatible states based on outputs yThen cross out more cells if indexed chart entries are already crossed out S1 S2 S3 S4 S5 S0S1S2S3S4 present next state output state00011011 S0S0S1S2S31 S1S0S3S1S40 S2S1S3S2S41 S3S1S0S4S50 S4S0S1S2S51 S5S1S4S0S50
19
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 19 “Polynomial” Algorithm zn (n+1)/2 squares for n states zAt each iteration, must cross off at least one square, or done ≤ n(n+1)/2 iterations at most zFilling out a square takes O(num input combinations) Total Running time is O(n 2 * num input combinations) z“Polynomial”?...well yRepresentation of finite state machine is often log number of states x log number of input combinations yConsider a counter zAlgorithm is exponential in this representation
20
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 20 Minimizing Incompletely Specified FSMs zEquivalence of states is transitive when machine is fully specified zBut its not transitive when don't cares are present e.g.,stateoutput S0– 0S1 is compatible with both S0 and S2 S11 –but S0 and S2 are incompatible S2– 1 disagree in output 2 zNo polynomial time algorithm exists for determining best grouping of states into equivalent sets that will yield the smallest number of final states
21
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 21 XQ1Q0Q1+Q0+000000010001100100011011111111–1000XQ1Q0Q1+Q0+000000010001100100011011111111–1000 Q 1 + = X (Q 1 xor Q 0 ) Q 0 + = X Q 1 ’ Q 0 ’ Minimizing States May Not Yield Best Circuit zExample: edge detector - outputs 1 when last two input changes from 0 to 1 00 [0] 11 [0] 01 [1] X’ X X X
22
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 22 XQ1Q0Q1+Q0+000000010001100100011011111111–1000XQ1Q0Q1+Q0+000000010001100100011011111111–1000 Q 1 + = X (Q 1 xor Q 0 ) Q 0 + = X Q 1 ’ Q 0 ’ Edge Detector Implementation 00 [0] 11 [0] 01 [1] X’ X X X
23
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 23 Another Implementation of Edge Detector z"Ad hoc" solution - not minimal but cheap and fast 00 [0] 10 [0] 01 [1] X’X X X X 11 [0] X’
24
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 24 State Assignment zChoose bit vectors to assign to each “symbolic” state yWith n state bits for m states there are 2 n ! / (2 n – m)! [log n <= m <= 2 n ] y2 n codes possible for 1st state, 2 n –1 for 2nd, 2 n –2 for 3rd, … yHuge number even for small values of n and m xIntractable for state machines of any size xHeuristics are necessary for practical solutions yOptimize some metric for the combinational logic xSize (amount of logic and number of FFs) xSpeed (depth of logic and fanout) xDependencies (decomposition)
25
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 25 Key Idea Behind State Assignment zGoal is to minimize the logic realizing a state machine yBut we can’t generate logic and optimize (takes too long) yNeed to get a good proxy for logic complexity zKey insight: If state bits don’t change, don’t need logic yHow many bit changes in one-hot? zOne-hot encoding yOne AND gate per incoming edge to state yOne OR gate per state yLogic is cheap, but far too many bits (one per state!) zTherefore: minimize bit changes subject to number- of-state-bits constraint
26
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 26 Note minimize-changes heuristic doesn’t always work! zConsider a counter zCan get n bit changes (consider counting from -1 to 0) yLogic is very small zBut is generally a good proxy yKey: minimizing number of bit changes (usually) minimizes Karnaugh maps
27
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 27 State Assignment Strategies zPossible Strategies ySequential – just number states as they appear in the state table yRandom – pick random codes yOne-hot – use as many state bits as there are states (bit=1 –> state) yOutput – use outputs to help encode states yHeuristic – rules of thumb that seem to work in most cases zNo guarantee of optimality – another intractable problem
28
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 28 One-hot State Assignment zSimple yEasy to encode, debug zSmall Logic Functions yEach state function requires only predecessor state bits as input zGood for Programmable Devices yLots of flip-flops readily available ySimple functions with small support (signals its dependent upon) zImpractical for Large Machines yToo many states require too many flip-flops yDecompose FSMs into smaller pieces that can be one-hot encoded zMany Slight Variations to One-hot yOne-hot + all-0
29
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 29 State Maps and Counting Bit Changes Bit Change Heuristic S0S0 S1S1 S2S2 S3S3 S4S4 01 S0 -> S1: 2 1 S0 -> S2: 3 1 S1 -> S3: 3 1 S2 -> S3: 2 1 S3 -> S4: 1 1 S4 -> S1: 2 2 Total: 13 7
30
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 30 Equations for Each Assignment S0S0 S1S1 S2S2 S3S3 S4S4 01 State Equations: S 1 + = S 0 X’ + S 4 S 2 + = S 0 X, S 3 + =S 1 + S 2, S 4 + = S 3 Q 2 = S 1 + S 2 Q 1 = S 4 + S 2 + S 3 Q 0 = S 4 + S 2 + S 1 Assignment One: S0000 S1101 S2111 S3010 S4011 Q 2 = S 0 X’ + S 4 + S 0 X Q 1 = S 3 + S 2 + S 1 + S 0 X Q 0 = S 3 + S 0 X’ + S 4 + S 0 X Q 2 = Q 2 ’Q 1 ’Q 0 ’ + Q 2 ’Q 1 Q 0 Q 1 = Q 2 ’Q 1 Q 0 ’ + Q 2 Q 1 Q 0 + Q 2 Q 1 ’Q 0 + Q 2 ’Q 1 ’Q 0 ’ X Q 0 = Q 2 ’Q 1 Q 0 ’ + Q 2 ’Q 1 ’Q 0 ’ + Q 2 ’Q 1 Q 0
31
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 31 Karnaugh Maps 1 11 11 11 00011110 00 01 11 10 Q1Q0Q1Q0 XQ 2 Q1Q1 111 00011110 0 1 Q1Q0Q1Q0 Q2Q2 Q0Q0 11 00011110 0 1 Q1Q0Q1Q0 Q2Q2 Q2Q2 Q 2 = Q 2 ’Q 1 ’Q 0 ’ + Q 2 ’Q 1 Q 0 Q 1 = Q 2 ’Q 1 Q 0 ’ + Q 2 Q 1 Q 0 + Q 2 Q 1 ’Q 0 + Q 2 ’Q 1 ’Q 0 ’ X Q 0 = Q 2 ’Q 1 Q 0 ’ + Q 2 ’Q 1 ’Q 0 ’ + Q 2 ’Q 1 Q 0
32
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 32 Equations for Each Assignment S0S0 S1S1 S2S2 S3S3 S4S4 01 State Equations: S 1 + = S 0 X’ + S 4 S 2 + = S 0 X, S 3 + =S 1 + S 2, S 4 + = S 3 Q 2 = S 4 Q 1 = S 4 + S 2 + S 3 Q 0 = S 4 + S 3 + S 1 Assignment Two: S0000 S1001 S2010 S3011 S4111 Q 2 = S 3 Q 1 = S 3 + S 2 + S 1 + S 0 X Q 0 = S 3 + S 2 + S 1 + S 4 + S 0 X Q 2 = Q 2 ’Q 1 Q 0 Q 1 = Q 2 ’Q 1 Q 0 + Q 2 ‘Q 1 Q 0 ’ + Q 2 ’Q 1 ’Q 0 + Q 2 ’Q 1 ’Q 0 ’ X Q 0 = Q 2 ’Q 1 Q 0 + Q 2 ’Q 1 Q 0 ’ + Q 2 ’Q 1 ’Q 0 + Q 2 Q 1 Q 0 + Q 2 ’Q 1 ’Q 0 ’ X
33
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 33 Karnaugh Maps 111 1111 00011110 00 01 11 10 Q1Q0Q1Q0 XQ 2 Q1Q1 1 00011110 0 1 Q1Q0Q1Q0 Q2Q2 Q2Q2 Q 2 = Q 2 ’Q 1 Q 0 Q 1 = Q 2 ’Q 1 Q 0 + Q 2 ‘Q 1 Q 0 ’ + Q 2 ’Q 1 ’Q 0 + Q 2 ’Q 1 ’Q 0 ’ X Q 0 = Q 2 ’Q 1 Q 0 + Q 2 ’Q 1 Q 0 ’ + Q 2 ’Q 1 ’Q 0 + Q 2 Q 1 Q 0 + Q 2 ’Q 1 ’Q 0 ’ X 111 1 1 1111 00011110 00 01 11 10 Q1Q0Q1Q0 XQ 2 Q0Q0
34
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 34 IQQ+OiacjibckIQQ+Oiacjibck IQQ+OiabjkaclIQQ+Oiabjkacl IQQ+OiabjicdjIQQ+Oiabjicdj c = i * a + i * b b = i * a c = k * a j = i * a + i * c b = i * a d = i * c i / j i / k a b c a bc i / j k / l bd i / j a c Adjacency Heuristics for State Assignment zAdjacent codes to states that share a common next state yGroup 1's in next state map zAdjacent codes to states that share a common ancestor state yGroup 1's in next state map zAdjacent codes to states that have a common output behavior yGroup 1's in output map
35
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 35 Heuristics for State Assignment Successor/Predecessor Heuristics z High Priority: S’ 3 and S’ 4 share common successor state (S 0 ) z Medium Priority: S’ 3 and S’ 4 share common predecessor state (S’ 1 ) z Low Priority: y0/0: S 0, S’ 1, S’ 3 y1/0: S 0, S’ 1, S’ 3, S’ 4
36
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 36 Heuristics for State Assignment
37
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 37 Another Example High Priority: S’ 3, S’ 4 S’ 7, S’ 10 Medium Priority: S 1, S 2 2 x S’ 3, S’ 4 S’ 7, S’ 10 Low Priority: 0/0: S 0, S 1, S 2, S’ 3, S’ 4, S’ 7 1/0: S 0, S 1, S 2, S’ 3, S’ 4, S’ 7, S 10
38
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 38 Example Continued z Choose assignment for S0 = 000 z Place the high priority adjacency state pairs into the State Map z Repeat for the medium adjacency pairs z Repeat for any left over states, using the low priority scheme Two alternative assignments at the left
39
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 39 Why Do These Heuristics Work? zAttempt to maximize adjacent groupings of 1’s in the next state and output functions
40
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 40 General Approach to Heuristic State Assignment zAll current methods are variants of this y1) Determine which states “attract” each other (weighted pairs) y2) Generate constraints on codes (which should be in same cube) y3) Place codes on Boolean cube so as to maximize constraints satisfied (weighted sum) zDifferent weights make sense depending on whether we are optimizing for two-level or multi-level forms zCan't consider all possible embeddings of state clusters in Boolean cube yHeuristics for ordering embedding yTo prune search for best embedding yExpand cube (more state bits) to satisfy more constraints
41
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 41 Output-Based Encoding zReuse outputs as state bits - use outputs to help distinguish states yWhy create new functions for state bits when output can serve as well yFits in nicely with synchronous Mealy implementations HG = ST’ H1’ H0’ F1 F0’ + ST H1 H0’ F1’ F0 HY = ST H1’ H0’ F1 F0’ + ST’ H1’ H0 F1 F0’ FG = ST H1’ H0 F1 F0’ + ST’ H1 H0’ F1’ F0’ HY = ST H1 H0’ F1’ F0’ + ST’ H1 H0’ F1’ F0 Output patterns are unique to states, we do not need ANY state bits – implement 5 functions (one for each output) instead of 7 (outputs plus 2 state bits) InputsPresent StateNext StateOutputs CTLTSSTHF 0––HGHG00010 –0–HGHG00010 11–HGHY10010 ––0HYHY00110 ––1HYFG10110 10–FGFG010 00 0––FGFY110 00 –1–FGFY110 00 ––0FYFY010 01 ––1FYHG110 01
42
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 42 Current State Assignment Approaches zFor tight encodings using close to the minimum number of state bits yBest of 10 random seems to be adequate (averages as well as heuristics) yHeuristic approaches are not even close to optimality yUsed in custom chip design zOne-hot encoding yEasy for small state machines yGenerates small equations with easy to estimate complexity yCommon in FPGAs and other programmable logic zOutput-based encoding yAd hoc - no tools yMost common approach taken by human designers yYields very small circuits for most FSMs
43
CS 150 - Spring 2008 – Lec #24: Seq Logic Optimization - 43 Sequential Logic Implementation Summary zImplementation of sequential logic yState minimization yState assignment zImplications for programmable logic devices yWhen logic is expensive and FFs are scarce, optimization is highly desirable (e.g., gate logic, PLAs, etc.) yIn Xilinx devices, logic is bountiful (4 and 5 variable TTs) and FFs are many (2 per CLB), so optimization is not so crucial an issue as in other forms of programmable logic yThis makes sparse encodings like One-Hot worth considering
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.