3 ms·
Compares and jumps are cheap only if the branch is predicted. If not predicted, they're worse than a division. In data-driven conditionals, a conditional move o
by chadaustin 15y ago
Compares and jumps are cheap only if the branch is predicted. If not predicted, they're worse than a division. In data-driven conditionals, a conditional move operations is likely the best.
- chadaustin 15y agoSorry, meant to respond to nknight.
- zokier 15y agoThere is still a compare/jump with the division method ( != 0) which needs prediction.
- nknight 15y agoBranch predictors have for years been accurate enough that the right thing is to not worry about a pipeline flush until you actually encounter a high miss rate. By the way, on the latest CPUs, they're not just "cheap" -- cmp is actually as low as 0.5 cycles, and a predicted jcc is effectively 0. The comparison is actually between something that, in the absolute best case, is 5.5 cycles, vs. something that, in the general case, is 0.5 cycles.