Lec13 Pipe Control
Lec13 Pipe Control
Computer Architecture
Lecture 13: Designing a Pipeline Processor
361 hazards.1
Clk
1
0
PC+4
PC+4
PC+4
PC
Imm16
Imm16
Mem/Wr Register
Ex/Mem Register
A Ra
busB Mem
Exec
IUnit
Rb RA Do 1
Rt Unit WA
RFile
Mux
Di
Rt Rw Di
I 0 0
Rd 1
1
Review: Pipeline Control “Data Stationary Control”
ExtOp ExtOp
ALUSrc ALUSrc
Ex/Mem Register
Mem/Wr Register
ALUOp ALUOp
ID/Ex Register
IF/ID Register
361 hazards.3
° Pipeline Processor:
• Natural enhancement of the multiple clock cycle processor
• Each functional unit can only be used once per instruction
• If a instruction is going to use a functional unit:
- it must use it at the same stage as all other instructions
• Pipeline Control:
- Each stage’s control signal depends ONLY on the instruction
that is currently in that stage
361 hazards.4
2
Outline of Today’s Lecture
° Introduction to Hazards
° Forwarding
° Summary
361 hazards.5
361 hazards.6
3
Single Memory is a Structural Hazard
ALU
I Mem Reg Mem Reg
n Load
s
ALU
Mem Reg Mem Reg
t Instr 1
r.
ALU
Mem Reg Mem Reg
O Instr 2
r
ALU
d Mem Reg Mem Reg
e
Instr 3
r
ALU
Mem Reg Mem Reg
Instr 4
361 hazards.7
361 hazards.8
4
Option 2: Duplicate to Resolve Structural Hazard
• Separate Instruction Cache (Im) & Data Cache (Dm)
Time (clock cycles)
ALU
I Im Reg Dm Reg
n Load
s
ALU
Im Reg Dm Reg
t Instr 1
r.
ALU
Im Reg Dm Reg
O Instr 2
r
ALU
d Im Reg Dm Reg
e
Instr 3
r
ALU
Im Reg Dm Reg
Instr 4
361 hazards.9
Data Hazard on r1
add r1 ,r2,r3
or r8, r1 ,r9
361 hazards.10
5
Data Hazard on r1: (Figure 6.30, page 397, P&H)
ALU
I add r1,r2,r3 Im Reg Dm Reg
ALU
s
t
sub r4,r1,r3 Im Reg Dm Reg
r.
ALU
Im Reg Dm Reg
and r6,r1,r7
O
ALU
r Im Reg Dm Reg
d or r8,r1,r9
e
ALU
Im Reg Dm Reg
r xor r10,r1,r11
361 hazards.11
n
ALU
s
t
sub r4, r1,r3 Im bubble bubble bubble Reg Dm Reg
r.
and r6,r1,r7
ALU
Im Reg Dm
O
r
or r8,r1,r9
ALU
d Im Reg
e
r Im Reg
xor r10,r1,r11
361 hazards.12
6
But recall use of “Data Stationary Control”
ExtOp ExtOp
ALUSrc ALUSrc
Ex/Mem Register
Mem/Wr Register
ALUOp ALUOp
ID/Ex Register
IF/ID Register
361 hazards.13
n
s
t
stall Im bubble bubble bubble bubble
r.
stall Im bubble bubble bubble bubble
O
r Im bubble bubble bubble bubble
d stall
e
sub r4,r1,r3
ALU
Im Reg Dm Reg
r
and r6,r1,r7
ALU
Im Reg Dm
361 hazards.14
7
Option 2: SW inserts indepdendent instructions
ALU
X
I add r1,r2,r3 Im Reg Dm Reg
ALU
s Im Reg Dm Reg
t
nop
r.
ALU
Im Reg Dm Reg
nop
O
ALU
r Im Reg Dm Reg
d nop
e
sub r4,r1,r3
ALU
Im Reg Dm Reg
r
and r6,r1,r7
ALU
Im Reg Dm
361 hazards.15
361 hazards.16
8
Option 3 Insight: Data is available! )
• Pipeline registers already contain needed data
ALU
X
I add r1,r2,r3 Im Reg Dm Reg
ALU
s
t
sub r4,r1,r3 Im Reg Dm Reg
r.
ALU
Im Reg Dm Reg
and r6,r1,r7
O
ALU
r Im Reg Dm Reg
d or r8,r1,r9
e
ALU
Im Reg Dm Reg
r xor r10,r1,r11
361 hazards.17
361 hazards.18
9
From Last Lecture: The Delay Load Phenomenon
Cycle 1 Cycle 2 Cycle 3 Cycle 4 Cycle 5 Cycle 6 Cycle 7 Cycle 8
Clock
361 hazards.19
n
ALU
s
t
sub r4,r1,r6 Im Reg Dm Reg
r.
ALU
Im Reg Dm Reg
and r6,r1,r7
O
ALU
r Im Reg Dm Reg
d or r8,r1,r9
e
r
361 hazards.20
10
Option1: HW Stalls to Resolve Data Hazard
• “Interlock”: checks for hazard & stalls
ALU
I lw r1, 0(r2) Im Reg Dm Reg
n
s
t
stall Im bubble bubble bubble bubble
r.
ALU
sub r4,r1,r3 Im Reg Dm Reg
O
r
ALU
Im Reg Dm Reg
d and r6,r1,r7
e
ALU
r Im Reg Dm Reg
or r8,r1,r9
361 hazards.21
n
ALU
s
t
nop Im Reg Dm Reg
r.
ALU
Im Reg Dm Reg
d and r6,r1,r7
e
ALU
r Im Reg Dm Reg
or r8,r1,r9
361 hazards.22
11
Software Scheduling to Avoid Load Hazards
361 hazards.24
12
Compiler Avoiding Load Stalls:
scheduled unscheduled
54%
gcc
31%
spice 42%
14%
tex 65%
25%
361 hazards.25
361 hazards.26
13
Control Hazard on Branches: 3 stage stall
361 hazards.27
° 2 part solution:
• Determine branch taken or not sooner, AND
• Compute taken branch address earlier
° Solution Option 1:
• Move Zero test to ID/RF stage
• Adder to calculate new PC in ID/RF stage
• 1 clock cycle penalty for branch vs. 3
361 hazards.28
14
Option 1: move HW forward to reduce branch delay
361 hazards.29
361 hazards.30
15
Option 2: Define Branch as Delayed
361 hazards.31
361 hazards.32
16
When is pipelining hard?
361 hazards.33
361 hazards.34
17
Hazard Detection
361 hazards.35
361 hazards.36
18
First Generation RISC Pipelines
361 hazards.37
361 hazards.38
19