Lines Matching +full:three +full:- +full:state

1 /* inffast.c -- fast decoding
2 * Copyright (C) 1995-2004 Mark Adler
33 available, an end-of-block is encountered, or a data error is encountered.
40 state->mode == LEN
41 strm->avail_in >= 6
42 strm->avail_out >= 258
43 start >= strm->avail_out
44 state->bits < 8
46 On return, state->mode is one of:
48 LEN -- ran out of enough output space or enough available input
49 TYPE -- reached end of block code, inflate() to interpret next block
50 BAD -- error in block data
54 - The maximum input bits used by a length/distance pair is 15 bits for the
57 Therefore if strm->avail_in >= 6, then there is enough input to avoid
60 - The maximum bytes that a single length/distance pair can output is 258
62 requires strm->avail_out >= 258 for each loop to avoid checking for
65 - @start: inflate()'s starting value for strm->avail_out
69 struct inflate_state *state; in inflate_fast() local
70 const unsigned char *in; /* local strm->next_in */ in inflate_fast()
72 unsigned char *out; /* local strm->next_out */ in inflate_fast()
73 unsigned char *beg; /* inflate()'s initial strm->next_out */ in inflate_fast()
82 unsigned long hold; /* local strm->hold */ in inflate_fast()
83 unsigned bits; /* local strm->bits */ in inflate_fast()
84 code const *lcode; /* local strm->lencode */ in inflate_fast()
85 code const *dcode; /* local strm->distcode */ in inflate_fast()
95 /* copy state to local variables */ in inflate_fast()
96 state = (struct inflate_state *)strm->state; in inflate_fast()
97 in = strm->next_in; in inflate_fast()
98 last = in + (strm->avail_in - 5); in inflate_fast()
99 out = strm->next_out; in inflate_fast()
100 beg = out - (start - strm->avail_out); in inflate_fast()
101 end = out + (strm->avail_out - 257); in inflate_fast()
103 dmax = state->dmax; in inflate_fast()
105 wsize = state->wsize; in inflate_fast()
106 whave = state->whave; in inflate_fast()
107 write = state->write; in inflate_fast()
108 window = state->window; in inflate_fast()
109 hold = state->hold; in inflate_fast()
110 bits = state->bits; in inflate_fast()
111 lcode = state->lencode; in inflate_fast()
112 dcode = state->distcode; in inflate_fast()
113 lmask = (1U << state->lenbits) - 1; in inflate_fast()
114 dmask = (1U << state->distbits) - 1; in inflate_fast()
116 /* decode literals and length/distances until end-of-block or not enough in inflate_fast()
129 bits -= op; in inflate_fast()
142 len += (unsigned)hold & ((1U << op) - 1); in inflate_fast()
144 bits -= op; in inflate_fast()
156 bits -= op; in inflate_fast()
169 dist += (unsigned)hold & ((1U << op) - 1); in inflate_fast()
172 strm->msg = (char *)"invalid distance too far back"; in inflate_fast()
173 state->mode = BAD; in inflate_fast()
178 bits -= op; in inflate_fast()
179 op = (unsigned)(out - beg); /* max distance in output */ in inflate_fast()
181 op = dist - op; /* distance back in window */ in inflate_fast()
183 strm->msg = (char *)"invalid distance too far back"; in inflate_fast()
184 state->mode = BAD; in inflate_fast()
189 from += wsize - op; in inflate_fast()
191 len -= op; in inflate_fast()
194 } while (--op); in inflate_fast()
195 from = out - dist; /* rest from output */ in inflate_fast()
199 from += wsize + write - op; in inflate_fast()
200 op -= write; in inflate_fast()
202 len -= op; in inflate_fast()
205 } while (--op); in inflate_fast()
209 len -= op; in inflate_fast()
212 } while (--op); in inflate_fast()
213 from = out - dist; /* rest from output */ in inflate_fast()
218 from += write - op; in inflate_fast()
220 len -= op; in inflate_fast()
223 } while (--op); in inflate_fast()
224 from = out - dist; /* rest from output */ in inflate_fast()
231 len -= 3; in inflate_fast()
243 from = out - dist; /* copy direct from output */ in inflate_fast()
244 /* minimum length is three */ in inflate_fast()
246 if (!((long)(out - 1) & 1)) { in inflate_fast()
248 len--; in inflate_fast()
261 } while (--loops); in inflate_fast()
267 pat16 = *(sout-1); in inflate_fast()
278 while (--loops); in inflate_fast()
286 this = dcode[this.val + (hold & ((1U << op) - 1))]; in inflate_fast()
290 strm->msg = (char *)"invalid distance code"; in inflate_fast()
291 state->mode = BAD; in inflate_fast()
296 this = lcode[this.val + (hold & ((1U << op) - 1))]; in inflate_fast()
299 else if (op & 32) { /* end-of-block */ in inflate_fast()
300 state->mode = TYPE; in inflate_fast()
304 strm->msg = (char *)"invalid literal/length code"; in inflate_fast()
305 state->mode = BAD; in inflate_fast()
312 in -= len; in inflate_fast()
313 bits -= len << 3; in inflate_fast()
314 hold &= (1U << bits) - 1; in inflate_fast()
316 /* update state and return */ in inflate_fast()
317 strm->next_in = in; in inflate_fast()
318 strm->next_out = out; in inflate_fast()
319 strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last)); in inflate_fast()
320 strm->avail_out = (unsigned)(out < end ? in inflate_fast()
321 257 + (end - out) : 257 - (out - end)); in inflate_fast()
322 state->hold = hold; in inflate_fast()
323 state->bits = bits; in inflate_fast()
329 - Using bit fields for code structure
330 - Different op definition to avoid & for extra bits (do & for table bits)
331 - Three separate decoding do-loops for direct, window, and write == 0
332 - Special case for distance > 1 copies to do overlapped load and store copy
333 - Explicit branch predictions (based on measured branch probabilities)
334 - Deferring match copy and interspersed it with decoding subsequent codes
335 - Swapping literal/length else
336 - Swapping window/direct else
337 - Larger unrolled copy loops (three is about right)
338 - Moving len -= 3 statement into middle of loop