• 沒有找到結果。

Chapter #9: Finite State Machine Optimization

N/A
N/A
Protected

Academic year: 2022

Share "Chapter #9: Finite State Machine Optimization"

Copied!
34
0
0

加載中.... (立即查看全文)

全文

(1)

Chapter #9: Finite State Machine Optimization

Contemporary Logic Design

Randy H. Katz

University of California, Berkeley

July 1993

(2)

• Procedures for optimizing implementation of an FSM State Reduction

State Assignment

(3)

(1) Understand the problem (2) Obtain a formal description (3) Minimize number of states (4) Encode the states

(5) Choose FFs to implement state register (6) Implement the FSM

This Chapter!

Next Chapter

(4)

Odd Parity Checker: two alternative state diagrams • Identical output behavior on all input strings

• FSMs are equivalent, but require different implementations • Design state diagram without concern for # of states,

Reduce later

0

S0 [0]

S1

[1] S2

[0]

1 S0

[0]

S1 [1]

0

1

1

0 0

0 1 1

(5)

Implement FSM with fewest possible states • Least number of flipflops

• Boundaries are power of two number of states

• Fewest states usually leads to more opportunities for don't cares • Reduce the number of gates needed for implementation

(6)

Identify and combine states that have equivalent behavior

Equivalent States: for all input combinations, states transition to the same or equivalent states

Odd Parity Checker: S0, S2 are equivalent states Both output a 0

Both transition to S1 on a 1 and self-loop on a 0

Algorithmic Approach

• Start with state transition table

• Identify states with same output behavior

• If such states transition to the same next state, they are equivalent

• Combine into a single new renamed state

• Repeat until no new states are combined

(7)

Example FSM Specification:

Single input X, output Z

Taking inputs grouped four at a time, output 1 if last four inputs were the string 1010 or 0110

Example I/O Behavior:

X = 0010 0110 1100 1010 0011 . . . Z = 0000 0001 0000 0001 0000 . . .

Upper bound on FSM complexity:

Fifteen states (1 + 2 + 4 + 8)

Thirty transitions (2 + 4 + 8 + 16)

sufficient to recognize any binary string of length four!

(8)

State Diagram for Example FSM:

Reset

0/0 1/0

0/0 1/0 0/0 1/0

0/0 1/0 0/0 1/0 0/0 1/0 0/0 1/0

0/0 1/0 0/0 0/0

1/0 1/0 0/0

1/0

1/0

0/1

0/0 1/0

1/0 0/0 1/0 0/1

(9)

Initial State Transition Table:

Present State S

0

S

1

S

2

S

3

S

4

S

5

S

6

S

7

S

8

S

9

S

10

S

1 1

S

12

S

13

S

14

Input Sequence

Reset 0 1 00 01 10 1 1 000 001 010 01 1 100 101 1 10 1 1 1

X =1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 X =0

S

1

S

3

S

5

S

7

S

9

S

1 1

S

13

S

0

S

0

S

0

S

0

S

0

S

0

S

0

S

0

X =1 S

2

S

4

S

6

S

8

S

10

S

12

S

14

S

0

S

0

S

0

S

0

S

0

S

0

S

0

S

0

X =0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0

Next State Output

(10)

Initial State Transition Table:

Present State S

0

S

1

S

2

S

3

S

4

S

5

S

6

S

7

S

8

S

9

S

10

S

1 1

S

12

S

13

S

14

Input Sequence

Reset 0 1 00 01 10 1 1 000 001 010 01 1 100 101 1 10 1 1 1

X =1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 X =0

S

1

S

3

S

5

S

7

S

9

S

1 1

S

13

S

0

S

0

S

0

S

0

S

0

S

0

S

0

S

0

X =1 S

2

S

4

S

6

S

8

S

10

S

12

S

14

S

0

S

0

S

0

S

0

S

0

S

0

S

0

S

0

X =0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0

Next State Output

(11)

Present State S

0

S

1

S

2

S

3

S

4

S

5

S

6

S

7

S

8

S

9

S '

10

S

1 1

S

13

S

14

Input Sequence

Reset 0 1 00 01 10 1 1 000 001 010 01 1 or 101 100 1 10 1 1 1

Next State X =0 X =1

S

1

S

3

S

5

S

7

S

9

S

1 1

S

13

S

0

S

0

S

0

S

0

S

0

S

0

S

0

S

2

S

4

S

6

S

8

S '

10

S '

10

S

14

S

0

S

0

S

0

S

0

S

0

S

0

S

0

X =0 0 0 0 0 0 0 0 0 0 0 1 0 0 0

X =1

0

0

0

0

0

0

0

0

0

0

0

0

0

0

Output

(12)

Present State S

0

S

1

S

2

S

3

S

4

S

5

S

6

S

7

S

8

S

9

S '

10

S

1 1

S

13

S

14

Input Sequence

Reset 0 1 00 01 10 1 1 000 001 010 01 1 or 101 100 1 10 1 1 1

Next State X =0 X =1

S

1

S

3

S

5

S

7

S

9

S

1 1

S

13

S

0

S

0

S

0

S

0

S

0

S

0

S

0

S

2

S

4

S

6

S

8

S '

10

S '

10

S

14

S

0

S

0

S

0

S

0

S

0

S

0

S

0

X =0 0 0 0 0 0 0 0 0 0 0 1 0 0 0

X =1

0

0

0

0

0

0

0

0

0

0

0

0

0

0

Output

(13)

Present State S

0

S

1

S

2

S

3

S

4

S

5

S

6

S

7

'

S '

10

Input Sequence

Reset 0 1 00 01 10 1 1 not (01 1 or 101) 01 1 or 101

X =0 S

1

S

3

S

5

S

0

S

0

X =1 S

2

S

4

S

6

S

0

S

0

X =0 0 0 0 0 0 0 0 0 1

X =1 0 0 0 0 0 0 0 0 0 Next State Output

S

7

' S

7

' S

7

' S

7

'

S

7

'

S '

10

S '

10

S

7

'

(14)

Present State S

0

S

1

S

2

S

3

S

4

S

5

S

6

S

7

'

S '

10

Input Sequence

Reset 0 1 00 01 10 1 1 not (01 1 or 101) 01 1 or 101

X =0 S

1

S

3

S

5

S

0

S

0

X =1 S

2

S

4

S

6

S

0

S

0

X =0 0 0 0 0 0 0 0 0 1

X =1 0 0 0 0 0 0 0 0 0 Next State Output

S

7

' S

7

' S

7

' S

7

'

S

7

'

S '

10

S '

10

S

7

'

(15)

Final Reduced State Transition Table

Final Reduced State Transition Table

Corresponding State Diagram

Corresponding State Diagram

Input Sequence Reset 0 1 00 or 11 01 or 10 not (011 or 101) 011 or 101

Present State S0

S1 S2 S3' S4' S7' S10'

X=0 S1 S3' S4' S7' S7' S0 S0

X=1 S2 S4' S3' S7' S10'

S0 S0

X=0 0 0 0 0 0 0 1

X=1 0 0 0 0 0 0 0

Reset

S1

S3'

S7'

S2

S4'

S10' 0,1/0

0,1/0 0/0

0/0

1/0 1/0 1/0

1/0

0/1 1/0 S0

0/0

0/0

(16)

• Straightforward to understand and easy to implement

• Problem: does not allows yield the most reduced state table!

Example: 3 State Odd Parity Checker

No way to combine states S0 and S2 based on Next State Criterion!

No way to combine states S0 and S2 based on Next State Criterion!

Present State S 0

S 1 S 2

Next State X =0

S 0 S 1 S 2

X =1 S 1 S 2 S 1

Output 0 1 0

(17)

New example FSM:

Single input X, Single output Z

Output a 1 whenever the serial sequence 010 or 110 has been observed at the inputs

State transition table:

Present State S

0

S

1

S

2

S

3

S

4

S

5

S

6

Input Sequence

Reset 0 1 00 01 10 1 1

X =1 0 0 0 0 0 0 0 Next State Output X =0

S

1

S

3

S

5

S

0

S

0

S

0

S

0

X =1 S

2

S

4

S

6

S

0

S

0

S

0

S

0

X =0

0

0

0

0

1

0

1

(18)

Enumerate all possible combinations of states taken two at a time

Naive Data Structure:

Xij will be the same as Xji

Also, can eliminate the diagonal

Implication Chart Next States

Under all Input

Combinations

S0 S1 S2 S3 S4 S5 S6

S0 S1 S2 S3 S4 S5 S6

S1 S2 S3 S4 S5 S6

S0 S1 S2 S3 S4 S5

(19)

Entry Xij — Row is Si, Column is Sj

Si is equivalent to Sj if outputs are the same and next states are equivalent

Xij contains the next states of Si, Sj which must be equivalent if Si and Sj are equivalent

If Si, Sj have different output behavior, then Xij is crossed out

Example:

S0 transitions to S1 on 0, S2 on 1;

S1 transitions to S3 on 0, S4 on 1;

So square X<0,1> contains entries S1-S3 (transition on zero) S2-S4 (transition on one)

S1-S3 S2-S4 S0

S1

(20)

Starting Implication Chart

S2 and S4 have different

I/O behavior This implies that S1 and S0 cannot

be combined S1

S2 S3 S4 S5 S6

S0 S1 S2 S3 S4 S5

S1-S3 S2-S4 S1-S5 S2-S6

S3-S5 S4-S6 S1-S0

S2-S0

S3-S0 S4-S0

S5-S0 S6-S0

S1-S0 S2-S0

S3-S0 S4-S0

S5-S0 S6-S0

S0-S0 S0-S0

S0-S0 S0-S0

(21)

Results of First Marking Pass

Second Pass Adds No New Information S3 and S5 are equivalent

S4 and S6 are equivalent

This implies that S1 and S2 are too!

Reduced State Transition Table Reduced State Transition Table

Input Sequence Reset 0 or 1 00 or 10 01 or 1 1

Present State S

0

S

1

' S

3

' S

4

'

X =0 S

1

' S

3

' S

0

S

0

X =1 S

1

' S

4

' S

0

S

0

X =0 0 0 0 1

X =1 0 0 0 0 Next State Output

S0-S0 S0-S0 S3-S5

S4-S6

S0-S0 S0-S0

S1 S2 S3 S4 S5 S6

S0 S1 S2 S3 S4 S5

(22)

State Diagram

Symbolic State Diagram

Present State

S 0 S 1 S 2 S 3 S 4 S 5

Next State 00

S 0 S 0 S 1 S 1 S 0 S 1

01 S 1 S 3 S 3 S 0 S 1 S 4

10 S 2 S 1 S 2 S 4 S 2 S 0

1 1 S 3 S 5 S 4 S 5 S 5 S 5

Output 1 0 1 0 1 0 S0

[1]

S2 [1]

S4 [1]

S1 [0]

S3 [0]

S5 [0]

10

01 11 00

00 01

11 10

10 01 00 11

10

00

01 11

00

11 10

01

10

01 11

00

(23)

Implication Chart

Minimized State Table

Present State

S 0 ' S 1 S 2 S 3 '

Next State 00

S 0 ' S 0 ' S 1 S 1

01 S 1 S 3 ' S 3 ' S 0 '

10 S 2 S 1 S 2 S 0 '

1 1 S 3 ' S 3 ' S 0 ' S 3 '

Output 1 0 1 0

S1

S2

S3

S4

S5

S0-S1 S1-S3 S2-S2 S3-S4

S0-S0 S1-S1 S2-S2 S3-S5

S0

S0-S1 S3-S0 S1-S4 S5-S5

S0-S1 S3-S4 S1-S0 S5-S5

S1

S1-S0 S3-S1 S2-S2 S4-S5

S2

S1-S1 S0-S4 S4-S0 S5-S5

S3 S4

(24)

Does the method solve the problem with the odd parity checker?

Implication Chart Implication Chart

S0 is equivalent to S2

since nothing contradicts this assertion!

S

1

S

2

S

0

S

1

S

0

- S

2

S

1

- S

1

(25)

The detailed algorithm:

1. Construct implication chart, one square for each combination of states taken two at a time

2. Square labeled Si, Sj, if outputs differ than square gets "X".

Otherwise write down implied state pairs for all input combinations

3. Advance through chart top-to-bottom and left-to-right. If square Si, Sj contains next state pair Sm, Sn and that pair labels a square already labeled "X", then Si, Sj is labeled "X".

4. Continue executing Step 3 until no new squares are marked with

"X".

5. For each remaining unmarked square Si, Sj, then Si and Sj are equivalent.

(26)

When FSM implemented with gate logic, number of gates will depend on mapping between symbolic state names and binary encodings

4 states = 4 choices for first state, 3 for second, 2 for third, 1 for last = 24 different encodings (4!)

Example for State Assignment: Traffic Light Controller

Symbolic State Names: HG, HY, FG, FY 24 state assignments

for the traffic light controller

HG 00 00 00 00 00 00 01 01 01 01 01 01

HY 01 01 10 10 1 1 1 1 00 00 10 10 1 1 1 1

FG 10 1 1 01 1 1 01 10 10 1 1 00 1 1 00 10

FY 1 1 10 1 1 01 10 01 1 1 10 1 1 00 10 00

HG 10 10 10 10 10 10 1 1 1 1 1 1 1 1 1 1 1 1

HY 00 00 01 01 1 1 1 1 00 00 01 01 10 10

FG 01 1 1 00 1 1 00 01 01 10 00 10 00 01

FY 1 1 01 1 1 00 01 00 10 01 10 00 01 00

C 0 X 1 X X 1 0 X X X

TL X

0 1 X X 0 X 1 X X

TS X X X 0 1 X X X 0 1

Inputs Present State Q 1 Q 0

HG HG HG HY HY FG FG FG FY FY

Next State P 1 P 0

HG HG HY HY FG FG FY FY FY HG

Outputs ST

0 0 1 0 1 0 1 1 0 1

H 1 H 0 00 00 00 01 01 10 10 10 10 10

F 1 F 0 10 10 10 10 10 00 00 00 01 01

(27)

State Maps: similar in concept to K-maps

If state X transitions to state Y, then assign "close" assignments to X and Y

S 0

S 1 S 2

S 3

S 4

0 1

Q 1 Q 0

00 01 1 1 10 0

1 Q 2

S 0 S 4 S 3 S 1 S 2 State Map State Name

S 0 S 1 S 2 S 3 S 4

Assignment Q 2

0 1 1 0 0

Q 1 0 0 1 1 1

Q 0 0 1 1 0 1 Assignment

Q 1 Q 0

00 01 1 1 10 Q 2

0 1

S 0 S 1 S 3 S 2 S 4 State Map State Name

S 0 S 1 S 2 S 3 S 4

Q 2 0 0 0 0 1

Q 1 0 0 1 1 1

Q 0 0 1 0 1 1 Assignment

Assignment

(28)

Minimum Bit Distance Criterion

13 7

Traffic light controller: HG = 00, HY = 01, FG = 11, FY = 10

yields minimum distance encoding but not best assignment!

Transition S0 to S1:

S0 to S2:

S1 to S3:

S2 to S3:

S3 to S4:

S4 to S1:

First Assignment Bit Changes

2 3 3 2 1 2

Second Assignment Bit Changes

1 1 1 1 1 2

(29)

Alternative heuristics based on input and output behavior as well as transitions:

Adjacent assignments to:

states that share a common next state (group 1's in next state map)

states that share a common ancestor state (group 1's in next state map)

states that have common output behavior (group 1's in output map)

Highest Priority

Medium Priority

Lowest Priority

i/j i/k

i/j i/j

α

α

α

β

β β

(30)

Example: 3-bit Sequence Detector

Highest Priority: (S3', S4') Medium Priority: (S3', S4') Lowest Priority:

0/0: (S0, S1', S3')

1/0: (S0, S1', S3', S4') Reset

S0 0,1/0

0,1/0

1/0

S1'

0/0

0/1, 1/0

S3' S4'

(31)

Reset State = 00

Highest Priority Adjacency

Not much difference in these two assignments

Not much difference in these two assignments

(32)

Highest Priority: (S3', S4'), (S7', S10') Medium Priority:

(S1, S2), 2x(S3', S4'), (S7', S10') Lowest Priority:

0/0: (S0, S1, S2, S3', S4', S7') 1/0: (S0, S1, S2, S3', S4', S7') Another Example: 4 bit String Recognizer

Reset

S1

S3'

S7'

S2

S4'

S10' 0,1/0

0,1/0 0/0

0/0

1/0 1/0 1/0

1/0

0/1 1/0 S0

0/0

0/0

(33)

00 = Reset = S0

(S1, S2), (S3', S4'), (S7', S10') placed adjacently

State Map Q1 Q0 Q2

0 1

00 01 11 10

S0

Q1 Q0 Q2

0 1

00 01 11 10

S0 S3'

S4'

Q1 Q0 Q2

0 1

00 01 11 10

S0 S3'

S4' S7' S10'

Q1 Q0 Q2

0 1

00 01 11 10

S0 S1 S3' S2 S4'

S7' S10'

Q1 Q0 Q2

0 1

00 01 11 10

S0

Q1 Q0 Q2

0 1

00 01 11 10

S0

S7' S10'

Q1 Q0 Q2

0 1

00 01 11 10

S0 S3'

S4'

S7' S10'

Q1 Q0 Q2

0 1

00 01 11 10

S0 S1 S3' S2 S4'

S7' S10'

(a) (b)

(34)

First encoding exhibits a better clustering of 1's in the next state map

Q 2 Q 1 Q 0 X

P 0 Q 2 Q 1

Q 0 X

P 0 Q 2 Q 1

Q 0 X

P 1 P 2

P 1 Q 2 Q 1

Q 0 X Q 2 Q 1

Q 0 X

( S 0 ) ( S 1 ) ( S 2 ) ( S 3 ' ) ( S 4 ' ) ( S 7 ' ) ( S ' 10 )

0 0 00

01

00 01 1 1 10

1 1 10

0

0 0

0 0 0 1 1 0

0

X X

P 2

00 01

00 01 1 1 10

1 1 10

0

1 1

1 1 1 1

X X

00 01

00 01 1 1 10

1 1 10

1 1 1 1

0 0 0 0

0 0 0 0

X X 1 1 ( S 0 )

( S 1 ) ( S 2 ) ( S 3 ' ) ( S 4 ' ) ( S 7 ' ) ( S ' 10 )

000 001 101 01 1 1 1 1 010 1 10

X = 0 001

01 1 1 1 1 010 010 000 000

X = 1 101 1 1 1 01 1 010 1 10 000 000 Current

State

Next State

000 001 010 01 1 100 101 1 10

X = 0 001

01 1 100 101 101 000 000

X = 1 010 100 01 1 101 1 10 000 000 Current

State

Next State

1 1 0 0

1 1 0 0 0

0 1 Q 2 Q 1

Q 0 X 00

01

00 01 1 1 10

1 1 10

0

0 0

0 1 0 0 1 1

1

1 1

00 01

00 01 1 1 10

1 1 10

0

0 1

X X 0 0

0 1

00 01

00 01 1 1 10

1 1 10

1 0 0 1

0 1 1 1

0 0 X X

1 0 0 0 X

0 0 X

0 0 0 0 1

參考文獻

相關文件

Each contracting State agrees that all aircraft of the other contracting States, being aircraft not engaged in scheduled international air services shall have the right, subject to

In addition, geometric engineering also suggests an absence of walls conjecture stating an equivalence between refined DT invariants of large radius limit stable objects of D b (X)

2.28 With the full implementation of the all-graduate teaching force policy, all teachers, including those in the basic rank, could have opportunities to take

● develop teachers’ ability to identify opportunities for students to connect their learning in English lessons (e.g. reading strategies and knowledge of topics) to their experiences

In this paper, we have shown that how to construct complementarity functions for the circular cone complementarity problem, and have proposed four classes of merit func- tions for

Optomechanical Interaction Nonclassical mechanical states - Want to find simple analogue quantum system that leads to nonclassical..

In fact, while we will be naturally thinking of a one-dimensional lattice, the following also holds for a lattice of arbitrary dimension on which sites have been numbered; however,

These are quite light states with masses in the 10 GeV to 20 GeV range and they have very small Yukawa couplings (implying that higgs to higgs pair chain decays are probable)..