Docsity

Understanding Stalling and Data Forwarding in CPU Pipelines - Prof. Jian-Guo Liu, Study notes of Mathematics

Toggle sidebar
bg1
Randal E. Bryant
Carnegie Mellon University
CS:APP
CS:APP Chapter 4
Computer Architecture
Pipelined
Implementation
Part II
CS:APP Chapter 4
CS:APP Chapter 4
Computer Architecture
Computer Architecture
Pipelined
Pipelined
Implementation
Implementation
Part II
Part II
http://csapp.cs.cmu.edu
– 2 – CS:APP
Overview
Overview
Make the pipelined processor work!
Data Hazards
Data Hazards
nInstruction having register R as source follows shortly after
instruction having register R as destination
nCommon condition, don’t want to slow down pipeline
Control Hazards
Control Hazards
nMispredict conditional branch
lOur design predicts all branches as being taken
lNaïve pipeline executes two extra instructions
nGetting return address for ret instruction
lNaïve pipeline executes three extra instructions
Making Sure It Really Works
Making Sure It Really Works
nWhat if multiple special cases happen simultaneously?
– 3 – CS:APP
Pipeline Stages
Pipeline Stages
Fetch
Fetch
nSelect current PC
nRead instruction
nCompute incremented PC
Decode
Decode
nRead program registers
Execute
Execute
nOperate ALU
Memory
Memory
nRead or write data memory
Write Back
Write Back
nUpdate register file
PC
increment
PC
increment
CC
CC ALU
ALU
Data
memory
Data
memory
Fetch
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
aluA, aluB
Bch valE
Addr, Data
valM
PC
W_valE, W_valM, W_dstE, W_dstMW_icode, W_valM
icode, ifun,
rA, rB, valC
E
M
W
F
D
valP
f_PC
predPC
Instruction
memory
Instruction
memory
M_icode,
M_Bch,
M_valA
– 4 – CS:APP
PIPE- Hardware
PIPE- Hardware
nPipeline registers hold
intermediate values
from instruction
execution
Forward (Upward) Paths
Forward (Upward) Paths
nValues passed from one
stage to next
nCannot jump past
stages
le.g., valC passes
through decode
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
AALU
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
Bchicode valE valA dstE dstM
icode ifun valC valA valB dstE dstM srcA srcB
valC valPicode ifun rA
predPC
CC
CC
d_srcBd_srcA
e_Bch
M_Bch
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Understanding Stalling and Data Forwarding in CPU Pipelines - Prof. Jian-Guo Liu and more Study notes Mathematics in PDF only on Docsity!

Randal E. Bryant

Carnegie Mellon University

CS:APP

CS:APP Chapter 4

Computer Architecture

Pipelined

Implementation

Part II

CS:APP Chapter 4 CS:APP Chapter 4

Computer Architecture Computer Architecture

Pipelined Pipelined

Implementation Implementation

Part IIPart II

http://csapp.cs.cmu.edu

– 2 – CS:APP

Overview Overview

Make the pipelined processor work!

Data HazardsData 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 HazardsControl Hazards

n Mispredict conditional branch

l Our design predicts all branches as being taken

l Naïve pipeline executes two extra instructions

n Getting return address for ret instruction

l Naïve pipeline executes three extra instructions

Making Sure It Really WorksMaking Sure It Really Works

n What if multiple special cases happen simultaneously?

Pipeline Stages Pipeline Stages

FetchFetch

n Select current PC

n Read instruction

n Compute incremented PC

DecodeDecode

n Read program registers

ExecuteExecute

n Operate ALU

MemoryMemory

n Read or write data memory

Write BackWrite Back

n Update register file

PC increment

PC increment

CCCC^ ALUALU

Data memory Data memory

Fetch

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

aluA, aluB

Bch valE

Addr, Data

valM

PC

W_icode, W_valM W_valE, W_valM, W_dstE, W_dstM

icode, ifun, rA, rB, valC

E

M

W

F

D

valP

f_PC

predPC

Instruction memory

Instruction memory

M_icode, M_Bch, M_valA

PIPE- Hardware PIPE- Hardware

n Pipeline registers hold intermediate values from instruction execution

Forward (Upward) PathsForward (Upward) Paths

n Values passed from one stage to next

n Cannot jump past stages

l e.g., valC passes

through decode

E

M

W

F

D

Instruction memory

Instruction memory PC increment

PC increment

Register file

Register file

ALUALU

Data memory

Data memory

Select PC

rB

SelectA dstE dstM

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

– 5 – CS:APP

Data Dependencies: 2 Nop’s 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

– 6 – CS:APP

Data Dependencies: No Nop Data Dependencies: No Nop

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

E

D

valA R[%edx] = 0 valB R[%eax] = 0

D

valA R[%edx] = 0 valB R[%eax] = 0

Cycle 4

Error

M

M_valE = 10 M_dstE = (^) %edx

e_valE 0 + 3 = 3 E_dstE = %eax

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

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

Stall Condition Stall Condition

Source RegistersSource Registers

n srcA and srcB of current instruction in decode stage

Destination RegistersDestination Registers

n dstE and dstM fields

n Instructions in execute, memory, and write-back stages

Special CaseSpecial Case

n Don’t stall for register ID 8

l Indicates absence of

register operand

E

M

W

F

D

Instruction memory

Instruction memory PC increment

PC increment

Register file

Register file

ALUALU

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

CCCC

d_srcA d_srcB

e_Bch

M_Bch

– 13 – CS:APP

Pipeline Register Modes 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

– 14 – CS:APP

Data Forwarding Data Forwarding

Naïve PipelineNaïve Pipeline

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

n Source operands read from register file in decode stage

l Needs to be in register file at start of stage

ObservationObservation

n Value generated in execute or memory stage

TrickTrick

n Pass value directly from generating instruction to decode stage

n Needs to be available at end of decode stage

– 15 – CS:APP

Data Forwarding Example Data Forwarding Example

n irmovl in write- back stage

n Destination value in W pipeline register

n Forward as valB for decode stage

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

Cycle 6 W R[%eax] 3

D valA R[%edx] = 10 valB W_valE = 3

W_dstE = %eax W_valE = 3

srcA = %edx srcB = %eax

– 16 – CS:APP

Bypass Paths Bypass Paths

Decode StageDecode Stage

n Forwarding logic selects valA and valB

n Normally from register file

n Forwarding: get valA or valB from later pipeline stage

Forwarding SourcesForwarding Sources

n Execute: valE

n Memory: valE, valM

n Write back: valE, valM

PC increment

PC increment

CCCC (^) ALUALU

Data memory

Data memory

Fetch

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

predPC

Instruction memory

Instruction memory

M_icode, M_Bch, M_valA

M_valE

W_valE W_valM

E_valA, E_valB, E_srcA, E_srcB

Forward

– 17 – CS:APP

Data Forwarding Example #2 Data Forwarding Example #

Register Register %%edxedx

n Generated by ALU

during previous cycle

n Forward from memory

as valA

Register Register %%eaxeax

n Value just generated

by ALU

n 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 f M_valE = 10 valB f e_valE = 3

M_dstE = %edx M_valE = 10

srcA = %edx srcB = %eax

E

E_dstE = %eax e_valE f 0 + 3 = 3

– 18 – CS:APP

Implementing

Forwarding

Implementing

Forwarding

n Add additional feedback paths from E, M, and W pipeline registers into decode stage

n Create logic blocks to select from multiple sources for valA and valB in decode stage

M

F

D

Instruction memory

Instruction memory

PC increment

PC increment

Register file

Register file

CCCC ALUALU

Data memory

Data memory

Select PC

rB

dstE dstM

ALU A

ALU B

Mem. control

Addr

srcA srcB

read write

ALU fun.

Fetch

Decode

Execute

Memory

Write back

data out

data in

A B (^) M E

M_valA

W_valE

W_valM W_valE

M_valA W_valM

f_PC

Predict PC

icode Bch valE valA dstE dstM

E icode ifun valC valA valB dstE dstM srcA srcB

icode ifun rA valC valP

predPC

d_srcA d_srcB

e_Bch

M_Bch

Sel+Fwd A

Fwd B

W icode valE valM dstE dstM m_valM

W_valM

M_valE

e_valE

– 19 – CS:APP

Implementing Forwarding Implementing Forwarding

Instruction memory

Instruction memory

PC increment

PC increment

Register file

Register file

CCCC ALUALU

Data memory

Data memory

Select PC

rB

dstE dstM

ALU A

ALU B

Mem. control

Addr

srcA srcB

read write

ALU fun.

e

te

ry

back

data out

data in

A B (^) M

E

M_valA

W_valE

W_valM W_valE

M_valA W_valM

f_PC

Predict PC

icode Bch valE valA dstE dstM

icode ifun valC valA valB dstE dstM srcA srcB

icode ifun rA valC valP

d_srcA d_srcB

e_Bch

M_Bch

Sel+Fwd A

Fwd B

icode valE valM dstE dstM m_valM

W_valM

M_valE

e_valE

## 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;

];

– 20 – CS:APP

Limitation of Forwarding Limitation of Forwarding

Load-use dependencyLoad-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

F D E M 0x006: irmovl $3,%ecx (^) F D E M W

W

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

F D E M W

F D E M W

10

F D E M W

11

Error

M

M_dstM = %eax m_valM f M[128] = 3

Cycle 7 Cycle 8

D

valA f M_valE = 10 valB f R[ %eax ] = 0

D

valA f M_valE = 10 valB f R[ %eax ] = 0

M

M_dstE = %ebx M_valE = 10

– 25 – CS:APP

Handling Misprediction Handling Misprediction

Predict branch as taken Predict branch as taken

n Fetch 2 instructions at target

Cancel when Cancel when mispredictedmispredicted

n Detect branch not-taken in execute stage

n On following cycle, replace instructions in execute and decode by bubbles

n No side effects have occurred yet

0x000: xorl %eax,%eax

1 2 3 4 5 6 7 8 9

FF DD EE MM WW

0x002: jne target # Not taken FF DD EE MM WW

E M W

# demo-j.ys^10

0x011: t: irmovl $2,%edx # Target bubble 0x017: irmovl $3,%ebx # Target+

F D

E M W

D

F

bubble 0x007: irmovl $1,%eax # Fall through 0x00d: nop

FF DD EE MM WW

FF DD EE MM WW

– 26 – CS:APP

Detecting Mispredicted Branch Detecting Mispredicted Branch

MispredictedMispredicted^ BranchBranch E_E_icodeicode^ = IJXX & !e_Bch= IJXX & !e_Bch

ConditionCondition TriggerTrigger

M

F

D

Instruction memory

Instruction memory

PC increment

PC increment

Register file

Register file

CCCC ALUALU

Data memory

Data memory

Select PC

rB

dstE dstM

ALU A

ALU B

Mem. control

Addr

srcA srcB

read write

ALU fun.

Fetch

Decode

Execute

Memory

Write back

data out

data in

A B (^) M

E

M_valA

W_valE

W_valM W_valE

M_valA W_valM

f_PC

Predict PC

icode Bch valE valA dstE dstM

E icode ifun valC valA valB dstE dstM srcA srcB

icode ifun rA valC valP

predPC

d_srcA d_srcB

e_Bch

M_Bch

Sel+Fwd A Fwd B

W icode valE valM dstE dstM m_valM

W_valM

M_valE

e_valE

M

F

D

Instruction memory

Instruction memory

PC increment

PC increment

Register file

Register file

CCCC ALUALU

Data memory

Data memory

Select PC

rB

dstE dstM

ALU A

ALU B

Mem. control

Addr

srcA srcB

read write

ALU fun.

Fetch

Decode

Execute

Memory

Write back

data out

data in

A B (^) M

E

M_valA

W_valE

W_valM W_valE

M_valA W_valM

f_PC

Predict PC

icode Bch valE valA dstE dstM

E icode ifun valC valA valB dstE dstM srcA srcB

icode ifun rA valC valP

predPC

d_srcA d_srcB

e_Bch

M_Bch

Sel+Fwd A Fwd B

W icode valE valM dstE dstM m_valM

W_valM

M_valE

e_valE

m_valM

W_valM

M_valE

e_valE

M

F

D

Instruction memory

Instruction memory

PC increment

PC increment

Register file

Register file

CCCC ALUALU

Data memory

Data memory

Select PC

rB

dstE dstM

ALU A

ALU B

Mem. control

Addr

srcA srcB

read write

ALU fun.

Fetch

Decode

Execute

Memory

Write back

data out

data in

A B (^) M

E

M_valA

W_valE

W_valM W_valE

M_valA W_valM

f_PC

Predict PC

icode Bch valE valA dstE dstM

E icode ifun valC valA valB dstE dstM srcA srcB

icode ifun rA valC valP

predPC

d_srcA d_srcB

e_Bch

M_Bch

Sel+Fwd A Fwd B

W icode valE valM dstE dstM m_valM

W_valM

M_valE

e_valE

m_valM

W_valM

M_valE

e_valE

M

F

D

Instruction memory

Instruction memory

PC increment

PC increment

Register file

Register file

CCCC ALUALU

Data memory

Data memory

Select PC

rB

dstE dstM

ALU A

ALU B

Mem. control

Addr

srcA srcB

read write

ALU fun.

Fetch

Decode

Execute

Memory

Write back

data out

data in

A B (^) M

E

M_valA

W_valE

W_valM W_valE

M_valA W_valM

f_PC

Predict PC

icode Bch valE valA dstE dstM

E icode ifun valC valA valB dstE dstM srcA srcB

icode ifun rA valC valP

predPC

d_srcA d_srcB

e_Bch

M_Bch

Sel+Fwd A Fwd B

W icode valE valM dstE dstM m_valM

W_valM

M_valE

e_valE

m_valM

W_valM

M_valE

e_valE

m_valM

W_valM

M_valE

e_valE

m_valM

W_valM

M_valE

e_valE

Control for Misprediction Control for Misprediction

0x000: xorl %eax,%eax

1 2 3 4 5 6 7 8 9

FF DD EE MM WW

0x002: jne target # Not taken FF DD EE MM WW

E M W

# demo-j.ys^10

0x011: t: irmovl $2,%edx # Target bubble 0x017: irmovl $3,%ebx # Target+

F D

E M W

D

F

bubble 0x007: irmovl $1,%eax # Fall through 0x00d: nop

FF DD EE MM WW

FF DD EE MM WW

normal normal

F F

bubblebubble

DD

bubble bubble

EE

normal normal

M M

normalnormal

W W

MispredictedMispredicted BranchBranch

ConditionCondition

0x000: irmovl Stack,%esp # Initialize stack pointer

0x006: call p # Procedure call

0x00b: irmovl $5,%esi # Return point

0x011: halt

0x020: .pos 0x

0x020: p: irmovl $-1,%edi # procedure

0x026: ret

0x027: irmovl $1,%eax # Should not be executed

0x02d: irmovl $2,%ecx # Should not be executed

0x033: irmovl $3,%edx # Should not be executed

0x039: irmovl $4,%ebx # Should not be executed

0x100: .pos 0x

0x100: Stack: # Stack: Stack pointer

Return Example Return Example

n Previously executed three additional instructions

demo-retb.ys

– 29 – CS:APP

0x026: ret F D E M

bubble F D E M W

W

bubble F D E M W

bubble F D E M W

0x00b: irmovl $5,%esi # Return F D E M W

# demo-retb

F D E M W

F

valC

5 rB

(^) %esi

F

valC

5 rB

(^) %esi

W

valM = (^) 0x0b

W

valM = (^) 0x0b

Correct Return Example Correct Return Example

n As ret passes through pipeline, stall at fetch stage

l While in decode, execute, and

memory stage

n Inject bubble into decode stage

n Release stall when reach write-back stage

– 30 – CS:APP

Detecting Return Detecting Return

Processing retProcessing ret IRET in { D_ IRET in { D_icodeicode, E_, E_icodeicode, M_, M_icodeicode }}

ConditionCondition Trigger Trigger

M

D

Register file

Register file

CCCC ALUALU

rB

dstE dstM

ALU A

ALU B

srcA srcB

ALU fun.

Decode

Execute

A B (^) M E

W_valM W_valE

icode Bch valE valA dstE dstM

E icode ifun valC valA valB dstE dstM srcA srcB

icode ifun rA valC valP

d_srcA d_srcB

e_Bch

M_Bch

Sel+Fwd A Fwd B

M_valE

e_valE

0x026: ret F D E M

bubble F D E M W

W

bubble F D E M W

bubble F D E M W

0x00b: irmovl $5,%esi # Return F D E M W

# demo-retb

F D E M W

Control for Return Control for Return

stall stall

F F

bubblebubble

D D

normal normal

EE

normalnormal

M M

normalnormal

W W

Processing retProcessing ret

ConditionCondition

Special Control Cases Special Control Cases

DetectionDetection

Action (on next cycle)Action (on next cycle)

MispredictedMispredicted BranchBranch E_E_icodeicode = IJXX & !e_Bch= IJXX & !e_Bch

E_E_icodeicode in { IMRMOVL, IPOPL } &&in { IMRMOVL, IPOPL } &&

E_E_dstMdstM in { d_in { d_srcAsrcA, d_, d_srcBsrcB }}

Load/Use HazardLoad/Use Hazard

Processing retProcessing ret IRET in { D_IRET in { D_icodeicode, E_, E_icodeicode, M_, M_icodeicode }}

ConditionCondition TriggerTrigger

normalnormal

stallstall

stallstall

FF

bubble bubble

stallstall

bubble bubble

DD

bubblebubble

bubblebubble

normalnormal

E E

normalnormal

normalnormal

normalnormal

MM

normal normal

normal normal

normal normal

WW

Mispredicted Mispredicted BranchBranch

Load/Use Hazard Load/Use Hazard

Processing ret Processing ret

Condition Condition

– 37 – CS:APP

Control Combination B Control Combination B

n Would attempt to bubble and stall pipeline register D

n Signaled by processor as pipeline error

E^ Load

D Use

M

Load/use

E

D ret

M

ret 1

E

D ret

M

ret 1

E

D ret

M

ret 1

Combination B

stall stall

stall stall

stall stall

FF

bubble +bubble +

stallstall

stallstall

bubble bubble

D D

bubblebubble

bubblebubble

normal normal

EE

normalnormal

normalnormal

normalnormal

MM

normalnormal

normalnormal

normalnormal

W W

Combination Combination

Load/Use Hazard Load/Use Hazard

Processing ret Processing ret

Condition Condition

– 38 – CS:APP

Handling Control Combination B Handling Control Combination B

n Load/use hazard should get priority

n ret instruction should be held in decode stage for additional cycle

E^ Load

D Use

M

Load/use

E

D ret

M

ret 1

E

D ret

M

ret 1

E

D ret

M

ret 1

Combination B

stall stall

stall stall

stall stall

F F

stall stall

stall stall

bubblebubble

DD

bubble bubble

bubble bubble

normalnormal

EE

normal normal

normal normal

normal normal

M M

normalnormal

normalnormal

normalnormal

W W

CombinationCombination

Load/Use HazardLoad/Use Hazard

Processing retProcessing ret

ConditionCondition

Corrected Pipeline Control Logic Corrected Pipeline Control Logic

n Load/use hazard should get priority

n ret instruction should be held in decode stage for additional cycle

stall stall

stall stall

stall stall

FF

stallstall

stallstall

bubble bubble

D D

bubblebubble

bubblebubble

normal normal

EE

normalnormal

normalnormal

normalnormal

MM

normalnormal

normalnormal

normalnormal

W W

Combination Combination

Load/Use Hazard Load/Use Hazard

Processing ret Processing ret

Condition Condition

bool D_bubble =

# Mispredicted branch

(E_icode == IJXX && !e_Bch) ||

# Stalling at fetch while ret passes through pipeline

IRET in { D_icode, E_icode, M_icode }

# but not condition for a load/use hazard

&& !(E_icode in { IMRMOVL, IPOPL }

&& E_dstM in { d_srcA, d_srcB });

Pipeline Summary Pipeline Summary

Data HazardsData Hazards

n Most handled by forwarding

l No performance penalty

n Load/use hazard requires one cycle stall

Control HazardsControl Hazards

n Cancel instructions when detect mispredicted branch

l Two clock cycles wasted

n Stall fetch stage while ret passes through pipeline

l Three clock cycles wasted

Control CombinationsControl Combinations

n Must analyze carefully

n First version had subtle bug

l Only arises with unusual instruction combination