android_kernel_xiaomi_sdm845/include/linux/byteorder
Trent Piepho 8e2c20023f Fix constant folding and poor optimization in byte swapping code
Constant folding does not work for the swabXX() byte swapping functions,
and the C versions optimize poorly.

Attempting to initialize a global variable to swab16(0x1234) or put
something like "case swab32(42):" in a switch statement will not compile.
It can work, swab.h just isn't doing it correctly.  This patch fixes that.

Contrary to the comment in asm-i386/byteorder.h, gcc does not recognize the
"C" version of swab16 and turn it into efficient code.  gcc can do this,
just not with the current code.  The simple function:

u16 foo(u16 x) { return swab16(x); }

Would compile to:
        movzwl  %ax, %eax
        movl    %eax, %edx
        shrl    $8, %eax
        sall    $8, %edx
        orl     %eax, %edx

With this patch, it will compile to:
        rolw    $8, %ax

I also attempted to document the maze different macros/inline functions
that are used to create the final product.

Signed-off-by: Trent Piepho <xyzzy@speakeasy.org>
Cc: Francois-Rene Rideau <fare@tunes.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-08 11:14:59 -07:00
..
big_endian.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
generic.h [PATCH] remove gcc-2 checks 2006-01-08 20:14:02 -08:00
Kbuild [PATCH] cleanup linux/byteorder/swabb.h 2007-02-11 10:51:34 -08:00
little_endian.h Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
swab.h Fix constant folding and poor optimization in byte swapping code 2007-05-08 11:14:59 -07:00
swabb.h [PATCH] cleanup linux/byteorder/swabb.h 2007-02-11 10:51:34 -08:00