Reputation: 5073
The branch that is guessed to be the most likely is then fetched and speculatively executed. If it is later detected that the guess was wrong then the speculatively executed or partially executed instructions are discarded and the pipeline starts over with the correct branch, incurring a delay.
The citation comes from wikipedia.
Why is it possible to always discard executed instructions? For example, what about a situation where the first instruction in mispredicted taken branch is syscall 0x60
( on Linux it is interruption: "Exit program" ). I know that the program won't be exited in case of misprediction but how the CPU is able to discard?
I know that every instruction ( splitted to micro-ops) must be retired to be finished. Maybe it is important for speculative execution?
Upvotes: 1
Views: 579
Reputation: 62472
Speculative execution typically applies to loading registers and branching. These are easily wound back by the CPU using techniques such as register renaming.
Not all instructions can be reliably rolled back. As you've identifier, things like a syscall
can't. For example, if you've made a system call to delete a file the CPU isn't going to be able to roll that back! What happens here is that when speculative execution is active certain instruction cause a "stall" in execution whilst the CPU waits to determine the actual outcome of the branch.
Upvotes: 1