In computer architecture I'm confused between speculative execution & branch prediction. Are the same or different?
“Branch prediction” will predict whether a particular branch is taken or not. The prediction can be right or wrong; whoever designs the hardware for it will want the prediction to be correct as often as possible.
Starting with a predicted branch, we don’t know if the instructions we execute should actually be executed, so we start with speculative execution. At some point the processor will learn correctly whether the branch should have been taken or not. If the branch was predicted correctly, the speculative execution is turned into non-speculative. If the branch was predicted incorrectly, all the results of speculative execution are thrown away and you continue with the correct branch.
Car analogy: You drive a car, I have the map. I say “I think you need to turn left” = branch prediction. You turn left = speculative execution. Later I tell you if the turn was correct or wrong.