Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* inffast.c -- fast decoding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * Copyright (C) 1995-2004 Mark Adler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * For conditions of distribution and use, see copyright notice in zlib.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/zutil.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include "inftrees.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include "inflate.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include "inffast.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #ifndef ASMINF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) union uu {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 	unsigned short us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 	unsigned char b[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) /* Endian independed version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) static inline unsigned short
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) get_unaligned16(const unsigned short *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	union uu  mm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	unsigned char *b = (unsigned char *)p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	mm.b[0] = b[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	mm.b[1] = b[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	return mm.us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)    Decode literal, length, and distance codes and write out the resulting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)    literal and match bytes until either not enough input or output is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)    available, an end-of-block is encountered, or a data error is encountered.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)    When large enough input and output buffers are supplied to inflate(), for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)    example, a 16K input buffer and a 64K output buffer, more than 95% of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)    inflate execution time is spent in this routine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)    Entry assumptions:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)         state->mode == LEN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)         strm->avail_in >= 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)         strm->avail_out >= 258
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)         start >= strm->avail_out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)         state->bits < 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)    On return, state->mode is one of:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)         LEN -- ran out of enough output space or enough available input
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)         TYPE -- reached end of block code, inflate() to interpret next block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)         BAD -- error in block data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)    Notes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)     - The maximum input bits used by a length/distance pair is 15 bits for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)       length code, 5 bits for the length extra, 15 bits for the distance code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)       and 13 bits for the distance extra.  This totals 48 bits, or six bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)       Therefore if strm->avail_in >= 6, then there is enough input to avoid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)       checking for available input while decoding.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)     - The maximum bytes that a single length/distance pair can output is 258
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)       bytes, which is the maximum length that can be coded.  inflate_fast()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)       requires strm->avail_out >= 258 for each loop to avoid checking for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)       output space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)     - @start:	inflate()'s starting value for strm->avail_out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) void inflate_fast(z_streamp strm, unsigned start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)     struct inflate_state *state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)     const unsigned char *in;    /* local strm->next_in */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)     const unsigned char *last;  /* while in < last, enough input available */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)     unsigned char *out;         /* local strm->next_out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)     unsigned char *beg;         /* inflate()'s initial strm->next_out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)     unsigned char *end;         /* while out < end, enough space available */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) #ifdef INFLATE_STRICT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)     unsigned dmax;              /* maximum distance from zlib header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)     unsigned wsize;             /* window size or zero if not using window */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)     unsigned whave;             /* valid bytes in the window */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)     unsigned write;             /* window write index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)     unsigned char *window;      /* allocated sliding window, if wsize != 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)     unsigned long hold;         /* local strm->hold */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)     unsigned bits;              /* local strm->bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)     code const *lcode;          /* local strm->lencode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)     code const *dcode;          /* local strm->distcode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)     unsigned lmask;             /* mask for first level of length codes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)     unsigned dmask;             /* mask for first level of distance codes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)     code this;                  /* retrieved table entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)     unsigned op;                /* code bits, operation, extra bits, or */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90)                                 /*  window position, window bytes to copy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)     unsigned len;               /* match length, unused bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92)     unsigned dist;              /* match distance */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)     unsigned char *from;        /* where to copy match from */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)     /* copy state to local variables */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)     state = (struct inflate_state *)strm->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)     in = strm->next_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)     last = in + (strm->avail_in - 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)     out = strm->next_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)     beg = out - (start - strm->avail_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)     end = out + (strm->avail_out - 257);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #ifdef INFLATE_STRICT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)     dmax = state->dmax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)     wsize = state->wsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)     whave = state->whave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)     write = state->write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)     window = state->window;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)     hold = state->hold;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)     bits = state->bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)     lcode = state->lencode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)     dcode = state->distcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)     lmask = (1U << state->lenbits) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)     dmask = (1U << state->distbits) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)     /* decode literals and length/distances until end-of-block or not enough
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)        input data or output space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)     do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)         if (bits < 15) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)             hold += (unsigned long)(*in++) << bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)             bits += 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)             hold += (unsigned long)(*in++) << bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)             bits += 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)         this = lcode[hold & lmask];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)       dolen:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)         op = (unsigned)(this.bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)         hold >>= op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)         bits -= op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)         op = (unsigned)(this.op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)         if (op == 0) {                          /* literal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)             *out++ = (unsigned char)(this.val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)         else if (op & 16) {                     /* length base */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)             len = (unsigned)(this.val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)             op &= 15;                           /* number of extra bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)             if (op) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)                 if (bits < op) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)                     hold += (unsigned long)(*in++) << bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)                     bits += 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)                 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)                 len += (unsigned)hold & ((1U << op) - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)                 hold >>= op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)                 bits -= op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)             if (bits < 15) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)                 hold += (unsigned long)(*in++) << bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)                 bits += 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)                 hold += (unsigned long)(*in++) << bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)                 bits += 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)             this = dcode[hold & dmask];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)           dodist:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)             op = (unsigned)(this.bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)             hold >>= op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)             bits -= op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)             op = (unsigned)(this.op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)             if (op & 16) {                      /* distance base */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)                 dist = (unsigned)(this.val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)                 op &= 15;                       /* number of extra bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)                 if (bits < op) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)                     hold += (unsigned long)(*in++) << bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)                     bits += 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)                     if (bits < op) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)                         hold += (unsigned long)(*in++) << bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)                         bits += 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)                     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)                 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)                 dist += (unsigned)hold & ((1U << op) - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) #ifdef INFLATE_STRICT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)                 if (dist > dmax) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)                     strm->msg = (char *)"invalid distance too far back";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)                     state->mode = BAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)                     break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)                 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)                 hold >>= op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)                 bits -= op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)                 op = (unsigned)(out - beg);     /* max distance in output */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)                 if (dist > op) {                /* see if copy from window */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)                     op = dist - op;             /* distance back in window */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)                     if (op > whave) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)                         strm->msg = (char *)"invalid distance too far back";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)                         state->mode = BAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)                         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)                     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)                     from = window;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)                     if (write == 0) {           /* very common case */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)                         from += wsize - op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)                         if (op < len) {         /* some from window */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)                             len -= op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)                             do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)                                 *out++ = *from++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)                             } while (--op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)                             from = out - dist;  /* rest from output */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)                         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)                     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)                     else if (write < op) {      /* wrap around window */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)                         from += wsize + write - op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)                         op -= write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)                         if (op < len) {         /* some from end of window */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)                             len -= op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)                             do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)                                 *out++ = *from++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)                             } while (--op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)                             from = window;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)                             if (write < len) {  /* some from start of window */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)                                 op = write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)                                 len -= op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)                                 do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)                                     *out++ = *from++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)                                 } while (--op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)                                 from = out - dist;      /* rest from output */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)                             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)                         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)                     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)                     else {                      /* contiguous in window */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)                         from += write - op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)                         if (op < len) {         /* some from window */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)                             len -= op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)                             do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)                                 *out++ = *from++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)                             } while (--op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)                             from = out - dist;  /* rest from output */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)                         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)                     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)                     while (len > 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)                         *out++ = *from++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)                         *out++ = *from++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)                         *out++ = *from++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)                         len -= 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)                     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)                     if (len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)                         *out++ = *from++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)                         if (len > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)                             *out++ = *from++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)                     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)                 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)                 else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		    unsigned short *sout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		    unsigned long loops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)                     from = out - dist;          /* copy direct from output */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		    /* minimum length is three */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		    /* Align out addr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		    if (!((long)(out - 1) & 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 			*out++ = *from++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 			len--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		    }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		    sout = (unsigned short *)(out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		    if (dist > 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 			unsigned short *sfrom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 			sfrom = (unsigned short *)(from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 			loops = len >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 			do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 			    *sout++ = *sfrom++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 			    *sout++ = get_unaligned16(sfrom++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 			while (--loops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 			out = (unsigned char *)sout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 			from = (unsigned char *)sfrom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		    } else { /* dist == 1 or dist == 2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 			unsigned short pat16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 			pat16 = *(sout-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 			if (dist == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 				union uu mm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 				/* copy one char pattern to both bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 				mm.us = pat16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 				mm.b[0] = mm.b[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 				pat16 = mm.us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 			loops = len >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 			do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 			    *sout++ = pat16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 			while (--loops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 			out = (unsigned char *)sout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		    }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		    if (len & 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			*out++ = *from++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)                 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)             else if ((op & 64) == 0) {          /* 2nd level distance code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)                 this = dcode[this.val + (hold & ((1U << op) - 1))];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)                 goto dodist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)             else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)                 strm->msg = (char *)"invalid distance code";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)                 state->mode = BAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)                 break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)         else if ((op & 64) == 0) {              /* 2nd level length code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)             this = lcode[this.val + (hold & ((1U << op) - 1))];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)             goto dolen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)         else if (op & 32) {                     /* end-of-block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)             state->mode = TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)             break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)         else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)             strm->msg = (char *)"invalid literal/length code";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)             state->mode = BAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)             break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)     } while (in < last && out < end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)     /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)     len = bits >> 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)     in -= len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)     bits -= len << 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)     hold &= (1U << bits) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)     /* update state and return */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)     strm->next_in = in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)     strm->next_out = out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)     strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)     strm->avail_out = (unsigned)(out < end ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)                                  257 + (end - out) : 257 - (out - end));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)     state->hold = hold;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)     state->bits = bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)     return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)    inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)    - Using bit fields for code structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)    - Different op definition to avoid & for extra bits (do & for table bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)    - Three separate decoding do-loops for direct, window, and write == 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)    - Special case for distance > 1 copies to do overlapped load and store copy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)    - Explicit branch predictions (based on measured branch probabilities)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)    - Deferring match copy and interspersed it with decoding subsequent codes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)    - Swapping literal/length else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)    - Swapping window/direct else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)    - Larger unrolled copy loops (three is about right)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)    - Moving len -= 3 statement into middle of loop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) #endif /* !ASMINF */