Coverage Report

Created: 2026-08-31 06:47

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
182M
#define KNUTH_SHIFT (32 - HASH_BITS)
10
182M
#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
132M
#define ROLL_MASK ((HASH_SIZE / 2) - 1u))
18
132M
#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
43.4M
Z_FORCEINLINE static uint32_t update_hash_roll(uint32_t h, uint32_t val) {
27
43.4M
    UPDATE_HASH_ROLL(h, val);
28
43.4M
    return h;
29
43.4M
}
deflate.c:update_hash_roll
Line
Count
Source
26
4.79k
Z_FORCEINLINE static uint32_t update_hash_roll(uint32_t h, uint32_t val) {
27
4.79k
    UPDATE_HASH_ROLL(h, val);
28
4.79k
    return h;
29
4.79k
}
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
compare256_avx2.c:update_hash_roll
Line
Count
Source
26
43.4M
Z_FORCEINLINE static uint32_t update_hash_roll(uint32_t h, uint32_t val) {
27
43.4M
    UPDATE_HASH_ROLL(h, val);
28
43.4M
    return h;
29
43.4M
}
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
19.0M
Z_FORCEINLINE static uint32_t insert_knuth_val(deflate_state *const s, uint32_t str, uint32_t val) {
37
19.0M
    uint32_t h, head;
38
39
19.0M
    UPDATE_HASH_KNUTH(h, val);
40
41
19.0M
    head = s->head[h];
42
19.0M
    if (LIKELY(head != str)) {
43
19.0M
        s->prev[str & W_MASK(s)] = (Pos)head;
44
19.0M
        s->head[h] = (Pos)str;
45
19.0M
    }
46
19.0M
    return head;
47
19.0M
}
Unexecuted instantiation: deflate.c:insert_knuth_val
deflate_fast.c:insert_knuth_val
Line
Count
Source
36
19.0M
Z_FORCEINLINE static uint32_t insert_knuth_val(deflate_state *const s, uint32_t str, uint32_t val) {
37
19.0M
    uint32_t h, head;
38
39
19.0M
    UPDATE_HASH_KNUTH(h, val);
40
41
19.0M
    head = s->head[h];
42
19.0M
    if (LIKELY(head != str)) {
43
19.0M
        s->prev[str & W_MASK(s)] = (Pos)head;
44
19.0M
        s->head[h] = (Pos)str;
45
19.0M
    }
46
19.0M
    return head;
47
19.0M
}
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
74.9M
Z_FORCEINLINE static uint32_t insert_knuth_val_head(deflate_state *const s, uint32_t str, uint32_t val) {
55
74.9M
    uint32_t h, head;
56
57
74.9M
    UPDATE_HASH_KNUTH(h, val);
58
59
74.9M
    head = s->head[h];
60
74.9M
    s->head[h] = (Pos)str;
61
74.9M
    return head;
62
74.9M
}
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
74.9M
Z_FORCEINLINE static uint32_t insert_knuth_val_head(deflate_state *const s, uint32_t str, uint32_t val) {
55
74.9M
    uint32_t h, head;
56
57
74.9M
    UPDATE_HASH_KNUTH(h, val);
58
59
74.9M
    head = s->head[h];
60
74.9M
    s->head[h] = (Pos)str;
61
74.9M
    return head;
62
74.9M
}
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
56.6M
Z_FORCEINLINE static uint32_t insert_knuth(deflate_state *const s, unsigned char *window, uint32_t str) {
70
56.6M
    uint8_t *strstart = window + str;
71
56.6M
    uint32_t val, h, head;
72
73
56.6M
    val = Z_U32_FROM_LE(zng_memread_4(strstart));
74
56.6M
    UPDATE_HASH_KNUTH(h, val);
75
76
56.6M
    head = s->head[h];
77
56.6M
    if (LIKELY(head != str)) {
78
56.6M
        s->prev[str & W_MASK(s)] = (Pos)head;
79
56.6M
        s->head[h] = (Pos)str;
80
56.6M
    }
81
56.6M
    return head;
82
56.6M
}
deflate.c:insert_knuth
Line
Count
Source
69
6.17k
Z_FORCEINLINE static uint32_t insert_knuth(deflate_state *const s, unsigned char *window, uint32_t str) {
70
6.17k
    uint8_t *strstart = window + str;
71
6.17k
    uint32_t val, h, head;
72
73
6.17k
    val = Z_U32_FROM_LE(zng_memread_4(strstart));
74
6.17k
    UPDATE_HASH_KNUTH(h, val);
75
76
6.17k
    head = s->head[h];
77
6.17k
    if (LIKELY(head != str)) {
78
2.36k
        s->prev[str & W_MASK(s)] = (Pos)head;
79
2.36k
        s->head[h] = (Pos)str;
80
2.36k
    }
81
6.17k
    return head;
82
6.17k
}
deflate_fast.c:insert_knuth
Line
Count
Source
69
356k
Z_FORCEINLINE static uint32_t insert_knuth(deflate_state *const s, unsigned char *window, uint32_t str) {
70
356k
    uint8_t *strstart = window + str;
71
356k
    uint32_t val, h, head;
72
73
356k
    val = Z_U32_FROM_LE(zng_memread_4(strstart));
74
356k
    UPDATE_HASH_KNUTH(h, val);
75
76
356k
    head = s->head[h];
77
356k
    if (LIKELY(head != str)) {
78
356k
        s->prev[str & W_MASK(s)] = (Pos)head;
79
356k
        s->head[h] = (Pos)str;
80
356k
    }
81
356k
    return head;
82
356k
}
deflate_medium.c:insert_knuth
Line
Count
Source
69
41.6M
Z_FORCEINLINE static uint32_t insert_knuth(deflate_state *const s, unsigned char *window, uint32_t str) {
70
41.6M
    uint8_t *strstart = window + str;
71
41.6M
    uint32_t val, h, head;
72
73
41.6M
    val = Z_U32_FROM_LE(zng_memread_4(strstart));
74
41.6M
    UPDATE_HASH_KNUTH(h, val);
75
76
41.6M
    head = s->head[h];
77
41.6M
    if (LIKELY(head != str)) {
78
41.6M
        s->prev[str & W_MASK(s)] = (Pos)head;
79
41.6M
        s->head[h] = (Pos)str;
80
41.6M
    }
81
41.6M
    return head;
82
41.6M
}
Unexecuted instantiation: deflate_quick.c:insert_knuth
deflate_slow.c:insert_knuth
Line
Count
Source
69
14.6M
Z_FORCEINLINE static uint32_t insert_knuth(deflate_state *const s, unsigned char *window, uint32_t str) {
70
14.6M
    uint8_t *strstart = window + str;
71
14.6M
    uint32_t val, h, head;
72
73
14.6M
    val = Z_U32_FROM_LE(zng_memread_4(strstart));
74
14.6M
    UPDATE_HASH_KNUTH(h, val);
75
76
14.6M
    head = s->head[h];
77
14.6M
    if (LIKELY(head != str)) {
78
14.6M
        s->prev[str & W_MASK(s)] = (Pos)head;
79
14.6M
        s->head[h] = (Pos)str;
80
14.6M
    }
81
14.6M
    return head;
82
14.6M
}
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
2.43k
Z_FORCEINLINE static uint32_t insert_knuth_head(deflate_state *const s, unsigned char *window, uint32_t str) {
90
2.43k
    uint8_t *strstart = window + str;
91
2.43k
    uint32_t val, h, head;
92
93
2.43k
    val = Z_U32_FROM_LE(zng_memread_4(strstart));
94
2.43k
    UPDATE_HASH_KNUTH(h, val);
95
96
2.43k
    head = s->head[h];
97
2.43k
    s->head[h] = (Pos)str;
98
2.43k
    return head;
99
2.43k
}
deflate.c:insert_knuth_head
Line
Count
Source
89
2.43k
Z_FORCEINLINE static uint32_t insert_knuth_head(deflate_state *const s, unsigned char *window, uint32_t str) {
90
2.43k
    uint8_t *strstart = window + str;
91
2.43k
    uint32_t val, h, head;
92
93
2.43k
    val = Z_U32_FROM_LE(zng_memread_4(strstart));
94
2.43k
    UPDATE_HASH_KNUTH(h, val);
95
96
2.43k
    head = s->head[h];
97
2.43k
    s->head[h] = (Pos)str;
98
2.43k
    return head;
99
2.43k
}
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
55.3M
Z_FORCEINLINE static uint32_t insert_roll(deflate_state *const s, unsigned char *window, uint32_t str) {
102
55.3M
    uint8_t *strstart = window + str + (STD_MIN_MATCH-1);
103
55.3M
    uint32_t h, head;
104
105
55.3M
    h = s->ins_h;
106
55.3M
    UPDATE_HASH_ROLL(h, strstart[0]);
107
55.3M
    s->ins_h = h;
108
109
55.3M
    head = s->head[h];
110
55.3M
    if (LIKELY(head != str)) {
111
55.3M
        s->prev[str & W_MASK(s)] = (Pos)head;
112
55.3M
        s->head[h] = (Pos)str;
113
55.3M
    }
114
55.3M
    return head;
115
55.3M
}
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
deflate_slow.c:insert_roll
Line
Count
Source
101
55.3M
Z_FORCEINLINE static uint32_t insert_roll(deflate_state *const s, unsigned char *window, uint32_t str) {
102
55.3M
    uint8_t *strstart = window + str + (STD_MIN_MATCH-1);
103
55.3M
    uint32_t h, head;
104
105
55.3M
    h = s->ins_h;
106
55.3M
    UPDATE_HASH_ROLL(h, strstart[0]);
107
55.3M
    s->ins_h = h;
108
109
55.3M
    head = s->head[h];
110
55.3M
    if (LIKELY(head != str)) {
111
55.3M
        s->prev[str & W_MASK(s)] = (Pos)head;
112
55.3M
        s->head[h] = (Pos)str;
113
55.3M
    }
114
55.3M
    return head;
115
55.3M
}
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
3.36M
Z_FORCEINLINE static void insert_knuth_batch_static(deflate_state *const s, unsigned char *window, uint32_t str, uint32_t count) {
126
3.36M
    uint8_t *strstart = window + str;
127
3.36M
    uint8_t *strend = strstart + count;
128
129
    /* Local pointers to avoid indirection */
130
3.36M
    Pos *headp = s->head;
131
3.36M
    Pos *prevp = s->prev;
132
3.36M
    const unsigned int w_mask = W_MASK(s);
133
134
35.0M
    for (uint32_t idx = str; strstart < strend; idx++, strstart++) {
135
31.7M
        uint32_t val, h, head;
136
137
31.7M
        val = Z_U32_FROM_LE(zng_memread_4(strstart));
138
31.7M
        UPDATE_HASH_KNUTH(h, val);
139
140
31.7M
        head = headp[h];
141
31.7M
        if (LIKELY(head != idx)) {
142
31.7M
            prevp[idx & w_mask] = (Pos)head;
143
31.7M
            headp[h] = (Pos)idx;
144
31.7M
        }
145
31.7M
    }
146
3.36M
}
Unexecuted instantiation: deflate.c:insert_knuth_batch_static
deflate_fast.c:insert_knuth_batch_static
Line
Count
Source
125
694k
Z_FORCEINLINE static void insert_knuth_batch_static(deflate_state *const s, unsigned char *window, uint32_t str, uint32_t count) {
126
694k
    uint8_t *strstart = window + str;
127
694k
    uint8_t *strend = strstart + count;
128
129
    /* Local pointers to avoid indirection */
130
694k
    Pos *headp = s->head;
131
694k
    Pos *prevp = s->prev;
132
694k
    const unsigned int w_mask = W_MASK(s);
133
134
2.77M
    for (uint32_t idx = str; strstart < strend; idx++, strstart++) {
135
2.08M
        uint32_t val, h, head;
136
137
2.08M
        val = Z_U32_FROM_LE(zng_memread_4(strstart));
138
2.08M
        UPDATE_HASH_KNUTH(h, val);
139
140
2.08M
        head = headp[h];
141
2.08M
        if (LIKELY(head != idx)) {
142
2.08M
            prevp[idx & w_mask] = (Pos)head;
143
2.08M
            headp[h] = (Pos)idx;
144
2.08M
        }
145
2.08M
    }
146
694k
}
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
2.67M
Z_FORCEINLINE static void insert_knuth_batch_static(deflate_state *const s, unsigned char *window, uint32_t str, uint32_t count) {
126
2.67M
    uint8_t *strstart = window + str;
127
2.67M
    uint8_t *strend = strstart + count;
128
129
    /* Local pointers to avoid indirection */
130
2.67M
    Pos *headp = s->head;
131
2.67M
    Pos *prevp = s->prev;
132
2.67M
    const unsigned int w_mask = W_MASK(s);
133
134
32.3M
    for (uint32_t idx = str; strstart < strend; idx++, strstart++) {
135
29.6M
        uint32_t val, h, head;
136
137
29.6M
        val = Z_U32_FROM_LE(zng_memread_4(strstart));
138
29.6M
        UPDATE_HASH_KNUTH(h, val);
139
140
29.6M
        head = headp[h];
141
29.6M
        if (LIKELY(head != idx)) {
142
29.6M
            prevp[idx & w_mask] = (Pos)head;
143
29.6M
            headp[h] = (Pos)idx;
144
29.6M
        }
145
29.6M
    }
146
2.67M
}
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
6.31M
Z_FORCEINLINE static void insert_roll_batch_static(deflate_state *const s, unsigned char *window, uint32_t str, uint32_t count) {
168
6.31M
    uint8_t *strstart = window + str + (STD_MIN_MATCH-1);
169
6.31M
    uint8_t *strend = strstart + count;
170
171
    /* Local pointers to avoid indirection */
172
6.31M
    Pos *headp = s->head;
173
6.31M
    Pos *prevp = s->prev;
174
6.31M
    uint32_t h = s->ins_h;
175
6.31M
    const unsigned int w_mask = W_MASK(s);
176
177
40.1M
    for (uint32_t idx = str; strstart < strend; idx++, strstart++) {
178
33.8M
        uint32_t head;
179
180
33.8M
        UPDATE_HASH_ROLL(h, strstart[0]);
181
182
33.8M
        head = headp[h];
183
33.8M
        if (LIKELY(head != idx)) {
184
33.8M
            prevp[idx & w_mask] = (Pos)head;
185
33.8M
            headp[h] = (Pos)idx;
186
33.8M
        }
187
33.8M
    }
188
6.31M
    s->ins_h = h;
189
6.31M
}
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
insert_string.c:insert_roll_batch_static
Line
Count
Source
167
6.31M
Z_FORCEINLINE static void insert_roll_batch_static(deflate_state *const s, unsigned char *window, uint32_t str, uint32_t count) {
168
6.31M
    uint8_t *strstart = window + str + (STD_MIN_MATCH-1);
169
6.31M
    uint8_t *strend = strstart + count;
170
171
    /* Local pointers to avoid indirection */
172
6.31M
    Pos *headp = s->head;
173
6.31M
    Pos *prevp = s->prev;
174
6.31M
    uint32_t h = s->ins_h;
175
6.31M
    const unsigned int w_mask = W_MASK(s);
176
177
40.1M
    for (uint32_t idx = str; strstart < strend; idx++, strstart++) {
178
33.8M
        uint32_t head;
179
180
33.8M
        UPDATE_HASH_ROLL(h, strstart[0]);
181
182
33.8M
        head = headp[h];
183
33.8M
        if (LIKELY(head != idx)) {
184
33.8M
            prevp[idx & w_mask] = (Pos)head;
185
33.8M
            headp[h] = (Pos)idx;
186
33.8M
        }
187
33.8M
    }
188
6.31M
    s->ins_h = h;
189
6.31M
}
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