diff options
author | Akinobu Mita <akinobu.mita@gmail.com> | 2006-12-08 05:36:25 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.osdl.org> | 2006-12-08 11:28:39 -0500 |
commit | 906d66df18faa4aac8d898ae6920d1014694a932 (patch) | |
tree | df91905b3c79b7af39091e82655088ad5057379e | |
parent | a5cfc1ec58a07074dacb6aa8c79eff864c966d12 (diff) |
[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: Akinobu Mita <akinobu.mita@gmail.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r-- | drivers/net/via-velocity.c | 2 | ||||
-rw-r--r-- | include/linux/crc32.h | 4 | ||||
-rw-r--r-- | lib/Kconfig | 1 | ||||
-rw-r--r-- | lib/crc32.c | 28 |
4 files changed, 9 insertions, 26 deletions
diff --git a/drivers/net/via-velocity.c b/drivers/net/via-velocity.c index 74f894795a1b..4587f23f4e4b 100644 --- a/drivers/net/via-velocity.c +++ b/drivers/net/via-velocity.c | |||
@@ -3132,7 +3132,7 @@ static u16 wol_calc_crc(int size, u8 * pattern, u8 *mask_pattern) | |||
3132 | } | 3132 | } |
3133 | /* Finally, invert the result once to get the correct data */ | 3133 | /* Finally, invert the result once to get the correct data */ |
3134 | crc = ~crc; | 3134 | crc = ~crc; |
3135 | return bitreverse(crc) >> 16; | 3135 | return bitrev32(crc) >> 16; |
3136 | } | 3136 | } |
3137 | 3137 | ||
3138 | /** | 3138 | /** |
diff --git a/include/linux/crc32.h b/include/linux/crc32.h index 56c0645789a9..e20dd1f9b40a 100644 --- a/include/linux/crc32.h +++ b/include/linux/crc32.h | |||
@@ -6,10 +6,10 @@ | |||
6 | #define _LINUX_CRC32_H | 6 | #define _LINUX_CRC32_H |
7 | 7 | ||
8 | #include <linux/types.h> | 8 | #include <linux/types.h> |
9 | #include <linux/bitrev.h> | ||
9 | 10 | ||
10 | extern u32 crc32_le(u32 crc, unsigned char const *p, size_t len); | 11 | extern u32 crc32_le(u32 crc, unsigned char const *p, size_t len); |
11 | extern u32 crc32_be(u32 crc, unsigned char const *p, size_t len); | 12 | extern u32 crc32_be(u32 crc, unsigned char const *p, size_t len); |
12 | extern u32 bitreverse(u32 in); | ||
13 | 13 | ||
14 | #define crc32(seed, data, length) crc32_le(seed, (unsigned char const *)data, length) | 14 | #define crc32(seed, data, length) crc32_le(seed, (unsigned char const *)data, length) |
15 | 15 | ||
@@ -21,7 +21,7 @@ extern u32 bitreverse(u32 in); | |||
21 | * is in bit nr 0], thus it must be reversed before use. Except for | 21 | * is in bit nr 0], thus it must be reversed before use. Except for |
22 | * nics that bit swap the result internally... | 22 | * nics that bit swap the result internally... |
23 | */ | 23 | */ |
24 | #define ether_crc(length, data) bitreverse(crc32_le(~0, data, length)) | 24 | #define ether_crc(length, data) bitrev32(crc32_le(~0, data, length)) |
25 | #define ether_crc_le(length, data) crc32_le(~0, data, length) | 25 | #define ether_crc_le(length, data) crc32_le(~0, data, length) |
26 | 26 | ||
27 | #endif /* _LINUX_CRC32_H */ | 27 | #endif /* _LINUX_CRC32_H */ |
diff --git a/lib/Kconfig b/lib/Kconfig index 0d683559080e..47b172df3e31 100644 --- a/lib/Kconfig +++ b/lib/Kconfig | |||
@@ -26,6 +26,7 @@ config CRC16 | |||
26 | config CRC32 | 26 | config CRC32 |
27 | tristate "CRC32 functions" | 27 | tristate "CRC32 functions" |
28 | default y | 28 | default y |
29 | select BITREVERSE | ||
29 | help | 30 | help |
30 | This option is provided for the case where no in-kernel-tree | 31 | This option is provided for the case where no in-kernel-tree |
31 | modules require CRC32 functions, but a module built outside the | 32 | modules require CRC32 functions, but a module built outside the |
diff --git a/lib/crc32.c b/lib/crc32.c index 285fd9bc61be..bfc33314c720 100644 --- a/lib/crc32.c +++ b/lib/crc32.c | |||
@@ -235,23 +235,8 @@ u32 __attribute_pure__ crc32_be(u32 crc, unsigned char const *p, size_t len) | |||
235 | } | 235 | } |
236 | #endif | 236 | #endif |
237 | 237 | ||
238 | /** | ||
239 | * bitreverse - reverse the order of bits in a u32 value | ||
240 | * @x: value to be bit-reversed | ||
241 | */ | ||
242 | u32 bitreverse(u32 x) | ||
243 | { | ||
244 | x = (x >> 16) | (x << 16); | ||
245 | x = (x >> 8 & 0x00ff00ff) | (x << 8 & 0xff00ff00); | ||
246 | x = (x >> 4 & 0x0f0f0f0f) | (x << 4 & 0xf0f0f0f0); | ||
247 | x = (x >> 2 & 0x33333333) | (x << 2 & 0xcccccccc); | ||
248 | x = (x >> 1 & 0x55555555) | (x << 1 & 0xaaaaaaaa); | ||
249 | return x; | ||
250 | } | ||
251 | |||
252 | EXPORT_SYMBOL(crc32_le); | 238 | EXPORT_SYMBOL(crc32_le); |
253 | EXPORT_SYMBOL(crc32_be); | 239 | EXPORT_SYMBOL(crc32_be); |
254 | EXPORT_SYMBOL(bitreverse); | ||
255 | 240 | ||
256 | /* | 241 | /* |
257 | * A brief CRC tutorial. | 242 | * A brief CRC tutorial. |
@@ -400,10 +385,7 @@ buf_dump(char const *prefix, unsigned char const *buf, size_t len) | |||
400 | static void bytereverse(unsigned char *buf, size_t len) | 385 | static void bytereverse(unsigned char *buf, size_t len) |
401 | { | 386 | { |
402 | while (len--) { | 387 | while (len--) { |
403 | unsigned char x = *buf; | 388 | unsigned char x = bitrev8(*buf); |
404 | x = (x >> 4) | (x << 4); | ||
405 | x = (x >> 2 & 0x33) | (x << 2 & 0xcc); | ||
406 | x = (x >> 1 & 0x55) | (x << 1 & 0xaa); | ||
407 | *buf++ = x; | 389 | *buf++ = x; |
408 | } | 390 | } |
409 | } | 391 | } |
@@ -460,11 +442,11 @@ static u32 test_step(u32 init, unsigned char *buf, size_t len) | |||
460 | /* Now swap it around for the other test */ | 442 | /* Now swap it around for the other test */ |
461 | 443 | ||
462 | bytereverse(buf, len + 4); | 444 | bytereverse(buf, len + 4); |
463 | init = bitreverse(init); | 445 | init = bitrev32(init); |
464 | crc2 = bitreverse(crc1); | 446 | crc2 = bitrev32(crc1); |
465 | if (crc1 != bitreverse(crc2)) | 447 | if (crc1 != bitrev32(crc2)) |
466 | printf("\nBit reversal fail: 0x%08x -> 0x%08x -> 0x%08x\n", | 448 | printf("\nBit reversal fail: 0x%08x -> 0x%08x -> 0x%08x\n", |
467 | crc1, crc2, bitreverse(crc2)); | 449 | crc1, crc2, bitrev32(crc2)); |
468 | crc1 = crc32_le(init, buf, len); | 450 | crc1 = crc32_le(init, buf, len); |
469 | if (crc1 != crc2) | 451 | if (crc1 != crc2) |
470 | printf("\nCRC endianness fail: 0x%08x != 0x%08x\n", crc1, | 452 | printf("\nCRC endianness fail: 0x%08x != 0x%08x\n", crc1, |