Re:How to check if any word is zero
by jcbages on Thursday October 20, 2022 @02:55PM
(#33279053)
Interesting! It'd be nice to benchmark to see if there are any practical difference in terms of speed.
[ Parent
| on HN ]
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.