
































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

































Overview
Overview
Make the pipelined processor work!
Data Hazards
Data Hazards
n Instruction having register R as source follows shortly after
instruction having register R as destination
n Common condition, don’t want to slow down pipeline
Control Hazards
Control Hazards
n Mispredict conditional branch
n Getting return address for ret instruction
Making Sure It Really Works Making Sure It Really Works
n What if multiple special cases happen simultaneously?
PIPE- Hardware
PIPE- Hardware
n Pipeline registers hold
intermediate values
from instruction
execution
Forward (Upward) Paths
Forward (Upward) Paths
n Values passed from one
stage to next
n Cannot jump past
stages
E
M
W
F
D
Instruction
memory
Instruction
memory
PC
increment
PC
increment
Register
file
Register
file
ALU
ALU
Data
memory
Data
memory
Select
PC
rB
dstE dstM
Select
A
ALU
A
ALU
B
Mem.
control
Addr
srcA srcB
read
write
ALU
fun.
Fetch
Decode
Execute
Memory
Write back
icode
data out
data in
A B
M
E
M_valA
W_valM
W_valE
M_valA
W_valM
d_rvalA
f_PC
Predict
PC
valE valM dstE dstM
icode Bch valE valA dstE dstM
icode ifun valC valA valB dstE dstM srcA srcB
icode ifun rA valC valP
predPC
CC
CC
d_srcA d_srcB
e_Bch
M_Bch
Data Dependencies: 2 Nop’s
Data Dependencies: 2 Nop’s
0x000: irmovl $10,%edx
1 2 3 4 5 6 7 8 9
0x006: irmovl $3,%eax
0x00c: nop
0x00d: nop
0x00e: addl %edx,%eax
0x010: halt
10
# demo-h2.ys
%eax
valA R[ %edx
valB R[ %eax
%eax
%eax
valA R[ %edx
valB R[ %eax
valA R[ %edx
valB R[ %eax
Error
Stalling for Data Dependencies
Stalling for Data Dependencies
n If instruction follows too closely after one that writes register,
slow it down
n Hold instruction in decode
n Dynamically inject nop into execute stage
0x000: irmovl $10,%edx
1 2 3 4 5 6 7 8 9
0x006: irmovl $3,%eax
0x00c: nop
bubble
0x00e: addl %edx,%eax
0x010: halt
10
# demo-h2.ys
0x00d: nop
11
Stall Condition
Stall Condition
Source Registers
Source Registers
n srcA and srcB of current
instruction in decode
stage
Destination Registers
Destination Registers
n dstE and dstM fields
n Instructions in execute,
memory, and write-back
stages
Special Case
Special Case
n Don’t stall for register ID
8
E
M
W
F
D
Instruction
memory
Instruction
memory
PC
increment
PC
increment
Register
file
Register
file
ALU
ALU
Data
memory
Data
memory
Select
PC
rB
Select dstE dstM
A
ALU
A
ALU
B
Mem.
control
Addr
srcA srcB
read
write
ALU
fun.
Fetch
Decode
Execute
Memory
Write back
icode
data out
data in
A B
M
E
M_valA
W_valM
W_valE
M_valA
W_valM
d_rvalA
f_PC
Predict
PC
valE valM dstE dstM
icode Bch valE valA dstE dstM
icode ifun valC valA valB dstE dstM srcA srcB
icode ifun rA valC valP
predPC
CC
CC
d_srcA d_srcB
e_Bch
M_Bch
Stalling X
Stalling X
0x000: irmovl $10,%edx
1 2 3 4 5 6 7 8 9
0x006: irmovl $3,%eax
bubble
bubble
0x00c: addl %edx,%eax
0x00e: halt
10
# demo-h0.ys
bubble
11
W_dstE = %eax
srcA = %edx
srcB = %eax
M_dstE = %eax
srcA = %edx
srcB = %eax
E_dstE = %eax
srcA = %edx
srcB = %eax
What Happens When Stalling?
What Happens When Stalling?
n Stalling instruction held back in decode stage
n Following instruction stays in fetch stage
n Bubbles injected into execute stage
0x000: irmovl $10,%edx
0x006: irmovl $3,%eax
0x00c: addl %edx,%eax
0x00e: halt
0x000: irmovl $10,%edx
0x006: irmovl $3,%eax
0x00c: addl %edx,%eax
# demo-h0.ys
0x00e: halt
0x000: irmovl $10,%edx
0x006: irmovl $3,%eax
bubble
0x00c: addl %edx,%eax
0x00e: halt
0x006: irmovl $3,%eax
bubble
0x00c: addl %edx,%eax
bubble
0x00e: halt
bubble
bubble
0x00c: addl %edx,%eax
bubble
0x00e: halt
bubble
bubble
0x00c: addl %edx,%eax
0x00e: halt
Pipeline Register Modes
Pipeline Register Modes
Rising
clock
Rising
clock
Output = y
Rising
clock
Rising
clock
Output = x
n
o
p
Rising
clock
Rising
clock
Output = nop
Input = y Output = x
stall
= 0
bubble
= 0
Input = y Output = x
stall
= 1
bubble
= 0
Input = y Output = x
stall
= 0
bubble
= 1
Data Forwarding
Data Forwarding
Naïve Pipeline
Naïve Pipeline
n Register isn’t written until completion of write-back stage
n Source operands read from register file in decode stage
Observation
Observation
n Value generated in execute or memory stage
Trick
Trick
n Pass value directly from generating instruction to decode
stage
n Needs to be available at end of decode stage
Bypass Paths
Bypass Paths
Decode Stage
Decode Stage
n Forwarding logic selects
valA and valB
n Normally from register
file
n Forwarding: get valA or
valB from later pipeline
stage
Forwarding Sources
Forwarding Sources
n Execute: valE
n Memory: valE, valM
n Write back: valE, valM
CC
CC
ALU
ALU
Data
memory
Data
memory
Decode
Execute
Memory
Write back
Register
file
Register
file
A B
M
E
Register
file
Register
file
A B
M
E
valP
d_srcA,
d_srcB
valA, valB
Bch
e_valE
Addr, Data
m_valM
W_icode, W_valM W_valE, W_valM, W_dstE, W_dstM
icode, ifun,
rA, rB, valC
E
M
W
D
valP
M_icode,
M_Bch,
M_valA
M_valE
W_valE
W_valM
E_valA, E_valB,
E_srcA, E_srcB
Forward
Data Forwarding Example #
Data Forwarding Example #
Register Register %%edxedx
Register Register %%eaxeax
0x000: irmovl $10,%edx
1 2 3 4 5 6 7 8
0x006: irmovl $3,%eax
0x00c: addl %edx,%eax
0x00e: halt
# demo-h0.ys
M_dstE = %edx
M_valE = 10
srcA = %edx
srcB = %eax
E_dstE = %eax
Implementing Forwarding
Implementing Forwarding
Instruction
nstruction
memory
PC
PC
increment
Register
file
Register
file
CC
CC ALU
ALU
Data
memory
Data
memory
rB
dstE dstM
ALU
A
ALU
B
Mem.
control
Addr
srcA srcB
read
write
ALU
fun.
data out
data in
A B
M
E
M_valA
W_valE
W_valM
W_valE
Predict
PC
Bch valE valA dstE dstM
valC valA valB dstE dstM srcA srcB
rA valC valP
d_srcA d_srcB
e_Bch
Sel+Fwd
A
Fwd
B
valE valM dstE dstM
m_valM
W_valM
M_valE
e_valE
Limitation of Forwarding
Limitation of Forwarding
Load-use dependency
Load-use dependency
n Value needed by end of
decode stage in cycle 7
n Value read from memory in
memory stage of cycle 8
0x000: irmovl $128,%edx
1 2 3 4 5 6 7 8 9
0x006: irmovl $3,%ecx F D E M
0x00c: rmmovl %ecx, 0(%edx)
F D E M W
0x012: irmovl $10,%ebx F D E M W
0x018: mrmovl 0(%edx), %eax # Load %eax F D E M W
# demo-luh.ys
0x01e: addl %ebx, %eax # Use %eax
0x020: halt
10
11
Error
M_dstM = %eax
m_valM f M[128] = 3
Cycle 7 Cycle 8
valA f M_valE = 10
valB f R[ %eax ] = 0
valA f M_valE = 10
valB f R[ %eax ] = 0
M_dstE = %ebx
M_valE = 10