Dynamic-BM/predictor.cpp
bool twoBitSaturatingCountersPredictor (int * table, int index, char taken) {
    bool correct = 0;
    int state = table[index] % 4;
    if (taken == '1') {
        switch (state) {
            case 0:
            case 1:
                table[index]++;
                break;
            case 2:
                table[index]++;
            case 3:
                correct = 1;
                break;
        }
    } else {
        switch (state) {
            case 0:
                correct = 1;
                break;
            case 1:
                correct = 1;
            case 2:
            case 3:
                table[index]--;
                break;
        }
    }
    return correct;
}
/**
 * Predictor using 2 bit saturating counters
 * Update the entry in table base on the actual branch direction
 * (11 - Strongly Taken, 10 - Weakly Taken, 01 - Weakly Not-Taken, 00 - Strongly Not-Taken)
 *
 * @param table prediction table
 * @param index locate the entry in prediction table
 * @param taken actual branch direction
 * @return whether entry in the table matches actual branch direction
 */


@param table prediction table
@param index locate the entry in prediction table
@param taken actual branch direction
@return whether entry in the table matches actual branch direction
@param table prediction table @param index locate the entry in prediction table @param taken actual branch direction @return whether entry in the table matches actual branch direction
bool twoBitSaturatingCountersPredictor (int * table, int index, char taken) {
    bool correct = 0;
    int state = table[index] % 4;
    if (taken == '1') {
        switch (state) {
            case 0:
            case 1:
                table[index]++;
                break;
            case 2:
                table[index]++;
            case 3:
                correct = 1;
                break;
        }
    } else {
        switch (state) {
            case 0:
                correct = 1;
                break;
            case 1:
                correct = 1;
            case 2:
            case 3:
                table[index]--;
                break;
        }
    }
    return correct;
}
bool twoBitSaturatingCountersPredictor ( int * table , int index , char taken ) { bool correct = 0 ; int state = table [ index ] % 4 ; if ( taken == ' ' ) { switch ( state ) { case 0 : case 1 : table [ index ] ++ ; break ; case 2 : table [ index ] ++ ; case 3 : correct = 1 ; break ; } } else { switch ( state ) { case 0 : correct = 1 ; break ; case 1 : correct = 1 ; case 2 : case 3 : table [ index ] -- ; break ; } } return correct ; }
Predictor using 2 bit saturating counters
 Update the entry in table base on the actual branch direction
 (11 - Strongly Taken, 10 - Weakly Taken, 01 - Weakly Not-Taken, 00 - Strongly Not-Taken)
Predictor using 2 bit saturating counters Update the entry in table base on the actual branch direction ( 11 - Strongly Taken 10 - Weakly Taken 01 - Weakly Not - Taken 00 - Strongly Not - Taken )