Docsity

Pipelined Processor - Computer Architecture and Design - Lecture Slides, Slides of Computer Science

Toggle sidebar
bg1
Page 1
1chapter 6
Designing a Pipelined Processor
In this Chapter, we will study
1. Pipelined datapath
2. Pipelined control
3. Data Hazards
4. Forwarding
5. Branch Hazards
6. Performance
2chapter 6
Pipelining is Natural
Car Wash Station (non-pipelined)
Vacuum Wash Dry
Brian
Steve Brian
Steve Brian
Steve Brian
Bob Steve
Car Wash Station (pipelined)
Vacuum Wash Dry
Brian
Steve Brian
Bob Steve Brian
Mike Bob Steve Brian
Gorge Mike Bob Steve
Vacuum, Wash, Dry each takes
5 minutes
Nonpipelined Car Wash Station
serving one customer per 15
minutes
Pipelined Car Wash Station
after the first customer (it takes
15 minutes), then every 5
minutes finishing service for
a new customer
3chapter 6
What we learn from car wash station
•Pipelining does not help latency of a single task, but it
helps throughput of entire workload
•Pipeline rate is limited by the slowest pipeline stage
•Multiple tasks operating simultaneously using different
resources
•Potential speedup = Number of stages
•Unbalanced lengths of pipe stages reduces speedup
•Time to fill the pipe and time to drain the pipe -> reduce
speedup
•Stall the pipe for dependences
4chapter 6
Performance
•Suppose we execute 100 instruction
•single cycle implementation
–50 ns/cycle x 1 CPI x 100 inst. = 5000 ns
•multiple cycle implementation
–10 ns/cycle x 4.6 CPI (instr. mix) x 100 inst = 4600 ns
•ideal pipelined processor
–10 ns/cycle x (1 CPI x 100 inst + 4 cycle to fill up the pipe)
= 1040 ns
–here we assume that 5 stages in the pipeline
–5 stages : IF, ID, EX, MEM, WB
Docsity.com
pf3
pf4
pf5
pf8

Partial preview of the text

Download Pipelined Processor - Computer Architecture and Design - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

1 Page 1

chapter 6

Designing a Pipelined ProcessorIn this Chapter, we will study1. Pipelined datapath2. Pipelined control3. Data Hazards4. Forwarding5. Branch Hazards6. Performance

chapter 6

Pipelining is Natural

Car Wash Station (non-pipelined)Vacuum

Wash^

Dry

BrianSteve^

Brian

Steve^

Brian

Steve^

Brian

Bob^

SteveCar Wash Station (pipelined)Vacuum

Wash^

Dry

BrianSteve^

Brian

Bob^

Steve^

Brian

Mike^

Bob^

Steve^

Brian

Gorge

Mike

Bob^

Steve

Vacuum, Wash, Dry each takes5 minutesNonpipelined Car Wash Stationserving one customer per 15minutes Pipelined Car Wash Stationafter the first customer (it takes15 minutes), then every 5minutes finishing service fora new customer

chapter 6

What we learn from car wash station • Pipelining does not help latency of a single task, but ithelps throughput of entire workload • Pipeline rate is limited by the slowest pipeline stage • Multiple tasks operating simultaneously using differentresources • Potential speedup = Number of stages • Unbalanced lengths of pipe stages reduces speedup • Time to fill the pipe and time to drain the pipe -> reducespeedup • Stall the pipe for dependences

chapter 6

Performance

-^ Suppose we execute 100 instruction •^ single cycle implementation^ –^ 50 ns/cycle x 1 CPI x 100 inst. = 5000 ns •^ multiple cycle implementation^ –^ 10 ns/cycle x 4.6 CPI (instr. mix) x 100 inst = 4600 ns •^ ideal pipelined processor^ –^ 10 ns/cycle x (1 CPI x 100 inst + 4 cycle to fill up the pipe)= 1040 ns^ –^ here we assume that 5 stages in the pipeline^ –^ 5 stages : IF, ID, EX, MEM, WB

5 Page 2

chapter 6

Why pipeline?

Because the resources are there! Why waste !Start fetching and executing the next instruction beforethe current one has completedRemember

the^ performance equation:
CPU time = CPI * CC * IC
Fetch (and execute) more than one instruction at a timeSuperscalar processing – stay tuned

chapter 6

A Pipelined MIPS Processor

-^ Start the next instruction before the current one has completed^ –^ improves throughput - total amount of work done in a giventime^ –^ instruction latency (execution time, delay time, response time- time from the start of an instruction to its completion) is

not

reducedCycle 1

Cycle 2

Cycle 3 Cycle 4

Cycle 5

IFetch^

Dec^

Exec^

Mem^

WB
lw

Cycle 7 Cycle 6^

Cycle 8

sw^

IFetch^

Dec^

Exec^

Mem^

WB
R-type^

IFetch^

Dec^

Exec^

Mem^

WB
»^ clock cycle (pipeline stage time) is limited by the slowest stage »^ for some instructions, some stages are wasted cycles

chapter 6

Single Cycle, Multiple Cycle, vs. PipelineMultiple Cycle Implementation:Cycle 1Clk IFetch^

Dec^ Exec

Mem

WB

Cycle 2 Cycle 3 Cycle 4 Cycle 5 Cycle 6 Cycle 7 Cycle 8 Cycle 9Cycle 10

IFetch^

Dec^ Exec

Mem

lw^

sw

R-type^ IFetch

lw^ IFetch

Dec^

Exec^

Mem^

WB

Pipeline Implementation:

IFetch^

Dec^ Exec

Mem

WB

sw

IFetch^

Dec^ Exec

Mem

WB

R-type Single Cycle Implementation:Clk

lw^

sw^

Waste

Cycle 1^

Cycle 2

chapter 6

MIPS Pipeline Datapath Modifications

-^ What do we need to add/modify in our MIPS datapath?^ –^ State registers between each pipeline stage to isolate them^ Instruction^ ReadAddress

Add 4 MemoryPC

Read Addr 1^ RegisterRead Addr 2FileWrite Addr Write Data

ReadData 1ReadData 2 16

32

AddShiftleft 2 ALU

DataMemoryRead AddressDataWrite Data

IFetch/Dec

Dec/Exec

Exec/Mem

Mem/WB

IF:IFetch

ID:Dec^

EX:Execute

MEM:MemAccess

WB:WriteBack

System Clock

SignExtend

13 Page 4

chapter 6^ I nst r. Or der
Time (clock cycles)

lw Inst 1Inst 2Inst 3Inst 4

ALU

Mem^

Reg^

Mem^

Reg ALU

Mem^

Reg^

Mem^

Reg ALU

Mem^

Reg^

Mem^

Reg ALU

Mem^

Reg^

Mem^

Reg ALU

Mem^

Reg^

Mem^

Reg

A Single Memory Would Be a Structural Hazard

Reading data frommemory

Reading instructionfrom memory

-^ Fix with separate instr and data memories (I$ and D$)

chapter 6How About Register File Access?^ I nst r. Or der

Time (clock cycles)

add $1, Inst 1Inst 2 add $2,$1,

ALU

IM^ Reg

DM^

Reg ALU IM^ Reg

DM^

Reg ALU IM^ Reg

DM^

Reg ALU IM^ Reg

DM^

Reg

chapter 6

How About Register File Access? I nst r. Or der

Time (clock cycles)

Inst 1Inst 2

ALU

IM^ Reg

DM^

Reg ALU IM^ Reg

DM^

Reg ALU IM^ Reg

DM^

Reg ALU IM^ Reg

DM^

Fix register fileaccess hazard bydoing reads in thesecond half of thecycle and writes inthe first halfReg

add $1, add $2,$1,^ clock edge that controlsregister writing

clock edge that controlsloading of pipeline stateregisters

chapter 6

Register Usage Can Cause Data Hazards add $1, I ns sub $4,$1,$5 t r. and $6,$1,$7 Or d or^ $8,$1,$9 er xor $4,$1,$

ALU

IM^ Reg

DM^

Reg ALU IM^ Reg

DM^

Reg ALU IM^ Reg

DM^

Reg ALU IM^ Reg

DM^

Reg ALU IM^ Reg

DM^

Reg

-^ Dependencies backward in time cause hazards^ •^ Read before write data hazard

17 Page 5

chapter 6

Register Usage Can Cause Data Hazards

ALU

IM^ Reg

DM^

Reg ALU IM^ Reg

DM^

Reg ALU IM^ Reg

DM^

Reg ALU IM^ Reg

DM^

Reg ALU IM^ Reg

DM^

Reg

-^ Dependencies backward in time cause hazards add $1,sub $4,$1,$5and $6,$1,$7or^ $8,$1,$9xor $4,$1,$5^ •^ Read before write data hazard

chapter 6

Loads Can Cause Data Hazards lw^ $1,4($2) I ns sub $4,$1,$5 t r. and $6,$1,$7 Or d or^ $8,$1,$9 er xor $4,$1,$

ALU

IM^ Reg

DM^

Reg ALU IM^ Reg

DM^

Reg ALU IM^ Reg

DM^

Reg ALU IM^ Reg

DM^

Reg ALU IM^ Reg

DM^

Reg

-^ Dependencies backward in time cause hazards^ •^ Load-use data hazard

chapter 6

One Way to “Fix” a Data Hazard^ add $1, I ns^ stall t r. O stall r der

ALU

IM^ Reg

DM^

Reg

sub $4,$1,$5and $6,$1,$

ALU

IM^ Reg

DM^

Reg ALU IM^ Reg

DM^

Reg

Can fix datahazard bywaiting – stall –but impacts CPI

chapter 6Another Way to “Fix” a Data Hazard^ add $1,^ I nst r. Or der

ALU

IM^ Reg

DM^

Reg

sub $4,$1,$5and $6,$1,$

ALU

IM^ Reg

DM^

Reg ALU IM^ Reg

DM^

Fix data hazardsby^ forwarding results as soon asthey are Reg

available

to where they are

needed

or^ xor $4,$1,$

$8,$1,$

ALU

IM^ Reg

DM^

Reg ALU IM^ Reg

DM^

Reg

25 Page 7

chapter 6

One Way to “Fix” a Control Hazard beq I ns stall t r. O stall r de stall r

ALU

IM^ Reg

DM^

Reg

lw

ALU

IM^ Reg

DM^

Reg ALU

Inst 3

IM^ Reg

DM

Fix branchhazard bywaiting –stall – butaffects CPI

chapter 6

Corrected Datapath to Save RegWrite Addr • Need to preserve the destination register address in thepipeline state registers^ InstructionMemory ReadAddress

Add (^4) PC

Read Addr 1^ RegisterRead Addr 2FileWrite Addr Write Data

ReadData 1ReadData 2 16

32

AddShiftleft 2 ALU

DataMemoryRead AddressDataWrite Data

IF/ID

SignExtend

ID/EX^

EX/MEM

MEM/WB

chapter 6

Corrected Datapath to Save RegWrite Addr • Need to preserve the destination register address in thepipeline state registers^ InstructionMemory ReadAddress

Add (^4) PC

Read Addr 1^ RegisterRead Addr 2FileWrite Addr Write Data

ReadData 1ReadData 2 16

32

AddShiftleft 2 ALU

DataMemoryRead AddressDataWrite Data

IF/ID

SignExtend

ID/EX^

EX/MEM

MEM/WB

chapter 6

MIPS Pipeline Control Path Modifications • All control signals can be determined during Decode – and held in the state registers between pipeline stages^ InstructionMemory ReadAddress

Add (^4) PC

Read Addr 1^ RegisterRead Addr 2FileWrite Addr Write Data

ReadData 1ReadData 2 16

32

AddShiftleft 2 ALU

DataMemoryRead AddressDataWrite Data

IF/ID

SignExtend

ID/EX

EX/MEM

MEM/WB

Control

29 Page 8

chapter 6

Other Pipeline Structures Are Possible • What about the (slow) multiply operation?^ –^ Make the clock twice as slow or …^ –^ let it take two cycles (since it doesn’t use the DM stage)

ALU

IM^ Reg

DM^

Reg MUL ALU IM^ Reg

DM^

DM2Reg

-^ What if the data memory access is twice as slow as theinstruction memory?^ –^ make the clock twice as slow or …^ –^ let data memory access take two cycles (and keep the sameclock rate)

chapter 6Sample Pipeline Alternatives^ •^

ARM7 • StrongARM-1 • XScale

ALU
IM1^ IM

RegDM1 DM

IM^ Reg

EX

PC updateIM access

decoderegaccess

ALU opDM accessshift/rotatecommit result(write back) ALU IM^ Reg

DM^

Reg Reg^ SHFT PC updateBTB accessstart IM access

IM access

decodereg 1 accessshift/rotatereg 2 access

ALU opstart DM accessexception

DM writereg write

chapter 6Summary^ •

All modern day processors use pipelining • Pipelining doesn’t help latency of single task, it helpsthroughput of entire workload • Potential speedup: a CPI of 1 and fast a CC • Pipeline rate limited by slowest pipeline stage^ –^ Unbalanced pipe stages makes for inefficiencies^ –^ The time to “fill” pipeline and time to “drain” it can impactspeedup for deep pipelines and short code runs • Must detect and resolve hazards^ –^ Stalling negatively affects CPI (makes CPI less than the ideal of1)