]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Simplify crc32 pre/post conditioning for consistency
authorNathan Moinvaziri <nathan@nathanm.com>
Sun, 4 Jan 2026 07:54:18 +0000 (23:54 -0800)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Tue, 6 Jan 2026 23:19:32 +0000 (00:19 +0100)
arch/generic/crc32_braid_c.c
arch/generic/crc32_chorba_c.c
arch/s390/crc32-vx.c
arch/x86/chorba_sse2.c
arch/x86/chorba_sse41.c
arch/x86/crc32_pclmulqdq_tpl.h

index 3b447ed9c0342488a70852aa71b55dd1551be04e..c56ba97b3f8eca9c71591ee0e5f851fcd1fe9e13 100644 (file)
@@ -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) {
index 9455b55eedf1687e186ca5e46ebaa8ba1b83139b..79a5024073955a5dc0ff46a1d57615d62b7b4e75 100644 (file)
@@ -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) {
index c1de8b6f85818a2e40e57e4c1f1143df2f2843ef..de805d150d9afc95d5fc9f8874423e4fbae972ea 100644 (file)
@@ -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);
index a5567faf3b4e58f0fe0e8446af672dbf20262644..4d7e7d1f012963ea08d3dac6297c94b3e6af2186 100644 (file)
@@ -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) {
index 07daf70947892dbb1e13dddb3780f5ed2d9db20e..65243bff3b6581d5bd3e7a0acaffdcb047947b82 100644 (file)
@@ -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) {
index fc35b449cf90e91c09f1f924b02d2ef21822956d..dc8fbfd5fcfbe8ef14f236a2f8fd7cdc2adcfa1f 100644 (file)
@@ -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) {