public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/29749]  New: Missing byte swap optimizations
@ 2006-11-07  7:06 ubizjak at gmail dot com
  2006-11-07 11:47 ` [Bug middle-end/29749] [4.0/4.1/4.2/4.3 regression] " schwab at suse dot de
                   ` (23 more replies)
  0 siblings, 24 replies; 25+ messages in thread
From: ubizjak at gmail dot com @ 2006-11-07  7:06 UTC (permalink / raw)
  To: gcc-bugs

There is a claim in linux asm-i386/byteswap.h that:

/* Do not define swab16.  Gcc is smart enough to recognize "C" version and
   convert it into rotation or exhange.  */

Not really. Consider these two testcases:

--cut here--
unsigned short bad(unsigned short a)
{
       return ((a & 0xff00) >> 8 | (a & 0x00ff) << 8);
}


unsigned short good(unsigned short a)
{
       return (a >> 8 | a << 8);
}
--cut here--


gcc -O2 -S -m32 -fomit-frame-pointer
bad:
       movzwl  4(%esp), %edx
       movl    %edx, %eax
       sall    $8, %eax
       shrl    $8, %edx
       orl     %edx, %eax
       movzwl  %ax, %eax
       ret


good:
       movzwl  4(%esp), %eax
       rolw    $8, %ax
       movzwl  %ax, %eax
       ret


IMO both forms should produce equal asm.

Unfortunatelly, first form is usually used:

drivers/net/sk98lin/skxmac2.c:
SWord = ((SWord & 0xff00) >> 8) | ((SWord & 0x00ff) << 8);

drivers/atm/iphase.c:
#define swap(x) (((x & 0xff) << 8) | ((x & 0xff00) >> 8))  

drivers/atm/iphase.c:
trailer->length = ((skb->len & 0xff) << 8) | ((skb->len & 0xff00) >> 8);


Ideally, this construct should be compiled using (not yet introduced...)
bswaphi2 pattern to generate "xchgb %ah,%al" instead of rolw insn. Accordint to
pentopt.pdf, xchg is faster, 1.5 vs 4 clks.

Maybe this transformation could also be used for 32bit and 64bit data, to
automatically convert open coded shift series into bswapsi2 and bswapdi2
patterns.


-- 
           Summary: Missing byte swap optimizations
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ubizjak at gmail dot com
  GCC host triplet: i686-pc-linux-gnu


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


^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2008-09-06 16:30 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-07  7:06 [Bug middle-end/29749] New: Missing byte swap optimizations ubizjak at gmail dot com
2006-11-07 11:47 ` [Bug middle-end/29749] [4.0/4.1/4.2/4.3 regression] " schwab at suse dot de
2007-02-03 17:29 ` jsm28 at gcc dot gnu dot org
2007-02-05  5:24 ` mmitchel at gcc dot gnu dot org
2007-02-14  9:19 ` mmitchel at gcc dot gnu dot org
2007-07-04 21:30 ` pinskia at gcc dot gnu dot org
2007-07-10 22:18 ` dougkwan at google dot com
2007-07-11 23:15 ` dougkwan at google dot com
2007-07-12  6:08 ` ubizjak at gmail dot com
2007-07-12  6:17 ` dougkwan at google dot com
2007-07-13 22:46 ` dougkwan at google dot com
2007-08-23 14:29 ` ubizjak at gmail dot com
2007-08-23 16:32 ` dougkwan at google dot com
2007-11-20 19:38 ` jakub at gcc dot gnu dot org
2007-11-20 20:05 ` rask at gcc dot gnu dot org
2007-11-21 14:51 ` jakub at gcc dot gnu dot org
2007-11-21 16:26 ` jakub at gcc dot gnu dot org
2007-11-21 19:11 ` rask at gcc dot gnu dot org
2007-12-03 22:39 ` jakub at gcc dot gnu dot org
2007-12-03 22:45 ` [Bug middle-end/29749] [4.0/4.1/4.2 " jakub at gcc dot gnu dot org
2007-12-17  9:24 ` ubizjak at gmail dot com
2007-12-17  9:29 ` jakub at gcc dot gnu dot org
2007-12-17  9:33 ` jakub at gcc dot gnu dot org
2008-07-04 21:45 ` [Bug middle-end/29749] [4.2 " jsm28 at gcc dot gnu dot org
2008-09-06 16:30 ` 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).