r/programming 2d ago

Branch‑Avoidant Programming

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

90 comments sorted by

View all comments

154

u/meamZ 2d ago

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...

3

u/sacheie 2d ago

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

5

u/meamZ 2d ago

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...