In computer architecture,
what is difference between (branch) prediction and speculation??
These seems very similar, but i think there is a subtle distinction between them.
In computer architecture,
what is difference between (branch) prediction and speculation??
These seems very similar, but i think there is a subtle distinction between them.
Branch prediction is done by the processor to try to determine where the execution will continue after a conditional jump, so that it can read the next instruction(s) from memory.
Speculative execution goes one step further and determines what the result would be from executing the next instruction(s). If the branch prediction was correct, the result is used, otherwise it is discarded.
Note that speculative execution can be applied even if there isn't an actual conditional branch in the code. The processor can determine the result from several instructions that normally would execute in succession, but the execution could be stopped for example by an arithmetic overflow interrupt.
If you want to speculatively do something, you increase your chance of it being useful by accurately predicting which path to speculate on.
In some cases, the prediction is trivial (e.g. predict that loads/stores won't segfault). In other cases, it's hard (branch prediction).
In either case, you need to be able to revert / throw away the speculative calculations if an exception occurs.
It is possible to speculate without prediction, by speculatively executing instructions from both directions of a branch, and only keeping the result from the line that's later found to have been the right path.
Current hardware doesn't make use of this for branches, but the same sort of thing happens on a much smaller local scale for stuff like parallel decoding of x86 instructions. Decoders start decoding at every possible instruction boundary, and only find out which start position was correct once the decode of the previous instruction determines the length.
Well I am a noob to programming and computer science, but this is my conclusion. The purpose of both these 'techniques' is to keep the pipelne filled, preventing waste of resources. When a processor encouters a conditional test instruction, normally you would expect it to wait until the condition has been tested before proceeding to the next instruction.
In speculative execution you execute the instruction anyways 'hoping' that the conditional test was TRUE instead of stalling the pipeline and hurting resources. Otherwise you just discard the results.
In branch prediction you go one step further and predict whether the condition will be TRUE or not based on past results of the conditional test.(You predict the direction your program will branch into).
Hope that clears things up. Got the info from here and a course I am taking this semester. http://www.pcguide.com/ref/cpu/arch/int/featSpeculative-c.html