Download presentation
Presentation is loading. Please wait.
Published byBarnaby Harrison Modified over 9 years ago
1
CSE431 L06 Basic MIPS Pipelining.1Irwin, PSU, 2005 MIPS Pipeline Datapath Modifications What do we need to add/modify in our MIPS datapath? l State registers between each pipeline stage to isolate them
2
CSE431 L06 Basic MIPS Pipelining.2Irwin, PSU, 2005 Pipelining the MIPS ISA What makes it easy l all instructions are the same length (32 bits) -can fetch in the 1 st stage and decode in the 2 nd stage l few instruction formats (three) with symmetry across formats -can begin reading register file in 2 nd stage l memory operations can occur only in loads and stores -can use the execute stage to calculate memory addresses What makes it hard l structural hazards: what if we had only one memory? l control hazards: what about branches? l data hazards: what if an instruction’s input operands depend on the output of a previous instruction?
3
CSE431 L06 Basic MIPS Pipelining.3Irwin, PSU, 2005 Graphically Representing MIPS Pipeline Can help with answering questions like: l How many cycles does it take to execute this code? l What is the ALU doing during cycle 4? l Is there a hazard, why does it occur, and how can it be fixed? ALU IM Reg DMReg
4
CSE431 L06 Basic MIPS Pipelining.4Irwin, PSU, 2005 Why Pipeline? For Performance! I n s t r. O r d e r Time (clock cycles) Inst 0 Inst 1 Inst 2 Inst 4 Inst 3 ALU IM Reg DMReg ALU IM Reg DMReg ALU IM Reg DMReg ALU IM Reg DMReg ALU IM Reg DMReg Once the pipeline is full, one instruction is completed every cycle, so CPI = 1 Time to fill the pipeline
5
CSE431 L06 Basic MIPS Pipelining.5Irwin, PSU, 2005 Can Pipelining Get Us Into Trouble? Yes: Pipeline Hazards l structural hazards: attempt to use the same resource by two different instructions at the same time l data hazards: attempt to use data before it is ready -An instruction’s source operand(s) are produced by a prior instruction still in the pipeline l control hazards: attempt to make a decision about program control flow before the condition has been evaluated and the new PC target address calculated -branch instructions Can always resolve hazards by waiting l pipeline control must detect the hazard l and take action to resolve hazards
6
CSE431 L06 Basic MIPS Pipelining.6Irwin, PSU, 2005 I n s t r. O r d e r Time (clock cycles) lw Inst 1 Inst 2 Inst 4 Inst 3 ALU Mem Reg MemReg ALU Mem Reg MemReg ALU Mem Reg MemReg ALU Mem Reg MemReg ALU Mem Reg MemReg A Single Memory Would Be a Structural Hazard Reading data from memory Reading instruction from memory Fix with separate instr and data memories (I$ and D$)
7
CSE431 L06 Basic MIPS Pipelining.7Irwin, PSU, 2005 How About Register File Access? I n s t r. O r d e r Time (clock cycles) add $1, Inst 1 Inst 2 add $2,$1, ALU IM Reg DMReg ALU IM Reg DMReg ALU IM Reg DMReg ALU IM Reg DMReg
8
CSE431 L06 Basic MIPS Pipelining.8Irwin, PSU, 2005 How About Register File Access? I n s t r. O r d e r Time (clock cycles) Inst 1 Inst 2 ALU IM Reg DMReg ALU IM Reg DMReg ALU IM Reg DMReg ALU IM Reg DMReg Fix register file access hazard by doing reads in the second half of the cycle and writes in the first half add $1, add $2,$1, clock edge that controls register writing clock edge that controls loading of pipeline state registers
9
CSE431 L06 Basic MIPS Pipelining.9Irwin, PSU, 2005 Register Usage Can Cause Data Hazards I n s t r. O r d e r add $1, sub $4,$1,$5 and $6,$1,$7 xor $4,$1,$5 or $8,$1,$9 ALU IM Reg DMReg ALU IM Reg DMReg ALU IM Reg DMReg ALU IM Reg DMReg ALU IM Reg DMReg Dependencies backward in time cause hazards Read before write data hazard
10
CSE431 L06 Basic MIPS Pipelining.10Irwin, PSU, 2005 Register Usage Can Cause Data Hazards ALU IM Reg DMReg ALU IM Reg DMReg ALU IM Reg DMReg ALU IM Reg DMReg ALU IM Reg DMReg Dependencies backward in time cause hazards add $1, sub $4,$1,$5 and $6,$1,$7 xor $4,$1,$5 or $8,$1,$9 Read before write data hazard
11
CSE431 L06 Basic MIPS Pipelining.11Irwin, PSU, 2005 Loads Can Cause Data Hazards I n s t r. O r d e r lw $1,4($2) sub $4,$1,$5 and $6,$1,$7 xor $4,$1,$5 or $8,$1,$9 ALU IM Reg DMReg ALU IM Reg DMReg ALU IM Reg DMReg ALU IM Reg DMReg ALU IM Reg DMReg Dependencies backward in time cause hazards Load-use data hazard
12
CSE431 L06 Basic MIPS Pipelining.12Irwin, PSU, 2005 stall One Way to “Fix” a Data Hazard I n s t r. O r d e r add $1, ALU IM Reg DMReg sub $4,$1,$5 and $6,$1,$7 ALU IM Reg DMReg ALU IM Reg DMReg Can fix data hazard by waiting – stall – but impacts CPI
13
CSE431 L06 Basic MIPS Pipelining.13Irwin, PSU, 2005 Another Way to “Fix” a Data Hazard I n s t r. O r d e r add $1, ALU IM Reg DMReg sub $4,$1,$5 and $6,$1,$7 ALU IM Reg DMReg ALU IM Reg DMReg Fix data hazards by forwarding results as soon as they are available to where they are needed xor $4,$1,$5 or $8,$1,$9 ALU IM Reg DMReg ALU IM Reg DMReg
14
CSE431 L06 Basic MIPS Pipelining.14Irwin, PSU, 2005 Another Way to “Fix” a Data Hazard ALU IM Reg DMReg ALU IM Reg DMReg ALU IM Reg DMReg Fix data hazards by forwarding results as soon as they are available to where they are needed ALU IM Reg DMReg ALU IM Reg DMReg I n s t r. O r d e r add $1, sub $4,$1,$5 and $6,$1,$7 xor $4,$1,$5 or $8,$1,$9
15
CSE431 L06 Basic MIPS Pipelining.15Irwin, PSU, 2005 Forwarding with Load-use Data Hazards I n s t r. O r d e r lw $1,4($2) sub $4,$1,$5 and $6,$1,$7 xor $4,$1,$5 or $8,$1,$9 ALU IM Reg DMReg ALU IM Reg DMReg ALU IM Reg DMReg ALU IM Reg DMReg ALU IM Reg DMReg
16
CSE431 L06 Basic MIPS Pipelining.16Irwin, PSU, 2005 Forwarding with Load-use Data Hazards ALU IM Reg DMReg ALU IM Reg DMReg ALU IM Reg DMReg ALU IM Reg DMReg ALU IM Reg DMReg Will still need one stall cycle even with forwarding I n s t r. O r d e r lw $1,4($2) sub $4,$1,$5 and $6,$1,$7 xor $4,$1,$5 or $8,$1,$9
17
CSE431 L06 Basic MIPS Pipelining.17Irwin, PSU, 2005 Branch Instructions Cause Control Hazards I n s t r. O r d e r lw Inst 4 Inst 3 beq ALU IM Reg DMReg ALU IM Reg DMReg ALU IM Reg DMReg ALU IM Reg DMReg Dependencies backward in time cause hazards
18
CSE431 L06 Basic MIPS Pipelining.18Irwin, PSU, 2005 stall One Way to “Fix” a Control Hazard I n s t r. O r d e r beq ALU IM Reg DMReg lw ALU IM Reg DMReg ALU Inst 3 IM Reg DM Fix branch hazard by waiting – stall – but affects CPI
19
CSE431 L06 Basic MIPS Pipelining.19Irwin, PSU, 2005 Corrected Datapath to Save RegWrite Addr Need to preserve the destination register address in the pipeline state registers
20
CSE431 L06 Basic MIPS Pipelining.20Irwin, PSU, 2005 Corrected Datapath to Save RegWrite Addr Need to preserve the destination register address in the pipeline state registers
21
CSE431 L06 Basic MIPS Pipelining.21Irwin, PSU, 2005 MIPS Pipeline Control Path Modifications All control signals can be determined during Decode l and held in the state registers between pipeline stages Control
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.