Question

My question comes out of Mystical's answer. As I have understood, you have a branch instruction, it can either go to another instruction, say like, 0x123344 or it can continue executing.

If a branch predictor makes guess from either of them from past patterns, how does it realize it has made a mistake, and revert it?

Was it helpful?

Solution

This all comes from staged processors where portions of the CPU in the past remained idle, now we make use of every little piece as much as possible. If there were no branching or conditional events this would be smooth, but now and then we need to change what's happening.

Thus as mentioned by Mystical the predictor makes a guess so that most of the time idle computing power isn't waiting. The processor continues forward with what was guessed at, and when the previous instruction that was being waited on completes the predictor is compared to. If it guessed right nothing happens, if it guessed wrong a signal is sent and the stages after the prediction point are thrown out and run again with the correct values.

How this is done at the technical level varies between architectures. It isn't so much a reverting action so much as it invalidates everything that was computed after the incorrect prediction and those processes are redone.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top