[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <alpine.LFD.1.10.0804290839220.3119@woody.linux-foundation.org>
Date: Tue, 29 Apr 2008 08:50:03 -0700 (PDT)
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: Harvey Harrison <harvey.harrison@...il.com>
cc: Andrew Morton <akpm@...ux-foundation.org>,
LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] lib: bitrev.c micro-optimization
Not very good. Why do it in memory, when doing it in a register is much
clearer?
This generates one byte longer code for me, but avoids the partial memory
stalls and looks more obvious. It is also portable, unlike your version
(you need to use a union to avoid aliasing issues - admittedly we disable
the gcc alias code anyway because of other kernel code, but still).
Linus
---
lib/bitrev.c | 10 ++++------
1 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/lib/bitrev.c b/lib/bitrev.c
index 989aff7..e0cb44e 100644
--- a/lib/bitrev.c
+++ b/lib/bitrev.c
@@ -42,17 +42,15 @@ const u8 byte_rev_table[256] = {
};
EXPORT_SYMBOL_GPL(byte_rev_table);
-static __always_inline u16 bitrev16(u16 x)
-{
- return (bitrev8(x & 0xff) << 8) | bitrev8(x >> 8);
-}
-
/**
* bitrev32 - reverse the order of bits in a u32 value
* @x: value to be bit-reversed
*/
u32 bitrev32(u32 x)
{
- return (bitrev16(x & 0xffff) << 16) | bitrev16(x >> 16);
+ return (bitrev8(x) << 24) |
+ (bitrev8(x >> 8) << 16) |
+ (bitrev8(x >> 16) << 8) |
+ (bitrev8(x >> 24));
}
EXPORT_SYMBOL(bitrev32);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists