You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The || and && operators have shortcutting behaviour. This is good when we need to test for unsafe behaviour, but otherwise these introduce conditional jumps statements which modern CPUs do not work well with. On the other hand, the logical operators | and & have no shortcutting behaviour; hence they use no jumps and use half the number of instructions (see here for some more discussion on the subject).
In C++ any bool value is either 0 or 1 (and nothing else). This also includes the result of == and < etc which can be done in a single instruction each. That means in many places we can use the logical operators | and & instead and not change the computation result! Yet, this is not a very common thing to do, so every time we do so, we need to add a little comment with an explanatory warning.
We only want to do it in the following places:
Our comparators run a linearithmic number of times with a small likelihood they are predictable.
Our predicates in internal/data.cpp on binary operators (e.g. is_left_shortcutting).
The text was updated successfully, but these errors were encountered:
The
||
and&&
operators have shortcutting behaviour. This is good when we need to test for unsafe behaviour, but otherwise these introduce conditional jumps statements which modern CPUs do not work well with. On the other hand, the logical operators|
and&
have no shortcutting behaviour; hence they use no jumps and use half the number of instructions (see here for some more discussion on the subject).In C++ any bool value is either 0 or 1 (and nothing else). This also includes the result of
==
and<
etc which can be done in a single instruction each. That means in many places we can use the logical operators|
and&
instead and not change the computation result! Yet, this is not a very common thing to do, so every time we do so, we need to add a little comment with an explanatory warning.We only want to do it in the following places:
is_left_shortcutting
).The text was updated successfully, but these errors were encountered: