* [PATCH] crc32 improvements for 2.5
[not found] <1044365707.4067.4.camel@passion.cambridge.redhat.com>
@ 2003-02-05 16:23 ` Joakim Tjernlund
2003-02-13 11:13 ` [PATCH] crc32 improvements for 2.5 [RESEND] Joakim Tjernlund
2003-02-18 9:28 ` [PATCH] crc32 improvements for 2.5, more optimizations Joakim Tjernlund
2 siblings, 0 replies; 5+ messages in thread
From: Joakim Tjernlund @ 2003-02-05 16:23 UTC (permalink / raw)
To: torvalds, alan; +Cc: linux-kernel
Hi
I did the optimizations in the crc32 patch Brian Murphy submitted a while ago.
Now I have cleaned it up a little and made some more optimizations.
gcc is quite bad at loop optimizations (at least for PPC) so I have
rewritten them to make gcc to generate better code. Even recent gcc's(3.2.x) produces
better code.
Also reduced the unrolling since it did not make a noticeable difference.
Joakim Tjernlund
--- lib/crc32.c.org Thu Jan 9 00:19:02 2003
+++ lib/crc32.c Tue Feb 4 19:05:01 2003
@@ -87,55 +87,51 @@
{
# if CRC_LE_BITS == 8
const u32 *b =(u32 *)p;
- const u32 *e;
- /* load data 32 bits wide, xor data 32 bits wide. */
+ const u32 *tab = crc32table_le;
- crc = __cpu_to_le32(crc);
- /* Align it */
- for ( ; ((long)b)&3 && len ; len--){
-# ifdef __LITTLE_ENDIAN
- crc = (crc>>8) ^ crc32table_le[ (crc ^ *((u8 *)b)++) & 0xff ];
-# else
- crc = (crc<<8) ^ crc32table_le[ crc>>24 ^ *((u8 *)b)++ ];
-# endif
- }
- e = (u32 *) ( (u8 *)b + (len & ~7));
- while (b < e) {
- crc ^= *b++;
-# ifdef __LITTLE_ENDIAN
- crc = (crc>>8) ^ crc32table_le[ crc & 0xff ];
- crc = (crc>>8) ^ crc32table_le[ crc & 0xff ];
- crc = (crc>>8) ^ crc32table_le[ crc & 0xff ];
- crc = (crc>>8) ^ crc32table_le[ crc & 0xff ];
-# else
- crc = (crc<<8) ^ crc32table_le[ crc >> 24 ];
- crc = (crc<<8) ^ crc32table_le[ crc >> 24 ];
- crc = (crc<<8) ^ crc32table_le[ crc >> 24 ];
- crc = (crc<<8) ^ crc32table_le[ crc >> 24 ];
-# endif
- crc ^= *b++;
# ifdef __LITTLE_ENDIAN
- crc = (crc>>8) ^ crc32table_le[ crc & 0xff ];
- crc = (crc>>8) ^ crc32table_le[ crc & 0xff ];
- crc = (crc>>8) ^ crc32table_le[ crc & 0xff ];
- crc = (crc>>8) ^ crc32table_le[ crc & 0xff ];
+# define DO_CRC crc = (crc>>8) ^ tab[ crc & 255 ]
+# define ENDIAN_SHIFT 0
# else
- crc = (crc<<8) ^ crc32table_le[ crc >> 24 ];
- crc = (crc<<8) ^ crc32table_le[ crc >> 24 ];
- crc = (crc<<8) ^ crc32table_le[ crc >> 24 ];
- crc = (crc<<8) ^ crc32table_le[ crc >> 24 ];
+# define DO_CRC crc = (crc<<8) ^ tab[ crc >> 24 ]
+# define ENDIAN_SHIFT 24
# endif
+
+ crc = __cpu_to_le32(crc);
+ /* Align it */
+ if(unlikely(((long)b)&3 && len)){
+ do {
+ crc ^= *((u8 *)b)++ << ENDIAN_SHIFT;
+ DO_CRC;
+ } while ((--len) && ((long)b)&3 );
+ }
+ if(likely(len >= 4)){
+ /* load data 32 bits wide, xor data 32 bits wide. */
+ size_t save_len = len & 3;
+ len = len >> 2;
+ --b; /* use pre increment below(*++b) for speed */
+ do {
+ crc ^= *++b;
+ DO_CRC;
+ DO_CRC;
+ DO_CRC;
+ DO_CRC;
+ } while (--len);
+ b++; /* point to next byte(s) */
+ len = save_len;
}
/* And the last few bytes */
- e = (u32 *)((u8 *)b + (len & 7));
- while (b < e){
-# ifdef __LITTLE_ENDIAN
- crc = (crc>>8) ^ crc32table_le[ (crc ^ *((u8 *)b)++) & 0xff ];
-# else
- crc = (crc<<8) ^ crc32table_le[ crc>>24 ^ *((u8 *)b)++ ];
-# endif
+ if(len){
+ do {
+ crc ^= *((u8 *)b)++ << ENDIAN_SHIFT;
+ DO_CRC;
+ } while (--len);
}
- return __le32_to_cpu(crc) ;
+
+ return __le32_to_cpu(crc);
+#undef ENDIAN_SHIFT
+#undef DO_CRC
+
# elif CRC_LE_BITS == 4
while (len--) {
crc ^= *p++;
@@ -196,55 +192,50 @@
{
# if CRC_BE_BITS == 8
const u32 *b =(u32 *)p;
- const u32 *e;
- /* load data 32 bits wide, xor data 32 bits wide. */
+ const u32 *tab = crc32table_be;
- crc = __cpu_to_be32(crc);
- /* Align it */
- for ( ; ((long)b)&3 && len ; len--){
-# ifdef __LITTLE_ENDIAN
- crc = (crc>>8) ^ crc32table_be[ (crc ^ *((u8 *)b)++) & 0xff ];
-# else
- crc = (crc<<8) ^ crc32table_be[ crc>>24 ^ *((u8 *)b)++ ];
-# endif
- }
- e = (u32 *) ( (u8 *)b + (len & ~7));
- while (b < e) {
- crc ^= *b++;
-# ifdef __LITTLE_ENDIAN
- crc = (crc>>8) ^ crc32table_be[ crc & 0xff ];
- crc = (crc>>8) ^ crc32table_be[ crc & 0xff ];
- crc = (crc>>8) ^ crc32table_be[ crc & 0xff ];
- crc = (crc>>8) ^ crc32table_be[ crc & 0xff ];
-# else
- crc = (crc<<8) ^ crc32table_be[ crc >> 24 ];
- crc = (crc<<8) ^ crc32table_be[ crc >> 24 ];
- crc = (crc<<8) ^ crc32table_be[ crc >> 24 ];
- crc = (crc<<8) ^ crc32table_be[ crc >> 24 ];
-# endif
- crc ^= *b++;
# ifdef __LITTLE_ENDIAN
- crc = (crc>>8) ^ crc32table_be[ crc & 0xff ];
- crc = (crc>>8) ^ crc32table_be[ crc & 0xff ];
- crc = (crc>>8) ^ crc32table_be[ crc & 0xff ];
- crc = (crc>>8) ^ crc32table_be[ crc & 0xff ];
+# define DO_CRC crc = (crc>>8) ^ tab[ crc & 255 ]
+# define ENDIAN_SHIFT 24
# else
- crc = (crc<<8) ^ crc32table_be[ crc >> 24 ];
- crc = (crc<<8) ^ crc32table_be[ crc >> 24 ];
- crc = (crc<<8) ^ crc32table_be[ crc >> 24 ];
- crc = (crc<<8) ^ crc32table_be[ crc >> 24 ];
+# define DO_CRC crc = (crc<<8) ^ tab[ crc >> 24 ]
+# define ENDIAN_SHIFT 0
# endif
+
+ crc = __cpu_to_be32(crc);
+ /* Align it */
+ if(unlikely(((long)b)&3 && len)){
+ do {
+ crc ^= *((u8 *)b)++ << ENDIAN_SHIFT;
+ DO_CRC;
+ } while ((--len) && ((long)b)&3 );
+ }
+ if(likely(len >= 4)){
+ /* load data 32 bits wide, xor data 32 bits wide. */
+ size_t save_len = len & 3;
+ len = len >> 2;
+ --b; /* use pre increment below(*++b) for speed */
+ do {
+ crc ^= *++b;
+ DO_CRC;
+ DO_CRC;
+ DO_CRC;
+ DO_CRC;
+ } while (--len);
+ b++; /* point to next byte(s) */
+ len = save_len;
}
/* And the last few bytes */
- e = (u32 *)((u8 *)b + (len & 7));
- while (b < e){
-# ifdef __LITTLE_ENDIAN
- crc = (crc>>8) ^ crc32table_be[ (crc ^ *((u8 *)b)++) & 0xff ];
-# else
- crc = (crc<<8) ^ crc32table_be[ crc>>24 ^ *((u8 *)b)++ ];
-# endif
- }
- return __be32_to_cpu(crc) ;
+ if(len){
+ do {
+ crc ^= *((u8 *)b)++ << ENDIAN_SHIFT;
+ DO_CRC;
+ } while (--len);
+ }
+ return __be32_to_cpu(crc);
+#undef ENDIAN_SHIFT
+#undef DO_CRC
+
# elif CRC_BE_BITS == 4
while (len--) {
crc ^= *p++ << 24;
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH] crc32 improvements for 2.5 [RESEND]
[not found] <1044365707.4067.4.camel@passion.cambridge.redhat.com>
2003-02-05 16:23 ` [PATCH] crc32 improvements for 2.5 Joakim Tjernlund
@ 2003-02-13 11:13 ` Joakim Tjernlund
2003-02-13 17:54 ` Andrew Morton
2003-02-18 9:28 ` [PATCH] crc32 improvements for 2.5, more optimizations Joakim Tjernlund
2 siblings, 1 reply; 5+ messages in thread
From: Joakim Tjernlund @ 2003-02-13 11:13 UTC (permalink / raw)
To: torvalds; +Cc: linux-kernel
[This is a resend, feedback welcome]
Hi
I did the optimizations in the crc32 patch Brian Murphy submitted a while ago.
Now I have cleaned it up a little and made some more optimizations.
gcc is quite bad at loop optimizations (at least for PPC) so I have
rewritten them to make gcc to generate better code. Even recent gcc's(3.2.x) produces
better code.
Also reduced the unrolling since it did not make a noticeable difference.
Joakim Tjernlund
--- lib/crc32.c.org Thu Jan 9 00:19:02 2003
+++ lib/crc32.c Tue Feb 4 19:05:01 2003
@@ -87,55 +87,51 @@
{
# if CRC_LE_BITS == 8
const u32 *b =(u32 *)p;
- const u32 *e;
- /* load data 32 bits wide, xor data 32 bits wide. */
+ const u32 *tab = crc32table_le;
- crc = __cpu_to_le32(crc);
- /* Align it */
- for ( ; ((long)b)&3 && len ; len--){
-# ifdef __LITTLE_ENDIAN
- crc = (crc>>8) ^ crc32table_le[ (crc ^ *((u8 *)b)++) & 0xff ];
-# else
- crc = (crc<<8) ^ crc32table_le[ crc>>24 ^ *((u8 *)b)++ ];
-# endif
- }
- e = (u32 *) ( (u8 *)b + (len & ~7));
- while (b < e) {
- crc ^= *b++;
-# ifdef __LITTLE_ENDIAN
- crc = (crc>>8) ^ crc32table_le[ crc & 0xff ];
- crc = (crc>>8) ^ crc32table_le[ crc & 0xff ];
- crc = (crc>>8) ^ crc32table_le[ crc & 0xff ];
- crc = (crc>>8) ^ crc32table_le[ crc & 0xff ];
-# else
- crc = (crc<<8) ^ crc32table_le[ crc >> 24 ];
- crc = (crc<<8) ^ crc32table_le[ crc >> 24 ];
- crc = (crc<<8) ^ crc32table_le[ crc >> 24 ];
- crc = (crc<<8) ^ crc32table_le[ crc >> 24 ];
-# endif
- crc ^= *b++;
# ifdef __LITTLE_ENDIAN
- crc = (crc>>8) ^ crc32table_le[ crc & 0xff ];
- crc = (crc>>8) ^ crc32table_le[ crc & 0xff ];
- crc = (crc>>8) ^ crc32table_le[ crc & 0xff ];
- crc = (crc>>8) ^ crc32table_le[ crc & 0xff ];
+# define DO_CRC crc = (crc>>8) ^ tab[ crc & 255 ]
+# define ENDIAN_SHIFT 0
# else
- crc = (crc<<8) ^ crc32table_le[ crc >> 24 ];
- crc = (crc<<8) ^ crc32table_le[ crc >> 24 ];
- crc = (crc<<8) ^ crc32table_le[ crc >> 24 ];
- crc = (crc<<8) ^ crc32table_le[ crc >> 24 ];
+# define DO_CRC crc = (crc<<8) ^ tab[ crc >> 24 ]
+# define ENDIAN_SHIFT 24
# endif
+
+ crc = __cpu_to_le32(crc);
+ /* Align it */
+ if(unlikely(((long)b)&3 && len)){
+ do {
+ crc ^= *((u8 *)b)++ << ENDIAN_SHIFT;
+ DO_CRC;
+ } while ((--len) && ((long)b)&3 );
+ }
+ if(likely(len >= 4)){
+ /* load data 32 bits wide, xor data 32 bits wide. */
+ size_t save_len = len & 3;
+ len = len >> 2;
+ --b; /* use pre increment below(*++b) for speed */
+ do {
+ crc ^= *++b;
+ DO_CRC;
+ DO_CRC;
+ DO_CRC;
+ DO_CRC;
+ } while (--len);
+ b++; /* point to next byte(s) */
+ len = save_len;
}
/* And the last few bytes */
- e = (u32 *)((u8 *)b + (len & 7));
- while (b < e){
-# ifdef __LITTLE_ENDIAN
- crc = (crc>>8) ^ crc32table_le[ (crc ^ *((u8 *)b)++) & 0xff ];
-# else
- crc = (crc<<8) ^ crc32table_le[ crc>>24 ^ *((u8 *)b)++ ];
-# endif
+ if(len){
+ do {
+ crc ^= *((u8 *)b)++ << ENDIAN_SHIFT;
+ DO_CRC;
+ } while (--len);
}
- return __le32_to_cpu(crc) ;
+
+ return __le32_to_cpu(crc);
+#undef ENDIAN_SHIFT
+#undef DO_CRC
+
# elif CRC_LE_BITS == 4
while (len--) {
crc ^= *p++;
@@ -196,55 +192,50 @@
{
# if CRC_BE_BITS == 8
const u32 *b =(u32 *)p;
- const u32 *e;
- /* load data 32 bits wide, xor data 32 bits wide. */
+ const u32 *tab = crc32table_be;
- crc = __cpu_to_be32(crc);
- /* Align it */
- for ( ; ((long)b)&3 && len ; len--){
-# ifdef __LITTLE_ENDIAN
- crc = (crc>>8) ^ crc32table_be[ (crc ^ *((u8 *)b)++) & 0xff ];
-# else
- crc = (crc<<8) ^ crc32table_be[ crc>>24 ^ *((u8 *)b)++ ];
-# endif
- }
- e = (u32 *) ( (u8 *)b + (len & ~7));
- while (b < e) {
- crc ^= *b++;
-# ifdef __LITTLE_ENDIAN
- crc = (crc>>8) ^ crc32table_be[ crc & 0xff ];
- crc = (crc>>8) ^ crc32table_be[ crc & 0xff ];
- crc = (crc>>8) ^ crc32table_be[ crc & 0xff ];
- crc = (crc>>8) ^ crc32table_be[ crc & 0xff ];
-# else
- crc = (crc<<8) ^ crc32table_be[ crc >> 24 ];
- crc = (crc<<8) ^ crc32table_be[ crc >> 24 ];
- crc = (crc<<8) ^ crc32table_be[ crc >> 24 ];
- crc = (crc<<8) ^ crc32table_be[ crc >> 24 ];
-# endif
- crc ^= *b++;
# ifdef __LITTLE_ENDIAN
- crc = (crc>>8) ^ crc32table_be[ crc & 0xff ];
- crc = (crc>>8) ^ crc32table_be[ crc & 0xff ];
- crc = (crc>>8) ^ crc32table_be[ crc & 0xff ];
- crc = (crc>>8) ^ crc32table_be[ crc & 0xff ];
+# define DO_CRC crc = (crc>>8) ^ tab[ crc & 255 ]
+# define ENDIAN_SHIFT 24
# else
- crc = (crc<<8) ^ crc32table_be[ crc >> 24 ];
- crc = (crc<<8) ^ crc32table_be[ crc >> 24 ];
- crc = (crc<<8) ^ crc32table_be[ crc >> 24 ];
- crc = (crc<<8) ^ crc32table_be[ crc >> 24 ];
+# define DO_CRC crc = (crc<<8) ^ tab[ crc >> 24 ]
+# define ENDIAN_SHIFT 0
# endif
+
+ crc = __cpu_to_be32(crc);
+ /* Align it */
+ if(unlikely(((long)b)&3 && len)){
+ do {
+ crc ^= *((u8 *)b)++ << ENDIAN_SHIFT;
+ DO_CRC;
+ } while ((--len) && ((long)b)&3 );
+ }
+ if(likely(len >= 4)){
+ /* load data 32 bits wide, xor data 32 bits wide. */
+ size_t save_len = len & 3;
+ len = len >> 2;
+ --b; /* use pre increment below(*++b) for speed */
+ do {
+ crc ^= *++b;
+ DO_CRC;
+ DO_CRC;
+ DO_CRC;
+ DO_CRC;
+ } while (--len);
+ b++; /* point to next byte(s) */
+ len = save_len;
}
/* And the last few bytes */
- e = (u32 *)((u8 *)b + (len & 7));
- while (b < e){
-# ifdef __LITTLE_ENDIAN
- crc = (crc>>8) ^ crc32table_be[ (crc ^ *((u8 *)b)++) & 0xff ];
-# else
- crc = (crc<<8) ^ crc32table_be[ crc>>24 ^ *((u8 *)b)++ ];
-# endif
- }
- return __be32_to_cpu(crc) ;
+ if(len){
+ do {
+ crc ^= *((u8 *)b)++ << ENDIAN_SHIFT;
+ DO_CRC;
+ } while (--len);
+ }
+ return __be32_to_cpu(crc);
+#undef ENDIAN_SHIFT
+#undef DO_CRC
+
# elif CRC_BE_BITS == 4
while (len--) {
crc ^= *p++ << 24;
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] crc32 improvements for 2.5 [RESEND]
2003-02-13 11:13 ` [PATCH] crc32 improvements for 2.5 [RESEND] Joakim Tjernlund
@ 2003-02-13 17:54 ` Andrew Morton
2003-02-13 21:45 ` Joakim Tjernlund
0 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2003-02-13 17:54 UTC (permalink / raw)
To: joakim.tjernlund; +Cc: torvalds, linux-kernel
Joakim Tjernlund <joakim.tjernlund@lumentis.se> wrote:
>
> I did the optimizations in the crc32 patch Brian Murphy submitted a while ago.
> Now I have cleaned it up a little and made some more optimizations.
I added this to -mm, but I don't know how to test it ;)
What testing have you performed? And have you any benchmark results?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] crc32 improvements for 2.5 [RESEND]
2003-02-13 17:54 ` Andrew Morton
@ 2003-02-13 21:45 ` Joakim Tjernlund
0 siblings, 0 replies; 5+ messages in thread
From: Joakim Tjernlund @ 2003-02-13 21:45 UTC (permalink / raw)
To: Andrew Morton; +Cc: torvalds, linux-kernel
From: "Andrew Morton" <akpm@digeo.com>
> Joakim Tjernlund <joakim.tjernlund@lumentis.se> wrote:
> >
> > I did the optimizations in the crc32 patch Brian Murphy submitted a while ago.
> > Now I have cleaned it up a little and made some more optimizations.
>
> I added this to -mm, but I don't know how to test it ;)
>
> What testing have you performed? And have you any benchmark results?
I have tested this extensivly using JFFS2 on PPC. I belive David Woodhouse
has done the same on X86.
I don't have any benchmarks, I used the JFFS2 mounting process which
crc32 checks all data and metadata in the FS and timed that.
There are some ethernet drivers that uses crc32 as well.
Jocke
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] crc32 improvements for 2.5, more optimizations
[not found] <1044365707.4067.4.camel@passion.cambridge.redhat.com>
2003-02-05 16:23 ` [PATCH] crc32 improvements for 2.5 Joakim Tjernlund
2003-02-13 11:13 ` [PATCH] crc32 improvements for 2.5 [RESEND] Joakim Tjernlund
@ 2003-02-18 9:28 ` Joakim Tjernlund
2 siblings, 0 replies; 5+ messages in thread
From: Joakim Tjernlund @ 2003-02-18 9:28 UTC (permalink / raw)
To: torvalds, Andrew Morton, David Woodhouse; +Cc: linux-kernel
Hi
Here is another update(against BK curr) for crc32(). A kind soul pointed out
the optimizations below.
lib/crc32defs.h:
- Make it possible to define new values for CRC_LE_BITS/CRC_BE_BITS without
modifying the source.
lib/crc32.c:
- Eliminate the need for ENDIAN_SHIFT. Saves a 24 bit shift in the byte
loops.
- Swap the XOR expression in DO_CRC. gcc for x86 can not do that simple
optimization itself(gcc 3.2.2 and RH gcc 2.96 tested). Will improve
performance with 20-25% on x86.
Joakim Tjernlund
--- lib/crc32defs.h Wed Jan 8 01:35:35 2003
+++ lib/new.crc32defs.h Tue Feb 18 09:38:08 2003
@@ -8,8 +8,12 @@
/* How many bits at a time to use. Requires a table of 4<<CRC_xx_BITS bytes. */
/* For less performance-sensitive, use 4 */
-#define CRC_LE_BITS 8
-#define CRC_BE_BITS 8
+#ifndef CRC_LE_BITS
+# define CRC_LE_BITS 8
+#endif
+#ifndef CRC_BE_BITS
+# define CRC_BE_BITS 8
+#endif
/*
* Little-endian CRC computation. Used with serial bit streams sent
--- lib/crc32.c Tue Feb 18 09:29:46 2003
+++ lib/new.crc32.c Tue Feb 18 09:43:15 2003
@@ -90,19 +90,16 @@
const u32 *tab = crc32table_le;
# ifdef __LITTLE_ENDIAN
-# define DO_CRC crc = (crc>>8) ^ tab[ crc & 255 ]
-# define ENDIAN_SHIFT 0
+# define DO_CRC(x) crc = tab[ (crc ^ (x)) & 255 ] ^ (crc>>8)
# else
-# define DO_CRC crc = (crc<<8) ^ tab[ crc >> 24 ]
-# define ENDIAN_SHIFT 24
+# define DO_CRC(x) crc = tab[ ((crc >> 24) ^ (x)) & 255] ^ (crc<<8)
# endif
crc = __cpu_to_le32(crc);
/* Align it */
if(unlikely(((long)b)&3 && len)){
do {
- crc ^= *((u8 *)b)++ << ENDIAN_SHIFT;
- DO_CRC;
+ DO_CRC(*((u8 *)b)++);
} while ((--len) && ((long)b)&3 );
}
if(likely(len >= 4)){
@@ -112,10 +109,10 @@
--b; /* use pre increment below(*++b) for speed */
do {
crc ^= *++b;
- DO_CRC;
- DO_CRC;
- DO_CRC;
- DO_CRC;
+ DO_CRC(0);
+ DO_CRC(0);
+ DO_CRC(0);
+ DO_CRC(0);
} while (--len);
b++; /* point to next byte(s) */
len = save_len;
@@ -123,8 +120,7 @@
/* And the last few bytes */
if(len){
do {
- crc ^= *((u8 *)b)++ << ENDIAN_SHIFT;
- DO_CRC;
+ DO_CRC(*((u8 *)b)++);
} while (--len);
}
@@ -195,19 +191,16 @@
const u32 *tab = crc32table_be;
# ifdef __LITTLE_ENDIAN
-# define DO_CRC crc = (crc>>8) ^ tab[ crc & 255 ]
-# define ENDIAN_SHIFT 24
+# define DO_CRC(x) crc = tab[ (crc ^ (x)) & 255 ] ^ (crc>>8)
# else
-# define DO_CRC crc = (crc<<8) ^ tab[ crc >> 24 ]
-# define ENDIAN_SHIFT 0
+# define DO_CRC(x) crc = tab[ ((crc >> 24) ^ (x)) & 255] ^ (crc<<8)
# endif
crc = __cpu_to_be32(crc);
/* Align it */
if(unlikely(((long)b)&3 && len)){
do {
- crc ^= *((u8 *)b)++ << ENDIAN_SHIFT;
- DO_CRC;
+ DO_CRC(*((u8 *)b)++);
} while ((--len) && ((long)b)&3 );
}
if(likely(len >= 4)){
@@ -217,10 +210,10 @@
--b; /* use pre increment below(*++b) for speed */
do {
crc ^= *++b;
- DO_CRC;
- DO_CRC;
- DO_CRC;
- DO_CRC;
+ DO_CRC(0);
+ DO_CRC(0);
+ DO_CRC(0);
+ DO_CRC(0);
} while (--len);
b++; /* point to next byte(s) */
len = save_len;
@@ -228,8 +221,7 @@
/* And the last few bytes */
if(len){
do {
- crc ^= *((u8 *)b)++ << ENDIAN_SHIFT;
- DO_CRC;
+ DO_CRC(*((u8 *)b)++);
} while (--len);
}
return __be32_to_cpu(crc);
^ permalink raw reply [flat|nested] 5+ messages in thread