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 /lib | |
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>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Kconfig | 1 | ||||
-rw-r--r-- | lib/crc32.c | 28 |
2 files changed, 6 insertions, 23 deletions
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, |