From: Dougall Johnson Date: Mon, 22 Aug 2022 01:44:41 +0000 (+1000) Subject: Inflate: add fast-path for literals X-Git-Tag: 2.1.0-beta1~33 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6a74e9294f12e879d792376bf98ed720f7362d7d;p=thirdparty%2Fzlib-ng.git Inflate: add fast-path for literals --- diff --git a/inffast_tpl.h b/inffast_tpl.h index c209021b..9ddd187d 100644 --- a/inffast_tpl.h +++ b/inffast_tpl.h @@ -145,15 +145,10 @@ void Z_INTERNAL INFLATE_FAST(PREFIX3(stream) *strm, uint32_t start) { window is overwritten then future matches with far distances will fail to copy correctly. */ extra_safe = (wsize != 0 && out >= window && out + INFLATE_FAST_MIN_LEFT <= window + wsize); - /* This is extremely latency sensitive, so empty inline assembly blocks are - used to prevent the compiler from reassociating. */ #define REFILL() do { \ hold |= load_64_bits(in, bits); \ in += 7; \ - __asm__ volatile ("" : "+r"(in)); \ - uint64_t tmp = ((bits >> 3) & 7); \ - __asm__ volatile ("" : "+r"(tmp)); \ - in -= tmp; \ + in -= ((bits >> 3) & 7); \ bits |= 56; \ } while (0) @@ -162,6 +157,16 @@ void Z_INTERNAL INFLATE_FAST(PREFIX3(stream) *strm, uint32_t start) { do { REFILL(); here = lcode + (hold & lmask); + if (here->op == 0) { + *out++ = (unsigned char)(here->val); + DROPBITS(here->bits); + here = lcode + (hold & lmask); + if (here->op == 0) { + *out++ = (unsigned char)(here->val); + DROPBITS(here->bits); + here = lcode + (hold & lmask); + } + } dolen: DROPBITS(here->bits); op = here->op; @@ -177,6 +182,9 @@ void Z_INTERNAL INFLATE_FAST(PREFIX3(stream) *strm, uint32_t start) { DROPBITS(op); Tracevv((stderr, "inflate: length %u\n", len)); here = dcode + (hold & dmask); + if (bits < MAX_BITS + MAX_DIST_EXTRA_BITS) { + REFILL(); + } dodist: DROPBITS(here->bits); op = here->op; diff --git a/inflate_p.h b/inflate_p.h index 2b57b317..a007cd05 100644 --- a/inflate_p.h +++ b/inflate_p.h @@ -132,8 +132,8 @@ strm->msg = (char *)errmsg; \ } while (0) -#define INFLATE_FAST_MIN_HAVE 8 -#define INFLATE_FAST_MIN_LEFT 258 +#define INFLATE_FAST_MIN_HAVE 15 +#define INFLATE_FAST_MIN_LEFT 260 /* Load 64 bits from IN and place the bytes at offset BITS in the result. */ static inline uint64_t load_64_bits(const unsigned char *in, unsigned bits) { diff --git a/zutil.h b/zutil.h index 7b9a8b09..663616b4 100644 --- a/zutil.h +++ b/zutil.h @@ -38,6 +38,8 @@ extern z_const char * const PREFIX(z_errmsg)[10]; /* indexed by 2-zlib_error */ #define MAX_BITS 15 /* all codes must not exceed MAX_BITS bits */ +#define MAX_DIST_EXTRA_BITS 13 +/* maximum number of extra distance bits */ #if MAX_MEM_LEVEL >= 8 # define DEF_MEM_LEVEL 8