Lines Matching +full:op +full:- +full:mode
1 /* inffast.c -- fast decoding
2 * Copyright (C) 1995-2004 Mark Adler
6 /* U-Boot: we already included these
15 /* Allow machine dependent optimization for post-increment or pre-increment.
17 Pre-increment preferred for:
18 - PowerPC G3 (Adler)
19 - MIPS R5000 (Randers-Pehrson)
20 Post-increment preferred for:
21 - none
23 - Pentium III (Anderson)
24 - M68060 (Nikl)
37 available, an end-of-block is encountered, or a data error is encountered.
44 state->mode == LEN
45 strm->avail_in >= 6
46 strm->avail_out >= 258
47 start >= strm->avail_out
48 state->bits < 8
50 On return, state->mode is one of:
52 LEN -- ran out of enough output space or enough available input
53 TYPE -- reached end of block code, inflate() to interpret next block
54 BAD -- error in block data
58 - The maximum input bits used by a length/distance pair is 15 bits for the
61 Therefore if strm->avail_in >= 6, then there is enough input to avoid
64 - The maximum bytes that a single length/distance pair can output is 258
66 requires strm->avail_out >= 258 for each loop to avoid checking for
70 /* start: inflate()'s starting value for strm->avail_out */ in inflate_fast()
73 unsigned char FAR *in; /* local strm->next_in */ in inflate_fast()
75 unsigned char FAR *out; /* local strm->next_out */ in inflate_fast()
76 unsigned char FAR *beg; /* inflate()'s initial strm->next_out */ in inflate_fast()
85 unsigned long hold; /* local strm->hold */ in inflate_fast()
86 unsigned bits; /* local strm->bits */ in inflate_fast()
87 code const FAR *lcode; /* local strm->lencode */ in inflate_fast()
88 code const FAR *dcode; /* local strm->distcode */ in inflate_fast()
92 unsigned op; /* code bits, operation, extra bits, or */ in inflate_fast() local
99 state = (struct inflate_state FAR *)strm->state; in inflate_fast()
100 in = strm->next_in - OFF; in inflate_fast()
101 last = in + (strm->avail_in - 5); in inflate_fast()
102 if (in > last && strm->avail_in > 5) { in inflate_fast()
104 * overflow detected, limit strm->avail_in to the in inflate_fast()
107 strm->avail_in = 0xffffffff - (uintptr_t)in; in inflate_fast()
108 last = in + (strm->avail_in - 5); in inflate_fast()
110 out = strm->next_out - OFF; in inflate_fast()
111 beg = out - (start - strm->avail_out); in inflate_fast()
112 end = out + (strm->avail_out - 257); in inflate_fast()
114 dmax = state->dmax; in inflate_fast()
116 wsize = state->wsize; in inflate_fast()
117 whave = state->whave; in inflate_fast()
118 write = state->write; in inflate_fast()
119 window = state->window; in inflate_fast()
120 hold = state->hold; in inflate_fast()
121 bits = state->bits; in inflate_fast()
122 lcode = state->lencode; in inflate_fast()
123 dcode = state->distcode; in inflate_fast()
124 lmask = (1U << state->lenbits) - 1; in inflate_fast()
125 dmask = (1U << state->distbits) - 1; in inflate_fast()
127 /* decode literals and length/distances until end-of-block or not enough in inflate_fast()
138 op = (unsigned)(this.bits); in inflate_fast()
139 hold >>= op; in inflate_fast()
140 bits -= op; in inflate_fast()
141 op = (unsigned)(this.op); in inflate_fast()
142 if (op == 0) { /* literal */ in inflate_fast()
148 else if (op & 16) { /* length base */ in inflate_fast()
150 op &= 15; /* number of extra bits */ in inflate_fast()
151 if (op) { in inflate_fast()
152 if (bits < op) { in inflate_fast()
156 len += (unsigned)hold & ((1U << op) - 1); in inflate_fast()
157 hold >>= op; in inflate_fast()
158 bits -= op; in inflate_fast()
169 op = (unsigned)(this.bits); in inflate_fast()
170 hold >>= op; in inflate_fast()
171 bits -= op; in inflate_fast()
172 op = (unsigned)(this.op); in inflate_fast()
173 if (op & 16) { /* distance base */ in inflate_fast()
175 op &= 15; /* number of extra bits */ in inflate_fast()
176 if (bits < op) { in inflate_fast()
179 if (bits < op) { in inflate_fast()
184 dist += (unsigned)hold & ((1U << op) - 1); in inflate_fast()
187 strm->msg = (char *)"invalid distance too far back"; in inflate_fast()
188 state->mode = BAD; in inflate_fast()
192 hold >>= op; in inflate_fast()
193 bits -= op; in inflate_fast()
195 op = (unsigned)(out - beg); /* max distance in output */ in inflate_fast()
196 if (dist > op) { /* see if copy from window */ in inflate_fast()
197 op = dist - op; /* distance back in window */ in inflate_fast()
198 if (op > whave) { in inflate_fast()
199 strm->msg = (char *)"invalid distance too far back"; in inflate_fast()
200 state->mode = BAD; in inflate_fast()
203 from = window - OFF; in inflate_fast()
205 from += wsize - op; in inflate_fast()
206 if (op < len) { /* some from window */ in inflate_fast()
207 len -= op; in inflate_fast()
210 } while (--op); in inflate_fast()
211 from = out - dist; /* rest from output */ in inflate_fast()
214 else if (write < op) { /* wrap around window */ in inflate_fast()
215 from += wsize + write - op; in inflate_fast()
216 op -= write; in inflate_fast()
217 if (op < len) { /* some from end of window */ in inflate_fast()
218 len -= op; in inflate_fast()
221 } while (--op); in inflate_fast()
222 from = window - OFF; in inflate_fast()
224 op = write; in inflate_fast()
225 len -= op; in inflate_fast()
228 } while (--op); in inflate_fast()
229 from = out - dist; /* rest from output */ in inflate_fast()
234 from += write - op; in inflate_fast()
235 if (op < len) { /* some from window */ in inflate_fast()
236 len -= op; in inflate_fast()
239 } while (--op); in inflate_fast()
240 from = out - dist; /* rest from output */ in inflate_fast()
247 len -= 3; in inflate_fast()
259 from = out - dist; /* copy direct from output */ in inflate_fast()
262 if (!((long)(out - 1 + OFF) & 1)) { in inflate_fast()
264 len--; in inflate_fast()
266 sout = (unsigned short *)(out - OFF); in inflate_fast()
270 sfrom = (unsigned short *)(from - OFF); in inflate_fast()
274 while (--loops); in inflate_fast()
280 pat16 = *(sout-2+2*OFF); in inflate_fast()
292 while (--loops); in inflate_fast()
299 else if ((op & 64) == 0) { /* 2nd level distance code */ in inflate_fast()
300 this = dcode[this.val + (hold & ((1U << op) - 1))]; in inflate_fast()
304 strm->msg = (char *)"invalid distance code"; in inflate_fast()
305 state->mode = BAD; in inflate_fast()
309 else if ((op & 64) == 0) { /* 2nd level length code */ in inflate_fast()
310 this = lcode[this.val + (hold & ((1U << op) - 1))]; in inflate_fast()
313 else if (op & 32) { /* end-of-block */ in inflate_fast()
315 state->mode = TYPE; in inflate_fast()
319 strm->msg = (char *)"invalid literal/length code"; in inflate_fast()
320 state->mode = BAD; in inflate_fast()
327 in -= len; in inflate_fast()
328 bits -= len << 3; in inflate_fast()
329 hold &= (1U << bits) - 1; in inflate_fast()
332 strm->next_in = in + OFF; in inflate_fast()
333 strm->next_out = out + OFF; in inflate_fast()
334 strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last)); in inflate_fast()
335 strm->avail_out = (unsigned)(out < end ? in inflate_fast()
336 257 + (end - out) : 257 - (out - end)); in inflate_fast()
337 state->hold = hold; in inflate_fast()
338 state->bits = bits; in inflate_fast()
344 - Using bit fields for code structure
345 - Different op definition to avoid & for extra bits (do & for table bits)
346 - Three separate decoding do-loops for direct, window, and write == 0
347 - Special case for distance > 1 copies to do overlapped load and store copy
348 - Explicit branch predictions (based on measured branch probabilities)
349 - Deferring match copy and interspersed it with decoding subsequent codes
350 - Swapping literal/length else
351 - Swapping window/direct else
352 - Larger unrolled copy loops (three is about right)
353 - Moving len -= 3 statement into middle of loop