The 2-bit predictor is a simple branch prediction mechanism implemented in many branch target buffers.

Explanation
A 2-bit predictor is a saturated counter that counts from 0 to 3. To understand the behavior of a predictor you have to understand branch instructions that can either "fall through" and execute the next sequential instruction, or jump to a new section of code and branch to the "taken path".

When the 2-bit counter is at '0' or '1', it is predicting that the branch instruction is not taken, or fall-through. When the counter is '2' or '3', the prediction is that the instruction is taken, and the next instruction to be executed should come from the taken path. If the prediction is incorrect, then the incorrect instructions are squashed, the correct instructions are fetched, and the counter is altered by 1, plus or minus depending on taken or not taken. That way the two-bit counter will fairly accuratly predict branches in single loops and multi-nested loops.

There will exist a 2-bit predictor for every branch stored in the Branch Target Buffer (BTB). Usually the counters are initiallized to the value 2, thereby predicting 'taken' by default, because in most implementations the processor will assume the branch is fall-through if it's not in the predictor (BTB).

Log in or register to write something here or to contact authors.