Pipe 2 New
Pipe 2 New
6 PM 7 8 9 10 11 12 1 2 AM
IF DCD EX MEM WB
IF DCD EX MEM WB
IF DCD EX MEM WB
IF DCD EX MEM WB
IF DCD EX MEM WB
Example: 40ns data path, 5 stages, Longest stage is 10 ns, Speedup 4
I mem
Regs lw $2,20($5) PC
Operand Register Selects
B A im n op rw
ALU Op <= PC + 4 + immed
alu
S
MEM Op
D mem
Datapath Output
Equal
R[rd] <– S; R[rt] <– S; R[rd] <– M;
Reg.
Inst. Mem
File
Exec
Reg
A M
Next PC
File
S
PC
IR
Access
Mem
Mem
Data
D
cs 152 L1 3 .9 DAP Fa97, U.CB
6.3 (Parts of 6.6) Pipelined Control
ExtOp ExtOp
ALUSrc ALUSrc
IF/ID Register
Ex/Mem Register
ALUOp ALUOp
Mem/Wr Register
ID/Ex Register
Decode
wb wb wb
rt me me WB
rs ex Mem
op Ctrl
Ctrl
rs rt im
Reg.
File
Reg
File A M
Exec
S
Access
Mem
Mem
Data
D
Next PC
PC
cs
cs 152
152 L1
L1 33 .14
.14 DAP Fa97, U.CB
Let’s Try it
Out
10 lw r1, r2(35)
14 addI r2, r2, 3
20 sub r3, r4, r5
24 beq r6, r7, 100
30 ori r8, r9, 17 these addresses are octal
34 add r10, r11, r12
Decode
WB
Mem
Ctrl
Ctrl
IR im
rs rt
Reg.
File
Reg
A M
File
Exec
S
B
Access
=
Mem
Mem
Data
D IF 10 lw r1, r2(35)
14 addI r2, r2, 3
Next PC
cs 152 L1 3 .16
100 and r13, r14, 15
DAP Fa97, U.CB
Fetch 14, Decode 10
n n n
lw r1, r2(35)
Inst. Mem
Decode
WB
Mem
Ctrl
Ctrl
IR im
2 rt
Reg.
File
Reg
A M
File
Exec
S
B
Access
=
Mem
Mem
Data
D ID 10 lw r1, r2(35)
IF 14 addI r2, r2, 3
Next PC
cs 152 L1 3 .17
100 and r13, r14, 15
DAP Fa97, U.CB
Fetch 20, Decode 14, Exec 10
n n
addI r2, r2, 3
Inst. Mem
Decode
lw r1
WB
Mem
Ctrl
Ctrl
IR
35
2 rt
Reg.
File
Reg
r2 M
File
Exec
S
B
Access
=
Mem
Mem
Data
D EX 10 lw r1, r2(35)
ID 14 addI r2, r2, 3
Next PC
cs 152 L1 3 .18
100 and r13, r14, 15
DAP Fa97, U.CB
Fetch 24, Decode 20, Exec 14, Mem 10
n
sub r3, r4, r5
Decode
lw r1
WB
Mem
Ctrl
Ctrl
IR
4 5
3
Reg.
r2+35
File
Reg
r2 M
File
Exec
B
Access
=
Mem
Mem
Data
D M 10 lw r1, r2(35)
EX 14 addI r2, r2, 3
Next PC
cs 152 L1 3 .19
100 and r13, r14, 15
DAP Fa97, U.CB
Fetch 30, Dcd 24, Ex 20, Mem 14, WB
10
beq r6, r7 100
Inst. Mem
Decode
addI r2
sub r3
lw r1
WB
Mem
Ctrl
Ctrl
IR
6 7
M[r2+35]
Reg.
File
Reg
r4
r2+3
File
Exec
r5
Access
=
Mem
Mem
Data
D WB 10 lw r1, r2(35)
M 14 addI r2, r2, 3
Next PC
Decode
addI r2
sub r3
WB
beq
Mem
Ctrl
Ctrl
IR
r1=M[r2+35]
100
9 xx
Reg.
r2+3
File
Reg
r4-r5
r6
File
Exec
r7
Access
=
Mem
Mem
Data
D 10 lw r1, r2(35)
WB 14 addI r2, r2, 3
M 20
Next PC
Decode
?
WB
Mem
Ctrl
Ctrl
IR
Reg.
File
Reg
File
Exec
Access
=
Mem
Mem
Data
D 10 lw r1, r2(35)
14 addI r2, r2, 3
Next PC
Fill it in yourself!
ID 100 and r13, r14, 15
cs 152 L1 3 .22 DAP Fa97, U.CB
Fetch 110, Dcd 104, Ex 100, Mem 30, WB
24
Inst. Mem
Decode
? ?
WB
Mem
Ctrl
Ctrl
IR ?
Reg.
File
Reg
?
File
Exec
Access
=
Mem
Mem
Data
D 10 lw r1, r2(35)
14 addI r2, r2, 3
Next PC
Fill it in yourself!
cs 152 L1 3 .23
EX 100 and r13, r14, 15
DAP Fa97, U.CB
Fetch 114, Dcd 110, Ex 104, Mem 100, WB
30
Inst. Mem
Decode
? ? ?
WB
Mem
Ctrl
Ctrl
IR ?
Reg.
File
Reg
? ?
File
Exec
Access
=
Mem
Mem
Data
D 10 lw r1, r2(35)
14 addI r2, r2, 3
Next PC
Fill it in yourself!
M 100 and r13, r14, 15
cs 152 L1 3 .24 DAP Fa97, U.CB
Pipeline Hazards Again
I-Fet ch DCD MemOpFetch OpFetch Exec Store
IF DCD OF Ex Mem
IF DCD EX Mem WB
WAW Data Hazard
IF DCD EX Mem WB
IF DCD OF Ex Mem
npc
° Current operand
I mem registers
Regs op rw rs rt PC
° Pending writes
° hazard <=
B A im n op rw ((rs == rwex) & regWex) OR
((rs == rwmem) & regWme) OR
alu
((rs == rwwb) & regWwb) OR
S n op rw
((rt == rwex) & regWex) OR
D mem ((rt == rwmem) & regWme) OR
((rt == rwwb) & regWwb)
m
n op rw
Regs
cs 152 L1 3 .30 DAP Fa97, U.CB
Resolve RAW by forwarding
IAU ° Detect nearest
valid write op
npc operand register
and forward into
I mem op latches,
Regs bypassing
op rw rs rt PC remainder of the
Forward
mux
pipe
• Increase muxes to
B A im n op rw add paths from
pipeline registers
alu
• Data Forwarding =
S n op rw Data Bypassing
D mem
m
n op rw
Regs
cs 152 L1 3 .31 DAP Fa97, U.CB
6.5 What about memory operations?
° If instructions are initiated in order and
operations always occur in the same
stage, there can be no hazards between op Rd Ra Rb
memory operations!
Rd T
Instr is in the ID stage means:
the instruction’s control signals are in to reg
file
the IF/ID register.
cs
cs 152
152 L1
L1 33 .33
.33 DAP Fa97, U.CB
No Solution by Forwarding
bubble
Or, more
accurately…
cs 152 L1 3 .36 Chapter 4 — The Processor
DAP Fa97, — 36
U.CB
Stalling
IF/IDWrite
EX/MEM
M
Control u M WB
x MEM/WB
0
IF/ID EX M WB
1 $1
PCWrite
M
Instruction
X u
x
Registers
Instruction Data
PC ALU
memory memory M
$X
u
M x
u
x
1
X
2
M
u
x
ID/EX.RegisterRt Forwarding
unit
Clock 2
EX/MEM
M
Control u M WB
x MEM/WB
0
IF/ID EX M WB
2 $2 $1
PCWrite
M
Instruction
5 u
x
Registers
Instruction Data
PC ALU
memory memory M
$5 $X
u
M x
u
x
2 1
5 X
2 M
4 u
x
ID/EX.RegisterRt Forwarding
unit
Clock 3
cs 152 L1 3 .36
.39 DAP Fa97, U.CB
Cycles 4 and 5
or $4, $4, $2 and $4, $2, $5 bubble lw $2, . . . before<1>
Hazard
ID/EX.MemRead
detection
2 unit ID/EX
5
10 00
WB
IF/IDWrite
EX/MEM
M 11
Control u M WB
x MEM/WB
0
IF/ID EX M WB
2 $2 $2
PCWrite
M
Instruction
5 u
x
Registers
Instruction Data
PC ALU
memory memory M
$5 $5
u
M x
u
x
2 2
5 5
M 2
4 4 u
x
ID/EX.RegisterRt Forwarding
unit
Clock 4
add $9, $4, $2 or $4, $4, $2 and $4, $2, $5 bubble lw $2, . . .
Hazard
ID/EX.MemRead
detection
4 unit ID/EX
2
10 10
WB
IF/IDWrite
EX/MEM
M 0
Control u M WB
x MEM/WB
0
11
IF/ID EX M WB
4 $4 $2
PCWrite
M
Instruction
2 u
x
Registers
Instruction 2 Data
PC ALU
memory memory M
$2 $5
u
M x
u
x
4 2
2 5
M 2
4 4 u
x
ID/EX.RegisterRt Forwarding
unit
Clock 5
cs 152 L1 3 .39
.40 DAP Fa97, U.CB
Cycles 6 and 7
after<1> add $9, $4, $2 or $4, $4, $2 and $4, . . . bubble
Hazard ID/EX.MemRead
detection
4
unit ID/EX
2
10 10
WB
IF/IDWrite
EX/MEM
M 10
Control u M WB
x MEM/WB
0
0
IF/ID EX M WB
4 $4 $4
PCWrite
Instruction
2 u
x
Registers
Instruction Data
PC ALU
memory memory M
$2 $2
u
M x
u
x
4 4
2 2
M 4
9 4 u
x
ID/EX.RegisterRt Forwarding
unit
Clock 6
EX/MEM
M 10
Control u M WB
x MEM/WB
0
1
IF/ID EX M WB
$4
PCWrite
M
Instruction
u
x
Registers
Instruction 4 Data
PC ALU
memory memory M
$2
u
M x
u
x
4
2
M 4 4
9 u
x
ID/EX.RegisterRt Forwarding
unit
Clock 7
cs 152 L1 3 ..41 DAP Fa97, U.CB