From: Nathan Moinvaziri Date: Thu, 15 Jan 2026 04:15:05 +0000 (-0800) Subject: Move crc32_copy_small to shared private header. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=646ba2d71f062600fbd78cf2dc90cad5e2235e67;p=thirdparty%2Fzlib-ng.git Move crc32_copy_small to shared private header. --- diff --git a/arch/generic/crc32_braid_c.c b/arch/generic/crc32_braid_c.c index 60da32efe..0236fbcd4 100644 --- a/arch/generic/crc32_braid_c.c +++ b/arch/generic/crc32_braid_c.c @@ -10,6 +10,7 @@ #include "zbuild.h" #include "crc32_braid_p.h" #include "crc32_braid_tbl.h" +#include "crc32_p.h" /* A CRC of a message is computed on BRAID_N braids of words in the message, where @@ -203,12 +204,7 @@ Z_INTERNAL uint32_t crc32_braid_internal(uint32_t c, const uint8_t *buf, size_t len -= 8; CRC_DO8; } - while (len) { - len--; - CRC_DO1; - } - - return c; + return crc32_copy_small(c, NULL, buf, len, 0); } Z_INTERNAL uint32_t crc32_braid(uint32_t crc, const uint8_t *buf, size_t len) { diff --git a/arch/x86/crc32_pclmulqdq_tpl.h b/arch/x86/crc32_pclmulqdq_tpl.h index 625a90fc0..701b0feeb 100644 --- a/arch/x86/crc32_pclmulqdq_tpl.h +++ b/arch/x86/crc32_pclmulqdq_tpl.h @@ -26,6 +26,7 @@ #include "crc32.h" #include "crc32_braid_p.h" #include "crc32_braid_tbl.h" +#include "crc32_p.h" #include "x86_intrins.h" #ifdef X86_VPCLMULQDQ @@ -136,20 +137,6 @@ static inline void fold_16(__m512i *zmm_crc0, __m512i *zmm_crc1, __m512i *zmm_cr } #endif -static inline uint32_t crc32_copy_small(uint32_t crc, uint8_t *dst, const uint8_t *buf, size_t len, const int COPY) { - uint32_t c = ~crc; - - while (len) { - len--; - if (COPY) { - *dst++ = *buf; - } - CRC_DO1; - } - - return ~c; -} - Z_FORCEINLINE static uint32_t crc32_copy_impl(uint32_t crc, uint8_t *dst, const uint8_t *src, size_t len, const int COPY) { size_t copy_len = len; if (len >= 16) { @@ -162,7 +149,7 @@ Z_FORCEINLINE static uint32_t crc32_copy_impl(uint32_t crc, uint8_t *dst, const } if (copy_len > 0) { - crc = crc32_copy_small(crc, dst, src, copy_len, COPY); + crc = crc32_copy_small(~crc, dst, src, copy_len, COPY); src += copy_len; len -= copy_len; if (COPY) { diff --git a/crc32_braid_p.h b/crc32_braid_p.h index 7a1b4474c..af26ebedd 100644 --- a/crc32_braid_p.h +++ b/crc32_braid_p.h @@ -27,9 +27,6 @@ # error "No endian defined" #endif -#define CRC_DO1 c = crc_table[(c ^ *buf++) & 0xff] ^ (c >> 8) -#define CRC_DO8 CRC_DO1; CRC_DO1; CRC_DO1; CRC_DO1; CRC_DO1; CRC_DO1; CRC_DO1; CRC_DO1 - /* CRC polynomial. */ #define POLY 0xedb88320 /* p(x) reflected, with x^32 implied */ diff --git a/crc32_p.h b/crc32_p.h new file mode 100644 index 000000000..37e9a4cf3 --- /dev/null +++ b/crc32_p.h @@ -0,0 +1,28 @@ +/* crc32_p.h -- Private inline functions and macros shared with + * different computation of the CRC-32 checksum + * of a data stream. + * Copyright (C) 1995-2011, 2016 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#ifndef CRC32_P_H +#define CRC32_P_H + +#define CRC_DO1 c = crc_table[(c ^ *buf++) & 0xff] ^ (c >> 8) +#define CRC_DO8 CRC_DO1; CRC_DO1; CRC_DO1; CRC_DO1; CRC_DO1; CRC_DO1; CRC_DO1; CRC_DO1 + +Z_FORCEINLINE static uint32_t crc32_copy_small(uint32_t crc, uint8_t *dst, const uint8_t *buf, size_t len, const int COPY) { + uint32_t c = crc; + + while (len) { + len--; + if (COPY) { + *dst++ = *buf; + } + CRC_DO1; + } + + return ~c; +} + +#endif /* CRC32_P_H */