Hardware solutions: BTAC
The BTAC is a set of tuples each of which contains:
- Field 1: the address of a branch (or jump) instruction (which was executed in the past),
- Field 2: the most recent target address for that branch or jump,
- Field 3: information that permits a prediction as to whether or not the branch will be taken.
The BTAC functions as follows:
- The IF stage compares PC against the addresses of jump and branch instructions in BTAC (Field 1). ---- Suppose a match:
- If the instruction is a jump, then the target address is used as new PC. If the instruction is a branch, a prediction is made based on information from BTAC (Field 3) as to whether the branch is to be taken or not.If predict taken, the most recent branch target address is read from BTAC (Field 2) and used to fetch the target instruction.
- Of course, a misprediction may occur. Therefore, when the branch direction is actually known in the MEM stage, the BTAC can be updated with the corrected prediction information and the branch target address.