Docsity

Pipeline Stalling and Forwarding in Computer Architecture, Slides of Software Engineering

Partial preview of the text

Download Pipeline Stalling and Forwarding in Computer Architecture and more Slides Software Engineering in PDF only on Docsity!

Randal E. Bryant

Carnegie Mellon University

CS:APP2e

CS:APP Chapter 4

Computer Architecture

Pipelined

Implementation

Part II

http://csapp.cs.cmu.edu

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

 Our design predicts all branches as being taken

 Naïve pipeline executes two extra instructions

Getting return address for ret instruction

 Naïve pipeline executes three extra instructions

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

 e.g., valC passes

through decode

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

W

R[%eax] ^3

D

valA ^ R[%edx] = 10 valB  R[%eax] = 0

W

R[%eax] ^3

W

R[%eax] ^3

D

valA ^ R[%edx] = 10 valB  R[%eax] = 0

D

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

E M W

0x00e: addl %edx,%eax (^) D D E M W 0x010: halt (^) F D E M W

# demo-h2.ys^10

F

0x00d: nop F D E M W

11

  • 8 – CS:APP2e

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)

 Indicates absence of

register operand

Don’t stall for failed conditional move

  • 10 – CS:APP2e

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

F

E M W

bubble

D

E M W

0x00c: addl %edx,%eax (^) D D E M W 0x00e: halt (^) F D E M W

# demo-h0.ys^10

F F

D

F

bubble E M W

11

Cycle 4 (^) •

W

W_dstE = %eax

D

srcA = %edx srcB = %eax

M

M_dstE = %eax

D

srcA = %edx srcB = %eax

E

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

 Like dynamically generated nop’s

 Move through later stages

0x000: irmovl $10,%edx 0x006: irmovl $3,%eax 0x00c: addl %edx,%eax

Cycle 4

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

Cycle 5

0x00e: halt

0x006: irmovl $3,%eax bubble

0x00c: addl %edx,%eax

bubble

Cycle 6

0x00e: halt

bubble bubble

0x00c: addl %edx,%eax

bubble

Cycle 7

0x00e: halt

bubble bubble

Cycle 8

0x00c: addl %edx,%eax 0x00e: halt

Write Back

Memory

Execute

Decode

Fetch

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

Normal^ xx

Input = y Output = x

stall = 1

bubble = 0

Stall xx

Input = y Output = x

stall = 0

bubble = 1

Bubble

Data Forwarding

Naïve Pipeline

Register isn’t written until completion of write-back stage

Source operands read from register file in decode stage

 Needs to be in register file at start of 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

 Generated by ALU

during previous cycle

 Forward from memory

as valA

Register %eax

 Value just generated

by ALU

 Forward from execute

as valB

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

W

0x00c: addl %edx,%eax F D E M W 0x00e: halt F D E M W

# demo-h0.ys

Cycle 4

M

D

valA  M_valE = 10 valB  e_valE = 3

M_dstE = %edx M_valE = 10

srcA = %edx srcB = %eax

E

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 = [

Use incremented PC

D_icode in { ICALL, IJXX } : D_valP;

Forward valE from execute

d_srcA == e_dstE : e_valE;

Forward valM from memory

d_srcA == M_dstM : m_valM;

Forward valE from memory

d_srcA == M_dstE : M_valE;

Forward valM from write back

d_srcA == W_dstM : W_valM;

Forward valE from write back

d_srcA == W_dstE : W_valE;

Use value read from register file

1 : d_rvalA; ];**