104
CMPUT 329 - Computer Org anization and Architectu re II 1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

Embed Size (px)

Citation preview

Page 1: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

1

CMPUT329 - Fall 2003

Topic C: State Assignment José Nelson Amaral

Page 2: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

2

Reading Assignment

Chapter 7, section 7.4.6

Page 3: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

3

Incompletely Specified State Tables

Network A Network CSequentialNetwork B

X Z

Assumptions:(i) Network A can only generate sequences X=100 and X = 110.(ii) Network B produces output Z=1 when it receives X=110 and output Z=0 for X=100(iii) Network C ignores values of Z at other times.

Page 4: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

4

Incompletely Specified State Tables

S0 1/-

Input Output X=100 Z=--0 X=110 Z=--1

S1

Page 5: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

5

Incompletely Specified State Tables

S0

S1

1/-S3

S2 0/-

1/-

Input Output X=100 Z=--0 X=110 Z=--1

Page 6: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

6

Incompletely Specified State Tables

S0

S1

1/-S3

S2 0/-

1/-

0/0

Input Output X=100 Z=--0 X=110 Z=--1

Page 7: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

7

Incompletely Specified State Tables

S0

S1

1/-S3

S2 0/-

1/-

0/00/1

Next State Z Present State X=0 X=1 X=0 X=1 S0 - S1 - - S1 S2 S3 - - S2 S0 - 0 - S3 S0 - 1 -

Whenever there is a don’tcare state or a don’t careoutput, I can fill it with anyvalue. Input Output

X=100 Z=--0 X=110 Z=--1

Page 8: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

8

Incompletely Specified State Tables

Next State Z Present State X=0 X=1 X=0 X=1 S0 S0 S1 0 - S1 S2 S3 - - S2 S0 S1 0 - S3 S0 - 1 -

Therefore, I should fill it ina way that allows minimizationof the state machine.

S0

S1

1/-S3

S2 0/-

1/-

0/00/1

Input Output X=100 Z=--0 X=110 Z=--1

Page 9: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

9

Incompletely Specified State Tables

Next State Z Present State X=0 X=1 X=0 X=1 S0 S0 S1 0 - S1 S2 S3 - - S2 S0 S1 0 - S3 S0 - 1 -

Therefore, I should fill it ina way the allows minimizationof the state machined.

S0

S1

1/-S3

S2 0/-

1/-

0/1

0/-

S0

0/0

Input Output X=100 Z=--0 X=110 Z=--1

Page 10: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

10

Incompletely Specified State Tables

Next State Z Present State X=0 X=1 X=0 X=1 S0 S0 S1 0 - S1 S2 S3 1 - S2 S0 S1 0 - S3 S0 S3 1 -

Therefore, I should fill it ina way the allows minimizationof the state machined.

S0

S1

1/-S3

S2 0/-

1/-

0/1

0/-

S0

0/0

Input Output X=100 Z=--0 X=110 Z=--1

Page 11: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

11

Incompletely Specified State Tables

Next State Z Present State X=0 X=1 X=0 X=1 S0 S0 S1 0 - S1 S2 S3 1 - S2 S0 S1 0 - S3 S0 S3 1 -

Therefore, I should fill it ina way the allows minimizationof the state machined.

S0

S1

1/-S3

S2 0/-

1/-

0/1

0/1

S0

0/0

S1

1/-

Input Output X=100 Z=--0 X=110 Z=--1

Page 12: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

12

Incompletely Specified State Tables

Next State Z Present State X=0 X=1 X=0 X=1 S0 S0 S1 0 - S1 S0 S1 1 -

S0

S1

1/-

0/1

0/0

1/-

Input Output X=100 Z=--0 X=110 Z=--1

Page 13: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

13

Do State Assignments Matter?

NextState Output Present State I0=0 I0=1 Z0 Z1

Asgn #1

Asgn #2

S0 S1 S2 0 0 000 000 S1 S4 S3 1 1 100 100 S2 S4 S3 1 0 011 110 S3 S4 S4 0 1 010 011 S4 S0 S0 0 0 111 010

S0

S4

S3 S2

S1

00

11

1001

00

0

1

0

1

0

1

0

1

0

1

Page 14: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

14

State and Output Equations for Asgn #1

NextState Output Present State I0=0 I0=1 Z0 Z1 000 100 011 0 0 100 111 010 1 1 011 111 010 1 0 010 111 111 0 1 111 000 000 0 0

Q1

D2 = Q1’ I0’ + Q2’ I0’ + Q1Q0’

Q0

1 1

X X

1

1

X X

X X 1

Q2

I0

Page 15: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

15

State and Output Equations for Asgn #1

NextState Output Present State I0=0 I0=1 Z0 Z1 000 100 011 0 0 100 111 010 1 1 011 111 010 1 0 010 111 111 0 1 111 000 000 0 0

Q0

1

X X

1

1

1 1

X X

1

X X 1Q1

Q2

I0

D2 = Q1’ I0’ + Q2’ I0’ + Q1Q0’

D1 = Q1Q2’ + Q2Q1’ + Q2’ I0

Page 16: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

16

State and Output Equations for Asgn #1

NextState Output Present State I0=0 I0=1 Z0 Z1 000 100 011 0 0 100 111 010 1 1 011 111 010 1 0 010 111 111 0 1 111 000 000 0 0

Q0

1

X X

1

1

1

X X

X X 1Q1

Q2

I0

D2 = Q1’ I0’ + Q2’ I0’ + Q1Q0’

D1 = Q1Q2’ + Q2Q1’ + Q2’ I0

D0 = Q2Q1’I0’ + Q2’Q0’ I0 + Q1Q2’I0’

Page 17: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

17

State and Output Equations for Asgn #1

NextState Output Present State I0=0 I0=1 Z0 Z1 000 100 011 0 0 100 111 010 1 1 011 111 010 1 0 010 111 111 0 1 111 000 000 0 0

Q0

1

X X

1

1

1

X X

X X 1Q1

Q2

I0

D2 = Q1’ I0’ + Q2’ I0’ + Q1Q0’

D1 = Q1Q2’ + Q2Q1’ + Q2’ I0

D0 = Q2Q1’I0’ + Q2’Q0’ I0 + Q1Q2’I0’

Page 18: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

18

State and Output Equations for Asgn #1

NextState Output Present State I0=0 I0=1 Z0 Z1 000 100 011 0 0 100 111 010 1 1 011 111 010 1 0 010 111 111 0 1 111 000 000 0 0

Q0

1

X X

1

XQ1

Q2

D2 = Q1’ I0’ + Q2’ I0’ + Q1Q0’ D1 = Q1Q2’ + Q2Q1’ + Q2’ I0 D0 = Q2Q1’I0’ + Q2’Q0’ I0 + Q1Q2’I0’ Z0 = Q2’Q0 + Q2Q1’

Page 19: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

19

State and Output Equations for Asgn #1

NextState Output Present State I0=0 I0=1 Z0 Z1 000 100 011 0 0 100 111 010 1 1 011 111 010 1 0 010 111 111 0 1 111 000 000 0 0

Q0

1

X X

1 XQ1

Q2

D2 = Q1’ I0’ + Q2’ I0’ + Q1Q0’

D1 = Q1Q2’ + Q2Q1’ + Q2’ I0

D0 = Q2Q1’I0’ + Q2’Q0’ I0 + Q1Q2’I0’

Z0 = Q2’Q0 + Q2Q1’

Z1 = Q1Q0’ + Q2Q1’

Page 20: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

20

State and Output Equations for Asgn #1

NextState Output Present State I0=0 I0=1 Z0 Z1 000 100 011 0 0 100 111 010 1 1 011 111 010 1 0 010 111 111 0 1 111 000 000 0 0

Equation Cost D2 = Q1’ I0’ + Q2’ I0’ + Q1Q0’ 2+2+2+3=9 D1 = Q1Q2’ + Q2Q1’ + Q2’ I0 2+2+2+3=9 D0 = Q2Q1’I0’ + Q2’Q0’ I0 + Q1Q2’I0’ 3+3+3+3=12 Z0 = Q2’Q0 + Q2Q1’ 2+2=4 Z1 = Q1Q0’ + Q2Q1’ 2=2

Total 36

same term, onlypay for it once

Page 21: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

21

State and Output Equations for Asgn #2

NextState Output Present State I0=0 I0=1 Z0 Z1 000 100 110 0 0 100 010 011 1 1 110 010 011 1 0 011 010 010 0 1 010 000 000 0 0

Q0

Q2

I0

Q1

D2 =

X X X X

X X

1 1

D2 = Q2’Q1’

Page 22: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

22

State and Output Equations for Asgn #2

NextState Output Present State I0=0 I0=1 Z0 Z1 000 100 110 0 0 100 010 011 1 1 110 010 011 1 0 011 010 010 0 1 010 000 000 0 0

Q0

X X X X

X X

Q2

I0

Q1

D2 = Q2’Q1’

D1 =D1 = Q2

1

1

1

1 1

1

1

D1 = Q2 + Q0D1 = Q2 + Q0 + Q1’I0

Page 23: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

23

State and Output Equations for Asgn #2

NextState Output Present State I0=0 I0=1 Z0 Z1 000 100 110 0 0 100 010 011 1 1 110 010 011 1 0 011 010 010 0 1 010 000 000 0 0

Q0

X X X X

X X

Q2

I0

Q1

D0 =

D2 = Q2’Q1’D1 = Q2 + Q0 + Q1’I0D0 = Q2I0

1

1

Page 24: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

24

State and Output Equations for Asgn #2

NextState Output Present State I0=0 I0=1 Z0 Z1 000 100 110 0 0 100 010 011 1 1 110 010 011 1 0 011 010 010 0 1 010 000 000 0 0

Q0

X X

XQ1

Q2

Z0 =

D0 = Q2I0

D2 = Q2’Q1’D1 = Q2 + Q0 + Q1’I0

1

1

Z0 = Q2

Page 25: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

25

State and Output Equations for Asgn #2

NextState Output Present State I0=0 I0=1 Z0 Z1 000 100 110 0 0 100 010 011 1 1 110 010 011 1 0 011 010 010 0 1 010 000 000 0 0

Q0

X X

XQ1

Q2

Z1 =

Z0 = Q2

D0 = Q2I0

D2 = Q2’Q1’D1 = Q2 + Q0 + Q1’I0

Z1 = Q0 Z1 = Q0 + Q2Q1’

1

1

Page 26: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

26

State and Output Equations for Asgn #2

NextState Output Present State I0=0 I0=1 Z0 Z1 000 100 110 0 0 100 010 011 1 1 110 010 011 1 0 011 010 010 0 1 010 000 000 0 0

Equation Cost D2 = Q2’Q1’ 2 D1 = Q2 + Q0 + Q1’I0 2+3=5 D0 = Q2I0 2 Z0 = Q2 0 Z1 = Q0 + Q2Q1’ 2+2=4

Total 13

Page 27: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

27

State and Output Equations for Asgn #2

Equation (Asgn #2) Cost D2 = Q2’Q1’ 2 D1 = Q2 + Q0 + Q1’I0 2+3=5 D0 = Q2I0 2 Z0 = Q2 0 Z1 = Q0 + Q2Q1’ 2+2=4

Total 13

NextState Output Present State I0=0 I0=1 Z0 Z1

Asgn #1

Asgn #2

S0 S1 S2 0 0 000 000 S1 S4 S3 1 1 100 100 S2 S4 S3 1 0 011 110 S3 S4 S4 0 1 010 011 S4 S0 S0 0 0 111 010

Equation (Asgn #1) Cost D2 = Q1’ I0’ + Q2’ I0’ + Q1Q0’ 2+2+2+3=9 D1 = Q1Q2’ + Q2Q1’ + Q2’ I0 2+2+2+3=9 D0 = Q2Q1’I0’ + Q2’Q0’ I0 + Q1Q2’I0’ 3+3+3+3=12 Z0 = Q2’Q0 + Q2Q1’ 2+2=4 Z1 = Q1Q0’ + Q2Q1’ 2=2

Total 36

36

13

Page 28: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

28

How to choose a state assignment?

What makes one assignment yield a set of equationswith a cost of 36 and another assignment result in

a set of equations with a cost of 13?

How can we choose the best state assignment for a given state machine?

Could we try all assignments by enumeration?

Page 29: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

29

Number of State Assignments

Given a finite state machine M with r states.Assume that we use s bits to encode the states,where s is the smallest integer such that 2s r.

How many state assigments can be made to thismachine?

! 2

!22 rCA

s

srs

Page 30: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

30

Number of State Assignments

How many state assigments can be made to thismachine?

! 2

!22 rCA

s

srs

r s A 2 1 2 3 2 24 4 2 24

State Assignment S0 0 S1 1 S0 1 S1 0

Page 31: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

31

Number of State Assignments

How many state assigments can be made to thismachine?

! 2

!22 rCA

s

srs

r s A 2 1 2 3 2 24 4 2 24

State Assignment S0 00 S1 01 S2 10 S3 11 S0 00 S1 01 S2 11 S3 10 S0 00 S1 11 S2 10 S3 01 ·· ···

Page 32: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

32

Number ofState Assignments

How many state assigments can be made to thismachine?

! 2

!22 rCA

s

srs

r s A 2 1 2 3 2 24 4 2 24 5 3 6720 6 3 20160 7 3 40320 8 3 40320

r s A 9 4 4,151,347,200 10 4 29,059,430,400 11 4 174,356,582,400 12 4 871,782,912,000 13 4 3,487,131,648,000 14 4 10,461,394,944,000 15 4 20,922,789,888,000 16 4 20,922,789,888,000

Page 33: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

33

Equivalent State Assignments (Definition 1)

How many of these state assigments are equivalentto each other?

State Equivalency (McCluskey and Unger, 1959):State assignments are equivalent if they differ only bythe re-ordenation of the columns of bits in eachassignment, or if they differ by complementing acolumns of the matrix.

Page 34: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

34

Equivalent State Assignments (Definition 2)

But, in 1967 Weiner and Smith showed that assignments that result from complementing a column of bits are not equivalent to each other.Therefore their definition of state equivalency is:

State Equivalency (Weiner and Smith, 1967):State assignments are equivalent if they differ only bythe re-ordenation of columns.

Page 35: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

35

Equivalent State Assignments (Example)

Which of the following state assignments are equivalent?State Code

Q2Q1Q0 S(-) 000 S(0) 001 S(1) 010 S(01) 011 S(10) 100 S(100) 101

State Code Q2Q1Q0

S(-) 000 S(0) 100 S(1) 010 S(01) 110 S(10) 001 S(100) 101

State Code Q2Q1Q0

S(-) 000 S(0) 001 S(1) 011 S(01) 010 S(10) 100 S(100) 101

State Code Q2Q1Q0

S(-) 010 S(0) 011 S(1) 000 S(01) 001 S(10) 110 S(100) 111

(a)

(b)

(c)

(d)

Page 36: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

36

Number of Distinct State Assignments

Given a finite state machine M with r states.Assume that we use s bits to encode the states,where s is the smallest integer such that 2s r. How many distinct assignments exist for this machine?

Page 37: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

37

Number of Distinct State Assignments

By McCluskey’s definition (1959), the number of equivalent state assignments is given by:

!! 2

! 121

srN

s

s

Using Weiner-Smith’s definition (1967), Harrisonfound (in 1968) that the number of equivalent stateassignments is:

!! 2

! 22

srN

s

s

Page 38: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

38

Number of Distinct State Assignments

r s A N1 N2 2 1 2 1 2 3 2 24 3 12 4 2 24 3 12 5 3 6720 140 1120 6 3 20160 420 1120 7 3 40320 840 6720 8 3 40320 840 6720

A: State AssignmentsN1: Distinct State Assign. (McCluskey)N2: Distinct State Assign. (Weiner-Smith-Harrison)

Page 39: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

39

Number of Distinct States Assignments

r s A N1 N2 9 4 4,151,347,200 10,810,800 172,972,800 10 4 29,059,430,400 75,675,600 1,210,809,600 11 4 174,356,582,400 454,053,600 7,264,857,600 12 4 871,782,912,000 2,270,268,000 36,324,288,000 13 4 3,487,131,648,000 9,081,072,000 114,529,715,200 14 4 10,461,394,944,000 27,243,216,000 435,891,456,000 15 4 20,922,789,888,000 54,486,432,000 871,782,720,000 16 4 20,922,789,888,000 54,486,432,000 871,782,720,000

A: State AssignmentsN1: Distinct State Assignments (McCluskey)N2: Distinct State Assign. (Weiner-Smith-Harrison)

Page 40: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

40

The Right Number of Distinct States

In 1977, Rhyne and Noe showed that:

(I) for circuits built with flip-flops SR, JK, and T, there are N1 (McCluskey) distinct states.(ii) for machines implemented with flip-flops D, there are N2 (Weiner-Smith-Harrison) distinct states.

Page 41: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

41

Finding an Optimal State Assignment

It seems that we will not be able to enumerateall possible state assignments, generate thenext state and output equations, compute thecost and then choose the best one.

As a matter of fact, the State Assignment Problem(SAP) is a well-known NP-complete problem. Therefore we must settle for “good” state assignments.

Page 42: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

42

Distance Between States

The distance between two states Sa and Sb, D(Sa,Sb) is defined as the Hamming distance between the code assigned to Sa, A(Sa), and the code assinged to Sb, A(Sb).

NextState Output Present State I0=0 I0=1 Z0 Z1

Asgn #1

Asgn #2

S0 S1 S2 0 0 000 000 S1 S4 S3 1 1 100 100 S2 S4 S3 1 0 011 110 S3 S4 S4 0 1 010 011 S4 S0 S0 0 0 111 010

Page 43: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

43

Distance Between States (Example)

As an example lets compute the distance tostate S0 of every other state in our example

NextState Output Present State I0=0 I0=1 Z0 Z1

Asgn #1

Asgn #2

D(S0,?) Asg#1

D(S0,?) Asg#2

S0 S1 S2 0 0 000 000 S1 S4 S3 1 1 100 100 S2 S4 S3 1 0 011 110 S3 S4 S4 0 1 010 011 S4 S0 S0 0 0 111 010

Page 44: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

44

Distance Between States (Example)

As an example lets compute the distance tostate S0 of every other state in our example

NextState Output Present State I0=0 I0=1 Z0 Z1

Asgn #1

Asgn #2

D(S0,?) Asg#1

D(S0,?) Asg#2

S0 S1 S2 0 0 000 000 0 0 S1 S4 S3 1 1 100 100 1 1 S2 S4 S3 1 0 011 110 2 2 S3 S4 S4 0 1 010 011 1 2 S4 S0 S0 0 0 111 010 3 1

Page 45: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

45

State Distance Graph

S1 1 S2 2 3 S3 1 2 1 S4 3 2 1 2 S0 S1 S2 S3

State Distance Graph(Asgn #1)

NextState Output Present State I0=0 I0=1 Z0 Z1

Asgn #1

Asgn #2

S0 S1 S2 0 0 000 000 S1 S4 S3 1 1 100 100 S2 S4 S3 1 0 011 110 S3 S4 S4 0 1 010 011 S4 S0 S0 0 0 111 010

S1 1 S2 2 1 S3 2 3 2 S4 1 2 1 1 S0 S1 S2 S3

State Distance Graph(Asgn #2)

Page 46: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

46

The Successor Rule

Good state assignments result when the followingset of empirical rules are followed in the selectionof the state assignment:

Rule 1: States that are the next states of a given state should be close to each other

Si

Sj Sk

01Suc(Si) = {Sj , Sk}

Sj and Sk should be close toeach other

Page 47: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

47

The Successor Rule(Example)

S1 1 S2 2 3 S3 1 2 1 S4 3 2 1 2 S0 S1 S2 S3

State Distance Graph(Asgn #1)

NextState Output Present State I0=0 I0=1 Z0 Z1

Asgn #1

Asgn #2

S0 S1 S2 0 0 000 000 S1 S4 S3 1 1 100 100 S2 S4 S3 1 0 011 110 S3 S4 S4 0 1 010 011 S4 S0 S0 0 0 111 010

S1 1 S2 2 1 S3 2 3 2 S4 1 2 1 1 S0 S1 S2 S3

State Distance Graph(Asgn #2)

Assign #2 bettersatisfies the successor

rule than Assign #1

Page 48: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

48

The Predecessor Rule

Rule 2: States that have the same next state, for a given input, should be close to each other.

Sc

Sa Sb

I0=1Pred(Sc, I0=1) = {Sa , Sb}

Sa and Sb should be close toeach other

I0=1

Page 49: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

49

The Predecessor Rule(Example)

State Distance Graph(Asgn #1)

NextState Output Present State I0=0 I0=1 Z0 Z1

Asgn #1

Asgn #2

S0 S1 S2 0 0 000 000 S1 S4 S3 1 1 100 100 S2 S4 S3 1 0 011 110 S3 S4 S4 0 1 010 011 S4 S0 S0 0 0 111 010

S1 1 S2 2 1 S3 2 3 2 S4 1 2 1 1 S0 S1 S2 S3

State Distance Graph(Asgn #2)

S1 1 S2 2 3 S3 1 2 1 S4 3 2 1 2 S0 S1 S2 S3

Assign #2 betterfollows the predecessor

rule than Assign #1

Page 50: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

50

The Output Rule

Rule 3: States that have the same output for a given input should be close to each other.

For a Moore machine we say that each outputpartitions the states into two subsets.

Page 51: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

51

The Output Rule(Example)

For a Moore machine we say that each outputpartitions the states into two subsets.

NextState Output Present State I0=0 I0=1 Z0 Z1

S0 S1 S2 0 0 S1 S4 S3 1 1 S2 S4 S3 1 0 S3 S4 S4 0 1 S4 S0 S0 0 0

In our example:

O(Z0) = {(S0, S3, S4), (S1, S2)}O(Z1) = {(S0, S2, S4), (S1, S3)}

Page 52: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

52

The Output Rule(Example)

State Distance Graph(Asgn #1)

S1 1 S2 2 1 S3 2 3 2 S4 1 2 1 1 S0 S1 S2 S3

State Distance Graph(Asgn #2)

S1 1 S2 2 3 S3 1 2 1 S4 3 2 1 2 S0 S1 S2 S3

NextState Output Present State I0=0 I0=1 Z0 Z1

S0 S1 S2 0 0 S1 S4 S3 1 1 S2 S4 S3 1 0 S3 S4 S4 0 1 S4 S0 S0 0 0

O(Z0) = {(S0, S3, S4), (S1, S2)}O(Z1) = {(S0, S2, S4), (S1, S3)}

Assign #2 betterfollows the output

rule for Z0

Page 53: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

53

The Output Rule(Example)

State Distance Graph(Asgn #1)

S1 1 S2 2 1 S3 2 3 2 S4 1 2 1 1 S0 S1 S2 S3

State Distance Graph(Asgn #2)

S1 1 S2 2 3 S3 1 2 1 S4 3 2 1 2 S0 S1 S2 S3

NextState Output Present State I0=0 I0=1 Z0 Z1

S0 S1 S2 0 0 S1 S4 S3 1 1 S2 S4 S3 1 0 S3 S4 S4 0 1 S4 S0 S0 0 0

O(Z0) = {(S0, S3, S4), (S1, S2)}O(Z1) = {(S0, S2, S4), (S1, S3)}

Assign #2 betterfollows the output

rule for Z1

Page 54: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

54

The Transition Rule

Rule 4: If there is a state transition between two states, the states should be close to each other.

Typically this rule is used to decide a tiebetween the other rules.

Page 55: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

55

The Transition Rule(Example)

S1 1 S2 2 3 S3 1 2 1 S4 3 2 1 2 S0 S1 S2 S3

State Distance Graph(Asgn #1)

NextState Output Present State I0=0 I0=1 Z0 Z1

Asgn #1

Asgn #2

S0 S1 S2 0 0 000 000 S1 S4 S3 1 1 100 100 S2 S4 S3 1 0 011 110 S3 S4 S4 0 1 010 011 S4 S0 S0 0 0 111 010

S1 1 S2 2 1 S3 2 3 2 S4 1 2 1 1 S0 S1 S2 S3

State Distance Graph(Asgn #2)

Assign #2 betterfollows the

transition rule

Page 56: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

56

The State “0” Guideline

Guideline: The cost of the circuit will not be affected by the choice of which state receives the state “0” (according to McCluskey). Therefore to simplify reset generating circuits, the state “0” should always be assigned to the reset state.

Page 57: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

57

Successor Sets

Using our definitions, we can compute theset of successors of each state in our example:

NextState Output Present State I0=0 I0=1 Z0 Z1

S0 S1 S2 0 0 S1 S4 S3 1 1 S2 S4 S3 1 0 S3 S4 S4 0 1 S4 S0 S0 0 0

S(S0) = {S1, S2}S(S1) = {S3, S4}S(S2) = {S3, S4}S(S3) = {S4}S(S4) = {S0}

Page 58: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

58

Predecessor Sets

We can also compute the set of predecessors of each state in our example:

NextState Output Present State I0=0 I0=1 Z0 Z1

S0 S1 S2 0 0 S1 S4 S3 1 1 S2 S4 S3 1 0 S3 S4 S4 0 1 S4 S0 S0 0 0

P (S1,I0=0) = {S0}P (S4,I0=0) = {S1, S2 , S3}P (S0,I0=0) = {S4}P (S2,I0=1) = {S0}P (S3,I0=1) = {S1, S2}P (S4,I0=1) = {S3}P (S0,I0=1) = {S0}

Page 59: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

59

Sets and Output Partition (Example)

Thus for our example we have:

Predecessor Sets:P (S1,I0=0) = {S0}P (S4,I0=0) = {S1, S2 , S3}P (S0,I0=0) = {S4}P (S2,I0=1) = {S0}P (S3,I0=1) = {S1, S2}P (S4,I0=1) = {S3}P (S0,I0=1) = {S0}

Output Partitions:O(Z0) = {(S0, S3, S4), (S1, S2)}O(Z1) = {(S0, S2, S4), (S1, S3)}

Successor Sets:S(S0) = {S1, S2}S(S1) = {S3, S4}S(S2) = {S3, S4}S(S3) = {S4}S(S4) = {S0}

But we are only interested in sets with multiple elements.

Page 60: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

60

Sets and Output Partition (Example)

Thus for our example we have:

Predecessor Sets:P (S4,I0=0) = {S1, S2 , S3}P (S3,I0=1) = {S1, S2}

Output Partitions:O(Z0) = {(S0, S3, S4), (S1, S2)}O(Z1) = {(S0, S2, S4), (S1, S3)}

Successor Sets:S(S0) = {S1, S2}S(S1) = {S3, S4}S(S2) = {S3, S4}

Page 61: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

61

Obtaining Good State Assignments (Example)

Predecessor Sets:P (S4,I0=0) = {S1, S2 , S3}P (S3,I0=1) = {S1, S2}

Output Partitions:O(Z0) = {(S0, S3, S4), (S1, S2)}O(Z1) = {(S0, S2, S4), (S1, S3)}

Successor Sets:S(S0) = {S1, S2}S(S1) = {S3, S4}S(S2) = {S3, S4}

NextState Output Present State I0=0 I0=1 Z0 Z1

S0 S1 S2 0 0 S1 S4 S3 1 1 S2 S4 S3 1 0 S3 S4 S4 0 1 S4 S0 S0 0 0

Problem: Choose a good state assignment for this machine.

Page 62: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

62

The Desired Adjacency Graph (DAG)

Based on early work of Armstrong (1962), Amaral (1990) incorporated the state assignment rules of Miller (1965) into a “Desired Adjacency Graph” that can be used to translate the state assignment rules into a graph that encodes the strenght of the connection between states.

J. N. Amaral and W. C. Cunha, “State Assignment Algorithm for Incompletely Specified Finite State Machines,” in Fifth Congress of the Brazilian Society for Microelectronics, pp. 174-183, 1990.J. N. Amaral, K. Tumer, and J. Ghosh, “Designing Genetic Algorithms for the State Assignment Problem,” IEEE Transactions on Systems, Man, and Cybernetics, vol. 25, No. 4, April, 1995.

Page 63: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

63

The Successor DAG

Successor Sets:S(S0) = {S1, S2}S(S1) = {S3, S4}S(S2) = {S3, S4}

To create the successor DAG, we start with a graph with zero associated to all edges

and add 1 to the edge (Sa, Sb) whenever Sa and Sb are elements of the successor set of a state.

S1 0 S2 0 1 S3 0 0 0 S4 0 0 0 2 S0 S1 S2 S3

Successor Desired Adjacency Graph

Page 64: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

64

The Predecessor DAG

S1 0 S2 0 2 S3 0 1 1 S4 0 0 0 0 S0 S1 S2 S3

Predecessor Desired Adjacency Graph

Predecessor Sets:P (S4,I0=0) = {S1, S2 , S3}P (S3,I0=1) = {S1, S2}

To create the predecessor DAG, we start with a graph with zero associated to all edges

and add 1 to the edge (Sa, Sb) whenever Sa and Sb are elements of the predecessor set of a state.

Page 65: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

65

The Output DAG

S1 0 S2 1 1 S3 1 1 0 S4 2 0 1 1 S0 S1 S2 S3

Output Desired Adjacency Graph

Output Partitions:O(Z0) = {(S0, S3, S4), (S1, S2)}O(Z1) = {(S0, S2, S4), (S1, S3)}

To create the output DAG, we start with a graph with zero associated to all edges

and add 1 to the edge (Sa, Sb) whenever Sa and Sb are in the same partition for an output Zp.

Page 66: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

66

The Transition DAG

S1 1 S2 1 0 S3 0 1 1 S4 2 1 1 2 S0 S1 S2 S3

Transition Desired Adjacency Graph

NextState Output Present State I0=0 I0=1 Z0 Z1

S0 S1 S2 0 0 S1 S4 S3 1 1 S2 S4 S3 1 0 S3 S4 S4 0 1 S4 S0 S0 0 0

To create the transition DAG, we start with a graph with zero associated to all edges

and add 1 to the edge (Sa, Sb) whenever there isa transition from state Sa to state Sb.

Page 67: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

67

Combining DAGS

S1 0 S2 1 1 S3 1 1 0 S4 2 0 1 1 S0 S1 S2 S3

Output DAG

S1 0 S2 0 2 S3 0 1 1 S4 0 0 0 0 S0 S1 S2 S3

Predecessor DAG

S1 0 S2 0 1 S3 0 0 0 S4 0 0 0 2 S0 S1 S2 S3

Successor DAG

How do we combine these four DAGs to obtain a single one?

S1 1 S2 1 0 S3 0 1 1 S4 2 1 1 2 S0 S1 S2 S3

Transition DAG

Page 68: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

68

The Weight of the Rules

If all the rules were equally important, we could just add the values in the vertices.

Comer [1984] suggests that Rule 2 (the predecessor rule)is the most important, followed by Rule 1 (the successor rule),

and by Rule 3 (the output rule). Rule 4 (the transition rule)should be used only as a tie breaker. Amaral [1990]proposes the following weights for the combination

of the Rule DAGs into a single DAG:

DAG = 3xSuccessor + 4xPredecessor + 2xOutput + Transition

Page 69: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

69

S1 0 S2 1 1 S3 1 1 0 S4 2 0 1 1 S0 S1 S2 S3

Output DAG

S1 0 S2 0 2 S3 0 1 1 S4 0 0 0 0 S0 S1 S2 S3

Predecessor DAG

S1 0 S2 0 1 S3 0 0 0 S4 0 0 0 2 S0 S1 S2 S3

Successor DAG

S1 1 S2 1 0 S3 0 1 1 S4 2 1 1 2 S0 S1 S2 S3

Transition DAG

S1 1 S2 3 13 S3 2 7 5 S4 6 1 3 10 S0 S1 S2 S3

DAG = 3xSuccessor + 4xPredecessor + 2xOutput + Transition

DAG

Page 70: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

70

How Asgn #2 and Asgn #2 measure up?

S1 1 S2 3 13 S3 2 7 5 S4 6 1 3 10 S0 S1 S2 S3

DAG

S1 1 S2 2 3 S3 1 2 1 S4 3 2 1 2 S0 S1 S2 S3

State Distance Graph(Asgn #1)

S1 1 S2 2 1 S3 2 3 2 S4 1 2 1 1 S0 S1 S2 S3

State Distance Graph(Asgn #2)

Page 71: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

71

Matching Code Distances with the DAG

S1 1 S2 3 13 S3 2 7 5 S4 6 1 3 10 S0 S1 S2 S3

DAG

001 1 010 1 2 011 2 1 1 100 1 2 2 3 101 2 1 3 2 1 110 2 3 1 2 1 2 111 3 2 2 1 2 1 1

000 001 010 011 100 101 110

Code Distances

Page 72: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

72

Where to Start the State Assignment?

S1 1 S2 3 13 S3 2 7 5 S4 6 1 3 10 S0 S1 S2 S3

DAG

First we compute the Weight ofeach state Sa by adding the valuesassociated with the edges (Sa, S?) in the DAG. This weight vector indicateswhich states should be given priority during the state assignment process.

S0 S1 S2 S3 S4 12 22 24 24 20

Weight

Page 73: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

73

Matching Code Distances with the DAG

DAGjiDAG

SSSSD

s

DAGSSD

ij

jiji

s

i

s

jijji

theof ,position theis

and statesbetween distance theis ,

machine, state finite in the states ofnumber theis where

,

:expression following theminimize tois objectiveOur 1

0

1

0

Page 74: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

74

The Weight of the States

S1 1 S2 3 13 S3 2 7 5 S4 6 1 3 10 S0 S1 S2 S3

DAG

S0 S1 S2 S3 S4 12 22 24 24 20

Weight

We start with the state with thelargest weight.

S0 S1 S2 S3 S4

Page 75: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

75

The First State Assignment

S1 1 S2 3 13 S3 2 7 5 S4 6 1 3 10 S0 S1 S2 S3

DAG

S0 S1 S2 S3 S4 12 22 24 24 20

Weight

We start with the state with thelargest weight.

S0 S1 S2 000 S3 S4

If there is a tie, we start with the state (among the ones that tie) that has an edge with maximum value in the DAG.

We assign “0” to this state.

Page 76: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

76

The Second State Assignment

S1 1 S2 3 13 S3 2 7 5 S4 6 1 3 10 S0 S1 S2 S3

DAG

S0 S1 S2 S3 S4 12 22 24 24 20

Weight

We start with the state with thelargest weight.

S0 S1 001 S2 000 S3 S4

If there is a tie, we start with the state (among the ones that tie) that has an edge with maximum value in the DAG.

We assign “0” to this state.

Then find the state with the strongest connection with that

first state in the DAG and assign “1” to this second state.

Page 77: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

77

Incomplete Assignment Table

S1 1 S2 3 13 S3 2 7 5 S4 6 1 3 10 S0 S1 S2 S3

DAG

000 001 010 011 100 101 110 111 S0 - - S1 - - - - - - - - - S2 - - - - - - - - - S3 - - S4 - -

S0 S1 001 S2 000 S3 S4

Each cell of the table contains howmuch would be added to the expression

If the state of the row would be giventhe code of the column

1

0

1

0

,s

i

s

jijji DAGSSD

Page 78: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

78

Incomplete Assignment Table

S1 1 S2 3 13 S3 2 7 5 S4 6 1 3 10 S0 S1 S2 S3

DAG

000 001 010 011 100 101 110 111 S0 - - 5 S1 - - - - - - - - - S2 - - - - - - - - - S3 - - S4 - -

S0 S1 001 S2 000 S3 S4

Thus the value at cell (S0,010) is:

5323112

000,010)001,010(

,,

0201

02200110

DAGDDAGD

DAGSSDDAGSSD

Page 79: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

79

Incomplete Assignment Table

S1 1 S2 3 13 S3 2 7 5 S4 6 1 3 10 S0 S1 S2 S3

DAG

000 001 010 011 100 101 110 111 S0 - - 5 7 5 7 9 9 S1 - - - - - - - - - S2 - - - - - - - - - S3 - - 19 17 19 17 31 29 S4 - - 5 7 5 7 9 11

S0 S1 001 S2 000 S3 S4

The value in the other cells iscomputed in the same way

Page 80: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

80

Incomplete Assignment Table

S1 1 S2 3 13 S3 2 7 5 S4 6 1 3 10 S0 S1 S2 S3

DAG

000 001 010 011 100 101 110 111 S0 - - 5 7 5 7 9 9 42 S1 - - - - - - - - - S2 - - - - - - - - - S3 - - 19 17 19 17 31 29 132 S4 - - 5 7 5 7 9 11 44

S0 S1 001 S2 000 S3 S4

Then we add the values in each row.

Page 81: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

81

Selecting a State in the IAT

S1 1 S2 3 13 S3 2 7 5 S4 6 1 3 10 S0 S1 S2 S3

DAG

S0 S1 001 S2 000 S3 S4

The state that has the heighest sumin the table is the one that can causethe most damage (increase the cost ofthe circuit). Therefore it should beassigned first.

000 001 010 011 100 101 110 111 S0 - - 5 7 5 7 9 9 42 S1 - - - - - - - - - S2 - - - - - - - - - S3 - - 19 17 19 17 31 29 132 S4 - - 5 7 5 7 9 11 44

Page 82: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

82

Selecting States in the IAT

S1 1 S2 3 13 S3 2 7 5 S4 6 1 3 10 S0 S1 S2 S3

DAG

S0 S1 001 S2 000 S3 S4

Thus we look for the row with maximumsum in the Incomplete Assignment Table, and we pick the cell with the minimum weight.

If there is a tie, we break it arbitrarily.

000 001 010 011 100 101 110 111 S0 - - 5 7 5 7 9 9 42 S1 - - - - - - - - - S2 - - - - - - - - - S3 - - 19 17 19 17 31 29 132 S4 - - 5 7 5 7 9 11 44

Page 83: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

83

Incomplete Assignment Table

S1 1 S2 3 13 S3 2 7 5 S4 6 1 3 10 S0 S1 S2 S3

DAG

S0 S1 001 S2 000 S3 101 S4

Now we have to recompute thevalues in the table.

Again we pick the minimum cell in the row with the maximum sum.

000 001 010 011 100 101 110 111 S0 - - 11 11 7 - 13 13 42 S1 - - - - - - - - - S2 - - - - - - - - - S3 - - - - - - - - - S4 - - 35 27 15 - 29 21 127

Page 84: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

84

000 001 010 011 100 101 110 111 S0 - - 23 29 - - 19 25 96 S1 - - - - - - - - - S2 - - - - - - - - - S3 - - - - - - - - - S4 - - - - - - - - -

Incomplete Assignment Table

S1 1 S2 3 13 S3 2 7 5 S4 6 1 3 10 S0 S1 S2 S3

DAG

S0 S1 001 S2 000 S3 101 S4 100

Again we recompute thevalues in the table.

We pick the minimum cell in the row.

Page 85: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

85

Checking the State Distance Graph

S1 1 S2 3 13 S3 2 7 5 S4 6 1 3 10 S0 S1 S2 S3

DAG

Does this assignment make sense?

To make checking it easier,we can build a state distance graph.

S1 3 S2 2 1 S3 2 1 2 S4 1 2 1 1 S0 S1 S2 S3

State Distance GraphS0 110

S1 001 S2 000 S3 101 S4 100

Page 86: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

86

Incomplete Assignment Table

But this assignment does not follow the guidelinethat says that the reset state (S0) should be state “0”.

To fix that, we have to complement the two first columns. Would that change the state distance graph?

S0 110 S1 001 S2 000 S3 101 S4 100

Page 87: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

87

Incomplete Assignment Table

S1 1 S2 3 13 S3 2 7 5 S4 6 1 3 10 S0 S1 S2 S3

DAG

S1 3 S2 2 1 S3 2 1 2 S4 1 2 1 1 S0 S1 S2 S3

S0 000 S1 111 S2 110 S3 011 S4 010

Assign #3

S0 110 S1 001 S2 000 S3 101 S4 100

State Distance Graph

Page 88: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

88

Comparing Assignments #1, #2, and #3

S1 1 S2 3 13 S3 2 7 5 S4 6 1 3 10 S0 S1 S2 S3

DAG

S1 1 S2 2 3 S3 1 2 1 S4 3 2 1 2 S0 S1 S2 S3

S0 000 S1 100 S2 011 S3 010 S4 111

Assign #1

S1 1 S2 2 1 S3 2 3 2 S4 1 2 1 1 S0 S1 S2 S3

S0 000 S1 100 S2 110 S3 011 S4 010

Assign #2

S1 3 S2 2 1 S3 2 1 2 S4 1 2 1 1 S0 S1 S2 S3

S0 000 S1 111 S2 110 S3 011 S4 010

Assign #3

Page 89: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

89

State and Output Equations for Asgn #3

S0 000 S1 111 S2 110 S3 011 S4 010

NextState Output Present State I0=0 I0=1 Z0 Z1

S0 S1 S2 0 0 S1 S4 S3 1 1 S2 S4 S3 1 0 S3 S4 S4 0 1 S4 S0 S0 0 0

NextState Output Present State I0=0 I0=1 Z0 Z1 000 111 110 0 0 111 010 011 1 1 110 010 011 1 0 011 010 010 0 1 010 000 000 0 0

Page 90: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

90

D2 Equations for Asgn #3

Q0

1 X

X X

X 1

X X

Q2

I0

Q1

NextState Output Present State I0=0 I0=1 Z0 Z1 000 111 110 0 0 111 010 011 1 1 110 010 011 1 0 011 010 010 0 1 010 000 000 0 0

D2 = Q1’

Asgn #3

Page 91: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

91

Comparing D2 Equation for Asgn #3 and Asgn #1

Q0

1 X

X X

X 1

X X

Q2

I0

Q1

NextState Output Present State I0=0 I0=1 Z0 Z1 000 111 110 0 0 111 010 011 1 1 110 010 011 1 0 011 010 010 0 1 010 000 000 0 0

Q0

1

X X

1

X X

X X

Q2

I0

D2 = Q2’Q1’

D2 = Q1’

Q1

Asgn #1

Asgn #3

Page 92: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

92

D1 Equations for Asgn #3

Q0

1 X

X X

1

X 1

X X

11

1

1

1

Q2

I0

Q1

D1 = Q2 + Q0 + Q1’

NextState Output Present State I0=0 I0=1 Z0 Z1 000 111 110 0 0 111 010 011 1 1 110 010 011 1 0 011 010 010 0 1 010 000 000 0 0

D2 = Q1’

Asgn #3

Page 93: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

93

Comparing D1 Equation for Asgn #3 and Asgn #1

Q0

1 X

X X

1

X 1

X X

11

1

1

1

Q2

I0

Q1

D1 = Q2 + Q0 + Q1’

NextState Output Present State I0=0 I0=1 Z0 Z1 000 111 110 0 0 111 010 011 1 1 110 010 011 1 0 011 010 010 0 1 010 000 000 0 0

Q0

1

X X

1

1 1

X X

1X

1

X

1

Q2

I0

Q1

D1 = Q2 + Q0 + Q1’I0

D2 = Q1’

Asgn #3

Asgn #1

Page 94: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

94

D0 Equations for Asgn #3

Q0

1 X

X X

X

X X

1

1

Q2

I0

Q1

D0 = Q2I0 + Q1’ I0’

NextState Output Present State I0=0 I0=1 Z0 Z1 000 111 110 0 0 111 010 011 1 1 110 010 011 1 0 011 010 010 0 1 010 000 000 0 0

D1 = Q2 + Q0 + Q1’D2 = Q1’

Asgn #3

Page 95: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

95

Comparing D0 Equation for Asgn #3 and Asgn #1

Q0

1 X

X X

X

X X

1

1

Q2

I0

Q1

D0 = Q2I0 + Q1’ I0’

NextState Output Present State I0=0 I0=1 Z0 Z1 000 111 110 0 0 111 010 011 1 1 110 010 011 1 0 011 010 010 0 1 010 000 000 0 0

Q0

X X

1

X X

X X

1

Q2

I0

Q1

D0 = Q2I0

D1 = Q2 + Q0 + Q1’D2 = Q1’

Asgn #3

Asgn #1

Page 96: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

96

Z0 Equations for Asgn #3

Q0

X

X X

1

1Q1

Q2

Z0 = Q2

NextState Output Present State I0=0 I0=1 Z0 Z1 000 111 110 0 0 111 010 011 1 1 110 010 011 1 0 011 010 010 0 1 010 000 000 0 0

D0 = Q2I0 + Q1’ I0’D1 = Q2 + Q0 + Q1’D2 = Q1’

Asgn #3

Page 97: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

97

Comparing D0 Equation for Asgn #3 and Asgn #1

Q0

X

X X

1

1Q1

Q2

Z0 = Q2

NextState Output Present State I0=0 I0=1 Z0 Z1 000 111 110 0 0 111 010 011 1 1 110 010 011 1 0 011 010 010 0 1 010 000 000 0 0

1

X X

X

1Q1

Q2

Z0 = Q2

Q0 D0 = Q2I0 + Q1’ I0’D1 = Q2 + Q0 + Q1’D2 = Q1’

Asgn #3

Asgn #1

Page 98: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

98

Z1 Equations for Asgn #3

Q0

X

X X

1 1Q1

Q2

Z1 = Q0

Z0 = Q2

NextState Output Present State I0=0 I0=1 Z0 Z1 000 111 110 0 0 111 010 011 1 1 110 010 011 1 0 011 010 010 0 1 010 000 000 0 0

D0 = Q2I0 + Q1’ I0’D1 = Q2 + Q0 + Q1’D2 = Q1’

Asgn #3

Page 99: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

99

Comparing D0 Equation for Asgn #3 and Asgn #1

Q0

X

X X

1 1Q1

Q2

Z1 = Q0

Z0 = Q2

NextState Output Present State I0=0 I0=1 Z0 Z1 000 111 110 0 0 111 010 011 1 1 110 010 011 1 0 011 010 010 0 1 010 000 000 0 0

Z1 = Q0 + Q2Q1’

Q0

1

X X

1 XQ1

Q2

D0 = Q2I0 + Q1’ I0’D1 = Q2 + Q0 + Q1’D2 = Q1’

Asgn #1

Asgn #3

Page 100: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

100

State and Output Equations for Asgn #3

Equation Cost D2 = Q1’ 0 D1 = Q2 + Q0 + Q1’ 3 D0 = Q2I0+ Q1’I0’ 2+2+2=6 Z0 = Q2 0 Z1 = Q0 0

Total 9

NextState Output Present State I0=0 I0=1 Z0 Z1 000 111 110 0 0 111 010 011 1 1 110 010 011 1 0 011 010 010 0 1 010 000 000 0 0

Z1 = Q0

Z0 = Q2

D0 = Q2I0 + Q1’ I0’D1 = Q2 + Q0 + Q1’D2 = Q2’Q1’

Page 101: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

101

Comparing Equations for Asgns #1, #2, and #3

Equation (Asgn #2) Cost D2 = Q2’Q1’ 2 D1 = Q2 + Q0 + Q1’I0 2+3=5 D0 = Q2I0 2 Z0 = Q2 0 Z1 = Q0 + Q2Q1’ 2+2=4

Total 13

Equation (Asgn #1) Cost D2 = Q1’ I0’ + Q2’ I0’ + Q1Q0’ 2+2+2+3=9 D1 = Q1Q2’ + Q2Q1’ + Q2’ I0 2+2+2+3=9 D0 = Q2Q1’I0’ + Q2’Q0’ I0 + Q1Q2’I0’ 3+3+3+3=12 Z0 = Q2’Q0 + Q2Q1’ 2+2=4 Z1 = Q1Q0’ + Q2Q1’ 2=2

Total 36

Equation (Asgn #3) Cost D2 = Q1’ 0 D1 = Q2 + Q0 + Q1’ 3 D0 = Q2I0+ Q1’I0’ 2+2+2=6 Z0 = Q2 0 Z1 = Q0 0

Total 9

36

13 9

Page 102: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

102

State of the Art for State Assignment

G. De Micheli, R. K. Brayton, and A. Sangiovanni- Vicentelli, “Optimal State Assignment for Finite State Machines,” IEEE Transactions on Computer Aided Design of Integrated Circuit Systems, vol. 4, pp. 269-284, July 1985.S. Devadas, H.-K. T. Ma, A. R. Newton, and A. Sangiovanni-Vicentelli, “Mustang: State Assignment of finite state machines for optimal multi-level logic implementations,” in International Conference on Computer Aided Design, pp. 16-19, 1987. (KISS - Keep Internal State Simple)

Page 103: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

103

State of the Art for State Assignment

D. Varma and E. A. Trachtenberg, “A fast algorithm for the optimal assignment of large finite state machines,” in International Conference on Computer Aided Design, pp. 152-155, 1988.T. Villa and A. Sangiovanni-Vicentelli, “NOVA: State assignment of finite state machines for optimal two-level logic implementation,” IEEE Transactions on Computer Aided Design of Integrated Circuit Systems, vol. 9, pp. 905-924, Sept. 1990.

Page 104: CMPUT 329 - Computer Organization and Architecture II1 CMPUT329 - Fall 2003 Topic C: State Assignment José Nelson Amaral

CMPUT 329 - Computer Organization and Architecture II

104

Where to find papers?

To find papers on the subject, search for thekeyword “state assignment” in citations of the site:

http://www.scienceindex.com

You can use this site for any subject ofyour interest within Computing Science.