From: Hans Kristian Rosbach Date: Sat, 29 Aug 2020 15:26:18 +0000 (+0200) Subject: Fix numerous sign-conversion warnings in compare256/compare258 and X-Git-Tag: 1.9.9-b1~56 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=93ae5483d8066ab1054b3fe9c398a7422905fdef;p=thirdparty%2Fzlib-ng.git Fix numerous sign-conversion warnings in compare256/compare258 and longest_match related code. --- diff --git a/arch/x86/compare258_avx.c b/arch/x86/compare258_avx.c index 8b708b60e..d9108fdeb 100644 --- a/arch/x86/compare258_avx.c +++ b/arch/x86/compare258_avx.c @@ -16,18 +16,18 @@ #endif /* UNALIGNED_OK, AVX2 intrinsic comparison */ -static inline int32_t compare256_unaligned_avx2_static(const unsigned char *src0, const unsigned char *src1) { - int32_t len = 0; +static inline uint32_t compare256_unaligned_avx2_static(const unsigned char *src0, const unsigned char *src1) { + uint32_t len = 0; do { __m256i ymm_src0, ymm_src1, ymm_cmp; ymm_src0 = _mm256_loadu_si256((__m256i*)src0); ymm_src1 = _mm256_loadu_si256((__m256i*)src1); ymm_cmp = _mm256_cmpeq_epi8(ymm_src0, ymm_src1); /* non-identical bytes = 00, identical bytes = FF */ - int mask = _mm256_movemask_epi8(ymm_cmp); - if ((unsigned int)mask != 0xFFFFFFFF) { - int match_byte = __builtin_ctz(~mask); /* Invert bits so identical = 0 */ - return (int32_t)(len + match_byte); + unsigned mask = (unsigned)_mm256_movemask_epi8(ymm_cmp); + if (mask != 0xFFFFFFFF) { + uint32_t match_byte = (uint32_t)__builtin_ctz(~mask); /* Invert bits so identical = 0 */ + return len + match_byte; } src0 += 32, src1 += 32, len += 32; @@ -35,10 +35,10 @@ static inline int32_t compare256_unaligned_avx2_static(const unsigned char *src0 ymm_src0 = _mm256_loadu_si256((__m256i*)src0); ymm_src1 = _mm256_loadu_si256((__m256i*)src1); ymm_cmp = _mm256_cmpeq_epi8(ymm_src0, ymm_src1); - mask = _mm256_movemask_epi8(ymm_cmp); - if ((unsigned int)mask != 0xFFFFFFFF) { - int match_byte = __builtin_ctz(~mask); - return (int32_t)(len + match_byte); + mask = (unsigned)_mm256_movemask_epi8(ymm_cmp); + if (mask != 0xFFFFFFFF) { + uint32_t match_byte = (uint32_t)__builtin_ctz(~mask); + return len + match_byte; } src0 += 32, src1 += 32, len += 32; @@ -47,14 +47,14 @@ static inline int32_t compare256_unaligned_avx2_static(const unsigned char *src0 return 256; } -static inline int32_t compare258_unaligned_avx2_static(const unsigned char *src0, const unsigned char *src1) { +static inline uint32_t compare258_unaligned_avx2_static(const unsigned char *src0, const unsigned char *src1) { if (*(uint16_t *)src0 != *(uint16_t *)src1) return (*src0 == *src1); return compare256_unaligned_avx2_static(src0+2, src1+2) + 2; } -Z_INTERNAL int32_t compare258_unaligned_avx2(const unsigned char *src0, const unsigned char *src1) { +Z_INTERNAL uint32_t compare258_unaligned_avx2(const unsigned char *src0, const unsigned char *src1) { return compare258_unaligned_avx2_static(src0, src1); } diff --git a/arch/x86/compare258_sse.c b/arch/x86/compare258_sse.c index 6f2af8e64..17534c051 100644 --- a/arch/x86/compare258_sse.c +++ b/arch/x86/compare258_sse.c @@ -26,27 +26,27 @@ #endif /* UNALIGNED_OK, SSE4.2 intrinsic comparison */ -static inline int32_t compare256_unaligned_sse4_static(const unsigned char *src0, const unsigned char *src1) { - int32_t len = 0; +static inline uint32_t compare256_unaligned_sse4_static(const unsigned char *src0, const unsigned char *src1) { + uint32_t len = 0; do { #define mode _SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_EACH | _SIDD_NEGATIVE_POLARITY __m128i xmm_src0, xmm_src1; - int ret; + uint32_t ret; xmm_src0 = _mm_loadu_si128((__m128i *)src0); xmm_src1 = _mm_loadu_si128((__m128i *)src1); - ret = _mm_cmpestri(xmm_src0, 16, xmm_src1, 16, mode); + ret = (uint32_t)_mm_cmpestri(xmm_src0, 16, xmm_src1, 16, mode); if (_mm_cmpestrc(xmm_src0, 16, xmm_src1, 16, mode)) { - return (int32_t)(len + ret); + return len + ret; } src0 += 16, src1 += 16, len += 16; xmm_src0 = _mm_loadu_si128((__m128i *)src0); xmm_src1 = _mm_loadu_si128((__m128i *)src1); - ret = _mm_cmpestri(xmm_src0, 16, xmm_src1, 16, mode); + ret = (uint32_t)_mm_cmpestri(xmm_src0, 16, xmm_src1, 16, mode); if (_mm_cmpestrc(xmm_src0, 16, xmm_src1, 16, mode)) { - return (int32_t)(len + ret); + return len + ret; } src0 += 16, src1 += 16, len += 16; } while (len < 256); @@ -54,14 +54,14 @@ static inline int32_t compare256_unaligned_sse4_static(const unsigned char *src0 return 256; } -static inline int32_t compare258_unaligned_sse4_static(const unsigned char *src0, const unsigned char *src1) { +static inline uint32_t compare258_unaligned_sse4_static(const unsigned char *src0, const unsigned char *src1) { if (*(uint16_t *)src0 != *(uint16_t *)src1) return (*src0 == *src1); return compare256_unaligned_sse4_static(src0+2, src1+2) + 2; } -Z_INTERNAL int32_t compare258_unaligned_sse4(const unsigned char *src0, const unsigned char *src1) { +Z_INTERNAL uint32_t compare258_unaligned_sse4(const unsigned char *src0, const unsigned char *src1) { return compare258_unaligned_sse4_static(src0, src1); } diff --git a/arch/x86/slide_avx.c b/arch/x86/slide_avx.c index c89f107f2..dd140912a 100644 --- a/arch/x86/slide_avx.c +++ b/arch/x86/slide_avx.c @@ -18,7 +18,7 @@ Z_INTERNAL void slide_hash_avx2(deflate_state *s) { Pos *p; unsigned n; uint16_t wsize = (uint16_t)s->w_size; - const __m256i zmm_wsize = _mm256_set1_epi16(wsize); + const __m256i zmm_wsize = _mm256_set1_epi16((short)wsize); n = HASH_SIZE; p = &s->head[n] - 16; diff --git a/arch/x86/slide_sse.c b/arch/x86/slide_sse.c index 7c9ee6be0..abf447475 100644 --- a/arch/x86/slide_sse.c +++ b/arch/x86/slide_sse.c @@ -17,7 +17,7 @@ Z_INTERNAL void slide_hash_sse2(deflate_state *s) { Pos *p; unsigned n; uint16_t wsize = (uint16_t)s->w_size; - const __m128i xmm_wsize = _mm_set1_epi16(wsize); + const __m128i xmm_wsize = _mm_set1_epi16((short)wsize); n = HASH_SIZE; p = &s->head[n] - 8; diff --git a/compare258.c b/compare258.c index 849c4e2a3..ab8c29abe 100644 --- a/compare258.c +++ b/compare258.c @@ -9,8 +9,8 @@ #include "fallback_builtins.h" /* ALIGNED, byte comparison */ -static inline int32_t compare256_c_static(const unsigned char *src0, const unsigned char *src1) { - int32_t len = 0; +static inline uint32_t compare256_c_static(const unsigned char *src0, const unsigned char *src1) { + uint32_t len = 0; do { if (*src0 != *src1) @@ -42,7 +42,7 @@ static inline int32_t compare256_c_static(const unsigned char *src0, const unsig return 256; } -static inline int32_t compare258_c_static(const unsigned char *src0, const unsigned char *src1) { +static inline uint32_t compare258_c_static(const unsigned char *src0, const unsigned char *src1) { if (*src0 != *src1) return 0; src0 += 1, src1 += 1; @@ -53,7 +53,7 @@ static inline int32_t compare258_c_static(const unsigned char *src0, const unsig return compare256_c_static(src0, src1) + 2; } -Z_INTERNAL int32_t compare258_c(const unsigned char *src0, const unsigned char *src1) { +Z_INTERNAL uint32_t compare258_c(const unsigned char *src0, const unsigned char *src1) { return compare258_c_static(src0, src1); } @@ -65,8 +65,8 @@ Z_INTERNAL int32_t compare258_c(const unsigned char *src0, const unsigned char * #ifdef UNALIGNED_OK /* UNALIGNED_OK, 16-bit integer comparison */ -static inline int32_t compare256_unaligned_16_static(const unsigned char *src0, const unsigned char *src1) { - int32_t len = 0; +static inline uint32_t compare256_unaligned_16_static(const unsigned char *src0, const unsigned char *src1) { + uint32_t len = 0; do { if (*(uint16_t *)src0 != *(uint16_t *)src1) @@ -86,14 +86,14 @@ static inline int32_t compare256_unaligned_16_static(const unsigned char *src0, return 256; } -static inline int32_t compare258_unaligned_16_static(const unsigned char *src0, const unsigned char *src1) { +static inline uint32_t compare258_unaligned_16_static(const unsigned char *src0, const unsigned char *src1) { if (*(uint16_t *)src0 != *(uint16_t *)src1) return (*src0 == *src1); return compare256_unaligned_16_static(src0+2, src1+2) + 2; } -Z_INTERNAL int32_t compare258_unaligned_16(const unsigned char *src0, const unsigned char *src1) { +Z_INTERNAL uint32_t compare258_unaligned_16(const unsigned char *src0, const unsigned char *src1) { return compare258_unaligned_16_static(src0, src1); } @@ -105,8 +105,8 @@ Z_INTERNAL int32_t compare258_unaligned_16(const unsigned char *src0, const unsi #ifdef HAVE_BUILTIN_CTZ /* UNALIGNED_OK, 32-bit integer comparison */ -static inline int32_t compare256_unaligned_32_static(const unsigned char *src0, const unsigned char *src1) { - int32_t len = 0; +static inline uint32_t compare256_unaligned_32_static(const unsigned char *src0, const unsigned char *src1) { + uint32_t len = 0; do { uint32_t sv = *(uint32_t *)src0; @@ -115,7 +115,7 @@ static inline int32_t compare256_unaligned_32_static(const unsigned char *src0, if (diff) { uint32_t match_byte = __builtin_ctz(diff) / 8; - return (int32_t)(len + match_byte); + return len + match_byte; } src0 += 4, src1 += 4, len += 4; @@ -124,14 +124,14 @@ static inline int32_t compare256_unaligned_32_static(const unsigned char *src0, return 256; } -static inline int32_t compare258_unaligned_32_static(const unsigned char *src0, const unsigned char *src1) { +static inline uint32_t compare258_unaligned_32_static(const unsigned char *src0, const unsigned char *src1) { if (*(uint16_t *)src0 != *(uint16_t *)src1) return (*src0 == *src1); return compare256_unaligned_32_static(src0+2, src1+2) + 2; } -Z_INTERNAL int32_t compare258_unaligned_32(const unsigned char *src0, const unsigned char *src1) { +Z_INTERNAL uint32_t compare258_unaligned_32(const unsigned char *src0, const unsigned char *src1) { return compare258_unaligned_32_static(src0, src1); } @@ -145,8 +145,8 @@ Z_INTERNAL int32_t compare258_unaligned_32(const unsigned char *src0, const unsi #if defined(UNALIGNED64_OK) && defined(HAVE_BUILTIN_CTZLL) /* UNALIGNED64_OK, 64-bit integer comparison */ -static inline int32_t compare256_unaligned_64_static(const unsigned char *src0, const unsigned char *src1) { - int32_t len = 0; +static inline uint32_t compare256_unaligned_64_static(const unsigned char *src0, const unsigned char *src1) { + uint32_t len = 0; do { uint64_t sv = *(uint64_t *)src0; @@ -155,7 +155,7 @@ static inline int32_t compare256_unaligned_64_static(const unsigned char *src0, if (diff) { uint64_t match_byte = __builtin_ctzll(diff) / 8; - return (int32_t)(len + match_byte); + return len + match_byte; } src0 += 8, src1 += 8, len += 8; @@ -164,14 +164,14 @@ static inline int32_t compare256_unaligned_64_static(const unsigned char *src0, return 256; } -static inline int32_t compare258_unaligned_64_static(const unsigned char *src0, const unsigned char *src1) { +static inline uint32_t compare258_unaligned_64_static(const unsigned char *src0, const unsigned char *src1) { if (*(uint16_t *)src0 != *(uint16_t *)src1) return (*src0 == *src1); return compare256_unaligned_64_static(src0+2, src1+2) + 2; } -Z_INTERNAL int32_t compare258_unaligned_64(const unsigned char *src0, const unsigned char *src1) { +Z_INTERNAL uint32_t compare258_unaligned_64(const unsigned char *src0, const unsigned char *src1) { return compare258_unaligned_64_static(src0, src1); } diff --git a/deflate_medium.c b/deflate_medium.c index d642c0141..a5b1b9a1e 100644 --- a/deflate_medium.c +++ b/deflate_medium.c @@ -213,7 +213,7 @@ Z_INTERNAL block_state deflate_medium(deflate_state *s, int flush) { * of window index 0 (in particular we have to avoid a match * of the string with itself at the start of the input file). */ - current_match.match_length = functable.longest_match(s, hash_head); + current_match.match_length = (uint16_t)functable.longest_match(s, hash_head); current_match.match_start = s->match_start; if (UNLIKELY(current_match.match_length < MIN_MATCH)) current_match.match_length = 1; @@ -246,7 +246,7 @@ Z_INTERNAL block_state deflate_medium(deflate_state *s, int flush) { * of window index 0 (in particular we have to avoid a match * of the string with itself at the start of the input file). */ - next_match.match_length = functable.longest_match(s, hash_head); + next_match.match_length = (uint16_t)functable.longest_match(s, hash_head); next_match.match_start = s->match_start; if (UNLIKELY(next_match.match_start >= next_match.strstart)) { /* this can happen due to some restarts */ diff --git a/functable.c b/functable.c index 1d4fe2a54..6f4f81566 100644 --- a/functable.c +++ b/functable.c @@ -95,34 +95,34 @@ extern uint32_t crc32_big(uint32_t, const unsigned char *, uint64_t); #endif /* compare258 */ -extern int32_t compare258_c(const unsigned char *src0, const unsigned char *src1); +extern uint32_t compare258_c(const unsigned char *src0, const unsigned char *src1); #ifdef UNALIGNED_OK -extern int32_t compare258_unaligned_16(const unsigned char *src0, const unsigned char *src1); -extern int32_t compare258_unaligned_32(const unsigned char *src0, const unsigned char *src1); +extern uint32_t compare258_unaligned_16(const unsigned char *src0, const unsigned char *src1); +extern uint32_t compare258_unaligned_32(const unsigned char *src0, const unsigned char *src1); #ifdef UNALIGNED64_OK -extern int32_t compare258_unaligned_64(const unsigned char *src0, const unsigned char *src1); +extern uint32_t compare258_unaligned_64(const unsigned char *src0, const unsigned char *src1); #endif #ifdef X86_SSE42_CMP_STR -extern int32_t compare258_unaligned_sse4(const unsigned char *src0, const unsigned char *src1); +extern uint32_t compare258_unaligned_sse4(const unsigned char *src0, const unsigned char *src1); #endif #if defined(X86_AVX2) && defined(HAVE_BUILTIN_CTZ) -extern int32_t compare258_unaligned_avx2(const unsigned char *src0, const unsigned char *src1); +extern uint32_t compare258_unaligned_avx2(const unsigned char *src0, const unsigned char *src1); #endif #endif /* longest_match */ -extern int32_t longest_match_c(deflate_state *const s, Pos cur_match); +extern uint32_t longest_match_c(deflate_state *const s, Pos cur_match); #ifdef UNALIGNED_OK -extern int32_t longest_match_unaligned_16(deflate_state *const s, Pos cur_match); -extern int32_t longest_match_unaligned_32(deflate_state *const s, Pos cur_match); +extern uint32_t longest_match_unaligned_16(deflate_state *const s, Pos cur_match); +extern uint32_t longest_match_unaligned_32(deflate_state *const s, Pos cur_match); #ifdef UNALIGNED64_OK -extern int32_t longest_match_unaligned_64(deflate_state *const s, Pos cur_match); +extern uint32_t longest_match_unaligned_64(deflate_state *const s, Pos cur_match); #endif #ifdef X86_SSE42_CMP_STR -extern int32_t longest_match_unaligned_sse4(deflate_state *const s, Pos cur_match); +extern uint32_t longest_match_unaligned_sse4(deflate_state *const s, Pos cur_match); #endif #if defined(X86_AVX2) && defined(HAVE_BUILTIN_CTZ) -extern int32_t longest_match_unaligned_avx2(deflate_state *const s, Pos cur_match); +extern uint32_t longest_match_unaligned_avx2(deflate_state *const s, Pos cur_match); #endif #endif @@ -365,7 +365,7 @@ Z_INTERNAL uint32_t crc32_stub(uint32_t crc, const unsigned char *buf, uint64_t return functable.crc32(crc, buf, len); } -Z_INTERNAL int32_t compare258_stub(const unsigned char *src0, const unsigned char *src1) { +Z_INTERNAL uint32_t compare258_stub(const unsigned char *src0, const unsigned char *src1) { functable.compare258 = &compare258_c; @@ -390,7 +390,7 @@ Z_INTERNAL int32_t compare258_stub(const unsigned char *src0, const unsigned cha return functable.compare258(src0, src1); } -Z_INTERNAL int32_t longest_match_stub(deflate_state *const s, Pos cur_match) { +Z_INTERNAL uint32_t longest_match_stub(deflate_state *const s, Pos cur_match) { functable.longest_match = &longest_match_c; diff --git a/functable.h b/functable.h index 22e62d4fb..276c284a0 100644 --- a/functable.h +++ b/functable.h @@ -14,8 +14,8 @@ struct functable_s { uint32_t (* adler32) (uint32_t adler, const unsigned char *buf, size_t len); uint32_t (* crc32) (uint32_t crc, const unsigned char *buf, uint64_t len); void (* slide_hash) (deflate_state *s); - int32_t (* compare258) (const unsigned char *src0, const unsigned char *src1); - int32_t (* longest_match) (deflate_state *const s, Pos cur_match); + uint32_t (* compare258) (const unsigned char *src0, const unsigned char *src1); + uint32_t (* longest_match) (deflate_state *const s, Pos cur_match); uint32_t (* chunksize) (void); uint8_t* (* chunkcopy) (uint8_t *out, uint8_t const *from, unsigned len); uint8_t* (* chunkcopy_safe) (uint8_t *out, uint8_t const *from, unsigned len, uint8_t *safe); diff --git a/match_tpl.h b/match_tpl.h index 823532cd2..da5a6cd81 100644 --- a/match_tpl.h +++ b/match_tpl.h @@ -28,7 +28,7 @@ typedef uint8_t bestcmp_t; * string (strstart) and its distance is <= MAX_DIST, and prev_length >=1 * OUT assertion: the match length is not greater than s->lookahead */ -Z_INTERNAL int32_t LONGEST_MATCH(deflate_state *const s, Pos cur_match) { +Z_INTERNAL uint32_t LONGEST_MATCH(deflate_state *const s, Pos cur_match) { unsigned int strstart = s->strstart; const unsigned wmask = s->w_mask; unsigned char *window = s->window;