acl wrote on 2023-09-07, 07:53:
- Speculative execution : make statistics (really basic ones) on code branching. For example : "the last 3 times i evaluated this condition, it was "true" so i will assume this will be true again". This allow the CPU to fill the pipeline with the code of the "true" branch. Without speculative execution, the CPU would have to wait until the condition is executed to know what to execute after. This helps to fill the pipeline efficiently. And if the prediction is wrong, then you just drop what's inside the pipeline and load the correct branch.
(for the experts : sorry if these descriptions contains aproximative statements, English does not help 😁)
Your explanation is quite good, but it doesn't describe "speculative execution", it describes "branch prediction".
The idea of speculative execution is to go one step further, and not only fill the pipeline, but also already execute those instructions, but do it in a way that the effects of the instructions can be undone/discarded if the prediction turned out false. Register Renaming (another feature you listed) helps a lot for speculative execution, as this just means that you need to keep the last confirmed value of a logical register in a different hardware register than the current value with speculative execution. If the prediction turned out to be right, your redeclare the "speculative current register" as "confirmed register". If the prediction turned out to be wrong, you just reset the register view to the registers that contain the last non-speculative values.