This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Mined out of comp.std.c...


Zack Weinberg wrote:

> static int int_max (int a, int b) {
>     int d = (b - a);
>     return (b - d) & (d >> (CHAR_BIT*sizeof(int) - 1));
> }

Maybe I need more coffee, but isn't (b-d) == a?

>    8:   89 c2                   mov    %eax,%edx
>    a:   29 ca                   sub    %ecx,%edx
>    c:   29 d0                   sub    %edx,%eax
>    e:   c1 fa 1f                sar    $0x1f,%edx
>   11:   21 d0                   and    %edx,%eax

so rather

        subl    %eax, %ecx
        sarl    $31, %ecx
        andl    %ecx, %eax

Rup.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]