1 /* inffast_chunk.h -- header to use inffast_chunk.c 2 * Copyright (C) 1995-2003, 2010 Mark Adler 3 * Copyright (C) 2017 ARM, Inc. 4 * Copyright 2023 The Chromium Authors 5 * For conditions of distribution and use, see copyright notice in zlib.h 6 */ 7 8 /* WARNING: this file should *not* be used by applications. It is 9 part of the implementation of the compression library and is 10 subject to change. Applications should only use zlib.h. 11 */ 12 13 #include "inffast.h" 14 15 /* INFLATE_FAST_MIN_INPUT: 16 The minimum number of input bytes needed so that we can safely call 17 inflate_fast() with only one up-front bounds check. One 18 length/distance code pair (15 bits for the length code, 5 bits for length 19 extra, 15 bits for the distance code, 13 bits for distance extra) requires 20 reading up to 48 input bits. Additionally, in the same iteraction, we may 21 decode two literals from the root-table (requiring MIN_OUTPUT = 258 + 2). 22 23 Each root-table entry is up to 10 bits, for a total of 68 input bits each 24 iteraction. 25 26 The refill variant reads 8 bytes from the buffer at a time, and advances 27 the input pointer by up to 7 bytes, ensuring there are at least 56-bits 28 available in the bit-buffer. The technique was documented by Fabian Giesen 29 on his blog as variant 4 in the article 'Reading bits in far too many ways': 30 https://fgiesen.wordpress.com/2018/02/20/ 31 32 In the worst case, we may refill twice in the same iteraction, requiring 33 MIN_INPUT = 8 + 7. 34 */ 35 #ifdef INFLATE_CHUNK_READ_64LE 36 #undef INFLATE_FAST_MIN_INPUT 37 #define INFLATE_FAST_MIN_INPUT 15 38 #undef INFLATE_FAST_MIN_OUTPUT 39 #define INFLATE_FAST_MIN_OUTPUT 260 40 #endif 41 42 void ZLIB_INTERNAL inflate_fast_chunk_(z_streamp strm, unsigned start); 43