News for hackers. Stuff that matters.
Re:How to check if any word is zero by AnotherGoodName on Thursday October 20, 2022 @04:24PM (#33280197)
Yes. In order:

A well predicted branch costs 0. This is the best case and why branching code can sometimes be faster.

An instruction that needs a previous instruction to compute has some pipeline stalls. This is slower than the above and why branchless code can be slower.

A mispredicted branch costs a full pipeline flush. The worst case. This is why we avoid branches but we shouldn't do so blindly since it might not be common in a given program.

So it depends. I discourage removing branches in general unless you have benchmarks to back it up.

There are no comments on this comment yet.