Re:Mispredicted branches can multiply your running times
by dooglius on Wednesday October 16, 2019 @09:19AM
(#21269999)
It looks as though you're being downvoted but I'm not sure why. This matches my mental model of OoO execution, for instance if you have a loop like:
I would expect that a branch predictor wouldn't be needed as the jump only needs the flags register to figure out where the branch is going to go.
[ Parent
| on HN ]
Re:Mispredicted branches can multiply your running times
by gpderetta on Wednesday October 16, 2019 @09:48AM
(#21270268)
that's not how ooo cpu work in practice. Jumps are resolved at the fetch stage, always by consulting the predictor; at this stage there is no opportunity to actually execute the jmpne instruction and check if the sign flag is set or not. When the jumpne is executed later in the pipeline, its only effect it to either commit or rollback the speculation.
This is not specific of OoO cpus. In order cpus work the same way, assuming they have a predictor of course.
edit: to be more precise, jumps are not not resolved at the fetch stage, but in one of the early stages, in fact there is often a bubble for taken branches as the fetcher will fetch the next instruction in the stream by default.