+++ title = "Speculation does not have a cost" date = "2022-04-29" author = "Yann Herklotz" tags = [] categories = [] backlinks = ["1c6d"] forwardlinks = [] zettelid = "1c6e" +++ It is interesting to note that speculating on an instruction does not really incur a cost in itself. The idea is that if one is always wrong with the speculation, one really only reverts back to the non-pipelined instructions. So in the worst case one is only sequential. However, if one speculates, then it is highly unlikely that one is always wrong, and one will therefore always benefit from it. Therefore, in the speculative loop pipelining, it does not really matter in the end which instructions are picked to speculate on, and often the most efficient will be the shortest path in the pipeline. For example, Steven showed that even when one speculates on a binary search algorithm to two iterations (where one then has a 25% chance of being right), one still benefits from speculating going into one of the directions.