[Zlib-devel] [PATCH 07/13] Add preprocessor define to tune crc32 unrolling.

Jim Kukunas james.t.kukunas at linux.intel.com
Mon Nov 25 17:21:43 EST 2013


Adds a preprocessor define, CRC32_UNROLL_LESS, to reduce unrolling
factor from 8 to 4 for the crc32 calculation.

Updates configure script to set as default on x86
---
 configure |    8 ++++----
 crc32.c   |   14 ++++++++++++++
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/configure b/configure
index 2766df0..640d789 100755
--- a/configure
+++ b/configure
@@ -752,8 +752,8 @@ case "${ARCH}" in
         CFLAGS="${CFLAGS} -DUNALIGNED_OK -D_REENTRANT"
         SFLAGS="${SFLAGS} -DUNALIGNED_OK -D_REENTRANT"
 
-        CFLAGS="${CFLAGS} -DADLER32_UNROLL_LESS"
-        SFLAGS="${SFLAGS} -DADLER32_UNROLL_LESS"
+        CFLAGS="${CFLAGS} -DADLER32_UNROLL_LESS -DCRC32_UNROLL_LESS"
+        SFLAGS="${SFLAGS} -DADLER32_UNROLL_LESS -DCRC32_UNROLL_LESS"
     ;;
     i386 | i486 | i586 | i686)
         OBJC="${OBJC} x86.o"
@@ -762,8 +762,8 @@ case "${ARCH}" in
         CFLAGS="${CFLAGS} -DUNALIGNED_OK -D_REENTRANT"
         SFLAGS="${SFLAGS} -DUNALIGNED_OK -D_REENTRANT"
 
-        CFLAGS="${CFLAGS} -DADLER32_UNROLL_LESS"
-        SFLAGS="${SFLAGS} -DADLER32_UNROLL_LESS"
+        CFLAGS="${CFLAGS} -DADLER32_UNROLL_LESS -DCRC32_UNROLL_LESS"
+        SFLAGS="${SFLAGS} -DADLER32_UNROLL_LESS -DCRC32_UNROLL_LESS"
     ;;
 esac
 
diff --git a/crc32.c b/crc32.c
index 979a719..15b8d2e 100644
--- a/crc32.c
+++ b/crc32.c
@@ -199,6 +199,7 @@ const z_crc_t FAR * ZEXPORT get_crc_table()
 /* ========================================================================= */
 #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
 #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
+#define DO4 DO1; DO1; DO1; DO1
 
 /* ========================================================================= */
 unsigned long ZEXPORT crc32(crc, buf, len)
@@ -225,10 +226,19 @@ unsigned long ZEXPORT crc32(crc, buf, len)
     }
 #endif /* BYFOUR */
     crc = crc ^ 0xffffffffUL;
+
+#ifdef CRC32_UNROLL_LESS
+    while (len >= 4) {
+        DO4;
+        len -= 4;
+    }
+#else
     while (len >= 8) {
         DO8;
         len -= 8;
     }
+#endif
+
     if (len) do {
         DO1;
     } while (--len);
@@ -260,10 +270,14 @@ local unsigned long crc32_little(crc, buf, len)
     }
 
     buf4 = (const z_crc_t FAR *)(const void FAR *)buf;
+
+#ifndef CRC32_UNROLL_LESS
     while (len >= 32) {
         DOLIT32;
         len -= 32;
     }
+#endif
+
     while (len >= 4) {
         DOLIT4;
         len -= 4;
-- 
1.7.1





More information about the Zlib-devel mailing list