Lines Matching +full:three +full:- +full:level
1 /* inffast.c -- fast decoding
2 * Copyright (C) 1995-2017 Mark Adler
12 # pragma message("Assembler code may have bugs -- use at your own risk")
18 available, an end-of-block is encountered, or a data error is encountered.
25 state->mode == LEN
26 strm->avail_in >= 6
27 strm->avail_out >= 258
28 start >= strm->avail_out
29 state->bits < 8
31 On return, state->mode is one of:
33 LEN -- ran out of enough output space or enough available input
34 TYPE -- reached end of block code, inflate() to interpret next block
35 BAD -- error in block data
39 - The maximum input bits used by a length/distance pair is 15 bits for the
42 Therefore if strm->avail_in >= 6, then there is enough input to avoid
45 - The maximum bytes that a single length/distance pair can output is 258
47 requires strm->avail_out >= 258 for each loop to avoid checking for
52 z_const unsigned char FAR *in; /* local strm->next_in */ in inflate_fast()
54 unsigned char FAR *out; /* local strm->next_out */ in inflate_fast()
55 unsigned char FAR *beg; /* inflate()'s initial strm->next_out */ in inflate_fast()
64 unsigned long hold; /* local strm->hold */ in inflate_fast()
65 unsigned bits; /* local strm->bits */ in inflate_fast()
66 code const FAR *lcode; /* local strm->lencode */ in inflate_fast()
67 code const FAR *dcode; /* local strm->distcode */ in inflate_fast()
68 unsigned lmask; /* mask for first level of length codes */ in inflate_fast()
69 unsigned dmask; /* mask for first level of distance codes */ in inflate_fast()
78 state = (struct inflate_state FAR *)strm->state; in inflate_fast()
79 in = strm->next_in; in inflate_fast()
80 last = in + (strm->avail_in - 5); in inflate_fast()
81 out = strm->next_out; in inflate_fast()
82 beg = out - (start - strm->avail_out); in inflate_fast()
83 end = out + (strm->avail_out - 257); in inflate_fast()
85 dmax = state->dmax; in inflate_fast()
87 wsize = state->wsize; in inflate_fast()
88 whave = state->whave; in inflate_fast()
89 wnext = state->wnext; in inflate_fast()
90 window = state->window; in inflate_fast()
91 hold = state->hold; in inflate_fast()
92 bits = state->bits; in inflate_fast()
93 lcode = state->lencode; in inflate_fast()
94 dcode = state->distcode; in inflate_fast()
95 lmask = (1U << state->lenbits) - 1; in inflate_fast()
96 dmask = (1U << state->distbits) - 1; in inflate_fast()
98 /* decode literals and length/distances until end-of-block or not enough in inflate_fast()
109 op = (unsigned)(here->bits); in inflate_fast()
111 bits -= op; in inflate_fast()
112 op = (unsigned)(here->op); in inflate_fast()
114 Tracevv((stderr, here->val >= 0x20 && here->val < 0x7f ? in inflate_fast()
116 "inflate: literal 0x%02x\n", here->val)); in inflate_fast()
117 *out++ = (unsigned char)(here->val); in inflate_fast()
120 len = (unsigned)(here->val); in inflate_fast()
127 len += (unsigned)hold & ((1U << op) - 1); in inflate_fast()
129 bits -= op; in inflate_fast()
140 op = (unsigned)(here->bits); in inflate_fast()
142 bits -= op; in inflate_fast()
143 op = (unsigned)(here->op); in inflate_fast()
145 dist = (unsigned)(here->val); in inflate_fast()
155 dist += (unsigned)hold & ((1U << op) - 1); in inflate_fast()
158 strm->msg = (char *)"invalid distance too far back"; in inflate_fast()
159 state->mode = BAD; in inflate_fast()
164 bits -= op; in inflate_fast()
166 op = (unsigned)(out - beg); /* max distance in output */ in inflate_fast()
168 op = dist - op; /* distance back in window */ in inflate_fast()
170 if (state->sane) { in inflate_fast()
171 strm->msg = in inflate_fast()
173 state->mode = BAD; in inflate_fast()
177 if (len <= op - whave) { in inflate_fast()
180 } while (--len); in inflate_fast()
183 len -= op - whave; in inflate_fast()
186 } while (--op > whave); in inflate_fast()
188 from = out - dist; in inflate_fast()
191 } while (--len); in inflate_fast()
198 from += wsize - op; in inflate_fast()
200 len -= op; in inflate_fast()
203 } while (--op); in inflate_fast()
204 from = out - dist; /* rest from output */ in inflate_fast()
208 from += wsize + wnext - op; in inflate_fast()
209 op -= wnext; in inflate_fast()
211 len -= op; in inflate_fast()
214 } while (--op); in inflate_fast()
218 len -= op; in inflate_fast()
221 } while (--op); in inflate_fast()
222 from = out - dist; /* rest from output */ in inflate_fast()
227 from += wnext - op; in inflate_fast()
229 len -= op; in inflate_fast()
232 } while (--op); in inflate_fast()
233 from = out - dist; /* rest from output */ in inflate_fast()
240 len -= 3; in inflate_fast()
249 from = out - dist; /* copy direct from output */ in inflate_fast()
250 do { /* minimum length is three */ in inflate_fast()
254 len -= 3; in inflate_fast()
263 else if ((op & 64) == 0) { /* 2nd level distance code */ in inflate_fast()
264 here = dcode + here->val + (hold & ((1U << op) - 1)); in inflate_fast()
268 strm->msg = (char *)"invalid distance code"; in inflate_fast()
269 state->mode = BAD; in inflate_fast()
273 else if ((op & 64) == 0) { /* 2nd level length code */ in inflate_fast()
274 here = lcode + here->val + (hold & ((1U << op) - 1)); in inflate_fast()
277 else if (op & 32) { /* end-of-block */ in inflate_fast()
279 state->mode = TYPE; in inflate_fast()
283 strm->msg = (char *)"invalid literal/length code"; in inflate_fast()
284 state->mode = BAD; in inflate_fast()
291 in -= len; in inflate_fast()
292 bits -= len << 3; in inflate_fast()
293 hold &= (1U << bits) - 1; in inflate_fast()
296 strm->next_in = in; in inflate_fast()
297 strm->next_out = out; in inflate_fast()
298 strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last)); in inflate_fast()
299 strm->avail_out = (unsigned)(out < end ? in inflate_fast()
300 257 + (end - out) : 257 - (out - end)); in inflate_fast()
301 state->hold = hold; in inflate_fast()
302 state->bits = bits; in inflate_fast()
308 - Using bit fields for code structure
309 - Different op definition to avoid & for extra bits (do & for table bits)
310 - Three separate decoding do-loops for direct, window, and wnext == 0
311 - Special case for distance > 1 copies to do overlapped load and store copy
312 - Explicit branch predictions (based on measured branch probabilities)
313 - Deferring match copy and interspersed it with decoding subsequent codes
314 - Swapping literal/length else
315 - Swapping window/direct else
316 - Larger unrolled copy loops (three is about right)
317 - Moving len -= 3 statement into middle of loop