2

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?

Community
  • 1
  • 1
Shubham
  • 21,300
  • 18
  • 66
  • 89

1 Answers1

3

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.

FaultyJuggler
  • 532
  • 1
  • 8
  • 29
  • Just being a bit nitpicky. An interrupt is *not* thrown as this would be visible to the operating system. The branch misprediction is handled completely in hardware and the software is completely unaware of it (except for the potential performance difference). There is no consistent term for the event, but interrupt is consistently used to refer to events that can potentially interrupt the operating system and are visible to software. – Nathan Binkert Jul 13 '12 at 17:38
  • As I said in my description above, when the branch evaluation is complete, there is an answer, true or false. The predictor made a guess at true or false. You could say it's branch inception almost, as it now has the prediction it made, and the actual evaluation of the branch, and it compares the two in one last == condition. That is how it knows. It simply compares what it now knows in the present with what it assumed in the past, the predicted value is stored off in the side for this future check. – FaultyJuggler Nov 30 '13 at 03:31