views:

193

answers:

4

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?

+1  A: 

Let me wikipedia it for you.

shoosh
+1  A: 

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
A: 

I've read the wikipedia article before posting it here and still don't quite get it

EquinoX
You shouldn't post this as an answer. You should add this as comment to your question or comment to other's answer or edit your question and add it to the question.
claws
+4  A: 

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
which branch type in your article is the question above?
EquinoX
It's an adaptive two-level predictor with one bit of local branch history, like in PMMX and above.
Tuna-Fish