Question

Consider the following sequence of actual outcomes for a single static branch. T means the branch is taken. N means the branch is not taken. For this question, assume that this is the only branch in the program.

T T T N T N T T T N T N T T T N T N

Assume a two-level branch predictor that uses one bit of branch history—i.e., a one-bit BHR. Since there is only one branch in the program, it does not matter how the BHR is concatenated with the branch PC to index the BHT. Assume that the BHT uses one-bit counters and that, again, all entries are initialized to N. Which of the branches in this sequence would be mis-predicted? Use the table below. alt text

Now I am not asking answers to this question, rather than guides and pointers on this. What does a two level branch predictor means and how does it works? What does the BHR and BHT stands for?

Was it helpful?

Solution

I only really got branch prediction after reading Agner Fog's text on microarchitecture of modern CPU's at http://www.agner.org/optimize/#manuals , specifically, the third one: http://www.agner.org/optimize/microarchitecture.pdf

If you want to be good at low-level programming, you should probably read it all. If you want to just know how the branch predictors work, just read the chapter on branch prediction in the microarchitecture manual. It uses real branch predictors from past processors to explain how the things work, starting from conceptually simple predictors such as the ones found in P1 and gradually adding more features until you get to the monsters in present-day processors.

OTHER TIPS

From Wikipedia: Branch predictor

A two-level adaptive predictor remembers the history of the last n occurrences of the branch and use one saturating counter for each of the possible 2n history patterns.

BHR: Branch History Register
BHT: Branch History Table

Both of these two terms are explained, briefly and without reference to their acronyms, in the article section linked above.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top