Beruflich Dokumente
Kultur Dokumente
• Thursday!!
1
Single-Cycle CPU Summary
• Fairly straightforward
• Which instruction takes the longest?
By how much? Why is that a problem?
• Execution time = insts * cpi * cycle
time
2
Evaluating Critical Path
I mem Decode, ALU PC D mem R-Write Total
R-Read update
R-type 1 1 .9 - - .8 3.7
Load 1 1 .9 - 1 .8 4.7
Store 1 1 .9 - 1 - 3.9
beq 1 1 .9 .1 - - 3
PCSrc
1
Add M
u
x
4 ALU 0
Add result
RegWrite Shift
left 2
ALUOp 3
different critical paths!
Multicycle design
• Problem: In single-cycle design, cycle time must be long
enough for longest instruction
• Solution: break execution into smaller tasks
- each task takes a cycle;
- different instructions require different numbers of cycles
4
Idea: quantize instruction execution into
smaller steps
• Five execution steps (some instructions use
fewer)
- IF: Instruction Fetch
- ID: Instruction Decode (& register fetch & add PC+immed)
- EX: Execute
- Mem: Memory access
- WB: Write-Back into registers
5
Will multicycle be faster?
Æ Depends on program + stage timings
Cycles Instruction
needed frequency
R-type 4 60% What is CPI assuming
Load 5 20% this instruction mix???
Store 4 10%
beq 3 10%
PCSrc
M
Add u
x
4 Add ALU
result
Shift
left 2
Registers
Read 3 ALU operation
MemWrite
Read register 1 ALUSrc
PC Read
address Read data 1 MemtoReg
register 2 Zero
Instruction ALU ALU
Write Read Address Read
register M result data
data 2 u M
Instruction u
memory Write x Data x
data memory
Write
RegWrite data
16 32
Sign
extend MemRead
8
Merging Logic from Single Cycle to MultiCycle
PCWriteCond PCSource
PCWrite ALUOp
IorD Outputs
ALUSrcB
MemRead
Control ALUSrcA
MemWrite
RegWrite
MemtoReg
Op RegDst
IRWrite [5–0]
0
M
Jump 1 u
Instruction [25–0] 26 28 address [31-0] x
Shift
left 2 2
Instruction
[31-26] PC [31-28]
PC 0 0
M Instruction Read
[25–21] register 1 M
u Address u
x Read x
Instruction Read A Zero
1 Memory
[20–16] register 2 data 1 1
0 ALU ALU ALUOut
MemData Registers
Instruction M Write result
Read B
[15–0] Instruction u register data 2 0
Write Instruction [15–11] x 4 1 M
data Write u
register 1 data 2 x
Instruction 0 3
[15–0] M
u
x
Memory 1
data 16 32 ALU
Sign Shift
register control
extend left 2
Instruction [5–0]
PCSrc
M
Add u
x
4 Add ALU
result
Shift
left 2
Registers
Read 3 ALU operation
MemWrite
Read register 1 ALUSrc
PC Read
address Read data 1 MemtoReg
register 2 Zero
Instruction ALU ALU
Write Read Address Read
register M result data
data 2 u M
Instruction u
memory Write x Data x
data memory
Write
RegWrite data
16 32
Sign
extend MemRead
9
Multicycle Datapath – let’s figure out
basic execution model
PCWriteCond PCSource
PCWrite ALUOp
IorD Outputs
ALUSrcB
MemRead
Control ALUSrcA
MemWrite
RegWrite
MemtoReg
Op RegDst
IRWrite [5–0]
0
M
Jump 1 u
Instruction [25–0] 26 28 address [31-0] x
Shift
left 2 2
Instruction
[31-26] PC [31-28]
PC 0 0
M Instruction Read
[25–21] register 1 M
u Address u
x Read x
Instruction Read A Zero
1 Memory
[20–16] register 2 data 1 1
0 ALU ALU ALUOut
MemData Registers
Instruction M Write result
Read B
[15–0] Instruction u register data 2 0
Write Instruction [15–11] x 4 1 M
data Write u
register 1 data 2 x
Instruction 0 3
[15–0] M
u
x
Memory 1
data 16 32 ALU
Sign Shift
register control
extend left 2
Instruction [5–0]
10
Summary of execution steps
S te p R -ty p e M e m o ry B ra n c h
In s tru c tio n F e tc h IR = M e m [P C ]
PC = PC + 4
In s tru c tio n D e c o d e / A = R e g [IR [2 5 -2 1 ]]
re g is te r fe tc h B = R e g [IR [2 0 -1 6 ]]
A L U o u t = P C + (s ig n -e x te n d (IR [1 5 -0 ]) < < 2 )
E x e c u tio n , a d d re s s A LU out = A op B A LU out = A + if (A = = B ) th e n
c o m p u ta tio n , b ra n c h s ig n - PC=A LU out
c o m p le tio n e x te n d (IR [1 5 -0 ])
M e m o ry a c c e s s o r R - R e g [IR [1 5 -1 1 ]] = m e m o ry -d a ta =
ty p e c o m p le tio n A LU out M e m [A L U o u t]
or
M e m [A L U o u t]=
B
W rite -b a c k R e g [IR [2 0 -1 6 ]] =
m e m o ry -d a ta
Instruction [5–0]
12
PCWriteCond CauseWrite
CauseWrite
PCWriteCond
IntCause
IntCause
PCWrite
PCWrite EPCWrite
Outputs EPCWrite
IorD
IorD Outputs PCSource
PCSource
MemRead ALUOp
ALUOp
MemRead
Control ALUSrcB
ALUSrcB
MemWrite
MemWrite Control
ALUSrcA
ALUSrcA
MemtoReg
MemtoReg RegWrite
RegWrite
Op
Op
IRWrite
IRWrite [5–0] RegDst
RegDst
[5–0]
00
Jump 11MM
Instruction 26
26 28
28 Jump u
Instruction[25–0]
[25–0] Shift
Shift
address
address[31-0]
[31-0] x
u
left 22 x
left22
Instruction CO 33
Instruction
[31-26] CO00
0000
0000
00
[31-26] PC
PC
PC 00 00 PC[31-28]
[31-28]
M Instruction
Instruction Read
Read
M [25–21] register MM
uu Address
Address [25–21] register11 uu
xx Read xx
Memory
Memory Instruction
Instruction Read
Read Read AA Zero
11 data 1 11 Zero
[20–16]
[20–16] register22 data 1
register
ALU
MemData
MemData 00 Registers ALU ALUALU ALUOut
ALUOut EPC
Registers result EPC
Instruction
Instruction MM Write
Write Read result
[15–0] register Read BB
[15–0] u register data 00
Instruction
Instruction xu data22
Write
Write Instruction [15–11]
[15–11] x 44 11M
data Instruction Write M
data 11 Write u
register
register data
data 22 xu
x
Instruction 00 33 00 00
Instruction
[15–0]
[15–0] M MM
M uu Cause
uu Cause
xx xx
Memory 11 11 11
Memory
data
data 16
16 32
32 ALU
Sign
Sign Shift
Shift ALU
register
register control
extend
extend left
left22 control
Instruction
Instruction[5–0]
[5–0]
13
14