Professional Documents
Culture Documents
Multicycle Datapath
Review
• Construction of the Datapath
– Determine instruction types
• R-format
• Conditional Branch
• Unconditional Branch
• Load/store
– Develop datapath modules (RF, ALU, Memory, SignExt)
– Connect modules to form composite datapath
• Single-Cycle Datapath
– All instructions take one cycle (CPI = 1)
– Cycle time dictated by circuit settling time
– All operations take time of slowest operation (load)
What’s wrong with single cycle?
Instructions Cycles Time
X X
Program Instruction Cycle
(code size) (CPI) (cycle time)
• Critical path probably lw:
– I-mem, reg-read, alu, d-mem, reg-write
• Other instructions faster
– E.g. rrr: skip d-mem
• Instruction variation much worse for full ISA and
real implementation:
– FP divide
– Cache misses
Single Cycle Implementation
• Solution
– Variable clock?
• Too hard to control, design
– Fixed short clock
• Variable cycles per instruction
Overview – Multicycle Datapath
• Each instruction has multiple stages
• Each stage takes one cycle
1. Instruction fetch All instructions use these
2. Instruction decode / Data fetch
3. ALU ops / R-format execution
4. R-format completion
5. Memory access completion
Each stage can re-use hardware from previous stage
efficient use of hardware and time
>> New Hardware required to buffer stage output
>> New Muxes required for hardware re-use
>> Expanded Control for new hardware
Recall: Simple Datapath
Instruction rd Data
memory
rs Address
PC
+4 Data
imm
Opcode,
funct
Controller
Write ALU
Register Read
Write Data Data 2
Result
Register
Write
Recall: Load/Store Datapath
Next
state
Next-state
Current state
function
Clock
Inputs
Output
Outputs
function
Memory access
R-type instructions Branch instruction Jump instruction
instructions
(Figure 5.39) (Figure 5.40) (Figure 5.41)
(Figure 5.38)
(Op = 'JMP')
')
-t
EQ
p =R
'B
') (O
=
W
= 'S
p
( Op
(O
W ') or
= 'L
( Op
ALUSrcA = 1
ALUSrcB = 10
ALUOp = 00
(O
(Op = 'LW')
p
=
'S
W
')
Memory Memory
access access
3 5
MemRead
MemWrite
IorD = 1
IorD = 1
Write-back step
4
RegWrite To state 0
MemtoReg = 1 (Figure 5.37)
RegDst = 0
Execution
6
ALUSrcA = 1
ALUSrcB = 00
ALUOp = 10
R-type completion
7
RegDst = 1
RegWrite
MemtoReg = 0
To state 0
(Figure 5.37)
FSM control to implement R-type instructions has 2 states
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)
From state 1
(Op = 'J')
Jump completion
9
PCWrite
PCSource = 10
To state 0
(Figure 5.37)
')
-t yp
EQ
(Op = 'J')
= R
'B
(Op
W ')
=
Memory address 'S
p
p= Branch Jump
(O
computation O
or ( Execution completion completion
W ')
= 'L
2 ( Op 6 8 9
ALUSrcA = 1
ALUSrcA = 1 ALUSrcB = 00
EX
ALUSrcA =1 PCWrite
ALUSrcB = 10 ALUSrcB = 00 ALUOp = 01
ALUOp = 00 PCSource = 10
ALUOp = 10 PCWriteCond
PCSource = 01
(O
(Op = 'LW')
p
=
'S
W
')
Memory Memory
access access R-type completion
3 5 7
Write-back step
4
RegDst = 0
WB RegWrite
MemtoReg = 1
I 28 32
1 R
Instruction I
5
jmpaddr
I[25:0] <<2 CONCAT
PCWr* rs rt rd
0
IorD 0 32 5 5
0
MUX
1 RegDst
0
2
M
PC
5 X ALUSrcA 010
Operation
1U
0
X
X RegWrite
2X
3
1 0 E
16 X 32
ALUSrcB
immediate
T
N
<<2 1
D
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
0 Instruction I jmpaddr 28 32
R 5 I[25:0] <<2 CONCAT
PCWr* rs rt rd
X 0 1 RegDst 0 2
IorD 0 32 5 5 MUX
5 X ALUSrcA 010 1U
M
X
PC Operation 0
MemWrite RN1 RN2 WN 3
0M 0M
U
1X
ADDR M Registers U PCSource
Zero
Memory
RD
D
R
1M
U WD
RD1 A 1X
ALU X
0X ALU
OUT
WD RD2 B 0
MemRead MemtoReg 4 1M
X
U
2X
3
0 RegWrite
0 E
X ALUSrcB
immediate 16
T
32
<<2 3
N
D
Multicycle Control Step (3):
ALU Instruction (R-Type)
ALUOut = A op B;
0
IRWrite
I 28 32
0 R
Instruction I
5
jmpaddr
I[25:0] <<2 CONCAT
PCWr* rs rt rd
X 0 1 RegDst
1
2
IorD 0 32 5 5 MUX
5 X ALUSrcA ??? 1U
M
X
PC Operation 0
MemWrite RN1 RN2 WN 3
0M 0M
U
1X
ADDR M Registers U PCSource
1X Zero
D A
Memory
RD R
1M
U
0X
WD
RD1
ALU X
ALU
OUT
WD RD2 B 0
MemRead MemtoReg 4 1M
U
X RegWrite
2X
3
0 0 E
16 X 32
ALUSrcB
immediate
T
N
<<2 0
D
Multicycle Control Step (4):
ALU Instruction (R-Type)
Reg[IR[15:11]] = ALUOut; (Reg[Rd] =
ALUOut) 0 IRWrite
I Instruction I jmpaddr 28 32
0
PCWr*
R
rs rt
5
rd
I[25:0] <<2 CONCAT
X 32 0 1 RegDst
X
2
M
0
5 5 MUX
IorD
1 XXX
1U
5 ALUSrcA X
PC Operation 0
MemWrite RN1 RN2 WN 3
0M 0M
U ADDR M Registers U PCSource
1X Zero
Memory D 0 M RD1 A 1X
RD R 1
U
X
WD ALU
ALU
X
OUT
WD RD2 B 0
MemRead MemtoReg 4 1M
U
2X
1 RegWrite 3
0 1 E
ALUSrcB
immediate 16 X 32
T
N
<<2 X
D
Multi-cycle IF MemRead
ALUSrcA=0
IorD = 0
IRWrite
ID
ALUSrcA = 0
Example
ALUSrcB = 11
Start ALUSrcB = 01
ALUOp = 00 ALUOp = 00
PCWrite
PCSrc = 00
(and) LW | SW
RRR
ALUSrcA = 1
BEQ
J
LW SW
WB
MEM MemRead MemWrite
RegDst = 1
RegWrite
IorD = 1 IorD = 1
MemtoReg = 0
RegDst = 0
WB RegWrite
MemtoReg = 1
Multi-cycle Example (and)
Multicycle Control Step (3):
Memory Reference Instructions
ALUOut = A + sign-extend(IR[15-0]);
0
IRWrite
I Instruction I jmpaddr 28 32
0
PCWr*
R
rs rt
5
rd
I[25:0] <<2 CONCAT
X 32
0 1 RegDst
1
2
0 5 5 MUX M
IorD
PC
5 X ALUSrcA 010
Operation
1U
0
X
X
2X
3
RegWrite
0 0 E
X ALUSrcB
immediate 16 32
T
N
<<2 2
D
Multicycle Control Step (4):
Memory Access - Read (lw)
MDR = Memory[ALUOut];
IRWrite 0
I 28 32
0 R
Instruction I
5
jmpaddr
I[25:0] <<2 CONCAT
PCWr* rs rt rd
1 0 1 RegDst
X
2
IorD 0 32 5 5 MUX
5 X ALUSrcA XXX 1U
M
X
PC Operation 0
MemWrite RN1 RN2 WN 3
0M 0M
U
1X
ADDR M Registers U PCSource
D A 1X Zero
RD1
X
1M
Memory WD ALU
RD R U
0X ALU
OUT
WD RD2 B 0
MemRead MemtoReg 4 1M
U
X RegWrite
2X
3
1 0 E
16 X 32
ALUSrcB
immediate
T
N
<<2 X
D
Multicycle Execution Steps (5)
Memory Read Completion (lw)
Reg[IR[20-16]] = MDR;
IRWrite 0
I 28 32
0 R
Instruction I
5
jmpaddr
I[25:0] <<2 CONCAT
PCWr* rs rt rd
X 0 1 RegDst
X 2
IorD 0 32 5 5 MUX
5 0 ALUSrcA XXX 1U
M
X
PC Operation 0
MemWrite RN1 RN2 WN 3
0M 0M
U ADDR M U PCSource
1X Registers Zero
D A
X
0 RD1 1X
Memory M
U WD ALU
RD R 1 X ALU
OUT
WD RD2 B 0
MemRead MemtoReg 4 1M
U
0 RegWrite
2X
3
0
16
1 E
X 32
ALUSrcB
X
immediate
T <<2
N
D
Multi-cycle IF MemRead
ALUSrcA=0
IorD = 0
IRWrite
ID
ALUSrcA = 0
Example
ALUSrcB = 11
Start ALUSrcB = 01
ALUOp = 00 ALUOp = 00
PCWrite
PCSrc = 00
(lw) LW | SW
RRR
ALUSrcA = 1
BEQ
J
LW SW
WB
MEM MemRead MemWrite
RegDst = 1
RegWrite
IorD = 1 IorD = 1
MemtoReg = 0
RegDst = 0
WB RegWrite
MemtoReg = 1
Multi-cycle Example (lw)
Multicycle Execution Steps (4)
Memory Access - Write (sw)
Memory[ALUOut] = B;
IRWrite 0
I Instruction I jmpaddr 28 32
0
PCWr*
R
rs rt
5
rd
I[25:0] <<2 CONCAT
1 32
0 1 RegDst
X
2
1 5 5 MUX M
IorD
5 X ALUSrcA XXX 1U
X
PC Operation 0
MemWrite RN1 RN2 WN 3
0M 0M
U
1X
ADDR M Registers U PCSource
1X Zero
D 1M RD1 A
Memory
RD R U
0X
WD ALU
ALU
X
OUT
WD RD2 B 0
MemRead MemtoReg 4 1M
U
X RegWrite
2X
3
0 0 E
16 X 32
ALUSrcB
immediate
T
N
<<2 X
D
Multi-cycle IF MemRead
ALUSrcA=0
IorD = 0
IRWrite
ID
ALUSrcA = 0
Example
ALUSrcB = 11
Start ALUSrcB = 01
ALUOp = 00 ALUOp = 00
PCWrite
PCSrc = 00
(sw) LW | SW
RRR
ALUSrcA = 1
BEQ
J
LW SW
WB
MEM MemRead MemWrite
RegDst = 1
RegWrite
IorD = 1 IorD = 1
MemtoReg = 0
RegDst = 0
WB RegWrite
MemtoReg = 1
Multi-cycle Example (sw)
Multi-cycle IF MemRead
ALUSrcA=0
IorD = 0
IRWrite
ID
ALUSrcA = 0
Example
ALUSrcB = 11
Start ALUSrcB = 01
ALUOp = 00 ALUOp = 00
PCWrite
PCSrc = 00
(beq T) LW | SW
RRR
ALUSrcA = 1
BEQ
J
LW SW
WB
MEM MemRead MemWrite
RegDst = 1
RegWrite
IorD = 1 IorD = 1
MemtoReg = 0
RegDst = 0
WB RegWrite
MemtoReg = 1
Multicycle Control Step (3):
Branch Instructions
if (A == B) PC = ALUOut;
0
IRWrite
1 if I Instruction I jmpaddr 28 32
Zero=1 R 5 I[25:0] <<2 CONCAT
PCWr* rs rt rd
X 0 1 RegDst
1
2
IorD 0 32 5 5 MUX
5 X ALUSrcA 011 1U
M
X
PC Operation 0
MemWrite RN1 RN2 WN 3
0M 0M
U
1X
ADDR M Registers U PCSource
1X Zero
D A
Memory
RD R
1M
U
0X
WD
RD1
ALU 1
ALU
OUT
WD RD2 B 0
MemRead MemtoReg 4 1M
U
X RegWrite
2X
3
0 0 E
16 X 32
ALUSrcB
immediate
T
N
<<2 0
D
Multi-cycle Example (beq T)
Multi-cycle Example (beq NT)
Multicycle Execution Step (3):
Jump Instruction
PC = PC[21-28] concat (IR[25-0] << 2);
0
IRWrite
I Instruction I jmpaddr 28 32
1
PCWr*
R
rs rt
5
rd
I[25:0] <<2 CONCAT
X 32
0 1 RegDst
X
2
0 5 5 MUX M
IorD
PC
5 X ALUSrcA XXX
Operation
1U
0
X
X
2X
3
RegWrite
0 0 E
X ALUSrcB
immediate 16 32
T
N
<<2 X
D
IF MemRead
ALUSrcA=0
ID
Multi-cycleStart IorD = 0
IRWrite
ALUSrcB = 01
ALUOp = 00
ALUSrcA = 0
ALUSrcB = 11
ALUOp = 00
Example (j)
PCWrite
PCSrc = 00
LW | SW J
RRR BEQ
ALUSrcA = 1
ALUSrcA = 1 ALUSrcA = 1 ALUSrcB = 00
EX ALUSrcB = 10 ALUSrcB = 00 ALUOp = 01
PCWrite
PCSource = 10
ALUOp = 00 ALUOp = 10 PCWriteCond
PCSource = 01
LW SW
WB
MEM MemRead MemWrite
RegDst = 1
RegWrite
IorD = 1 IorD = 1
MemtoReg = 0
RegDst = 0
WB RegWrite
MemtoReg = 1
Multi-cycle Example (j)
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
Conclusions
• MIPS ISA: Three instruction formats (R,I,J)
• One cycle per stage, Different stages per format
• One-Cycle Steps R-fmt lw sw beq j
1. Instruction Fetch
2. Instruction Decode
3. ALU ops / R-format Execution
4. R-format Completion/Mem Access
5. Memory Read Completion