/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 | 12.8M | #define KNUTH_SHIFT (32 - HASH_BITS) |
10 | 12.8M | #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 | 10.5M | #define ROLL_MASK ((HASH_SIZE / 2) - 1u)) |
18 | 10.5M | #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 | 5.39M | Z_FORCEINLINE static uint32_t update_hash_roll(uint32_t h, uint32_t val) { |
27 | 5.39M | UPDATE_HASH_ROLL(h, val); |
28 | 5.39M | return h; |
29 | 5.39M | } deflate.c:update_hash_roll Line | Count | Source | 26 | 10.3k | Z_FORCEINLINE static uint32_t update_hash_roll(uint32_t h, uint32_t val) { | 27 | 10.3k | UPDATE_HASH_ROLL(h, val); | 28 | 10.3k | return h; | 29 | 10.3k | } |
Unexecuted instantiation: deflate_fast.c:update_hash_roll Unexecuted instantiation: deflate_medium.c:update_hash_roll Unexecuted instantiation: deflate_quick.c:update_hash_roll deflate_slow.c:update_hash_roll Line | Count | Source | 26 | 8.37k | Z_FORCEINLINE static uint32_t update_hash_roll(uint32_t h, uint32_t val) { | 27 | 8.37k | UPDATE_HASH_ROLL(h, val); | 28 | 8.37k | return h; | 29 | 8.37k | } |
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 | 5.37M | Z_FORCEINLINE static uint32_t update_hash_roll(uint32_t h, uint32_t val) { | 27 | 5.37M | UPDATE_HASH_ROLL(h, val); | 28 | 5.37M | return h; | 29 | 5.37M | } |
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 | 733k | Z_FORCEINLINE static uint32_t insert_knuth_val(deflate_state *const s, uint32_t str, uint32_t val) { |
37 | 733k | uint32_t h, head; |
38 | | |
39 | 733k | UPDATE_HASH_KNUTH(h, val); |
40 | | |
41 | 733k | head = s->head[h]; |
42 | 733k | if (LIKELY(head != str)) { |
43 | 733k | s->prev[str & W_MASK(s)] = (Pos)head; |
44 | 733k | s->head[h] = (Pos)str; |
45 | 733k | } |
46 | 733k | return head; |
47 | 733k | } Unexecuted instantiation: deflate.c:insert_knuth_val deflate_fast.c:insert_knuth_val Line | Count | Source | 36 | 733k | Z_FORCEINLINE static uint32_t insert_knuth_val(deflate_state *const s, uint32_t str, uint32_t val) { | 37 | 733k | uint32_t h, head; | 38 | | | 39 | 733k | UPDATE_HASH_KNUTH(h, val); | 40 | | | 41 | 733k | head = s->head[h]; | 42 | 733k | if (LIKELY(head != str)) { | 43 | 733k | s->prev[str & W_MASK(s)] = (Pos)head; | 44 | 733k | s->head[h] = (Pos)str; | 45 | 733k | } | 46 | 733k | return head; | 47 | 733k | } |
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 | 0 | Z_FORCEINLINE static uint32_t insert_knuth_val_head(deflate_state *const s, uint32_t str, uint32_t val) { |
55 | 0 | uint32_t h, head; |
56 | |
|
57 | 0 | UPDATE_HASH_KNUTH(h, val); |
58 | |
|
59 | 0 | head = s->head[h]; |
60 | 0 | s->head[h] = (Pos)str; |
61 | 0 | return head; |
62 | 0 | } 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 Unexecuted instantiation: deflate_quick.c:insert_knuth_val_head 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 | 3.07M | Z_FORCEINLINE static uint32_t insert_knuth(deflate_state *const s, unsigned char *window, uint32_t str) { |
70 | 3.07M | uint8_t *strstart = window + str; |
71 | 3.07M | uint32_t val, h, head; |
72 | | |
73 | 3.07M | val = Z_U32_FROM_LE(zng_memread_4(strstart)); |
74 | 3.07M | UPDATE_HASH_KNUTH(h, val); |
75 | | |
76 | 3.07M | head = s->head[h]; |
77 | 3.07M | if (LIKELY(head != str)) { |
78 | 3.05M | s->prev[str & W_MASK(s)] = (Pos)head; |
79 | 3.05M | s->head[h] = (Pos)str; |
80 | 3.05M | } |
81 | 3.07M | return head; |
82 | 3.07M | } Line | Count | Source | 69 | 23.3k | Z_FORCEINLINE static uint32_t insert_knuth(deflate_state *const s, unsigned char *window, uint32_t str) { | 70 | 23.3k | uint8_t *strstart = window + str; | 71 | 23.3k | uint32_t val, h, head; | 72 | | | 73 | 23.3k | val = Z_U32_FROM_LE(zng_memread_4(strstart)); | 74 | 23.3k | UPDATE_HASH_KNUTH(h, val); | 75 | | | 76 | 23.3k | head = s->head[h]; | 77 | 23.3k | if (LIKELY(head != str)) { | 78 | 5.82k | s->prev[str & W_MASK(s)] = (Pos)head; | 79 | 5.82k | s->head[h] = (Pos)str; | 80 | 5.82k | } | 81 | 23.3k | return head; | 82 | 23.3k | } |
deflate_fast.c:insert_knuth Line | Count | Source | 69 | 558 | Z_FORCEINLINE static uint32_t insert_knuth(deflate_state *const s, unsigned char *window, uint32_t str) { | 70 | 558 | uint8_t *strstart = window + str; | 71 | 558 | uint32_t val, h, head; | 72 | | | 73 | 558 | val = Z_U32_FROM_LE(zng_memread_4(strstart)); | 74 | 558 | UPDATE_HASH_KNUTH(h, val); | 75 | | | 76 | 558 | head = s->head[h]; | 77 | 558 | if (LIKELY(head != str)) { | 78 | 558 | s->prev[str & W_MASK(s)] = (Pos)head; | 79 | 558 | s->head[h] = (Pos)str; | 80 | 558 | } | 81 | 558 | return head; | 82 | 558 | } |
deflate_medium.c:insert_knuth Line | Count | Source | 69 | 2.45M | Z_FORCEINLINE static uint32_t insert_knuth(deflate_state *const s, unsigned char *window, uint32_t str) { | 70 | 2.45M | uint8_t *strstart = window + str; | 71 | 2.45M | uint32_t val, h, head; | 72 | | | 73 | 2.45M | val = Z_U32_FROM_LE(zng_memread_4(strstart)); | 74 | 2.45M | UPDATE_HASH_KNUTH(h, val); | 75 | | | 76 | 2.45M | head = s->head[h]; | 77 | 2.45M | if (LIKELY(head != str)) { | 78 | 2.45M | s->prev[str & W_MASK(s)] = (Pos)head; | 79 | 2.45M | s->head[h] = (Pos)str; | 80 | 2.45M | } | 81 | 2.45M | return head; | 82 | 2.45M | } |
Unexecuted instantiation: deflate_quick.c:insert_knuth deflate_slow.c:insert_knuth Line | Count | Source | 69 | 592k | Z_FORCEINLINE static uint32_t insert_knuth(deflate_state *const s, unsigned char *window, uint32_t str) { | 70 | 592k | uint8_t *strstart = window + str; | 71 | 592k | uint32_t val, h, head; | 72 | | | 73 | 592k | val = Z_U32_FROM_LE(zng_memread_4(strstart)); | 74 | 592k | UPDATE_HASH_KNUTH(h, val); | 75 | | | 76 | 592k | head = s->head[h]; | 77 | 592k | if (LIKELY(head != str)) { | 78 | 592k | s->prev[str & W_MASK(s)] = (Pos)head; | 79 | 592k | s->head[h] = (Pos)str; | 80 | 592k | } | 81 | 592k | return head; | 82 | 592k | } |
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 | 0 | Z_FORCEINLINE static uint32_t insert_knuth_head(deflate_state *const s, unsigned char *window, uint32_t str) { |
90 | 0 | uint8_t *strstart = window + str; |
91 | 0 | uint32_t val, h, head; |
92 | |
|
93 | 0 | val = Z_U32_FROM_LE(zng_memread_4(strstart)); |
94 | 0 | UPDATE_HASH_KNUTH(h, val); |
95 | |
|
96 | 0 | head = s->head[h]; |
97 | 0 | s->head[h] = (Pos)str; |
98 | 0 | return head; |
99 | 0 | } Unexecuted instantiation: deflate.c:insert_knuth_head 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 | | /* =========================================================================== |
102 | | * Insert a single position into the dictionary using passed table pointers. |
103 | | */ |
104 | 371k | Z_FORCEINLINE static void insert_knuth_one(Pos *headp, Pos *prevp, const unsigned int w_mask, const unsigned char *window, uint32_t idx) { |
105 | 371k | uint32_t val, h, head; |
106 | | |
107 | 371k | val = Z_U32_FROM_LE(zng_memread_4(window + idx)); |
108 | 371k | UPDATE_HASH_KNUTH(h, val); |
109 | | |
110 | 371k | head = headp[h]; |
111 | 371k | if (LIKELY(head != idx)) { |
112 | 371k | prevp[idx & w_mask] = (Pos)head; |
113 | 371k | headp[h] = (Pos)idx; |
114 | 371k | } |
115 | 371k | } Unexecuted instantiation: deflate.c:insert_knuth_one deflate_fast.c:insert_knuth_one Line | Count | Source | 104 | 371k | Z_FORCEINLINE static void insert_knuth_one(Pos *headp, Pos *prevp, const unsigned int w_mask, const unsigned char *window, uint32_t idx) { | 105 | 371k | uint32_t val, h, head; | 106 | | | 107 | 371k | val = Z_U32_FROM_LE(zng_memread_4(window + idx)); | 108 | 371k | UPDATE_HASH_KNUTH(h, val); | 109 | | | 110 | 371k | head = headp[h]; | 111 | 371k | if (LIKELY(head != idx)) { | 112 | 371k | prevp[idx & w_mask] = (Pos)head; | 113 | 371k | headp[h] = (Pos)idx; | 114 | 371k | } | 115 | 371k | } |
Unexecuted instantiation: deflate_medium.c:insert_knuth_one Unexecuted instantiation: deflate_quick.c:insert_knuth_one Unexecuted instantiation: deflate_slow.c:insert_knuth_one Unexecuted instantiation: insert_string.c:insert_knuth_one Unexecuted instantiation: compare256_sse2.c:insert_knuth_one Unexecuted instantiation: compare256_avx2.c:insert_knuth_one Unexecuted instantiation: compare256_avx512.c:insert_knuth_one |
116 | | |
117 | 1.63M | Z_FORCEINLINE static uint32_t insert_roll(deflate_state *const s, unsigned char *window, uint32_t str) { |
118 | 1.63M | uint8_t *strstart = window + str + (STD_MIN_MATCH-1); |
119 | 1.63M | uint32_t h, head; |
120 | | |
121 | 1.63M | h = s->ins_h; |
122 | 1.63M | UPDATE_HASH_ROLL(h, strstart[0]); |
123 | 1.63M | s->ins_h = h; |
124 | | |
125 | 1.63M | head = s->head[h]; |
126 | 1.63M | if (LIKELY(head != str)) { |
127 | 1.63M | s->prev[str & W_MASK(s)] = (Pos)head; |
128 | 1.63M | s->head[h] = (Pos)str; |
129 | 1.63M | } |
130 | 1.63M | return head; |
131 | 1.63M | } 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 | 117 | 1.63M | Z_FORCEINLINE static uint32_t insert_roll(deflate_state *const s, unsigned char *window, uint32_t str) { | 118 | 1.63M | uint8_t *strstart = window + str + (STD_MIN_MATCH-1); | 119 | 1.63M | uint32_t h, head; | 120 | | | 121 | 1.63M | h = s->ins_h; | 122 | 1.63M | UPDATE_HASH_ROLL(h, strstart[0]); | 123 | 1.63M | s->ins_h = h; | 124 | | | 125 | 1.63M | head = s->head[h]; | 126 | 1.63M | if (LIKELY(head != str)) { | 127 | 1.63M | s->prev[str & W_MASK(s)] = (Pos)head; | 128 | 1.63M | s->head[h] = (Pos)str; | 129 | 1.63M | } | 130 | 1.63M | return head; | 131 | 1.63M | } |
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 |
132 | | |
133 | | /* =========================================================================== |
134 | | * Insert string str in the dictionary and set match_head to the previous head |
135 | | * of the hash chain (the most recent string with same hash key). Return |
136 | | * the previous length of the hash chain. |
137 | | * IN assertion: all calls to insert_knuth_batch are made with consecutive |
138 | | * input characters and the first STD_MIN_MATCH bytes of str are valid |
139 | | * (except for the last STD_MIN_MATCH-1 bytes of the input file). |
140 | | */ |
141 | 353k | Z_FORCEINLINE static void insert_knuth_batch_static(deflate_state *const s, unsigned char *window, uint32_t str, uint32_t count) { |
142 | 353k | uint8_t *strstart = window + str; |
143 | 353k | uint8_t *strend = strstart + count; |
144 | | |
145 | | /* Local pointers to avoid indirection */ |
146 | 353k | Pos *headp = s->head; |
147 | 353k | Pos *prevp = s->prev; |
148 | 353k | const unsigned int w_mask = W_MASK(s); |
149 | | |
150 | 6.67M | for (uint32_t idx = str; strstart < strend; idx++, strstart++) { |
151 | 6.32M | uint32_t val, h, head; |
152 | | |
153 | 6.32M | val = Z_U32_FROM_LE(zng_memread_4(strstart)); |
154 | 6.32M | UPDATE_HASH_KNUTH(h, val); |
155 | | |
156 | 6.32M | head = headp[h]; |
157 | 6.32M | if (LIKELY(head != idx)) { |
158 | 6.31M | prevp[idx & w_mask] = (Pos)head; |
159 | 6.31M | headp[h] = (Pos)idx; |
160 | 6.31M | } |
161 | 6.32M | } |
162 | 353k | } 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 deflate_slow.c:insert_knuth_batch_static Line | Count | Source | 141 | 5.79k | Z_FORCEINLINE static void insert_knuth_batch_static(deflate_state *const s, unsigned char *window, uint32_t str, uint32_t count) { | 142 | 5.79k | uint8_t *strstart = window + str; | 143 | 5.79k | uint8_t *strend = strstart + count; | 144 | | | 145 | | /* Local pointers to avoid indirection */ | 146 | 5.79k | Pos *headp = s->head; | 147 | 5.79k | Pos *prevp = s->prev; | 148 | 5.79k | const unsigned int w_mask = W_MASK(s); | 149 | | | 150 | 468k | for (uint32_t idx = str; strstart < strend; idx++, strstart++) { | 151 | 462k | uint32_t val, h, head; | 152 | | | 153 | 462k | val = Z_U32_FROM_LE(zng_memread_4(strstart)); | 154 | 462k | UPDATE_HASH_KNUTH(h, val); | 155 | | | 156 | 462k | head = headp[h]; | 157 | 462k | if (LIKELY(head != idx)) { | 158 | 462k | prevp[idx & w_mask] = (Pos)head; | 159 | 462k | headp[h] = (Pos)idx; | 160 | 462k | } | 161 | 462k | } | 162 | 5.79k | } |
insert_string.c:insert_knuth_batch_static Line | Count | Source | 141 | 348k | Z_FORCEINLINE static void insert_knuth_batch_static(deflate_state *const s, unsigned char *window, uint32_t str, uint32_t count) { | 142 | 348k | uint8_t *strstart = window + str; | 143 | 348k | uint8_t *strend = strstart + count; | 144 | | | 145 | | /* Local pointers to avoid indirection */ | 146 | 348k | Pos *headp = s->head; | 147 | 348k | Pos *prevp = s->prev; | 148 | 348k | const unsigned int w_mask = W_MASK(s); | 149 | | | 150 | 6.20M | for (uint32_t idx = str; strstart < strend; idx++, strstart++) { | 151 | 5.85M | uint32_t val, h, head; | 152 | | | 153 | 5.85M | val = Z_U32_FROM_LE(zng_memread_4(strstart)); | 154 | 5.85M | UPDATE_HASH_KNUTH(h, val); | 155 | | | 156 | 5.85M | head = headp[h]; | 157 | 5.85M | if (LIKELY(head != idx)) { | 158 | 5.85M | prevp[idx & w_mask] = (Pos)head; | 159 | 5.85M | headp[h] = (Pos)idx; | 160 | 5.85M | } | 161 | 5.85M | } | 162 | 348k | } |
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 |
163 | | |
164 | | /* =========================================================================== |
165 | | * Like insert_knuth_batch_static(), except this spreads out max_inserts hashes over |
166 | | * the length of count. Also ensures that both the first and last entry gets hashed. |
167 | | * This assumes both count and max_inserts are 258 or less. |
168 | | */ |
169 | 33.2k | Z_FORCEINLINE static void insert_knuth_stepped_static(deflate_state *const s, unsigned char *window, uint32_t str, uint32_t count, uint32_t max_inserts) { |
170 | 33.2k | Assert(count >= 3, "Insert count too low"); |
171 | 33.2k | Assert(max_inserts >= 2, "max_inserts too low"); |
172 | | |
173 | | /* Local pointers to avoid indirection */ |
174 | 33.2k | Pos *headp = s->head; |
175 | 33.2k | Pos *prevp = s->prev; |
176 | 33.2k | const unsigned int w_mask = W_MASK(s); |
177 | | |
178 | 33.2k | uint32_t inserts = (count < max_inserts) ? count : max_inserts; |
179 | 33.2k | uint32_t intervals = inserts - 1; |
180 | | |
181 | | /* |
182 | | * Calculate a 32-bit Fixed-Point Scale with a 16-bit fraction. |
183 | | * Safe from overflow since (count - 1) <= 257, meaning ((257 << 16) + 256) fits easily in 32 bits. |
184 | | * The rounding bias guarantees hitting the exact tail end ('str + count - 1') smoothly. |
185 | | */ |
186 | 33.2k | uint32_t inc_fp = (((count - 1) << 16) + (intervals - 1)) / intervals; |
187 | | |
188 | | /* Initialize the fixed-point index tracking register */ |
189 | 33.2k | uint32_t idx_fp = str << 16; |
190 | | |
191 | 1.33M | for (uint32_t i = 0; i < inserts; i++) { |
192 | 1.29M | uint32_t val, h, head, idx; |
193 | | |
194 | | /* Extract the real window index by shifting out the fractional bits */ |
195 | 1.29M | idx = idx_fp >> 16; |
196 | | |
197 | | /* Increment offset for next iteration */ |
198 | 1.29M | idx_fp += inc_fp; |
199 | | |
200 | 1.29M | val = Z_U32_FROM_LE(zng_memread_4(window + idx)); |
201 | 1.29M | UPDATE_HASH_KNUTH(h, val); |
202 | | |
203 | 1.29M | head = headp[h]; |
204 | 1.29M | if (LIKELY(head != idx)) { |
205 | 1.29M | prevp[idx & w_mask] = (Pos)head; |
206 | 1.29M | headp[h] = (Pos)idx; |
207 | 1.29M | } |
208 | 1.29M | } |
209 | 33.2k | } Unexecuted instantiation: deflate.c:insert_knuth_stepped_static Unexecuted instantiation: deflate_fast.c:insert_knuth_stepped_static Unexecuted instantiation: deflate_medium.c:insert_knuth_stepped_static Unexecuted instantiation: deflate_quick.c:insert_knuth_stepped_static Unexecuted instantiation: deflate_slow.c:insert_knuth_stepped_static insert_string.c:insert_knuth_stepped_static Line | Count | Source | 169 | 33.2k | Z_FORCEINLINE static void insert_knuth_stepped_static(deflate_state *const s, unsigned char *window, uint32_t str, uint32_t count, uint32_t max_inserts) { | 170 | 33.2k | Assert(count >= 3, "Insert count too low"); | 171 | 33.2k | Assert(max_inserts >= 2, "max_inserts too low"); | 172 | | | 173 | | /* Local pointers to avoid indirection */ | 174 | 33.2k | Pos *headp = s->head; | 175 | 33.2k | Pos *prevp = s->prev; | 176 | 33.2k | const unsigned int w_mask = W_MASK(s); | 177 | | | 178 | 33.2k | uint32_t inserts = (count < max_inserts) ? count : max_inserts; | 179 | 33.2k | uint32_t intervals = inserts - 1; | 180 | | | 181 | | /* | 182 | | * Calculate a 32-bit Fixed-Point Scale with a 16-bit fraction. | 183 | | * Safe from overflow since (count - 1) <= 257, meaning ((257 << 16) + 256) fits easily in 32 bits. | 184 | | * The rounding bias guarantees hitting the exact tail end ('str + count - 1') smoothly. | 185 | | */ | 186 | 33.2k | uint32_t inc_fp = (((count - 1) << 16) + (intervals - 1)) / intervals; | 187 | | | 188 | | /* Initialize the fixed-point index tracking register */ | 189 | 33.2k | uint32_t idx_fp = str << 16; | 190 | | | 191 | 1.33M | for (uint32_t i = 0; i < inserts; i++) { | 192 | 1.29M | uint32_t val, h, head, idx; | 193 | | | 194 | | /* Extract the real window index by shifting out the fractional bits */ | 195 | 1.29M | idx = idx_fp >> 16; | 196 | | | 197 | | /* Increment offset for next iteration */ | 198 | 1.29M | idx_fp += inc_fp; | 199 | | | 200 | 1.29M | val = Z_U32_FROM_LE(zng_memread_4(window + idx)); | 201 | 1.29M | UPDATE_HASH_KNUTH(h, val); | 202 | | | 203 | 1.29M | head = headp[h]; | 204 | 1.29M | if (LIKELY(head != idx)) { | 205 | 1.29M | prevp[idx & w_mask] = (Pos)head; | 206 | 1.29M | headp[h] = (Pos)idx; | 207 | 1.29M | } | 208 | 1.29M | } | 209 | 33.2k | } |
Unexecuted instantiation: compare256_sse2.c:insert_knuth_stepped_static Unexecuted instantiation: compare256_avx2.c:insert_knuth_stepped_static Unexecuted instantiation: compare256_avx512.c:insert_knuth_stepped_static |
210 | | |
211 | | /* =========================================================================== |
212 | | * Like insert_knuth_stepped_static(), except optimized for small max_inserts (deflate_fast levels) |
213 | | * The first and last position are always hashed, and an approximate middle position as well. |
214 | | * Larger max_inserts fall back to insert_knuth_stepped_static(). |
215 | | */ |
216 | 123k | Z_FORCEINLINE static void insert_knuth_spread_static(deflate_state *const s, unsigned char *window, uint32_t str, uint32_t count, uint32_t max_inserts) { |
217 | 123k | Assert(count >= 3, "Insert count too low"); |
218 | 123k | Assert(max_inserts >= 2, "max_inserts too low"); |
219 | | |
220 | 123k | if (UNLIKELY(max_inserts > 3)) { |
221 | | /* In case count is bigger than 3: tuned deflate_fast level params, or NO_MEDIUM_STRATEGY */ |
222 | 0 | insert_knuth_stepped(s, window, str, count, max_inserts); |
223 | 0 | return; |
224 | 0 | } |
225 | | |
226 | | /* Local pointers to avoid indirection */ |
227 | 123k | Pos *headp = s->head; |
228 | 123k | Pos *prevp = s->prev; |
229 | 123k | const unsigned int w_mask = W_MASK(s); |
230 | | |
231 | | /* Insert head and tail, and middle if needed */ |
232 | 123k | insert_knuth_one(headp, prevp, w_mask, window, str); |
233 | 123k | if (max_inserts == 3) |
234 | 123k | insert_knuth_one(headp, prevp, w_mask, window, str + ((count - 1) >> 1)); |
235 | 123k | insert_knuth_one(headp, prevp, w_mask, window, str + count - 1); |
236 | 123k | } Unexecuted instantiation: deflate.c:insert_knuth_spread_static deflate_fast.c:insert_knuth_spread_static Line | Count | Source | 216 | 123k | Z_FORCEINLINE static void insert_knuth_spread_static(deflate_state *const s, unsigned char *window, uint32_t str, uint32_t count, uint32_t max_inserts) { | 217 | 123k | Assert(count >= 3, "Insert count too low"); | 218 | 123k | Assert(max_inserts >= 2, "max_inserts too low"); | 219 | | | 220 | 123k | if (UNLIKELY(max_inserts > 3)) { | 221 | | /* In case count is bigger than 3: tuned deflate_fast level params, or NO_MEDIUM_STRATEGY */ | 222 | 0 | insert_knuth_stepped(s, window, str, count, max_inserts); | 223 | 0 | return; | 224 | 0 | } | 225 | | | 226 | | /* Local pointers to avoid indirection */ | 227 | 123k | Pos *headp = s->head; | 228 | 123k | Pos *prevp = s->prev; | 229 | 123k | const unsigned int w_mask = W_MASK(s); | 230 | | | 231 | | /* Insert head and tail, and middle if needed */ | 232 | 123k | insert_knuth_one(headp, prevp, w_mask, window, str); | 233 | 123k | if (max_inserts == 3) | 234 | 123k | insert_knuth_one(headp, prevp, w_mask, window, str + ((count - 1) >> 1)); | 235 | 123k | insert_knuth_one(headp, prevp, w_mask, window, str + count - 1); | 236 | 123k | } |
Unexecuted instantiation: deflate_medium.c:insert_knuth_spread_static Unexecuted instantiation: deflate_quick.c:insert_knuth_spread_static Unexecuted instantiation: deflate_slow.c:insert_knuth_spread_static Unexecuted instantiation: insert_string.c:insert_knuth_spread_static Unexecuted instantiation: compare256_sse2.c:insert_knuth_spread_static Unexecuted instantiation: compare256_avx2.c:insert_knuth_spread_static Unexecuted instantiation: compare256_avx512.c:insert_knuth_spread_static |
237 | | |
238 | | /* =========================================================================== |
239 | | * Insert count strings read from the window, leaving the prev links untouched. |
240 | | * Used by fill_window during deflate_quick, which only inspects the chain head. |
241 | | */ |
242 | 0 | Z_FORCEINLINE static void insert_knuth_batch_head_static(deflate_state *const s, unsigned char *window, uint32_t str, uint32_t count) { |
243 | 0 | uint8_t *strstart = window + str; |
244 | 0 | uint8_t *strend = strstart + count; |
245 | 0 | Pos *headp = s->head; |
246 | |
|
247 | 0 | for (uint32_t idx = str; strstart < strend; idx++, strstart++) { |
248 | 0 | uint32_t val, h; |
249 | |
|
250 | 0 | val = Z_U32_FROM_LE(zng_memread_4(strstart)); |
251 | 0 | UPDATE_HASH_KNUTH(h, val); |
252 | |
|
253 | 0 | headp[h] = (Pos)idx; |
254 | 0 | } |
255 | 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 |
256 | | |
257 | 242k | Z_FORCEINLINE static void insert_roll_batch_static(deflate_state *const s, unsigned char *window, uint32_t str, uint32_t count) { |
258 | 242k | uint8_t *strstart = window + str + (STD_MIN_MATCH-1); |
259 | 242k | uint8_t *strend = strstart + count; |
260 | | |
261 | | /* Local pointers to avoid indirection */ |
262 | 242k | Pos *headp = s->head; |
263 | 242k | Pos *prevp = s->prev; |
264 | 242k | uint32_t h = s->ins_h; |
265 | 242k | const unsigned int w_mask = W_MASK(s); |
266 | | |
267 | 3.71M | for (uint32_t idx = str; strstart < strend; idx++, strstart++) { |
268 | 3.47M | uint32_t head; |
269 | | |
270 | 3.47M | UPDATE_HASH_ROLL(h, strstart[0]); |
271 | | |
272 | 3.47M | head = headp[h]; |
273 | 3.47M | if (LIKELY(head != idx)) { |
274 | 3.47M | prevp[idx & w_mask] = (Pos)head; |
275 | 3.47M | headp[h] = (Pos)idx; |
276 | 3.47M | } |
277 | 3.47M | } |
278 | 242k | s->ins_h = h; |
279 | 242k | } 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 deflate_slow.c:insert_roll_batch_static Line | Count | Source | 257 | 8.37k | Z_FORCEINLINE static void insert_roll_batch_static(deflate_state *const s, unsigned char *window, uint32_t str, uint32_t count) { | 258 | 8.37k | uint8_t *strstart = window + str + (STD_MIN_MATCH-1); | 259 | 8.37k | uint8_t *strend = strstart + count; | 260 | | | 261 | | /* Local pointers to avoid indirection */ | 262 | 8.37k | Pos *headp = s->head; | 263 | 8.37k | Pos *prevp = s->prev; | 264 | 8.37k | uint32_t h = s->ins_h; | 265 | 8.37k | const unsigned int w_mask = W_MASK(s); | 266 | | | 267 | 586k | for (uint32_t idx = str; strstart < strend; idx++, strstart++) { | 268 | 578k | uint32_t head; | 269 | | | 270 | 578k | UPDATE_HASH_ROLL(h, strstart[0]); | 271 | | | 272 | 578k | head = headp[h]; | 273 | 578k | if (LIKELY(head != idx)) { | 274 | 578k | prevp[idx & w_mask] = (Pos)head; | 275 | 578k | headp[h] = (Pos)idx; | 276 | 578k | } | 277 | 578k | } | 278 | 8.37k | s->ins_h = h; | 279 | 8.37k | } |
insert_string.c:insert_roll_batch_static Line | Count | Source | 257 | 233k | Z_FORCEINLINE static void insert_roll_batch_static(deflate_state *const s, unsigned char *window, uint32_t str, uint32_t count) { | 258 | 233k | uint8_t *strstart = window + str + (STD_MIN_MATCH-1); | 259 | 233k | uint8_t *strend = strstart + count; | 260 | | | 261 | | /* Local pointers to avoid indirection */ | 262 | 233k | Pos *headp = s->head; | 263 | 233k | Pos *prevp = s->prev; | 264 | 233k | uint32_t h = s->ins_h; | 265 | 233k | const unsigned int w_mask = W_MASK(s); | 266 | | | 267 | 3.13M | for (uint32_t idx = str; strstart < strend; idx++, strstart++) { | 268 | 2.89M | uint32_t head; | 269 | | | 270 | 2.89M | UPDATE_HASH_ROLL(h, strstart[0]); | 271 | | | 272 | 2.89M | head = headp[h]; | 273 | 2.89M | if (LIKELY(head != idx)) { | 274 | 2.89M | prevp[idx & w_mask] = (Pos)head; | 275 | 2.89M | headp[h] = (Pos)idx; | 276 | 2.89M | } | 277 | 2.89M | } | 278 | 233k | s->ins_h = h; | 279 | 233k | } |
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 |
280 | | |
281 | | /* =========================================================================== |
282 | | * Mark count strings as the end of their hash chain without inserting them. |
283 | | * longest_match reads prev for every position inside a candidate match, so a |
284 | | * skipped string must not keep a link from earlier input. |
285 | | */ |
286 | 14.1k | Z_FORCEINLINE static void insert_skip(deflate_state *const s, uint32_t str, uint32_t count) { |
287 | 14.1k | uint32_t idx = str & W_MASK(s); |
288 | | /* The range wraps around the end of prev at most once. */ |
289 | 14.1k | uint32_t first = MIN(count, s->w_size - idx); |
290 | | |
291 | 14.1k | memset(&s->prev[idx], 0, first * sizeof(Pos)); |
292 | 14.1k | memset(s->prev, 0, (count - first) * sizeof(Pos)); |
293 | 14.1k | } Unexecuted instantiation: deflate.c:insert_skip Unexecuted instantiation: deflate_fast.c:insert_skip Unexecuted instantiation: deflate_medium.c:insert_skip Unexecuted instantiation: deflate_quick.c:insert_skip deflate_slow.c:insert_skip Line | Count | Source | 286 | 14.1k | Z_FORCEINLINE static void insert_skip(deflate_state *const s, uint32_t str, uint32_t count) { | 287 | 14.1k | uint32_t idx = str & W_MASK(s); | 288 | | /* The range wraps around the end of prev at most once. */ | 289 | 14.1k | uint32_t first = MIN(count, s->w_size - idx); | 290 | | | 291 | 14.1k | memset(&s->prev[idx], 0, first * sizeof(Pos)); | 292 | 14.1k | memset(s->prev, 0, (count - first) * sizeof(Pos)); | 293 | 14.1k | } |
Unexecuted instantiation: insert_string.c:insert_skip Unexecuted instantiation: compare256_sse2.c:insert_skip Unexecuted instantiation: compare256_avx2.c:insert_skip Unexecuted instantiation: compare256_avx512.c:insert_skip |
294 | | |
295 | | /* =========================================================================== |
296 | | * Insert only the last tail strings of a batch and end the chains of the rest. |
297 | | * IN assertion: tail < count. |
298 | | */ |
299 | | Z_FORCEINLINE static void insert_knuth_batch_tail_static(deflate_state *const s, unsigned char *window, uint32_t str, |
300 | 5.79k | uint32_t count, uint32_t tail) { |
301 | 5.79k | uint32_t skip = count - tail; |
302 | | |
303 | 5.79k | insert_skip(s, str, skip); |
304 | 5.79k | insert_knuth_batch_static(s, window, str + skip, tail); |
305 | 5.79k | } Unexecuted instantiation: deflate.c:insert_knuth_batch_tail_static Unexecuted instantiation: deflate_fast.c:insert_knuth_batch_tail_static Unexecuted instantiation: deflate_medium.c:insert_knuth_batch_tail_static Unexecuted instantiation: deflate_quick.c:insert_knuth_batch_tail_static deflate_slow.c:insert_knuth_batch_tail_static Line | Count | Source | 300 | 5.79k | uint32_t count, uint32_t tail) { | 301 | 5.79k | uint32_t skip = count - tail; | 302 | | | 303 | 5.79k | insert_skip(s, str, skip); | 304 | 5.79k | insert_knuth_batch_static(s, window, str + skip, tail); | 305 | 5.79k | } |
Unexecuted instantiation: insert_string.c:insert_knuth_batch_tail_static Unexecuted instantiation: compare256_sse2.c:insert_knuth_batch_tail_static Unexecuted instantiation: compare256_avx2.c:insert_knuth_batch_tail_static Unexecuted instantiation: compare256_avx512.c:insert_knuth_batch_tail_static |
306 | | |
307 | | Z_FORCEINLINE static void insert_roll_batch_tail_static(deflate_state *const s, unsigned char *window, uint32_t str, |
308 | 8.37k | uint32_t count, uint32_t tail) { |
309 | 8.37k | uint32_t skip = count - tail; |
310 | | |
311 | 8.37k | insert_skip(s, str, skip); |
312 | 8.37k | str += skip; |
313 | | /* Seed the rolling hash with two bytes, the insert feeds the third. */ |
314 | 8.37k | s->ins_h = update_hash_roll(window[str], window[str + 1]); |
315 | 8.37k | insert_roll_batch_static(s, window, str, tail); |
316 | 8.37k | } Unexecuted instantiation: deflate.c:insert_roll_batch_tail_static Unexecuted instantiation: deflate_fast.c:insert_roll_batch_tail_static Unexecuted instantiation: deflate_medium.c:insert_roll_batch_tail_static Unexecuted instantiation: deflate_quick.c:insert_roll_batch_tail_static deflate_slow.c:insert_roll_batch_tail_static Line | Count | Source | 308 | 8.37k | uint32_t count, uint32_t tail) { | 309 | 8.37k | uint32_t skip = count - tail; | 310 | | | 311 | 8.37k | insert_skip(s, str, skip); | 312 | 8.37k | str += skip; | 313 | | /* Seed the rolling hash with two bytes, the insert feeds the third. */ | 314 | 8.37k | s->ins_h = update_hash_roll(window[str], window[str + 1]); | 315 | 8.37k | insert_roll_batch_static(s, window, str, tail); | 316 | 8.37k | } |
Unexecuted instantiation: insert_string.c:insert_roll_batch_tail_static Unexecuted instantiation: compare256_sse2.c:insert_roll_batch_tail_static Unexecuted instantiation: compare256_avx2.c:insert_roll_batch_tail_static Unexecuted instantiation: compare256_avx512.c:insert_roll_batch_tail_static |
317 | | |
318 | | #endif |