/src/rust-brotli/src/enc/compress_fragment_two_pass.rs
Line | Count | Source |
1 | | use core; |
2 | | use core::cmp::min; |
3 | | |
4 | | use super::super::alloc; |
5 | | use super::backward_references::kHashMul32; |
6 | | use super::bit_cost::BitsEntropy; |
7 | | use super::brotli_bit_stream::{BrotliBuildAndStoreHuffmanTreeFast, BrotliStoreHuffmanTree}; |
8 | | use super::entropy_encode::{ |
9 | | BrotliConvertBitDepthsToSymbols, BrotliCreateHuffmanTree, HuffmanTree, |
10 | | }; |
11 | | use super::static_dict::{ |
12 | | FindMatchLengthWithLimit, BROTLI_UNALIGNED_LOAD32, BROTLI_UNALIGNED_LOAD64, |
13 | | BROTLI_UNALIGNED_STORE64, |
14 | | }; |
15 | | use super::util::{floatX, Log2FloorNonZero}; |
16 | | static kCompressFragmentTwoPassBlockSize: usize = (1i32 << 17) as usize; |
17 | | |
18 | | // returns number of commands inserted |
19 | 211k | fn EmitInsertLen(insertlen: u32, commands: &mut &mut [u32]) -> usize { |
20 | 211k | if insertlen < 6u32 { |
21 | 165k | (*commands)[0] = insertlen; |
22 | 165k | } else if insertlen < 130u32 { |
23 | 42.9k | let tail: u32 = insertlen.wrapping_sub(2); |
24 | 42.9k | let nbits: u32 = Log2FloorNonZero(tail as (u64)).wrapping_sub(1); |
25 | 42.9k | let prefix: u32 = tail >> nbits; |
26 | 42.9k | let inscode: u32 = (nbits << 1).wrapping_add(prefix).wrapping_add(2); |
27 | 42.9k | let extra: u32 = tail.wrapping_sub(prefix << nbits); |
28 | 42.9k | (*commands)[0] = inscode | extra << 8; |
29 | 42.9k | } else if insertlen < 2114u32 { |
30 | 3.25k | let tail: u32 = insertlen.wrapping_sub(66); |
31 | 3.25k | let nbits: u32 = Log2FloorNonZero(tail as (u64)); |
32 | 3.25k | let code: u32 = nbits.wrapping_add(10); |
33 | 3.25k | let extra: u32 = tail.wrapping_sub(1u32 << nbits); |
34 | 3.25k | (*commands)[0] = code | extra << 8; |
35 | 3.25k | } else if insertlen < 6210u32 { |
36 | 134 | let extra: u32 = insertlen.wrapping_sub(2114); |
37 | 134 | (*commands)[0] = 21u32 | extra << 8; |
38 | 134 | } else if insertlen < 22594u32 { |
39 | 76 | let extra: u32 = insertlen.wrapping_sub(6210); |
40 | 76 | (*commands)[0] = 22u32 | extra << 8; |
41 | 76 | } else { |
42 | 25 | let extra: u32 = insertlen.wrapping_sub(22594); |
43 | 25 | (*commands)[0] = 23u32 | extra << 8; |
44 | 25 | } |
45 | 211k | let remainder = core::mem::take(commands); |
46 | 211k | let _ = core::mem::replace(commands, &mut remainder[1..]); |
47 | 211k | 1 |
48 | 211k | } |
49 | | |
50 | 313k | fn EmitDistance(distance: u32, commands: &mut &mut [u32]) -> usize { |
51 | 313k | let d: u32 = distance.wrapping_add(3); |
52 | 313k | let nbits: u32 = Log2FloorNonZero(d as (u64)).wrapping_sub(1); |
53 | 313k | let prefix: u32 = d >> nbits & 1u32; |
54 | 313k | let offset: u32 = (2u32).wrapping_add(prefix) << nbits; |
55 | 313k | let distcode: u32 = (2u32) |
56 | 313k | .wrapping_mul(nbits.wrapping_sub(1)) |
57 | 313k | .wrapping_add(prefix) |
58 | 313k | .wrapping_add(80); |
59 | 313k | let extra: u32 = d.wrapping_sub(offset); |
60 | 313k | (*commands)[0] = distcode | extra << 8; |
61 | 313k | let remainder = core::mem::take(commands); |
62 | 313k | let _ = core::mem::replace(commands, &mut remainder[1..]); |
63 | 313k | 1 |
64 | 313k | } |
65 | | |
66 | 207k | fn EmitCopyLenLastDistance(copylen: usize, commands: &mut &mut [u32]) -> usize { |
67 | 207k | if copylen < 12usize { |
68 | 169k | (*commands)[0] = copylen.wrapping_add(20) as u32; |
69 | 169k | let remainder = core::mem::take(commands); |
70 | 169k | let _ = core::mem::replace(commands, &mut remainder[1..]); |
71 | 169k | 1 |
72 | 37.8k | } else if copylen < 72usize { |
73 | 29.5k | let tail: usize = copylen.wrapping_sub(8); |
74 | 29.5k | let nbits: usize = Log2FloorNonZero(tail as u64).wrapping_sub(1) as usize; |
75 | 29.5k | let prefix: usize = tail >> nbits; |
76 | 29.5k | let code: usize = (nbits << 1).wrapping_add(prefix).wrapping_add(28); |
77 | 29.5k | let extra: usize = tail.wrapping_sub(prefix << nbits); |
78 | 29.5k | (*commands)[0] = (code | extra << 8) as u32; |
79 | 29.5k | let remainder = core::mem::take(commands); |
80 | 29.5k | let _ = core::mem::replace(commands, &mut remainder[1..]); |
81 | 29.5k | 1 |
82 | 8.31k | } else if copylen < 136usize { |
83 | 2.83k | let tail: usize = copylen.wrapping_sub(8); |
84 | 2.83k | let code: usize = (tail >> 5).wrapping_add(54); |
85 | 2.83k | let extra: usize = tail & 31usize; |
86 | 2.83k | (*commands)[0] = (code | extra << 8) as u32; |
87 | 2.83k | let remainder = core::mem::take(commands); |
88 | 2.83k | let _ = core::mem::replace(commands, &mut remainder[1..]); |
89 | 2.83k | (*commands)[0] = 64u32; |
90 | 2.83k | let remainder2 = core::mem::take(commands); |
91 | 2.83k | let _ = core::mem::replace(commands, &mut remainder2[1..]); |
92 | 2.83k | 2 |
93 | 5.47k | } else if copylen < 2120usize { |
94 | 5.10k | let tail: usize = copylen.wrapping_sub(72); |
95 | 5.10k | let nbits: usize = Log2FloorNonZero(tail as u64) as usize; |
96 | 5.10k | let code: usize = nbits.wrapping_add(52); |
97 | 5.10k | let extra: usize = tail.wrapping_sub(1usize << nbits); |
98 | 5.10k | (*commands)[0] = (code | extra << 8) as u32; |
99 | 5.10k | let remainder = core::mem::take(commands); |
100 | 5.10k | let _ = core::mem::replace(commands, &mut remainder[1..]); |
101 | 5.10k | (*commands)[0] = 64u32; |
102 | 5.10k | let remainder2 = core::mem::take(commands); |
103 | 5.10k | let _ = core::mem::replace(commands, &mut remainder2[1..]); |
104 | 5.10k | 2 |
105 | | } else { |
106 | 364 | let extra: usize = copylen.wrapping_sub(2120); |
107 | 364 | (*commands)[0] = (63usize | extra << 8) as u32; |
108 | 364 | let remainder = core::mem::take(commands); |
109 | 364 | let _ = core::mem::replace(commands, &mut remainder[1..]); |
110 | 364 | (*commands)[0] = 64u32; |
111 | 364 | let remainder2 = core::mem::take(commands); |
112 | 364 | let _ = core::mem::replace(commands, &mut remainder2[1..]); |
113 | 364 | 2 |
114 | | } |
115 | 207k | } |
116 | 1.70M | fn HashBytesAtOffset(v: u64, offset: i32, shift: usize, length: usize) -> u32 { |
117 | 1.70M | let h: u64 = (v >> (8i32 * offset) << ((8 - length) * 8)).wrapping_mul(kHashMul32 as (u64)); |
118 | 1.70M | (h >> shift) as u32 |
119 | 1.70M | } |
120 | | |
121 | 189k | fn EmitCopyLen(copylen: usize, commands: &mut &mut [u32]) -> usize { |
122 | 189k | if copylen < 10usize { |
123 | 135k | (*commands)[0] = copylen.wrapping_add(38) as u32; |
124 | 135k | } else if copylen < 134usize { |
125 | 46.1k | let tail: usize = copylen.wrapping_sub(6); |
126 | 46.1k | let nbits: usize = Log2FloorNonZero(tail as u64).wrapping_sub(1) as usize; |
127 | 46.1k | let prefix: usize = tail >> nbits; |
128 | 46.1k | let code: usize = (nbits << 1).wrapping_add(prefix).wrapping_add(44); |
129 | 46.1k | let extra: usize = tail.wrapping_sub(prefix << nbits); |
130 | 46.1k | (*commands)[0] = (code | extra << 8) as u32; |
131 | 46.1k | } else if copylen < 2118usize { |
132 | 6.89k | let tail: usize = copylen.wrapping_sub(70); |
133 | 6.89k | let nbits: usize = Log2FloorNonZero(tail as u64) as usize; |
134 | 6.89k | let code: usize = nbits.wrapping_add(52); |
135 | 6.89k | let extra: usize = tail.wrapping_sub(1usize << nbits); |
136 | 6.89k | (*commands)[0] = (code | extra << 8) as u32; |
137 | 6.89k | } else { |
138 | 573 | let extra: usize = copylen.wrapping_sub(2118); |
139 | 573 | (*commands)[0] = (63usize | extra << 8) as u32; |
140 | 573 | } |
141 | 189k | let remainder = core::mem::take(commands); |
142 | 189k | let _ = core::mem::replace(commands, &mut remainder[1..]); |
143 | 189k | 1 |
144 | 189k | } |
145 | 1.84M | fn Hash(p: &[u8], shift: usize, length: usize) -> u32 { |
146 | 1.84M | let h: u64 = |
147 | 1.84M | (BROTLI_UNALIGNED_LOAD64(p) << ((8 - length) * 8)).wrapping_mul(kHashMul32 as (u64)); |
148 | 1.84M | (h >> shift) as u32 |
149 | 1.84M | } |
150 | | |
151 | 3.57M | fn IsMatch(p1: &[u8], p2: &[u8], length: usize) -> bool { |
152 | 3.57M | BROTLI_UNALIGNED_LOAD32(p1) == BROTLI_UNALIGNED_LOAD32(p2) |
153 | 407k | && (length == 4 || (p1[4] == p2[4] && p1[5] == p2[5])) |
154 | 3.57M | } |
155 | | |
156 | | #[allow(unused_assignments)] |
157 | 7.91k | fn CreateCommands( |
158 | 7.91k | input_index: usize, |
159 | 7.91k | block_size: usize, |
160 | 7.91k | input_size: usize, |
161 | 7.91k | base_ip: &[u8], |
162 | 7.91k | table: &mut [i32], |
163 | 7.91k | table_bits: usize, |
164 | 7.91k | min_match: usize, |
165 | 7.91k | literals: &mut &mut [u8], |
166 | 7.91k | num_literals: &mut usize, |
167 | 7.91k | commands: &mut &mut [u32], |
168 | 7.91k | num_commands: &mut usize, |
169 | 7.91k | ) { |
170 | 7.91k | let mut ip_index: usize = input_index; |
171 | 7.91k | let shift: usize = (64u32 as usize).wrapping_sub(table_bits); |
172 | 7.91k | let ip_end: usize = input_index.wrapping_add(block_size); |
173 | 7.91k | let mut next_emit: usize = input_index; |
174 | 7.91k | let mut last_distance: i32 = -1i32; |
175 | 7.91k | let kInputMarginBytes: usize = 16usize; |
176 | | |
177 | 7.91k | if block_size >= kInputMarginBytes { |
178 | 7.88k | let len_limit: usize = min( |
179 | 7.88k | block_size.wrapping_sub(min_match), |
180 | 7.88k | input_size.wrapping_sub(kInputMarginBytes), |
181 | | ); |
182 | 7.88k | let ip_limit: usize = input_index.wrapping_add(len_limit); |
183 | | let mut next_hash: u32; |
184 | 7.88k | let mut goto_emit_remainder = false; |
185 | 7.88k | next_hash = Hash( |
186 | 7.88k | &base_ip[{ |
187 | 7.88k | ip_index = ip_index.wrapping_add(1); |
188 | 7.88k | ip_index |
189 | 7.88k | }..], |
190 | 7.88k | shift, |
191 | 7.88k | min_match, |
192 | 7.88k | ); |
193 | 212k | while !goto_emit_remainder { |
194 | 209k | let mut skip: u32 = 32u32; |
195 | 209k | let mut next_ip: usize = ip_index; |
196 | 209k | let mut candidate: usize = 0; |
197 | | loop { |
198 | | { |
199 | | 'break3: loop { |
200 | | { |
201 | 1.64M | let hash: u32 = next_hash; |
202 | 1.64M | let bytes_between_hash_lookups: u32 = skip >> 5; |
203 | 1.64M | skip = skip.wrapping_add(1); |
204 | 1.64M | ip_index = next_ip; |
205 | 1.64M | next_ip = ip_index.wrapping_add(bytes_between_hash_lookups as usize); |
206 | 1.64M | if next_ip > ip_limit { |
207 | 2.35k | goto_emit_remainder = true; |
208 | | { |
209 | 2.35k | break 'break3; |
210 | | } |
211 | 1.63M | } |
212 | 1.63M | next_hash = Hash(&base_ip[next_ip..], shift, min_match); |
213 | 1.63M | candidate = ip_index.wrapping_sub(last_distance as usize); |
214 | 1.63M | if IsMatch(&base_ip[ip_index..], &base_ip[candidate..], min_match) |
215 | 88.4k | && candidate < ip_index |
216 | | { |
217 | 82.8k | table[(hash as usize)] = ip_index.wrapping_sub(0) as i32; |
218 | | { |
219 | 82.8k | break 'break3; |
220 | | } |
221 | 1.55M | } |
222 | 1.55M | candidate = table[(hash as usize)] as usize; |
223 | 1.55M | table[(hash as usize)] = ip_index.wrapping_sub(0) as i32; |
224 | | } |
225 | 1.55M | if IsMatch(&base_ip[ip_index..], &base_ip[candidate..], min_match) { |
226 | 127k | break; |
227 | 1.42M | } |
228 | | } |
229 | | } |
230 | 212k | if !(ip_index.wrapping_sub(candidate) |
231 | 212k | > (1usize << 18).wrapping_sub(16) as isize as usize |
232 | 2.85k | && !goto_emit_remainder) |
233 | | { |
234 | 209k | break; |
235 | 2.85k | } |
236 | | } |
237 | 209k | if goto_emit_remainder { |
238 | 2.35k | break; |
239 | 207k | } |
240 | | { |
241 | 207k | let base: usize = ip_index; |
242 | 207k | let matched: usize = min_match.wrapping_add(FindMatchLengthWithLimit( |
243 | 207k | &base_ip[(candidate + min_match)..], |
244 | 207k | &base_ip[(ip_index + min_match)..], |
245 | 207k | ip_end.wrapping_sub(ip_index).wrapping_sub(min_match), |
246 | | )); |
247 | 207k | let distance: i32 = base.wrapping_sub(candidate) as i32; |
248 | 207k | let insert: i32 = base.wrapping_sub(next_emit) as i32; |
249 | 207k | ip_index = ip_index.wrapping_add(matched); |
250 | 207k | *num_commands += EmitInsertLen(insert as u32, commands); |
251 | 207k | (*literals)[..(insert as usize)] |
252 | 207k | .clone_from_slice(&base_ip[next_emit..(next_emit + insert as usize)]); |
253 | 207k | *num_literals += insert as usize; |
254 | 207k | let new_literals = core::mem::take(literals); |
255 | 207k | let _ = core::mem::replace(literals, &mut new_literals[(insert as usize)..]); |
256 | 207k | if distance == last_distance { |
257 | 82.8k | (*commands)[0] = 64u32; |
258 | 82.8k | let remainder = core::mem::take(commands); |
259 | 82.8k | let _ = core::mem::replace(commands, &mut remainder[1..]); |
260 | 82.8k | *num_commands += 1; |
261 | 124k | } else { |
262 | 124k | *num_commands += EmitDistance(distance as u32, commands); |
263 | 124k | last_distance = distance; |
264 | 124k | } |
265 | 207k | *num_commands += EmitCopyLenLastDistance(matched, commands); |
266 | 207k | next_emit = ip_index; |
267 | 207k | if ip_index >= ip_limit { |
268 | 2.64k | goto_emit_remainder = true; |
269 | | { |
270 | 2.64k | break; |
271 | | } |
272 | 204k | } |
273 | | { |
274 | | let mut input_bytes: u64; |
275 | | let mut prev_hash: u32; |
276 | | let cur_hash: u32; |
277 | 204k | if min_match == 4 { |
278 | 168k | input_bytes = BROTLI_UNALIGNED_LOAD64(&base_ip[(ip_index - 3)..]); |
279 | 168k | cur_hash = HashBytesAtOffset(input_bytes, 3i32, shift, min_match); |
280 | 168k | prev_hash = HashBytesAtOffset(input_bytes, 0i32, shift, min_match); |
281 | 168k | table[(prev_hash as usize)] = ip_index.wrapping_sub(3) as i32; |
282 | 168k | prev_hash = HashBytesAtOffset(input_bytes, 1i32, shift, min_match); |
283 | 168k | table[(prev_hash as usize)] = ip_index.wrapping_sub(2) as i32; |
284 | 168k | prev_hash = HashBytesAtOffset(input_bytes, 0i32, shift, min_match); |
285 | 168k | table[(prev_hash as usize)] = ip_index.wrapping_sub(1) as i32; |
286 | 168k | } else { |
287 | 36.5k | assert!(ip_index >= 5); |
288 | | // could this be off the end FIXME |
289 | 36.5k | input_bytes = BROTLI_UNALIGNED_LOAD64(&base_ip[(ip_index - 5)..]); |
290 | 36.5k | prev_hash = HashBytesAtOffset(input_bytes, 0i32, shift, min_match); |
291 | 36.5k | table[(prev_hash as usize)] = ip_index.wrapping_sub(5) as i32; |
292 | 36.5k | prev_hash = HashBytesAtOffset(input_bytes, 1i32, shift, min_match); |
293 | 36.5k | table[(prev_hash as usize)] = ip_index.wrapping_sub(4) as i32; |
294 | 36.5k | prev_hash = HashBytesAtOffset(input_bytes, 2i32, shift, min_match); |
295 | 36.5k | table[(prev_hash as usize)] = ip_index.wrapping_sub(3) as i32; |
296 | 36.5k | assert!(ip_index >= 2); |
297 | 36.5k | input_bytes = BROTLI_UNALIGNED_LOAD64(&base_ip[(ip_index - 2)..]); |
298 | 36.5k | cur_hash = HashBytesAtOffset(input_bytes, 2i32, shift, min_match); |
299 | 36.5k | prev_hash = HashBytesAtOffset(input_bytes, 0i32, shift, min_match); |
300 | 36.5k | table[(prev_hash as usize)] = ip_index.wrapping_sub(2) as i32; |
301 | 36.5k | prev_hash = HashBytesAtOffset(input_bytes, 1i32, shift, min_match); |
302 | 36.5k | table[(prev_hash as usize)] = ip_index.wrapping_sub(1) as i32; |
303 | | } |
304 | 204k | candidate = table[(cur_hash as usize)] as usize; |
305 | 204k | table[(cur_hash as usize)] = ip_index as i32; |
306 | | } |
307 | | } |
308 | 390k | while ip_index.wrapping_sub(candidate) |
309 | 390k | <= (1usize << 18).wrapping_sub(16) as isize as usize |
310 | 385k | && IsMatch(&base_ip[ip_index..], &base_ip[candidate..], min_match) |
311 | | { |
312 | 189k | let base_index: usize = ip_index; |
313 | 189k | let matched: usize = min_match.wrapping_add(FindMatchLengthWithLimit( |
314 | 189k | &base_ip[(candidate + min_match)..], |
315 | 189k | &base_ip[(ip_index + min_match)..], |
316 | 189k | ip_end.wrapping_sub(ip_index).wrapping_sub(min_match), |
317 | | )); |
318 | 189k | ip_index = ip_index.wrapping_add(matched); |
319 | 189k | last_distance = base_index.wrapping_sub(candidate) as i32; |
320 | 189k | *num_commands += EmitCopyLen(matched, commands); |
321 | 189k | *num_commands += EmitDistance(last_distance as u32, commands); |
322 | 189k | next_emit = ip_index; |
323 | 189k | if ip_index >= ip_limit { |
324 | 2.88k | goto_emit_remainder = true; |
325 | | { |
326 | 2.88k | break; |
327 | | } |
328 | 186k | } |
329 | | { |
330 | 186k | assert!(ip_index >= 5); |
331 | | let mut input_bytes: u64; |
332 | | |
333 | | let cur_hash: u32; |
334 | | let mut prev_hash: u32; |
335 | 186k | if min_match == 4 { |
336 | 151k | input_bytes = BROTLI_UNALIGNED_LOAD64(&base_ip[(ip_index - 3)..]); |
337 | 151k | cur_hash = HashBytesAtOffset(input_bytes, 3i32, shift, min_match); |
338 | 151k | prev_hash = HashBytesAtOffset(input_bytes, 0i32, shift, min_match); |
339 | 151k | table[(prev_hash as usize)] = ip_index.wrapping_sub(3) as i32; |
340 | 151k | prev_hash = HashBytesAtOffset(input_bytes, 1i32, shift, min_match); |
341 | 151k | table[(prev_hash as usize)] = ip_index.wrapping_sub(2) as i32; |
342 | 151k | prev_hash = HashBytesAtOffset(input_bytes, 2i32, shift, min_match); |
343 | 151k | table[(prev_hash as usize)] = ip_index.wrapping_sub(1) as i32; |
344 | 151k | } else { |
345 | 34.3k | input_bytes = BROTLI_UNALIGNED_LOAD64(&base_ip[(ip_index - 5)..]); |
346 | 34.3k | prev_hash = HashBytesAtOffset(input_bytes, 0i32, shift, min_match); |
347 | 34.3k | table[(prev_hash as usize)] = ip_index.wrapping_sub(5) as i32; |
348 | 34.3k | prev_hash = HashBytesAtOffset(input_bytes, 1i32, shift, min_match); |
349 | 34.3k | table[(prev_hash as usize)] = ip_index.wrapping_sub(4) as i32; |
350 | 34.3k | prev_hash = HashBytesAtOffset(input_bytes, 2i32, shift, min_match); |
351 | 34.3k | table[(prev_hash as usize)] = ip_index.wrapping_sub(3) as i32; |
352 | 34.3k | assert!(ip_index >= 2); |
353 | 34.3k | input_bytes = BROTLI_UNALIGNED_LOAD64(&base_ip[(ip_index - 2)..]); |
354 | 34.3k | cur_hash = HashBytesAtOffset(input_bytes, 2i32, shift, min_match); |
355 | 34.3k | prev_hash = HashBytesAtOffset(input_bytes, 0i32, shift, min_match); |
356 | 34.3k | table[(prev_hash as usize)] = ip_index.wrapping_sub(2) as i32; |
357 | 34.3k | prev_hash = HashBytesAtOffset(input_bytes, 1i32, shift, min_match); |
358 | 34.3k | table[(prev_hash as usize)] = ip_index.wrapping_sub(1) as i32; |
359 | | } |
360 | 186k | candidate = table[(cur_hash as usize)] as usize; |
361 | 186k | table[(cur_hash as usize)] = ip_index as i32; |
362 | | } |
363 | | } |
364 | 204k | if !goto_emit_remainder { |
365 | 201k | next_hash = Hash( |
366 | 201k | &base_ip[{ |
367 | 201k | ip_index = ip_index.wrapping_add(1); |
368 | 201k | ip_index |
369 | 201k | }..], |
370 | 201k | shift, |
371 | 201k | min_match, |
372 | 201k | ); |
373 | 201k | } |
374 | | } |
375 | 28 | } |
376 | 7.91k | if next_emit < ip_end { |
377 | 4.42k | let insert: u32 = ip_end.wrapping_sub(next_emit) as u32; |
378 | 4.42k | *num_commands += EmitInsertLen(insert, commands); |
379 | 4.42k | literals[..insert as usize] |
380 | 4.42k | .clone_from_slice(&base_ip[next_emit..(next_emit + insert as usize)]); |
381 | 4.42k | let mut xliterals = core::mem::take(literals); |
382 | 4.42k | *literals = &mut core::mem::take(&mut xliterals)[(insert as usize)..]; |
383 | 4.42k | *num_literals += insert as usize; |
384 | 4.42k | } |
385 | 7.91k | } |
386 | | |
387 | 7.91k | fn ShouldCompress(input: &[u8], input_size: usize, num_literals: usize) -> bool { |
388 | 7.91k | let corpus_size = input_size as floatX; |
389 | 7.91k | if (num_literals as floatX) < 0.98 * corpus_size { |
390 | 6.64k | true |
391 | | } else { |
392 | 1.26k | let mut literal_histo: [u32; 256] = [0; 256]; |
393 | 1.26k | let max_total_bit_cost: floatX = corpus_size * 8.0 * 0.98 / 43.0; |
394 | | let mut i: usize; |
395 | 1.26k | i = 0usize; |
396 | 35.7k | while i < input_size { |
397 | 34.4k | { |
398 | 34.4k | let _rhs = 1; |
399 | 34.4k | let _lhs = &mut literal_histo[input[i] as usize]; |
400 | 34.4k | *_lhs = (*_lhs).wrapping_add(_rhs as u32); |
401 | 34.4k | } |
402 | 34.4k | i = i.wrapping_add(43); |
403 | 34.4k | } |
404 | 1.26k | BitsEntropy(&mut literal_histo[..], 256) < max_total_bit_cost |
405 | | } |
406 | 7.91k | } |
407 | | |
408 | 30.1M | pub fn BrotliWriteBits(n_bits: usize, bits: u64, pos: &mut usize, array: &mut [u8]) { |
409 | 30.1M | let p = &mut array[(*pos >> 3)..]; |
410 | 30.1M | let mut v: u64 = p[0] as (u64); |
411 | 30.1M | v |= bits << (*pos & 7); |
412 | 30.1M | BROTLI_UNALIGNED_STORE64(p, v); |
413 | 30.1M | *pos = pos.wrapping_add(n_bits); |
414 | 30.1M | } |
415 | | |
416 | 38.4k | pub(crate) fn store_meta_block_header( |
417 | 38.4k | len: usize, |
418 | 38.4k | is_uncompressed: bool, |
419 | 38.4k | storage_ix: &mut usize, |
420 | 38.4k | storage: &mut [u8], |
421 | 38.4k | ) { |
422 | 38.4k | let mut nibbles: u64 = 6; |
423 | 38.4k | BrotliWriteBits(1, 0, storage_ix, storage); |
424 | 38.4k | if len <= (1u32 << 16) as usize { |
425 | 38.1k | nibbles = 4; |
426 | 38.1k | } else if len <= (1u32 << 20) as usize { |
427 | 280 | nibbles = 5; |
428 | 280 | } |
429 | 38.4k | BrotliWriteBits(2, nibbles.wrapping_sub(4), storage_ix, storage); |
430 | 38.4k | BrotliWriteBits( |
431 | 38.4k | nibbles.wrapping_mul(4) as usize, |
432 | 38.4k | len.wrapping_sub(1) as u64, |
433 | 38.4k | storage_ix, |
434 | 38.4k | storage, |
435 | | ); |
436 | 38.4k | BrotliWriteBits(1, u64::from(is_uncompressed), storage_ix, storage); |
437 | 38.4k | } |
438 | | |
439 | 563k | pub fn memcpy<T: Sized + Clone>( |
440 | 563k | dst: &mut [T], |
441 | 563k | dst_offset: usize, |
442 | 563k | src: &[T], |
443 | 563k | src_offset: usize, |
444 | 563k | size_to_copy: usize, |
445 | 563k | ) { |
446 | 563k | dst[dst_offset..(dst_offset + size_to_copy)] |
447 | 563k | .clone_from_slice(&src[src_offset..(src_offset + size_to_copy)]); |
448 | 563k | } brotli::enc::compress_fragment_two_pass::memcpy::<u8> Line | Count | Source | 439 | 366k | pub fn memcpy<T: Sized + Clone>( | 440 | 366k | dst: &mut [T], | 441 | 366k | dst_offset: usize, | 442 | 366k | src: &[T], | 443 | 366k | src_offset: usize, | 444 | 366k | size_to_copy: usize, | 445 | 366k | ) { | 446 | 366k | dst[dst_offset..(dst_offset + size_to_copy)] | 447 | 366k | .clone_from_slice(&src[src_offset..(src_offset + size_to_copy)]); | 448 | 366k | } |
brotli::enc::compress_fragment_two_pass::memcpy::<u16> Line | Count | Source | 439 | 196k | pub fn memcpy<T: Sized + Clone>( | 440 | 196k | dst: &mut [T], | 441 | 196k | dst_offset: usize, | 442 | 196k | src: &[T], | 443 | 196k | src_offset: usize, | 444 | 196k | size_to_copy: usize, | 445 | 196k | ) { | 446 | 196k | dst[dst_offset..(dst_offset + size_to_copy)] | 447 | 196k | .clone_from_slice(&src[src_offset..(src_offset + size_to_copy)]); | 448 | 196k | } |
|
449 | 7.90k | fn BuildAndStoreCommandPrefixCode( |
450 | 7.90k | histogram: &[u32], |
451 | 7.90k | depth: &mut [u8], |
452 | 7.90k | bits: &mut [u16], |
453 | 7.90k | storage_ix: &mut usize, |
454 | 7.90k | storage: &mut [u8], |
455 | 7.90k | ) { |
456 | 7.90k | let mut tree = [HuffmanTree::new(0, 0, 0); 129]; |
457 | 7.90k | let mut cmd_depth: [u8; 704] = [0; 704]; |
458 | 7.90k | let mut cmd_bits: [u16; 64] = [0; 64]; |
459 | 7.90k | BrotliCreateHuffmanTree(histogram, 64usize, 15i32, &mut tree[..], depth); |
460 | 7.90k | BrotliCreateHuffmanTree( |
461 | 7.90k | &histogram[64..], |
462 | | 64usize, |
463 | | 14i32, |
464 | 7.90k | &mut tree[..], |
465 | 7.90k | &mut depth[64..], |
466 | | ); |
467 | | /* We have to jump through a few hoops here in order to compute |
468 | | the command bits because the symbols are in a different order than in |
469 | | the full alphabet. This looks complicated, but having the symbols |
470 | | in this order in the command bits saves a few branches in the Emit* |
471 | | functions. */ |
472 | 7.90k | memcpy(&mut cmd_depth[..], 0, depth, 24, 24); |
473 | 7.90k | memcpy(&mut cmd_depth[..], 24, depth, 0, 8); |
474 | 7.90k | memcpy(&mut cmd_depth[..], 32usize, depth, (48usize), 8usize); |
475 | 7.90k | memcpy(&mut cmd_depth[..], 40usize, depth, (8usize), 8usize); |
476 | 7.90k | memcpy(&mut cmd_depth[..], 48usize, depth, (56usize), 8usize); |
477 | 7.90k | memcpy(&mut cmd_depth[..], 56usize, depth, (16usize), 8usize); |
478 | 7.90k | BrotliConvertBitDepthsToSymbols(&mut cmd_depth[..], 64usize, &mut cmd_bits[..]); |
479 | 7.90k | memcpy(bits, 0, &cmd_bits[..], 24usize, 16usize); |
480 | 7.90k | memcpy(bits, (8usize), &cmd_bits[..], 40usize, 8usize); |
481 | 7.90k | memcpy(bits, (16usize), &cmd_bits[..], 56usize, 8usize); |
482 | 7.90k | memcpy(bits, (24usize), &cmd_bits[..], 0, 48usize); |
483 | 7.90k | memcpy(bits, (48usize), &cmd_bits[..], 32usize, 8usize); |
484 | 7.90k | memcpy(bits, (56usize), &cmd_bits[..], 48usize, 8usize); |
485 | 7.90k | BrotliConvertBitDepthsToSymbols(&mut depth[64..], 64usize, &mut bits[64..]); |
486 | | { |
487 | 505k | for item in cmd_depth[..64].iter_mut() { |
488 | 505k | *item = 0; |
489 | 505k | } |
490 | | //memset(&mut cmd_depth[..], 0i32, 64usize); |
491 | 7.90k | memcpy(&mut cmd_depth[..], 0, depth, (24usize), 8usize); |
492 | 7.90k | memcpy(&mut cmd_depth[..], 64usize, depth, (32usize), 8usize); |
493 | 7.90k | memcpy(&mut cmd_depth[..], 128usize, depth, (40usize), 8usize); |
494 | 7.90k | memcpy(&mut cmd_depth[..], 192usize, depth, (48usize), 8usize); |
495 | 7.90k | memcpy(&mut cmd_depth[..], 384usize, depth, (56usize), 8usize); |
496 | 71.1k | for i in 0usize..8usize { |
497 | 63.2k | cmd_depth[(128usize).wrapping_add((8usize).wrapping_mul(i))] = depth[i]; |
498 | 63.2k | cmd_depth[(256usize).wrapping_add((8usize).wrapping_mul(i))] = depth[i.wrapping_add(8)]; |
499 | 63.2k | cmd_depth[(448usize).wrapping_add((8usize).wrapping_mul(i))] = |
500 | 63.2k | depth[i.wrapping_add(16)]; |
501 | 63.2k | } |
502 | 7.90k | BrotliStoreHuffmanTree( |
503 | 7.90k | &mut cmd_depth[..], |
504 | | 704usize, |
505 | 7.90k | &mut tree[..], |
506 | 7.90k | storage_ix, |
507 | 7.90k | storage, |
508 | | ); |
509 | | } |
510 | 7.90k | BrotliStoreHuffmanTree( |
511 | 7.90k | &mut depth[64..], |
512 | | 64usize, |
513 | 7.90k | &mut tree[..], |
514 | 7.90k | storage_ix, |
515 | 7.90k | storage, |
516 | | ); |
517 | 7.90k | } |
518 | | |
519 | 7.90k | fn StoreCommands<AllocHT: alloc::Allocator<HuffmanTree>>( |
520 | 7.90k | mht: &mut AllocHT, |
521 | 7.90k | mut literals: &[u8], |
522 | 7.90k | num_literals: usize, |
523 | 7.90k | commands: &[u32], |
524 | 7.90k | num_commands: usize, |
525 | 7.90k | storage_ix: &mut usize, |
526 | 7.90k | storage: &mut [u8], |
527 | 7.90k | ) { |
528 | | static kNumExtraBits: [u32; 128] = [ |
529 | | 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 7, 8, 9, 10, 12, 14, 24, 0, 0, 0, 0, 0, |
530 | | 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, |
531 | | 7, 8, 9, 10, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, |
532 | | 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, |
533 | | 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, |
534 | | ]; |
535 | | static kInsertOffset: [u32; 24] = [ |
536 | | 0, 1, 2, 3, 4, 5, 6, 8, 10, 14, 18, 26, 34, 50, 66, 98, 130, 194, 322, 578, 1090, 2114, |
537 | | 6210, 22594, |
538 | | ]; |
539 | 7.90k | let mut lit_depths: [u8; 256] = [0; 256]; |
540 | 7.90k | let mut lit_bits: [u16; 256] = [0; 256]; // maybe return this instead |
541 | 7.90k | let mut lit_histo: [u32; 256] = [0; 256]; // maybe return this instead of init |
542 | 7.90k | let mut cmd_depths: [u8; 128] = [0; 128]; |
543 | 7.90k | let mut cmd_bits: [u16; 128] = [0; 128]; |
544 | 7.90k | let mut cmd_histo: [u32; 128] = [0; 128]; |
545 | | let mut i: usize; |
546 | 5.32M | for i in 0usize..num_literals { |
547 | 5.32M | let _rhs = 1; |
548 | 5.32M | let _lhs = &mut lit_histo[literals[i] as usize]; |
549 | 5.32M | *_lhs = (*_lhs).wrapping_add(_rhs as u32); |
550 | 5.32M | } |
551 | 7.90k | BrotliBuildAndStoreHuffmanTreeFast( |
552 | 7.90k | mht, |
553 | 7.90k | &lit_histo[..], |
554 | 7.90k | num_literals, |
555 | | 8usize, |
556 | 7.90k | &mut lit_depths[..], |
557 | 7.90k | &mut lit_bits[..], |
558 | 7.90k | storage_ix, |
559 | 7.90k | storage, |
560 | | ); |
561 | 7.90k | i = 0usize; |
562 | 1.02M | while i < num_commands { |
563 | 1.01M | { |
564 | 1.01M | let code: u32 = commands[i] & 0xffu32; |
565 | 1.01M | { |
566 | 1.01M | let _rhs = 1; |
567 | 1.01M | let _lhs = &mut cmd_histo[code as usize]; |
568 | 1.01M | *_lhs = (*_lhs).wrapping_add(_rhs as u32); |
569 | 1.01M | } |
570 | 1.01M | } |
571 | 1.01M | i = i.wrapping_add(1); |
572 | 1.01M | } |
573 | 7.90k | { |
574 | 7.90k | let _rhs = 1i32; |
575 | 7.90k | let _lhs = &mut cmd_histo[1]; |
576 | 7.90k | *_lhs = (*_lhs).wrapping_add(_rhs as u32); |
577 | 7.90k | } |
578 | 7.90k | { |
579 | 7.90k | let _rhs = 1i32; |
580 | 7.90k | let _lhs = &mut cmd_histo[2]; |
581 | 7.90k | *_lhs = (*_lhs).wrapping_add(_rhs as u32); |
582 | 7.90k | } |
583 | 7.90k | { |
584 | 7.90k | let _rhs = 1i32; |
585 | 7.90k | let _lhs = &mut cmd_histo[64]; |
586 | 7.90k | *_lhs = (*_lhs).wrapping_add(_rhs as u32); |
587 | 7.90k | } |
588 | 7.90k | { |
589 | 7.90k | let _rhs = 1i32; |
590 | 7.90k | let _lhs = &mut cmd_histo[84]; |
591 | 7.90k | *_lhs = (*_lhs).wrapping_add(_rhs as u32); |
592 | 7.90k | } |
593 | 7.90k | BuildAndStoreCommandPrefixCode( |
594 | 7.90k | &mut cmd_histo[..], |
595 | 7.90k | &mut cmd_depths[..], |
596 | 7.90k | &mut cmd_bits[..], |
597 | 7.90k | storage_ix, |
598 | 7.90k | storage, |
599 | | ); |
600 | 1.01M | for i in 0usize..num_commands { |
601 | 1.01M | let cmd: u32 = commands[i]; |
602 | 1.01M | let code: u32 = cmd & 0xffu32; |
603 | 1.01M | let extra: u32 = cmd >> 8; |
604 | 1.01M | BrotliWriteBits( |
605 | 1.01M | cmd_depths[code as usize] as usize, |
606 | 1.01M | cmd_bits[code as usize] as (u64), |
607 | 1.01M | storage_ix, |
608 | 1.01M | storage, |
609 | | ); |
610 | 1.01M | BrotliWriteBits( |
611 | 1.01M | kNumExtraBits[code as usize] as usize, |
612 | 1.01M | extra as (u64), |
613 | 1.01M | storage_ix, |
614 | 1.01M | storage, |
615 | | ); |
616 | 1.01M | if code < 24u32 { |
617 | 211k | let insert: u32 = kInsertOffset[code as usize].wrapping_add(extra); |
618 | 5.32M | for literal in literals[..(insert as usize)].iter() { |
619 | 5.32M | let lit: u8 = *literal; |
620 | 5.32M | BrotliWriteBits( |
621 | 5.32M | lit_depths[lit as usize] as usize, |
622 | 5.32M | lit_bits[lit as usize] as (u64), |
623 | 5.32M | storage_ix, |
624 | 5.32M | storage, |
625 | 5.32M | ); |
626 | 5.32M | } |
627 | 211k | literals = &literals[insert as usize..]; |
628 | 801k | } |
629 | | } |
630 | 7.90k | } brotli::enc::compress_fragment_two_pass::StoreCommands::<alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 519 | 7.90k | fn StoreCommands<AllocHT: alloc::Allocator<HuffmanTree>>( | 520 | 7.90k | mht: &mut AllocHT, | 521 | 7.90k | mut literals: &[u8], | 522 | 7.90k | num_literals: usize, | 523 | 7.90k | commands: &[u32], | 524 | 7.90k | num_commands: usize, | 525 | 7.90k | storage_ix: &mut usize, | 526 | 7.90k | storage: &mut [u8], | 527 | 7.90k | ) { | 528 | | static kNumExtraBits: [u32; 128] = [ | 529 | | 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 7, 8, 9, 10, 12, 14, 24, 0, 0, 0, 0, 0, | 530 | | 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, | 531 | | 7, 8, 9, 10, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, | 532 | | 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, | 533 | | 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, | 534 | | ]; | 535 | | static kInsertOffset: [u32; 24] = [ | 536 | | 0, 1, 2, 3, 4, 5, 6, 8, 10, 14, 18, 26, 34, 50, 66, 98, 130, 194, 322, 578, 1090, 2114, | 537 | | 6210, 22594, | 538 | | ]; | 539 | 7.90k | let mut lit_depths: [u8; 256] = [0; 256]; | 540 | 7.90k | let mut lit_bits: [u16; 256] = [0; 256]; // maybe return this instead | 541 | 7.90k | let mut lit_histo: [u32; 256] = [0; 256]; // maybe return this instead of init | 542 | 7.90k | let mut cmd_depths: [u8; 128] = [0; 128]; | 543 | 7.90k | let mut cmd_bits: [u16; 128] = [0; 128]; | 544 | 7.90k | let mut cmd_histo: [u32; 128] = [0; 128]; | 545 | | let mut i: usize; | 546 | 5.32M | for i in 0usize..num_literals { | 547 | 5.32M | let _rhs = 1; | 548 | 5.32M | let _lhs = &mut lit_histo[literals[i] as usize]; | 549 | 5.32M | *_lhs = (*_lhs).wrapping_add(_rhs as u32); | 550 | 5.32M | } | 551 | 7.90k | BrotliBuildAndStoreHuffmanTreeFast( | 552 | 7.90k | mht, | 553 | 7.90k | &lit_histo[..], | 554 | 7.90k | num_literals, | 555 | | 8usize, | 556 | 7.90k | &mut lit_depths[..], | 557 | 7.90k | &mut lit_bits[..], | 558 | 7.90k | storage_ix, | 559 | 7.90k | storage, | 560 | | ); | 561 | 7.90k | i = 0usize; | 562 | 1.02M | while i < num_commands { | 563 | 1.01M | { | 564 | 1.01M | let code: u32 = commands[i] & 0xffu32; | 565 | 1.01M | { | 566 | 1.01M | let _rhs = 1; | 567 | 1.01M | let _lhs = &mut cmd_histo[code as usize]; | 568 | 1.01M | *_lhs = (*_lhs).wrapping_add(_rhs as u32); | 569 | 1.01M | } | 570 | 1.01M | } | 571 | 1.01M | i = i.wrapping_add(1); | 572 | 1.01M | } | 573 | 7.90k | { | 574 | 7.90k | let _rhs = 1i32; | 575 | 7.90k | let _lhs = &mut cmd_histo[1]; | 576 | 7.90k | *_lhs = (*_lhs).wrapping_add(_rhs as u32); | 577 | 7.90k | } | 578 | 7.90k | { | 579 | 7.90k | let _rhs = 1i32; | 580 | 7.90k | let _lhs = &mut cmd_histo[2]; | 581 | 7.90k | *_lhs = (*_lhs).wrapping_add(_rhs as u32); | 582 | 7.90k | } | 583 | 7.90k | { | 584 | 7.90k | let _rhs = 1i32; | 585 | 7.90k | let _lhs = &mut cmd_histo[64]; | 586 | 7.90k | *_lhs = (*_lhs).wrapping_add(_rhs as u32); | 587 | 7.90k | } | 588 | 7.90k | { | 589 | 7.90k | let _rhs = 1i32; | 590 | 7.90k | let _lhs = &mut cmd_histo[84]; | 591 | 7.90k | *_lhs = (*_lhs).wrapping_add(_rhs as u32); | 592 | 7.90k | } | 593 | 7.90k | BuildAndStoreCommandPrefixCode( | 594 | 7.90k | &mut cmd_histo[..], | 595 | 7.90k | &mut cmd_depths[..], | 596 | 7.90k | &mut cmd_bits[..], | 597 | 7.90k | storage_ix, | 598 | 7.90k | storage, | 599 | | ); | 600 | 1.01M | for i in 0usize..num_commands { | 601 | 1.01M | let cmd: u32 = commands[i]; | 602 | 1.01M | let code: u32 = cmd & 0xffu32; | 603 | 1.01M | let extra: u32 = cmd >> 8; | 604 | 1.01M | BrotliWriteBits( | 605 | 1.01M | cmd_depths[code as usize] as usize, | 606 | 1.01M | cmd_bits[code as usize] as (u64), | 607 | 1.01M | storage_ix, | 608 | 1.01M | storage, | 609 | | ); | 610 | 1.01M | BrotliWriteBits( | 611 | 1.01M | kNumExtraBits[code as usize] as usize, | 612 | 1.01M | extra as (u64), | 613 | 1.01M | storage_ix, | 614 | 1.01M | storage, | 615 | | ); | 616 | 1.01M | if code < 24u32 { | 617 | 211k | let insert: u32 = kInsertOffset[code as usize].wrapping_add(extra); | 618 | 5.32M | for literal in literals[..(insert as usize)].iter() { | 619 | 5.32M | let lit: u8 = *literal; | 620 | 5.32M | BrotliWriteBits( | 621 | 5.32M | lit_depths[lit as usize] as usize, | 622 | 5.32M | lit_bits[lit as usize] as (u64), | 623 | 5.32M | storage_ix, | 624 | 5.32M | storage, | 625 | 5.32M | ); | 626 | 5.32M | } | 627 | 211k | literals = &literals[insert as usize..]; | 628 | 801k | } | 629 | | } | 630 | 7.90k | } |
Unexecuted instantiation: brotli::enc::compress_fragment_two_pass::StoreCommands::<_> |
631 | 1.32k | fn EmitUncompressedMetaBlock( |
632 | 1.32k | input: &[u8], |
633 | 1.32k | input_size: usize, |
634 | 1.32k | storage_ix: &mut usize, |
635 | 1.32k | storage: &mut [u8], |
636 | 1.32k | ) { |
637 | 1.32k | store_meta_block_header(input_size, true, storage_ix, storage); |
638 | 1.32k | *storage_ix = storage_ix.wrapping_add(7u32 as usize) & !7u32 as usize; |
639 | 1.32k | memcpy(storage, (*storage_ix >> 3), input, 0, input_size); |
640 | 1.32k | *storage_ix = storage_ix.wrapping_add(input_size << 3); |
641 | 1.32k | storage[(*storage_ix >> 3)] = 0u8; |
642 | 1.32k | } |
643 | | |
644 | | #[allow(unused_variables)] |
645 | | #[inline(always)] |
646 | 8.34k | fn compress_fragment_two_pass_impl<AllocHT: alloc::Allocator<HuffmanTree>>( |
647 | 8.34k | m: &mut AllocHT, |
648 | 8.34k | base_ip: &[u8], |
649 | 8.34k | mut input_size: usize, |
650 | 8.34k | is_last: bool, |
651 | 8.34k | command_buf: &mut [u32], |
652 | 8.34k | literal_buf: &mut [u8], |
653 | 8.34k | table: &mut [i32], |
654 | 8.34k | table_bits: usize, |
655 | 8.34k | min_match: usize, |
656 | 8.34k | storage_ix: &mut usize, |
657 | 8.34k | storage: &mut [u8], |
658 | 8.34k | ) { |
659 | 8.34k | let mut input_index: usize = 0usize; |
660 | 16.2k | while input_size > 0usize { |
661 | 7.91k | let block_size: usize = min(input_size, kCompressFragmentTwoPassBlockSize); |
662 | 7.91k | let mut num_literals: usize = 0; |
663 | 7.91k | let mut num_commands: usize = 0; |
664 | 7.91k | { |
665 | 7.91k | let mut literals = &mut literal_buf[..]; |
666 | 7.91k | let mut commands = &mut command_buf[..]; |
667 | 7.91k | CreateCommands( |
668 | 7.91k | input_index, |
669 | 7.91k | block_size, |
670 | 7.91k | input_size, |
671 | 7.91k | base_ip, |
672 | 7.91k | table, |
673 | 7.91k | table_bits, |
674 | 7.91k | min_match, |
675 | 7.91k | &mut literals, |
676 | 7.91k | &mut num_literals, |
677 | 7.91k | &mut commands, |
678 | 7.91k | &mut num_commands, |
679 | 7.91k | ); |
680 | 7.91k | } |
681 | 7.91k | if ShouldCompress(&base_ip[input_index..], block_size, num_literals) { |
682 | 7.90k | store_meta_block_header(block_size, false, storage_ix, storage); |
683 | 7.90k | BrotliWriteBits(13usize, 0, storage_ix, storage); |
684 | 7.90k | StoreCommands( |
685 | 7.90k | m, |
686 | 7.90k | literal_buf, |
687 | 7.90k | num_literals, |
688 | 7.90k | command_buf, |
689 | 7.90k | num_commands, |
690 | 7.90k | storage_ix, |
691 | 7.90k | storage, |
692 | 7.90k | ); |
693 | 7.90k | } else { |
694 | 13 | EmitUncompressedMetaBlock(&base_ip[input_index..], block_size, storage_ix, storage); |
695 | 13 | } |
696 | 7.91k | input_index = input_index.wrapping_add(block_size); |
697 | 7.91k | input_size = input_size.wrapping_sub(block_size); |
698 | | } |
699 | 8.34k | } brotli::enc::compress_fragment_two_pass::compress_fragment_two_pass_impl::<alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 646 | 8.34k | fn compress_fragment_two_pass_impl<AllocHT: alloc::Allocator<HuffmanTree>>( | 647 | 8.34k | m: &mut AllocHT, | 648 | 8.34k | base_ip: &[u8], | 649 | 8.34k | mut input_size: usize, | 650 | 8.34k | is_last: bool, | 651 | 8.34k | command_buf: &mut [u32], | 652 | 8.34k | literal_buf: &mut [u8], | 653 | 8.34k | table: &mut [i32], | 654 | 8.34k | table_bits: usize, | 655 | 8.34k | min_match: usize, | 656 | 8.34k | storage_ix: &mut usize, | 657 | 8.34k | storage: &mut [u8], | 658 | 8.34k | ) { | 659 | 8.34k | let mut input_index: usize = 0usize; | 660 | 16.2k | while input_size > 0usize { | 661 | 7.91k | let block_size: usize = min(input_size, kCompressFragmentTwoPassBlockSize); | 662 | 7.91k | let mut num_literals: usize = 0; | 663 | 7.91k | let mut num_commands: usize = 0; | 664 | 7.91k | { | 665 | 7.91k | let mut literals = &mut literal_buf[..]; | 666 | 7.91k | let mut commands = &mut command_buf[..]; | 667 | 7.91k | CreateCommands( | 668 | 7.91k | input_index, | 669 | 7.91k | block_size, | 670 | 7.91k | input_size, | 671 | 7.91k | base_ip, | 672 | 7.91k | table, | 673 | 7.91k | table_bits, | 674 | 7.91k | min_match, | 675 | 7.91k | &mut literals, | 676 | 7.91k | &mut num_literals, | 677 | 7.91k | &mut commands, | 678 | 7.91k | &mut num_commands, | 679 | 7.91k | ); | 680 | 7.91k | } | 681 | 7.91k | if ShouldCompress(&base_ip[input_index..], block_size, num_literals) { | 682 | 7.90k | store_meta_block_header(block_size, false, storage_ix, storage); | 683 | 7.90k | BrotliWriteBits(13usize, 0, storage_ix, storage); | 684 | 7.90k | StoreCommands( | 685 | 7.90k | m, | 686 | 7.90k | literal_buf, | 687 | 7.90k | num_literals, | 688 | 7.90k | command_buf, | 689 | 7.90k | num_commands, | 690 | 7.90k | storage_ix, | 691 | 7.90k | storage, | 692 | 7.90k | ); | 693 | 7.90k | } else { | 694 | 13 | EmitUncompressedMetaBlock(&base_ip[input_index..], block_size, storage_ix, storage); | 695 | 13 | } | 696 | 7.91k | input_index = input_index.wrapping_add(block_size); | 697 | 7.91k | input_size = input_size.wrapping_sub(block_size); | 698 | | } | 699 | 8.34k | } |
Unexecuted instantiation: brotli::enc::compress_fragment_two_pass::compress_fragment_two_pass_impl::<_> |
700 | | macro_rules! compress_specialization { |
701 | | ($table_bits : expr, $fname: ident) => { |
702 | 8.34k | fn $fname<AllocHT: alloc::Allocator<HuffmanTree>>( |
703 | 8.34k | mht: &mut AllocHT, |
704 | 8.34k | input: &[u8], |
705 | 8.34k | input_size: usize, |
706 | 8.34k | is_last: bool, |
707 | 8.34k | command_buf: &mut [u32], |
708 | 8.34k | literal_buf: &mut [u8], |
709 | 8.34k | table: &mut [i32], |
710 | 8.34k | storage_ix: &mut usize, |
711 | 8.34k | storage: &mut [u8], |
712 | 8.34k | ) { |
713 | 8.34k | let min_match = if $table_bits < 15 { 4 } else { 6 }; |
714 | 8.34k | compress_fragment_two_pass_impl( |
715 | 8.34k | mht, |
716 | 8.34k | input, |
717 | 8.34k | input_size, |
718 | 8.34k | is_last, |
719 | 8.34k | command_buf, |
720 | 8.34k | literal_buf, |
721 | 8.34k | table, |
722 | | $table_bits, |
723 | 8.34k | min_match, |
724 | 8.34k | storage_ix, |
725 | 8.34k | storage, |
726 | | ); |
727 | 8.34k | } brotli::enc::compress_fragment_two_pass::BrotliCompressFragmentTwoPassImpl8::<alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 702 | 768 | fn $fname<AllocHT: alloc::Allocator<HuffmanTree>>( | 703 | 768 | mht: &mut AllocHT, | 704 | 768 | input: &[u8], | 705 | 768 | input_size: usize, | 706 | 768 | is_last: bool, | 707 | 768 | command_buf: &mut [u32], | 708 | 768 | literal_buf: &mut [u8], | 709 | 768 | table: &mut [i32], | 710 | 768 | storage_ix: &mut usize, | 711 | 768 | storage: &mut [u8], | 712 | 768 | ) { | 713 | 768 | let min_match = if $table_bits < 15 { 4 } else { 6 }; | 714 | 768 | compress_fragment_two_pass_impl( | 715 | 768 | mht, | 716 | 768 | input, | 717 | 768 | input_size, | 718 | 768 | is_last, | 719 | 768 | command_buf, | 720 | 768 | literal_buf, | 721 | 768 | table, | 722 | | $table_bits, | 723 | 768 | min_match, | 724 | 768 | storage_ix, | 725 | 768 | storage, | 726 | | ); | 727 | 768 | } |
brotli::enc::compress_fragment_two_pass::BrotliCompressFragmentTwoPassImpl9::<alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 702 | 47 | fn $fname<AllocHT: alloc::Allocator<HuffmanTree>>( | 703 | 47 | mht: &mut AllocHT, | 704 | 47 | input: &[u8], | 705 | 47 | input_size: usize, | 706 | 47 | is_last: bool, | 707 | 47 | command_buf: &mut [u32], | 708 | 47 | literal_buf: &mut [u8], | 709 | 47 | table: &mut [i32], | 710 | 47 | storage_ix: &mut usize, | 711 | 47 | storage: &mut [u8], | 712 | 47 | ) { | 713 | 47 | let min_match = if $table_bits < 15 { 4 } else { 6 }; | 714 | 47 | compress_fragment_two_pass_impl( | 715 | 47 | mht, | 716 | 47 | input, | 717 | 47 | input_size, | 718 | 47 | is_last, | 719 | 47 | command_buf, | 720 | 47 | literal_buf, | 721 | 47 | table, | 722 | | $table_bits, | 723 | 47 | min_match, | 724 | 47 | storage_ix, | 725 | 47 | storage, | 726 | | ); | 727 | 47 | } |
brotli::enc::compress_fragment_two_pass::BrotliCompressFragmentTwoPassImpl10::<alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 702 | 7.21k | fn $fname<AllocHT: alloc::Allocator<HuffmanTree>>( | 703 | 7.21k | mht: &mut AllocHT, | 704 | 7.21k | input: &[u8], | 705 | 7.21k | input_size: usize, | 706 | 7.21k | is_last: bool, | 707 | 7.21k | command_buf: &mut [u32], | 708 | 7.21k | literal_buf: &mut [u8], | 709 | 7.21k | table: &mut [i32], | 710 | 7.21k | storage_ix: &mut usize, | 711 | 7.21k | storage: &mut [u8], | 712 | 7.21k | ) { | 713 | 7.21k | let min_match = if $table_bits < 15 { 4 } else { 6 }; | 714 | 7.21k | compress_fragment_two_pass_impl( | 715 | 7.21k | mht, | 716 | 7.21k | input, | 717 | 7.21k | input_size, | 718 | 7.21k | is_last, | 719 | 7.21k | command_buf, | 720 | 7.21k | literal_buf, | 721 | 7.21k | table, | 722 | | $table_bits, | 723 | 7.21k | min_match, | 724 | 7.21k | storage_ix, | 725 | 7.21k | storage, | 726 | | ); | 727 | 7.21k | } |
brotli::enc::compress_fragment_two_pass::BrotliCompressFragmentTwoPassImpl11::<alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 702 | 210 | fn $fname<AllocHT: alloc::Allocator<HuffmanTree>>( | 703 | 210 | mht: &mut AllocHT, | 704 | 210 | input: &[u8], | 705 | 210 | input_size: usize, | 706 | 210 | is_last: bool, | 707 | 210 | command_buf: &mut [u32], | 708 | 210 | literal_buf: &mut [u8], | 709 | 210 | table: &mut [i32], | 710 | 210 | storage_ix: &mut usize, | 711 | 210 | storage: &mut [u8], | 712 | 210 | ) { | 713 | 210 | let min_match = if $table_bits < 15 { 4 } else { 6 }; | 714 | 210 | compress_fragment_two_pass_impl( | 715 | 210 | mht, | 716 | 210 | input, | 717 | 210 | input_size, | 718 | 210 | is_last, | 719 | 210 | command_buf, | 720 | 210 | literal_buf, | 721 | 210 | table, | 722 | | $table_bits, | 723 | 210 | min_match, | 724 | 210 | storage_ix, | 725 | 210 | storage, | 726 | | ); | 727 | 210 | } |
brotli::enc::compress_fragment_two_pass::BrotliCompressFragmentTwoPassImpl12::<alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 702 | 3 | fn $fname<AllocHT: alloc::Allocator<HuffmanTree>>( | 703 | 3 | mht: &mut AllocHT, | 704 | 3 | input: &[u8], | 705 | 3 | input_size: usize, | 706 | 3 | is_last: bool, | 707 | 3 | command_buf: &mut [u32], | 708 | 3 | literal_buf: &mut [u8], | 709 | 3 | table: &mut [i32], | 710 | 3 | storage_ix: &mut usize, | 711 | 3 | storage: &mut [u8], | 712 | 3 | ) { | 713 | 3 | let min_match = if $table_bits < 15 { 4 } else { 6 }; | 714 | 3 | compress_fragment_two_pass_impl( | 715 | 3 | mht, | 716 | 3 | input, | 717 | 3 | input_size, | 718 | 3 | is_last, | 719 | 3 | command_buf, | 720 | 3 | literal_buf, | 721 | 3 | table, | 722 | | $table_bits, | 723 | 3 | min_match, | 724 | 3 | storage_ix, | 725 | 3 | storage, | 726 | | ); | 727 | 3 | } |
brotli::enc::compress_fragment_two_pass::BrotliCompressFragmentTwoPassImpl13::<alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 702 | 10 | fn $fname<AllocHT: alloc::Allocator<HuffmanTree>>( | 703 | 10 | mht: &mut AllocHT, | 704 | 10 | input: &[u8], | 705 | 10 | input_size: usize, | 706 | 10 | is_last: bool, | 707 | 10 | command_buf: &mut [u32], | 708 | 10 | literal_buf: &mut [u8], | 709 | 10 | table: &mut [i32], | 710 | 10 | storage_ix: &mut usize, | 711 | 10 | storage: &mut [u8], | 712 | 10 | ) { | 713 | 10 | let min_match = if $table_bits < 15 { 4 } else { 6 }; | 714 | 10 | compress_fragment_two_pass_impl( | 715 | 10 | mht, | 716 | 10 | input, | 717 | 10 | input_size, | 718 | 10 | is_last, | 719 | 10 | command_buf, | 720 | 10 | literal_buf, | 721 | 10 | table, | 722 | | $table_bits, | 723 | 10 | min_match, | 724 | 10 | storage_ix, | 725 | 10 | storage, | 726 | | ); | 727 | 10 | } |
brotli::enc::compress_fragment_two_pass::BrotliCompressFragmentTwoPassImpl14::<alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 702 | 11 | fn $fname<AllocHT: alloc::Allocator<HuffmanTree>>( | 703 | 11 | mht: &mut AllocHT, | 704 | 11 | input: &[u8], | 705 | 11 | input_size: usize, | 706 | 11 | is_last: bool, | 707 | 11 | command_buf: &mut [u32], | 708 | 11 | literal_buf: &mut [u8], | 709 | 11 | table: &mut [i32], | 710 | 11 | storage_ix: &mut usize, | 711 | 11 | storage: &mut [u8], | 712 | 11 | ) { | 713 | 11 | let min_match = if $table_bits < 15 { 4 } else { 6 }; | 714 | 11 | compress_fragment_two_pass_impl( | 715 | 11 | mht, | 716 | 11 | input, | 717 | 11 | input_size, | 718 | 11 | is_last, | 719 | 11 | command_buf, | 720 | 11 | literal_buf, | 721 | 11 | table, | 722 | | $table_bits, | 723 | 11 | min_match, | 724 | 11 | storage_ix, | 725 | 11 | storage, | 726 | | ); | 727 | 11 | } |
brotli::enc::compress_fragment_two_pass::BrotliCompressFragmentTwoPassImpl15::<alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 702 | 24 | fn $fname<AllocHT: alloc::Allocator<HuffmanTree>>( | 703 | 24 | mht: &mut AllocHT, | 704 | 24 | input: &[u8], | 705 | 24 | input_size: usize, | 706 | 24 | is_last: bool, | 707 | 24 | command_buf: &mut [u32], | 708 | 24 | literal_buf: &mut [u8], | 709 | 24 | table: &mut [i32], | 710 | 24 | storage_ix: &mut usize, | 711 | 24 | storage: &mut [u8], | 712 | 24 | ) { | 713 | 24 | let min_match = if $table_bits < 15 { 4 } else { 6 }; | 714 | 24 | compress_fragment_two_pass_impl( | 715 | 24 | mht, | 716 | 24 | input, | 717 | 24 | input_size, | 718 | 24 | is_last, | 719 | 24 | command_buf, | 720 | 24 | literal_buf, | 721 | 24 | table, | 722 | | $table_bits, | 723 | 24 | min_match, | 724 | 24 | storage_ix, | 725 | 24 | storage, | 726 | | ); | 727 | 24 | } |
brotli::enc::compress_fragment_two_pass::BrotliCompressFragmentTwoPassImpl16::<alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 702 | 15 | fn $fname<AllocHT: alloc::Allocator<HuffmanTree>>( | 703 | 15 | mht: &mut AllocHT, | 704 | 15 | input: &[u8], | 705 | 15 | input_size: usize, | 706 | 15 | is_last: bool, | 707 | 15 | command_buf: &mut [u32], | 708 | 15 | literal_buf: &mut [u8], | 709 | 15 | table: &mut [i32], | 710 | 15 | storage_ix: &mut usize, | 711 | 15 | storage: &mut [u8], | 712 | 15 | ) { | 713 | 15 | let min_match = if $table_bits < 15 { 4 } else { 6 }; | 714 | 15 | compress_fragment_two_pass_impl( | 715 | 15 | mht, | 716 | 15 | input, | 717 | 15 | input_size, | 718 | 15 | is_last, | 719 | 15 | command_buf, | 720 | 15 | literal_buf, | 721 | 15 | table, | 722 | | $table_bits, | 723 | 15 | min_match, | 724 | 15 | storage_ix, | 725 | 15 | storage, | 726 | | ); | 727 | 15 | } |
brotli::enc::compress_fragment_two_pass::BrotliCompressFragmentTwoPassImpl17::<alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 702 | 40 | fn $fname<AllocHT: alloc::Allocator<HuffmanTree>>( | 703 | 40 | mht: &mut AllocHT, | 704 | 40 | input: &[u8], | 705 | 40 | input_size: usize, | 706 | 40 | is_last: bool, | 707 | 40 | command_buf: &mut [u32], | 708 | 40 | literal_buf: &mut [u8], | 709 | 40 | table: &mut [i32], | 710 | 40 | storage_ix: &mut usize, | 711 | 40 | storage: &mut [u8], | 712 | 40 | ) { | 713 | 40 | let min_match = if $table_bits < 15 { 4 } else { 6 }; | 714 | 40 | compress_fragment_two_pass_impl( | 715 | 40 | mht, | 716 | 40 | input, | 717 | 40 | input_size, | 718 | 40 | is_last, | 719 | 40 | command_buf, | 720 | 40 | literal_buf, | 721 | 40 | table, | 722 | | $table_bits, | 723 | 40 | min_match, | 724 | 40 | storage_ix, | 725 | 40 | storage, | 726 | | ); | 727 | 40 | } |
Unexecuted instantiation: brotli::enc::compress_fragment_two_pass::BrotliCompressFragmentTwoPassImpl8::<_> Unexecuted instantiation: brotli::enc::compress_fragment_two_pass::BrotliCompressFragmentTwoPassImpl9::<_> Unexecuted instantiation: brotli::enc::compress_fragment_two_pass::BrotliCompressFragmentTwoPassImpl10::<_> Unexecuted instantiation: brotli::enc::compress_fragment_two_pass::BrotliCompressFragmentTwoPassImpl11::<_> Unexecuted instantiation: brotli::enc::compress_fragment_two_pass::BrotliCompressFragmentTwoPassImpl12::<_> Unexecuted instantiation: brotli::enc::compress_fragment_two_pass::BrotliCompressFragmentTwoPassImpl13::<_> Unexecuted instantiation: brotli::enc::compress_fragment_two_pass::BrotliCompressFragmentTwoPassImpl14::<_> Unexecuted instantiation: brotli::enc::compress_fragment_two_pass::BrotliCompressFragmentTwoPassImpl15::<_> Unexecuted instantiation: brotli::enc::compress_fragment_two_pass::BrotliCompressFragmentTwoPassImpl16::<_> Unexecuted instantiation: brotli::enc::compress_fragment_two_pass::BrotliCompressFragmentTwoPassImpl17::<_> |
728 | | }; |
729 | | } |
730 | | compress_specialization!(8, BrotliCompressFragmentTwoPassImpl8); |
731 | | compress_specialization!(9, BrotliCompressFragmentTwoPassImpl9); |
732 | | compress_specialization!(10, BrotliCompressFragmentTwoPassImpl10); |
733 | | compress_specialization!(11, BrotliCompressFragmentTwoPassImpl11); |
734 | | compress_specialization!(12, BrotliCompressFragmentTwoPassImpl12); |
735 | | compress_specialization!(13, BrotliCompressFragmentTwoPassImpl13); |
736 | | compress_specialization!(14, BrotliCompressFragmentTwoPassImpl14); |
737 | | compress_specialization!(15, BrotliCompressFragmentTwoPassImpl15); |
738 | | compress_specialization!(16, BrotliCompressFragmentTwoPassImpl16); |
739 | | compress_specialization!(17, BrotliCompressFragmentTwoPassImpl17); |
740 | | |
741 | 1.31k | fn RewindBitPosition(new_storage_ix: usize, storage_ix: &mut usize, storage: &mut [u8]) { |
742 | 1.31k | let bitpos: usize = new_storage_ix & 7usize; |
743 | 1.31k | let mask: usize = (1u32 << bitpos).wrapping_sub(1) as usize; |
744 | 1.31k | { |
745 | 1.31k | let _rhs = mask as u8; |
746 | 1.31k | let _lhs = &mut storage[(new_storage_ix >> 3)]; |
747 | 1.31k | *_lhs = (*_lhs as i32 & _rhs as i32) as u8; |
748 | 1.31k | } |
749 | 1.31k | *storage_ix = new_storage_ix; |
750 | 1.31k | } |
751 | | |
752 | | |
753 | 8.34k | pub(crate) fn compress_fragment_two_pass<AllocHT: alloc::Allocator<HuffmanTree>>( |
754 | 8.34k | m: &mut AllocHT, |
755 | 8.34k | input: &[u8], |
756 | 8.34k | input_size: usize, |
757 | 8.34k | is_last: bool, |
758 | 8.34k | command_buf: &mut [u32], |
759 | 8.34k | literal_buf: &mut [u8], |
760 | 8.34k | table: &mut [i32], |
761 | 8.34k | table_size: usize, |
762 | 8.34k | storage_ix: &mut usize, |
763 | 8.34k | storage: &mut [u8], |
764 | 8.34k | ) { |
765 | 8.34k | let initial_storage_ix: usize = *storage_ix; |
766 | 8.34k | let table_bits: usize = Log2FloorNonZero(table_size as u64) as usize; |
767 | 8.34k | if table_bits == 8usize { |
768 | 768 | BrotliCompressFragmentTwoPassImpl8( |
769 | 768 | m, |
770 | 768 | input, |
771 | 768 | input_size, |
772 | 768 | is_last, |
773 | 768 | command_buf, |
774 | 768 | literal_buf, |
775 | 768 | table, |
776 | 768 | storage_ix, |
777 | 768 | storage, |
778 | 768 | ); |
779 | 7.57k | } |
780 | 8.34k | if table_bits == 9usize { |
781 | 47 | BrotliCompressFragmentTwoPassImpl9( |
782 | 47 | m, |
783 | 47 | input, |
784 | 47 | input_size, |
785 | 47 | is_last, |
786 | 47 | command_buf, |
787 | 47 | literal_buf, |
788 | 47 | table, |
789 | 47 | storage_ix, |
790 | 47 | storage, |
791 | 47 | ); |
792 | 8.29k | } |
793 | 8.34k | if table_bits == 10usize { |
794 | 7.21k | BrotliCompressFragmentTwoPassImpl10( |
795 | 7.21k | m, |
796 | 7.21k | input, |
797 | 7.21k | input_size, |
798 | 7.21k | is_last, |
799 | 7.21k | command_buf, |
800 | 7.21k | literal_buf, |
801 | 7.21k | table, |
802 | 7.21k | storage_ix, |
803 | 7.21k | storage, |
804 | 7.21k | ); |
805 | 7.21k | } |
806 | 8.34k | if table_bits == 11usize { |
807 | 210 | BrotliCompressFragmentTwoPassImpl11( |
808 | 210 | m, |
809 | 210 | input, |
810 | 210 | input_size, |
811 | 210 | is_last, |
812 | 210 | command_buf, |
813 | 210 | literal_buf, |
814 | 210 | table, |
815 | 210 | storage_ix, |
816 | 210 | storage, |
817 | 210 | ); |
818 | 8.13k | } |
819 | 8.34k | if table_bits == 12usize { |
820 | 3 | BrotliCompressFragmentTwoPassImpl12( |
821 | 3 | m, |
822 | 3 | input, |
823 | 3 | input_size, |
824 | 3 | is_last, |
825 | 3 | command_buf, |
826 | 3 | literal_buf, |
827 | 3 | table, |
828 | 3 | storage_ix, |
829 | 3 | storage, |
830 | 3 | ); |
831 | 8.33k | } |
832 | 8.34k | if table_bits == 13usize { |
833 | 10 | BrotliCompressFragmentTwoPassImpl13( |
834 | 10 | m, |
835 | 10 | input, |
836 | 10 | input_size, |
837 | 10 | is_last, |
838 | 10 | command_buf, |
839 | 10 | literal_buf, |
840 | 10 | table, |
841 | 10 | storage_ix, |
842 | 10 | storage, |
843 | 10 | ); |
844 | 8.33k | } |
845 | 8.34k | if table_bits == 14usize { |
846 | 11 | BrotliCompressFragmentTwoPassImpl14( |
847 | 11 | m, |
848 | 11 | input, |
849 | 11 | input_size, |
850 | 11 | is_last, |
851 | 11 | command_buf, |
852 | 11 | literal_buf, |
853 | 11 | table, |
854 | 11 | storage_ix, |
855 | 11 | storage, |
856 | 11 | ); |
857 | 8.32k | } |
858 | 8.34k | if table_bits == 15usize { |
859 | 24 | BrotliCompressFragmentTwoPassImpl15( |
860 | 24 | m, |
861 | 24 | input, |
862 | 24 | input_size, |
863 | 24 | is_last, |
864 | 24 | command_buf, |
865 | 24 | literal_buf, |
866 | 24 | table, |
867 | 24 | storage_ix, |
868 | 24 | storage, |
869 | 24 | ); |
870 | 8.31k | } |
871 | 8.34k | if table_bits == 16usize { |
872 | 15 | BrotliCompressFragmentTwoPassImpl16( |
873 | 15 | m, |
874 | 15 | input, |
875 | 15 | input_size, |
876 | 15 | is_last, |
877 | 15 | command_buf, |
878 | 15 | literal_buf, |
879 | 15 | table, |
880 | 15 | storage_ix, |
881 | 15 | storage, |
882 | 15 | ); |
883 | 8.32k | } |
884 | 8.34k | if table_bits == 17usize { |
885 | 40 | BrotliCompressFragmentTwoPassImpl17( |
886 | 40 | m, |
887 | 40 | input, |
888 | 40 | input_size, |
889 | 40 | is_last, |
890 | 40 | command_buf, |
891 | 40 | literal_buf, |
892 | 40 | table, |
893 | 40 | storage_ix, |
894 | 40 | storage, |
895 | 40 | ); |
896 | 8.30k | } |
897 | 8.34k | if storage_ix.wrapping_sub(initial_storage_ix) > (31usize).wrapping_add(input_size << 3) { |
898 | 1.31k | RewindBitPosition(initial_storage_ix, storage_ix, storage); |
899 | 1.31k | EmitUncompressedMetaBlock(input, input_size, storage_ix, storage); |
900 | 7.02k | } |
901 | 8.34k | if is_last { |
902 | 502 | BrotliWriteBits(1, 1, storage_ix, storage); |
903 | 502 | BrotliWriteBits(1, 1, storage_ix, storage); |
904 | 502 | *storage_ix = storage_ix.wrapping_add(7u32 as usize) & !7u32 as usize; |
905 | 7.83k | } |
906 | 8.34k | } brotli::enc::compress_fragment_two_pass::compress_fragment_two_pass::<alloc_stdlib::std_alloc::StandardAlloc> Line | Count | Source | 753 | 8.34k | pub(crate) fn compress_fragment_two_pass<AllocHT: alloc::Allocator<HuffmanTree>>( | 754 | 8.34k | m: &mut AllocHT, | 755 | 8.34k | input: &[u8], | 756 | 8.34k | input_size: usize, | 757 | 8.34k | is_last: bool, | 758 | 8.34k | command_buf: &mut [u32], | 759 | 8.34k | literal_buf: &mut [u8], | 760 | 8.34k | table: &mut [i32], | 761 | 8.34k | table_size: usize, | 762 | 8.34k | storage_ix: &mut usize, | 763 | 8.34k | storage: &mut [u8], | 764 | 8.34k | ) { | 765 | 8.34k | let initial_storage_ix: usize = *storage_ix; | 766 | 8.34k | let table_bits: usize = Log2FloorNonZero(table_size as u64) as usize; | 767 | 8.34k | if table_bits == 8usize { | 768 | 768 | BrotliCompressFragmentTwoPassImpl8( | 769 | 768 | m, | 770 | 768 | input, | 771 | 768 | input_size, | 772 | 768 | is_last, | 773 | 768 | command_buf, | 774 | 768 | literal_buf, | 775 | 768 | table, | 776 | 768 | storage_ix, | 777 | 768 | storage, | 778 | 768 | ); | 779 | 7.57k | } | 780 | 8.34k | if table_bits == 9usize { | 781 | 47 | BrotliCompressFragmentTwoPassImpl9( | 782 | 47 | m, | 783 | 47 | input, | 784 | 47 | input_size, | 785 | 47 | is_last, | 786 | 47 | command_buf, | 787 | 47 | literal_buf, | 788 | 47 | table, | 789 | 47 | storage_ix, | 790 | 47 | storage, | 791 | 47 | ); | 792 | 8.29k | } | 793 | 8.34k | if table_bits == 10usize { | 794 | 7.21k | BrotliCompressFragmentTwoPassImpl10( | 795 | 7.21k | m, | 796 | 7.21k | input, | 797 | 7.21k | input_size, | 798 | 7.21k | is_last, | 799 | 7.21k | command_buf, | 800 | 7.21k | literal_buf, | 801 | 7.21k | table, | 802 | 7.21k | storage_ix, | 803 | 7.21k | storage, | 804 | 7.21k | ); | 805 | 7.21k | } | 806 | 8.34k | if table_bits == 11usize { | 807 | 210 | BrotliCompressFragmentTwoPassImpl11( | 808 | 210 | m, | 809 | 210 | input, | 810 | 210 | input_size, | 811 | 210 | is_last, | 812 | 210 | command_buf, | 813 | 210 | literal_buf, | 814 | 210 | table, | 815 | 210 | storage_ix, | 816 | 210 | storage, | 817 | 210 | ); | 818 | 8.13k | } | 819 | 8.34k | if table_bits == 12usize { | 820 | 3 | BrotliCompressFragmentTwoPassImpl12( | 821 | 3 | m, | 822 | 3 | input, | 823 | 3 | input_size, | 824 | 3 | is_last, | 825 | 3 | command_buf, | 826 | 3 | literal_buf, | 827 | 3 | table, | 828 | 3 | storage_ix, | 829 | 3 | storage, | 830 | 3 | ); | 831 | 8.33k | } | 832 | 8.34k | if table_bits == 13usize { | 833 | 10 | BrotliCompressFragmentTwoPassImpl13( | 834 | 10 | m, | 835 | 10 | input, | 836 | 10 | input_size, | 837 | 10 | is_last, | 838 | 10 | command_buf, | 839 | 10 | literal_buf, | 840 | 10 | table, | 841 | 10 | storage_ix, | 842 | 10 | storage, | 843 | 10 | ); | 844 | 8.33k | } | 845 | 8.34k | if table_bits == 14usize { | 846 | 11 | BrotliCompressFragmentTwoPassImpl14( | 847 | 11 | m, | 848 | 11 | input, | 849 | 11 | input_size, | 850 | 11 | is_last, | 851 | 11 | command_buf, | 852 | 11 | literal_buf, | 853 | 11 | table, | 854 | 11 | storage_ix, | 855 | 11 | storage, | 856 | 11 | ); | 857 | 8.32k | } | 858 | 8.34k | if table_bits == 15usize { | 859 | 24 | BrotliCompressFragmentTwoPassImpl15( | 860 | 24 | m, | 861 | 24 | input, | 862 | 24 | input_size, | 863 | 24 | is_last, | 864 | 24 | command_buf, | 865 | 24 | literal_buf, | 866 | 24 | table, | 867 | 24 | storage_ix, | 868 | 24 | storage, | 869 | 24 | ); | 870 | 8.31k | } | 871 | 8.34k | if table_bits == 16usize { | 872 | 15 | BrotliCompressFragmentTwoPassImpl16( | 873 | 15 | m, | 874 | 15 | input, | 875 | 15 | input_size, | 876 | 15 | is_last, | 877 | 15 | command_buf, | 878 | 15 | literal_buf, | 879 | 15 | table, | 880 | 15 | storage_ix, | 881 | 15 | storage, | 882 | 15 | ); | 883 | 8.32k | } | 884 | 8.34k | if table_bits == 17usize { | 885 | 40 | BrotliCompressFragmentTwoPassImpl17( | 886 | 40 | m, | 887 | 40 | input, | 888 | 40 | input_size, | 889 | 40 | is_last, | 890 | 40 | command_buf, | 891 | 40 | literal_buf, | 892 | 40 | table, | 893 | 40 | storage_ix, | 894 | 40 | storage, | 895 | 40 | ); | 896 | 8.30k | } | 897 | 8.34k | if storage_ix.wrapping_sub(initial_storage_ix) > (31usize).wrapping_add(input_size << 3) { | 898 | 1.31k | RewindBitPosition(initial_storage_ix, storage_ix, storage); | 899 | 1.31k | EmitUncompressedMetaBlock(input, input_size, storage_ix, storage); | 900 | 7.02k | } | 901 | 8.34k | if is_last { | 902 | 502 | BrotliWriteBits(1, 1, storage_ix, storage); | 903 | 502 | BrotliWriteBits(1, 1, storage_ix, storage); | 904 | 502 | *storage_ix = storage_ix.wrapping_add(7u32 as usize) & !7u32 as usize; | 905 | 7.83k | } | 906 | 8.34k | } |
Unexecuted instantiation: brotli::enc::compress_fragment_two_pass::compress_fragment_two_pass::<_> |