English 中文(简体)
Branch Prediction - Global Share Implementation Explanation [closed]
原标题:
Closed. This question is off-topic. It is not currently accepting answers.

Want to improve this question? Update the question so it s on-topic for Stack Overflow.

Closed 10 years ago.

I m working on an assignment in my Computer Architecture class where we have to implement a branch prediction algorithm in C++ (for the Alpha 21264 microprocessor architecture).

There is a solution provided as an example. This solution is an implementation of a Global Share Predictor.

I am simply trying to understand the given solution, specifically what is going on in:

*predict (branch_info &b) {...}

specifically,

if (b.br_flags & BR_CONDITIONAL) {...}

Can anyone provide me with an explanation? Thank you.

最佳回答

I think the following paper by Scott McFarling provides the detailed answer:

http://www.hpl.hp.com/techreports/Compaq-DEC/WRL-TN-36.pdf

Let me use your code to explain.

unsigned char tab[1<<TABLE_BITS];

is the Pattern History Table. Each entry in the tab keeps a 2-bit saturating counter. The direction of the conditional branch is finally determined by the MSB of the counter:

u.direction_prediction (tab[u.index] >> 1);

The reason why we use a counter of two or more bits instead of just one bit is to make the pattern less sensitive to reduce misprediction. For example,

for( int i = 0; i < m; i++ )
{
    for( int j = 0; j < n; j++ )
    {
       ...
    }
}

when the inner loop is executed for the next time, one bit counter will mispredict the branch while 2-bit counter can prevent it.

The next is how to find the correct pattern in the Pattern History Table.

The naive way is to use branch address as index. But it ignores the correlation between different branches. That is why Global Branch History is introduced (For more details, please refer to http://www.eecg.utoronto.ca/~moshovos/ACA06/readings/two-level-bpred.pdf).

In your code,

unsigned int history;

is the Branch History Register which stores the Global Branch History.

Then some guys have found that combining Global Branch History and Branch Address as index can lead to more accurate prediction than just using one of them. The reason is that both Global Branch History and Branch Address affect the branch pattern. If ignoring one of them, different branch pattern may be hashed to the same position of the Pattern History Table, thus causing collision problem.

Before Gshare is proposed, there is a solution called Gselect, which uses concatenation of Global Branch History and Branch Address as index of Pattern History Table.

The solution provided by Gshare is the hash function of

index = branch_addr XOR branch_history

This is what exactly what the following code means:

 u.index = (history << (TABLE_BITS - HISTORY_LENGTH)) ^ (b.address & ((1<<TABLE_BITS)-1));

Scott McFarling s paper provides a good example to show how Gshare works better than Gselect:

  1. Branch Address=1111_1111 Global Branch History=0000_0000
  2. Branch Address=1111_1111 Global Branch History=1000_0000

Assume that we use the following Gselect strategy to prevent bias:

index = { {branch_addr[7:4]}, {branch_history[3:0]} }

Then Gselect will produce 1111_0000 for both cases while Gshare can distinguish the different patterns.

As far as I know, Gshare turns out to be the best solution by far to remove the collision.

问题回答

暂无回答




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签