> gcc -v
Using built-in specs.
Target: i386-apple-darwin9.2.2
Configured with: ../gcc/configure --prefix=/usr/local/gcc44
--enable-threads=posix --with-arch=core2 --with-tune=core2 --with-gmp=/sw
--with-mpfr=/sw --disable-nls --disable-bootstrap --enable-checking=yes,rtl
--enable-languages=c,c++,objc
Thread model: posix
gcc version 4.4.0 20080611 (experimental) (GCC) 

gcc compiles

int shift32(int i, int n)
{
        return i >> (32 - n);
}

to

_shift32:
        subl    $12, %esp
        movl    $32, %ecx
        subl    20(%esp), %ecx
        movl    16(%esp), %eax
        sarl    %cl, %eax
        addl    $12, %esp
        ret

Since all 286-and-up CPUs only use the low 5 bits of ecx when shifting, this
can be:

_shift32:
        movl    8(%esp), %ecx
        movl    4(%esp), %eax
        negl   %ecx
        sarl    %cl, %eax
        ret

This is very common in bitstream readers, where it's used to read the top N
bits from a word. ffmpeg already has an inline asm to do it, which I'd like to
get rid of.

I'd guess this applies to some other architectures; it probably works on
x86-64, but doesn't on PPC.


-- 
           Summary: x86 can use x >> -y for x >> 32-y
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: astrange at ithinksw dot com
GCC target triplet: i?86-*-*


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36503

Reply via email to