2

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?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
aherlambang
  • 14,290
  • 50
  • 150
  • 253
  • 1
    My [survey paper](https://arxiv.org/pdf/1804.00261.pdf) on branch predictors may be a useful guide. It also explains the design and working of two-level branch predictors. – user984260 Apr 03 '18 at 10:13

3 Answers3

11

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.

Tuna-Fish
  • 586
  • 2
  • 4
  • which branch type in your article is the question above? – aherlambang Mar 29 '10 at 14:03
  • 1
    It's an adaptive two-level predictor with one bit of local branch history, like in PMMX and above. – Tuna-Fish Mar 30 '10 at 03:14
  • Update: modern Intel since at least Haswell (and AMD Ryzen 2) use TAGE / ITTAGE predictors (TAgged GEometric history length predictor) that use past branch history as part of the index into a table of predictors. https://danluu.com/branch-prediction/ has a section on that at the bottom. TAGE can "learn" very long patterns involving multiple branches, e.g. all the branches for a 12-element Bubble Sort with the same data repeatedly, or the indirect branch in an interpreter. It's a different strategy, not just further extensions of the older strategies like having local/global history. – Peter Cordes Jul 08 '19 at 23:46
2

Let me wikipedia it for you.

shoosh
  • 76,898
  • 55
  • 205
  • 325
2

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.

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179