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