Как я могу преобразовать старшие n битов индекса (ПК) в младшие n битов в предсказании ветви gshare? - PullRequest
0 голосов
/ 03 марта 2019

Я пытаюсь построить симуляцию предсказания веток gshare.Я застрял, когда пытался создать регистр истории веток.Мне нужно определить индекс ветвления в таблицу прогнозирования, и индекс должен сгенерироваться так, как если бы текущий n-битный регистр глобальной истории ветвлений был XORed с самыми младшими n битами битов индекса (ПК).Это работа, которую я получил до сих пор.

//initialization
Predictor::Predictor (int m, int n) {
index_bits = m;
history_bits = n;
table_rows = pow(2, index_bits);
table = new int[table_rows];  //Branch predictor table

predictions = mispredictions = 0;

//30 bit 0x11.. Right shift for mask.
PCmask = (1073741823 >> (30-index_bits) ); //For n=0.

PCmask_gshare = (1073741823 >> ( 30 - (index_bits - history_bits))) ; //For m-n bits         

Hmask = (1073741823 >> (30 - history_bits) );   //For n bits in gshare.
initialize();
}

Вот моя функция gshare:

gshare(unsigned int addr, const char *op) {
predictions++;
int prediction;
int actual;
unsigned int p =0;
unsigned int x =0;

address = addr;

p = history_table ^ ( (address >> ( 2 + index_bits - history_bits)) & Hmask );

index = (p << (index_bits - history_bits)) + ( (address >> 2) & PCmask_gshare );

// cout << " GP: " << dec << index << "  " << table[index] << endl;

// 1 is taken, 0 is not-taken.
if (table[index] > 3)
    prediction = 1;
else if (table[index] < 4)
    prediction = 0;

if ( *op == 'n')
    actual = 0;
else if ( *op == 't')
    actual = 1;

if ( prediction != actual) {
    mispredictions++;
}

// Update branch prediction table.
if ( actual == 1 ) {
    table[index] = table[index] + 1;
    if (table[index] > 7)
        table[index] = 7;
}

else if( actual == 0 ) {
    table[index] = table[index] - 1;
    if (table[index] < 0)
        table[index] = 0;
}

// Update global branch history register.
x = history_table >> 1;
history_table = (actual << (history_bits-1))  + x;
}

Этот код предназначен для старших n битов индекса (ПК).Мне нужно получить младшие n бит.

...