From: Nathan Moinvaziri Date: Sun, 4 Jan 2026 07:54:18 +0000 (-0800) Subject: Simplify crc32 pre/post conditioning for consistency X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d7fc636840b6d6bf2c9b1e0bbbbb08b645659cfd;p=thirdparty%2Fzlib-ng.git Simplify crc32 pre/post conditioning for consistency --- diff --git a/arch/generic/crc32_braid_c.c b/arch/generic/crc32_braid_c.c index 3b447ed9c..c56ba97b3 100644 --- a/arch/generic/crc32_braid_c.c +++ b/arch/generic/crc32_braid_c.c @@ -208,17 +208,11 @@ Z_INTERNAL uint32_t crc32_braid_internal(uint32_t c, const uint8_t *buf, size_t CRC_DO1; } - /* Return the CRC, post-conditioned. */ return c; } Z_INTERNAL uint32_t crc32_braid(uint32_t crc, const uint8_t *buf, size_t len) { - crc = (~crc) & 0xffffffff; - - crc = crc32_braid_internal(crc, buf, len); - - /* Return the CRC, post-conditioned. */ - return crc ^ 0xffffffff; + return ~crc32_braid_internal(~crc, buf, len); } Z_INTERNAL uint32_t crc32_copy_braid(uint32_t crc, uint8_t *dst, const uint8_t *src, size_t len) { diff --git a/arch/generic/crc32_chorba_c.c b/arch/generic/crc32_chorba_c.c index 9455b55ee..79a502407 100644 --- a/arch/generic/crc32_chorba_c.c +++ b/arch/generic/crc32_chorba_c.c @@ -1449,7 +1449,7 @@ Z_INTERNAL uint32_t crc32_chorba_small_nondestructive_32bit (uint32_t crc, const Z_INTERNAL uint32_t crc32_chorba(uint32_t crc, const uint8_t *buf, size_t len) { uint64_t *aligned_buf; - uint32_t c = (~crc) & 0xffffffff; + uint32_t c = ~crc; uintptr_t align_diff = ALIGN_DIFF(buf, 8); if (len > align_diff + CHORBA_SMALL_THRESHOLD) { @@ -1477,7 +1477,7 @@ Z_INTERNAL uint32_t crc32_chorba(uint32_t crc, const uint8_t *buf, size_t len) { } /* Return the CRC, post-conditioned. */ - return c ^ 0xffffffff; + return ~c; } uint32_t crc32_copy_chorba(uint32_t crc, uint8_t *dst, const uint8_t *src, size_t len) { diff --git a/arch/s390/crc32-vx.c b/arch/s390/crc32-vx.c index c1de8b6f8..de805d150 100644 --- a/arch/s390/crc32-vx.c +++ b/arch/s390/crc32-vx.c @@ -213,7 +213,7 @@ uint32_t Z_INTERNAL crc32_s390_vx(uint32_t crc, const unsigned char *buf, size_t aligned = len & ~VX_ALIGN_MASK; remaining = len & VX_ALIGN_MASK; - crc = crc32_le_vgfm_16(crc ^ 0xffffffff, buf, aligned) ^ 0xffffffff; + crc = ~crc32_le_vgfm_16(~crc, buf, aligned); if (remaining) crc = crc32_braid(crc, buf + aligned, remaining); diff --git a/arch/x86/chorba_sse2.c b/arch/x86/chorba_sse2.c index a5567faf3..4d7e7d1f0 100644 --- a/arch/x86/chorba_sse2.c +++ b/arch/x86/chorba_sse2.c @@ -848,7 +848,7 @@ Z_INTERNAL uint32_t chorba_small_nondestructive_sse2(uint32_t crc, const uint64_ Z_INTERNAL uint32_t crc32_chorba_sse2(uint32_t crc, const uint8_t *buf, size_t len) { uint64_t *aligned_buf; - uint32_t c = (~crc) & 0xffffffff; + uint32_t c = ~crc; uintptr_t align_diff = ALIGN_DIFF(buf, 16); if (len > align_diff + CHORBA_SMALL_THRESHOLD_64BIT) { @@ -871,7 +871,7 @@ Z_INTERNAL uint32_t crc32_chorba_sse2(uint32_t crc, const uint8_t *buf, size_t l } /* Return the CRC, post-conditioned. */ - return c ^ 0xffffffff; + return ~c; } Z_INTERNAL uint32_t crc32_copy_chorba_sse2(uint32_t crc, uint8_t *dst, const uint8_t *src, size_t len) { diff --git a/arch/x86/chorba_sse41.c b/arch/x86/chorba_sse41.c index 07daf7094..65243bff3 100644 --- a/arch/x86/chorba_sse41.c +++ b/arch/x86/chorba_sse41.c @@ -306,7 +306,7 @@ static Z_FORCEINLINE uint32_t crc32_chorba_32768_nondestructive_sse41(uint32_t c Z_INTERNAL uint32_t crc32_chorba_sse41(uint32_t crc, const uint8_t *buf, size_t len) { uint64_t *aligned_buf; - uint32_t c = (~crc) & 0xffffffff; + uint32_t c = ~crc; uintptr_t align_diff = ALIGN_DIFF(buf, 16); if (len > align_diff + CHORBA_SMALL_THRESHOLD_64BIT) { @@ -331,7 +331,7 @@ Z_INTERNAL uint32_t crc32_chorba_sse41(uint32_t crc, const uint8_t *buf, size_t } /* Return the CRC, post-conditioned. */ - return c ^ 0xffffffff; + return ~c; } Z_INTERNAL uint32_t crc32_copy_chorba_sse41(uint32_t crc, uint8_t *dst, const uint8_t *src, size_t len) { diff --git a/arch/x86/crc32_pclmulqdq_tpl.h b/arch/x86/crc32_pclmulqdq_tpl.h index fc35b449c..dc8fbfd5f 100644 --- a/arch/x86/crc32_pclmulqdq_tpl.h +++ b/arch/x86/crc32_pclmulqdq_tpl.h @@ -285,7 +285,7 @@ static inline void partial_fold(const size_t len, __m128i *xmm_crc0, __m128i *xm } 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) & 0xffffffff; + uint32_t c = ~crc; while (len) { len--; @@ -295,7 +295,7 @@ static inline uint32_t crc32_copy_small(uint32_t crc, uint8_t *dst, const uint8_ CRC_DO1; } - return c ^ 0xffffffff; + return ~c; } static inline uint32_t fold_final(__m128i *xmm_crc0, __m128i *xmm_crc1, __m128i *xmm_crc2, __m128i *xmm_crc3) {