

































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!


































CS:APP2e
Overview
Make the pipelined processor work!
Data Hazards
Instruction having register R as source follows shortly after instruction having register R as destination
Common condition, don’t want to slow down pipeline
Control Hazards
Mispredict conditional branch
Getting return address for ret instruction
Making Sure It Really Works
What if multiple special cases happen simultaneously?
PIPE- Hardware
Pipeline registers hold intermediate values from instruction execution
Forward (Upward) Paths
Values passed from one stage to next
Cannot jump past stages
Data Dependencies: 2 Nop’s
0x000: irmovl $10,%edx
1 2 3 4 5 6 7 8 9
FF DD EE MM WW 0x006: irmovl $3,%eax (^) FF DD EE MM WW 0x00c: nop (^) FF DD EE MM WW 0x00d: nop (^) FF DD EE MM WW 0x00e: addl %edx,%eax (^) FF DD EE MM WW 0x010: halt (^) FF DD EE MM WW
# demo-h2.ys^10
R[%eax] ^3
valA ^ R[%edx] = 10 valB R[%eax] = 0
R[%eax] ^3
R[%eax] ^3
valA ^ R[%edx] = 10 valB R[%eax] = 0
valA ^ R[%edx] = 10 valB R[%eax] = 0
Cycle 6
Error
Stalling for Data Dependencies
If instruction follows too closely after one that writes register, slow it down
Hold instruction in decode
Dynamically inject nop into execute stage
0x000: irmovl $10,%edx
1 2 3 4 5 6 7 8 9
F D E M W 0x006: irmovl $3,%eax (^) F D E M W 0x00c: nop (^) F D E M W
bubble F
0x00e: addl %edx,%eax (^) D D E M W 0x010: halt (^) F D E M W
# demo-h2.ys^10
0x00d: nop F D E M W
11
Stall Condition
Source Registers
srcA and srcB of current instruction in decode stage
Destination Registers
dstE and dstM fields
Instructions in execute, memory, and write-back stages
Special Case
Don’t stall for register ID 15 (0xF)
Don’t stall for failed conditional move
Stalling X
0x000: irmovl $10,%edx
1 2 3 4 5 6 7 8 9
F D E M W 0x006: irmovl $3,%eax (^) F D E M W bubble
bubble
0x00c: addl %edx,%eax (^) D D E M W 0x00e: halt (^) F D E M W
# demo-h0.ys^10
bubble E M W
11
Cycle 4 (^) •
W_dstE = %eax
srcA = %edx srcB = %eax
M_dstE = %eax
srcA = %edx srcB = %eax
E_dstE = %eax D srcA = %edx srcB = %eax
Cycle 5
Cycle 6
What Happens When Stalling?
Stalling instruction held back in decode stage
Following instruction stays in fetch stage
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
Rising clock
Rising clock
Output = y yy
Rising clock
Rising clock
Output = x xx
xx
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
Naïve Pipeline
Register isn’t written until completion of write-back stage
Source operands read from register file in decode stage
Observation
Value generated in execute or memory stage
Trick
Pass value directly from generating instruction to decode stage
Needs to be available at end of decode stage
Bypass Paths
Decode Stage
Forwarding logic selects valA and valB
Normally from register file
Forwarding: get valA or valB from later pipeline stage
Forwarding Sources
Execute: valE
Memory: valE, valM
Write back: valE, valM
Data Forwarding Example #
Register %edx
Register %eax
0x000: irmovl $10,%edx
1 2 3 4 5 6 7 8
F D E M 0x006: irmovl $3,%eax (^) F D E M W
0x00c: addl %edx,%eax F D E M W 0x00e: halt F D E M W
# demo-h0.ys
Cycle 4
M
valA M_valE = 10 valB e_valE = 3
M_dstE = %edx M_valE = 10
srcA = %edx srcB = %eax
E_dstE = %eax e_valE 0 + 3 = 3
Implementing
Forwarding
Add additional feedback
paths from E, M, and W pipeline registers into decode stage
Create logic blocks to
select from multiple sources for valA and valB in decode stage
Implementing Forwarding
**## What should be the A value? int new_E_valA = [
D_icode in { ICALL, IJXX } : D_valP;
d_srcA == e_dstE : e_valE;
d_srcA == M_dstM : m_valM;
d_srcA == M_dstE : M_valE;
d_srcA == W_dstM : W_valM;
d_srcA == W_dstE : W_valE;
1 : d_rvalA; ];**