From fd80ca4fb96b8bdeb4e7f9ec863ebc34a9303968 Mon Sep 17 00:00:00 2001 From: Jim Kukunas Date: Wed, 17 Jul 2013 10:38:54 -0700 Subject: [PATCH] Add preprocessor define to tune crc32 unrolling. 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 d6f790bae..ff66ab32e 100755 --- a/configure +++ b/configure @@ -772,8 +772,8 @@ case "${ARCH}" in CFLAGS="${CFLAGS} -DUNALIGNED_OK" SFLAGS="${SFLAGS} -DUNALIGNED_OK" - 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" @@ -785,8 +785,8 @@ case "${ARCH}" in CFLAGS="${CFLAGS} -DUNALIGNED_OK" SFLAGS="${SFLAGS} -DUNALIGNED_OK" - 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 979a7190a..15b8d2e4b 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; -- 2.47.3