Skip to content

Commit

Permalink
crc32: some minor cleanups
Browse files Browse the repository at this point in the history
Signed-off-by: Joakim Tjernlund <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
joakim-tjernlund authored and torvalds committed Mar 6, 2010
1 parent 5e79d96 commit 4f2a946
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions lib/crc32.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@
#include <asm/atomic.h>
#include "crc32defs.h"
#if CRC_LE_BITS == 8
#define tole(x) __constant_cpu_to_le32(x)
#define tobe(x) __constant_cpu_to_be32(x)
# define tole(x) __constant_cpu_to_le32(x)
#else
#define tole(x) (x)
#define tobe(x) (x)
# define tole(x) (x)
#endif

#if CRC_BE_BITS == 8
# define tobe(x) __constant_cpu_to_be32(x)
#else
# define tobe(x) (x)
#endif
#include "crc32table.h"

Expand All @@ -52,20 +56,19 @@ crc32_body(u32 crc, unsigned char const *buf, size_t len, const u32 *tab)
# else
# define DO_CRC(x) crc = tab[((crc >> 24) ^ (x)) & 255] ^ (crc << 8)
# endif
const u32 *b = (const u32 *)buf;
const u32 *b;
size_t rem_len;

/* Align it */
if (unlikely((long)b & 3 && len)) {
u8 *p = (u8 *)b;
if (unlikely((long)buf & 3 && len)) {
do {
DO_CRC(*p++);
} while ((--len) && ((long)p)&3);
b = (u32 *)p;
DO_CRC(*buf++);
} while ((--len) && ((long)buf)&3);
}
rem_len = len & 3;
/* load data 32 bits wide, xor data 32 bits wide. */
len = len >> 2;
b = (const u32 *)buf;
for (--b; len; --len) {
crc ^= *++b; /* use pre increment for speed */
DO_CRC(0);
Expand All @@ -82,6 +85,7 @@ crc32_body(u32 crc, unsigned char const *buf, size_t len, const u32 *tab)
} while (--len);
}
return crc;
#undef DO_CRC
}
#endif
/**
Expand Down Expand Up @@ -119,9 +123,6 @@ u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len)
crc = __cpu_to_le32(crc);
crc = crc32_body(crc, p, len, tab);
return __le32_to_cpu(crc);
#undef ENDIAN_SHIFT
#undef DO_CRC

# elif CRC_LE_BITS == 4
while (len--) {
crc ^= *p++;
Expand Down Expand Up @@ -179,9 +180,6 @@ u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len)
crc = __cpu_to_be32(crc);
crc = crc32_body(crc, p, len, tab);
return __be32_to_cpu(crc);
#undef ENDIAN_SHIFT
#undef DO_CRC

# elif CRC_BE_BITS == 4
while (len--) {
crc ^= *p++ << 24;
Expand Down

0 comments on commit 4f2a946

Please sign in to comment.