missed optimization compiling naive get_unaligned_le32 on x86

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When compiling this code:

unsigned int get_le32(unsigned char *p)
{
  return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
}

On gcc 4.6.0 rev. 172266 for x86-64, I get:

        movzbl  1(%rdi), %eax
        movzbl  2(%rdi), %edx
        sall    $8, %eax
        sall    $16, %edx
        orl     %edx, %eax
        movzbl  (%rdi), %edx
        orl     %edx, %eax
        movzbl  3(%rdi), %edx
        sall    $24, %edx
        orl     %edx, %eax
        ret

I hoped for much better code. I hoped to avoid ifdef's depending on
endianess, but this means I can't.
Am I missing something obvious that precludes the compiler from
optimizing the expression?
This is not a regression and other compilers didn't do any better, so
I hope I'm just missing something.

thanks,
-Z.T.


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux