lkml.org 
[lkml]   [2008]   [Apr]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [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);

\
 
 \ /
  Last update: 2008-04-29 17:53    [W:0.028 / U:0.288 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site