Source
- URL: https://x.com/anicic_filip/status/1947536063959839200
- Author: Filip Aničić (@anicic_filip)
- Posted: 2025-07-22 05:55:55
Branch
1/ @anicic_filip
@nicbarkeragain
A more compact example is using a bitmask integer. It’s a good way to learn bitshifting and you don’t need to update the look up table when you update the enum
2/ @nicbarkeragain
@anicic_filip
Agreed, I made the assumption that people who haven’t heard of branchless before might struggle a little with the more compact approaches 🙂
3/ @anicic_filip
@nicbarkeragain
Look up table is a good introductory example.
The logic of CPUs doing multiplications faster than boolean comparisons is bonkers.
Is it releated to SIMD compiler optimizations or does this apply to non-AVX supporting CPUs?
4/ @Ashkan_GC
@anicic_filip @nicbarkeragain
Branches are slower because they need to be predicted and predictions can be wrong and cause stalls in instruction processing
5/ @anicic_filip
@Ashkan_GC @nicbarkeragain
So the CPU having to switch between doing a sum or not doing a sum based on the if is slowing it down, while doing a constant workload of multiply and then sum is more predictable, so also faster?
Does this mean that older CPUs with worse to none prediction would suffer the most?