ENEE350 Ankur Srivastava University of Maryland, College Park Based on Slides from Mary Jane Irwin ( www.cse.psu.edu/~mji )www.cse.psu.edu/~mji www.cse.psu.edu/~cg431.

Slides:



Advertisements
Similar presentations
Morgan Kaufmann Publishers The Processor
Advertisements

CMSC 611: Advanced Computer Architecture Pipelining Some material adapted from Mohamed Younis, UMBC CMSC 611 Spr 2003 course slides Some material adapted.
Pipeline Control Hazards: Detection and Circumvention Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005, and from slides kindly.
Review: MIPS Pipeline Data and Control Paths
ENEE350 Ankur Srivastava University of Maryland, College Park Based on Slides from Mary Jane Irwin ( )
Mary Jane Irwin ( ) [Adapted from Computer Organization and Design,
ENEE350 Ankur Srivastava University of Maryland, College Park Based on Slides from Mary Jane Irwin ( )
John Lazzaro (
CS 152 L12 RAW Hazards, Interrrupts (1)Fall 2004 © UC Regents CS152 – Computer Architecture and Engineering Lecture 12 – Pipeline Wrap up: Control Hazards,
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.
ENEE350 Ankur Srivastava University of Maryland, College Park Based on Slides from Mary Jane Irwin ( )
Chapter 6 Pipelining to Increase Effective Computer Speed.
Pipelined Datapath and Control (Lecture #15) ECE 445 – Computer Organization The slides included herein were taken from the materials accompanying Computer.
Control Hazards.1 Review: Datapath with Data Hazard Control Read Address Instruction Memory Add PC 4 Write Data Read Addr 1 Read Addr 2 Write Addr Register.
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.
Lecture 15: Pipelining and Hazards CS 2011 Fall 2014, Dr. Rozier.
Chapter 4B: The Processor, Part B. Review: 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.
Pipeline Data Hazards: Detection and Circumvention Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005, and from slides kindly.
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.
11/13/2015 8:57 AM 1 of 86 Pipelining Chapter 6. 11/13/2015 8:57 AM 2 of 86 Overview of Pipelining Pipelining is an implementation technique in which.
CSE 340 Computer Architecture Summer 2014 Basic MIPS Pipelining Review.
Basic Pipelining & MIPS Pipelining Chapter 6 [Computer Organization and Design, © 2007 Patterson (UCB) & Hennessy (Stanford), & Slides Adapted from: Mary.
CS.305 Computer Architecture Enhancing Performance with Pipelining Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005, and from.
Computer Organization CS224 Chapter 4 Part b The Processor Spring 2010 With thanks to M.J. Irwin, T. Fountain, D. Patterson, and J. Hennessy for some lecture.
Computer Architecture and Design – ELEN 350 Part 8 [Some slides adapted from M. Irwin, D. Paterson. D. Garcia and others]
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]
CSIE30300 Computer Architecture Unit 04: Basic MIPS Pipelining Hsin-Chou Chi [Adapted from material by and
1 (Based on text: David A. Patterson & John L. Hennessy, Computer Organization and Design: The Hardware/Software Interface, 3 rd Ed., Morgan Kaufmann,
CSE431 L07 Overcoming Data Hazards.1Irwin, PSU, 2005 CSE 431 Computer Architecture Fall 2005 Lecture 07: Overcoming Data Hazards Mary Jane Irwin (
CSIE30300 Computer Architecture Unit 05: Overcoming Data Hazards Hsin-Chou Chi [Adapted from material by and
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.
Adapted from Computer Organization and Design, Patterson & Hennessy, UCB ECE232: Hardware Organization and Design Part 13: Branch prediction (Chapter 4/6)
CMPE 421 Parallel Computer Architecture Part 3: Hardware Solution: Control Hazard and Prediction.
CSIE30300 Computer Architecture Unit 06: Containing Control Hazards
Designing a Pipelined Processor
EI209 Chapter 4D.1Haojin Zhu, CSE, 2015 EI 209 Computer Organization Fall 2015 Chapter 4D: Pipeline Hazard [Adapted from Computer Organization and Design,
CPE432 Chapter 4B.1Dr. W. Abu-Sufah, UJ Chapter 4B: The Processor, Part B-1 Read Sections 4.7 Adapted from Slides by Prof. Mary Jane Irwin, Penn State.
ECE/CS 552: Pipeline Hazards © Prof. Mikko Lipasti Lecture notes based in part on slides created by Mark Hill, David Wood, Guri Sohi, John Shen and Jim.
Pipelining: Implementation CPSC 252 Computer Organization Ellen Walker, Hiram College.
CSE 340 Computer Architecture Spring 2016 Overcoming Data Hazards.
Computer Organization
Computer Organization CS224
Stalling delays the entire pipeline
Mary Jane Irwin ( ) [Adapted from Computer Organization and Design,
Lecture 08: Control Hazards
Appendix C Pipeline implementation
Morgan Kaufmann Publishers The Processor
Chapter 4 The Processor Part 4
ECS 154B Computer Architecture II Spring 2009
ECE232: Hardware Organization and Design
Processor Design: Pipeline Handling Hazards
Chapter 4 The Processor Part 3
Review: MIPS Pipeline Data and Control Paths
Peng Liu Lecture 9 Pipeline Peng Liu
Morgan Kaufmann Publishers The Processor
EI 209 Computer Organization Fall 2017
Pipelining review.
The processor: Pipelining and Branching
Lecture 9. MIPS Processor Design – Pipelined Processor Design #2
Pipelining in more detail
Data Hazards Data Hazard
The Processor Lecture 3.6: Control Hazards
Control unit extension for data hazards
The Processor Lecture 3.5: Data Hazards
CSC3050 – Computer Architecture
Pipelining (II).
Control unit extension for data hazards
Control unit extension for data hazards
ELEC / Computer Architecture and Design Spring 2015 Pipeline Control and Performance (Chapter 6) Vishwani D. Agrawal James J. Danaher.
Presentation transcript:

ENEE350 Ankur Srivastava University of Maryland, College Park Based on Slides from Mary Jane Irwin ( ) [Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005, UCB] Computer Systems Organization: Lecture 8

ENEE350 Review: Datapath with Data Hazard Control Read Address Instruction Memory Add PC 4 Write Data Read Addr 1 Read Addr 2 Write Addr Register File Read Data 1 Read Data ALU Shift left 2 Add Data Memory Address Write Data Read Data IF/ID Sign Extend ID/EX EX/MEM MEM/WB Control ALU cntrl Branch PCSrc Forward Unit Hazard Unit 0 1 ID/EX.RegisterRt 0 ID/EX.MemRead PC.Write IF/ID.Write

ENEE350 Control Hazards  When the flow of instruction addresses is not sequential (i.e., PC = PC + 4); incurred by change of flow instructions Conditional branches ( beq, bne ) Unconditional branches ( j, jal, jr ) l Exceptions  Possible approaches l Stall (impacts CPI) l Move decision point as early in the pipeline as possible, thereby reducing the number of stall cycles l Delay decision (requires compiler support) l Predict and hope for the best !  Control hazards occur less frequently than data hazards, but there is nothing as effective against control hazards as forwarding is for data hazards

ENEE350 Datapath Branch and Jump Hardware ID/EX Read Address Instruction Memory Add PC 4 Write Data Read Addr 1 Read Addr 2 Write Addr Register File Read Data 1 Read Data ALU Data Memory Address Write Data Read Data IF/ID Sign Extend EX/MEM MEM/WB Control ALU cntrl Forward Unit

ENEE350 Datapath Branch and Jump Hardware ID/EX Read Address Instruction Memory Add PC 4 Write Data Read Addr 1 Read Addr 2 Write Addr Register File Read Data 1 Read Data ALU Data Memory Address Write Data Read Data IF/ID Sign Extend EX/MEM MEM/WB Control ALU cntrl Forward Unit Branch PCSrc Shift left 2 Add Shift left 2 Jump PC+4[31-28]

ENEE350 flush Jumps Incur One Stall I n s t r. O r d e r j j target ALU IM Reg DMReg ALU IM Reg DMReg  Fortunately, jumps are very infrequent – only 3% of the SPECint benchmarks  Jumps not decoded until ID, so one flush is needed Fix jump hazard by waiting – stall – but affects CPI ALU IM Reg DMReg

ENEE350 Supporting ID Stage Jumps 0

ENEE350 Two “Types” of Stalls  Noop instruction (or bubble) inserted between two instructions in the pipeline (as done for load-use situations) l Keep the instructions earlier in the pipeline (later in the code) from progressing down the pipeline for a cycle (“bounce” them in place with write control signals) Insert noop by zeroing control bits in the pipeline register at the appropriate stage l Let the instructions later in the pipeline (earlier in the code) progress normally down the pipeline  Flushes (or instruction squashing) were an instruction in the pipeline is replaced with a noop instruction (as done for instructions located sequentially after j instructions) l Zero the control bits for the instruction to be flushed

ENEE350 flush Review: Branches Incur Three Stalls I n s t r. O r d e r beq ALU IM Reg DMReg beq target ALU IM Reg DMReg Fix branch hazard by waiting – stall – but affects CPI

ENEE350 Moving Branch Decisions Earlier in Pipe  Move the branch decision hardware back to the EX stage l Reduces the number of stall (flush) cycles to two Adds an and gate and a 2x1 mux to the EX timing path  Add hardware to compute the branch target address and evaluate the branch decision to the ID stage l Reduces the number of stall (flush) cycles to one (like with jumps) -But now need to add forwarding hardware in ID stage l Computing branch target address can be done in parallel with RegFile read (done for all instructions – only used when needed) Comparing the registers can’t be done until after RegFile read, so comparing and updating the PC adds a mux, a comparator, and an and gate to the ID timing path  For deeper pipelines, branch decision points can be even later in the pipeline, incurring more stalls

ENEE350 Supporting ID Stage Branches (without going into details) Read Address Instruction Memory PC 4 Write Data Read Addr 1 Read Addr 2 Write Addr RegFile Read Data 1 ReadData ALU Shift left 2 Add Data Memory Address Write Data Read Data IF/ID Sign Extend ID/EX EX/MEM MEM/WB Control ALU cntrl Branch PCSrc Forward Unit Hazard Unit Compare Forward Unit Add IF.Flush

ENEE350 Static Branch Prediction  Resolve branch hazards by assuming a given outcome and proceeding without waiting to see the actual branch outcome 1. Predict not taken – always predict branches will not be taken, continue to fetch from the sequential instruction stream, only when branch is taken does the pipeline stall l If taken, flush instructions after the branch (earlier in the pipeline) -in IF, ID, and EX stages if branch logic in MEM – three stalls -In IF and ID stages if branch logic in EX – two stalls -in IF stage if branch logic in ID – one stall l ensure that those flushed instructions haven’t changed the machine state – automatic in the MIPS pipeline since machine state changing operations are at the tail end of the pipeline (MemWrite (in MEM) or RegWrite (in WB)) l restart the pipeline at the branch destination

ENEE350 Flushing with Misprediction (Not Taken) 4 beq $1,$2,2 I n s t r. O r d e r ALU IM Reg DMReg ALU IM Reg DMReg 8 sub $4,$1,$5  To flush the IF stage instruction, assert IF.Flush to zero the instruction field of the IF/ID pipeline register (transforming it into a noop )

ENEE350 flush Flushing with Misprediction (Not Taken) 4 beq $1,$2,2 I n s t r. O r d e r ALU IM Reg DMReg 16 and $6,$1,$7 20 or r8,$1,$9 ALU IM Reg DMReg ALU IM Reg DMReg ALU IM Reg DMReg 8 sub $4,$1,$5  To flush the IF stage instruction, assert IF.Flush to zero the instruction field of the IF/ID pipeline register (transforming it into a noop )

ENEE350 Branching Structures  Predict not taken works well for “top of the loop” branching structures Loop: beq $1,$2,Out 1 nd loop instr. last loop instr j Loop Out: fall out instr l But such loops have jumps at the bottom of the loop to return to the top of the loop – and incur the jump stall overhead  Predict not taken doesn’t work well for “bottom of the loop” branching structures Loop: 1 st loop instr 2 nd loop instr. last loop instr bne $1,$2,Loop fall out instr

ENEE350 Static Branch Prediction, con’t  Resolve branch hazards by assuming a given outcome and proceeding 2. Predict taken – predict branches will always be taken l Predict taken always incurs one stall cycle (if branch destination hardware has been moved to the ID stage)  As the branch penalty increases (for deeper pipelines), a simple static prediction scheme will hurt performance. With more hardware, it is possible to try to predict branch behavior dynamically during program execution 3. Dynamic branch prediction – predict branches at run- time using run-time information

ENEE350 Dynamic Branch Prediction  A branch prediction buffer (aka branch history table (BHT)) in the IF stage addressed by the lower bits of the PC, contains a bit passed to the ID stage through the IF/ID pipeline register that tells whether the branch was taken the last time it was execute l Prediction bit may predict incorrectly (may be a wrong prediction for this branch this iteration or may be from a different branch with the same low order PC bits) but the doesn’t affect correctness, just performance -Branch decision occurs in the ID stage after determining that the fetched instruction is a branch and checking the prediction bit l If the prediction is wrong, flush the incorrect instruction(s) in pipeline, restart the pipeline with the right instruction, and invert the prediction bit -A 4096 bit BHT varies from 1% misprediction (nasa7, tomcatv) to 18% (eqntott)

ENEE350 Branch Target Buffer  The BHT predicts when a branch is taken, but does not tell where its taken to! l A branch target buffer (BTB) in the IF stage can cache the branch target address, but we also need to fetch the next sequential instruction. The prediction bit in IF/ID selects which “next” instruction will be loaded into IF/ID at the next clock edge -Would need a two read port instruction memory  If the prediction is correct, stalls can be avoided no matter which direction they go l Or the BTB can cache the branch taken instruction while the instruction memory is fetching the next sequential instruction Read Address Instruction Memory PC 0 BTB

ENEE350 2-bit Predictors Predict Taken Predict Not Taken Predict Taken Predict Not Taken Taken Not taken Taken Loop: 1 st loop instr 2 nd loop instr. last loop instr bne $1,$2,Loop fall out instr

ENEE350 2-bit Predictors Predict Taken Predict Not Taken Predict Taken Predict Not Taken Taken Not taken Taken Loop: 1 st loop instr 2 nd loop instr. last loop instr bne $1,$2,Loop fall out instr wrong on loop fall out right 9 times right on 1 st iteration 0  BHT also stores the initial FSM state

ENEE350 Dealing with Exceptions  Exceptions (aka interrupts) are just another form of control hazard. Exceptions arise from l R-type arithmetic overflow l Trying to execute an undefined instruction l An I/O device request l An OS service request (e.g., a page fault, TLB exception) l A hardware malfunction  The pipeline has to stop executing the offending instruction in midstream, let all prior instructions complete, flush all following instructions, set a register to show the cause of the exception, save the address of the offending instruction, and then jump to a prearranged address (the address of the exception handler code)  The software (OS) looks at the cause of the exception and “deals” with it

ENEE350 Summary  All modern day processors use pipelining for performance (a CPI of 1 and fast a CC)  Pipeline clock rate limited by slowest pipeline stage – so designing a balanced pipeline is important  Must detect and resolve hazards l Structural hazards – resolved by designing the pipeline correctly l Data hazards -Stall (impacts CPI) -Forward (requires hardware support) l Control hazards – put the branch decision hardware in as early a stage in the pipeline as possible -Stall (impacts CPI) -Delay decision (requires compiler support) -Static and dynamic prediction (requires hardware support)