From: Nathan Moinvaziri Date: Sun, 5 Jun 2022 20:59:44 +0000 (-0700) Subject: Used fixed width uint8_t for crc32 and adler32 function declarations. X-Git-Tag: 2.1.0-beta1~212 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2ca4a777612b81c5f811ff27f3b8af1a10bd8ed3;p=thirdparty%2Fzlib-ng.git Used fixed width uint8_t for crc32 and adler32 function declarations. --- diff --git a/adler32.c b/adler32.c index 7590d9679..c47f76458 100644 --- 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; diff --git a/adler32_p.h b/adler32_p.h index e97f2eac3..8fe41b142 100644 --- a/adler32_p.h +++ b/adler32_p.h @@ -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; diff --git a/arch/arm/adler32_neon.c b/arch/arm/adler32_neon.c index 08032672e..0e2a1b403 100644 --- a/arch/arm/adler32_neon.c +++ b/arch/arm/adler32_neon.c @@ -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; diff --git a/arch/arm/crc32_acle.c b/arch/arm/crc32_acle.c index 6f6ed4537..68cdafa31 100644 --- a/arch/arm/crc32_acle.c +++ b/arch/arm/crc32_acle.c @@ -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; diff --git a/arch/power/adler32_power8.c b/arch/power/adler32_power8.c index fe5e46eaa..0e8e0d162 100644 --- a/arch/power/adler32_power8.c +++ b/arch/power/adler32_power8.c @@ -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; diff --git a/arch/power/adler32_vmx.c b/arch/power/adler32_vmx.c index 11fe55944..2c8eb6827 100644 --- a/arch/power/adler32_vmx.c +++ b/arch/power/adler32_vmx.c @@ -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); diff --git a/arch/s390/crc32-vx.c b/arch/s390/crc32-vx.c index 088800344..340846083 100644 --- a/arch/s390/crc32-vx.c +++ b/arch/s390/crc32-vx.c @@ -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. diff --git a/arch/x86/adler32_ssse3.c b/arch/x86/adler32_ssse3.c index 1c9f58486..45fddd42a 100644 --- a/arch/x86/adler32_ssse3.c +++ b/arch/x86/adler32_ssse3.c @@ -14,7 +14,7 @@ #include -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 */ diff --git a/arch/x86/crc32_fold_pclmulqdq.c b/arch/x86/crc32_fold_pclmulqdq.c index 3d0eaf353..104455e36 100644 --- a/arch/x86/crc32_fold_pclmulqdq.c +++ b/arch/x86/crc32_fold_pclmulqdq.c @@ -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) diff --git a/cpu_features.h b/cpu_features.h index 84ce3cfdf..84c511563 100644 --- a/cpu_features.h +++ b/cpu_features.h @@ -23,29 +23,29 @@ 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 */ diff --git a/crc32_braid.c b/crc32_braid.c index f5b223eea..07af068de 100644 --- a/crc32_braid.c +++ b/crc32_braid.c @@ -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 */ diff --git a/crc32_braid_p.h b/crc32_braid_p.h index 80c0f14b9..53b7f53a6 100644 --- a/crc32_braid_p.h +++ b/crc32_braid_p.h @@ -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_ */ diff --git a/functable.c b/functable.c index 4c9bc2d42..a96caafc5 100644 --- a/functable.c +++ b/functable.c @@ -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"); diff --git a/functable.h b/functable.h index 932ddcc89..838af2fd9 100644 --- a/functable.h +++ b/functable.h @@ -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); diff --git a/test/benchmarks/benchmark_adler32_copy.cc b/test/benchmarks/benchmark_adler32_copy.cc index acc3fe5c1..81fdc4a0c 100644 --- a/test/benchmarks/benchmark_adler32_copy.cc +++ b/test/benchmarks/benchmark_adler32_copy.cc @@ -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); \ }); \