}
ZLIB_INTERNAL void crc_fold_copy(deflate_state *const s, unsigned char *dst, const unsigned char *src, long len) {
- uintptr_t algn_diff;
+ unsigned long algn_diff;
__m128i xmm_t0, xmm_t1, xmm_t2, xmm_t3;
CRC_LOAD(s)
ZLIB_INTERNAL void fill_window_sse(deflate_state *s) {
const __m128i xmm_wsize = _mm_set1_epi16(s->w_size);
- register uint32_t n;
+ register unsigned n;
register Pos *p;
- uint32_t more; /* Amount of free space at the end of the window. */
+ unsigned more; /* Amount of free space at the end of the window. */
uInt wsize = s->w_size;
Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
do {
- more = (uint32_t)(s->window_size -(uint32_t)s->lookahead -(uint32_t)s->strstart);
+ more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
/* Deal with !@#$% 64K limit: */
if (sizeof(int) <= 2) {
* routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.
*/
if (s->high_water < s->window_size) {
- uint32_t curr = s->strstart + (uint32_t)(s->lookahead);
- uint32_t init;
+ ulg curr = s->strstart + (ulg)(s->lookahead);
+ ulg init;
if (s->high_water < curr) {
/* Previous high water mark below current data -- zero WIN_INIT
init = WIN_INIT;
memset(s->window + curr, 0, (unsigned)init);
s->high_water = curr + init;
- } else if (s->high_water < curr + WIN_INIT) {
+ } else if (s->high_water < (ulg)curr + WIN_INIT) {
/* High water mark at or above current data, but below current data
* plus WIN_INIT -- zero out to current data plus WIN_INIT, or up
* to end of window, whichever is less.
*/
- init = curr + WIN_INIT - s->high_water;
+ init = (ulg)curr + WIN_INIT - s->high_water;
if (init > s->window_size - s->high_water)
init = s->window_size - s->high_water;
memset(s->window + s->high_water, 0, (unsigned)init);
}
}
- Assert(s->strstart <= s->window_size - MIN_LOOKAHEAD, "not enough room for search");
+ Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, "not enough room for search");
}
#endif
overlay = (uint16_t *) ZALLOC(strm, s->lit_bufsize, sizeof(uint16_t)+2);
s->pending_buf = (unsigned char *) overlay;
- s->pending_buf_size = (uint32_t)s->lit_bufsize * (sizeof(uint16_t)+2L);
+ s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(uint16_t)+2L);
if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
s->pending_buf == Z_NULL) {
* Initialize the "longest match" routines for a new zlib stream
*/
local void lm_init(deflate_state *s) {
- s->window_size = (uint32_t)2L*s->w_size;
+ s->window_size = (ulg)2L*s->w_size;
CLEAR_HASH(s);
local void fill_window_c(deflate_state *s) {
register unsigned n;
register Pos *p;
- uint32_t more; /* Amount of free space at the end of the window. */
+ unsigned more; /* Amount of free space at the end of the window. */
uInt wsize = s->w_size;
Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
do {
- more = (uint32_t)(s->window_size -(uint32_t)s->lookahead -(uint32_t)s->strstart);
+ more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
/* If the window is almost full and there is insufficient lookahead,
* move the upper half to the lower one to make room in the upper half.
* routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.
*/
if (s->high_water < s->window_size) {
- uint32_t curr = s->strstart + (uint32_t)(s->lookahead);
- uint32_t init;
+ ulg curr = s->strstart + (ulg)(s->lookahead);
+ ulg init;
if (s->high_water < curr) {
/* Previous high water mark below current data -- zero WIN_INIT
init = WIN_INIT;
memset(s->window + curr, 0, (unsigned)init);
s->high_water = curr + init;
- } else if (s->high_water < curr + WIN_INIT) {
+ } else if (s->high_water < (ulg)curr + WIN_INIT) {
/* High water mark at or above current data, but below current data
* plus WIN_INIT -- zero out to current data plus WIN_INIT, or up
* to end of window, whichever is less.
*/
- init = curr + WIN_INIT - s->high_water;
+ init = (ulg)curr + WIN_INIT - s->high_water;
if (init > s->window_size - s->high_water)
init = s->window_size - s->high_water;
memset(s->window + s->high_water, 0, (unsigned)init);
}
}
- Assert(s->strstart <= s->window_size - MIN_LOOKAHEAD,
+ Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
"not enough room for search");
}
_tr_flush_block(s, (s->block_start >= 0L ? \
(char *)&s->window[(unsigned)s->block_start] : \
(char *)Z_NULL), \
- (uint16_t)((int32_t)s->strstart - s->block_start), \
+ (ulg)((long)s->strstart - s->block_start), \
(last)); \
s->block_start = s->strstart; \
flush_pending(s->strm); \
/* Stored blocks are limited to 0xffff bytes, pending_buf is limited
* to pending_buf_size, and each stored block has a 5 byte header:
*/
- uint32_t max_block_size = 0xffff;
- uint32_t max_start;
+ ulg max_block_size = 0xffff;
+ ulg max_start;
if (max_block_size > s->pending_buf_size - 5) {
max_block_size = s->pending_buf_size - 5;
/* Emit a stored block if pending_buf will be full: */
max_start = s->block_start + max_block_size;
- if (s->strstart == 0 || s->strstart >= max_start) {
+ if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
/* strstart == 0 is possible when wraparound on 16-bit machine */
s->lookahead = (uInt)(s->strstart - max_start);
s->strstart = (uInt)max_start;
*/
typedef struct internal_state {
- z_stream *strm; /* pointer back to this zlib stream */
- int status; /* as the name implies */
- unsigned char *pending_buf; /* output still pending */
- uint16_t pending_buf_size; /* size of pending_buf */
- unsigned char *pending_out; /* next pending byte to output to the stream */
- uInt pending; /* nb of bytes in the pending buffer */
- int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
- gz_headerp gzhead; /* gzip header information to write */
- uInt gzindex; /* where in extra, name, or comment */
- unsigned char method; /* can only be DEFLATED */
- int last_flush; /* value of flush param for previous deflate call */
+ z_stream *strm; /* pointer back to this zlib stream */
+ int status; /* as the name implies */
+ unsigned char *pending_buf; /* output still pending */
+ ulg pending_buf_size; /* size of pending_buf */
+ unsigned char *pending_out; /* next pending byte to output to the stream */
+ uInt pending; /* nb of bytes in the pending buffer */
+ int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
+ gz_headerp gzhead; /* gzip header information to write */
+ uInt gzindex; /* where in extra, name, or comment */
+ unsigned char method; /* can only be DEFLATED */
+ int last_flush; /* value of flush param for previous deflate call */
#ifdef X86_PCLMULQDQ_CRC
unsigned __attribute__((aligned(16))) crc0[4 * 5];
* To do: use the user input buffer as sliding window.
*/
- uint32_t window_size;
+ ulg window_size;
/* Actual size of window: 2*wSize, except when the user input buffer
* is directly used as sliding window.
*/
* array would be necessary.
*/
- uint32_t opt_len; /* bit length of current block with optimal trees */
- uint32_t static_len; /* bit length of current block with static trees */
- uInt matches; /* number of string matches in current block */
- uInt insert; /* bytes at end of window left to insert */
+ ulg opt_len; /* bit length of current block with optimal trees */
+ ulg static_len; /* bit length of current block with static trees */
+ uInt matches; /* number of string matches in current block */
+ uInt insert; /* bytes at end of window left to insert */
#ifdef DEBUG
- uint32_t compressed_len; /* total bit length of compressed file mod 2^32 */
- uint32_t bits_sent; /* bit length of compressed data sent mod 2^32 */
+ ulg compressed_len; /* total bit length of compressed file mod 2^32 */
+ ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
#endif
uint16_t bi_buf;
* are always zero.
*/
- uint32_t high_water;
+ ulg high_water;
/* High water mark offset in window for initialized bytes -- bytes above
* this are set to zero in order to avoid memory check warnings when
* longest match routines access bytes past the input. This is then
/* in trees.c */
void ZLIB_INTERNAL _tr_init(deflate_state *s);
int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc);
-void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, char *buf, uint16_t stored_len, int last);
+void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, char *buf, ulg stored_len, int last);
void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s);
void ZLIB_INTERNAL _tr_align(deflate_state *s);
-void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, char *buf, uint16_t stored_len, int last);
+void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, char *buf, ulg stored_len, int last);
void ZLIB_INTERNAL bi_windup(deflate_state *s);
#define d_code(dist) ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
local void send_bits(deflate_state *s, int value, int length) {
Tracevv((stderr, " l %2d v %4x ", length, value));
Assert(length > 0 && length <= 15, "invalid length");
- s->bits_sent += (uint32_t)length;
+ s->bits_sent += (ulg)length;
/* If not enough room in bi_buf, use (valid) bits from bi_buf and
* (16 - bi_valid) bits from value, leaving (width - (16-bi_valid))
do { \
PULL(); \
have--; \
- hold += (uint32_t)(*next++) << bits; \
+ hold += (unsigned long)(*next++) << bits; \
bits += 8; \
} while (0)
*/
int ZEXPORT inflateBack(z_stream *strm, in_func in, void *in_desc, out_func out, void *out_desc) {
struct inflate_state *state;
- const unsigned char *next; /* next input */
- unsigned char *put; /* next output */
+ const unsigned char *next; /* next input */
+ unsigned char *put; /* next output */
unsigned have, left; /* available input and output */
- uint32_t hold; /* bit buffer */
+ unsigned long hold; /* bit buffer */
unsigned bits; /* bits in bit buffer */
unsigned copy; /* number of stored or match bytes to copy */
- unsigned char *from; /* where to copy match bytes from */
+ unsigned char *from; /* where to copy match bytes from */
code here; /* current decoding table entry */
code last; /* parent table entry */
unsigned len; /* length to copy for repeats, bits to drop */
void ZLIB_INTERNAL inflate_fast(z_stream *strm, unsigned start) {
/* start: inflate()'s starting value for strm->avail_out */
struct inflate_state *state;
- const unsigned char *in; /* local strm->next_in */
- const unsigned char *last; /* have enough input while in < last */
- unsigned char *out; /* local strm->next_out */
- unsigned char *beg; /* inflate()'s initial strm->next_out */
- unsigned char *end; /* while out < end, enough space available */
+ const unsigned char *in; /* local strm->next_in */
+ const unsigned char *last; /* have enough input while in < last */
+ unsigned char *out; /* local strm->next_out */
+ unsigned char *beg; /* inflate()'s initial strm->next_out */
+ unsigned char *end; /* while out < end, enough space available */
#ifdef INFLATE_STRICT
unsigned dmax; /* maximum distance from zlib header */
#endif
unsigned wsize; /* window size or zero if not using window */
unsigned whave; /* valid bytes in the window */
unsigned wnext; /* window write index */
- unsigned char *window; /* allocated sliding window, if wsize != 0 */
- uint32_t hold; /* local strm->hold */
+ unsigned char *window; /* allocated sliding window, if wsize != 0 */
+ unsigned long hold; /* local strm->hold */
unsigned bits; /* local strm->bits */
- code const *lcode; /* local strm->lencode */
- code const *dcode; /* local strm->distcode */
+ code const *lcode; /* local strm->lencode */
+ code const *dcode; /* local strm->distcode */
unsigned lmask; /* mask for first level of length codes */
unsigned dmask; /* mask for first level of distance codes */
code here; /* retrieved table entry */
input data or output space */
do {
if (bits < 15) {
- hold += (uint32_t)(PUP(in)) << bits;
+ hold += (unsigned long)(PUP(in)) << bits;
bits += 8;
- hold += (uint32_t)(PUP(in)) << bits;
+ hold += (unsigned long)(PUP(in)) << bits;
bits += 8;
}
here = lcode[hold & lmask];
op &= 15; /* number of extra bits */
if (op) {
if (bits < op) {
- hold += (uint32_t)(PUP(in)) << bits;
+ hold += (unsigned long)(PUP(in)) << bits;
bits += 8;
}
len += BITS(op);
}
Tracevv((stderr, "inflate: length %u\n", len));
if (bits < 15) {
- hold += (uint32_t)(PUP(in)) << bits;
+ hold += (unsigned long)(PUP(in)) << bits;
bits += 8;
- hold += (uint32_t)(PUP(in)) << bits;
+ hold += (unsigned long)(PUP(in)) << bits;
bits += 8;
}
here = dcode[hold & dmask];
dist = (unsigned)(here.val);
op &= 15; /* number of extra bits */
if (bits < op) {
- hold += (uint32_t)(PUP(in)) << bits;
+ hold += (unsigned long)(PUP(in)) << bits;
bits += 8;
if (bits < op) {
- hold += (uint32_t)(PUP(in)) << bits;
+ hold += (unsigned long)(PUP(in)) << bits;
bits += 8;
}
}
do { \
if (have == 0) goto inf_leave; \
have--; \
- hold += (uint32_t)(*next++) << bits; \
+ hold += (unsigned long)(*next++) << bits; \
bits += 8; \
} while (0)
int ZEXPORT inflate(z_stream *strm, int flush) {
struct inflate_state *state;
const unsigned char *next; /* next input */
- unsigned char *put; /* next output */
+ unsigned char *put; /* next output */
unsigned have, left; /* available input and output */
- uint32_t hold; /* bit buffer */
+ unsigned long hold; /* bit buffer */
unsigned bits; /* bits in bit buffer */
unsigned in, out; /* save starting available input and output */
unsigned copy; /* number of stored or match bytes to copy */
- unsigned char *from; /* where to copy match bytes from */
+ unsigned char *from; /* where to copy match bytes from */
code here; /* current decoding table entry */
code last; /* parent table entry */
unsigned len; /* length to copy for repeats, bits to drop */
int ZEXPORT inflateSetDictionary(z_stream *strm, const unsigned char *dictionary, uInt dictLength) {
struct inflate_state *state;
- uint32_t dictid;
+ unsigned long dictid;
int ret;
/* check state */
int ZEXPORT inflateSync(z_stream *strm) {
unsigned len; /* number of bytes to look at or looked at */
- size_t in, out; /* temporary to save total_in and total_out */
+ unsigned long in, out; /* temporary to save total_in and total_out */
unsigned char buf[4]; /* to restore bit buffer to byte string */
struct inflate_state *state;
int havedict; /* true if dictionary provided */
int flags; /* gzip header method and flags (0 if zlib) */
unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
- size_t check; /* protected copy of check value */
- size_t total; /* protected copy of output count */
+ unsigned long check; /* protected copy of check value */
+ unsigned long total; /* protected copy of output count */
gz_headerp head; /* where to save gzip header information */
/* sliding window */
unsigned wbits; /* log base 2 of requested window size */
unsigned wnext; /* window write index */
unsigned char *window; /* allocated sliding window, if needed */
/* bit accumulator */
- uint32_t hold; /* input bit accumulator */
+ unsigned long hold; /* input bit accumulator */
unsigned bits; /* number of bits in "in" */
/* for string and stored block copying */
unsigned length; /* literal or length of data to copy */
scan_end1 = scan[best_len-1];
scan_end = scan[best_len];
- Assert((size_t)s->strstart <= s->window_size - MIN_LOOKAHEAD, "need lookahead");
+ Assert((unsigned long)s->strstart <= s->window_size - MIN_LOOKAHEAD, "need lookahead");
do {
Assert(cur_match < s->strstart, "no future");
match = s->window + cur_match;
scan_start = *(uint16_t *)scan;
scan_end = *(uint16_t *)(scan + best_len-1);
- Assert((size_t)s->strstart <= s->window_size - MIN_LOOKAHEAD, "need lookahead");
+ Assert((unsigned long)s->strstart <= s->window_size - MIN_LOOKAHEAD, "need lookahead");
do {
unsigned char *match;
Assert(cur_match < s->strstart, "no future");
*/
if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
- Assert((size_t)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
+ Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
do {
Assert(cur_match < s->strstart, "no future");
scan += 2, match+=2;
Assert(*scan == *match, "match[2]?");
do {
- uintptr_t sv = *(uintptr_t*)(void*)scan;
- uintptr_t mv = *(uintptr_t*)(void*)match;
- uintptr_t xor = sv ^ mv;
+ unsigned long sv = *(unsigned long*)(void*)scan;
+ unsigned long mv = *(unsigned long*)(void*)match;
+ unsigned long xor = sv ^ mv;
if (xor) {
int match_byte = __builtin_ctzl(xor) / 8;
scan += match_byte;
match += match_byte;
break;
} else {
- scan += sizeof(uintptr_t);
- match += sizeof(uintptr_t);
+ scan += sizeof(unsigned long);
+ match += sizeof(unsigned long);
}
} while (scan < strend);
local int detect_data_type (deflate_state *s);
local unsigned bi_reverse (unsigned value, int length);
local void bi_flush (deflate_state *s);
-local void copy_block (deflate_state *s, char *buf, uint16_t len, int header);
+local void copy_block (deflate_state *s, char *buf, unsigned len, int header);
#ifdef GEN_TREES_H
local void gen_trees_header(void);
if (n >= base)
xbits = extra[n-base];
f = tree[n].Freq;
- s->opt_len += (size_t)f * (bits + xbits);
+ s->opt_len += (ulg)f * (bits + xbits);
if (stree)
- s->static_len += (size_t)f * (stree[n].Len + xbits);
+ s->static_len += (ulg)f * (stree[n].Len + xbits);
}
if (overflow == 0)
return;
/* ===========================================================================
* Send a stored block
*/
-void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, char *buf, uint16_t stored_len, int last) {
+void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, char *buf, ulg stored_len, int last) {
/* buf: input block */
/* stored_len: length of input block */
/* last: one if this is the last block for a file */
send_bits(s, (STORED_BLOCK << 1)+last, 3); /* send block type */
#ifdef DEBUG
- s->compressed_len = (s->compressed_len + 3 + 7) & (uint32_t)~7L;
+ s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
s->compressed_len += (stored_len + 4) << 3;
#endif
- copy_block(s, buf, stored_len, 1); /* with header */
+ copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
}
/* ===========================================================================
* Determine the best encoding for the current block: dynamic trees, static
* trees or store, and output the encoded block to the zip file.
*/
-void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, char *buf, uint16_t stored_len, int last) {
+void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, char *buf, ulg stored_len, int last) {
/* buf: input block, or NULL if too old */
/* stored_len: length of input block */
/* last: one if this is the last block for a file */
- uint16_t opt_lenb, static_lenb; /* opt_len and static_len in bytes */
+ ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
int max_blindex = 0; /* index of last bit length code of non zero freq */
/* Build the Huffman trees unless a stored block is forced */
/* Try to guess if it is profitable to stop the current block here */
if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
/* Compute an upper bound for the compressed length */
- size_t out_length = (size_t)s->last_lit*8L;
- size_t in_length = (size_t)((long)s->strstart - s->block_start);
+ ulg out_length = (ulg)s->last_lit*8L;
+ ulg in_length = (ulg)((long)s->strstart - s->block_start);
int dcode;
for (dcode = 0; dcode < D_CODES; dcode++) {
- out_length += (size_t)s->dyn_dtree[dcode].Freq * (5L+extra_dbits[dcode]);
+ out_length += (ulg)s->dyn_dtree[dcode].Freq * (5L+extra_dbits[dcode]);
}
out_length >>= 3;
Tracev((stderr, "\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
* set bits 0..6, 14..25, and 28..31
* 0xf3ffc07f = binary 11110011111111111100000001111111
*/
- uint32_t black_mask = 0xf3ffc07fUL;
+ unsigned long black_mask = 0xf3ffc07fUL;
int n;
/* Check for non-textual ("black-listed") bytes. */
* Copy a stored block, storing first the length and its
* one's complement if requested.
*/
-local void copy_block(deflate_state *s, char *buf, uint16_t len, int header) {
+local void copy_block(deflate_state *s, char *buf, unsigned len, int header) {
/* buf: the input data */
/* len: its length */
/* header: true if block header must be written */
#endif
}
#ifdef DEBUG
- s->bits_sent += (uint32_t)len << 3;
+ s->bits_sent += (ulg)len << 3;
#endif
while (len--) {
put_byte(s, *buf++);