Hi,
for the function (really: ternary expressions)
int dummy(int x)
{
#ifdef VARIANT
x < 0 ? --x : x > 0 ? ++x : 0;
#else
x < 0 ? --x : x > 0 ? ++x : x;
#endif
}
GCC 10.2.0 generates the following code targeting AMD64:
testl %edi, %edi
js .L0
leal 1(%rdi), %eax
movl $0, %edi # SUPERFLUOUS:
cmove %edi, %eax # cmove is only executed if edi was already 0
ret
.L0:
leal -1(%rdi), %eax
ret
Targeting i386, GCC 10.2.0 generates it the other way 'round:
movl 4(%esp), %eax
testl %eax, %eax
js L0
leal 1(%eax), %edx
movl $0, %eax # SUPERFLUOUS:
cmovne %edx, %eax # cmovne is only executed if eax was not 0
ret
L0:
subl $1, %eax
ret
regards
Stefan