[Bug rtl-optimization/18560] New: better optimalization of EOR/MOV block.

pluto at pld-linux dot org gcc-bugzilla@gcc.gnu.org
Fri Nov 19 08:13:00 GMT 2004


/* 
    This function reverses the bytes in a word. The method was discovered in 
    1986 following a competition between ARM programmers; it requires just 4 
    instructions and 1 work register. A method using only 3 instructions per 
    word reversed was also found, but it has some set-up overhead and uses 
    a 2nd register. 
*/ 
 
unsigned long reverse(unsigned long v) 
{ 
    unsigned long t; 
    t = v ^ ((v << 16) | (v >> 16));    //      EOR r1,r0,r0,ROR #16    [1] 
    t &= ~0xff0000;                     //      BIC r1,r1,#&ff0000 
    v = (v << 24) | (v >> 8);           //      MOV r0,r0,ROR #8 
    return v ^ (t >> 8);                //      EOR r0,r0,r1,LSR #8 
} 
 
The gcc-3.4.3 with -O2 produces: 
 
reverse: 
        mov     r3, r0                  [2] 
        mov     r0, r0, ror #16         [2] 
        eor     r0, r0, r3              [2] 
        bic     r0, r0, #16711680 
        mov     r3, r3, ror #8 
        eor     r0, r3, r0, lsr #8 
        mov     pc, lr 
 
Itc doesn't seem to produce [2] optimal code [1].

-- 
           Summary: better optimalization of EOR/MOV block.
           Product: gcc
           Version: 3.4.3
            Status: UNCONFIRMED
          Severity: minor
          Priority: P2
         Component: rtl-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pluto at pld-linux dot org
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: pentium3-pld-linux
  GCC host triplet: pentium3-pld-linux
GCC target triplet: arm-pld-linux


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



More information about the Gcc-bugs mailing list