How can I code the C ‘&&’ operator in x86? For example:
int a = ...
int b = ...
int c = a && b;
What would be the equivalent of the last line in x86?
EDIT: I want to do the above without any jumps.
EDIT: g++ generates this, but I don’t understand it:
testl %edi, %edi
setne %dl
xorl %eax, %eax
testl %esi, %esi
setne %al
andl %edx, %eax
Here is how GCC implements it at
-O3.Note that this code does not short-circuit; this is because in this case GCC can prove that there are no side effects from the second argument. If the second argument has side-effects, you must implement it using jumps. For example:
becomes: