Dynamic Branch Prediction

Slides:



Advertisements
Similar presentations
Lecture 8 Dynamic Branch Prediction, Superscalar and VLIW Advanced Computer Architecture COE 501.
Advertisements

Dynamic Branch Prediction (Sec 4.3) Control dependences become a limiting factor in exploiting ILP So far, we’ve discussed only static branch prediction.
Computer Organization and Architecture (AT70.01) Comp. Sc. and Inf. Mgmt. Asian Institute of Technology Instructor: Dr. Sumanta Guha Slide Sources: Based.
CPE 631: Branch Prediction Electrical and Computer Engineering University of Alabama in Huntsville Aleksandar Milenkovic,
Dynamic Branch Prediction
Copyright 2001 UCB & Morgan Kaufmann ECE668.1 Adapted from Patterson, Katz and Culler © UCB Csaba Andras Moritz UNIVERSITY OF MASSACHUSETTS Dept. of Electrical.
CPE 731 Advanced Computer Architecture ILP: Part II – Branch Prediction Dr. Gheith Abandah Adapted from the slides of Prof. David Patterson, University.
CPE 631: Branch Prediction Electrical and Computer Engineering University of Alabama in Huntsville Aleksandar Milenkovic,
W04S1 COMP s1 Seminar 4: Branch Prediction Slides due to David A. Patterson, 2001.
Lecture 3: Branch Prediction Young Cho Graduate Computer Architecture I.
EECS 470 Branch Prediction Lecture 6 Coverage: Chapter 3.
1 COMP 206: Computer Architecture and Implementation Montek Singh Wed., Oct. 8, 2003 Topic: Instruction-Level Parallelism (Dynamic Branch Prediction)
1 COMP 206: Computer Architecture and Implementation Montek Singh Mon., Oct. 7, 2002 Topic: Instruction-Level Parallelism (Dynamic Branch Prediction)
EECE476: Computer Architecture Lecture 20: Branch Prediction Chapter extra The University of British ColumbiaEECE 476© 2005 Guy Lemieux.
EECC551 - Shaaban #1 lec # 5 Fall Reduction of Control Hazards (Branch) Stalls with Dynamic Branch Prediction So far we have dealt with.
EENG449b/Savvides Lec /17/04 February 17, 2004 Prof. Andreas Savvides Spring EENG 449bG/CPSC 439bG.
1 Lecture 5 Branch Prediction (2.3) and Scoreboarding (A.7)
EECC551 - Shaaban #1 lec # 7 Fall Hardware Dynamic Branch Prediction Simplest method: –A branch prediction buffer or Branch History Table.
Goal: Reduce the Penalty of Control Hazards
Branch Target Buffers BPB: Tag + Prediction
EECC551 - Shaaban #1 lec # 5 Winter Reduction of Control Hazards (Branch) Stalls with Dynamic Branch Prediction So far we have dealt with.
Computer Architecture Instruction Level Parallelism Dr. Esam Al-Qaralleh.
Branch Prediction Dimitris Karteris Rafael Pasvantidιs.
1 COMP 740: Computer Architecture and Implementation Montek Singh Thu, Feb 19, 2009 Topic: Instruction-Level Parallelism III (Dynamic Branch Prediction)
So far we have dealt with control hazards in instruction pipelines by:
Dynamic Branch Prediction
EENG449b/Savvides Lec /25/05 March 24, 2005 Prof. Andreas Savvides Spring g449b EENG 449bG/CPSC 439bG.
CIS 429/529 Winter 2007 Branch Prediction.1 Branch Prediction, Multiple Issue.
ENGS 116 Lecture 91 Dynamic Branch Prediction and Speculation Vincent H. Berk October 10, 2005 Reading for today: Chapter 3.2 – 3.6 Reading for Wednesday:
1 Dynamic Branch Prediction. 2 Why do we want to predict branches? MIPS based pipeline – 1 instruction issued per cycle, branch hazard of 1 cycle. –Delayed.
CSCI 6461: Computer Architecture Branch Prediction Instructor: M. Lancaster Corresponding to Hennessey and Patterson Fifth Edition Section 3.3 and Part.
Branch.1 10/14 Branch Prediction Static, Dynamic Branch prediction techniques.
CPE 631 Session 17 Branch Prediction Electrical and Computer Engineering University of Alabama in Huntsville.
Adapted from Computer Organization and Design, Patterson & Hennessy, UCB ECE232: Hardware Organization and Design Part 13: Branch prediction (Chapter 4/6)
Yiorgos Makris Professor Department of Electrical Engineering University of Texas at Dallas EE (CE) 6304 Computer Architecture Lecture #13 (10/28/15) Course.
ILP: Instruction Level Parallelism Slides mainly from Hennessy & Patterson Computer Architecture, a Quantitative Approach 4 th edition.
Dynamic Branch Prediction
CSL718 : Pipelined Processors
Instruction-Level Parallelism Dynamic Branch Prediction
Instruction-Level Parallelism and Its Dynamic Exploitation
CS203 – Advanced Computer Architecture
Concepts and Challenges
Dynamic Branch Prediction
COMP 740: Computer Architecture and Implementation
UNIVERSITY OF MASSACHUSETTS Dept
CS5100 Advanced Computer Architecture Advanced Branch Prediction
CS 704 Advanced Computer Architecture
Instruction-Level Parallelism (ILP)
现代计算机体系结构 主讲教师:张钢 教授 天津大学计算机学院 2017年
CMSC 611: Advanced Computer Architecture
So far we have dealt with control hazards in instruction pipelines by:
Dynamic Hardware Branch Prediction
CPE 631: Branch Prediction
Branch statistics Branches occur every 4-6 instructions (16-25%) in integer programs; somewhat less frequently in scientific ones Unconditional branches.
Chapter 3: ILP and Its Exploitation
Advanced Computer Architecture
/ Computer Architecture and Design
Pipelining and control flow
So far we have dealt with control hazards in instruction pipelines by:
Lecture 10: Branch Prediction and Instruction Delivery
So far we have dealt with control hazards in instruction pipelines by:
So far we have dealt with control hazards in instruction pipelines by:
Adapted from the slides of Prof
Dynamic Hardware Prediction
So far we have dealt with control hazards in instruction pipelines by:
So far we have dealt with control hazards in instruction pipelines by:
So far we have dealt with control hazards in instruction pipelines by:
So far we have dealt with control hazards in instruction pipelines by:
So far we have dealt with control hazards in instruction pipelines by:
CPE 631 Lecture 12: Branch Prediction
Presentation transcript:

Dynamic Branch Prediction Why does prediction work? Underlying algorithm has regularities Data that is being operated on has regularities Instruction sequence has redundancies that are artifacts of way that humans/compilers think about problems Is dynamic branch prediction better than static branch prediction? Seems to be There are a small number of important branches in programs which have dynamic behavior 12/8/2018 Lec4 ILP

Dynamic Branch Prediction Performance = ƒ(accuracy, cost of misprediction) Branch History Table: Lower bits of PC address index table of 1-bit values Says whether or not branch taken last time No address check Problem: in a loop, 1-bit BHT will cause two mispredictions (avg is 9 iteratios before exit): End of loop case, when it exits instead of looping as before First time through loop on next time through code, when it predicts exit instead of looping 12/8/2018 Lec4 ILP

Dynamic Branch Prediction Solution: 2-bit scheme where change prediction only if get misprediction twice Red: stop, not taken Green: go, taken Adds hysteresis to decision making process T NT Predict Taken Predict Not Taken 12/8/2018 Lec4 ILP

BHT Accuracy Mispredict because either: 4096 entry table: Wrong guess for that branch Got branch history of wrong branch when index the table 4096 entry table: 12/8/2018 Lec4 ILP Integer Floating Point

Correlating Branch Predictor It may possible to improve the accuracy if we look at the behavior of other branches. if (aa == 2) aa = 0; if (bb == 0) bb = 0; if (aa != bb) The behavior of b3 is correlated with the behavior of b1 and b2.

Correlating Predictors Two-level predictors if (d == 0) d = 1; if (d == 1)

initial value of d b1 value of d before b2 b2 nt 1 t 2

1-bit Predictor (Initialized to NT) b1 predic b1 action new b1 pr b2 predic b2 action new b2 pr 2 nt t T

(1,1) Predictor Every branch has two separate prediction bits. First bit: the prediction if the last branch in the program is not taken. Second bit: the prediction if the last branch in the program is taken. Write the pair of prediction bits together.

Combinations & Meaning Prediction bits Prediction if not taken Prediction if taken NT/NT NT NT/T T T/NT T/T

(1,1) Predictor Example d b1 pred b1 action new b1 pred b2 pred nt/nt t t/nt nt/t nt Let’s write all b1/b2 real actions and initial b1/b2 pred as nt/nt Initial prediction bits are nt/nt Initial last branch is nt Used prediction bit is colored with red

Correlated Branch Prediction Idea: record m most recently executed branches as taken or not taken, and use that pattern to select the proper n-bit branch history table In general, (m,n) predictor means record last m branches to select between 2m history tables, each with n-bit counters Thus, old 2-bit BHT is a (0,2) predictor Global Branch History: m-bit shift register keeping T/NT status of last m branches. Each entry in table has m n-bit predictors. 12/8/2018 Lec4 ILP 12

Correlating Branches (2,2) predictor Branch address – Behavior of recent branches selects between four predictions of next branch, updating just that prediction Branch address 4 2-bits per branch predictor Prediction 2-bit global branch history 12/8/2018 Lec4 ILP

Accuracy of Different Schemes 20% 4096 Entries 2-bit BHT Unlimited Entries 2-bit BHT 1024 Entries (2,2) BHT 18% 16% 14% 12% 11% Frequency of Mispredictions 10% 8% 6% 6% 6% 6% 5% 5% 4% 4% 2% 1% 1% 0% 0% nasa7 matrix300 tomcatv doducd spice fpppp gcc expresso eqntott li 4,096 entries: 2-bits per entry Unlimited entries: 2-bits/entry 1,024 entries (2,2) 12/8/2018 Lec4 ILP

Tournament Predictors Multilevel branch predictor Use n-bit saturating counter to choose between predictors Usual choice between global and local predictors 12/8/2018 Lec4 ILP

Tournament Predictors Tournament predictor using, say, 4K 2-bit counters indexed by local branch address. Chooses between: Global predictor 4K entries index by history of last 12 branches (212 = 4K) Each entry is a standard 2-bit predictor Local predictor Local history table: 1024 10-bit entries recording last 10 branches, index by branch address The pattern of the last 10 occurrences of that particular branch used to index table of 1K entries with 3-bit saturating counters 12/8/2018 Lec4 ILP

Comparing Predictors Advantage of tournament predictor is ability to select the right predictor for a particular branch Particularly crucial for integer benchmarks A typical tournament predictor will select the global predictor almost 40% of the time for the SPEC integer benchmarks and less than 15% of the time for the SPEC FP benchmarks 2-bit BHT SPEC89 12/8/2018 Lec4 ILP

Pentium 4 Misprediction Rate (per 1000 instructions, not per branch) 6% misprediction rate per branch SPECint (19% of INT instructions are branch) 2% misprediction rate per branch SPECfp (5% of FP instructions are branch) SPECint2000 SPECfp2000 12/8/2018 Lec4 ILP

Branch Target Buffers (BTB) Branch target calculation is costly and stalls the instruction fetch. BTB stores PCs the same way as caches The PC of a branch is sent to the BTB When a match is found the corresponding Predicted PC is returned If the branch was predicted taken, instruction fetch continues at the returned predicted PC

Branch Target Buffers Branch PC Predicted PC PC of instruction FETCH Yes: inst is branch, Next PC = predicted PC =? Extra Prediction state bits No: proceed normally (Next PC = PC+4)

Dynamic Branch Prediction Summary Prediction becoming important part of execution Branch History Table: 2 bits for loop accuracy Correlation: Recently executed branches correlated with next branch Either different branches (GA) Or different executions of same branches (PA) Tournament predictors take insight to next level, by using multiple predictors usually one based on global information and one based on local information, and combining them with a selector In 2006, tournament predictors using  30K bits are in processors like the Power5 and Pentium 4 Branch Target Buffer: include branch address & prediction 12/8/2018 Lec4 ILP