When compiling the following function for a coldfire target, such as mcf5249:
(using the following command line m68k-elf-gcc hswap.c -mcpu=5249 -S -O2)
unsigned hswap(unsigned x)
{
    return (x << 16) | (x >> 16);
}

gcc produces:

hswap:
        link.w %fp,#0
        move.l 8(%fp),%d1
        move.l %d1,%d0
        clr.w %d0
        swap %d0
        swap %d1
        clr.w %d1
        or.l %d1,%d0
        unlk %fp
        rts

Optimization level affects only instr ordering.

the same function compiled for 68020
(using the following command line m68k-elf-gcc hswap.c -mcpu=68020 -S -O2)

hswap:
        link.w %fp,#0
        move.l 8(%fp),%d0
        swap %d0
        unlk %fp
        rts

which is valid code for the coldfire target too and much smaller and faster

this is using gcc 4.4.2 configured with 
--enable-languages=c --disable-libssp --with-arch=cf --with-cpu=5249

the same behaviour is present in gcc 3.4.6 too.


-- 
           Summary: [m68k] Suboptimal halfword swap on coldfire
           Product: gcc
           Version: 4.4.2
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: nizze86 at hotmail dot com
  GCC host triplet: amd64-unknown-linux
GCC target triplet: m68k-elf


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

Reply via email to