提交 906d66df 编写于 作者: A Akinobu Mita 提交者: Linus Torvalds

[PATCH] crc32: replace bitreverse by bitrev32

This patch replaces bitreverse() by bitrev32.  The only users of bitreverse()
are crc32 itself and via-velocity.

Cc: Jeff Garzik <jgarzik@pobox.com>
Cc: Matt Domsch <Matt_Domsch@dell.com>
Signed-off-by: NAkinobu Mita <akinobu.mita@gmail.com>
Signed-off-by: NAndrew Morton <akpm@osdl.org>
Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
上级 a5cfc1ec
...@@ -3132,7 +3132,7 @@ static u16 wol_calc_crc(int size, u8 * pattern, u8 *mask_pattern) ...@@ -3132,7 +3132,7 @@ static u16 wol_calc_crc(int size, u8 * pattern, u8 *mask_pattern)
} }
/* Finally, invert the result once to get the correct data */ /* Finally, invert the result once to get the correct data */
crc = ~crc; crc = ~crc;
return bitreverse(crc) >> 16; return bitrev32(crc) >> 16;
} }
/** /**
......
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
#define _LINUX_CRC32_H #define _LINUX_CRC32_H
#include <linux/types.h> #include <linux/types.h>
#include <linux/bitrev.h>
extern u32 crc32_le(u32 crc, unsigned char const *p, size_t len); extern u32 crc32_le(u32 crc, unsigned char const *p, size_t len);
extern u32 crc32_be(u32 crc, unsigned char const *p, size_t len); extern u32 crc32_be(u32 crc, unsigned char const *p, size_t len);
extern u32 bitreverse(u32 in);
#define crc32(seed, data, length) crc32_le(seed, (unsigned char const *)data, length) #define crc32(seed, data, length) crc32_le(seed, (unsigned char const *)data, length)
...@@ -21,7 +21,7 @@ extern u32 bitreverse(u32 in); ...@@ -21,7 +21,7 @@ extern u32 bitreverse(u32 in);
* is in bit nr 0], thus it must be reversed before use. Except for * is in bit nr 0], thus it must be reversed before use. Except for
* nics that bit swap the result internally... * nics that bit swap the result internally...
*/ */
#define ether_crc(length, data) bitreverse(crc32_le(~0, data, length)) #define ether_crc(length, data) bitrev32(crc32_le(~0, data, length))
#define ether_crc_le(length, data) crc32_le(~0, data, length) #define ether_crc_le(length, data) crc32_le(~0, data, length)
#endif /* _LINUX_CRC32_H */ #endif /* _LINUX_CRC32_H */
...@@ -26,6 +26,7 @@ config CRC16 ...@@ -26,6 +26,7 @@ config CRC16
config CRC32 config CRC32
tristate "CRC32 functions" tristate "CRC32 functions"
default y default y
select BITREVERSE
help help
This option is provided for the case where no in-kernel-tree This option is provided for the case where no in-kernel-tree
modules require CRC32 functions, but a module built outside the modules require CRC32 functions, but a module built outside the
......
...@@ -235,23 +235,8 @@ u32 __attribute_pure__ crc32_be(u32 crc, unsigned char const *p, size_t len) ...@@ -235,23 +235,8 @@ u32 __attribute_pure__ crc32_be(u32 crc, unsigned char const *p, size_t len)
} }
#endif #endif
/**
* bitreverse - reverse the order of bits in a u32 value
* @x: value to be bit-reversed
*/
u32 bitreverse(u32 x)
{
x = (x >> 16) | (x << 16);
x = (x >> 8 & 0x00ff00ff) | (x << 8 & 0xff00ff00);
x = (x >> 4 & 0x0f0f0f0f) | (x << 4 & 0xf0f0f0f0);
x = (x >> 2 & 0x33333333) | (x << 2 & 0xcccccccc);
x = (x >> 1 & 0x55555555) | (x << 1 & 0xaaaaaaaa);
return x;
}
EXPORT_SYMBOL(crc32_le); EXPORT_SYMBOL(crc32_le);
EXPORT_SYMBOL(crc32_be); EXPORT_SYMBOL(crc32_be);
EXPORT_SYMBOL(bitreverse);
/* /*
* A brief CRC tutorial. * A brief CRC tutorial.
...@@ -400,10 +385,7 @@ buf_dump(char const *prefix, unsigned char const *buf, size_t len) ...@@ -400,10 +385,7 @@ buf_dump(char const *prefix, unsigned char const *buf, size_t len)
static void bytereverse(unsigned char *buf, size_t len) static void bytereverse(unsigned char *buf, size_t len)
{ {
while (len--) { while (len--) {
unsigned char x = *buf; unsigned char x = bitrev8(*buf);
x = (x >> 4) | (x << 4);
x = (x >> 2 & 0x33) | (x << 2 & 0xcc);
x = (x >> 1 & 0x55) | (x << 1 & 0xaa);
*buf++ = x; *buf++ = x;
} }
} }
...@@ -460,11 +442,11 @@ static u32 test_step(u32 init, unsigned char *buf, size_t len) ...@@ -460,11 +442,11 @@ static u32 test_step(u32 init, unsigned char *buf, size_t len)
/* Now swap it around for the other test */ /* Now swap it around for the other test */
bytereverse(buf, len + 4); bytereverse(buf, len + 4);
init = bitreverse(init); init = bitrev32(init);
crc2 = bitreverse(crc1); crc2 = bitrev32(crc1);
if (crc1 != bitreverse(crc2)) if (crc1 != bitrev32(crc2))
printf("\nBit reversal fail: 0x%08x -> 0x%08x -> 0x%08x\n", printf("\nBit reversal fail: 0x%08x -> 0x%08x -> 0x%08x\n",
crc1, crc2, bitreverse(crc2)); crc1, crc2, bitrev32(crc2));
crc1 = crc32_le(init, buf, len); crc1 = crc32_le(init, buf, len);
if (crc1 != crc2) if (crc1 != crc2)
printf("\nCRC endianness fail: 0x%08x != 0x%08x\n", crc1, printf("\nCRC endianness fail: 0x%08x != 0x%08x\n", crc1,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册