]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Move crc32_copy_small to shared private header.
authorNathan Moinvaziri <nathan@nathanm.com>
Thu, 15 Jan 2026 04:15:05 +0000 (20:15 -0800)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Thu, 29 Jan 2026 12:29:39 +0000 (13:29 +0100)
arch/generic/crc32_braid_c.c
arch/x86/crc32_pclmulqdq_tpl.h
crc32_braid_p.h
crc32_p.h [new file with mode: 0644]

index 60da32efeaf44c7d7b178657fee3fbebed75b83b..0236fbcd4826348e0006046781ad062f7f42d1c5 100644 (file)
@@ -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) {
index 625a90fc03c5a13a83cad96d1f2553bb3add751e..701b0feeb678d48885aee99e2b2c37713d152bcd 100644 (file)
@@ -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) {
index 7a1b4474ccaf69f549ec33c69021b63a90a65437..af26ebeddaf5a2e875c4fa3a44f77c19eecb0620 100644 (file)
@@ -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 (file)
index 0000000..37e9a4c
--- /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 */