Branch Prediction CS 3220 Fall 2014 Hadi Esmaeilzadeh Georgia Institute of Technology Some slides adopted from Prof. Milos Prvulovic.

Slides:



Advertisements
Similar presentations
Basic Pipelining CS 3220 Fall 2014 Hadi Esmaeilzadeh Georgia Institute of Technology Some slides adopted from Prof. Milos Prvulovic.
Advertisements

Morgan Kaufmann Publishers The Processor
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.
CMSC 611: Advanced Computer Architecture Pipelining Some material adapted from Mohamed Younis, UMBC CMSC 611 Spr 2003 course slides Some material adapted.
Pipelining and Control Hazards Oct
Lecture Objectives: 1)Define branch prediction. 2)Draw a state machine for a 2 bit branch prediction scheme 3)Explain the impact on the compiler of branch.
Single-Cycle Processor Design CS 3220 Fall 2014 Hadi Esmaeilzadeh Georgia Institute of Technology Some slides adopted from Prof. Milos.
Pipelined Processor II (cont’d) CPSC 321
The Light at the End of the Tunnel – Doesn’t Mean You Died ! Part 3 - Branch Hazards – Easier! – 3/24/04 This is a control hazard – as opposed to data.
Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University Pipeline Hazards See: P&H Chapter 4.7.
Pipelining II Andreas Klappenecker CPSC321 Computer Architecture.
Mary Jane Irwin ( ) [Adapted from Computer Organization and Design,
ENEE350 Ankur Srivastava University of Maryland, College Park Based on Slides from Mary Jane Irwin ( )
Chapter 12 Pipelining Strategies Performance Hazards.
Pipelining III Andreas Klappenecker CPSC321 Computer Architecture.
1  2004 Morgan Kaufmann Publishers Chapter Six. 2  2004 Morgan Kaufmann Publishers Pipelining The laundry analogy.
Pipelining Andreas Klappenecker CPSC321 Computer Architecture.
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.
L18 – Pipeline Issues 1 Comp 411 – Spring /03/08 CPU Pipelining Issues Finishing up Chapter 6 This pipe stuff makes my head hurt! What have you.
Goal: Reduce the Penalty of Control Hazards
L17 – Pipeline Issues 1 Comp 411 – Fall /1308 CPU Pipelining Issues Finishing up Chapter 6 This pipe stuff makes my head hurt! What have you been.
1 Lecture 18: Pipelining Today’s topics:  Hazards and instruction scheduling  Branch prediction  Out-of-order execution Reminder:  Assignment 7 will.
Pipelined Processor II CPSC 321 Andreas Klappenecker.
Computer Organization Lecture Set – 06 Chapter 6 Huei-Yung Lin.
Pipelined Datapath and Control (Lecture #15) ECE 445 – Computer Organization The slides included herein were taken from the materials accompanying Computer.
Pipelining What is it? How does it work? What are the benefits? What could go wrong? By Derek Closson.
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.
A Tour of A Five-Stage Processor CS 3220 Fall 2014 Hadi Esmaeilzadeh Georgia Institute of Technology Some slides adopted from Prof.
1 Pipelining Reconsider the data path we just did Each instruction takes from 3 to 5 clock cycles However, there are parts of hardware that are idle many.
Pipeline Hazards. CS5513 Fall Pipeline Hazards Situations that prevent the next instructions in the instruction stream from executing during its.
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.
CS 1104 Help Session IV Five Issues in Pipelining Colin Tan, S
CECS 440 Pipelining.1(c) 2014 – R. W. Allison [slides adapted from D. Patterson slides with additional credits to M.J. Irwin]
Winter 2002CSE Topic Branch Hazards in the Pipelined Processor.
Chap 6.1 Computer Architecture Chapter 6 Enhancing Performance with Pipelining.
CSIE30300 Computer Architecture Unit 04: Basic MIPS Pipelining Hsin-Chou Chi [Adapted from material by and
5/13/99 Ashish Sabharwal1 Pipelining and Hazards n Hazards occur because –Don’t have enough resources (ALU’s, memory,…) Structural Hazard –Need a value.
1  1998 Morgan Kaufmann Publishers Chapter Six. 2  1998 Morgan Kaufmann Publishers Pipelining Improve perfomance by increasing instruction throughput.
Branch Hazards and Static Branch Prediction Techniques
CS 6290 Branch Prediction. Control Dependencies Branches are very frequent –Approx. 20% of all instructions Can not wait until we know where it goes –Long.
CBP 2005Comp 3070 Computer Architecture1 Last Time … All instructions the same length We learned to program MIPS And a bit about Intel’s x86 Instructions.
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.
Circuit Optimization CS 3220 Fall 2014 Hadi Esmaeilzadeh Georgia Institute of Technology Some slides adopted from Prof. Milos Prvulovic.
Adapted from Computer Organization and Design, Patterson & Hennessy, UCB ECE232: Hardware Organization and Design Part 13: Branch prediction (Chapter 4/6)
L17 – Pipeline Issues 1 Comp 411 – Fall /23/09 CPU Pipelining Issues Read Chapter This pipe stuff makes my head hurt! What have you been.
Pipelining: Implementation CPSC 252 Computer Organization Ellen Walker, Hiram College.
Chapter Six.
Stalling delays the entire pipeline
CS/COE 1541 (term 2174) Jarrett Billingsley
ECS 154B Computer Architecture II Spring 2009
Chapter 4 The Processor Part 3
Pipelining review.
Pipelining Chapter 6.
Lecture 19: Branches, OOO Today’s topics: Instruction scheduling
Lecture 18: Pipelining Today’s topics:
Lecture 5: Pipelining Basics
Lecture 18: Pipelining Today’s topics:
Pipelining in more detail
Lecture 19: Branches, OOO Today’s topics: Instruction scheduling
Chapter Six.
The Processor Lecture 3.6: Control Hazards
Chapter Six.
Control unit extension for data hazards
Lecture 18: Pipelining Today’s topics:
Control unit extension for data hazards
Wackiness Algorithm A: Algorithm B:
Control unit extension for data hazards
Presentation transcript:

Branch Prediction CS 3220 Fall 2014 Hadi Esmaeilzadeh Georgia Institute of Technology Some slides adopted from Prof. Milos Prvulovic

Control Hazards Revisited  Forwarding helps a lot with data hazards – Can have a deep pipeline (high clock rate) – Need to stall rarely (few wasted cycles)  But we must still flush due to control hazards! – Each flush wastes several cycles worth of work – We fetch from PC+4, so we must flush all insts that were fetched after a branch that is taken! – Problem: there are lots of taken branches Think loops! 6 Mar 2014Branch Prediction2

 Idea: try to fetch the correct instructions – Guess what should be fetched – If we guessed correctly, no flush – If we guessed wrong, must flush – The trick is to be correct most of the time  Lucky us - things are easy to guess – JAL – almost always goes to the same address – Branch – if taken, always goes to the same address And taken/not-taken behavior highly repeatable! 6 Mar 2014Branch Prediction3

We already have branch prediction  But we predict that the next PC should be PC+4! clk) begin if(reset) PC<=STARTPC; else if(mispred_A)PC<=pcgood_A; else if(!stall_F) PC<=pcpred_F; end wire [(DBITS-1):0] pcplus_F=PC+32'd4; wire [(DBITS-1):0] pcpred_F=pcplus_F; … assign pcgood_A=dobranch_A?brtarg_A: isjump_A?jmptarg_A: pcplus_A; assign mispred_A=(pcgood_A!=pcpred_A)&&!isnop_A; 6 Mar 2014Branch Prediction4 Smarter prediction code goes here

How to Predict?  We need to fetch the correct next instruction! – (Almost) every cycle – Without looking at the previous instruction  So we need to guess the PC of the next instruction while we are fetching the current one – We only know the PC of the current instruction, but nothing else about it! – But… we can remember what it did when we executed it before…  Use a table to remember what happened! – At some point, we know the correct next-PC (let’s call it pcgood) – When inst done, update predictor: bpred[PC_X]<=pcgood_X; Where stage X is where we want to update the predictor, e.g. the last stage  Look up the prediction instead of using pcplus assign pcpred_F=pcplus_F; assign pcpred_F=bpred[PC]; 6 Mar 2014Branch Prediction5

Much faster!  Branch Prediction Benefit #1 – Fewer flushes => fewer cycles to execute Sorter2.mif  Branch Prediction Benefit #2 – Takes time to figure out pcgood, ~ late in ALU stage Then need time for PC selection and to feed that iMem address input Often this is the critical path: get forwading-corrected reg values from D->A pipeline latches, compare for EQ/NE, use this to select between btarg and pcplus, see if this pcgood is equal to pcplus, get this mispred signal to where the PC is selected, do selection, get that PC value to where the memory is, latch it as address for next fetch – Moving some of this to next stage (MEM) would fix this E.g. can determine pcgood, then do the rest early in the M stage Didn’t work well before: wastes another cycle on each taken branch Now: wastes another cycle rarely: only if prediction wrong 6 Mar 2014Branch Prediction6