by throwawaylinux · 3y ago · 0 comments
If you are testing quite predictable things, you almost always want to use branch prediction and not predicated/conditional instructions.
If something is totally unpredictable, let's say a binary search that is looking up random elements in a well balanced heap or tree. Each comparison is very unpredictable. A conditional select would work best there:
item = (val < item->val ? item->left : item->right);
if (val == item->val) ...
You could do your tree walks entirely without branch misses if that first line was a select... But it turns out that is not true. Or it's not necessarily true, depending a few (not uncommon) factors, it can be worse to use a select there.No comments yet.