https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60554

--- Comment #3 from Uroš Bizjak <ubizjak at gmail dot com> ---
(In reply to Luchezar Belev from comment #0)
> consider this simple function:
>  int is_float_negative(int x) { return (int)(x ^ 0x80000000) > 0; }
> 
> for x86, with options "-O3 -march=core2", GCC 4.8.2 generates the following
> code:
>    ....
>    _is_float_negative:
>       movl    4(%esp), %eax
>       addl    $-2147483648, %eax
>       testl   %eax, %eax
>       setg    %al
>       movzbl  %al, %eax
>       ret
>    ....
> 
> apparently (x^0x80000000) is replaced with (x+0x80000000), that's ok.
> the problem is the testl instruction - why the compiler decided to emit it?
> the addl instruction itself sets the needed flags (Z and N) just right.

Nope, setg means "Set byte if greater (ZF=0 and SF=OF)". The problem is when
%eax is -1. addl sets OF flag and clears SF, so setg doesn't set %al.

Reply via email to