diff options
Diffstat (limited to 'crc32.c')
-rw-r--r-- | crc32.c | 60 |
1 files changed, 21 insertions, 39 deletions
@@ -63,10 +63,12 @@ #include "deflate.h" +ZLIB_INTERNAL uint32_t crc32_generic(uint32_t, const unsigned char *, z_off64_t); + #if BYTE_ORDER == LITTLE_ENDIAN -static uint32_t crc32_little(uint32_t, const unsigned char *, size_t); +ZLIB_INTERNAL uint32_t crc32_little(uint32_t, const unsigned char *, size_t); #elif BYTE_ORDER == BIG_ENDIAN -static uint32_t crc32_big(uint32_t, const unsigned char *, size_t); +ZLIB_INTERNAL uint32_t crc32_big(uint32_t, const unsigned char *, size_t); #endif /* Local functions for crc concatenation */ @@ -205,12 +207,6 @@ const uint32_t * ZEXPORT get_crc_table(void) { return (const uint32_t *)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 - -/* ========================================================================= */ uint32_t ZEXPORT crc32_z(uint32_t crc, const unsigned char *buf, size_t len) { if (buf == NULL) return 0; @@ -226,6 +222,18 @@ uint32_t ZEXPORT crc32_z(uint32_t crc, const unsigned char *buf, size_t len) { return crc32_big(crc, buf, len); #endif } + + return crc32_generic(crc, buf, len); +} + +/* ========================================================================= */ +#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 + +/* ========================================================================= */ +ZLIB_INTERNAL uint32_t crc32_generic(uint32_t crc, const unsigned char *buf, z_off64_t len) +{ crc = crc ^ 0xffffffff; #ifdef UNROLL_LESS @@ -270,7 +278,7 @@ uint32_t ZEXPORT crc32(uint32_t crc, const unsigned char *buf, uint32_t len) { #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4 /* ========================================================================= */ -static uint32_t crc32_little(uint32_t crc, const unsigned char *buf, size_t len) { +ZLIB_INTERNAL uint32_t crc32_little(uint32_t crc, const unsigned char *buf, size_t len) { register uint32_t c; register const uint32_t *buf4; @@ -312,7 +320,7 @@ static uint32_t crc32_little(uint32_t crc, const unsigned char *buf, size_t len) #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4 /* ========================================================================= */ -static uint32_t crc32_big(uint32_t crc, const unsigned char *buf, size_t len) { +ZLIB_INTERNAL uint32_t crc32_big(uint32_t crc, const unsigned char *buf, size_t len) { register uint32_t c; register const uint32_t *buf4; @@ -432,40 +440,14 @@ uint32_t ZEXPORT crc32_combine64(uint32_t crc1, uint32_t crc2, z_off64_t len2) { return crc32_combine_(crc1, crc2, len2); } - -#ifdef X86_PCLMULQDQ_CRC -#include "arch/x86/x86.h" -extern void ZLIB_INTERNAL crc_fold_init(deflate_state *const s); -extern void ZLIB_INTERNAL crc_fold_copy(deflate_state *const s, - unsigned char *dst, const unsigned char *src, long len); -extern uint32_t ZLIB_INTERNAL crc_fold_512to32(deflate_state *const s); -#endif - +#ifndef X86_PCLMULQDQ_CRC ZLIB_INTERNAL void crc_reset(deflate_state *const s) { -#ifdef X86_PCLMULQDQ_CRC - if (x86_cpu_has_pclmulqdq) { - crc_fold_init(s); - return; - } -#endif s->strm->adler = crc32(0L, Z_NULL, 0); } -ZLIB_INTERNAL void crc_finalize(deflate_state *const s) { -#ifdef X86_PCLMULQDQ_CRC - if (x86_cpu_has_pclmulqdq) - s->strm->adler = crc_fold_512to32(s); -#endif -} - -ZLIB_INTERNAL void copy_with_crc(z_stream *strm, unsigned char *dst, long size) { -#ifdef X86_PCLMULQDQ_CRC - if (x86_cpu_has_pclmulqdq) { - crc_fold_copy(strm->state, dst, strm->next_in, size); - return; - } -#endif +ZLIB_INTERNAL void copy_with_crc(z_stream *strm, unsigned char *dst, unsigned long size) { memcpy(dst, strm->next_in, size); strm->adler = crc32(strm->adler, dst, size); } +#endif |