When I am down to squeezing the last bit of performance out of a kernel, I usually find that replacing the logical operators (&&
and
A && B:
if (!A) {
return 0;
}
if (!B) {
return 0;
}
return 1;
A & B:
return A & B;
These are the semantics considering that evaluating A and B can have side effects (they can be functions that alter the state of the system when evaluated).
There are many ways that the compiler can optimize the A && B
case, depending on the types of A and B and the context.