Copyright 2001 UCB & Morgan Kaufmann ECE668.1 Adapted from Patterson, Katz and Culler © UCB Csaba Andras Moritz UNIVERSITY OF MASSACHUSETTS Dept. of Electrical.

Slides:



Advertisements
Similar presentations
Dynamic History-Length Fitting: A third level of adaptivity for branch prediction Toni Juan Sanji Sanjeevan Juan J. Navarro Department of Computer Architecture.
Advertisements

Lecture 8 Dynamic Branch Prediction, Superscalar and VLIW Advanced Computer Architecture COE 501.
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
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.
EECC551 - Shaaban #1 lec # 5 Spring Reduction of Control Hazards (Branch) Stalls with Dynamic Branch Prediction So far we have dealt with.
EECS 470 Branch Prediction Lecture 6 Coverage: Chapter 3.
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.
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.
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.
Pipelined Datapath and Control (Lecture #15) ECE 445 – Computer Organization The slides included herein were taken from the materials accompanying Computer.
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:
CPSC614 Lec 5.1 Instruction Level Parallelism and Dynamic Execution #4: Based on lectures by Prof. David A. Patterson E. J. Kim.
Branch Prediction High-Performance Computer Architecture Joe Crop Oregon State University School of Electrical Engineering and Computer Science.
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.
Lecture 4.5 Pipelines – Control Hazards Topics Control Hazards Branch Prediction Misprediction stalls Readings: Appendix C September 2, 2015 CSCE 513 Computer.
Branch Prediction Prof. Mikko H. Lipasti University of Wisconsin-Madison Lecture notes based on notes by John P. Shen Updated by Mikko Lipasti.
CPE 631 Session 17 Branch Prediction Electrical and Computer Engineering University of Alabama in Huntsville.
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.
Adapted from Computer Organization and Design, Patterson & Hennessy, UCB ECE232: Hardware Organization and Design Part 13: Branch prediction (Chapter 4/6)
Copyright 2016 Csaba Andras MoritzECE668 Power Aware Branching.1 Few slides adapted from Patterson, et al © UCB and Morgan Kaufmann Csaba Andras Moritz.
Yiorgos Makris Professor Department of Electrical Engineering University of Texas at Dallas EE (CE) 6304 Computer Architecture Lecture #13 (10/28/15) Course.
Dynamic Branch Prediction
CSL718 : Pipelined Processors
Computer Organization CS224
CS203 – Advanced Computer Architecture
Computer Structure Advanced Branch Prediction
Dynamic Branch Prediction
Computer Architecture Advanced Branch Prediction
UNIVERSITY OF MASSACHUSETTS Dept
COSC3330 Computer Architecture Lecture 15. Branch Prediction
CS 704 Advanced Computer Architecture
Chapter 4 The Processor Part 4
April 2, 2002 Prof. David E. Culler Computer Science 252 Spring 2002
CMSC 611: Advanced Computer Architecture
The processor: Pipelining and Branching
So far we have dealt with control hazards in instruction pipelines by:
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.
Dynamic Branch Prediction
/ 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:

Copyright 2001 UCB & Morgan Kaufmann ECE668.1 Adapted from Patterson, Katz and Culler © UCB Csaba Andras Moritz UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering Computer Architecture ECE 668 Dynamic Branch Prediction

Copyright 2001 UCB & Morgan Kaufmann ECE668.2 Adapted from Patterson, Katz and Culler © UCB Static Branch Prediction  Simplest: Predict taken  average misprediction rate = untaken branch frequency, which for the SPEC programs is 34%  Unfortunately, the correct prediction rate ranges from not very accurate (41%) to highly accurate (91%)  Predict on the basis of branch direction?  choosing backward-going branches to be taken (loop)  forward-going branches to be not taken (if)  SPEC programs, however, most forward-going branches are taken => predict taken is better  Predict branches on the basis of profile information collected from earlier runs  Misprediction varies from 5% to 22%

Copyright 2001 UCB & Morgan Kaufmann ECE668.3 Adapted from Patterson, Katz and Culler © UCB Eight Branch Prediction Schemes  1-bit Branch-Prediction  2-bit Branch-Prediction  Correlating Branch Prediction  Gshare  Tournament Branch Predictor  Branch Target Buffer  Conditionally Executed Instructions  Return Address Predictors - Branch Prediction even more important when N instructions per cycle are issued - Amdahl’s Law => relative impact of the control stalls will be larger with the lower potential CPI in an n-issue processor

Copyright 2001 UCB & Morgan Kaufmann ECE668.4 Adapted from Patterson, Katz and Culler © UCB Dynamic Branch Prediction  Performance = ƒ(accuracy, cost of misprediction)  Branch History Table (BHT): Lower bits of PC address index table of 1-bit values  Says whether or not branch taken last time ( T -Taken, N )  No full address check (saves HW, but may be wrong)  Problem: in a loop, 1-bit BHT will cause 2 mispredictions (avg is 9 iterations 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  Only 77.8% accuracy if 9 iterations per loop on average... TTT T N T TT...

Copyright 2001 UCB & Morgan Kaufmann ECE668.5 Adapted from Patterson, Katz and Culler © UCB  Better Solution: 2-bit scheme:  Red: stop, not taken  Green: go, taken 2-bit Branch Prediction - Scheme 1 T T N Predict Taken Predict Not Taken Predict Taken Predict Not Taken T N T N N T* T*N N* N*T (Jim Smith, 1981)

Copyright 2001 UCB & Morgan Kaufmann ECE668.6 Adapted from Patterson, Katz and Culler © UCB Branch History Table (BHT)  BHT is a table of “Predictors”  2-bit, saturating counters indexed by PC address of Branch  In Fetch phase of branch:  Predictor from BHT used to make prediction  When branch completes:  Update corresponding Predictor Predictor 0 Predictor 127 Predictor 1 Branch PC T T N T N T N N T* T*N N* N*T

Copyright 2001 UCB & Morgan Kaufmann ECE668.7 Adapted from Patterson, Katz and Culler © UCB  Another Solution: 2-bit scheme where change prediction (in either direction) only if get misprediction twice:  Red: stop, not taken  Green: go, taken 2-bit Branch Prediction - Scheme 2 T T N Predict Taken Predict Not Taken Predict Taken Predict Not Taken T N T N N T* T*N N* N*T Lee & A. Smith, IEEE Computer, Jan 1984

Copyright 2001 UCB & Morgan Kaufmann ECE668.8 Adapted from Patterson, Katz and Culler © UCB Comparison Actual : N N T N N T N N State: N* N* N* N*T N* N* N*T N* Predicted: N N N N N N N N Actual : T N T T T N T State: T* T* T*N T* T* T* T*N T* Predicted: T T T T T T T Actual : N N T T N N T T State: N* N* N* N*T T* T*N N* N*T Predicted: N N N N ? ? ? ?  For both schemes Actual : N N T T N N T T State: N* N* N* N*T T*N N*T N* N*T Predicted: N N N N T N N N Scheme 1 Scheme 2 T T N T N T N N T* T*N N* N*T T T N T N T N N T* T*N N* N*T 21

Copyright 2001 UCB & Morgan Kaufmann ECE668.9 Adapted from Patterson, Katz and Culler © UCB Further Comparison  Alternating taken / not-taken  Your worst-case prediction scenario  Both schemes achieve 80-95% accuracy with only a small difference in behavior T T N T N T N N T* T*N N* N*T T T N T N T N N T* T*N N* N*T 12

Copyright 2001 UCB & Morgan Kaufmann ECE Adapted from Patterson, Katz and Culler © UCB Correlating Branches Idea: taken/not taken of recently executed branches is related to behavior of present branch (as well as the history of that branch behavior)  Then behavior of recent branches selects between, say, 4 predictions of next branch, updating just that prediction  (2,2) predictor: 2-bit global, 2-bit local Branch address (4 bits) 2-bits per branch local predictors Prediction 2-bit recent global branch history (01 = not taken (0) then taken (1) branches before reaching this)

Copyright 2001 UCB & Morgan Kaufmann ECE Adapted from Patterson, Katz and Culler © UCB Accuracy of Different Schemes

Copyright 2001 UCB & Morgan Kaufmann ECE Adapted from Patterson, Katz and Culler © UCB Re-evaluating Correlation  Several SPEC benchmarks have less than a dozen branches responsible for 90% of taken branches: program branch % static# = 90% compress14%23613 eqntott25%4945 gcc15% mpeg10% real gcc13%  Real programs + OS more like gcc  Small benefits of correlation beyond benchmarks?  Mispredict because either:  Wrong guess for that branch  Got branch history of wrong branch when indexing the table  For SPEC92, 4096 about as good as infinite table  Misprediction mostly due to wrong prediction  Can we improve using global history?

Copyright 2001 UCB & Morgan Kaufmann ECE Adapted from Patterson, Katz and Culler © UCB Gselect and Gshare predictors  Keep a global register (GR) with outcome of k branches  Use that in conjunction with PC to index into a table containing 2-bit predictor  Gselect – concatenate  Gshare – XOR (better) Copyright 2007 CAM

Copyright 2001 UCB & Morgan Kaufmann ECE Adapted from Patterson, Katz and Culler © UCB Tournament Predictors  Motivation for correlating branch predictors: 2-bit local predictor failed on important branches; by adding global information, performance improved  Tournament predictors: use two predictors, 1 based on global information and 1 based on local information, and combine with a selector  Hopes to select right predictor for right branch (or right context of branch)

Copyright 2001 UCB & Morgan Kaufmann ECE Adapted from Patterson, Katz and Culler © UCB Tournament Predictor in Alpha  4K 2-bit counters to choose from among a global predictor and a local predictor  Global predictor also has 4K entries and is indexed by the history of the last 12 branches; each entry in the global predictor is a standard 2-bit predictor  12-bit pattern: ith bit is 0 => ith prior branch not taken; ith bit is 1 => ith prior branch taken ; 00,10,11 00,11 10 Use 1 Use 2 Use 1 00,01,11 00, K  2 bits

Copyright 2001 UCB & Morgan Kaufmann ECE Adapted from Patterson, Katz and Culler © UCB Tournament Predictor in Alpha  Local predictor consists of a 2-level predictor:  Top level a local history table consisting of bit entries; each 10-bit entry corresponds to the most recent 10 branch outcomes for the entry. 10-bit history allows patterns 10 branches to be discovered and predicted  Next level Selected entry from the local history table is used to index a table of 1K entries consisting a 3-bit saturating counters, which provide the local prediction  Total size: 4K*2 + 4K*2 + 1K*10 + 1K*3 = 29K bits! (~180K transistors) 1K  10 bits 1K  3 bits

Copyright 2001 UCB & Morgan Kaufmann ECE Adapted from Patterson, Katz and Culler © UCB % of predictions from local predictor in Tournament Prediction Scheme 98% 100% 94% 90% 55% 76% 72% 63% 37% 69% 0%20%40%60%80%100% nasa7 matrix300 tomcatv doduc spice fpppp gcc espresso eqntott li

Copyright 2001 UCB & Morgan Kaufmann ECE Adapted from Patterson, Katz and Culler © UCB 94% 96% 98% 97% 100% 70% 82% 77% 82% 84% 99% 88% 86% 88% 86% 95% 99% 0%20%40%60%80%100% gcc espresso li fpppp doduc tomcatv Profile-based 2-bit counter Tournament Accuracy of Branch Prediction  Profile: branch profile from last execution (static in that is encoded in instruction, but profile) fig 3.40

Copyright 2001 UCB & Morgan Kaufmann ECE Adapted from Patterson, Katz and Culler © UCB Accuracy v. Size (SPEC89) 0% 1% 2% 3% 4% 5% 6% 7% 8% 9% 10% Total predictor size (Kbits) Conditional branch misprediction rate Local - 2 bit counters Correlating - (2,2) scheme Tournament

Copyright 2001 UCB & Morgan Kaufmann ECE Adapted from Patterson, Katz and Culler © UCB Need Address at Same Time as Prediction  Branch Target Buffer (BTB): Address of branch used as index to get prediction AND branch address (if taken)  Note: must check for branch match now, since can’t use wrong branch address Branch PCPredicted PC =? PC of instruction FETCH Prediction state bits Yes: instruction is branch; use predicted PC as next PC (if predict Taken) No: branch not predicted; proceed normally (PC+4)

Copyright 2001 UCB & Morgan Kaufmann ECE Adapted from Patterson, Katz and Culler © UCB Branch Target “Cache”  Branch Target cache - Only predicted taken branches  “Cache” - Content Addressable Memory (CAM) or Associative Memory (see figure)  Use a big Branch History Table & a small Branch Target Cache Branch PCPredicted PC =? Prediction state bits (optional) Yes: predicted taken branch found No: not found PC

Copyright 2001 UCB & Morgan Kaufmann ECE Adapted from Patterson, Katz and Culler © UCB Steps with Branch target Buffer Branch_CPI_Penalty = [Buffer_hit_rate x P{Incorrect_prediction}] x Penalty_Cycles + [(1-Buffer_hit_rate) x P{Branch_taken}] x Penalty_Cycles =.91x.1x2 +.09x.6x2 =.29 Taken Branch? Entry found in branch- target buffer? Send out predicted PC Is instruction a taken branch? Send PC to memory and branch-target buffer Enter branch instruction address and next PC into branch-target buffer Mispredicted branch, kill fetched instruction; restart fetch at other target; delete entry from target buffer Normal instruction execution Branch correctly predicted; continue execution with no stalls No Yes No ID IF EX for the 5-stage MIPS

Copyright 2001 UCB & Morgan Kaufmann ECE Adapted from Patterson, Katz and Culler © UCB  Avoid branch prediction by turning branches into conditionally executed instructions: if (x) then A = B op C else NOP  If false, then neither store result nor cause interference  Expanded ISA of Alpha, MIPS, PowerPC, SPARC have conditional move; PA-RISC can annul any following instruction  Drawbacks to conditional instructions  Still takes a clock even if “annulled”  Stall if condition evaluated late: Complex conditions reduce effectiveness since condition becomes known late in pipeline x A = B op C Predicated Execution

Copyright 2001 UCB & Morgan Kaufmann ECE Adapted from Patterson, Katz and Culler © UCB Special Case: Return Addresses  Register Indirect branch - hard to predict address  SPEC89 85% such branches for procedure return  Since stack discipline for procedures, save return address in small buffer that acts like a stack: 8 to 16 entries has small miss rate

Copyright 2001 UCB & Morgan Kaufmann ECE Adapted from Patterson, Katz and Culler © UCB How to Reduce Power  Reduce load capacitances switched  Smaller BTAC  Smaller local, global predictors  Less associativity  How do you know which branches? »Use static information »Combine runtime and compile time information »Add hints to be used at runtime  Also, predict statically  Branch folding »Runtime »Compile-time Copyright 2007 CAM & BlueRISC

Copyright 2001 UCB & Morgan Kaufmann ECE Adapted from Patterson, Katz and Culler © UCB Power Consumption BlueRISC’s Compiler-driven Power-Aware Branch Prediction Comparison with 512 entry BTAC bimodal (patent-issued) Copyright 2007 CAM & BlueRISC

Copyright 2001 UCB & Morgan Kaufmann ECE Adapted from Patterson, Katz and Culler © UCB Pitfall: Sometimes dumber is better  Alpha uses tournament predictor (29 Kbits)  Earlier uses a simple 2-bit predictor with 2K entries (or a total of 4 Kbits)  SPEC95 benchmarks, outperforms  avg mispredictions per 1000 instructions  avg mispredictions per 1000 instructions  Reversed for transaction processing (TP) !  avg. 17 mispredictions per 1000 instructions  avg. 15 mispredictions per 1000 instructions  TP code much larger & hold 2X branch predictions based on local behavior (2K vs. 1K local predictor in the 21264)  What about power?  Large predictors give some increase in prediction rate but for a large power cost

Copyright 2001 UCB & Morgan Kaufmann ECE Adapted from Patterson, Katz and Culler © UCB