3 ms·
You have to be careful with turning control dependencies into data dependencies. It can be very hard to understand or predict how a CPU will behave. If you are
by throwawaylinux 3y ago
You have to be careful with turning control dependencies into data dependencies. It can be very hard to understand or predict how a CPU will behave.
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.