ENGS 116 Lecture 51 Pipelining and Hazards Vincent H. Berk September 30, 2005 Reading for today: Chapter A.1 – A.3, article: Patterson&Ditzel Reading for.

Slides:



Advertisements
Similar presentations
1 Pipelining Part 2 CS Data Hazards Data hazards occur when the pipeline changes the order of read/write accesses to operands that differs from.
Advertisements

CMSC 611: Advanced Computer Architecture Pipelining Some material adapted from Mohamed Younis, UMBC CMSC 611 Spr 2003 course slides Some material adapted.
Mehmet Can Vuran, Instructor University of Nebraska-Lincoln Acknowledgement: Overheads adapted from those provided by the authors of the textbook.
Lecture Objectives: 1)Define pipelining 2)Calculate the speedup achieved by pipelining for a given number of instructions. 3)Define how pipelining improves.
Review: Pipelining. Pipelining Laundry Example Ann, Brian, Cathy, Dave each have one load of clothes to wash, dry, and fold Washer takes 30 minutes Dryer.
Pipelining - Hazards.
Instruction-Level Parallelism (ILP)
COMP381 by M. Hamdi 1 Pipeline Hazards. COMP381 by M. Hamdi 2 Pipeline Hazards Hazards are situations in pipelining where one instruction cannot immediately.
ENEE350 Ankur Srivastava University of Maryland, College Park Based on Slides from Mary Jane Irwin ( )
ENEE350 Ankur Srivastava University of Maryland, College Park Based on Slides from Mary Jane Irwin ( )
Mary Jane Irwin ( ) [Adapted from Computer Organization and Design,
Chapter 5 Pipelining and Hazards
©UCB CS 162 Computer Architecture Lecture 3: Pipelining Contd. Instructor: L.N. Bhuyan
1 Stalling  The easiest solution is to stall the pipeline  We could delay the AND instruction by introducing a one-cycle delay into the pipeline, sometimes.
Computer ArchitectureFall 2007 © October 24nd, 2007 Majd F. Sakr CS-447– Computer Architecture.
DLX Instruction Format
Pipelining - II Adapted from CS 152C (UC Berkeley) lectures notes of Spring 2002.
Appendix A Pipelining: Basic and Intermediate Concepts
-1.1- PIPELINING 2 nd week. -2- Khoa Coâng Ngheä Thoâng Tin – Ñaïi Hoïc Baùch Khoa Tp.HCM PIPELINING 2 nd week References Pipelining concepts The DLX.
Pipeline Hazard CT101 – Computing Systems. Content Introduction to pipeline hazard Structural Hazard Data Hazard Control Hazard.
Pipelining. 10/19/ Outline 5 stage pipelining Structural and Data Hazards Forwarding Branch Schemes Exceptions and Interrupts Conclusion.
CPE 731 Advanced Computer Architecture Pipelining Review Dr. Gheith Abandah Adapted from the slides of Prof. David Patterson, University of California,
1 Appendix A Pipeline implementation Pipeline hazards, detection and forwarding Multiple-cycle operations MIPS R4000 CDA5155 Spring, 2007, Peir / University.
EEL5708 Lotzi Bölöni EEL 5708 High Performance Computer Architecture Pipelining.
CPE432 Chapter 4B.1Dr. W. Abu-Sufah, UJ Chapter 4B: The Processor, Part B-2 Read Section 4.7 Adapted from Slides by Prof. Mary Jane Irwin, Penn State University.
CSE 340 Computer Architecture Summer 2014 Basic MIPS Pipelining Review.
CS.305 Computer Architecture Enhancing Performance with Pipelining Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005, and from.
CMPE 421 Parallel Computer Architecture
1 Designing a Pipelined Processor In this Chapter, we will study 1. Pipelined datapath 2. Pipelined control 3. Data Hazards 4. Forwarding 5. Branch Hazards.
CMPE 421 Parallel Computer Architecture Part 2: Hardware Solution: Forwarding.
CECS 440 Pipelining.1(c) 2014 – R. W. Allison [slides adapted from D. Patterson slides with additional credits to M.J. Irwin]
1 (Based on text: David A. Patterson & John L. Hennessy, Computer Organization and Design: The Hardware/Software Interface, 3 rd Ed., Morgan Kaufmann,
2/15/02CSE Data Hazzards Data Hazards in the Pipelined Implementation.
Branch Hazards and Static Branch Prediction Techniques
Oct. 18, 2000Machine Organization1 Machine Organization (CS 570) Lecture 4: Pipelining * Jeremy R. Johnson Wed. Oct. 18, 2000 *This lecture was derived.
HazardsCS510 Computer Architectures Lecture Lecture 7 Pipeline Hazards.
HazardsCS510 Computer Architectures Lecture Lecture 7 Pipeline Hazards.
11 Pipelining Kosarev Nikolay MIPT Oct, Pipelining Implementation technique whereby multiple instructions are overlapped in execution Each pipeline.
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.
Lecture 9. MIPS Processor Design – Pipelined Processor Design #1 Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System.
CS203 – Advanced Computer Architecture Pipelining Review.
Pipelining: Implementation CPSC 252 Computer Organization Ellen Walker, Hiram College.
CSE 340 Computer Architecture Spring 2016 Overcoming Data Hazards.
Computer Organization
Review: Instruction Set Evolution
Pipelining: Hazards Ver. Jan 14, 2014
5 Steps of MIPS Datapath Figure A.2, Page A-8
Single Clock Datapath With Control
Appendix C Pipeline implementation
\course\cpeg323-08F\Topic6b-323
Appendix A - Pipelining
Chapter 4 The Processor Part 3
Review: MIPS Pipeline Data and Control Paths
Morgan Kaufmann Publishers The Processor
Pipelining review.
Pipelining Chapter 6.
Current Design.
Pipelining in more detail
\course\cpeg323-05F\Topic6b-323
Pipeline control unit (highly abstracted)
The Processor Lecture 3.6: Control Hazards
The Processor Lecture 3.5: Data Hazards
Instruction Execution Cycle
Overview What are pipeline hazards? Types of hazards
Pipeline control unit (highly abstracted)
CS203 – Advanced Computer Architecture
Pipeline Control unit (highly abstracted)
Introduction to Computer Organization and Architecture
Throughput = #instructions per unit time (seconds/cycles etc.)
Pipelining Hazards.
Presentation transcript:

ENGS 116 Lecture 51 Pipelining and Hazards Vincent H. Berk September 30, 2005 Reading for today: Chapter A.1 – A.3, article: Patterson&Ditzel Reading for Monday: 3.1, A.4 – A.6, article: Yeager

ENGS 116 Lecture 52 Review: Pipelined DLX Datapath Figure A.18, Page A-31

ENGS 116 Lecture 53 Hazards Hazards are situations that hamper execution flow Structural Hazards: –Resource Conflict, hardware cannot support all possible combinations of instructions simultaneously. Data Hazards: –Source operands are not available: instruction depends on results of previous instructions still in the pipeline Control Hazards: –Changes in program counter

ENGS 116 Lecture 54 Structural Hazards

ENGS 116 Lecture 55 Load Instr 1 Instr 2 stall Instr 3 One Memory Port/Structural Hazards from: SECOND EDITION I n s t r. O r d e r Time (clock cycles) bubble CC 1CC 5CC 2CC 3CC 4CC 6CC 7CC 8 Mem ALU Mem Reg ALU Mem Reg ALU Mem Reg

ENGS 116 Lecture 56 Structural Hazard: Single Memory

ENGS 116 Lecture 57 Speed Up Equation for Pipelining Speedup from pipelining= = Ideal CPI = CPI unpipelined /Pipeline depth Speedup =

ENGS 116 Lecture 58 Speed Up Equation for Pipelining

ENGS 116 Lecture 59 Example: Dual-port vs. Single-port Machine A: Dual ported memory Machine B: Single ported memory, but its pipelined implementation has a clock rate that is 1.2 times faster Ideal CPI=1 for both Loads and stores are 40% of instructions executed Machine A is 1.17 times faster

ENGS 116 Lecture 510 Data Hazards subR2, R1, R3; R2 written by sub and R12, R2, R5; first operand (R2) depends on sub orR13, R6, R2; second operand (R2) depends on sub addR14, R2, R2; both operands depend on sub sw100 (R2), R15; index (R2) depends on sub Notice that the value written into R2 by the subtract instruction is needed in all of the following instructions

ENGS 116 Lecture 511 Classification of Data Hazards Consider instructions i and j, where i occurs before j. RAW (read after write) — j tries to read a source before i writes it, so j gets the old value WAW (write after write) — j tries to write an operand before it is written by i (only possible in pipelines that write in more than one pipe stage or allow an instruction to proceed even when a previous instruction is stalled) WAR (write after read) — j tries to write a destination before it is read by i, so i incorrectly gets the new value (only possible when some instructions can write results early in the pipeline and other instructions can read sources late in the pipeline)

ENGS 116 Lecture 512 Software Solution Compiler recognizes data hazard and adds nops to eliminate it subR2, R1, R3; register R2 written by sub nop; no operation nop andR12, R2, R5; now, result from sub available orR13, R6, R2 addR14, R2, R2 sw100 (R2), R15

ENGS 116 Lecture 513 Data Hazard Control: Stalls Hazard occurs when instruction reads (in ID stage) register that will be written by an earlier instruction (in WB stage) Idea: Detect hazard and stall instructions in pipeline until hazard is resolved Detect hazard by comparing read fields in IF/ID pipeline register with write fields in later pipeline registers (ID/EX, EX/MEM, MEM/WB) To add bubble in pipeline –Preserve PC register and IF/ID pipeline register –Change EX, MEM, and WB control fields of ID/EX pipeline register to do nothing

ENGS 116 Lecture 514 Data Hazard Reduction: Forwarding Needed result is available before it is written into register file in WB stage Idea: Use temporary results instead of waiting for registers to be written Cannot solve problem of write (load) followed by read Almost all pipelined machines today use some form of forwarding

ENGS 116 Lecture 515 sub r4, r1, r3 add r1, r2, r3 and r6, r1, r7 or r8, r1, r9 xor r10, r1, r11 Data Hazard on R1 Figure A.6, Page A-17 I n s t r. O r d e r Time (clock cycles) IMRegDMReg IMRegDMReg IMRegDM IMReg IMReg CC 1CC 5CC 2CC 3CC 4CC 6

ENGS 116 Lecture 516 Forwarding to Avoid Data Hazard Figure A.7, Page A-18 I n s t r. O r d e r IMRegDMReg IMRegDMReg IMRegDM IMReg IMReg Time (clock cycles) CC 1CC 5CC 2CC 3CC 4CC 6 sub r4, r1, r3 add r1, r2, r3 and r6, r1, r7 or r8, r1, r9 xor r10, r1, r11

ENGS 116 Lecture 517 Data Hazard Even with Forwarding Figure A.9, Page A-20 I n s t r. O r d e r IMRegDM IMRegDMReg IMReg IMReg Time (clock cycles) CC 1CC 5CC 2CC 3CC 4 sub r4, r1, r5 lw r1, 0(r2) and r6, r1, r7 or r8, r1, r9

ENGS 116 Lecture 518 Data Hazard Even with Forwarding Figure A.10, Page A-21 I n s t r. O r d e r IMReg IMRegDMReg IM DM Reg IMReg Time (clock cycles) CC 1CC 5CC 2CC 3CC 4CC 6 sub r4, r1, r5 lw r1, 0(r2) and r6, r1, r7 or r8, r1, r9 bubble

ENGS 116 Lecture 519

ENGS 116 Lecture and R12, R2, R5 40 beqz R1, or R13, R6, R2 52 add R14, R2, R2 80 ld R4, R7, 100 Control Hazard on Branches Three Stage Stall Program Execution Order (in instructions) Time (clock cycles) CC 1CC 5CC 2CC 3CC 4CC 6 DMIMDMIM Reg DMIM DM CC 7CC 8CC 9 IM DM Reg

ENGS 116 Lecture 521

ENGS 116 Lecture 522 Branch Stall Impact If CPI = 1, 30% branches, 3-cycle stall  new CPI = 1.9! Two simple solutions: Predict not taken –Continue with decoding code that is already in Instruction Cache –Usually < 50% correct, however, no stalls when correct Branch delay slot –The first instruction following the branch is ALWAYS executed –Compiler can figure out what to put there

ENGS 116 Lecture 523 Delayed Branch

ENGS 116 Lecture 524 Delayed Branch Where to get instructions to fill branch delay slot? – Before branch instruction – From the target address: only valuable when branch taken – From fall through: only valuable when branch not taken – Canceling branches allow more slots to be filled Compiler effectiveness for single branch delay slot: – Fills about 60% of branch delay slots – About 80% of instructions executed in branch delay slots useful in computation – About 50% (60% x 80%) of slots usefully filled

ENGS 116 Lecture 525 Evaluating Branch Alternatives