11cb0ef41Sopenharmony_ci/* deflate.h -- internal compression state
21cb0ef41Sopenharmony_ci * Copyright (C) 1995-2018 Jean-loup Gailly
31cb0ef41Sopenharmony_ci * For conditions of distribution and use, see copyright notice in zlib.h
41cb0ef41Sopenharmony_ci */
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ci/* WARNING: this file should *not* be used by applications. It is
71cb0ef41Sopenharmony_ci   part of the implementation of the compression library and is
81cb0ef41Sopenharmony_ci   subject to change. Applications should only use zlib.h.
91cb0ef41Sopenharmony_ci */
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ci/* @(#) $Id$ */
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci#ifndef DEFLATE_H
141cb0ef41Sopenharmony_ci#define DEFLATE_H
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci#include "zutil.h"
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ci/* define NO_GZIP when compiling if you want to disable gzip header and
191cb0ef41Sopenharmony_ci   trailer creation by deflate().  NO_GZIP would be used to avoid linking in
201cb0ef41Sopenharmony_ci   the crc code when it is not needed.  For shared libraries, gzip encoding
211cb0ef41Sopenharmony_ci   should be left enabled. */
221cb0ef41Sopenharmony_ci#ifndef NO_GZIP
231cb0ef41Sopenharmony_ci#  define GZIP
241cb0ef41Sopenharmony_ci#endif
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci/* define LIT_MEM to slightly increase the speed of deflate (order 1% to 2%) at
271cb0ef41Sopenharmony_ci   the cost of a larger memory footprint */
281cb0ef41Sopenharmony_ci#define LIT_MEM
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ci/* ===========================================================================
311cb0ef41Sopenharmony_ci * Internal compression state.
321cb0ef41Sopenharmony_ci */
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ci#define LENGTH_CODES 29
351cb0ef41Sopenharmony_ci/* number of length codes, not counting the special END_BLOCK code */
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ci#define LITERALS  256
381cb0ef41Sopenharmony_ci/* number of literal bytes 0..255 */
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ci#define L_CODES (LITERALS+1+LENGTH_CODES)
411cb0ef41Sopenharmony_ci/* number of Literal or Length codes, including the END_BLOCK code */
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ci#define D_CODES   30
441cb0ef41Sopenharmony_ci/* number of distance codes */
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_ci#define BL_CODES  19
471cb0ef41Sopenharmony_ci/* number of codes used to transfer the bit lengths */
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_ci#define HEAP_SIZE (2*L_CODES+1)
501cb0ef41Sopenharmony_ci/* maximum heap size */
511cb0ef41Sopenharmony_ci
521cb0ef41Sopenharmony_ci#define MAX_BITS 15
531cb0ef41Sopenharmony_ci/* All codes must not exceed MAX_BITS bits */
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ci#define Buf_size 16
561cb0ef41Sopenharmony_ci/* size of bit buffer in bi_buf */
571cb0ef41Sopenharmony_ci
581cb0ef41Sopenharmony_ci#define INIT_STATE    42    /* zlib header -> BUSY_STATE */
591cb0ef41Sopenharmony_ci#ifdef GZIP
601cb0ef41Sopenharmony_ci#  define GZIP_STATE  57    /* gzip header -> BUSY_STATE | EXTRA_STATE */
611cb0ef41Sopenharmony_ci#endif
621cb0ef41Sopenharmony_ci#define EXTRA_STATE   69    /* gzip extra block -> NAME_STATE */
631cb0ef41Sopenharmony_ci#define NAME_STATE    73    /* gzip file name -> COMMENT_STATE */
641cb0ef41Sopenharmony_ci#define COMMENT_STATE 91    /* gzip comment -> HCRC_STATE */
651cb0ef41Sopenharmony_ci#define HCRC_STATE   103    /* gzip header CRC -> BUSY_STATE */
661cb0ef41Sopenharmony_ci#define BUSY_STATE   113    /* deflate -> FINISH_STATE */
671cb0ef41Sopenharmony_ci#define FINISH_STATE 666    /* stream complete */
681cb0ef41Sopenharmony_ci/* Stream status */
691cb0ef41Sopenharmony_ci
701cb0ef41Sopenharmony_ci
711cb0ef41Sopenharmony_ci/* Data structure describing a single value and its code string. */
721cb0ef41Sopenharmony_citypedef struct ct_data_s {
731cb0ef41Sopenharmony_ci    union {
741cb0ef41Sopenharmony_ci        ush  freq;       /* frequency count */
751cb0ef41Sopenharmony_ci        ush  code;       /* bit string */
761cb0ef41Sopenharmony_ci    } fc;
771cb0ef41Sopenharmony_ci    union {
781cb0ef41Sopenharmony_ci        ush  dad;        /* father node in Huffman tree */
791cb0ef41Sopenharmony_ci        ush  len;        /* length of bit string */
801cb0ef41Sopenharmony_ci    } dl;
811cb0ef41Sopenharmony_ci} FAR ct_data;
821cb0ef41Sopenharmony_ci
831cb0ef41Sopenharmony_ci#define Freq fc.freq
841cb0ef41Sopenharmony_ci#define Code fc.code
851cb0ef41Sopenharmony_ci#define Dad  dl.dad
861cb0ef41Sopenharmony_ci#define Len  dl.len
871cb0ef41Sopenharmony_ci
881cb0ef41Sopenharmony_citypedef struct static_tree_desc_s  static_tree_desc;
891cb0ef41Sopenharmony_ci
901cb0ef41Sopenharmony_citypedef struct tree_desc_s {
911cb0ef41Sopenharmony_ci    ct_data *dyn_tree;           /* the dynamic tree */
921cb0ef41Sopenharmony_ci    int     max_code;            /* largest code with non zero frequency */
931cb0ef41Sopenharmony_ci    const static_tree_desc *stat_desc;  /* the corresponding static tree */
941cb0ef41Sopenharmony_ci} FAR tree_desc;
951cb0ef41Sopenharmony_ci
961cb0ef41Sopenharmony_citypedef ush Pos;
971cb0ef41Sopenharmony_citypedef Pos FAR Posf;
981cb0ef41Sopenharmony_citypedef unsigned IPos;
991cb0ef41Sopenharmony_ci
1001cb0ef41Sopenharmony_ci/* A Pos is an index in the character window. We use short instead of int to
1011cb0ef41Sopenharmony_ci * save space in the various tables. IPos is used only for parameter passing.
1021cb0ef41Sopenharmony_ci */
1031cb0ef41Sopenharmony_ci
1041cb0ef41Sopenharmony_citypedef struct internal_state {
1051cb0ef41Sopenharmony_ci    z_streamp strm;      /* pointer back to this zlib stream */
1061cb0ef41Sopenharmony_ci    int   status;        /* as the name implies */
1071cb0ef41Sopenharmony_ci    Bytef *pending_buf;  /* output still pending */
1081cb0ef41Sopenharmony_ci    ulg   pending_buf_size; /* size of pending_buf */
1091cb0ef41Sopenharmony_ci    Bytef *pending_out;  /* next pending byte to output to the stream */
1101cb0ef41Sopenharmony_ci    ulg   pending;       /* nb of bytes in the pending buffer */
1111cb0ef41Sopenharmony_ci    int   wrap;          /* bit 0 true for zlib, bit 1 true for gzip */
1121cb0ef41Sopenharmony_ci    gz_headerp  gzhead;  /* gzip header information to write */
1131cb0ef41Sopenharmony_ci    ulg   gzindex;       /* where in extra, name, or comment */
1141cb0ef41Sopenharmony_ci    Byte  method;        /* can only be DEFLATED */
1151cb0ef41Sopenharmony_ci    int   last_flush;    /* value of flush param for previous deflate call */
1161cb0ef41Sopenharmony_ci    unsigned crc0[4 * 5];
1171cb0ef41Sopenharmony_ci    /* used by deflate.c: */
1181cb0ef41Sopenharmony_ci
1191cb0ef41Sopenharmony_ci    uInt  w_size;        /* LZ77 window size (32K by default) */
1201cb0ef41Sopenharmony_ci    uInt  w_bits;        /* log2(w_size)  (8..16) */
1211cb0ef41Sopenharmony_ci    uInt  w_mask;        /* w_size - 1 */
1221cb0ef41Sopenharmony_ci
1231cb0ef41Sopenharmony_ci    Bytef *window;
1241cb0ef41Sopenharmony_ci    /* Sliding window. Input bytes are read into the second half of the window,
1251cb0ef41Sopenharmony_ci     * and move to the first half later to keep a dictionary of at least wSize
1261cb0ef41Sopenharmony_ci     * bytes. With this organization, matches are limited to a distance of
1271cb0ef41Sopenharmony_ci     * wSize-MAX_MATCH bytes, but this ensures that IO is always
1281cb0ef41Sopenharmony_ci     * performed with a length multiple of the block size. Also, it limits
1291cb0ef41Sopenharmony_ci     * the window size to 64K, which is quite useful on MSDOS.
1301cb0ef41Sopenharmony_ci     * To do: use the user input buffer as sliding window.
1311cb0ef41Sopenharmony_ci     */
1321cb0ef41Sopenharmony_ci
1331cb0ef41Sopenharmony_ci    ulg window_size;
1341cb0ef41Sopenharmony_ci    /* Actual size of window: 2*wSize, except when the user input buffer
1351cb0ef41Sopenharmony_ci     * is directly used as sliding window.
1361cb0ef41Sopenharmony_ci     */
1371cb0ef41Sopenharmony_ci
1381cb0ef41Sopenharmony_ci    Posf *prev;
1391cb0ef41Sopenharmony_ci    /* Link to older string with same hash index. To limit the size of this
1401cb0ef41Sopenharmony_ci     * array to 64K, this link is maintained only for the last 32K strings.
1411cb0ef41Sopenharmony_ci     * An index in this array is thus a window index modulo 32K.
1421cb0ef41Sopenharmony_ci     */
1431cb0ef41Sopenharmony_ci
1441cb0ef41Sopenharmony_ci    Posf *head; /* Heads of the hash chains or NIL. */
1451cb0ef41Sopenharmony_ci
1461cb0ef41Sopenharmony_ci    uInt  ins_h;          /* hash index of string to be inserted */
1471cb0ef41Sopenharmony_ci    uInt  hash_size;      /* number of elements in hash table */
1481cb0ef41Sopenharmony_ci    uInt  hash_bits;      /* log2(hash_size) */
1491cb0ef41Sopenharmony_ci    uInt  hash_mask;      /* hash_size-1 */
1501cb0ef41Sopenharmony_ci
1511cb0ef41Sopenharmony_ci    uInt  hash_shift;
1521cb0ef41Sopenharmony_ci    /* Number of bits by which ins_h must be shifted at each input
1531cb0ef41Sopenharmony_ci     * step. It must be such that after MIN_MATCH steps, the oldest
1541cb0ef41Sopenharmony_ci     * byte no longer takes part in the hash key, that is:
1551cb0ef41Sopenharmony_ci     *   hash_shift * MIN_MATCH >= hash_bits
1561cb0ef41Sopenharmony_ci     */
1571cb0ef41Sopenharmony_ci
1581cb0ef41Sopenharmony_ci    long block_start;
1591cb0ef41Sopenharmony_ci    /* Window position at the beginning of the current output block. Gets
1601cb0ef41Sopenharmony_ci     * negative when the window is moved backwards.
1611cb0ef41Sopenharmony_ci     */
1621cb0ef41Sopenharmony_ci
1631cb0ef41Sopenharmony_ci    uInt match_length;           /* length of best match */
1641cb0ef41Sopenharmony_ci    IPos prev_match;             /* previous match */
1651cb0ef41Sopenharmony_ci    int match_available;         /* set if previous match exists */
1661cb0ef41Sopenharmony_ci    uInt strstart;               /* start of string to insert */
1671cb0ef41Sopenharmony_ci    uInt match_start;            /* start of matching string */
1681cb0ef41Sopenharmony_ci    uInt lookahead;              /* number of valid bytes ahead in window */
1691cb0ef41Sopenharmony_ci
1701cb0ef41Sopenharmony_ci    uInt prev_length;
1711cb0ef41Sopenharmony_ci    /* Length of the best match at previous step. Matches not greater than this
1721cb0ef41Sopenharmony_ci     * are discarded. This is used in the lazy match evaluation.
1731cb0ef41Sopenharmony_ci     */
1741cb0ef41Sopenharmony_ci
1751cb0ef41Sopenharmony_ci    uInt max_chain_length;
1761cb0ef41Sopenharmony_ci    /* To speed up deflation, hash chains are never searched beyond this
1771cb0ef41Sopenharmony_ci     * length.  A higher limit improves compression ratio but degrades the
1781cb0ef41Sopenharmony_ci     * speed.
1791cb0ef41Sopenharmony_ci     */
1801cb0ef41Sopenharmony_ci
1811cb0ef41Sopenharmony_ci    uInt max_lazy_match;
1821cb0ef41Sopenharmony_ci    /* Attempt to find a better match only when the current match is strictly
1831cb0ef41Sopenharmony_ci     * smaller than this value. This mechanism is used only for compression
1841cb0ef41Sopenharmony_ci     * levels >= 4.
1851cb0ef41Sopenharmony_ci     */
1861cb0ef41Sopenharmony_ci#   define max_insert_length  max_lazy_match
1871cb0ef41Sopenharmony_ci    /* Insert new strings in the hash table only if the match length is not
1881cb0ef41Sopenharmony_ci     * greater than this length. This saves time but degrades compression.
1891cb0ef41Sopenharmony_ci     * max_insert_length is used only for compression levels <= 3.
1901cb0ef41Sopenharmony_ci     */
1911cb0ef41Sopenharmony_ci
1921cb0ef41Sopenharmony_ci    int level;    /* compression level (1..9) */
1931cb0ef41Sopenharmony_ci    int strategy; /* favor or force Huffman coding*/
1941cb0ef41Sopenharmony_ci
1951cb0ef41Sopenharmony_ci    uInt good_match;
1961cb0ef41Sopenharmony_ci    /* Use a faster search when the previous match is longer than this */
1971cb0ef41Sopenharmony_ci
1981cb0ef41Sopenharmony_ci    int nice_match; /* Stop searching when current match exceeds this */
1991cb0ef41Sopenharmony_ci
2001cb0ef41Sopenharmony_ci                /* used by trees.c: */
2011cb0ef41Sopenharmony_ci    /* Didn't use ct_data typedef below to suppress compiler warning */
2021cb0ef41Sopenharmony_ci    struct ct_data_s dyn_ltree[HEAP_SIZE];   /* literal and length tree */
2031cb0ef41Sopenharmony_ci    struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
2041cb0ef41Sopenharmony_ci    struct ct_data_s bl_tree[2*BL_CODES+1];  /* Huffman tree for bit lengths */
2051cb0ef41Sopenharmony_ci
2061cb0ef41Sopenharmony_ci    struct tree_desc_s l_desc;               /* desc. for literal tree */
2071cb0ef41Sopenharmony_ci    struct tree_desc_s d_desc;               /* desc. for distance tree */
2081cb0ef41Sopenharmony_ci    struct tree_desc_s bl_desc;              /* desc. for bit length tree */
2091cb0ef41Sopenharmony_ci
2101cb0ef41Sopenharmony_ci    ush bl_count[MAX_BITS+1];
2111cb0ef41Sopenharmony_ci    /* number of codes at each bit length for an optimal tree */
2121cb0ef41Sopenharmony_ci
2131cb0ef41Sopenharmony_ci    int heap[2*L_CODES+1];      /* heap used to build the Huffman trees */
2141cb0ef41Sopenharmony_ci    int heap_len;               /* number of elements in the heap */
2151cb0ef41Sopenharmony_ci    int heap_max;               /* element of largest frequency */
2161cb0ef41Sopenharmony_ci    /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
2171cb0ef41Sopenharmony_ci     * The same heap array is used to build all trees.
2181cb0ef41Sopenharmony_ci     */
2191cb0ef41Sopenharmony_ci
2201cb0ef41Sopenharmony_ci    uch depth[2*L_CODES+1];
2211cb0ef41Sopenharmony_ci    /* Depth of each subtree used as tie breaker for trees of equal frequency
2221cb0ef41Sopenharmony_ci     */
2231cb0ef41Sopenharmony_ci
2241cb0ef41Sopenharmony_ci#ifdef LIT_MEM
2251cb0ef41Sopenharmony_ci    ushf *d_buf;          /* buffer for distances */
2261cb0ef41Sopenharmony_ci    uchf *l_buf;          /* buffer for literals/lengths */
2271cb0ef41Sopenharmony_ci#else
2281cb0ef41Sopenharmony_ci    uchf *sym_buf;        /* buffer for distances and literals/lengths */
2291cb0ef41Sopenharmony_ci#endif
2301cb0ef41Sopenharmony_ci
2311cb0ef41Sopenharmony_ci    uInt  lit_bufsize;
2321cb0ef41Sopenharmony_ci    /* Size of match buffer for literals/lengths.  There are 4 reasons for
2331cb0ef41Sopenharmony_ci     * limiting lit_bufsize to 64K:
2341cb0ef41Sopenharmony_ci     *   - frequencies can be kept in 16 bit counters
2351cb0ef41Sopenharmony_ci     *   - if compression is not successful for the first block, all input
2361cb0ef41Sopenharmony_ci     *     data is still in the window so we can still emit a stored block even
2371cb0ef41Sopenharmony_ci     *     when input comes from standard input.  (This can also be done for
2381cb0ef41Sopenharmony_ci     *     all blocks if lit_bufsize is not greater than 32K.)
2391cb0ef41Sopenharmony_ci     *   - if compression is not successful for a file smaller than 64K, we can
2401cb0ef41Sopenharmony_ci     *     even emit a stored file instead of a stored block (saving 5 bytes).
2411cb0ef41Sopenharmony_ci     *     This is applicable only for zip (not gzip or zlib).
2421cb0ef41Sopenharmony_ci     *   - creating new Huffman trees less frequently may not provide fast
2431cb0ef41Sopenharmony_ci     *     adaptation to changes in the input data statistics. (Take for
2441cb0ef41Sopenharmony_ci     *     example a binary file with poorly compressible code followed by
2451cb0ef41Sopenharmony_ci     *     a highly compressible string table.) Smaller buffer sizes give
2461cb0ef41Sopenharmony_ci     *     fast adaptation but have of course the overhead of transmitting
2471cb0ef41Sopenharmony_ci     *     trees more frequently.
2481cb0ef41Sopenharmony_ci     *   - I can't count above 4
2491cb0ef41Sopenharmony_ci     */
2501cb0ef41Sopenharmony_ci
2511cb0ef41Sopenharmony_ci    uInt sym_next;      /* running index in symbol buffer */
2521cb0ef41Sopenharmony_ci    uInt sym_end;       /* symbol table full when sym_next reaches this */
2531cb0ef41Sopenharmony_ci
2541cb0ef41Sopenharmony_ci    ulg opt_len;        /* bit length of current block with optimal trees */
2551cb0ef41Sopenharmony_ci    ulg static_len;     /* bit length of current block with static trees */
2561cb0ef41Sopenharmony_ci    uInt matches;       /* number of string matches in current block */
2571cb0ef41Sopenharmony_ci    uInt insert;        /* bytes at end of window left to insert */
2581cb0ef41Sopenharmony_ci
2591cb0ef41Sopenharmony_ci#ifdef ZLIB_DEBUG
2601cb0ef41Sopenharmony_ci    ulg compressed_len; /* total bit length of compressed file mod 2^32 */
2611cb0ef41Sopenharmony_ci    ulg bits_sent;      /* bit length of compressed data sent mod 2^32 */
2621cb0ef41Sopenharmony_ci#endif
2631cb0ef41Sopenharmony_ci
2641cb0ef41Sopenharmony_ci    ush bi_buf;
2651cb0ef41Sopenharmony_ci    /* Output buffer. bits are inserted starting at the bottom (least
2661cb0ef41Sopenharmony_ci     * significant bits).
2671cb0ef41Sopenharmony_ci     */
2681cb0ef41Sopenharmony_ci    int bi_valid;
2691cb0ef41Sopenharmony_ci    /* Number of valid bits in bi_buf.  All bits above the last valid bit
2701cb0ef41Sopenharmony_ci     * are always zero.
2711cb0ef41Sopenharmony_ci     */
2721cb0ef41Sopenharmony_ci
2731cb0ef41Sopenharmony_ci    ulg high_water;
2741cb0ef41Sopenharmony_ci    /* High water mark offset in window for initialized bytes -- bytes above
2751cb0ef41Sopenharmony_ci     * this are set to zero in order to avoid memory check warnings when
2761cb0ef41Sopenharmony_ci     * longest match routines access bytes past the input.  This is then
2771cb0ef41Sopenharmony_ci     * updated to the new high water mark.
2781cb0ef41Sopenharmony_ci     */
2791cb0ef41Sopenharmony_ci
2801cb0ef41Sopenharmony_ci    uInt chromium_zlib_hash;
2811cb0ef41Sopenharmony_ci    /* 0 if Rabin-Karp rolling hash is enabled, non-zero if chromium zlib
2821cb0ef41Sopenharmony_ci     * hash is enabled.
2831cb0ef41Sopenharmony_ci     */
2841cb0ef41Sopenharmony_ci
2851cb0ef41Sopenharmony_ci} FAR deflate_state;
2861cb0ef41Sopenharmony_ci
2871cb0ef41Sopenharmony_ci/* Output a byte on the stream.
2881cb0ef41Sopenharmony_ci * IN assertion: there is enough room in pending_buf.
2891cb0ef41Sopenharmony_ci */
2901cb0ef41Sopenharmony_ci#define put_byte(s, c) {s->pending_buf[s->pending++] = (Bytef)(c);}
2911cb0ef41Sopenharmony_ci
2921cb0ef41Sopenharmony_ci
2931cb0ef41Sopenharmony_ci#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
2941cb0ef41Sopenharmony_ci/* Minimum amount of lookahead, except at the end of the input file.
2951cb0ef41Sopenharmony_ci * See deflate.c for comments about the MIN_MATCH+1.
2961cb0ef41Sopenharmony_ci */
2971cb0ef41Sopenharmony_ci
2981cb0ef41Sopenharmony_ci#define MAX_DIST(s)  ((s)->w_size-MIN_LOOKAHEAD)
2991cb0ef41Sopenharmony_ci/* In order to simplify the code, particularly on 16 bit machines, match
3001cb0ef41Sopenharmony_ci * distances are limited to MAX_DIST instead of WSIZE.
3011cb0ef41Sopenharmony_ci */
3021cb0ef41Sopenharmony_ci
3031cb0ef41Sopenharmony_ci#define WIN_INIT MAX_MATCH
3041cb0ef41Sopenharmony_ci/* Number of bytes after end of data in window to initialize in order to avoid
3051cb0ef41Sopenharmony_ci   memory checker errors from longest match routines */
3061cb0ef41Sopenharmony_ci
3071cb0ef41Sopenharmony_ci        /* in trees.c */
3081cb0ef41Sopenharmony_civoid ZLIB_INTERNAL _tr_init(deflate_state *s);
3091cb0ef41Sopenharmony_ciint ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc);
3101cb0ef41Sopenharmony_civoid ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf,
3111cb0ef41Sopenharmony_ci                                   ulg stored_len, int last);
3121cb0ef41Sopenharmony_civoid ZLIB_INTERNAL _tr_flush_bits(deflate_state *s);
3131cb0ef41Sopenharmony_civoid ZLIB_INTERNAL _tr_align(deflate_state *s);
3141cb0ef41Sopenharmony_civoid ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf,
3151cb0ef41Sopenharmony_ci                                    ulg stored_len, int last);
3161cb0ef41Sopenharmony_ci
3171cb0ef41Sopenharmony_ci#define d_code(dist) \
3181cb0ef41Sopenharmony_ci   ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
3191cb0ef41Sopenharmony_ci/* Mapping from a distance to a distance code. dist is the distance - 1 and
3201cb0ef41Sopenharmony_ci * must not have side effects. _dist_code[256] and _dist_code[257] are never
3211cb0ef41Sopenharmony_ci * used.
3221cb0ef41Sopenharmony_ci */
3231cb0ef41Sopenharmony_ci
3241cb0ef41Sopenharmony_ci#ifndef ZLIB_DEBUG
3251cb0ef41Sopenharmony_ci/* Inline versions of _tr_tally for speed: */
3261cb0ef41Sopenharmony_ci
3271cb0ef41Sopenharmony_ci#if defined(GEN_TREES_H) || !defined(STDC)
3281cb0ef41Sopenharmony_ci  extern uch ZLIB_INTERNAL _length_code[];
3291cb0ef41Sopenharmony_ci  extern uch ZLIB_INTERNAL _dist_code[];
3301cb0ef41Sopenharmony_ci#else
3311cb0ef41Sopenharmony_ci  extern const uch ZLIB_INTERNAL _length_code[];
3321cb0ef41Sopenharmony_ci  extern const uch ZLIB_INTERNAL _dist_code[];
3331cb0ef41Sopenharmony_ci#endif
3341cb0ef41Sopenharmony_ci
3351cb0ef41Sopenharmony_ci#ifdef LIT_MEM
3361cb0ef41Sopenharmony_ci# define _tr_tally_lit(s, c, flush) \
3371cb0ef41Sopenharmony_ci  { uch cc = (c); \
3381cb0ef41Sopenharmony_ci    s->d_buf[s->sym_next] = 0; \
3391cb0ef41Sopenharmony_ci    s->l_buf[s->sym_next++] = cc; \
3401cb0ef41Sopenharmony_ci    s->dyn_ltree[cc].Freq++; \
3411cb0ef41Sopenharmony_ci    flush = (s->sym_next == s->sym_end); \
3421cb0ef41Sopenharmony_ci   }
3431cb0ef41Sopenharmony_ci# define _tr_tally_dist(s, distance, length, flush) \
3441cb0ef41Sopenharmony_ci  { uch len = (uch)(length); \
3451cb0ef41Sopenharmony_ci    ush dist = (ush)(distance); \
3461cb0ef41Sopenharmony_ci    s->d_buf[s->sym_next] = dist; \
3471cb0ef41Sopenharmony_ci    s->l_buf[s->sym_next++] = len; \
3481cb0ef41Sopenharmony_ci    dist--; \
3491cb0ef41Sopenharmony_ci    s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
3501cb0ef41Sopenharmony_ci    s->dyn_dtree[d_code(dist)].Freq++; \
3511cb0ef41Sopenharmony_ci    flush = (s->sym_next == s->sym_end); \
3521cb0ef41Sopenharmony_ci  }
3531cb0ef41Sopenharmony_ci#else
3541cb0ef41Sopenharmony_ci# define _tr_tally_lit(s, c, flush) \
3551cb0ef41Sopenharmony_ci  { uch cc = (c); \
3561cb0ef41Sopenharmony_ci    s->sym_buf[s->sym_next++] = 0; \
3571cb0ef41Sopenharmony_ci    s->sym_buf[s->sym_next++] = 0; \
3581cb0ef41Sopenharmony_ci    s->sym_buf[s->sym_next++] = cc; \
3591cb0ef41Sopenharmony_ci    s->dyn_ltree[cc].Freq++; \
3601cb0ef41Sopenharmony_ci    flush = (s->sym_next == s->sym_end); \
3611cb0ef41Sopenharmony_ci   }
3621cb0ef41Sopenharmony_ci# define _tr_tally_dist(s, distance, length, flush) \
3631cb0ef41Sopenharmony_ci  { uch len = (uch)(length); \
3641cb0ef41Sopenharmony_ci    ush dist = (ush)(distance); \
3651cb0ef41Sopenharmony_ci    s->sym_buf[s->sym_next++] = (uch)dist; \
3661cb0ef41Sopenharmony_ci    s->sym_buf[s->sym_next++] = (uch)(dist >> 8); \
3671cb0ef41Sopenharmony_ci    s->sym_buf[s->sym_next++] = len; \
3681cb0ef41Sopenharmony_ci    dist--; \
3691cb0ef41Sopenharmony_ci    s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
3701cb0ef41Sopenharmony_ci    s->dyn_dtree[d_code(dist)].Freq++; \
3711cb0ef41Sopenharmony_ci    flush = (s->sym_next == s->sym_end); \
3721cb0ef41Sopenharmony_ci  }
3731cb0ef41Sopenharmony_ci#endif
3741cb0ef41Sopenharmony_ci#else
3751cb0ef41Sopenharmony_ci# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
3761cb0ef41Sopenharmony_ci# define _tr_tally_dist(s, distance, length, flush) \
3771cb0ef41Sopenharmony_ci              flush = _tr_tally(s, distance, length)
3781cb0ef41Sopenharmony_ci#endif
3791cb0ef41Sopenharmony_ci
3801cb0ef41Sopenharmony_ci/* Functions that are SIMD optimised on x86 */
3811cb0ef41Sopenharmony_civoid ZLIB_INTERNAL crc_fold_init(deflate_state* const s);
3821cb0ef41Sopenharmony_civoid ZLIB_INTERNAL crc_fold_copy(deflate_state* const s,
3831cb0ef41Sopenharmony_ci                                 unsigned char* dst,
3841cb0ef41Sopenharmony_ci                                 const unsigned char* src,
3851cb0ef41Sopenharmony_ci                                 long len);
3861cb0ef41Sopenharmony_ciunsigned ZLIB_INTERNAL crc_fold_512to32(deflate_state* const s);
3871cb0ef41Sopenharmony_ci
3881cb0ef41Sopenharmony_ci#endif /* DEFLATE_H */
389