From: Nathan Moinvaziri Date: Sat, 13 Dec 2025 01:50:15 +0000 (-0800) Subject: Use different bit accumulator type for x86 compiler optimization X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=HEAD;p=thirdparty%2Fzlib-ng.git Use different bit accumulator type for x86 compiler optimization --- diff --git a/infback.c b/infback.c index dca46dab..b3b6d86d 100644 --- a/infback.c +++ b/infback.c @@ -154,7 +154,7 @@ int32_t Z_EXPORT PREFIX(inflateBack)(PREFIX3(stream) *strm, in_func in, void *in unsigned char *put; /* next output */ unsigned have, left; /* available input and output */ uint64_t hold; /* bit buffer */ - uint8_t bits; /* bits in bit buffer */ + bits_t bits; /* bits in bit buffer */ unsigned copy; /* number of stored or match bytes to copy */ unsigned char *from; /* where to copy match bytes from */ code here; /* current decoding table entry */ diff --git a/inffast_tpl.h b/inffast_tpl.h index 316bd3a3..4798d81e 100644 --- a/inffast_tpl.h +++ b/inffast_tpl.h @@ -101,7 +101,7 @@ void Z_INTERNAL INFLATE_FAST(PREFIX3(stream) *strm, uint32_t start) { with (1<hold >> state->bits) == 0. */ - uint8_t bits; /* local strm->bits */ + bits_t bits; /* local strm->bits */ uint64_t hold; /* local strm->hold */ unsigned lmask; /* mask for first level of length codes */ unsigned dmask; /* mask for first level of distance codes */ @@ -128,7 +128,7 @@ void Z_INTERNAL INFLATE_FAST(PREFIX3(stream) *strm, uint32_t start) { wnext = state->wnext; window = state->window; hold = state->hold; - bits = (uint8_t)state->bits; + bits = (bits_t)state->bits; lcode = state->lencode; dcode = state->distcode; lmask = (1U << state->lenbits) - 1; @@ -305,7 +305,7 @@ void Z_INTERNAL INFLATE_FAST(PREFIX3(stream) *strm, uint32_t start) { /* return unused bytes (on entry, bits < 8, so in won't go too far back) */ len = bits >> 3; in -= len; - bits -= (uint8_t)(len << 3); + bits -= (bits_t)(len << 3); hold &= (UINT64_C(1) << bits) - 1; /* update state and return */ diff --git a/inflate.c b/inflate.c index edba74cb..4cac4817 100644 --- a/inflate.c +++ b/inflate.c @@ -479,7 +479,7 @@ int32_t Z_EXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int32_t flush) { unsigned char *from; /* where to copy match bytes from */ unsigned have, left; /* available input and output */ uint64_t hold; /* bit buffer */ - unsigned bits; /* bits in bit buffer */ + bits_t bits; /* bits in bit buffer */ uint32_t in, out; /* save starting available input and output */ unsigned copy; /* number of stored or match bytes to copy */ code here; /* current decoding table entry */ diff --git a/inflate_p.h b/inflate_p.h index 425709ae..fad4b53f 100644 --- a/inflate_p.h +++ b/inflate_p.h @@ -72,6 +72,13 @@ } while (0) #endif +/* Compiler optimization for bit accumulator on x86 architectures */ +#if defined(__x86_64__) || defined(__i386__) +typedef uint8_t bits_t; +#else +typedef unsigned bits_t; +#endif + /* Load registers with state in inflate() for speed */ #define LOAD() \ do { \ @@ -80,7 +87,7 @@ next = strm->next_in; \ have = strm->avail_in; \ hold = state->hold; \ - bits = (uint8_t)state->bits; \ + bits = (bits_t)state->bits; \ } while (0) /* Restore state from registers in inflate() */ @@ -105,7 +112,7 @@ not enough available input to do that, then return from inflate()/inflateBack(). */ #define NEEDBITS(n) \ do { \ - while (bits < (uint8_t)(n)) \ + while (bits < (bits_t)(n)) \ PULLBYTE(); \ } while (0) @@ -117,7 +124,7 @@ #define DROPBITS(n) \ do { \ hold >>= (n); \ - bits -= (uint8_t)(n); \ + bits -= (bits_t)(n); \ } while (0) /* Remove zero to seven bits as needed to go to a byte boundary */