public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/36503]  New: x86 can use x >> -y for x >> 32-y
@ 2008-06-11 22:53 astrange at ithinksw dot com
  2008-06-11 22:53 ` [Bug target/36503] " astrange at ithinksw dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 10+ messages in thread
From: astrange at ithinksw dot com @ 2008-06-11 22:53 UTC (permalink / raw)
  To: gcc-bugs

> 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


^ permalink raw reply	[flat|nested] 10+ messages in thread
[parent not found: <bug-36503-4@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2010-10-22  7:37 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-11 22:53 [Bug target/36503] New: x86 can use x >> -y for x >> 32-y astrange at ithinksw dot com
2008-06-11 22:53 ` [Bug target/36503] " astrange at ithinksw dot com
2008-06-12  0:05 ` pinskia at gcc dot gnu dot org
2008-06-12  9:25 ` rguenth at gcc dot gnu dot org
2008-06-12 10:44 ` ubizjak at gmail dot com
2008-06-12 16:49 ` astrange at ithinksw dot com
2009-11-07  9:22 ` bonzini at gnu dot org
2009-11-09  7:38 ` ubizjak at gmail dot com
     [not found] <bug-36503-4@http.gcc.gnu.org/bugzilla/>
2010-10-21  4:39 ` astrange at ithinksw dot com
2010-10-22  7:37 ` ubizjak at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).