Вы находитесь на странице: 1из 101

Computer Architecture

Nguy n Tr Thnh
Information Systems Department Faculty of Technology College of Technology ntthanh@vnu.edu.vn

11/12/2010

More on the Processor

11/12/2010

Instruction Execution
PC instruction memory, fetch instruction Register numbers register file, read registers Depending on instruction class
Use ALU to calculate Arithmetic result Memory address for load/store Branch target address Access data memory for load/store PC target address or PC + 4

11/12/2010

Implementing MIPS
We're ready to look at an implementation of the MIPS instruction set Simplified to contain only
arithmetic-logic instructions: add, sub, and, or, slt memory-reference instructions: lw, sw control-flow instructions: beq, j
6 bits 5 bits 5 bits 5 bits 5 bits 6 bits

op
6 bits

rs
5 bits

rt
5 bits

rd

shamt funct
16 bits

R-Format

op
6 bits
11/12/2010

rs

rt
26 bits

offset

I-Format J-Format
4

op

address

ALU Control
ALU used for
Load/Store: F = add Branch: F = subtract R-type: F depends on funct field
ALU control 0000 0001 0010 0110 0111 1100
11/12/2010

Function AND OR add subtract set-on-less-than NOR


5

ALU Control
Assume 2-bit ALUOp derived from opcode
Combinational logic derives ALU control
opcode lw sw beq R-type ALUOp 00 00 01 10 Operation load word store word branch equal add subtract AND OR set-on-less-than funct XXXXXX XXXXXX XXXXXX 100000 100010 100100 100101 101010 ALU function add add subtract add subtract AND OR set-on-less-than ALU control 0010 0010 0110 0010 0110 0000 0001 0111

11/12/2010

Implementing MIPS: the Fetch/Execute Cycle


High-level abstract view of fetch/execute implementation
use the program counter (PC) to read instruction address fetch the instruction from memory and increment PC use fields of the instruction to select registers to read execute depending on the instruction repeat
Data Register # PC Address Instruction memory Instruction Registers Register # Register # Data ALU Address Data memory

11/12/2010

Overview: Processor Implementation Styles


Single Cycle perform each instruction in 1 clock cycle clock cycle must be long enough for slowest instruction; therefore, disadvantage: only as fast as slowest instruction Multi-Cycle break fetch/execute cycle into multiple steps perform 1 step in each clock cycle advantage: each instruction uses only as many cycles as it needs Pipelined execute each instruction in multiple steps perform 1 step / instruction in each clock cycle 11/12/2010 process multiple instructions in parallel assembly line

Single-cycle Implementation of MIPS


Our first implementation of MIPS will use a single long clock cycle for every instruction This approach is not practical as it is much slower than a multicycle implementation where different instruction classes can take different numbers of cycles in a single-cycle implementation every instruction must take the same amount of time as the slowest instruction in a multicycle implementation this problem is avoided by allowing quicker instructions to use fewer cycles
11/12/2010 9

Datapath: Instruction Store/Fetch & PC Increment

Instruction address PC Instruction Instruction memory Add Sum

Add 4 Read address Instruction

PC
a. Instruction memory b. Program counter c. Adder

Three elements used to store and fetch instructions and increment the PC

Instruction memory

Datapath
11/12/2010 10

Animating the Datapath

Instruction <- MEM[PC] PC <- PC + 4


ADD
4

PC
ADDR

Memory

RD

Instruction

11/12/2010

11

Datapath: R-Type Instruction

5 Register numbers 5 5

Read register 1 Read register 2 Registers Write register Write data

3 Read data 1 Data Read data 2

ALU control

Read register 1 Instruction

3 Read

ALU operation

ALU

Zero ALU result

Data

RegWrite a. Registers b. ALU

data 1 Read register 2 Registers Write register Read data 2 Write data RegWrite

Zero ALU ALU result

Two elements used to implement R-type instructions

Datapath

11/12/2010

12

Animating the Datapath

Instruction op rs
5

add rd, rs, rt


rt
5

rd
5

shamt funct
Operation
3

R[rd] <- R[rs] + R[rt];

RN1

RN2

Register File
WD

WN RD1

ALU

Zero

RD2 RegWrite

11/12/2010

13

Datapath: Load/Store Instruction

MemWrite
Instruction

Read register 1 Read register 2 Registers Write register Write data RegWrite 16

3 Read data 1

ALU operation MemWrite

Address

Read data Data memory

16

Write data

Sign extend

32

Zero ALU ALU result Read data 2

Address

Read data Data memory

Write data Sign extend 32

MemRead a. Data memory unit b. Sign-extension unit

MemRead

Two additional elements used To implement load/stores


11/12/2010

Datapath
14

Animating the Datapath


op rs rt offset/immediate
16 5 5 5

lw rt, offset(rs)

R[rt] <- MEM[R[rs] + s_extend(offset)];


Operation
3

RN1

RN2

Register File
WD

WN RD1

ALU

Zero

RD2 RegWrite E X T N D

MemWrite ADDR WD
32

Memory

RD

16

MemRead
15

11/12/2010

Animating the Datapath


op rs rt offset/immediate
16 5 5 5

sw rt, offset(rs)

MEM[R[rs] + sign_extend(offset)] <- R[rt]


Operation
3

RN1

RN2

Register File
WD

WN RD1

ALU

Zero

RD2 RegWrite E X T N D

MemWrite ADDR WD
32

Memory

RD

16

MemRead
16

11/12/2010

Datapath: Branch Instruction


PC + 4 from instruction datapath

No shift hardware required: simply connect wires from input to output, each shifted left 2 bits
Read register 1 Read register 2 Registers Write register Write data RegWrite 16 Sign extend 32

Add Sum Shift left 2 3 Read data 1 ALU Zero Read data 2

Branch target

ALU operation

Instruction

To branch control logic

11/12/2010

Datapath

17

Animating the Datapath


op rs rt offset/immediate
16 5 5

PC +4 from instruction datapath

ADD

Operation

<<2
RN1 RN2

Register File
WD

WN RD1

ALU

Zero

RD2 RegWrite E X T N D

16

32

beq rs, rt, offset


if (R[rs] == R[rt]) then PC <- PC+4 + s_extend(offset<<2) 18

11/12/2010

Animating the Datapath: R-type Instruction


Instruction
32 16 5 5 5

add rd,rs,rt
Operation
3

RN1

RN2

Register File
WD

WN RD1

ALU
M U X

Zero

RD2 RegWrite E X T N D

MemWrite ADDR

MemtoReg RD
M U X

16

32

ALUSrc

Data Memory
WD MemRead

11/12/2010

19

Animating the Datapath: Load Instruction


Instruction
32 16 5 5 5

lw rt,offset(rs)
Operation
3

RN1

RN2

Register File
WD

WN RD1

ALU
M U X

Zero

RD2 RegWrite E X T N D

MemWrite ADDR

MemtoReg RD
M U X

16

32

ALUSrc

Data Memory
WD MemRead

11/12/2010

20

Animating the Datapath: Store Instruction


Instruction
32 16 5 5 5

sw rt,offset(rs)
Operation
3

RN1

RN2

Register File
WD

WN RD1

ALU
M U X

Zero

RD2 RegWrite E X T N D

MemWrite ADDR

MemtoReg RD
M U X

16

32

ALUSrc

Data Memory
WD MemRead

11/12/2010

21

Datapath Executing add

ADD ADD ADD


M U X

PC
ADDR RD

Instruction Instruction Memory


32 16 5 5 5

<<2
Operation
3

PCSrc

RN1

RN2

Register File
WD

WN RD1

ALU
M U X

Zero

RD2 RegWrite E X T N D

MemWrite ADDR

MemtoReg RD
M U X

16

32

ALUSrc

Data Memory
WD MemRead

add rd, rs, rt


11/12/2010

22

Datapath Executing lw

ADD ADD ADD


M U X

PC
ADDR RD

Instruction Instruction Memory


32 16 5 5 5

<<2
Operation
3

PCSrc

RN1

RN2

Register File
WD

WN RD1

ALU
M U X

Zero

RD2 RegWrite E X T N D

MemWrite ADDR

MemtoReg RD
M U X

16

32

ALUSrc

Data Memory
WD MemRead

lw rt,offset(rs)
11/12/2010

23

Datapath Executing sw

ADD ADD ADD


M U X

PC
ADDR RD

Instruction Instruction Memory


32 16 5 5 5

<<2
Operation
3

PCSrc

RN1

RN2

Register File
WD

WN RD1

ALU
M U X

Zero

RD2 RegWrite E X T N D

MemWrite ADDR

MemtoReg RD
M U X

16

32

ALUSrc

Data Memory
WD MemRead

sw rt,offset(rs)
11/12/2010

24

Datapath Executing beq

ADD ADD ADD


M U X

PC
ADDR RD

Instruction Instruction Memory


32 16 5 5 5

<<2
Operation
3

PCSrc

RN1

RN2

Register File
WD

WN RD1

ALU
M U X

Zero

RD2 RegWrite E X T N D

MemWrite ADDR

MemtoReg RD
M U X

16

32

ALUSrc

Data Memory
WD MemRead

beq r1,r2,offset
11/12/2010

25

Control
Control unit takes input from
the instruction opcode bits

Control unit generates


ALU control input write enable (possibly, read enable also) signals for each storage element selector controls for each multiplexor

11/12/2010

26

ALU Control
Plan to control ALU: main control sends a 2-bit ALUOp control field to the ALU control. Based on ALUOp and funct field of instruction the ALU control generates the 3-bit ALU control field
ALU control field 000 001 010 110 111 Function and or add sub slt
Recall
Main Control

2 ALUOp ALU Control 3 ALU control input To ALU

6 Instruction funct field

ALU must perform

add for load/stores (ALUOp 00) sub for branches (ALUOp 01) one of and, or, add, sub, slt for R-type instructions, depending on the instructions 6-bit funct field (ALUOp 10)
11/12/2010 27

Setting ALU Control Bits


Instruction AluOp Instruction Funct Field Desired ALU control opcode operation ALU action input
LW SW Branch eq R-type R-type R-type R-type R-type 00 00 01 10 10 10 10 10 load word store word branch eq add subtract AND OR set on less xxxxxx xxxxxx xxxxxx 100000 100010 100100 100101 101010 add add subtract add subtract and or set on less 010 010 110 010 110 000 001 111

11/12/2010

ALUOp Funct field Operation ALUOp1 ALUOp0 F5 F4 F3 F2 F1 F0 0 0 X X X X X X 010 0 1 X X X X X X 110 1 X X X 0 0 0 0 010 1 X X X 0 0 1 0 110 1 X X X 0 1 0 0 000 1 X X X 0 1 0 1 001 1 X X X 1 0 1 0 111 Truth table for ALU control bits

28

Designing the Main Control


R-type opcode 31-26 Load/store or branch rs 25-21 rt 20-16 rd 15-11 shamt 10-6 funct 5-0

opcode 31-26

rs 25-21

rt 20-16

address 15-0

Observations about MIPS instruction format


opcode is always in bits 31-26 two registers to be read are always rs (bits 25-21) and rt (bits 20-16) base register for load/stores is always rs (bits 25-21) 16-bit offset for branch equal and load/store is always bits 15-0 destination register for loads is in bits 20-16 (rt) while for R-type instructions it is in bits 15-11 (rd) (will require multiplexor to select)
11/12/2010 29

Datapath with Control I


PCSrc 1 M u x 0 Add 4 ALU Add result RegWrite Read register 1 Read register 2 Shift left 2

New multiplexor
Instruction [25 21] PC Read address Instruction [31 0] Instruction memory Instruction [20 16] 1 M u Instruction [15 11] x 0 RegDst Instruction [15 0]

Read data 1

MemWrite ALUSrc 1 M u x 0 32 ALU control Zero ALU ALU result MemtoReg Address Read data 1 M u x 0

Read Write data 2 register Write Registers data 16 Sign extend

Write data

Data memory

MemRead

Instruction [5 0] ALUOp

Adding control to the MIPS Datapath III (and a new multiplexor to select field to specify destination register): what are the functions of the 9 control signals?
11/12/2010 30

Datapath with Control II


0 M u x ALU Add result Add 4 Instruction [31 26] RegDst Branch MemRead MemtoReg ALUOp MemWrite ALUSrc RegWrite Read register 1 Shift left 2 1 PCSrc

Control

Instruction [25 21] PC Read address Instruction [31 0] Instruction memory Instruction [15 11] Instruction [20 16] 0 M u x 1

Read data 1 Read register 2 Registers Read Write data 2 register Write data

0 M u x 1

Zero ALU ALU result

Address

Read data Data memory

Write data Instruction [15 0] 16 Sign extend 32 ALU control

1 M u x 0

Instruction [5 0]

MIPS datapath with the control unit: input to control is the 6-bit instruction opcode field, output is seven 1-bit signals and the 2-bit ALUOp signal 11/12/2010

31

0 M u x ALU Add result Add 4 Instruction [31 26] RegDst Branch MemRead MemtoReg ALUOp MemWrite ALUSrc RegWrite Read register 1 Shift left 2 1

PCSrc cannot be set directly from the opcode: zero test outcome is required
PCSrc

Control

Instruction [25 21] PC Read address Instruction [31 0] Instruction memory Instruction [15 11] Instruction [20 16] 0 M u x 1

Read data 1 Read register 2 Registers Read Write data 2 register Write data

0 M u x 1

Zero ALU ALU result

Address

Read data Data memory

Write data

1 M u x 0

Datapath with Control II (cont.)

Instruction [15 0]

16

Sign extend

32 ALU control

Instruction [5 0]

Determining control signals for the MIPS datapath based on instruction opcode
Memto- Reg Mem Mem Instruction RegDst ALUSrc Reg Write Read Write Branch ALUOp1 ALUp0 R-format 1 0 0 1 0 0 0 1 0 lw 0 1 1 1 1 0 0 0 0 sw X 1 X 0 0 1 0 0 0 11/12/2010 beq X 0 X 0 0 0 1 0 1

32

Control Signals: R-Type Instruction


ADD ADD ADD rs rt rd I[25:21] I[20:16] I[15:11] 1 0
M U X

PC
ADDR RD

Instruction Instruction Memory

<<2
0
5
MUX

PCSrc

I 32
16 5

??? RegDst Operation

Value depends on

funct

RN1

RN2

Register File
WD immediate/ offset I[15:0]

WN RD1 0 RD2
M U X

ALU

Zero

0
MemtoReg 1 RD 0
M U X

RegWrite

MemWrite ADDR

1
Control signals shown in blue
11/12/2010

16

E X T N D

1
32

ALUSrc

Data Memory
WD MemRead

0
33

Control Signals: lw Instruction


ADD ADD ADD rs rt rd I[25:21] I[20:16] I[15:11] 1

0
M U X

PC
ADDR RD

Instruction Instruction Memory

<<2
0
5
MUX

PCSrc

I 32
16 5

RegDst Operation

010
3

RN1

RN2

Register File
WD immediate/ offset I[15:0]

WN RD1 0 RD2
M U X

ALU

Zero

0
MemtoReg 1 RD 0
M U X

RegWrite

MemWrite ADDR

1
Control signals shown in blue
11/12/2010

16

E X T N D

1
32

ALUSrc

Data Memory
WD MemRead

1
34

Control Signals: sw Instruction

ADD ADD ADD rs rt rd I[25:21] I[20:16] I[15:11]

0
M U X

PC
ADDR RD

Instruction Instruction Memory

<<2
0
5
MUX

PCSrc

I 32
16 5

0
1 RegDst Operation

010
3

RN1

RN2

Register File
WD immediate/ offset I[15:0]

WN RD1 0 RD2
M U X

ALU

Zero

1
MemtoReg 1 RD 0
M U X

RegWrite

MemWrite ADDR

0
Control signals shown in blue
11/12/2010

16

E X T N D

1
32

ALUSrc

Data Memory
WD MemRead

0
35

Control Signals: beq Instruction


ADD ADD ADD rs rt rd I[25:21] I[20:16] I[15:11] 1

0
M U X

PC
ADDR RD

Instruction Instruction Memory

<<2
0
5
MUX

PCSrc

I 32
16 5

1 if Zero=1
1 RegDst Operation

110
3

RN1

RN2

Register File
WD immediate/ offset I[15:0]

WN RD1 0 RD2
M U X

ALU

Zero

0
MemtoReg 1 RD 0
M U X

RegWrite

MemWrite ADDR

0
Control signals shown in blue
11/12/2010

16

E X T N D

1
32

ALUSrc

Data Memory
WD MemRead

0
36

Datapath with Control III


Jump opcode 31-26 Composing jump target address
Instruction [25 0] 26 Shift left 2

address 25-0 New multiplexor with additional control bit Jump

Jump address [31 0] 28 0 M u x ALU Add result 1 1 M u x 0

PC+4 [31 28]

Add 4 Instruction [31 26] Control

RegDst Jump Branch MemRead MemtoReg ALUOp MemWrite ALUSrc RegWrite Read register 1

Shift left 2

Instruction [25 21] PC Read address Instruction [31 0] Instruction memory Instruction [15 11] Instruction [20 16] 0 M u x 1

Read data 1 Read register 2 Registers Read Write data 2 register Write data

0 M u x 1

Zero ALU ALU result

Address

Read data Data memory

Write data Instruction [15 0] 16 Sign extend 32 ALU control

1 M u x 0

Instruction [5 0]

11/12/2010

37

MIPS datapath extended to jumps: control unit generates new Jump control bit

Datapath Executing j

jmpaddr I[25:0] ADD


26

28

32

<<2

CONCAT PC+4[31-28] 0 ADD ADD ALU Control


M U X

1
M U X

Control Unit

ALUOp
2

0 Jump

PC
ADDR RD op 6 I[31:26]
32 funct 6 I[5:0] 5
MUX

<<2 Instruction Memory


Instruction I
16 5

1 PCSrc

0
5

1 RegDst Operation
3

Branch Zero

RN1
op I[31:

RN2

Register File
WD

WN RD1 0 RD2
M U X

ALU

RegWrite E X T N D 1
32

MemWrite ADDR

MemtoReg 1 RD 0
M U X

16

ALUSrc

Data Memory
WD MemRead

11/12/2010

38

R-type Instruction: Step 1 add $t1, $t2, $t3 (active = bold)


0 M u x Add Add 4 Instruction [31 26] RegDst Branch MemRead MemtoReg ALUOp MemWrite ALUSrc RegWrite Read register 1 Shift left 2 ALU result 1

Control

Instruction [25 21] PC Read address Instruction [31 0] Instruction memory Instruction [15 11] Instruction [20 16] 0 M u x 1

Read data 1 Read register 2 Registers Read Write data 2 register Write data

0 M u x 1

Zero ALU ALU result

Address

Read data Data memory

Write data Instruction [15 0] 16 Sign extend 32 ALU control

1 M u x 0

Instruction [5 0]

11/12/2010

39

Fetch instruction and increment PC count

R-type Instruction: Step 2 add $t1, $t2, $t3 (active = bold)


0 M u x ALU Add result Add 4 Instruction [31 26] RegDst Branch MemRead MemtoReg ALUOp MemWrite ALUSrc RegWrite Read register 1 Shift left 2 1

Control

Instruction [25 21] PC Read address Instruction [31 0] Instruction memory Instruction [15 11] Instruction [20 16] 0 M u x 1

Read data 1 Read register 2 Registers Read Write data 2 register Write data

0 M u x 1

Zero ALU ALU result

Address

Read data Data memory

Write data Instruction [15 0] 16 Sign extend 32 ALU control

1 M u x 0

Instruction [5 0]

11/12/2010

40

Read two source registers from the register file

R-type Instruction: Step 3 add $t1, $t2, $t3 (active = bold)


0 M u x Add Add 4 Instruction [31 26] RegDst Branch MemRead MemtoReg ALUOp MemWrite ALUSrc RegWrite Read register 1 Shift left 2 ALU result 1

Control

Instruction [25 21] PC Read address Instruction [31 0] Instruction memory Instruction [15 11] Instruction [20 16] 0 M u x 1

Read data 1 Read register 2 Registers Read Write data 2 register Write data

0 M u x 1

Zero ALU ALU result

Address

Read data Data memory

Write data Instruction [15 0] 16 Sign extend 32 ALU control

1 M u x 0

Instruction [5 0]

11/12/2010

ALU operates on the two register operands

41

R-type Instruction: Step 4 add $t1, $t2, $t3 (active = bold)


0 M u x ALU Add result Add 4 Instruction [31 26] RegDst Branch MemRead MemtoReg ALUOp MemWrite ALUSrc RegWrite Read register 1 Shift left 2 1

Control

Instruction [25 21] PC Read address Instruction [31 0] Instruction memory Instruction [15 11] Instruction [20 16] 0 M u x 1

Read data 1 Read register 2 Registers Read Write data 2 register Write data

0 M u x 1

Zero ALU ALU result

Address

Read data Data memory

Write data Instruction [15 0] 16 Sign extend 32 ALU control

1 M u x 0

Instruction [5 0]

11/12/2010

42

Write result to register

Load Instruction Steps lw $t1, offset($t2)


1. 2.

3.

4.

5.

Fetch instruction and increment PC Read base register from the register file: the base register ($t2) is given by bits 25-21 of the instruction ALU computes sum of value read from the register file and the sign-extended lower 16 bits (offset) of the instruction The sum from the ALU is used as the address for the data memory The data from the memory unit is written into the register file: the destination register ($t1) is given by bits 20-16 of the instruction
43

11/12/2010

Load Instruction lw $t1, offset($t2)


0 M u x ALU Add result Add 4 Instruction [31 26] RegDst Branch MemRead MemtoReg ALUOp MemWrite ALUSrc RegWrite Read register 1 Shift left 2 1

Control

Instruction [25 21] PC Read address Instruction [31 0] Instruction memory Instruction [15 11] Instruction [20 16] 0 M u x 1

Read data 1 Read register 2 Registers Read Write data 2 register Write data

0 M u x 1

Zero ALU ALU result

Address

Read data Data memory

Write data Instruction [15 0] 16 Sign extend 32 ALU control

1 M u x 0

Instruction [5 0]

11/12/2010

44

Branch Instruction Steps beq $t1, $t2, offset


1. 2. 3.

4.

Fetch instruction and increment PC Read two register ($t1 and $t2) from the register file ALU performs a subtract on the data values from the register file; the value of PC+4 is added to the sign-extended lower 16 bits (offset) of the instruction shifted left by two to give the branch target address The Zero result from the ALU is used to decide which adder result (from step 1 or 3) to store in the PC
45

11/12/2010

Branch Instruction beq $t1, $t2, offset


0 M u x ALU Add result Add 4 Instruction [31 26] RegDst Branch MemRead MemtoReg ALUOp MemWrite ALUSrc RegWrite Read register 1 Shift left 2 1

Control

Instruction [25 21] PC Read address Instruction [31 0] Instruction memory Instruction [15 11] Instruction [20 16] 0 M u x 1

Read data 1 Read register 2 Registers Read Write data 2 register Write data

0 M u x 1

Zero ALU ALU result

Address

Read data Data memory

Write data Instruction [15 0] 16 Sign extend 32 ALU control

1 M u x 0

11/12/2010

Instruction [5 0]

46

Implementation: ALU Control Block


ALUOp Funct field Operation ALUOp1 ALUOp0 F5 F4 F3 F2 F1 F0 0 0 X X X X X X 010 0 1 X X X X X X 110 1 X X X 0 0 0 0 010 1 X X X 0 0 1 0 110 1 X X X 0 1 0 0 000 1 X X X 0 1 0 1 001 1 X X X 1 0 1 0 111 Truth table for ALU control bits
ALUOp ALU control block ALUOp0 ALUOp1

F3 F2 F (5 0) F1

Operation2 Operation1 Operation0 Operation

F0

11/12/2010

ALU control logic

47

Implementation: Main Control Block


Inputs Op5 Op4 Op3 Op2 Op1 Op0

Signal name Inputs

Rlw format
0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 1 0 0 0 1 1 0 1 1 1 1 0 0 0 0

sw
1 0 1 0 1 1 x 1 x 0 0 1 0 0 0

beq
0 0 0 1 0 0 x 0 x 0 0 0 1 0 1

Op5 Op4 Op3 Op2 Op1 Op0 RegDst ALUSrc MemtoReg RegWrite MemRead MemWrite Branch ALUOp1 ALUOP2
11/12/2010

Outputs R-format Iw sw beq RegDst ALUSrc MemtoReg RegWrite MemRead MemWrite Branch ALUOp1 ALUOpO

Outputs

Truth table for main control signals

Main control PLA (programmable logic array): principle underlying PLAs is that any logical expression 48 can be written as a sum-of-products

Multicycle Approach
Break up the instructions into steps
each step takes one clock cycle balance the amount of work to be done in each step/cycle so that they are about equal restrict each cycle to use at most once each major functional unit so that such units do not have to be replicated functional units can be shared between different cycles within one instruction

Between steps/cycles
At the end of one cycle store data to be used in later cycles of the same instruction need to introduce additional internal (programmer-invisible) registers for this purpose Data to be used in later instructions are stored in programmervisible state elements: the register file, PC, memory
11/12/2010 49

Multicycle Approach
PCSrc Add 4 Shift left 2 Registers Read register 1 Read Read data 1 register 2 Write register Write data RegWrite 16 Read data 2 3 ALU operation MemWrite MemtoReg Address Read data Add ALU result M u x

Note particularities of multicyle vs. singlediagrams

PC

Read address Instruction Instruction memory

ALUSrc

M u x

Zero ALU ALU result

single memory for data and instructions single ALU, no extra adders extra registers to hold data between clock cycles
PC Address Memory

Write data Sign extend 32

Data memory

M u x

MemRead

Single-cycle datapath

Instruction register

Data A Register #

Instruction or data Memory data register

Registers Register # B Register #

ALU

ALUOut

Data

11/12/2010

50

Multicycle datapath (high-level view)

Multicycle Datapath

PC

0 M u x 1

Address
Memory MemData Write data

Instruction [25 21] Instruction [20 16] Instruction [15 0] Instruction register Instruction [15 0] Memory data register 0 M Instruction u x [15 11] 1 0 M u x 1 16

Read register 1 Read Read register 2 data 1 Registers Write Read register data 2 Write data A

0 M u x 1

Zero ALU ALU result

ALUOut

B 4

0 1 M u 2 x 3

Sign extend

32

Shift left 2

Basic multicycle MIPS datapath handles R-type instructions and load/stores: new internal register in red ovals, new multiplexors in blue ovals
11/12/2010 51

Breaking instructions into steps


Our goal is to break up the instructions into steps so that
each step takes one clock cycle the amount of work to be done in each step/cycle is about equal each cycle uses at most once each major functional unit so that such units do not have to be replicated functional units can be shared between different cycles within one instruction

Data at end of one cycle to be used in next must be stored !!


11/12/2010 52

Breaking instructions into steps


We break instructions into the following potential execution steps not all instructions require all the steps each step takes one clock cycle
1. 2. 3.

4. 5.

Instruction fetch and PC increment (IF) Instruction decode and register fetch (ID) Execution, memory address computation, or branch completion (EX) Memory access or R-type instruction completion (MEM) Memory read completion (WB)

Each MIPS instruction takes from 3 5 cycles (steps)


11/12/2010 53

Step 1: Instruction Fetch & PC Increment (IF)


Use PC to get instruction and put it in the instruction register. Increment the PC by 4 and put the result back in the PC. Can be described succinctly using RTL (Register-Transfer Language): IR = Memory[PC]; PC = PC + 4;

11/12/2010

54

Step 2: Instruction Decode and Register Fetch (ID)


Read registers rs and rt in case we need them. Compute the branch address in case the instruction is a branch. RTL: A = Reg[IR[25-21]]; B = Reg[IR[20-16]]; ALUOut = PC + (sign-extend(IR[15-0]) << 2);
11/12/2010 55

Step 3: Execution, Address Computation or Branch Completion (EX)


ALU performs one of four functions depending on instruction type
memory reference: ALUOut = A + sign-extend(IR[15-0]); R-type: ALUOut = A op B; branch (instruction completes): if (A==B) PC = ALUOut; jump (instruction completes): PC = PC[31-28] || (IR(25-0) << 2)
11/12/2010 56

Step 4: Memory access or R-type Instruction Completion (MEM)


Again depending on instruction type: Loads and stores access memory
load MDR = Memory[ALUOut]; store (instruction completes) Memory[ALUOut] = B;

R-type (instructions completes) Reg[IR[15-11]] = ALUOut;


11/12/2010 57

Step 5: Memory Read Completion (WB)


Again depending on instruction type: Load writes back (instruction completes) Reg[IR[20-16]]= MDR; Important: There is no reason from a datapath (or control) point of view that Step 5 cannot be eliminated by performing Reg[IR[20-16]]= Memory[ALUOut]; for loads in Step 4. This would eliminate the MDR as well. The reason this is not done is that, to keep steps balanced in length, the design restriction is to allow each step to contain at most one ALU operation, or one register access, or one memory access.
11/12/2010 58

Summary of Instruction Execution

Step 1: IF 2: ID 3: EX 4:

Step name Instruction fetch Instruction decode/register fetch Execution, address computation, branch/ jump completion

Action for R-type instructions

Action for memory-reference Action for instructions branches IR = Memory[PC] PC = PC + 4 A = Reg [IR[25-21]] B = Reg [IR[20-16]] ALUOut = PC + (sign-extend (IR[15-0]) << 2) ALUOut = A + sign-extend (IR[15-0]) Load: MDR = Memory[ALUOut] or Store: Memory [ALUOut] = B Load: Reg[IR[20-16]] = MDR if (A ==B) then PC = ALUOut

Action for jumps

ALUOut = A op B

PC = PC [31-28] II (IR[25-0]<<2)

Memory access or R-type MEM completion Memory read completion

Reg [IR[15-11]] = ALUOut

5: WB

11/12/2010

59

Multicycle Execution Step (1): Instruction Fetch


IR = Memory[PC]; PC = PC + 4;

I R PC
MemWrite ADDR

Instruction I
5 5 5

Operation
3

RN1

RN2

WN RD1

Memory
RD

PC + 4

WD MemRead

M D R

Registers
WD

A ALU

Zero
ALU OUT

RD2 RegWrite

11/12/2010

60

Multicycle Execution Step (2): Instruction Decode & Register Fetch


A = Reg[IR[25-21]]; (A = Reg[rs]) B = Reg[IR[20-15]]; (B = Reg[rt]) ALUOut = (PC + sign-extend(IR[15-0]) << 2)

I R PC
MemWrite ADDR

Instruction I
5 5 5

Reg[rs]
A

Operation
3

RN1

RN2

WN RD1

Branch Target Address


ALU OUT

Memory
RD

PC + 4

WD MemRead

M D R

Registers
WD

Zero

ALU
RD2

RegWrite

Reg[rt]

11/12/2010

61

Multicycle Execution Step (3): Memory Reference Instructions


ALUOut = A + sign-extend(IR[15-0]);

I R PC
MemWrite ADDR

Instruction I
5 5 5

Reg[rs]
A

Operation
3

RN1

RN2

WN RD1

Mem. Address
ALU OUT

Memory
RD

PC + 4

WD MemRead

M D R

Registers
WD

Zero

ALU
RD2

RegWrite

Reg[rt]

11/12/2010

62

Multicycle Execution Step (3): ALU Instruction (R-Type)


ALUOut = A op B

I R PC
MemWrite ADDR

Instruction I
5 5 5

Reg[rs]
A

Operation
3

RN1

RN2

WN RD1

Memory
RD

PC + 4

WD MemRead

M D R

Registers
WD

Zero

R-Type Result
ALU OUT

ALU
RD2

RegWrite

Reg[rt]

11/12/2010

63

Multicycle Execution Step (3): Branch Instructions


if (A == B) PC = ALUOut;

I R PC
MemWrite ADDR

Instruction I
5 5 5

Reg[rs]
A

Operation
3

RN1

RN2

WN RD1

Memory

Branch Target Address

RD WD MemRead

M D R

Registers
WD

Zero

Branch Target Address


ALU OUT

ALU
RD2

RegWrite

Reg[rt]

11/12/2010

64

Multicycle Execution Step (3): Jump Instruction


PC = PC[31-28] concat (IR[25-0] << 2)

I R PC
MemWrite ADDR

Instruction I
5 5 5

Reg[rs]
A

Operation
3

RN1

RN2

WN RD1

Memory

Jump Address

RD WD MemRead

M D R

Registers
WD

Zero

Branch Target Address


ALU OUT

ALU
RD2

RegWrite

Reg[rt]

11/12/2010

65

Multicycle Execution Step (4): Memory Access - Read (lw)


MDR = Memory[ALUOut];

I R PC
MemWrite ADDR

Instruction I
5 5 5

Reg[rs]
A

Operation
3

RN1

RN2

WN RD1

Mem. Address
ALU OUT

Memory
RD

PC + 4

WD MemRead

M D R

Registers
WD

Zero

ALU
RD2

RegWrite

Mem. Data

Reg[rt]

11/12/2010

66

Multicycle Execution Step (4): Memory Access - Write (sw)


Memory[ALUOut] = B;

I R PC
MemWrite ADDR

Instruction I
5 5 5

Reg[rs]
A

Operation
3

RN1

RN2

WN RD1

Memory
RD

PC + 4

WD MemRead

M D R

Registers
WD

Zero

ALU
ALU OUT

RD2 RegWrite

Reg[rt]

11/12/2010

67

Multicycle Execution Step (4): ALU Instruction (R-Type)


Reg[IR[15:11]] = ALUOUT

I R PC
MemWrite ADDR

Instruction I
5 5 5

Reg[rs]
A

Operation
3

RN1

RN2

WN RD1

Memory
RD

PC + 4

WD MemRead

M D R

Registers
WD

Zero

R-Type Result
ALU OUT

ALU
RD2

RegWrite

Reg[rt]

11/12/2010

68

Multicycle Execution Step (5): Memory Read Completion (lw)


Reg[IR[20-16]] = MDR;

I R PC
MemWrite ADDR

Instruction I
5 5 5

Reg[rs]
A

Operation
3

RN1

RN2

WN RD1

Memory
RD

PC + 4

WD MemRead

M D R

Registers
WD

Zero

Mem. Address
ALU OUT

ALU
RD2

RegWrite

Mem. Data

Reg[rt]

11/12/2010

69

Multicycle Datapath with Control I


IorD MemRead MemWrite IRWrite RegDst RegWrite ALUSrcA

PC

0 M u x 1

Address Memory MemData Write data

Instruction [25 21] Instruction [20 16] Instruction [15 0] Instruction register Instruction [15 0] Memory data register 0 M Instruction u x [15 11] 1 0 M u x 1 16

Read register 1 Read Read data 1 register 2 Registers Write Read register data 2 Write data A

0 M u x 1 0 1 M u 2 x 3

B 4

Zero ALU ALU result

ALUOut

Sign extend

32

Shift left 2

ALU control

Instruction [5 0]

11/12/2010

MemtoReg

ALUSrcB ALUOp

70

with control lines and the ALU control block added not all control lines are shown

Multicycle Datapath with Control II


New gates For the jump address
PCWriteCond PCSource

New multiplexor

PCWrite Outputs ALUOp IorD ALUSrcB MemRead ALUSrcA Control MemWrite RegWrite MemtoReg Op RegDst IRWrite [5 0] Jump address [31-0]

Instruction [25 0] Instruction [31-26] Address Memory MemData Write data Instruction [25 21] Instruction [20 16] Instruction [15 0] Instruction register Instruction [15 0] Memory data register 0 M Instruction u x [15 11] 1 0 M u x 1 16 Sign extend 32 Shift left 2 Read register 1 Read Read register 2 data 1 Registers Write Read register data 2 Write data A 0 M u x 1 0 1 M u 2 x 3

26

Shift left 2

28

1 u
x 2

PC

0 M u x 1

PC [31-28]

B 4

Zero ALU ALU result

ALUOut

ALU control

Instruction [5 0]

11/12/2010

Complete multicycle MIPS datapath (with branch and jump capability) and showing the main control block and all control lines

71

Multicycle Control Step (1): Fetch


IR = Memory[PC]; PC = PC + 4; 1
IRWrite

1
PCWr* IorD

I R

Instruction I rs rt
5 5 5

jmpaddr rd 1
I[25:0]

28

32

<<2

CONCAT 2 1U 0
M X

0
MemWrite ADDR

32

MUX

RegDst

PC
0M
U 1X

X
A B
4

0 ALUSrcA
0M 1X
U

010 Operation
3

RN1

RN2

WN RD1

Memory
WD MemRead

RD

M D R

1M 0X MemtoReg
U

Registers
WD

Zero

PCSource

ALU
0 1M U 2X 3 ALUSrcB
ALU OUT

RD2

X 1
immediate

RegWrite

0
16

E X T N D

32

<<2

1
72

11/12/2010

Multicycle Control Step (2): Instruction Decode & Register Fetch


A = Reg[IR[25-21]]; (A = Reg[rs]) B = Reg[IR[20-15]]; (B = Reg[rt]) ALUOut = (PC + sign-extend(IR[15-0]) << 2);

0IRWrite
I R

0
PCWr*

Instruction I rs rt
5 5 5

jmpaddr rd 1
I[25:0]

28

32

<<2

CONCAT 2
M X

X
IorD 0M
U 1X

0
MemWrite ADDR

32

MUX

RegDst

PC Memory
WD MemRead MemtoReg

0
0M
U

ALUSrcA Operation
3

010

1U 0

RN1

RN2

WN RD1

RD

M D R

1M 0X
U

Registers
WD

A B
4

1X

Zero

PCSource

ALU
0 1M U 2X 3 ALUSrcB
ALU OUT

RD2

0
immediate

RegWrite

16

11/12/2010

E X T N D

32

<<2

73

Multicycle Control Step (3): Memory Reference Instructions


ALUOut = A + sign-extend(IR[15-0]);
IRWrite

0 PCWr*
IorD

I R

Instruction I rs rt
5 5 5

jmpaddr rd 1
I[25:0]

28

32

<<2

CONCAT 2
M X

0
MemWrite ADDR

32

MUX

RegDst

PC
0M
U 1X

X
A B
4

1 ALUSrcA
0M 1X
U

Operation
3

010
ALU

1U 0

RN1

RN2

WN RD1

Memory
WD MemRead

RD

M D R

1M 0X MemtoReg
U

Registers
WD

Zero
ALU OUT

PCSource

RD2

X 0
immediate

RegWrite
16

0 1M U 2X 3 ALUSrcB

E X T N D

32

<<2

2
74

11/12/2010

Multicycle Control Step (3): ALU Instruction (R-Type)


ALUOut = A op B;
IRWrite

PCWr*

I R

Instruction I rs rt
5 5 5

jmpaddr rd 1
I[25:0]

28

32

<<2

CONCAT 2
M X

X
IorD 0M
U 1X

0
MemWrite ADDR

32

MUX

RegDst

PC Memory
WD MemRead MemtoReg

X
A B
4

1
0M 1X
U

ALUSrcA Operation
3

???
ALU

1U 0

RN1

RN2

WN RD1

RD

M D R

1M 0X
U

Registers
WD

Zero
ALU OUT

PCSource

RD2

X 0
immediate

RegWrite

0 1M U 2X 3 ALUSrcB

16

E X T N D

32

<<2

0
75

11/12/2010

Multicycle Control Step (3): Branch Instructions


if (A == B) PC = ALUOut;
IRWrite

1 if Zero=1 PCWr* X
IorD

I R

Instruction I rs rt
5 5 5

jmpaddr rd 1
I[25:0]

28

32

<<2

CONCAT 2
M X

0
MemWrite ADDR

32

MUX

RegDst

PC
0M
U 1X

X
A B
4

1
0M 1X
U

ALUSrcA Operation
3

011
ALU

1U 0

RN1

RN2

WN RD1

Memory
WD MemRead

RD

M D R

1M 0X MemtoReg
U

Registers
WD

Zero
ALU OUT

PCSource

RD2

X 0
immediate

RegWrite

0 1M U 2X 3 ALUSrcB

16

E X T N D

32

<<2

0
76

11/12/2010

Multicycle Execution Step (3): Jump Instruction


PC = PC[21-28] concat (IR[25-0] << 2);
IRWrite

1 PCWr*
PC

I R
IorD 0M
U 1X

Instruction I rs rt
5 5 5

jmpaddr rd 1
I[25:0]

28

32

<<2

CONCAT 2
M X

0
MemWrite ADDR

32

MUX

RegDst

X
A B
4

ALUSrcA Operation 0M 1X
U

XXX
3

1U 0

RN1

RN2

WN RD1

Memory
WD MemRead

RD

M D R

1M 0X MemtoReg
U

Registers
WD

Zero

PCSource
ALU OUT

ALU
0 1M U 2X 3 ALUSrcB

RD2

X 0
immediate

RegWrite
16

E X T N D

32

<<2

X
77

11/12/2010

Multicycle Control Step (4): Memory Access - Read (lw)


MDR = Memory[ALUOut];
IRWrite

PCWr*

I R

Instruction I rs rt
5 5 5

jmpaddr rd 1
I[25:0]

28

32

<<2

CONCAT 2
M X

1
IorD 0M
U 1X

0
MemWrite ADDR

32

MUX

RegDst

PC Memory
WD MemRead MemtoReg

X
A B
4

X
0M 1X
U

ALUSrcA Operation
3

XXX
ALU

1U 0

RN1

RN2

WN RD1

RD

M D R

1M 0X
U

Registers
WD

Zero
ALU OUT

PCSource

RD2

X 1
immediate

RegWrite

0 1M U 2X 3 ALUSrcB

0
16

E X T N D

32

<<2

X
78

11/12/2010

Multicycle Execution Steps (4) Memory Access - Write (sw)


Memory[ALUOut] = B;
IRWrite

0
Instruction I rs rt
5 5 5

0 PCWr*
PC

I R
IorD 0M
U 1X

jmpaddr rd 1
I[25:0]

28

32

<<2

CONCAT 2
M X

1
MemWrite ADDR

32

MUX

RegDst

X
A B
4

ALUSrcA Operation 0M 1X
U

XXX
3

1U 0

RN1

RN2

WN RD1

Memory
WD MemRead

RD

M D R

1M 0X MemtoReg
U

Registers
WD

Zero

PCSource
ALU OUT

ALU
0 1M U 2X 3 ALUSrcB

RD2

X 0
immediate

RegWrite
16

E X T N D

32

<<2

X
79

11/12/2010

Multicycle Control Step (4): ALU Instruction (R-Type)


Reg[IR[15:11]] = ALUOut;
IRWrite

(Reg[Rd] = ALUOut)

0 PCWr*
IorD

I R

Instruction I rs rt
5 5 5

jmpaddr
I[25:0]

28

32

<<2

CONCAT 2
M X

rd 1 RegDst

0
MemWrite ADDR

32

MUX

PC
0M
U 1X

1
A B
4

X ALUSrcA
0M 1X
U

Operation
3

XXX
Zero

1U 0

RN1

RN2

WN RD1

Memory
WD MemRead

RD

M D R

0M 1X MemtoReg
U

Registers
WD

PCSource
ALU OUT

ALU
0 1M U 2X 3 ALUSrcB

RD2

1 0
immediate

RegWrite
16

E X T N D

32

<<2

X
80

11/12/2010

Multicycle Execution Steps (5) Memory Read Completion (lw)


Reg[IR[20-16]] = MDR;
IRWrite

0
28 32

PCWr*

I R

Instruction I rs rt
5 5 5

jmpaddr
I[25:0]

<<2

CONCAT 2
M X

X
IorD 0M
U 1X

rd 1 RegDst

0
MemWrite ADDR

32

MUX

PC Memory
WD MemRead MemtoReg

0
A B
4

X
0M
U

ALUSrcA Operation
3

XXX
Zero

1U 0

RN1

RN2

WN RD1 1X

RD

M D R

0M 1X
U

Registers
WD

PCSource

ALU
0 1M U 2X 3 ALUSrcB

X
ALU OUT

RD2

0
immediate

RegWrite
16

E X T N D

32

<<2

X
81

11/12/2010

Simple Questions
How many cycles will it take to execute this code? lw $t2, 0($t3) lw $t3, 4($t3) beq $t2, $t3, Label #assume not equal add $t5, $t2, $t3 sw $t5, 8($t3) ...

Label:

What is going on during the 8th cycle of execution?

Clock time-line

In what cycle does the actual addition of $t2 and $t3 takes place?

11/12/2010

82

Implementing Control
Value of control signals is dependent upon:
what instruction is being executed which step is being performed

Use the information we have accumulated to specify a finite state machine


specify the finite state machine graphically, or use microprogramming

Implementation is then derived from the specification


11/12/2010 83

Review: Finite State Machines


Finite state machines (FSMs):
a set of states and next state function, determined by current state and the input output function, determined by current state and possibly input
Next state

Current state Clock Inputs

Next-state function

Output function

Outputs

Well use a Moore machine output based only on current state


11/12/2010 84

Example: Moore Machine


The Moore machine below, given input a binary string terminated by #, will output even if the string has an even number of 0s and odd if the string has an odd number of 0s
1 Even state No output Start # # 0 0 Odd state 1 No output

What is the the output of the string 100010 Build a FSM to recognize odd/even numbers

Output even Output even state


11/12/2010

Output odd Output odd state

85

FSM Control: High-level View


Start Instruction fetch/decode and register fetch (Figure 5.37)

Memory access instructions (Figure 5.38)

R-type instructions (Figure 5.39)

Branch instruction (Figure 5.40)

Jump instruction (Figure 5.41)

High-level view of FSM control


Instruction fetch 0 MemRead ALUSrcA = 0 IorD = 0 IRWrite ALUSrcB = 01 ALUOp = 00 PCWrite PCSource = 00
-t =R ype )
=

Instruction decode/ Register fetch 1 ALUSrcA = 0 ALUSrcB = 11 ALUOp = 00

Asserted signals shown inside state circles

Start

(Op

W = 'L

= 'S (Op ') or

Memory reference FSM (Figure 5.38)

R-type FSM (Figure 5.39)

Branch FSM (Figure 5.40)

(O

W')

(O

Jump FSM (Figure 5.41)

11/12/2010

(Op = 'JMP')

'B

EQ ')

Instruction fetch and decode steps of every instruction is identical

86

FSM Control: Memory Reference


From state 1 (Op = 'LW') or (Op = 'SW') Memory address computation 2 ALUSrcA = 1 ALUSrcB = 10 ALUOp = 00

(O

(Op = 'LW')

p = 'S ') W

Memory access 5

Memory access

3 MemRead IorD = 1

MemWrite IorD = 1

Write-back step 4 RegWrite MemtoReg = 1 RegDst = 0


11/12/2010

To state 0 (Figure 5.37)

87

FSM control for memory-reference has 4 states

FSM Control: R-type Instruction


From state 1 (Op = R-type) Execution 6 ALUSrcA = 1 ALUSrcB = 00 ALUOp = 10

R-type completion 7 RegDst = 1 RegWrite MemtoReg = 0

11/12/2010

To state 0 (Figure 5.37)

FSM control to implement R-type instructions has 2 states

88

FSM Control: Branch Instruction


From state 1 (Op = 'BEQ') Branch completion 8 ALUSrcA = 1 ALUSrcB = 00 ALUOp = 01 PCWriteCond PCSource = 01

To state 0 (Figure 5.37)

FSM control to implement branches has 1 state


11/12/2010 89

FSM Control: Jump Instruction


From state 1 (Op = 'J') Jump completion 9 PCWrite PCSource = 10

To state 0 (Figure 5.37)

FSM control to implement jumps has 1 state

11/12/2010

90

FSM Control: Complete View


Instruction fetch 0 Instruction decode/ register fetch

IF
Start

EQ (O p = 'B

')

MemRead ALUSrcA = 0 IorD = 0 IRWrite ALUSrcB = 01 ALUOp = 00 PCWrite PCSource = 00


')

ID

1 ALUSrcA = 0 ALUSrcB = 11 ALUOp = 00

Memory address computation 2


(Op

= (Op ') or W = 'L

'SW

Execution 6 ALUSrcA =1 ALUSrcB = 00 ALUOp = 10 8

e) - t yp =R (Op Branch completion

(Op = 'J')

Jump completion

9 ALUSrcA = 1 ALUSrcB = 00 ALUOp = 01 PCWriteCond PCSource = 01 PCWrite PCSource = 10

EX

ALUSrcA = 1 ALUSrcB = 10 ALUOp = 00

(O

(Op = 'LW')

p = 'S ') W

Memory access 5

Memory access 7 MemWrite IorD = 1

R-type completion

MEM

MemRead IorD = 1

RegDst = 1 RegWrite MemtoReg = 0

Labels on arcs are conditions that determine next state

Write-back step 4 RegDst = 0 RegWrite MemtoReg = 1

WB
11/12/2010

The complete FSM control for the multicycle MIPS datapath: 91 refer Multicycle Datapath with Control II

Example: CPI in a multicycle CPU


Assume
the control design of the previous slide An instruction mix of 22% loads, 11% stores, 49% R-type operations, 16% branches, and 2% jumps

What is the CPI assuming each step requires 1 clock cycle? Solution:
Number of clock cycles from previous slide for each instruction class:
loads 5, stores 4, R-type instructions 4, branches 3, jumps 3

CPI = CPU clock cycles / instruction count = (instruction countclass i CPIclass i) / instruction count = (instruction countclass I / instruction count) CPIclass I = 0.22 5 + 0.11 4 + 0.49 4 + 0.16 3 + 0.02 3 = 4.04
11/12/2010 92

FSM Control: Implementation

PCWrite PCWriteCond IorD MemRead MemWrite IRWrite Control logic MemtoReg PCSource ALUOp Outputs ALUSrcB ALUSrcA RegWrite RegDst NS3 NS2 NS1 NS0

Inputs

Op5

Op4

Op3

Op2

Op1

Op0

S3

S2

S1

Instruction register opcode field

State register

Four state bits are required for 10 states

High-level view of FSM implementation: inputs to the combinational logic block are the11/12/2010 state number and instruction opcode bits; outputs are the next state93 current number and control signals to be asserted for the current state

S0

Op5 Op4

FSM Control: PLA Implementation

Op3 Op2 Op1 Op0 S3 S2 S1 S0 PCWrite PCWriteCond IorD MemRead MemWrite IRWrite MemtoReg PCSource1 PCSource0 ALUOp1 ALUOp0 ALUSrcB1 ALUSrcB0 ALUSrcA RegWrite RegDst NS3 NS2 NS1 NS0

Upper half is the AND plane that computes all the products. The products are carried to the lower OR plane by the vertical lines. The sum terms for each output is given by the11/12/2010 corresponding horizontal line 94 E.g., IorD = S0.S1.S2.S3 + S0.S1.S2.S3

FSM Control: ROM Implementation


ROM (Read Only Memory)
values of memory locations are fixed ahead of time

A ROM can be used to implement a truth table


if the address is m-bits, we can address 2m entries in the ROM outputs are the bits of the entry the address points to
address output
0 0 0 m = 3 0 n = 4 1 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 0 1 1 1 0 0 0 0 0 1 1 0 0 0 1 1 1 0 0 0 0 0 1 1 1 0 0 0 0 1 0 1

ROM

The size of an m-input n-output ROM is 2m x n bits such a ROM can be thought of as an array of size 2m with each entry in the array being 11/12/2010 n bits

95

FSM Control: ROM vs. PLA


First improve the ROM: break the table into two parts
4 state bits give the 16 output signals 24 x 16 bits of ROM all 10 input bits give the 4 next state bits 210 x 4 bits of ROM Total 4.3K bits of ROM

PLA is much smaller


can share product terms only need entries that produce an active output can take into account don't cares

PLA size = (#inputs #product-terms) + (#outputs #productterms)


FSM control PLA = (10x17)+(20x17) = 460 PLA cells
11/12/2010

PLA cells usually about the size of a ROM cell (slightly bigger)

96

Microprogramming
Microprogramming is a method of specifying FSM control that resembles a programming language textual rather graphic
this is appropriate when the FSM becomes very large, e.g., if the instruction set is large and/or the number of cycles per instruction is large in such situations graphical representation becomes difficult as there may be thousands of states and even more arcs joining them a microprogram is specification : implementation is by ROM or PLA

A microprogram is a sequence of microinstructions


each microinstruction has eight fields (label + 7 functional)
Label: used to control microcode sequencing ALU control: specify operation to be done by ALU SRC1: specify source for first ALU operand SRC2: specify source for second ALU operand Register control: specify read/write for register file Memory: specify read/write for memory PCWrite control: specify the writing of the PC Sequencing: specify choice of next microinstruction

11/12/2010

97

Microprogramming
The Sequencing field value determines the execution order of the microprogram
value Seq : control passes to the sequentially next microinstruction value Fetch : branch to the first microinstruction to begin the next MIPS instruction, i.e., the first microinstruction in the microprogram value Dispatch i : branch to a microinstruction based on control input and a dispatch table entry (called dispatching): Dispatching is implemented by means of creating a table, called dispatch table, whose entries are microinstruction labels and which is indexed by the control input. There may be multiple dispatch tables the value Dispatch i in the sequencing field indicates that the i th dispatch table is to be used
11/12/2010 98

Control Microprogram
The microprogram corresponding to the FSM control shown graphically earlier:
Labe l Fe tch M em 1 LW 2 SW 2 R form at1 BEQ1 JU M P 1 A LU control Add Add Add SRC1 SRC2 PC 4 PC E xtshft R ead A E xtend R e gister control M em ory R e ad P C P C W rite control A LU S equenc ing S eq D isp atch 1 D isp atch 2 S eq Fetch Fetch S eq Fetch Fetch Fetch

R e ad A LU W rite M D R W rite A LU Func code S u bt A A B W rite A LU B A LU O ut-co nd Jum p addre ss

Microprogram containing 10 microinstructions


Op 000000 000010 000100 100011 101011 11/12/2010 Dispatch ROM 1 Opcode name R-format jmp beq lw sw Value Rformat1 JUMP1 BEQ1 Mem1 Mem1 Dispatch ROM 2 Opcode name lw sw

Op 100011 101011

Value LW2 SW2

Dispatch Table 2
99

Dispatch Table 1

Microcode: Trade-offs
Specification advantages
easy to design and write typically manufacturer designs architecture and microcode in parallel

Implementation advantages
easy to change since values are in memory (e.g., off-chip ROM) can emulate other architectures can make use of internal registers

Implementation disadvantages
control is implemented nowadays on same chip as processor so the advantage of an off-chip ROM does not exist ROM is no longer faster than on-board cache there is little need to change the microcode as general-purpose computers are used far more nowadays than computers designed for specific applications
11/12/2010 100

Summary
Techniques described in this chapter to design datapaths and control are at the core of all modern computer architecture Multicycle datapaths offer two great advantages over single-cycle
functional units can be reused within a single instruction if they are accessed in different cycles reducing the need to replicate expensive logic instructions with shorter execution paths can complete quicker by consuming fewer cycles

Modern computers, in fact, take the multicycle paradigm to a higher level to achieve greater instruction throughput:
pipelining (next topic) where multiple instructions execute simultaneously by having cycles of different instructions overlap in the datapath the MIPS architecture was designed to be pipelined

11/12/2010

101

Вам также может понравиться