[Samba] [RESEND] crc32 optimization

Joakim Tjernlund
Tue, 27 May 2003 10:42:55 -0000

Hi Samba

I noticed that the crc32 function in lib/crc32.c is somewhat
inefficient. This little patch will reduce the inner loop from 10
instructions to 8 instructions on x86 with gcc. gcc can't figure
out this simple optimization by itself on x86.

Further optimization is possible by using the impl. in the linux 2.5 kernel, but
I don't know if it is worth it. Is crc32 common in samba? What would the
typical
buffer len be?

    Jocke

Patch against 2_2_8 CVS:
--- lib/crc32.c	Sat Oct 20 23:23:35 2001
+++ lib/crc32.c.new	Tue May 13 14:45:31 2003
@@ -60,7 +60,7 @@
         uint32 crc=0xffffffff;
 	int i;
         for(i=0;i<count;i++)
-                crc = (crc>>8) ^ CRCTable[(buffer[i] ^ crc) & 0xff];
+                crc = CRCTable[(buffer[i] ^ crc) & 0xff] ^ (crc>>8);
         crc^=0xffffffff;
 	DEBUG(10,("crc32_calc_buffer: %x\n", crc));
 	dump_data(100, buffer, count);