public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] bitreversal program
@ 2008-05-19 17:04 Soumyadip Das Mahapatra
  2008-05-19 20:42 ` Harvey Harrison
  0 siblings, 1 reply; 13+ messages in thread
From: Soumyadip Das Mahapatra @ 2008-05-19 17:04 UTC (permalink / raw)
  To: linux-kernel; +Cc: akinobu.mita

--- a/include/linux/bitrev.h    2008-04-17 08:19:44.000000000 +0530
+++ b/include/linux/bitrev.h    2008-05-19 21:49:46.000000000 +0530
@@ -3,11 +3,32 @@

  #include <linux/types.h>

-extern u8 const byte_rev_table[256];
+/**
+ * Here is a generalised bit reversal program
+ * @x: word to get bits reversed
+ * @k: key, explained below
+ * for k = 31, it reverses the bits of word(32 bit)
+ * for k = 24, it reverses the bytes in word
+ * for k = 7, it reverses the bits in every byte without
+ * changing the positions of bytes in a word
+ * and for k = 16 it swaps the left and right halves of a
+ * word
+ */

-static inline u8 bitrev8(u8 byte)
+static inline u32 gen_bit_rev(u32 x, u32 k)
  {
-       return byte_rev_table[byte];
+       if(k & 1)
+               x = (x & 0x55555555) << 1 | (x & 0xaaaaaaaa) >> 1;
+       if(k & 2)
+               x = (x & 0x33333333) << 2 | (x & 0xcccccccc) >> 2;
+       if(k & 4)
+               x = (x & 0x0f0f0f0f) << 4 | (x & 0xf0f0f0f0) >> 4;
+       if(k & 8)
+               x = (x & 0x00ff00ff) << 8 | (x & 0xff00ff00) >> 8;
+       if(k & 16)
+               x = (x & 0x0000ffff) << 16 | (x & 0xffff0000) >> 16;
+
+       return x;
  }

  extern u32 bitrev32(u32 in);

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2008-05-21 16:52 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-19 17:04 [PATCH 1/2] bitreversal program Soumyadip Das Mahapatra
2008-05-19 20:42 ` Harvey Harrison
2008-05-20  6:53   ` John Hubbard
2008-05-20 11:01   ` Soumyadip Das Mahapatra
2008-05-20 12:13     ` Akinobu Mita
2008-05-20 15:25       ` Soumyadip Das Mahapatra
2008-05-20 15:47         ` Benoit Boissinot
2008-05-20 15:57           ` Soumyadip Das Mahapatra
2008-05-20 16:39             ` Benoit Boissinot
2008-05-21  8:54               ` Soumyadip Das Mahapatra
2008-05-21  9:11                 ` Benoit Boissinot
2008-05-21 11:11                 ` Rene Herman
2008-05-21 16:52         ` Tilman Schmidt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox