]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Used fixed width uint8_t for crc32 and adler32 function declarations.
authorNathan Moinvaziri <nathan@nathanm.com>
Sun, 5 Jun 2022 20:59:44 +0000 (13:59 -0700)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Fri, 24 Jun 2022 13:12:00 +0000 (15:12 +0200)
15 files changed:
adler32.c
adler32_p.h
arch/arm/adler32_neon.c
arch/arm/crc32_acle.c
arch/power/adler32_power8.c
arch/power/adler32_vmx.c
arch/s390/crc32-vx.c
arch/x86/adler32_ssse3.c
arch/x86/crc32_fold_pclmulqdq.c
cpu_features.h
crc32_braid.c
crc32_braid_p.h
functable.c
functable.h
test/benchmarks/benchmark_adler32_copy.cc

index 7590d967907f10a0fbb6d7741835a53ea41c81db..c47f7645866f92465bd61056b4c052d2dde299e0 100644 (file)
--- a/adler32.c
+++ b/adler32.c
@@ -8,7 +8,7 @@
 #include "adler32_p.h"
 
 /* ========================================================================= */
-Z_INTERNAL uint32_t adler32_c(uint32_t adler, const unsigned char *buf, uint64_t len) {
+Z_INTERNAL uint32_t adler32_c(uint32_t adler, const uint8_t *buf, uint64_t len) {
     uint32_t sum2;
     unsigned n;
 
index e97f2eac334de2ff3d01685e5a6578025f820590..8fe41b1422c323d567bfc6cb0b1439930adc013a 100644 (file)
@@ -18,7 +18,7 @@
 #define DO8(sum1, sum2, buf, i)  {DO4(sum1, sum2, buf, i); DO4(sum1, sum2, buf, i+4);}
 #define DO16(sum1, sum2, buf)    {DO8(sum1, sum2, buf, 0); DO8(sum1, sum2, buf, 8);}
 
-static inline uint32_t adler32_len_1(uint32_t adler, const unsigned char *buf, uint32_t sum2) {
+static inline uint32_t adler32_len_1(uint32_t adler, const uint8_t *buf, uint32_t sum2) {
     adler += buf[0];
     adler %= BASE;
     sum2 += adler;
@@ -26,7 +26,7 @@ static inline uint32_t adler32_len_1(uint32_t adler, const unsigned char *buf, u
     return adler | (sum2 << 16);
 }
 
-static inline uint32_t adler32_len_16(uint32_t adler, const unsigned char *buf, uint64_t len, uint32_t sum2) {
+static inline uint32_t adler32_len_16(uint32_t adler, const uint8_t *buf, uint64_t len, uint32_t sum2) {
     while (len) {
         --len;
         adler += *buf++;
@@ -38,7 +38,7 @@ static inline uint32_t adler32_len_16(uint32_t adler, const unsigned char *buf,
     return adler | (sum2 << 16);
 }
 
-static inline uint32_t adler32_copy_len_16(uint32_t adler, const unsigned char *buf, uint8_t *dst, uint64_t len, uint32_t sum2) {
+static inline uint32_t adler32_copy_len_16(uint32_t adler, const uint8_t *buf, uint8_t *dst, uint64_t len, uint32_t sum2) {
     while (len--) {
         *dst = *buf++;
         adler += *dst++;
@@ -50,7 +50,7 @@ static inline uint32_t adler32_copy_len_16(uint32_t adler, const unsigned char *
     return adler | (sum2 << 16);
 }
 
-static inline uint32_t adler32_len_64(uint32_t adler, const unsigned char *buf, uint64_t len, uint32_t sum2) {
+static inline uint32_t adler32_len_64(uint32_t adler, const uint8_t *buf, uint64_t len, uint32_t sum2) {
 #ifdef UNROLL_MORE
     while (len >= 16) {
         len -= 16;
index 08032672e762173fe67c90a7aa4a697d2b948e37..0e2a1b40336ba119f3b2dbc51e0eb3f5f2bdc430 100644 (file)
@@ -15,7 +15,7 @@
 #include "../../adler32_p.h"
 #include "../../fallback_builtins.h"
 
-static void NEON_accum32(uint32_t *s, const unsigned char *buf, uint64_t len) {
+static void NEON_accum32(uint32_t *s, const uint8_t *buf, uint64_t len) {
     static const uint16_t ALIGNED_(16) taps[64] = {
         64, 63, 62, 61, 60, 59, 58, 57,
         56, 55, 54, 53, 52, 51, 50, 49,
@@ -138,7 +138,7 @@ static void NEON_accum32(uint32_t *s, const unsigned char *buf, uint64_t len) {
     s[1] = vget_lane_u32(as, 1);
 }
 
-static void NEON_handle_tail(uint32_t *pair, const unsigned char *buf, uint64_t len) {
+static void NEON_handle_tail(uint32_t *pair, const uint8_t *buf, uint64_t len) {
     unsigned int i;
     for (i = 0; i < len; ++i) {
         pair[0] += buf[i];
@@ -146,7 +146,7 @@ static void NEON_handle_tail(uint32_t *pair, const unsigned char *buf, uint64_t
     }
 }
 
-uint32_t adler32_neon(uint32_t adler, const unsigned char *buf, uint64_t len) {
+uint32_t adler32_neon(uint32_t adler, const uint8_t *buf, uint64_t len) {
     /* split Adler-32 into component sums */
     uint32_t sum2 = (adler >> 16) & 0xffff;
     adler &= 0xffff;
index 6f6ed45373fec5a7a1d0f6240989ee2e310ea7f9..68cdafa31415b25096288def4e28cf4f82174d8e 100644 (file)
@@ -11,7 +11,7 @@
 #endif
 #include "../../zbuild.h"
 
-uint32_t crc32_acle(uint32_t crc, const unsigned char *buf, uint64_t len) {
+uint32_t crc32_acle(uint32_t crc, const uint8_t *buf, uint64_t len) {
     Z_REGISTER uint32_t c;
     Z_REGISTER const uint16_t *buf2;
     Z_REGISTER const uint32_t *buf4;
index fe5e46eaa8799c3693466681f5c80dbf9f73e063..0e8e0d162ccc72b78e49900c49e4ac4169b77919 100644 (file)
@@ -52,7 +52,7 @@ static inline vector unsigned int vec_sumsu(vector unsigned int __a, vector unsi
     return __a;
 }
 
-uint32_t adler32_power8(uint32_t adler, const unsigned char* buf, uint64_t len) {
+uint32_t adler32_power8(uint32_t adler, const uint8_t *buf, uint64_t len) {
     uint32_t s1 = adler & 0xffff;
     uint32_t s2 = (adler >> 16) & 0xffff;
 
index 11fe55944995f2df8de5afbe0110816e6ab03dbb..2c8eb68270221aeaa82cf63fa1ad443125a428d6 100644 (file)
@@ -12,7 +12,7 @@
 
 #define vmx_zero()  (vec_splat_u32(0))
 
-static inline void vmx_handle_head_or_tail(uint32_t *pair, const unsigned char *buf, uint64_t len) {
+static inline void vmx_handle_head_or_tail(uint32_t *pair, const uint8_t *buf, uint64_t len) {
     unsigned int i;
     for (i = 0; i < len; ++i) {
         pair[0] += buf[i];
@@ -20,7 +20,7 @@ static inline void vmx_handle_head_or_tail(uint32_t *pair, const unsigned char *
     }
 }
 
-static void vmx_accum32(uint32_t *s, const unsigned char *buf, uint64_t len) {
+static void vmx_accum32(uint32_t *s, const uint8_t *buf, uint64_t len) {
     /* Different taps for the separable components of sums */
     const vector unsigned char t0 = {64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49};
     const vector unsigned char t1 = {48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33};
@@ -113,7 +113,7 @@ static void vmx_accum32(uint32_t *s, const unsigned char *buf, uint64_t len) {
     vec_ste(s2acc, 0, s+1);
 }
 
-uint32_t adler32_vmx(uint32_t adler, const unsigned char *buf, uint64_t len) {
+uint32_t adler32_vmx(uint32_t adler, const uint8_t *buf, uint64_t len) {
     uint32_t sum2;
     uint32_t pair[16] ALIGNED_(16);
     memset(&pair[2], 0, 14);
index 0888003445eb194efba6cb3aef65d6e748bc2ce5..340846083ee481cf78f33ad0ebc2a963e77dd710 100644 (file)
@@ -21,7 +21,7 @@ typedef unsigned char uv16qi __attribute__((vector_size(16)));
 typedef unsigned int uv4si __attribute__((vector_size(16)));
 typedef unsigned long long uv2di __attribute__((vector_size(16)));
 
-static uint32_t crc32_le_vgfm_16(uint32_t crc, const unsigned char *buf, uint64_t len) {
+static uint32_t crc32_le_vgfm_16(uint32_t crc, const uint8_t *buf, uint64_t len) {
     /*
      * The CRC-32 constant block contains reduction constants to fold and
      * process particular chunks of the input data stream in parallel.
index 1c9f58486d4e0bedfc6b39170837c941d9d99416..45fddd42afefb59c1b19993f129d5d0ad89290b2 100644 (file)
@@ -14,7 +14,7 @@
 
 #include <immintrin.h>
 
-Z_INTERNAL uint32_t adler32_ssse3(uint32_t adler, const unsigned char *buf, uint64_t len) {
+Z_INTERNAL uint32_t adler32_ssse3(uint32_t adler, const uint8_t *buf, uint64_t len) {
     uint32_t sum2;
 
      /* split Adler-32 into component sums */
index 3d0eaf35313b19b3ccf067f7b6801a7f792b5987..104455e36e474e7e58e82e50195d822fe9d6a24c 100644 (file)
@@ -341,7 +341,7 @@ Z_INTERNAL uint32_t crc32_fold_pclmulqdq_final(crc32_fold *crc) {
     return crc->value;
 }
 
-uint32_t crc32_pclmulqdq(uint32_t crc32, const unsigned char* buf, uint64_t len) {
+uint32_t crc32_pclmulqdq(uint32_t crc32, const uint8_t *buf, uint64_t len) {
     /* For lens < 64, crc32_braid method is faster. The CRC32 instruction for
      * these short lengths might also prove to be effective */
     if (len < 64)
index 84ce3cfdf9a6cb92e4e6833d1d8b1bb6f37d3095..84c511563269e46dc897210b29070ee93aad2a42 100644 (file)
 extern void cpu_check_features(void);
 
 /* adler32 */
-typedef uint32_t (*adler32_func)(uint32_t adler, const unsigned char *buf, uint64_t len);
+typedef uint32_t (*adler32_func)(uint32_t adler, const uint8_t *buf, uint64_t len);
 
-extern uint32_t adler32_c(uint32_t adler, const unsigned char *buf, uint64_t len);
+extern uint32_t adler32_c(uint32_t adler, const uint8_t *buf, uint64_t len);
 #ifdef ARM_NEON_ADLER32
-extern uint32_t adler32_neon(uint32_t adler, const unsigned char *buf, uint64_t len);
+extern uint32_t adler32_neon(uint32_t adler, const uint8_t *buf, uint64_t len);
 #endif
 #ifdef PPC_VMX_ADLER32
-extern uint32_t adler32_vmx(uint32_t adler, const unsigned char *buf, uint64_t len);
+extern uint32_t adler32_vmx(uint32_t adler, const uint8_t *buf, uint64_t len);
 #endif
 #ifdef X86_SSSE3_ADLER32
-extern uint32_t adler32_ssse3(uint32_t adler, const unsigned char *buf, uint64_t len);
+extern uint32_t adler32_ssse3(uint32_t adler, const uint8_t *buf, uint64_t len);
 #endif
 #ifdef X86_AVX2_ADLER32
-extern uint32_t adler32_avx2(uint32_t adler, const unsigned char *buf, uint64_t len);
+extern uint32_t adler32_avx2(uint32_t adler, const uint8_t *buf, uint64_t len);
 #endif
 #ifdef X86_AVX512_ADLER32
-extern uint32_t adler32_avx512(uint32_t adler, const unsigned char *buf, uint64_t len);
+extern uint32_t adler32_avx512(uint32_t adler, const uint8_t *buf, uint64_t len);
 #endif
 #ifdef X86_AVX512VNNI_ADLER32
-extern uint32_t adler32_avx512_vnni(uint32_t adler, const unsigned char *buf, uint64_t len);
+extern uint32_t adler32_avx512_vnni(uint32_t adler, const uint8_t *buf, uint64_t len);
 #endif
 #ifdef POWER8_VSX_ADLER32
-extern uint32_t adler32_power8(uint32_t adler, const unsigned char* buf, uint64_t len);
+extern uint32_t adler32_power8(uint32_t adler, const uint8_t *buf, uint64_t len);
 #endif
 
 /* adler32 folding */
@@ -68,7 +68,7 @@ extern uint32_t crc32_fold_pclmulqdq_reset(crc32_fold *crc);
 extern void     crc32_fold_pclmulqdq_copy(crc32_fold *crc, uint8_t *dst, const uint8_t *src, uint64_t len);
 extern void     crc32_fold_pclmulqdq(crc32_fold *crc, const uint8_t *src, uint64_t len, uint32_t init_crc);
 extern uint32_t crc32_fold_pclmulqdq_final(crc32_fold *crc);
-extern uint32_t crc32_pclmulqdq(uint32_t crc32, const unsigned char* buf, uint64_t len);
+extern uint32_t crc32_pclmulqdq(uint32_t crc32, const uint8_t *buf, uint64_t len);
 #endif
 
 /* memory chunking */
@@ -111,15 +111,15 @@ extern uint8_t* chunkmemset_safe_power8(uint8_t *out, unsigned dist, unsigned le
 #endif
 
 /* CRC32 */
-typedef uint32_t (*crc32_func)(uint32_t crc32, const unsigned char * buf, uint64_t len);
+typedef uint32_t (*crc32_func)(uint32_t crc32, const uint8_t *buf, uint64_t len);
 
-extern uint32_t crc32_braid(uint32_t crc, const unsigned char *buf, uint64_t len);
+extern uint32_t crc32_braid(uint32_t crc, const uint8_t *buf, uint64_t len);
 #ifdef ARM_ACLE_CRC_HASH
-extern uint32_t crc32_acle(uint32_t crc, const unsigned char *buf, uint64_t len);
+extern uint32_t crc32_acle(uint32_t crc, const uint8_t *buf, uint64_t len);
 #elif defined(POWER8_VSX_CRC32)
-extern uint32_t crc32_power8(uint32_t crc, const unsigned char *buf, uint64_t len);
+extern uint32_t crc32_power8(uint32_t crc, const uint8_t *buf, uint64_t len);
 #elif defined(S390_CRC32_VX)
-extern uint32_t PREFIX(s390_crc32_vx)(uint32_t crc, const unsigned char *buf, uint64_t len);
+extern uint32_t PREFIX(s390_crc32_vx)(uint32_t crc, const uint8_t *buf, uint64_t len);
 #endif
 
 /* compare256 */
index f5b223eeabfe840f3bf594bb5d73319e683f7f5e..07af068de181f1f6fe88ead48c0e934f562aeae5 100644 (file)
@@ -111,7 +111,7 @@ static z_word_t crc_word(z_word_t data) {
 #endif /* W */
 
 /* ========================================================================= */
-Z_INTERNAL uint32_t crc32_braid(uint32_t crc, const unsigned char *buf, uint64_t len) {
+Z_INTERNAL uint32_t crc32_braid(uint32_t crc, const uint8_t *buf, uint64_t len) {
     Z_REGISTER uint32_t c;
 
     /* Pre-condition the CRC */
index 80c0f14b9cdfb7525fe877ee6af0af4b80a338cb..53b7f53a666641125879c2bc97b6d0e2350ebd9e 100644 (file)
@@ -45,6 +45,6 @@
 /* CRC polynomial. */
 #define POLY 0xedb88320         /* p(x) reflected, with x^32 implied */
 
-extern uint32_t crc32_braid(uint32_t crc, const unsigned char *buf, uint64_t len);
+extern uint32_t crc32_braid(uint32_t crc, const uint8_t *buf, uint64_t len);
 
 #endif /* CRC32_BRAID_P_H_ */
index 4c9bc2d425a6b5ff8d80f9077272c30bfe9a3d99..a96caafc5f83eb1af8f20b3afb330f8557bc0072 100644 (file)
@@ -162,7 +162,7 @@ Z_INTERNAL uint32_t longest_match_slow_stub(deflate_state *const s, Pos cur_matc
     return functable.longest_match_slow(s, cur_match);
 }
 
-Z_INTERNAL uint32_t adler32_stub(uint32_t adler, const unsigned char *buf, uint64_t len) {
+Z_INTERNAL uint32_t adler32_stub(uint32_t adler, const uint8_t *buf, uint64_t len) {
     // Initialize default
     functable.adler32 = &adler32_c;
     cpu_check_features();
@@ -403,7 +403,7 @@ Z_INTERNAL uint8_t* chunkmemset_safe_stub(uint8_t *out, unsigned dist, unsigned
     return functable.chunkmemset_safe(out, dist, len, left);
 }
 
-Z_INTERNAL uint32_t crc32_stub(uint32_t crc, const unsigned char *buf, uint64_t len) {
+Z_INTERNAL uint32_t crc32_stub(uint32_t crc, const uint8_t *buf, uint64_t len) {
     Assert(sizeof(uint64_t) >= sizeof(size_t),
            "crc32_z takes size_t but internally we have a uint64_t len");
 
index 932ddcc89816cd1772584597ad303cf636e20d95..838af2fd95761778b322319d0a8487fdd1fed626 100644 (file)
@@ -11,9 +11,9 @@
 #include "adler32_fold.h"
 
 struct functable_s {
-    uint32_t (* adler32)            (uint32_t adler, const unsigned char *buf, uint64_t len);
+    uint32_t (* adler32)            (uint32_t adler, const uint8_t *buf, uint64_t len);
     uint32_t (* adler32_fold_copy)  (uint32_t adler, uint8_t *dst, const uint8_t *src, uint64_t len);
-    uint32_t (* crc32)              (uint32_t crc, const unsigned char *buf, uint64_t len);
+    uint32_t (* crc32)              (uint32_t crc, const uint8_t *buf, uint64_t len);
     uint32_t (* crc32_fold_reset)   (crc32_fold *crc);
     void     (* crc32_fold_copy)    (crc32_fold *crc, uint8_t *dst, const uint8_t *src, uint64_t len);
     void     (* crc32_fold)         (crc32_fold *crc, const uint8_t *src, uint64_t len, uint32_t init_crc);
index acc3fe5c110fea9bb970d4a560e3a5d4bd8512bd..81fdc4a0c6f33149c232bfd6e7f8761e7a435252 100644 (file)
@@ -18,7 +18,7 @@ extern "C" {
 #define MAX_RANDOM_INTS (1024 * 1024)
 #define MAX_RANDOM_INTS_SIZE (MAX_RANDOM_INTS * sizeof(uint32_t))
 
-typedef uint32_t (*adler32_cpy_func)(uint32_t adler, unsigned char *dst, const unsigned char *buf, uint64_t len);
+typedef uint32_t (*adler32_cpy_func)(uint32_t adler, unsigned char *dst, const uint8_t *buf, uint64_t len);
 
 class adler32_copy: public benchmark::Fixture {
 private:
@@ -75,7 +75,7 @@ public:
             state.SkipWithError("CPU does not support " #name); \
         } \
         Bench(state, [](uint32_t init_sum, unsigned char *dst, \
-                        const unsigned char *buf, uint64_t len) -> uint32_t { \
+                        const uint8_t *buf, uint64_t len) -> uint32_t { \
             memcpy(dst, buf, len); \
             return fptr(init_sum, buf, len); \
         }); \