aboutsummaryrefslogtreecommitdiffstats
path: root/lib/crc32.c
diff options
context:
space:
mode:
authorJoakim Tjernlund <Joakim.Tjernlund@transmode.se>2010-03-05 16:43:55 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2010-03-06 14:26:45 -0500
commit4f2a9463d18517a9839401c3de6419ee1435875b (patch)
treefa19722c8b1a214ef269cb210f73d9c8a35e88da /lib/crc32.c
parent5e79d96eed306a8b4af67b3f35f6867edfabeebc (diff)
crc32: some minor cleanups
Signed-off-by: Joakim Tjernlund <Joakim.Tjernlund@transmode.se> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib/crc32.c')
-rw-r--r--lib/crc32.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/lib/crc32.c b/lib/crc32.c
index 02e3b31b3a79..0f45fbff34cb 100644
--- a/lib/crc32.c
+++ b/lib/crc32.c
@@ -30,11 +30,15 @@
30#include <asm/atomic.h> 30#include <asm/atomic.h>
31#include "crc32defs.h" 31#include "crc32defs.h"
32#if CRC_LE_BITS == 8 32#if CRC_LE_BITS == 8
33#define tole(x) __constant_cpu_to_le32(x) 33# define tole(x) __constant_cpu_to_le32(x)
34#define tobe(x) __constant_cpu_to_be32(x)
35#else 34#else
36#define tole(x) (x) 35# define tole(x) (x)
37#define tobe(x) (x) 36#endif
37
38#if CRC_BE_BITS == 8
39# define tobe(x) __constant_cpu_to_be32(x)
40#else
41# define tobe(x) (x)
38#endif 42#endif
39#include "crc32table.h" 43#include "crc32table.h"
40 44
@@ -52,20 +56,19 @@ crc32_body(u32 crc, unsigned char const *buf, size_t len, const u32 *tab)
52# else 56# else
53# define DO_CRC(x) crc = tab[((crc >> 24) ^ (x)) & 255] ^ (crc << 8) 57# define DO_CRC(x) crc = tab[((crc >> 24) ^ (x)) & 255] ^ (crc << 8)
54# endif 58# endif
55 const u32 *b = (const u32 *)buf; 59 const u32 *b;
56 size_t rem_len; 60 size_t rem_len;
57 61
58 /* Align it */ 62 /* Align it */
59 if (unlikely((long)b & 3 && len)) { 63 if (unlikely((long)buf & 3 && len)) {
60 u8 *p = (u8 *)b;
61 do { 64 do {
62 DO_CRC(*p++); 65 DO_CRC(*buf++);
63 } while ((--len) && ((long)p)&3); 66 } while ((--len) && ((long)buf)&3);
64 b = (u32 *)p;
65 } 67 }
66 rem_len = len & 3; 68 rem_len = len & 3;
67 /* load data 32 bits wide, xor data 32 bits wide. */ 69 /* load data 32 bits wide, xor data 32 bits wide. */
68 len = len >> 2; 70 len = len >> 2;
71 b = (const u32 *)buf;
69 for (--b; len; --len) { 72 for (--b; len; --len) {
70 crc ^= *++b; /* use pre increment for speed */ 73 crc ^= *++b; /* use pre increment for speed */
71 DO_CRC(0); 74 DO_CRC(0);
@@ -82,6 +85,7 @@ crc32_body(u32 crc, unsigned char const *buf, size_t len, const u32 *tab)
82 } while (--len); 85 } while (--len);
83 } 86 }
84 return crc; 87 return crc;
88#undef DO_CRC
85} 89}
86#endif 90#endif
87/** 91/**
@@ -119,9 +123,6 @@ u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len)
119 crc = __cpu_to_le32(crc); 123 crc = __cpu_to_le32(crc);
120 crc = crc32_body(crc, p, len, tab); 124 crc = crc32_body(crc, p, len, tab);
121 return __le32_to_cpu(crc); 125 return __le32_to_cpu(crc);
122#undef ENDIAN_SHIFT
123#undef DO_CRC
124
125# elif CRC_LE_BITS == 4 126# elif CRC_LE_BITS == 4
126 while (len--) { 127 while (len--) {
127 crc ^= *p++; 128 crc ^= *p++;
@@ -179,9 +180,6 @@ u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len)
179 crc = __cpu_to_be32(crc); 180 crc = __cpu_to_be32(crc);
180 crc = crc32_body(crc, p, len, tab); 181 crc = crc32_body(crc, p, len, tab);
181 return __be32_to_cpu(crc); 182 return __be32_to_cpu(crc);
182#undef ENDIAN_SHIFT
183#undef DO_CRC
184
185# elif CRC_BE_BITS == 4 183# elif CRC_BE_BITS == 4
186 while (len--) { 184 while (len--) {
187 crc ^= *p++ << 24; 185 crc ^= *p++ << 24;