Coverage Report

Created: 2026-09-01 06:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/zlib-ng/insert_string_p.h
Line
Count
Source
1
/* insert_string_p.h -- static single and batch hash insert functions
2
 *
3
 * Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler
4
 * For conditions of distribution and use, see copyright notice in zlib.h
5
 */
6
#ifndef INSERT_STRING_P_H_
7
#define INSERT_STRING_P_H_
8
9
614M
#define KNUTH_SHIFT (32 - HASH_BITS)
10
614M
#define UPDATE_HASH_KNUTH(h,val) h = (((val) * 2654435761U) >> KNUTH_SHIFT)
11
12
#if (HASH_SIZE) > 65536u
13
#  define ROLL_HASH_SIZE 65536
14
#else
15
#  define ROLL_HASH_SIZE HASH_SIZE
16
#endif
17
0
#define ROLL_MASK ((HASH_SIZE / 2) - 1u))
18
0
#define UPDATE_HASH_ROLL(h,val) h = (((h << 5) ^ ((uint8_t)(val))) & ROLL_MASK
19
20
/* ===========================================================================
21
 * Update a hash value with the given input byte
22
 * IN  assertion: all calls to UPDATE_HASH are made with consecutive
23
 *    input characters, so that a running hash key can be computed from the
24
 *    previous key instead of complete recalculation each time.
25
 */
26
0
Z_FORCEINLINE static uint32_t update_hash_roll(uint32_t h, uint32_t val) {
27
0
    UPDATE_HASH_ROLL(h, val);
28
0
    return h;
29
0
}
Unexecuted instantiation: deflate.c:update_hash_roll
Unexecuted instantiation: deflate_fast.c:update_hash_roll
Unexecuted instantiation: deflate_medium.c:update_hash_roll
Unexecuted instantiation: deflate_quick.c:update_hash_roll
Unexecuted instantiation: deflate_slow.c:update_hash_roll
Unexecuted instantiation: insert_string.c:update_hash_roll
Unexecuted instantiation: compare256_sse2.c:update_hash_roll
Unexecuted instantiation: compare256_avx2.c:update_hash_roll
Unexecuted instantiation: compare256_avx512.c:update_hash_roll
30
31
/* ===========================================================================
32
 * Insert string str in the dictionary using a pre-read value and set match_head
33
 * to the previous head of the hash chain (the most recent string with same hash key).
34
 * Return the previous length of the hash chain.
35
 */
36
0
Z_FORCEINLINE static uint32_t insert_knuth_val(deflate_state *const s, uint32_t str, uint32_t val) {
37
0
    uint32_t h, head;
38
39
0
    UPDATE_HASH_KNUTH(h, val);
40
41
0
    head = s->head[h];
42
0
    if (LIKELY(head != str)) {
43
0
        s->prev[str & W_MASK(s)] = (Pos)head;
44
0
        s->head[h] = (Pos)str;
45
0
    }
46
0
    return head;
47
0
}
Unexecuted instantiation: deflate.c:insert_knuth_val
Unexecuted instantiation: deflate_fast.c:insert_knuth_val
Unexecuted instantiation: deflate_medium.c:insert_knuth_val
Unexecuted instantiation: deflate_quick.c:insert_knuth_val
Unexecuted instantiation: deflate_slow.c:insert_knuth_val
Unexecuted instantiation: insert_string.c:insert_knuth_val
Unexecuted instantiation: compare256_sse2.c:insert_knuth_val
Unexecuted instantiation: compare256_avx2.c:insert_knuth_val
Unexecuted instantiation: compare256_avx512.c:insert_knuth_val
48
49
/* ===========================================================================
50
 * Insert string str using a pre-read value, returning the previous head of the
51
 * hash chain. The prev link is left untouched since deflate_quick only inspects
52
 * the chain head and never walks the chain.
53
 */
54
116M
Z_FORCEINLINE static uint32_t insert_knuth_val_head(deflate_state *const s, uint32_t str, uint32_t val) {
55
116M
    uint32_t h, head;
56
57
116M
    UPDATE_HASH_KNUTH(h, val);
58
59
116M
    head = s->head[h];
60
116M
    s->head[h] = (Pos)str;
61
116M
    return head;
62
116M
}
Unexecuted instantiation: deflate.c:insert_knuth_val_head
Unexecuted instantiation: deflate_fast.c:insert_knuth_val_head
Unexecuted instantiation: deflate_medium.c:insert_knuth_val_head
deflate_quick.c:insert_knuth_val_head
Line
Count
Source
54
116M
Z_FORCEINLINE static uint32_t insert_knuth_val_head(deflate_state *const s, uint32_t str, uint32_t val) {
55
116M
    uint32_t h, head;
56
57
116M
    UPDATE_HASH_KNUTH(h, val);
58
59
116M
    head = s->head[h];
60
116M
    s->head[h] = (Pos)str;
61
116M
    return head;
62
116M
}
Unexecuted instantiation: deflate_slow.c:insert_knuth_val_head
Unexecuted instantiation: insert_string.c:insert_knuth_val_head
Unexecuted instantiation: compare256_sse2.c:insert_knuth_val_head
Unexecuted instantiation: compare256_avx2.c:insert_knuth_val_head
Unexecuted instantiation: compare256_avx512.c:insert_knuth_val_head
63
64
/* ===========================================================================
65
 * Insert string str in the dictionary and set match_head to the previous head
66
 * of the hash chain (the most recent string with same hash key). Return
67
 * the previous length of the hash chain.
68
 */
69
349M
Z_FORCEINLINE static uint32_t insert_knuth(deflate_state *const s, unsigned char *window, uint32_t str) {
70
349M
    uint8_t *strstart = window + str;
71
349M
    uint32_t val, h, head;
72
73
349M
    val = Z_U32_FROM_LE(zng_memread_4(strstart));
74
349M
    UPDATE_HASH_KNUTH(h, val);
75
76
349M
    head = s->head[h];
77
349M
    if (LIKELY(head != str)) {
78
349M
        s->prev[str & W_MASK(s)] = (Pos)head;
79
349M
        s->head[h] = (Pos)str;
80
349M
    }
81
349M
    return head;
82
349M
}
deflate.c:insert_knuth
Line
Count
Source
69
14.0k
Z_FORCEINLINE static uint32_t insert_knuth(deflate_state *const s, unsigned char *window, uint32_t str) {
70
14.0k
    uint8_t *strstart = window + str;
71
14.0k
    uint32_t val, h, head;
72
73
14.0k
    val = Z_U32_FROM_LE(zng_memread_4(strstart));
74
14.0k
    UPDATE_HASH_KNUTH(h, val);
75
76
14.0k
    head = s->head[h];
77
14.0k
    if (LIKELY(head != str)) {
78
44
        s->prev[str & W_MASK(s)] = (Pos)head;
79
44
        s->head[h] = (Pos)str;
80
44
    }
81
14.0k
    return head;
82
14.0k
}
Unexecuted instantiation: deflate_fast.c:insert_knuth
deflate_medium.c:insert_knuth
Line
Count
Source
69
231M
Z_FORCEINLINE static uint32_t insert_knuth(deflate_state *const s, unsigned char *window, uint32_t str) {
70
231M
    uint8_t *strstart = window + str;
71
231M
    uint32_t val, h, head;
72
73
231M
    val = Z_U32_FROM_LE(zng_memread_4(strstart));
74
231M
    UPDATE_HASH_KNUTH(h, val);
75
76
231M
    head = s->head[h];
77
231M
    if (LIKELY(head != str)) {
78
231M
        s->prev[str & W_MASK(s)] = (Pos)head;
79
231M
        s->head[h] = (Pos)str;
80
231M
    }
81
231M
    return head;
82
231M
}
Unexecuted instantiation: deflate_quick.c:insert_knuth
deflate_slow.c:insert_knuth
Line
Count
Source
69
118M
Z_FORCEINLINE static uint32_t insert_knuth(deflate_state *const s, unsigned char *window, uint32_t str) {
70
118M
    uint8_t *strstart = window + str;
71
118M
    uint32_t val, h, head;
72
73
118M
    val = Z_U32_FROM_LE(zng_memread_4(strstart));
74
118M
    UPDATE_HASH_KNUTH(h, val);
75
76
118M
    head = s->head[h];
77
118M
    if (LIKELY(head != str)) {
78
118M
        s->prev[str & W_MASK(s)] = (Pos)head;
79
118M
        s->head[h] = (Pos)str;
80
118M
    }
81
118M
    return head;
82
118M
}
Unexecuted instantiation: insert_string.c:insert_knuth
Unexecuted instantiation: compare256_sse2.c:insert_knuth
Unexecuted instantiation: compare256_avx2.c:insert_knuth
Unexecuted instantiation: compare256_avx512.c:insert_knuth
83
84
/* ===========================================================================
85
 * Insert string str read from the window, returning the previous head of the
86
 * hash chain. Like insert_knuth but leaves the prev link untouched for
87
 * deflate_quick, which only inspects the chain head.
88
 */
89
4.68k
Z_FORCEINLINE static uint32_t insert_knuth_head(deflate_state *const s, unsigned char *window, uint32_t str) {
90
4.68k
    uint8_t *strstart = window + str;
91
4.68k
    uint32_t val, h, head;
92
93
4.68k
    val = Z_U32_FROM_LE(zng_memread_4(strstart));
94
4.68k
    UPDATE_HASH_KNUTH(h, val);
95
96
4.68k
    head = s->head[h];
97
4.68k
    s->head[h] = (Pos)str;
98
4.68k
    return head;
99
4.68k
}
deflate.c:insert_knuth_head
Line
Count
Source
89
4.68k
Z_FORCEINLINE static uint32_t insert_knuth_head(deflate_state *const s, unsigned char *window, uint32_t str) {
90
4.68k
    uint8_t *strstart = window + str;
91
4.68k
    uint32_t val, h, head;
92
93
4.68k
    val = Z_U32_FROM_LE(zng_memread_4(strstart));
94
4.68k
    UPDATE_HASH_KNUTH(h, val);
95
96
4.68k
    head = s->head[h];
97
4.68k
    s->head[h] = (Pos)str;
98
4.68k
    return head;
99
4.68k
}
Unexecuted instantiation: deflate_fast.c:insert_knuth_head
Unexecuted instantiation: deflate_medium.c:insert_knuth_head
Unexecuted instantiation: deflate_quick.c:insert_knuth_head
Unexecuted instantiation: deflate_slow.c:insert_knuth_head
Unexecuted instantiation: insert_string.c:insert_knuth_head
Unexecuted instantiation: compare256_sse2.c:insert_knuth_head
Unexecuted instantiation: compare256_avx2.c:insert_knuth_head
Unexecuted instantiation: compare256_avx512.c:insert_knuth_head
100
101
0
Z_FORCEINLINE static uint32_t insert_roll(deflate_state *const s, unsigned char *window, uint32_t str) {
102
0
    uint8_t *strstart = window + str + (STD_MIN_MATCH-1);
103
0
    uint32_t h, head;
104
105
0
    h = s->ins_h;
106
0
    UPDATE_HASH_ROLL(h, strstart[0]);
107
0
    s->ins_h = h;
108
109
0
    head = s->head[h];
110
0
    if (LIKELY(head != str)) {
111
0
        s->prev[str & W_MASK(s)] = (Pos)head;
112
0
        s->head[h] = (Pos)str;
113
0
    }
114
0
    return head;
115
0
}
Unexecuted instantiation: deflate.c:insert_roll
Unexecuted instantiation: deflate_fast.c:insert_roll
Unexecuted instantiation: deflate_medium.c:insert_roll
Unexecuted instantiation: deflate_quick.c:insert_roll
Unexecuted instantiation: deflate_slow.c:insert_roll
Unexecuted instantiation: insert_string.c:insert_roll
Unexecuted instantiation: compare256_sse2.c:insert_roll
Unexecuted instantiation: compare256_avx2.c:insert_roll
Unexecuted instantiation: compare256_avx512.c:insert_roll
116
117
/* ===========================================================================
118
 * Insert string str in the dictionary and set match_head to the previous head
119
 * of the hash chain (the most recent string with same hash key). Return
120
 * the previous length of the hash chain.
121
 * IN  assertion: all calls to insert_knuth_batch are made with consecutive
122
 *    input characters and the first STD_MIN_MATCH bytes of str are valid
123
 *    (except for the last STD_MIN_MATCH-1 bytes of the input file).
124
 */
125
11.4M
Z_FORCEINLINE static void insert_knuth_batch_static(deflate_state *const s, unsigned char *window, uint32_t str, uint32_t count) {
126
11.4M
    uint8_t *strstart = window + str;
127
11.4M
    uint8_t *strend = strstart + count;
128
129
    /* Local pointers to avoid indirection */
130
11.4M
    Pos *headp = s->head;
131
11.4M
    Pos *prevp = s->prev;
132
11.4M
    const unsigned int w_mask = W_MASK(s);
133
134
159M
    for (uint32_t idx = str; strstart < strend; idx++, strstart++) {
135
147M
        uint32_t val, h, head;
136
137
147M
        val = Z_U32_FROM_LE(zng_memread_4(strstart));
138
147M
        UPDATE_HASH_KNUTH(h, val);
139
140
147M
        head = headp[h];
141
147M
        if (LIKELY(head != idx)) {
142
147M
            prevp[idx & w_mask] = (Pos)head;
143
147M
            headp[h] = (Pos)idx;
144
147M
        }
145
147M
    }
146
11.4M
}
Unexecuted instantiation: deflate.c:insert_knuth_batch_static
Unexecuted instantiation: deflate_fast.c:insert_knuth_batch_static
Unexecuted instantiation: deflate_medium.c:insert_knuth_batch_static
Unexecuted instantiation: deflate_quick.c:insert_knuth_batch_static
Unexecuted instantiation: deflate_slow.c:insert_knuth_batch_static
insert_string.c:insert_knuth_batch_static
Line
Count
Source
125
11.4M
Z_FORCEINLINE static void insert_knuth_batch_static(deflate_state *const s, unsigned char *window, uint32_t str, uint32_t count) {
126
11.4M
    uint8_t *strstart = window + str;
127
11.4M
    uint8_t *strend = strstart + count;
128
129
    /* Local pointers to avoid indirection */
130
11.4M
    Pos *headp = s->head;
131
11.4M
    Pos *prevp = s->prev;
132
11.4M
    const unsigned int w_mask = W_MASK(s);
133
134
159M
    for (uint32_t idx = str; strstart < strend; idx++, strstart++) {
135
147M
        uint32_t val, h, head;
136
137
147M
        val = Z_U32_FROM_LE(zng_memread_4(strstart));
138
147M
        UPDATE_HASH_KNUTH(h, val);
139
140
147M
        head = headp[h];
141
147M
        if (LIKELY(head != idx)) {
142
147M
            prevp[idx & w_mask] = (Pos)head;
143
147M
            headp[h] = (Pos)idx;
144
147M
        }
145
147M
    }
146
11.4M
}
Unexecuted instantiation: compare256_sse2.c:insert_knuth_batch_static
Unexecuted instantiation: compare256_avx2.c:insert_knuth_batch_static
Unexecuted instantiation: compare256_avx512.c:insert_knuth_batch_static
147
148
/* ===========================================================================
149
 * Insert count strings read from the window, leaving the prev links untouched.
150
 * Used by fill_window during deflate_quick, which only inspects the chain head.
151
 */
152
0
Z_FORCEINLINE static void insert_knuth_batch_head_static(deflate_state *const s, unsigned char *window, uint32_t str, uint32_t count) {
153
0
    uint8_t *strstart = window + str;
154
0
    uint8_t *strend = strstart + count;
155
0
    Pos *headp = s->head;
156
157
0
    for (uint32_t idx = str; strstart < strend; idx++, strstart++) {
158
0
        uint32_t val, h;
159
160
0
        val = Z_U32_FROM_LE(zng_memread_4(strstart));
161
0
        UPDATE_HASH_KNUTH(h, val);
162
163
0
        headp[h] = (Pos)idx;
164
0
    }
165
0
}
Unexecuted instantiation: deflate.c:insert_knuth_batch_head_static
Unexecuted instantiation: deflate_fast.c:insert_knuth_batch_head_static
Unexecuted instantiation: deflate_medium.c:insert_knuth_batch_head_static
Unexecuted instantiation: deflate_quick.c:insert_knuth_batch_head_static
Unexecuted instantiation: deflate_slow.c:insert_knuth_batch_head_static
Unexecuted instantiation: insert_string.c:insert_knuth_batch_head_static
Unexecuted instantiation: compare256_sse2.c:insert_knuth_batch_head_static
Unexecuted instantiation: compare256_avx2.c:insert_knuth_batch_head_static
Unexecuted instantiation: compare256_avx512.c:insert_knuth_batch_head_static
166
167
0
Z_FORCEINLINE static void insert_roll_batch_static(deflate_state *const s, unsigned char *window, uint32_t str, uint32_t count) {
168
0
    uint8_t *strstart = window + str + (STD_MIN_MATCH-1);
169
0
    uint8_t *strend = strstart + count;
170
171
    /* Local pointers to avoid indirection */
172
0
    Pos *headp = s->head;
173
0
    Pos *prevp = s->prev;
174
0
    uint32_t h = s->ins_h;
175
0
    const unsigned int w_mask = W_MASK(s);
176
177
0
    for (uint32_t idx = str; strstart < strend; idx++, strstart++) {
178
0
        uint32_t head;
179
180
0
        UPDATE_HASH_ROLL(h, strstart[0]);
181
182
0
        head = headp[h];
183
0
        if (LIKELY(head != idx)) {
184
0
            prevp[idx & w_mask] = (Pos)head;
185
0
            headp[h] = (Pos)idx;
186
0
        }
187
0
    }
188
0
    s->ins_h = h;
189
0
}
Unexecuted instantiation: deflate.c:insert_roll_batch_static
Unexecuted instantiation: deflate_fast.c:insert_roll_batch_static
Unexecuted instantiation: deflate_medium.c:insert_roll_batch_static
Unexecuted instantiation: deflate_quick.c:insert_roll_batch_static
Unexecuted instantiation: deflate_slow.c:insert_roll_batch_static
Unexecuted instantiation: insert_string.c:insert_roll_batch_static
Unexecuted instantiation: compare256_sse2.c:insert_roll_batch_static
Unexecuted instantiation: compare256_avx2.c:insert_roll_batch_static
Unexecuted instantiation: compare256_avx512.c:insert_roll_batch_static
190
191
#endif