Coverage Report

Created: 2026-10-17 07:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/zlib-ng/deflate.h
Line
Count
Source
1
#ifndef DEFLATE_H_
2
#define DEFLATE_H_
3
/* deflate.h -- internal compression state
4
 * Copyright (C) 1995-2026 Jean-loup Gailly
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 "zutil.h"
14
#include "zendian.h"
15
#include "zmemory.h"
16
17
#ifdef S390_DFLTCC_DEFLATE
18
#  include "arch/s390/dfltcc_common.h"
19
#  define HAVE_ARCH_DEFLATE_STATE
20
#endif
21
22
/* define NO_GZIP when compiling if you want to disable gzip header and
23
   trailer creation by deflate().  NO_GZIP would be used to avoid linking in
24
   the crc code when it is not needed.  For shared libraries, gzip encoding
25
   should be left enabled. */
26
#ifndef NO_GZIP
27
#  define GZIP
28
#endif
29
30
/* LIT_MEM uses separate distance/length buffers instead of the overlaid sym_buf.
31
   This uses ~20% more memory but is 1-2% faster on platforms without fast unaligned
32
   access. By default, LIT_MEM is only enabled when OPTIMAL_CMP < 32. Define LIT_MEM
33
   to force separate buffers, or NO_LIT_MEM to force sym_buf usage. */
34
#if !defined(LIT_MEM) && !defined(NO_LIT_MEM) && (OPTIMAL_CMP < 32)
35
#  define LIT_MEM
36
#endif
37
38
/* ===========================================================================
39
 * Internal compression state.
40
 */
41
42
11.0M
#define LENGTH_CODES 29
43
/* number of length codes, not counting the special END_BLOCK code */
44
45
37.9M
#define LITERALS  256
46
/* number of literal bytes 0..255 */
47
48
11.0M
#define L_CODES (LITERALS+1+LENGTH_CODES)
49
/* number of Literal or Length codes, including the END_BLOCK code */
50
51
1.19M
#define D_CODES   30
52
/* number of distance codes */
53
54
798k
#define BL_CODES  19
55
/* number of codes used to transfer the bit lengths */
56
57
#define HEAP_SIZE (2*L_CODES+1)
58
/* maximum heap size */
59
60
0
#define BIT_BUF_SIZE 64
61
/* size of bit buffer in bi_buf */
62
63
38.5k
#define END_BLOCK 256
64
/* end of block literal code */
65
66
201k
#define INIT_STATE      1    /* zlib header -> BUSY_STATE */
67
#ifdef GZIP
68
23.4k
#  define GZIP_STATE    4    /* gzip header -> BUSY_STATE | EXTRA_STATE */
69
11.7k
#  define EXTRA_STATE   5    /* gzip extra block -> NAME_STATE */
70
11.7k
#  define NAME_STATE    6    /* gzip file name -> COMMENT_STATE */
71
11.7k
#  define COMMENT_STATE 7    /* gzip comment -> HCRC_STATE */
72
66.4k
#  define HCRC_STATE    8    /* gzip header CRC -> BUSY_STATE */
73
#endif
74
80.7k
#define BUSY_STATE      2    /* deflate -> FINISH_STATE */
75
196k
#define FINISH_STATE    3    /* stream complete */
76
#ifdef GZIP
77
54.7k
#  define MAX_STATE     HCRC_STATE
78
#else
79
#  define MAX_STATE     FINISH_STATE
80
#endif
81
/* Stream status */
82
83
#ifndef HASH_SIZE
84
144M
#  define HASH_SIZE 65536u         /* number of elements in hash table */
85
197M
#  define HASH_BITS    16u         /* log2(HASH_SIZE) */
86
#else
87
#  if ((HASH_SIZE) & ((HASH_SIZE) - 1)) != 0
88
#    error HASH_SIZE must be a perfect power of 2!
89
#  endif
90
#  if (HASH_SIZE) < 64u || (HASH_SIZE) > 524288u
91
#    error HASH_SIZE must be within 64-524288. Note that non-default sizes are not supported, and might not work correctly.
92
#  endif
93
#  define HASH_BITS ( \
94
     (HASH_SIZE) == 64u ? 6u : \
95
     (HASH_SIZE) == 128u ? 7u : \
96
     (HASH_SIZE) == 256u ? 8u : \
97
     (HASH_SIZE) == 512u ? 9u : \
98
     (HASH_SIZE) == 1024u ? 10u : \
99
     (HASH_SIZE) == 2048u ? 11u : \
100
     (HASH_SIZE) == 4096u ? 12u : \
101
     (HASH_SIZE) == 8192u ? 13u : \
102
     (HASH_SIZE) == 16384u ? 14u : \
103
     (HASH_SIZE) == 32768u ? 15u : \
104
     (HASH_SIZE) == 65536u ? 16u : \
105
     (HASH_SIZE) == 131072u ? 17u : \
106
     (HASH_SIZE) == 262144u ? 18u : \
107
     (HASH_SIZE) == 524288u ? 19u : 0u)
108
#endif
109
110
#define HASH_MASK (HASH_SIZE - 1u) /* HASH_SIZE-1 */
111
112
63.1M
#define MIN_ROLL_LEVEL 9
113
/* Levels at and above this use the rolling three-byte hash, which can find
114
 * minimum-length matches the four-byte Knuth hash cannot index.
115
 *
116
 * Every level at and above this must map to deflate_slow in configuration_table
117
 * to prevent the hash chains from mixing Knuth and rolling hashes.
118
 */
119
#if MIN_ROLL_LEVEL < 7
120
#  error MIN_ROLL_LEVEL must only reach levels that map to deflate_slow
121
#endif
122
123
/* Data structure describing a single value and its code string. */
124
typedef struct ct_data_s {
125
    union {
126
        uint16_t  freq;       /* frequency count */
127
        uint16_t  code;       /* bit string */
128
    } fc;
129
    union {
130
        uint16_t  dad;        /* father node in Huffman tree */
131
        uint16_t  len;        /* length of bit string */
132
    } dl;
133
} ct_data;
134
135
324M
#define Freq fc.freq
136
31.3M
#define Code fc.code
137
16.9M
#define Dad  dl.dad
138
72.3M
#define Len  dl.len
139
140
typedef struct static_tree_desc_s  static_tree_desc;
141
142
typedef struct tree_desc_s {
143
    ct_data                *dyn_tree;  /* the dynamic tree */
144
    int                    max_code;   /* largest code with non zero frequency */
145
    const static_tree_desc *stat_desc; /* the corresponding static tree */
146
} tree_desc;
147
148
typedef uint16_t Pos;
149
150
/* A Pos is an index in the character window. We use short instead of int to
151
 * save space in the various tables.
152
 */
153
/* Type definitions for hash callbacks */
154
typedef struct internal_state deflate_state;
155
156
typedef void (* insert_batch_func)   (deflate_state *const s, unsigned char *window, uint32_t str, uint32_t count);
157
void         insert_knuth_batch      (deflate_state *const s, unsigned char *window, uint32_t str, uint32_t count);
158
void         insert_roll_batch       (deflate_state *const s, unsigned char *window, uint32_t str, uint32_t count);
159
void         insert_knuth_batch_head (deflate_state *const s, unsigned char *window, uint32_t str, uint32_t count);
160
161
/* Match function. Returns the longest match. */
162
typedef uint32_t (* longest_match_func) (deflate_state *const s, uint32_t cur_match);
163
164
/* Struct for memory allocation handling */
165
typedef struct deflate_allocs_s {
166
    char            *buf_start;
167
    free_func        zfree;
168
    deflate_state   *state;
169
    unsigned char   *window;
170
    unsigned char   *pending_buf;
171
    Pos             *prev;
172
    Pos             *head;
173
} deflate_allocs;
174
175
struct ALIGNED_(64) internal_state {
176
                /* Cacheline 0 */
177
    PREFIX3(stream)      *strm;            /* pointer back to this zlib stream */
178
    unsigned char        *pending_buf;     /* output still pending */
179
    unsigned char        *pending_out;     /* next pending byte to output to the stream */
180
    uint32_t             pending_buf_size; /* size of pending_buf */
181
    uint32_t             pending;          /* nb of bytes in the pending buffer */
182
    int                  wrap;             /* bit 0 true for zlib, bit 1 true for gzip */
183
    uint32_t             gzindex;          /* where in extra, name, or comment */
184
    PREFIX(gz_headerp)   gzhead;           /* gzip header information to write */
185
    int                  status;           /* as the name implies */
186
    int                  last_flush;       /* value of flush param for previous deflate call */
187
    int                  reproducible;     /* Whether reproducible compression results are required. */
188
189
    unsigned int block_open;
190
    /* Whether or not a block is currently open for the QUICK deflation scheme.
191
     * This is set to 1 if there is an active block, or 0 if the block was just closed.
192
     */
193
194
                /* Cacheline 1 */
195
196
    unsigned int  lookahead;    /* number of valid bytes ahead in window */
197
    unsigned int strstart;      /* start of string to insert */
198
    unsigned int  w_size;       /* LZ77 window size (32K by default) */
199
200
    int block_start;            /* Window position at the beginning of the current output block.
201
                                 * Gets negative when the window is moved backwards. */
202
203
    unsigned int high_water;
204
    /* High water mark offset in window for initialized bytes -- bytes above
205
     * this are set to zero in order to avoid memory check warnings when
206
     * longest match routines access bytes past the input.  This is then
207
     * updated to the new high water mark.
208
     */
209
210
    unsigned int window_size;
211
    /* Actual size of window: 2*wSize, except when the user input buffer
212
     * is directly used as sliding window.
213
     */
214
215
    unsigned char *window;
216
    /* Sliding window. Input bytes are read into the second half of the window,
217
     * and move to the first half later to keep a dictionary of at least wSize
218
     * bytes. With this organization, matches are limited to a distance of
219
     * wSize-STD_MAX_MATCH bytes, but this ensures that IO is always
220
     * performed with a length multiple of the block size. Also, it limits
221
     * the window size to 64K, which is quite useful on MSDOS.
222
     * To do: use the user input buffer as sliding window.
223
     */
224
225
    Pos *prev;
226
    /* Link to older string with same hash index. To limit the size of this
227
     * array to 64K, this link is maintained only for the last 32K strings.
228
     * An index in this array is thus a window index modulo 32K.
229
     */
230
231
    Pos *head; /* Heads of the hash chains or 0. */
232
233
    uint32_t ins_h; /* hash index of string to be inserted */
234
235
    unsigned int match_length;       /* length of best match */
236
    int          match_available;    /* set if previous match exists */
237
    uint32_t     prev_match;         /* previous match (used by deflate_slow) */
238
239
                /* Cacheline 2 */
240
241
    unsigned int match_start;        /* start of matching string */
242
243
    unsigned int prev_length;
244
    /* Length of the best match at previous step. Matches not greater than this
245
     * are discarded. This is used in the lazy match evaluation.
246
     */
247
248
    unsigned int max_chain_length;
249
    /* To speed up deflation, hash chains are never searched beyond this length.
250
     * A higher limit improves compression ratio but degrades the speed.
251
     */
252
253
    unsigned int max_lazy_match;
254
    /* Attempt to find a better match only when the current match is strictly smaller
255
     * than this value. This mechanism is used only for compression levels >= 4.
256
     */
257
2.47M
#   define max_insert_length  max_lazy_match
258
    /* Insert new strings in the hash table only if the match length is not
259
     * greater than this length. This saves time but degrades compression.
260
     * max_insert_length is used only for compression levels <= 6.
261
     */
262
263
    int level;                  /* compression level (1..9) */
264
    int strategy;               /* favor or force Huffman coding*/
265
    unsigned int good_match;    /* Use a faster search when the previous match is longer than this */
266
    int nice_match;             /* Stop searching when current match exceeds this */
267
    unsigned int insert;        /* bytes at end of window left to insert */
268
269
    int32_t bi_used;            /* Last number of used bits when going to a byte boundary. */
270
    uint64_t bi_buf;            /* Output buffer.
271
                                 * Bits are inserted starting at the bottom (least significant bits). */
272
    int32_t bi_valid;           /* Number of valid bits in bi_buf.
273
                                 * All bits above the last valid bit are always zero. */
274
275
    int32_t padding[2];         /* Keeps Cacheline 3 aligned */
276
277
                /* used by trees.c: */
278
    unsigned int  lit_bufsize;
279
    /* Size of match buffer for literals/lengths.  There are 4 reasons for
280
     * limiting lit_bufsize to 64K:
281
     *   - frequencies can be kept in 16 bit counters
282
     *   - if compression is not successful for the first block, all input
283
     *     data is still in the window so we can still emit a stored block even
284
     *     when input comes from standard input.  (This can also be done for
285
     *     all blocks if lit_bufsize is not greater than 32K.)
286
     *   - if compression is not successful for a file smaller than 64K, we can
287
     *     even emit a stored file instead of a stored block (saving 5 bytes).
288
     *     This is applicable only for zip (not gzip or zlib).
289
     *   - creating new Huffman trees less frequently may not provide fast
290
     *     adaptation to changes in the input data statistics. (Take for
291
     *     example a binary file with poorly compressible code followed by
292
     *     a highly compressible string table.) Smaller buffer sizes give
293
     *     fast adaptation but have of course the overhead of transmitting
294
     *     trees more frequently.
295
     *   - I can't count above 4
296
     */
297
298
                /* Cacheline 3 */
299
300
#ifdef LIT_MEM
301
#   define LIT_BUFS 5
302
    uint16_t *d_buf;              /* buffer for distances */
303
    unsigned char *l_buf;         /* buffer for literals/lengths */
304
#else
305
11.7k
#   define LIT_BUFS 4
306
    unsigned char *sym_buf;       /* buffer for distances and literals/lengths */
307
#endif
308
309
    unsigned int sym_next;        /* running index in symbol buffer */
310
    unsigned int sym_end;         /* symbol table full when sym_next reaches this */
311
312
    unsigned int opt_len;         /* bit length of current block with optimal trees */
313
    unsigned int static_len;      /* bit length of current block with static trees */
314
315
    struct tree_desc_s l_desc;               /* desc. for literal tree */
316
    struct tree_desc_s d_desc;               /* desc. for distance tree */
317
    struct tree_desc_s bl_desc;              /* desc. for bit length tree */
318
319
    uint16_t bl_count[MAX_BITS+1];
320
    /* number of codes at each bit length for an optimal tree */
321
322
    uint32_t pq_leaves[L_CODES+1];  /* build_tree() packed leaf entries */
323
    uint32_t pq_scratch[L_CODES+1]; /* build_tree() radix buffer and internal node FIFO */
324
325
    /* Didn't use ct_data typedef below to suppress compiler warning */
326
    struct ct_data_s dyn_ltree[HEAP_SIZE];   /* literal and length tree */
327
    struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
328
    struct ct_data_s bl_tree[2*BL_CODES+1];  /* Huffman tree for bit lengths */
329
330
    deflate_allocs *alloc_bufs;
331
332
#ifdef HAVE_ARCH_DEFLATE_STATE
333
    arch_deflate_state arch;      /* architecture-specific extensions */
334
#endif
335
336
    /* compressed_len and bits_sent are only used if ZLIB_DEBUG is defined */
337
#ifdef ZLIB_DEBUG
338
    unsigned long compressed_len; /* total bit length of compressed file mod 2^32 */
339
    unsigned long bits_sent;      /* bit length of compressed data sent mod 2^32 */
340
#endif
341
342
    /* Level-selected function variants, set by lm_set_level() */
343
    longest_match_func longest_match;
344
    insert_batch_func insert_batch;
345
346
    /* Reserved for future use and alignment purposes */
347
    int32_t reserved[20];
348
};
349
350
typedef enum {
351
    need_more,      /* block not completed, need more input or more output */
352
    block_done,     /* block flush performed */
353
    finish_started, /* finish started, need only more output at next deflate */
354
    finish_done     /* finish done, accept no more input or output */
355
} block_state;
356
357
/* Output a byte on the stream.
358
 * IN assertion: there is enough room in pending_buf.
359
 */
360
89.1k
#define put_byte(s, c) { \
361
89.1k
    s->pending_buf[s->pending++] = (unsigned char)(c); \
362
89.1k
}
363
364
/* ===========================================================================
365
 * Output a short LSB first on the stream.
366
 * IN assertion: there is enough room in pending_buf.
367
 */
368
30.8k
static inline void put_short(deflate_state *s, uint16_t w) {
369
30.8k
    w = Z_U16_TO_LE(w);
370
30.8k
    zng_memwrite_2(&s->pending_buf[s->pending], w);
371
30.8k
    s->pending += 2;
372
30.8k
}
Unexecuted instantiation: deflate.c:put_short
Unexecuted instantiation: deflate_fast.c:put_short
Unexecuted instantiation: deflate_huff.c:put_short
Unexecuted instantiation: deflate_medium.c:put_short
deflate_quick.c:put_short
Line
Count
Source
368
472
static inline void put_short(deflate_state *s, uint16_t w) {
369
472
    w = Z_U16_TO_LE(w);
370
472
    zng_memwrite_2(&s->pending_buf[s->pending], w);
371
472
    s->pending += 2;
372
472
}
Unexecuted instantiation: deflate_rle.c:put_short
Unexecuted instantiation: deflate_slow.c:put_short
deflate_stored.c:put_short
Line
Count
Source
368
1.50k
static inline void put_short(deflate_state *s, uint16_t w) {
369
1.50k
    w = Z_U16_TO_LE(w);
370
1.50k
    zng_memwrite_2(&s->pending_buf[s->pending], w);
371
1.50k
    s->pending += 2;
372
1.50k
}
Unexecuted instantiation: functable.c:put_short
Unexecuted instantiation: inflate.c:put_short
Unexecuted instantiation: insert_string.c:put_short
trees.c:put_short
Line
Count
Source
368
28.8k
static inline void put_short(deflate_state *s, uint16_t w) {
369
28.8k
    w = Z_U16_TO_LE(w);
370
28.8k
    zng_memwrite_2(&s->pending_buf[s->pending], w);
371
28.8k
    s->pending += 2;
372
28.8k
}
Unexecuted instantiation: chunkset_sse2.c:put_short
Unexecuted instantiation: compare256_sse2.c:put_short
Unexecuted instantiation: crc32_chorba_sse2.c:put_short
Unexecuted instantiation: slide_hash_sse2.c:put_short
Unexecuted instantiation: chunkset_ssse3.c:put_short
Unexecuted instantiation: crc32_chorba_sse41.c:put_short
Unexecuted instantiation: slide_hash_avx2.c:put_short
Unexecuted instantiation: chunkset_avx2.c:put_short
Unexecuted instantiation: compare256_avx2.c:put_short
Unexecuted instantiation: adler32_avx2_vnni.c:put_short
Unexecuted instantiation: adler32_avx512.c:put_short
Unexecuted instantiation: chunkset_avx512.c:put_short
Unexecuted instantiation: compare256_avx512.c:put_short
Unexecuted instantiation: adler32_avx512_vnni.c:put_short
Unexecuted instantiation: adler32_c.c:put_short
Unexecuted instantiation: crc32_braid_c.c:put_short
Unexecuted instantiation: crc32_chorba_c.c:put_short
Unexecuted instantiation: crc32.c:put_short
373
374
/* ===========================================================================
375
 * Output a short MSB first on the stream.
376
 * IN assertion: there is enough room in pending_buf.
377
 */
378
0
static inline void put_short_msb(deflate_state *s, uint16_t w) {
379
0
    w = Z_U16_TO_BE(w);
380
0
    zng_memwrite_2(&s->pending_buf[s->pending], w);
381
0
    s->pending += 2;
382
0
}
Unexecuted instantiation: deflate.c:put_short_msb
Unexecuted instantiation: deflate_fast.c:put_short_msb
Unexecuted instantiation: deflate_huff.c:put_short_msb
Unexecuted instantiation: deflate_medium.c:put_short_msb
Unexecuted instantiation: deflate_quick.c:put_short_msb
Unexecuted instantiation: deflate_rle.c:put_short_msb
Unexecuted instantiation: deflate_slow.c:put_short_msb
Unexecuted instantiation: deflate_stored.c:put_short_msb
Unexecuted instantiation: functable.c:put_short_msb
Unexecuted instantiation: inflate.c:put_short_msb
Unexecuted instantiation: insert_string.c:put_short_msb
Unexecuted instantiation: trees.c:put_short_msb
Unexecuted instantiation: chunkset_sse2.c:put_short_msb
Unexecuted instantiation: compare256_sse2.c:put_short_msb
Unexecuted instantiation: crc32_chorba_sse2.c:put_short_msb
Unexecuted instantiation: slide_hash_sse2.c:put_short_msb
Unexecuted instantiation: chunkset_ssse3.c:put_short_msb
Unexecuted instantiation: crc32_chorba_sse41.c:put_short_msb
Unexecuted instantiation: slide_hash_avx2.c:put_short_msb
Unexecuted instantiation: chunkset_avx2.c:put_short_msb
Unexecuted instantiation: compare256_avx2.c:put_short_msb
Unexecuted instantiation: adler32_avx2_vnni.c:put_short_msb
Unexecuted instantiation: adler32_avx512.c:put_short_msb
Unexecuted instantiation: chunkset_avx512.c:put_short_msb
Unexecuted instantiation: compare256_avx512.c:put_short_msb
Unexecuted instantiation: adler32_avx512_vnni.c:put_short_msb
Unexecuted instantiation: adler32_c.c:put_short_msb
Unexecuted instantiation: crc32_braid_c.c:put_short_msb
Unexecuted instantiation: crc32_chorba_c.c:put_short_msb
Unexecuted instantiation: crc32.c:put_short_msb
383
384
/* ===========================================================================
385
 * Output a 32-bit unsigned int LSB first on the stream.
386
 * IN assertion: there is enough room in pending_buf.
387
 */
388
38.2k
static inline void put_uint32(deflate_state *s, uint32_t dw) {
389
38.2k
    dw = Z_U32_TO_LE(dw);
390
38.2k
    zng_memwrite_4(&s->pending_buf[s->pending], dw);
391
38.2k
    s->pending += 4;
392
38.2k
}
deflate.c:put_uint32
Line
Count
Source
388
35.2k
static inline void put_uint32(deflate_state *s, uint32_t dw) {
389
35.2k
    dw = Z_U32_TO_LE(dw);
390
35.2k
    zng_memwrite_4(&s->pending_buf[s->pending], dw);
391
35.2k
    s->pending += 4;
392
35.2k
}
Unexecuted instantiation: deflate_fast.c:put_uint32
Unexecuted instantiation: deflate_huff.c:put_uint32
Unexecuted instantiation: deflate_medium.c:put_uint32
deflate_quick.c:put_uint32
Line
Count
Source
388
532
static inline void put_uint32(deflate_state *s, uint32_t dw) {
389
532
    dw = Z_U32_TO_LE(dw);
390
532
    zng_memwrite_4(&s->pending_buf[s->pending], dw);
391
532
    s->pending += 4;
392
532
}
Unexecuted instantiation: deflate_rle.c:put_uint32
Unexecuted instantiation: deflate_slow.c:put_uint32
Unexecuted instantiation: deflate_stored.c:put_uint32
Unexecuted instantiation: functable.c:put_uint32
Unexecuted instantiation: inflate.c:put_uint32
Unexecuted instantiation: insert_string.c:put_uint32
trees.c:put_uint32
Line
Count
Source
388
2.48k
static inline void put_uint32(deflate_state *s, uint32_t dw) {
389
2.48k
    dw = Z_U32_TO_LE(dw);
390
2.48k
    zng_memwrite_4(&s->pending_buf[s->pending], dw);
391
2.48k
    s->pending += 4;
392
2.48k
}
Unexecuted instantiation: chunkset_sse2.c:put_uint32
Unexecuted instantiation: compare256_sse2.c:put_uint32
Unexecuted instantiation: crc32_chorba_sse2.c:put_uint32
Unexecuted instantiation: slide_hash_sse2.c:put_uint32
Unexecuted instantiation: chunkset_ssse3.c:put_uint32
Unexecuted instantiation: crc32_chorba_sse41.c:put_uint32
Unexecuted instantiation: slide_hash_avx2.c:put_uint32
Unexecuted instantiation: chunkset_avx2.c:put_uint32
Unexecuted instantiation: compare256_avx2.c:put_uint32
Unexecuted instantiation: adler32_avx2_vnni.c:put_uint32
Unexecuted instantiation: adler32_avx512.c:put_uint32
Unexecuted instantiation: chunkset_avx512.c:put_uint32
Unexecuted instantiation: compare256_avx512.c:put_uint32
Unexecuted instantiation: adler32_avx512_vnni.c:put_uint32
Unexecuted instantiation: adler32_c.c:put_uint32
Unexecuted instantiation: crc32_braid_c.c:put_uint32
Unexecuted instantiation: crc32_chorba_c.c:put_uint32
Unexecuted instantiation: crc32.c:put_uint32
393
394
/* ===========================================================================
395
 * Output a 32-bit unsigned int MSB first on the stream.
396
 * IN assertion: there is enough room in pending_buf.
397
 */
398
0
static inline void put_uint32_msb(deflate_state *s, uint32_t dw) {
399
0
    dw = Z_U32_TO_BE(dw);
400
0
    zng_memwrite_4(&s->pending_buf[s->pending], dw);
401
0
    s->pending += 4;
402
0
}
Unexecuted instantiation: deflate.c:put_uint32_msb
Unexecuted instantiation: deflate_fast.c:put_uint32_msb
Unexecuted instantiation: deflate_huff.c:put_uint32_msb
Unexecuted instantiation: deflate_medium.c:put_uint32_msb
Unexecuted instantiation: deflate_quick.c:put_uint32_msb
Unexecuted instantiation: deflate_rle.c:put_uint32_msb
Unexecuted instantiation: deflate_slow.c:put_uint32_msb
Unexecuted instantiation: deflate_stored.c:put_uint32_msb
Unexecuted instantiation: functable.c:put_uint32_msb
Unexecuted instantiation: inflate.c:put_uint32_msb
Unexecuted instantiation: insert_string.c:put_uint32_msb
Unexecuted instantiation: trees.c:put_uint32_msb
Unexecuted instantiation: chunkset_sse2.c:put_uint32_msb
Unexecuted instantiation: compare256_sse2.c:put_uint32_msb
Unexecuted instantiation: crc32_chorba_sse2.c:put_uint32_msb
Unexecuted instantiation: slide_hash_sse2.c:put_uint32_msb
Unexecuted instantiation: chunkset_ssse3.c:put_uint32_msb
Unexecuted instantiation: crc32_chorba_sse41.c:put_uint32_msb
Unexecuted instantiation: slide_hash_avx2.c:put_uint32_msb
Unexecuted instantiation: chunkset_avx2.c:put_uint32_msb
Unexecuted instantiation: compare256_avx2.c:put_uint32_msb
Unexecuted instantiation: adler32_avx2_vnni.c:put_uint32_msb
Unexecuted instantiation: adler32_avx512.c:put_uint32_msb
Unexecuted instantiation: chunkset_avx512.c:put_uint32_msb
Unexecuted instantiation: compare256_avx512.c:put_uint32_msb
Unexecuted instantiation: adler32_avx512_vnni.c:put_uint32_msb
Unexecuted instantiation: adler32_c.c:put_uint32_msb
Unexecuted instantiation: crc32_braid_c.c:put_uint32_msb
Unexecuted instantiation: crc32_chorba_c.c:put_uint32_msb
Unexecuted instantiation: crc32.c:put_uint32_msb
403
404
/* ===========================================================================
405
 * Output a 64-bit unsigned int LSB first on the stream.
406
 * IN assertion: there is enough room in pending_buf.
407
 */
408
8.86M
static inline void put_uint64(deflate_state *s, uint64_t lld) {
409
8.86M
    lld = Z_U64_TO_LE(lld);
410
8.86M
    zng_memwrite_8(&s->pending_buf[s->pending], lld);
411
8.86M
    s->pending += 8;
412
8.86M
}
Unexecuted instantiation: deflate.c:put_uint64
Unexecuted instantiation: deflate_fast.c:put_uint64
Unexecuted instantiation: deflate_huff.c:put_uint64
Unexecuted instantiation: deflate_medium.c:put_uint64
deflate_quick.c:put_uint64
Line
Count
Source
408
8.76M
static inline void put_uint64(deflate_state *s, uint64_t lld) {
409
8.76M
    lld = Z_U64_TO_LE(lld);
410
8.76M
    zng_memwrite_8(&s->pending_buf[s->pending], lld);
411
8.76M
    s->pending += 8;
412
8.76M
}
Unexecuted instantiation: deflate_rle.c:put_uint64
Unexecuted instantiation: deflate_slow.c:put_uint64
Unexecuted instantiation: deflate_stored.c:put_uint64
Unexecuted instantiation: functable.c:put_uint64
Unexecuted instantiation: inflate.c:put_uint64
Unexecuted instantiation: insert_string.c:put_uint64
trees.c:put_uint64
Line
Count
Source
408
91.7k
static inline void put_uint64(deflate_state *s, uint64_t lld) {
409
91.7k
    lld = Z_U64_TO_LE(lld);
410
91.7k
    zng_memwrite_8(&s->pending_buf[s->pending], lld);
411
91.7k
    s->pending += 8;
412
91.7k
}
Unexecuted instantiation: chunkset_sse2.c:put_uint64
Unexecuted instantiation: compare256_sse2.c:put_uint64
Unexecuted instantiation: crc32_chorba_sse2.c:put_uint64
Unexecuted instantiation: slide_hash_sse2.c:put_uint64
Unexecuted instantiation: chunkset_ssse3.c:put_uint64
Unexecuted instantiation: crc32_chorba_sse41.c:put_uint64
Unexecuted instantiation: slide_hash_avx2.c:put_uint64
Unexecuted instantiation: chunkset_avx2.c:put_uint64
Unexecuted instantiation: compare256_avx2.c:put_uint64
Unexecuted instantiation: adler32_avx2_vnni.c:put_uint64
Unexecuted instantiation: adler32_avx512.c:put_uint64
Unexecuted instantiation: chunkset_avx512.c:put_uint64
Unexecuted instantiation: compare256_avx512.c:put_uint64
Unexecuted instantiation: adler32_avx512_vnni.c:put_uint64
Unexecuted instantiation: adler32_c.c:put_uint64
Unexecuted instantiation: crc32_braid_c.c:put_uint64
Unexecuted instantiation: crc32_chorba_c.c:put_uint64
Unexecuted instantiation: crc32.c:put_uint64
413
414
266M
#define MIN_LOOKAHEAD (STD_MAX_MATCH + STD_MIN_MATCH + 1)
415
/* Minimum amount of lookahead, except at the end of the input file.
416
 * See deflate.c for comments about the STD_MIN_MATCH+1.
417
 */
418
419
418M
#define MAX_DIST(s)  ((s)->w_size - MIN_LOOKAHEAD)
420
/* In order to simplify the code, particularly on 16 bit machines, match
421
 * distances are limited to MAX_DIST instead of WSIZE.
422
 */
423
424
207M
#define W_MASK(s)  ((s)->w_size - 1)
425
/* Window mask: w_size is always a power of 2, so w_mask = w_size - 1 */
426
427
0
#define W_BITS(s)  zng_ctz32((s)->w_size)
428
/* Window bits: log2(w_size), computed from w_size since w_size is a power of 2 */
429
430
373k
#define WIN_INIT STD_MAX_MATCH
431
/* Number of bytes after end of data in window to initialize in order to avoid
432
   memory checker errors from longest match routines */
433
434
435
void Z_INTERNAL PREFIX(fill_window)(deflate_state *s);
436
void Z_INTERNAL slide_hash_c(deflate_state *s);
437
void Z_INTERNAL slide_hash_head_c(deflate_state *s);
438
439
        /* in trees.c */
440
void Z_INTERNAL zng_tr_init(deflate_state *s);
441
void Z_INTERNAL zng_tr_flush_block(deflate_state *s, unsigned char *buf, uint32_t stored_len, int last);
442
void Z_INTERNAL zng_tr_flush_bits(deflate_state *s);
443
void Z_INTERNAL zng_tr_align(deflate_state *s);
444
void Z_INTERNAL zng_tr_stored_block(deflate_state *s, unsigned char *buf, uint32_t stored_len, int last);
445
void Z_INTERNAL PREFIX(flush_pending)(PREFIX3(streamp) strm);
446
26.7M
#define d_code(dist) ((dist) < 256 ? zng_dist_code[dist] : zng_dist_code[256+((dist)>>7)])
447
/* Mapping from a distance to a distance code. dist is the distance - 1 and
448
 * must not have side effects. zng_dist_code[256] and zng_dist_code[257] are never
449
 * used.
450
 */
451
452
/* Bit buffer and compress bits calculation debugging */
453
#ifdef ZLIB_DEBUG
454
#  define cmpr_bits_add(s, len)     s->compressed_len += (len)
455
#  define cmpr_bits_align(s)        s->compressed_len = ALIGN_UP(s->compressed_len, 8)
456
#  define sent_bits_add(s, bits)    s->bits_sent += (bits)
457
#  define sent_bits_align(s)        s->bits_sent = ALIGN_UP(s->bits_sent, 8)
458
#else
459
66.1M
#  define cmpr_bits_add(s, len)     Z_UNUSED(len)
460
#  define cmpr_bits_align(s)
461
270M
#  define sent_bits_add(s, bits)    Z_UNUSED(bits)
462
#  define sent_bits_align(s)
463
#endif
464
465
/* ===========================================================================
466
 *  Architecture-specific hooks.
467
 */
468
#ifdef S390_DFLTCC_DEFLATE
469
#  include "arch/s390/dfltcc_deflate.h"
470
/* DFLTCC instructions require window to be page-aligned */
471
#  define PAD_WINDOW            PAD_4096
472
#  define WINDOW_PAD_SIZE       4096
473
#  define HINT_ALIGNED_WINDOW   HINT_ALIGNED_4096
474
#else
475
23.4k
#  define PAD_WINDOW            PAD_64
476
#  define WINDOW_PAD_SIZE       64
477
46.9k
#  define HINT_ALIGNED_WINDOW   HINT_ALIGNED_64
478
/* Adjust the window size for the arch-specific deflate code. */
479
11.7k
#  define DEFLATE_ADJUST_WINDOW_SIZE(n) (n)
480
/* Invoked at the beginning of deflateSetDictionary(). Useful for checking arch-specific window data. */
481
0
#  define DEFLATE_SET_DICTIONARY_HOOK(strm, dict, dict_len) do {} while (0)
482
/* Invoked at the beginning of deflateGetDictionary(). Useful for adjusting arch-specific window data. */
483
0
#  define DEFLATE_GET_DICTIONARY_HOOK(strm, dict, dict_len) do {} while (0)
484
/* Invoked at the end of deflateResetKeep(). Useful for initializing arch-specific extension blocks. */
485
11.7k
#  define DEFLATE_RESET_KEEP_HOOK(strm) do {} while (0)
486
/* Invoked at the beginning of deflateParams(). Useful for updating arch-specific compression parameters. */
487
0
#  define DEFLATE_PARAMS_HOOK(strm, level, strategy, hook_flush) do {} while (0)
488
/* Returns whether the last deflate(flush) operation did everything it's supposed to do. */
489
0
#  define DEFLATE_DONE(strm, flush) 1
490
/* Adjusts the upper bound on compressed data length based on compression parameters and uncompressed data length.
491
 * Useful when arch-specific deflation code behaves differently than regular zlib-ng algorithms. */
492
0
#  define DEFLATE_BOUND_ADJUST_COMPLEN(strm, complen, sourceLen) do {} while (0)
493
/* Returns whether an optimistic upper bound on compressed data length should *not* be used.
494
 * Useful when arch-specific deflation code behaves differently than regular zlib-ng algorithms. */
495
0
#  define DEFLATE_NEED_CONSERVATIVE_BOUND(strm) 0
496
/* Invoked for each deflate() call. Useful for plugging arch-specific deflation code. */
497
16.1k
#  define DEFLATE_HOOK(strm, flush, bstate) 0
498
/* Returns whether zlib-ng should compute a checksum. Set to 0 if arch-specific deflation code already does that. */
499
23.9k
#  define DEFLATE_NEED_CHECKSUM(strm) 1
500
/* Returns whether reproducibility parameter can be set to a given value. */
501
0
#  define DEFLATE_CAN_SET_REPRODUCIBLE(strm, reproducible) 1
502
#endif
503
504
#endif /* DEFLATE_H_ */