Professional Documents
Culture Documents
Christos Kozyrakis
Stanford University
http://eeclass.stanford.edu/ee108b
ALU
I
add r1,r2,r3 Im Reg Dm Reg
ALU
s sub r4, r1, r3 Im Reg Dm Reg
t
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
C. Kozyrakis EE 108b Lecture 10 4
Forwarding Hardware
• Datapath
– Need to add multiplexers to functional units
– Source to function unit could come from
• Register file
• Memory
• ALU of last cycle
• ALU from two cycles ago
– Adding this mux increases the critical path of design
• Needs to be designed carefully
• Simple procedure
– Identify all pipeline stages that produce new values
• In our case, EX and MEM
– All pipeline stages after the earliest producer can be the source of a
forwarded operand
• In our case, MEM
ALU
Data
Memory
MuxB
ALU
I
lw r1, 0(r2) Im Reg Dm Reg
ALU
s sub r4, r1, r6 Im Reg Dm Reg
t
r.
ALU
Im Reg Dm Reg
and r6, r1, r7
O
ALU
r Im Reg Dm Reg
d
or r8, r1, r9
e
r
C. Kozyrakis EE 108b Lecture 10 11
Review: Hardware Stall
ALU
I
lw r1, 0(r2) Im Reg Dm Reg
ALU
s sub r4, r1, r3 Im Reg
bubble Dm Reg
t
r.
ALU
Im Reg Dm Reg
and r6, r1, r7 bubble
O
ALU
r Im Reg Dm Reg
d or r8, r1, r9
e
r
ALU
I
lw r1, 0(r2) Im Reg Dm Reg
ALU
s unrelated instruction Im Reg Dm Reg
t
r.
ALU
sub r4, r1, r3 Im Reg Dm Reg
O
ALU
r Im Reg Dm Reg
d and r6, r1, r7
e
ALU
r Im Reg Dm Reg
or r8, r1, r9
C. Kozyrakis EE 108b Lecture 10 16
Control Hazard
• Control hazards:
– Branch instruction
• If a branch is not taken then control simply continues with PC + 4
• If the branch is taken, then the PC jumps to a new address
– Jump instruction
• Causes a greater performance problem than data hazards
– Instruction fetch happens very early in the pipeline
ID/EX
0
M
u WB
x EX/MEM
1
Control M WB
MEM/WB
EX M WB
IF/ID
Add
Add
4 Add result
RegWrite
Branch
Shift
left 2
MemWrite
ALUSrc
MemtoReg
Read
Instruction
PC Address register 1
Read
data 1
Read
register 2 Zero
Instruction
Registers Read ALU ALU
memory Write 0 Read
data 2 result Address 1
register M data
u Data M
Write x memory u
data x
1
0
Write
data
Instruction 16 32 6
[15– 0] Sign ALU MemRead
extend control
Instruction
[20– 16]
0 ALUOp
M
Instruction u
[15– 11] x
1
RegDst
IF ID/RF EX MEM WB
ALU
beq r1, r2, L Im Reg Dm Reg
ALU
sub r4, r1, r3 Im Reg Dm Reg
ALU
Im Reg Dm Reg
and r6, r2, r7
ALU
Im Reg Dm Reg
or r8, r7, r9
ALU
L: add r1, r2, r1 Im Reg Dm Reg
• Stall
– Wait until you know the answer
– But makes CPI of branch large (about 3)
• Predict not-taken
– Continue to fetch and execute instruction
– Need to be able to nullify instruction if prediction was wrong
• Can be tricky, but is not that hard if done correctly
• Predict taken
– More complex, since need to compute destination
• Generally this takes some time, so
• Store destination address prediction with instruction
– Still need to nullify when wrong
• Most machines do some type of prediction (taken, not-taken)
C. Kozyrakis EE 108b Lecture 10 20
Branch Control Hazard: Another look
(Moving the control point)
Time (clock cycles)
IF ID/RF EX MEM WB
ALU
beq r1, r2, L Im Reg Dm Reg
ALU
sub r4, r1, r3 Im Reg Dm Reg
ALU
Im Reg Dm Reg
and r6, r2, r7
ALU
Im Reg Dm Reg
or r8, r7, r9
ALU
L: add r1, r2, r1 Im Reg Dm Reg
• What is the new effective CPI if 15% of the instructions are branches?
• Fetch and execute multiple instructions per cycle => CPI < 1
• Example: 2-way Superscalar
– Fetch 2 instructions/clock cycle
– Decision to execute two instructions handled dynamically
– Can only execute 2nd instruction if 1st instruction executes (in-order exec.)
Pipe Stages
IF ID EX MEM WB
IF ID EX MEM WB
Pipe Stages
IF1 IF2 ID EX MEM1 MEM2 MEM3 WB
IF1 IF2 ID EX MEM1 MEM2 MEM3 WB
• Almost double number of pipe stage registers (MIPS R4000)
• Issues: branch delay, load delay: CPI = 1.4 - 2.0
• Modern pipelines
– Pentium 4: 24 stages, 3+ GHz
– Prescott: 35 stages, 4+ GHz
BAT
C. Kozyrakis EE 108b Lecture 10 34
Dynamic Scheduling
16-entry 16-entry
int. Q FP. Q
64-entry 64-entry
Int GPR FPR
7R3W 5R3W OOO
LD/ST
ALU1 ALU2 ALU1 ALU2
Data mem
C. Kozyrakis EE 108b Lecture 10 37
Limits of Advanced Pipelining
• Problem:
– Typically want a lot of memory in your machine
• Usually hundreds of dollars
• Since it is expensive, you want the most bits/$
– Since the memory price is #1 issue, you have other issues
C. Kozyrakis EE 108b Lecture 10 39
Five Components
Computer
•Datapath
Processor Memory Devices
•Control
Control Input •Memory
Datapath Output
•Input
•Output