[<prev] [next>] [day] [month] [year] [list]
Message-ID: <Pine.LNX.4.58.0702161617330.16341@shell2.speakeasy.net>
Date: Fri, 16 Feb 2007 16:19:20 -0800 (PST)
From: Trent Piepho <xyzzy@...akeasy.org>
To: Linux Kernel Mailing list <linux-kernel@...r.kernel.org>
cc: Andrew Morton <akpm@...l.org>,
Francois-Rene Rideau <fare@...es.org>
Subject: [PATCH] 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.
View attachment "swab-fix.patch" of type "TEXT/PLAIN" (7074 bytes)
Powered by blists - more mailing lists