Commit 4f2a9463d18517a9839401c3de6419ee1435875b

Authored by Joakim Tjernlund
Committed by Linus Torvalds
1 parent 5e79d96eed

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>

Showing 1 changed file with 14 additions and 16 deletions Side-by-side Diff

... ... @@ -30,12 +30,16 @@
30 30 #include <asm/atomic.h>
31 31 #include "crc32defs.h"
32 32 #if CRC_LE_BITS == 8
33   -#define tole(x) __constant_cpu_to_le32(x)
34   -#define tobe(x) __constant_cpu_to_be32(x)
  33 +# define tole(x) __constant_cpu_to_le32(x)
35 34 #else
36   -#define tole(x) (x)
37   -#define tobe(x) (x)
  35 +# define tole(x) (x)
38 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)
  42 +#endif
39 43 #include "crc32table.h"
40 44  
41 45 MODULE_AUTHOR("Matt Domsch <Matt_Domsch@dell.com>");
42 46  
43 47  
44 48  
... ... @@ -52,20 +56,19 @@
52 56 # else
53 57 # define DO_CRC(x) crc = tab[((crc >> 24) ^ (x)) & 255] ^ (crc << 8)
54 58 # endif
55   - const u32 *b = (const u32 *)buf;
  59 + const u32 *b;
56 60 size_t rem_len;
57 61  
58 62 /* Align it */
59   - if (unlikely((long)b & 3 && len)) {
60   - u8 *p = (u8 *)b;
  63 + if (unlikely((long)buf & 3 && len)) {
61 64 do {
62   - DO_CRC(*p++);
63   - } while ((--len) && ((long)p)&3);
64   - b = (u32 *)p;
  65 + DO_CRC(*buf++);
  66 + } while ((--len) && ((long)buf)&3);
65 67 }
66 68 rem_len = len & 3;
67 69 /* load data 32 bits wide, xor data 32 bits wide. */
68 70 len = len >> 2;
  71 + b = (const u32 *)buf;
69 72 for (--b; len; --len) {
70 73 crc ^= *++b; /* use pre increment for speed */
71 74 DO_CRC(0);
... ... @@ -82,6 +85,7 @@
82 85 } while (--len);
83 86 }
84 87 return crc;
  88 +#undef DO_CRC
85 89 }
86 90 #endif
87 91 /**
... ... @@ -119,9 +123,6 @@
119 123 crc = __cpu_to_le32(crc);
120 124 crc = crc32_body(crc, p, len, tab);
121 125 return __le32_to_cpu(crc);
122   -#undef ENDIAN_SHIFT
123   -#undef DO_CRC
124   -
125 126 # elif CRC_LE_BITS == 4
126 127 while (len--) {
127 128 crc ^= *p++;
... ... @@ -179,9 +180,6 @@
179 180 crc = __cpu_to_be32(crc);
180 181 crc = crc32_body(crc, p, len, tab);
181 182 return __be32_to_cpu(crc);
182   -#undef ENDIAN_SHIFT
183   -#undef DO_CRC
184   -
185 183 # elif CRC_BE_BITS == 4
186 184 while (len--) {
187 185 crc ^= *p++ << 24;