An Introduction to Branch Prediction

Computer Science University of Hertfordshire 1

AIMS This unit introduces you to: „ „

the ‘Branch Problem’ mechanisms to overcome the ‘Branch Problem’

2

Learning Outcomes At the end of this units you will: Š Have gained an insight into the impact that branch instructions can have on processor performance. Š Be able to explain mechanisms by which the branch problem can be reduced.

3

Material Sources Š Computer Architecture A Quantitative Approach (Second Edition) David Patterson and John L. Hennessy. Š Superscalar Processor Design Mike Johnson (Prentice Hall 1991) „

These are highly recommended to read (copies are in the LRC).

Š Dynamic Branch Prediction in High Performance Superscalar Processors - Colin Egan’s PhD Thesis! 4

Branch Instructions Š Branch instructions change the flow of program control. Š Branches follow one of two paths. „ „

The fall through or not taken path. The branch target stream or taken path.

Š In general purpose code branches occur approximately every 5 – 8 instructions. Š Branch instructions cause control hazards. (We will look at this in more detail in another lecture). 5

Branch Instructions Š Branch instructions reduce processor performance. Š In simple processors instructions from the sequential path are pre-fetched from an Icache to ensure the pipeline is fully utilised. (Review your pipelining notes).

6

Branch Instructions Š A taken branch incurs a misfetch penalty. Š Forecasting the outcome of a branch ahead of time is essential to improve processor performance.

7

“Prediction is difficult, especially about the future.” Neils Bohr, (1885 – 1962).

8

Branch Problem Š Consists of two sub-problems: „

Generating the correct prediction.

„

In the case of a taken branch predicting the correct target.

9

Branch Prediction Š Static Branch Prediction „

The direction of each branch is predicted before a programs runs using either compile time heuristics or profiling.

Š Dynamic Branch Prediction „

The direction of each branch is predicted by recording information, in hardware, of past branch history during a program’s execution and is therefore done at run-time.

10

Importance of Branch Prediction Š Superscalar processors attempt to achieve high performance by prefetching groups of instructions into an instruction buffer and issuing those instructions for execution as soon as the required operands are available.

11

Importance of Branch Prediction Š Even with out-of-order instruction issue and Tomasulo (a later lecture), a high sustained instruction issue rate can only be achieved if the contents of he instruction buffer spans several basic blocks. This can only be achieved by dynamic branch prediction.

12

Static Branch Prediction Š Static branch prediction prediction at compile time.

involves

making

a

Š Predictions are either based on: „

compile time heuristics

or „

profile information that has been obtained from previous runs of the program.

Š Static Branch Prediction, predicts in the ID stage of 13 the pipeline.

Static Branch Prediction - a Heuristic Approach (Predict Not Taken) Š The simplest static branch prediction scheme ignores the presence of a branch and continues to fetch instructions from the sequential instruction stream. Š All branches are therefore predicted as not taken.

14

Static Branch Prediction - a Heuristic Approach (Predict Not Taken) Š Incorrectly fetched instructions are squashed when the branch is resolved. Š Using predict not taken, a correctly predicted branch incurs no penalty.

15

Static Branch Prediction - a Heuristic Approach (Predict Taken) Š A correctly predicted branch will always incur a penalty of at least one clock cycle while the branch target address is being computed.

16

Static Branch Prediction - a Heuristic Approach (Predict Not Taken / Predict Taken) Š Predicting not taken is slightly better than always predicting taken (McFarling). Š Predict taken scheme is more complex to implement than the predict not taken scheme (McFarling). (McFarling, S. and Hennessy, J. Reducing the Cost of Branches. 13th International Symposium of Computer Architecture, ACM, pp. 396 – 403, June 1986). 17

Static Branch Prediction - a Heuristic Approach (BTFNT) Š Backward Taken Forward Not Taken „

„

„

Is based on the premise that backward branches tend to close loops and are therefore probably taken. The strategy is simple to implement since it relies only on the sign bit of the branch displacement. Since the type and direction of a branch must be known before a prediction can be made, the prediction must be delayed until the ID stage of the pipeline.

(Smith, J. E. A Study of branch prediction Strategies. Proceedings of the 8th Annual International Symposium on Computer Architecture, pp. 135 – 148, Minneapolis, June 1981). 18

Static Branch Prediction - a Heuristic Approach (Encoding into op-code) Š Program heuristics based on compile time knowledge can be encoded into the op-code of the branch instruction. Š This ‘branch-likely’ or ‘hint-bit’ is used to provide the branch direction the next time that the branch instruction is encountered. (Ball, T. and Larus, J. Branch Prediction for Free. Proceedings of the SigPlan93 Conference on Programming Language and Implementation, pp. 300 – 313, June 1993).

19

Static Branch Prediction - a Profiling Approach Š By examination of profile information that has been obtained from previous runs of the program. Š Branch behaviour is bimodal. „

an individual branch is biased to one path.

(Fisher, J. A. and Freudenberger, S. M. Predicting Conditional Branch Directions from Previous Runs of a Program. Proceedings of the 5th International Conference on Architectural Support for Programming Languages and Operating Systems, Boston, Mass., pp. 85 – 95, October 1992.)

20

Dynamic Branch Prediction Š Reduces branch penalties under hardware control. Š The prediction is made in the IF stage of the pipeline. Š The simplest dynamic prediction scheme is a branch prediction buffer or branch history table.

21

A Branch Prediction Buffer Š Is a small fast memory. Š Contains history information of the previous outcome of the branch as a prediction field. „ „

0 for not-taken. 1 for taken.

Š Is indexed by the low order bits of the branch address either in IF or ID/IR. Š The branch target can then be accessed as soon as the branch target address is computed, but before the branch condition is available. 22

A Branch Prediction Buffer Disadvantages 1. Even if a branch is predicted correctly there will be a branch penalty of one cycle. 2. May access a prediction bit for another branch that has the same least significant address bits. To rectify this problem a tag could be added to hold the msbs of the branch instruction address. However, this addition would significantly increase the size of the buffer.

23

A Branch Prediction Buffer Disadvantages 3. In many RISC pipelines the branch is resolved in the ID pipeline stage. In this case the branch prediction information would be obtained during the same cycle as the branch is resolved – too late to be of any use. In MIPS the prediction might preceed the branch resolution by one cycle.

24

A Branch Prediction Buffer Disadvantages 4. One bit achieves Limited prediction accuracy. P&H suggest that a buffer with 500 – 100 entries and two bits of prediction information per entry is likely to predict the outcome of branches correctly about 86% of the time.

25

A Branch Target Cache (BTC) Requirements Š Need to be determined while each instruction is being fetched: „ „ „

If the instruction is a branch If the branch will be taken If the branch prediction is taken, what the target address is.

Š If these requirements are met the processor can initiate the next instruction access as soon as the previous access is complete.

26

A BTC Š Is a Branch Prediction Buffer with more information: „

„ „

Has an address tag of a branch instruction – the high order bits. Stores the target address. Usually uses two-bit up-down saturating counters as a prediction field.

Š Can be organised in different ways: „ „ „

Direct mapped Fully associative Set associative

27

A BTC Š

Some references: 1.

2.

Lee, J. and Smith, J. Branch Prediction Strategies and Branch Target Buffer Design. IEEE Computer, pp. 6 – 22, January 1984. Perleberg, C. and Smith, J. Branch Target Buffer Design and Optimisation. IEEE Transactions on Computers, vol. 4, pp. 396 – 411, 1993.

28

A BTC low order bits

0

1

tag target cnt tag target cnt …

prediction 29

A BTC - Operation 1. During the IF stage, the lsb of the PC are also used to access the BTC. 2. If the msbs of the PC match the tag, the entry is valid. 3. If the branch is predicted as taken, the predicted branch target address is used to access the I-cache during the next cycle. 4. When the branch is finally resolved, the prediction is verified and the BTC entry updated. 30

A BTC – Prediction Mechanism Š The predict taken/not taken bits implement simple finite state machines that record the past history of he branch. Š Single bit prediction „

The simplest implementation is a single bit recording what happened the last time the branch was executed. Alternatively, entries can be saved in the BTC by only recording branches that were taken last time.

31

A BTC – Prediction Mechanism Š Two-bit bit prediction „

Most BTCs use a two-bit up-down saturating counter. The counter is incremented every time a branch is taken to a maximum of 112 and decremented every time a branch is not taken to a minimum of 002.

32

Two-bit up-down saturating counters T

NT

00

T

01 NT

T 10

NT

Predict not taken

T

11 NT

Predict taken 33

A BTC – Prediction Mechanism Š Three-bit bit prediction „

Generally does not increase the accuracy of predictions. (Sechrest, S., Lee, C. and Mudge, T. The Role of Adaptivity in Two-level Branch Prediction. Micro-28, Ann Arbor, Michigan, pp. 264 – 269, November 1995).

34

A simple Loop Example Š Consider the following loop: loop:

Š

inst 1 : bne loop

Assume that the loop closing branch is taken n times and then falls through.

35

A simple Loop Example Š

If a single bit is used the branch will be mispredicted twice every time the entire loop is executed. „

„

„ „

When the branch is executed the very first time, it will not be held in the BTC and will therefore be mispredicted. So long as the loop is iterated, the branch will be correctly predicted as taken. When, the loop exits a single misprediction will occur. This misprediction will also set the prediction bit back to not taken. This means that, if the loop is executed again, the branch will be mispredicted again at the end of the first loop iteration.

36

A simple Loop Example Š If a two-bit up-down saturating counter is used the branch will only be mispredicted once every time the entire loop is executed. „

This is because two mispredictions are now required to change the prediction from strongly predicted taken (112) to weakly predicted not taken (012).

37

BTC Prediction Accuracy Š BTC achieves a prediction accuracy between 80 and 90%. Š For multiple instruction issue (MII) processors „

„

Many instructions issued before a misprediction is detected. A mispredicted branch incurs a heavy penalty.

Š A BTC therefore does not provide sufficient accuracy for MII processors. 38

BTC Prediction Accuracy

39

Other Mechanisms For Sorting the Branch Problem Š Aggressive Scheduling „ „

HSA IA-64

Š Branch Delay Slots „

HSA

Š Multithreading „

This could be a Modular Masters project.

40

State of the Art Dynamic Branch Prediction Š

Two-level Adaptive Branch Prediction „ „

History Registers (global and local) Pattern History Table (PHT)

Š

Hybrid Predictors are usually based on a bimodal predictor (such as a BTC) and a two-level predictor or Two twolevel predictors.

Š

Cached Correlated Branch Prediction „ „

Š

History Registers (global, local and combined) Prediction Cache.

Multistage Prediction (derived from Markov Predictors) employs more than one stage and is based on Cached Correlated Prediction.

41

Dynamic Branch Prediction -

David Patterson and John L. Hennessy. ◇ Superscalar Processor .... Lee, J. and Smith, J. Branch Prediction Strategies and Branch. Target Buffer Design.

249KB Sizes 0 Downloads 324 Views

Recommend Documents

Exploring Dynamic Branch Prediction Methods - Semantic Scholar
Department of Computer Science and Engineering, Michigan State University ... branch prediction methods and analyze which kinds of information are important ...

Exploring Dynamic Branch Prediction Methods - Semantic Scholar
Department of Computer Science and Engineering, Michigan State University. {wuming .... In the course of pursuing the most important factors to improve prediction accuracy, only simulation can make .... basic prediction mechanism. Given a ...

Branch Prediction Techniques and Optimizations
prediction techniques provide fast lookup and power efficiency .... almost as fast as global prediction. .... efficient hash functions enable the better use of PHT.

On-Demand Branch Prediction
Sep 12, 2013 - ... operations and of the remaining lookups, 80% are done for highly bi- .... Hardware Architecture: a BPU consists of three key components: ...

Automating Branch-and-Bound for Dynamic Programs
Jan 7, 2008 - tion calculating a bound on the value of the dynamic program, we can optimize the ..... This leads to cleaner and faster code. The argument ...

A Self-Similar Traffic Prediction Model for Dynamic ...
known about the traffic characteristics of wireless networks. It was shown in [1] that wireless traffic traces do indeed exhibit a certain degree of self-similarity and ...

A Self-Similar Traffic Prediction Model for Dynamic ...
The availability of precise high-quality and high-volume data sets of traffic ... to forecast real-time traffic workload could make dynamic resource allocation more ...

A Three-dimensional Dynamic Posture Prediction Model for ...
A three-dimensional dynamic posture prediction model for simulating in-vehicle seated reaching movements is presented. The model employs a four-segment ...

A Dynamic Bayesian Network Approach to Location Prediction in ...
A Dynamic Bayesian Network Approach to Location. Prediction in Ubiquitous ... SKK Business School and Department of Interaction Science. Sungkyunkwan ...

Branch Operations_National Branch Marketing Executive JD.pdf ...
Page 1 of 1. Branch Operations_National Branch Marketing Executive JD.pdf. Branch Operations_National Branch Marketing Executive JD.pdf. Open. Extract.

Branch Ops_National Branch Marketing Executive.pdf
Branch Ops_National Branch Marketing Executive.pdf. Branch Ops_National Branch Marketing Executive.pdf. Open. Extract. Open with. Sign In. Main menu.

Branch pages
Sep 21, 2006 - additional support against gravity and allow the white dwarf to become overmassive before it exploded. The maximum mass a white dwarf ...

Branch pages
Sep 21, 2006 - enough energy from nuclear fusion to blast the white dwarf apart at speeds of a ... about 0.6 solar masses of the white dwarf to a single isotope ...

Bank / Branch Code
Bank Code Br. Code Bank & Branch Name. 01. INVESTMENT CORPORATION OF BANGLADESH. 01. Head Office, Dhaka. 02. Local Office, Nayapaltan, Dhaka. 03. Chittagong Branch, Chittagong. 04. Rajshahi Branch, Rajshahi. 05. Sylhet Branch, Sylhet. 06. Bogra Branc

branch a5_en_Nov.pdf
TEA BLACK / GREEN / ORANGE. BOTH BREAKFAST AND BRUNCH! SATURDAY / SUNDAY. FROM 12:00 TILL 16:00. MAIN + DESSERT + DRINK = 390 ₽.

ANC 2015 Branch Manual.pdf
development, poverty alleviation and improved service delivery. .... that will best serve the ANC and help achieve our goals. .... A smaller working committee is elected by the REC to do the day-to-day management work of ...... Email to those with em

Judicial Branch - USCIS
The judicial branch can probably be covered in one lesson. The handouts focus on ... about all the levels for the test, but you should explain that there are many ...

branch
Teams, Recognition and Reward, Performance Appraisal, Benefits, Continuous Process. Improvement – Juran Trilogy, PDSA Cycle, 5S, Kaizen, Supplier Partnership –. Partnering, sourcing, Supplier Selection, Supplier Rating, Relationship Development,.

ANC Branch Manual 2010
many other organisations and structures that form the living collective body that the Liberation Movement represents. It is by understanding this mass base, rather ..... portfolio holders are elected as additional members and portfolios can be alloca

ANC 2015 Branch Manual.pdf
that will best serve the ANC and help achieve our goals. ..... Acfively involves members in on-going campaigns that address specific community concerns and problems;. △ Recruit ...... Email to those with email and print only for those without.

Branch Averages.pdf
Loading… Whoops! There was a problem loading more pages. Retrying... Whoops! There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. Branch Averages.pdf. Branch A

Forbes Branch ABA
3 Arrow. 1As Grading Total. 1 Arrow. Cub Boys Longbow Traditional D. 1 F Dalton Cain. Forbes. 78. 32. 0 ... 6 F Kenneth Reed. Forbes. 330. 308. 0. 638. 638.

branch a5.pdf
... GREEN / ORANGE. BOTH BREAKFAST AND BRUNCH! SATURDAY / SUNDAY. FROM 12:00 TILL 16:00. MAIN + DRINK = 390 ₽. Page 1 of 1. branch a5.pdf.