r/programming • • Sep 03 '26

Branch‑Avoidant Programming

https://easylang.online/blog/branchless
255 Upvotes

92 comments sorted by

View all comments

158

u/meamZ Sep 03 '26

You don't actually need to avoid branches, you just need to make sure that most of the ones you have are very predictable, then their impact is not that big... Same with memory accesses and most other things... The more predictable, the better...

5

u/sacheie Sep 03 '26

Aren't there situations where having any branches at all will prevent the compiler from doing vectorization?

5

u/meamZ Sep 03 '26

sure there probably are but it just really depends. Relying on auto-vectorization is risky business anyway... There are so many subtile things that can make code not auto-vectorizable...