Skip to content
Permalink
Browse files
Inflate: Use zero-latency refill strategy
This requires refilling while there are still enough bits in the
buffer for the next table lookup. The next table lookup can then
use the old bit-buffer and then shift the refilled bit-buffer,
completely removing the refill from the critical path.
  • Loading branch information
dougallj committed Aug 26, 2022
1 parent efa5a2d commit 315b6636bfca5797f7e7d037e29c5edd2c605e70
Showing 1 changed file with 22 additions and 2 deletions.
@@ -167,11 +167,20 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
memcpy(&here, &here32, sizeof(code)); \
} while (0)

if (bits < 10) {
REFILL();
}

/* decode literals and length/distances until end-of-block or not enough
input data or output space */
do {
REFILL();
uint64_t next_hold = hold | (read64le(in) << bits);
in += 7;
uint64_t tmp = ((bits >> 3) & 7);
in -= tmp;
bits |= 56;
TABLE_LOAD(lcode, hold & lmask);
hold = next_hold;
old = hold;
hold >>= here.bits;
bits -= here32;
@@ -223,9 +232,20 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
break;
}
#endif
if (unlikely((bits & 63) < 10)) {
REFILL();
}

/* preload and shift for next iteration */
REFILL();
uint64_t next_hold = hold | (read64le(in) << bits);
in += 7;
asm volatile ("" : "+r"(in));
uint64_t tmp = ((bits >> 3) & 7);
asm volatile ("" : "+r"(tmp));
in -= tmp;
bits |= 56;
TABLE_LOAD(lcode, hold & lmask);
hold = next_hold;
old = hold;
hold >>= here.bits;
bits -= here32;

0 comments on commit 315b663

Please sign in to comment.