I had a function which looked like this (showing only the important part):
double CompareShifted(const std::vector& l, const std::vector&
The && operator implements short-circuit evaluation. This means that the second operand is only evaluated if the first one evaluates to true. This certainly results in a jump in that case.
You can create a small example to show this:
#include
bool f(int);
bool g(int);
void test(int x, int y)
{
if ( f(x) && g(x) )
{
std::cout << "ok";
}
}
The assembler output can be found here.
You can see the generated code first calls f(x), then checks the output and jumps to the evaluation of g(x) when this was true. Otherwise it leaves the function.
Using "boolean" multiplication instead forces the evaluation of both operands every time and thus does not need a jump.
Depending on the data, the jump can cause a slow down because it disturbs the pipeline of the CPU and other things like speculative execution. Normally branch prediction helps, but if your data is random there is not much which can be predicted.