| OLD | NEW |
| 1 /* deflate.c -- compress data using the deflation algorithm | 1 /* deflate.c -- compress data using the deflation algorithm |
| 2 * Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler | 2 * Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler |
| 3 * For conditions of distribution and use, see copyright notice in zlib.h | 3 * For conditions of distribution and use, see copyright notice in zlib.h |
| 4 */ | 4 */ |
| 5 | 5 |
| 6 /* | 6 /* |
| 7 * ALGORITHM | 7 * ALGORITHM |
| 8 * | 8 * |
| 9 * The "deflation" process depends on being able to identify portions | 9 * The "deflation" process depends on being able to identify portions |
| 10 * of the input text which are identical to earlier input (within a | 10 * of the input text which are identical to earlier input (within a |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 * "Algorithms" by R. Sedgewick, Addison-Wesley, p252. | 43 * "Algorithms" by R. Sedgewick, Addison-Wesley, p252. |
| 44 * | 44 * |
| 45 * Fiala,E.R., and Greene,D.H. | 45 * Fiala,E.R., and Greene,D.H. |
| 46 * Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595 | 46 * Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595 |
| 47 * | 47 * |
| 48 */ | 48 */ |
| 49 | 49 |
| 50 /* @(#) $Id$ */ | 50 /* @(#) $Id$ */ |
| 51 | 51 |
| 52 #include "deflate.h" | 52 #include "deflate.h" |
| 53 #include "x86.h" |
| 53 | 54 |
| 54 const char deflate_copyright[] = | 55 const char deflate_copyright[] = |
| 55 " deflate 1.2.5 Copyright 1995-2010 Jean-loup Gailly and Mark Adler "; | 56 " deflate 1.2.5 Copyright 1995-2010 Jean-loup Gailly and Mark Adler "; |
| 56 /* | 57 /* |
| 57 If you use the zlib library in a product, an acknowledgment is welcome | 58 If you use the zlib library in a product, an acknowledgment is welcome |
| 58 in the documentation of your product. If for some reason you cannot | 59 in the documentation of your product. If for some reason you cannot |
| 59 include such an acknowledgment, I would appreciate that you keep this | 60 include such an acknowledgment, I would appreciate that you keep this |
| 60 copyright string in the executable of your product. | 61 copyright string in the executable of your product. |
| 61 */ | 62 */ |
| 62 | 63 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 78 local block_state deflate_stored OF((deflate_state *s, int flush, int clas)); | 79 local block_state deflate_stored OF((deflate_state *s, int flush, int clas)); |
| 79 local block_state deflate_fast OF((deflate_state *s, int flush, int clas)); | 80 local block_state deflate_fast OF((deflate_state *s, int flush, int clas)); |
| 80 #ifndef FASTEST | 81 #ifndef FASTEST |
| 81 local block_state deflate_slow OF((deflate_state *s, int flush, int clas)); | 82 local block_state deflate_slow OF((deflate_state *s, int flush, int clas)); |
| 82 #endif | 83 #endif |
| 83 local block_state deflate_rle OF((deflate_state *s, int flush)); | 84 local block_state deflate_rle OF((deflate_state *s, int flush)); |
| 84 local block_state deflate_huff OF((deflate_state *s, int flush)); | 85 local block_state deflate_huff OF((deflate_state *s, int flush)); |
| 85 local void lm_init OF((deflate_state *s)); | 86 local void lm_init OF((deflate_state *s)); |
| 86 local void putShortMSB OF((deflate_state *s, uInt b)); | 87 local void putShortMSB OF((deflate_state *s, uInt b)); |
| 87 local void flush_pending OF((z_streamp strm)); | 88 local void flush_pending OF((z_streamp strm)); |
| 88 local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); | 89 |
| 89 #ifdef ASMV | 90 #ifdef ASMV |
| 90 void match_init OF((void)); /* asm code initialization */ | 91 void match_init OF((void)); /* asm code initialization */ |
| 91 uInt longest_match OF((deflate_state *s, IPos cur_match, int clas)); | 92 uInt longest_match OF((deflate_state *s, IPos cur_match, int clas)); |
| 92 #else | 93 #else |
| 93 local uInt longest_match OF((deflate_state *s, IPos cur_match, int clas)); | 94 local uInt longest_match OF((deflate_state *s, IPos cur_match, int clas)); |
| 94 #endif | 95 #endif |
| 95 | 96 |
| 96 #ifdef DEBUG | 97 #ifdef DEBUG |
| 97 local void check_match OF((deflate_state *s, IPos start, IPos match, | 98 local void check_match OF((deflate_state *s, IPos start, IPos match, |
| 98 int length)); | 99 int length)); |
| 99 #endif | 100 #endif |
| 100 | 101 |
| 102 /* For fill_window_sse.c to use */ |
| 103 ZLIB_INTERNAL int read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); |
| 104 |
| 105 /* From crc32.c */ |
| 106 extern void ZLIB_INTERNAL crc_reset(deflate_state *const s); |
| 107 extern void ZLIB_INTERNAL crc_finalize(deflate_state *const s); |
| 108 extern void ZLIB_INTERNAL copy_with_crc(z_streamp strm, Bytef *dst, long size); |
| 109 |
| 101 /* =========================================================================== | 110 /* =========================================================================== |
| 102 * Local data | 111 * Local data |
| 103 */ | 112 */ |
| 104 | 113 |
| 105 #define NIL 0 | 114 #define NIL 0 |
| 106 /* Tail of hash chains */ | 115 /* Tail of hash chains */ |
| 107 | 116 |
| 108 #ifndef TOO_FAR | 117 #ifndef TOO_FAR |
| 109 # define TOO_FAR 4096 | 118 # define TOO_FAR 4096 |
| 110 #endif | 119 #endif |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 #endif | 166 #endif |
| 158 | 167 |
| 159 /* =========================================================================== | 168 /* =========================================================================== |
| 160 * Update a hash value with the given input byte | 169 * Update a hash value with the given input byte |
| 161 * IN assertion: all calls to to UPDATE_HASH are made with consecutive | 170 * IN assertion: all calls to to UPDATE_HASH are made with consecutive |
| 162 * input characters, so that a running hash key can be computed from the | 171 * input characters, so that a running hash key can be computed from the |
| 163 * previous key instead of complete recalculation each time. | 172 * previous key instead of complete recalculation each time. |
| 164 */ | 173 */ |
| 165 #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask) | 174 #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask) |
| 166 | 175 |
| 176 #ifdef _MSC_VER |
| 177 #define INLINE __inline |
| 178 #else |
| 179 #define INLINE inline |
| 180 #endif |
| 167 | 181 |
| 168 /* =========================================================================== | 182 /* =========================================================================== |
| 169 * Insert string str in the dictionary and set match_head to the previous head | 183 * Insert string str in the dictionary and set match_head to the previous head |
| 170 * of the hash chain (the most recent string with same hash key). Return | 184 * of the hash chain (the most recent string with same hash key). Return |
| 171 * the previous length of the hash chain. | 185 * the previous length of the hash chain. |
| 172 * If this file is compiled with -DFASTEST, the compression level is forced | 186 * If this file is compiled with -DFASTEST, the compression level is forced |
| 173 * to 1, and no hash chains are maintained. | 187 * to 1, and no hash chains are maintained. |
| 174 * IN assertion: all calls to to INSERT_STRING are made with consecutive | 188 * IN assertion: all calls to to INSERT_STRING are made with consecutive |
| 175 * input characters and the first MIN_MATCH bytes of str are valid | 189 * input characters and the first MIN_MATCH bytes of str are valid |
| 176 * (except for the last MIN_MATCH-1 bytes of the input file). | 190 * (except for the last MIN_MATCH-1 bytes of the input file). |
| 177 */ | 191 */ |
| 192 local INLINE Pos insert_string_c(deflate_state *const s, const Pos str) |
| 193 { |
| 194 Pos ret; |
| 195 |
| 196 UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]); |
| 178 #ifdef FASTEST | 197 #ifdef FASTEST |
| 179 #define INSERT_STRING(s, str, match_head) \ | 198 ret = s->head[s->ins_h]; |
| 180 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ | |
| 181 match_head = s->head[s->ins_h], \ | |
| 182 s->head[s->ins_h] = (Pos)(str)) | |
| 183 #else | 199 #else |
| 184 #define INSERT_STRING(s, str, match_head) \ | 200 ret = s->prev[str & s->w_mask] = s->head[s->ins_h]; |
| 185 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ | |
| 186 match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \ | |
| 187 s->head[s->ins_h] = (Pos)(str)) | |
| 188 #endif | 201 #endif |
| 202 s->head[s->ins_h] = str; |
| 203 |
| 204 return ret; |
| 205 } |
| 206 |
| 207 local INLINE Pos insert_string(deflate_state *const s, const Pos str) |
| 208 { |
| 209 if (x86_cpu_enable_simd) |
| 210 return insert_string_sse(s, str); |
| 211 return insert_string_c(s, str); |
| 212 } |
| 213 |
| 189 | 214 |
| 190 /* =========================================================================== | 215 /* =========================================================================== |
| 191 * Initialize the hash table (avoiding 64K overflow for 16 bit systems). | 216 * Initialize the hash table (avoiding 64K overflow for 16 bit systems). |
| 192 * prev[] will be initialized on the fly. | 217 * prev[] will be initialized on the fly. |
| 193 */ | 218 */ |
| 194 #define CLEAR_HASH(s) \ | 219 #define CLEAR_HASH(s) \ |
| 195 s->head[s->hash_size-1] = NIL; \ | 220 s->head[s->hash_size-1] = NIL; \ |
| 196 zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head)); | 221 zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head)); |
| 197 | 222 |
| 198 /* ========================================================================= */ | 223 /* ========================================================================= */ |
| (...skipping 13 matching lines...) Expand all Loading... |
| 212 version, stream_size) | 237 version, stream_size) |
| 213 z_streamp strm; | 238 z_streamp strm; |
| 214 int level; | 239 int level; |
| 215 int method; | 240 int method; |
| 216 int windowBits; | 241 int windowBits; |
| 217 int memLevel; | 242 int memLevel; |
| 218 int strategy; | 243 int strategy; |
| 219 const char *version; | 244 const char *version; |
| 220 int stream_size; | 245 int stream_size; |
| 221 { | 246 { |
| 247 unsigned window_padding = 8; |
| 222 deflate_state *s; | 248 deflate_state *s; |
| 223 int wrap = 1; | 249 int wrap = 1; |
| 224 static const char my_version[] = ZLIB_VERSION; | 250 static const char my_version[] = ZLIB_VERSION; |
| 225 | 251 |
| 226 ushf *overlay; | 252 ushf *overlay; |
| 227 /* We overlay pending_buf and d_buf+l_buf. This works since the average | 253 /* We overlay pending_buf and d_buf+l_buf. This works since the average |
| 228 * output size for (length,distance) codes is <= 24 bits. | 254 * output size for (length,distance) codes is <= 24 bits. |
| 229 */ | 255 */ |
| 230 | 256 |
| 257 x86_check_features(); |
| 258 |
| 231 if (version == Z_NULL || version[0] != my_version[0] || | 259 if (version == Z_NULL || version[0] != my_version[0] || |
| 232 stream_size != sizeof(z_stream)) { | 260 stream_size != sizeof(z_stream)) { |
| 233 return Z_VERSION_ERROR; | 261 return Z_VERSION_ERROR; |
| 234 } | 262 } |
| 235 if (strm == Z_NULL) return Z_STREAM_ERROR; | 263 if (strm == Z_NULL) return Z_STREAM_ERROR; |
| 236 | 264 |
| 237 strm->msg = Z_NULL; | 265 strm->msg = Z_NULL; |
| 238 if (strm->zalloc == (alloc_func)0) { | 266 if (strm->zalloc == (alloc_func)0) { |
| 239 strm->zalloc = zcalloc; | 267 strm->zalloc = zcalloc; |
| 240 strm->opaque = (voidpf)0; | 268 strm->opaque = (voidpf)0; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 267 if (s == Z_NULL) return Z_MEM_ERROR; | 295 if (s == Z_NULL) return Z_MEM_ERROR; |
| 268 strm->state = (struct internal_state FAR *)s; | 296 strm->state = (struct internal_state FAR *)s; |
| 269 s->strm = strm; | 297 s->strm = strm; |
| 270 | 298 |
| 271 s->wrap = wrap; | 299 s->wrap = wrap; |
| 272 s->gzhead = Z_NULL; | 300 s->gzhead = Z_NULL; |
| 273 s->w_bits = windowBits; | 301 s->w_bits = windowBits; |
| 274 s->w_size = 1 << s->w_bits; | 302 s->w_size = 1 << s->w_bits; |
| 275 s->w_mask = s->w_size - 1; | 303 s->w_mask = s->w_size - 1; |
| 276 | 304 |
| 277 s->hash_bits = memLevel + 7; | 305 if (x86_cpu_enable_simd) { |
| 306 s->hash_bits = 15; |
| 307 } else { |
| 308 s->hash_bits = memLevel + 7; |
| 309 } |
| 310 |
| 278 s->hash_size = 1 << s->hash_bits; | 311 s->hash_size = 1 << s->hash_bits; |
| 279 s->hash_mask = s->hash_size - 1; | 312 s->hash_mask = s->hash_size - 1; |
| 280 s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH); | 313 s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH); |
| 281 | 314 |
| 282 s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte)); | 315 s->window = (Bytef *) ZALLOC(strm, s->w_size + window_padding, 2*sizeof(Byte
)); |
| 283 s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos)); | 316 s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos)); |
| 284 s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos)); | 317 s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos)); |
| 285 s->class_bitmap = NULL; | 318 s->class_bitmap = NULL; |
| 286 zmemzero(&s->cookie_locations, sizeof(s->cookie_locations)); | 319 zmemzero(&s->cookie_locations, sizeof(s->cookie_locations)); |
| 287 strm->clas = 0; | 320 strm->clas = 0; |
| 288 | 321 |
| 289 s->high_water = 0; /* nothing written to s->window yet */ | 322 s->high_water = 0; /* nothing written to s->window yet */ |
| 290 | 323 |
| 291 s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ | 324 s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ |
| 292 | 325 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 s->strstart = length; | 373 s->strstart = length; |
| 341 s->block_start = (long)length; | 374 s->block_start = (long)length; |
| 342 | 375 |
| 343 /* Insert all strings in the hash table (except for the last two bytes). | 376 /* Insert all strings in the hash table (except for the last two bytes). |
| 344 * s->lookahead stays null, so s->ins_h will be recomputed at the next | 377 * s->lookahead stays null, so s->ins_h will be recomputed at the next |
| 345 * call of fill_window. | 378 * call of fill_window. |
| 346 */ | 379 */ |
| 347 s->ins_h = s->window[0]; | 380 s->ins_h = s->window[0]; |
| 348 UPDATE_HASH(s, s->ins_h, s->window[1]); | 381 UPDATE_HASH(s, s->ins_h, s->window[1]); |
| 349 for (n = 0; n <= length - MIN_MATCH; n++) { | 382 for (n = 0; n <= length - MIN_MATCH; n++) { |
| 350 INSERT_STRING(s, n, hash_head); | 383 insert_string(s, n); |
| 351 } | 384 } |
| 352 if (hash_head) hash_head = 0; /* to make compiler happy */ | 385 if (hash_head) hash_head = 0; /* to make compiler happy */ |
| 353 return Z_OK; | 386 return Z_OK; |
| 354 } | 387 } |
| 355 | 388 |
| 356 /* ========================================================================= */ | 389 /* ========================================================================= */ |
| 357 int ZEXPORT deflateReset (strm) | 390 int ZEXPORT deflateReset (strm) |
| 358 z_streamp strm; | 391 z_streamp strm; |
| 359 { | 392 { |
| 360 deflate_state *s; | 393 deflate_state *s; |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR); | 639 if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR); |
| 607 | 640 |
| 608 s->strm = strm; /* just in case */ | 641 s->strm = strm; /* just in case */ |
| 609 old_flush = s->last_flush; | 642 old_flush = s->last_flush; |
| 610 s->last_flush = flush; | 643 s->last_flush = flush; |
| 611 | 644 |
| 612 /* Write the header */ | 645 /* Write the header */ |
| 613 if (s->status == INIT_STATE) { | 646 if (s->status == INIT_STATE) { |
| 614 #ifdef GZIP | 647 #ifdef GZIP |
| 615 if (s->wrap == 2) { | 648 if (s->wrap == 2) { |
| 616 strm->adler = crc32(0L, Z_NULL, 0); | 649 crc_reset(s); |
| 617 put_byte(s, 31); | 650 put_byte(s, 31); |
| 618 put_byte(s, 139); | 651 put_byte(s, 139); |
| 619 put_byte(s, 8); | 652 put_byte(s, 8); |
| 620 if (s->gzhead == Z_NULL) { | 653 if (s->gzhead == Z_NULL) { |
| 621 put_byte(s, 0); | 654 put_byte(s, 0); |
| 622 put_byte(s, 0); | 655 put_byte(s, 0); |
| 623 put_byte(s, 0); | 656 put_byte(s, 0); |
| 624 put_byte(s, 0); | 657 put_byte(s, 0); |
| 625 put_byte(s, 0); | 658 put_byte(s, 0); |
| 626 put_byte(s, s->level == 9 ? 2 : | 659 put_byte(s, s->level == 9 ? 2 : |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 } | 917 } |
| 885 } | 918 } |
| 886 Assert(strm->avail_out > 0, "bug2"); | 919 Assert(strm->avail_out > 0, "bug2"); |
| 887 | 920 |
| 888 if (flush != Z_FINISH) return Z_OK; | 921 if (flush != Z_FINISH) return Z_OK; |
| 889 if (s->wrap <= 0) return Z_STREAM_END; | 922 if (s->wrap <= 0) return Z_STREAM_END; |
| 890 | 923 |
| 891 /* Write the trailer */ | 924 /* Write the trailer */ |
| 892 #ifdef GZIP | 925 #ifdef GZIP |
| 893 if (s->wrap == 2) { | 926 if (s->wrap == 2) { |
| 927 crc_finalize(s); |
| 894 put_byte(s, (Byte)(strm->adler & 0xff)); | 928 put_byte(s, (Byte)(strm->adler & 0xff)); |
| 895 put_byte(s, (Byte)((strm->adler >> 8) & 0xff)); | 929 put_byte(s, (Byte)((strm->adler >> 8) & 0xff)); |
| 896 put_byte(s, (Byte)((strm->adler >> 16) & 0xff)); | 930 put_byte(s, (Byte)((strm->adler >> 16) & 0xff)); |
| 897 put_byte(s, (Byte)((strm->adler >> 24) & 0xff)); | 931 put_byte(s, (Byte)((strm->adler >> 24) & 0xff)); |
| 898 put_byte(s, (Byte)(strm->total_in & 0xff)); | 932 put_byte(s, (Byte)(strm->total_in & 0xff)); |
| 899 put_byte(s, (Byte)((strm->total_in >> 8) & 0xff)); | 933 put_byte(s, (Byte)((strm->total_in >> 8) & 0xff)); |
| 900 put_byte(s, (Byte)((strm->total_in >> 16) & 0xff)); | 934 put_byte(s, (Byte)((strm->total_in >> 16) & 0xff)); |
| 901 put_byte(s, (Byte)((strm->total_in >> 24) & 0xff)); | 935 put_byte(s, (Byte)((strm->total_in >> 24) & 0xff)); |
| 902 } | 936 } |
| 903 else | 937 else |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1006 #endif /* MAXSEG_64K */ | 1040 #endif /* MAXSEG_64K */ |
| 1007 } | 1041 } |
| 1008 | 1042 |
| 1009 /* =========================================================================== | 1043 /* =========================================================================== |
| 1010 * Read a new buffer from the current input stream, update the adler32 | 1044 * Read a new buffer from the current input stream, update the adler32 |
| 1011 * and total number of bytes read. All deflate() input goes through | 1045 * and total number of bytes read. All deflate() input goes through |
| 1012 * this function so some applications may wish to modify it to avoid | 1046 * this function so some applications may wish to modify it to avoid |
| 1013 * allocating a large strm->next_in buffer and copying from it. | 1047 * allocating a large strm->next_in buffer and copying from it. |
| 1014 * (See also flush_pending()). | 1048 * (See also flush_pending()). |
| 1015 */ | 1049 */ |
| 1016 local int read_buf(strm, buf, size) | 1050 ZLIB_INTERNAL int read_buf(strm, buf, size) |
| 1017 z_streamp strm; | 1051 z_streamp strm; |
| 1018 Bytef *buf; | 1052 Bytef *buf; |
| 1019 unsigned size; | 1053 unsigned size; |
| 1020 { | 1054 { |
| 1021 unsigned len = strm->avail_in; | 1055 unsigned len = strm->avail_in; |
| 1022 | 1056 |
| 1023 if (len > size) len = size; | 1057 if (len > size) len = size; |
| 1024 if (len == 0) return 0; | 1058 if (len == 0) return 0; |
| 1025 | 1059 |
| 1026 strm->avail_in -= len; | 1060 strm->avail_in -= len; |
| 1027 | 1061 |
| 1028 if (strm->state->wrap == 1) { | 1062 #ifdef GZIP |
| 1029 strm->adler = adler32(strm->adler, strm->next_in, len); | 1063 if (strm->state->wrap == 2) { |
| 1064 copy_with_crc(strm, buf, len); |
| 1030 } | 1065 } |
| 1031 #ifdef GZIP | 1066 else |
| 1032 else if (strm->state->wrap == 2) { | 1067 #endif |
| 1033 strm->adler = crc32(strm->adler, strm->next_in, len); | 1068 { |
| 1069 zmemcpy(buf, strm->next_in, len); |
| 1070 if (strm->state->wrap == 1) |
| 1071 strm->adler = adler32(strm->adler, buf, len); |
| 1034 } | 1072 } |
| 1035 #endif | |
| 1036 zmemcpy(buf, strm->next_in, len); | |
| 1037 strm->next_in += len; | 1073 strm->next_in += len; |
| 1038 strm->total_in += len; | 1074 strm->total_in += len; |
| 1039 | 1075 |
| 1040 return (int)len; | 1076 return (int)len; |
| 1041 } | 1077 } |
| 1042 | 1078 |
| 1043 /* =========================================================================== | 1079 /* =========================================================================== |
| 1044 * Initialize the "longest match" routines for a new zlib stream | 1080 * Initialize the "longest match" routines for a new zlib stream |
| 1045 */ | 1081 */ |
| 1046 local void lm_init (s) | 1082 local void lm_init (s) |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1438 /* =========================================================================== | 1474 /* =========================================================================== |
| 1439 * Fill the window when the lookahead becomes insufficient. | 1475 * Fill the window when the lookahead becomes insufficient. |
| 1440 * Updates strstart and lookahead. | 1476 * Updates strstart and lookahead. |
| 1441 * | 1477 * |
| 1442 * IN assertion: lookahead < MIN_LOOKAHEAD | 1478 * IN assertion: lookahead < MIN_LOOKAHEAD |
| 1443 * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD | 1479 * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD |
| 1444 * At least one byte has been read, or avail_in == 0; reads are | 1480 * At least one byte has been read, or avail_in == 0; reads are |
| 1445 * performed for at least two bytes (required for the zip translate_eol | 1481 * performed for at least two bytes (required for the zip translate_eol |
| 1446 * option -- not supported here). | 1482 * option -- not supported here). |
| 1447 */ | 1483 */ |
| 1448 local void fill_window(s) | 1484 local void fill_window_c(deflate_state *s); |
| 1485 |
| 1486 local void fill_window(deflate_state *s) |
| 1487 { |
| 1488 if (x86_cpu_enable_simd) { |
| 1489 fill_window_sse(s); |
| 1490 return; |
| 1491 } |
| 1492 |
| 1493 fill_window_c(s); |
| 1494 } |
| 1495 |
| 1496 local void fill_window_c(s) |
| 1449 deflate_state *s; | 1497 deflate_state *s; |
| 1450 { | 1498 { |
| 1451 register unsigned n, m; | 1499 register unsigned n, m; |
| 1452 register Posf *p; | 1500 register Posf *p; |
| 1453 unsigned more; /* Amount of free space at the end of the window. */ | 1501 unsigned more; /* Amount of free space at the end of the window. */ |
| 1454 uInt wsize = s->w_size; | 1502 uInt wsize = s->w_size; |
| 1455 | 1503 |
| 1456 do { | 1504 do { |
| 1457 more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); | 1505 more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); |
| 1458 | 1506 |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1704 return need_more; | 1752 return need_more; |
| 1705 } | 1753 } |
| 1706 if (s->lookahead == 0) break; /* flush the current block */ | 1754 if (s->lookahead == 0) break; /* flush the current block */ |
| 1707 } | 1755 } |
| 1708 | 1756 |
| 1709 /* Insert the string window[strstart .. strstart+2] in the | 1757 /* Insert the string window[strstart .. strstart+2] in the |
| 1710 * dictionary, and set hash_head to the head of the hash chain: | 1758 * dictionary, and set hash_head to the head of the hash chain: |
| 1711 */ | 1759 */ |
| 1712 hash_head = NIL; | 1760 hash_head = NIL; |
| 1713 if (s->lookahead >= MIN_MATCH) { | 1761 if (s->lookahead >= MIN_MATCH) { |
| 1714 INSERT_STRING(s, s->strstart, hash_head); | 1762 hash_head = insert_string(s, s->strstart); |
| 1715 } | 1763 } |
| 1716 | 1764 |
| 1717 /* Find the longest match, discarding those <= prev_length. | 1765 /* Find the longest match, discarding those <= prev_length. |
| 1718 * At this point we have always match_length < MIN_MATCH | 1766 * At this point we have always match_length < MIN_MATCH |
| 1719 */ | 1767 */ |
| 1720 if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) { | 1768 if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) { |
| 1721 /* To simplify the code, we prevent matches with the string | 1769 /* To simplify the code, we prevent matches with the string |
| 1722 * of window index 0 (in particular we have to avoid a match | 1770 * of window index 0 (in particular we have to avoid a match |
| 1723 * of the string with itself at the start of the input file). | 1771 * of the string with itself at the start of the input file). |
| 1724 */ | 1772 */ |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1735 | 1783 |
| 1736 /* Insert new strings in the hash table only if the match length | 1784 /* Insert new strings in the hash table only if the match length |
| 1737 * is not too large. This saves time but degrades compression. | 1785 * is not too large. This saves time but degrades compression. |
| 1738 */ | 1786 */ |
| 1739 #ifndef FASTEST | 1787 #ifndef FASTEST |
| 1740 if (s->match_length <= s->max_insert_length && | 1788 if (s->match_length <= s->max_insert_length && |
| 1741 s->lookahead >= MIN_MATCH) { | 1789 s->lookahead >= MIN_MATCH) { |
| 1742 s->match_length--; /* string at strstart already in table */ | 1790 s->match_length--; /* string at strstart already in table */ |
| 1743 do { | 1791 do { |
| 1744 s->strstart++; | 1792 s->strstart++; |
| 1745 INSERT_STRING(s, s->strstart, hash_head); | 1793 hash_head = insert_string(s, s->strstart); |
| 1746 /* strstart never exceeds WSIZE-MAX_MATCH, so there are | 1794 /* strstart never exceeds WSIZE-MAX_MATCH, so there are |
| 1747 * always MIN_MATCH bytes ahead. | 1795 * always MIN_MATCH bytes ahead. |
| 1748 */ | 1796 */ |
| 1749 } while (--s->match_length != 0); | 1797 } while (--s->match_length != 0); |
| 1750 s->strstart++; | 1798 s->strstart++; |
| 1751 } else | 1799 } else |
| 1752 #endif | 1800 #endif |
| 1753 { | 1801 { |
| 1754 s->strstart += s->match_length; | 1802 s->strstart += s->match_length; |
| 1755 s->match_length = 0; | 1803 s->match_length = 0; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1814 return need_more; | 1862 return need_more; |
| 1815 } | 1863 } |
| 1816 if (s->lookahead == 0) break; /* flush the current block */ | 1864 if (s->lookahead == 0) break; /* flush the current block */ |
| 1817 } | 1865 } |
| 1818 | 1866 |
| 1819 /* Insert the string window[strstart .. strstart+2] in the | 1867 /* Insert the string window[strstart .. strstart+2] in the |
| 1820 * dictionary, and set hash_head to the head of the hash chain: | 1868 * dictionary, and set hash_head to the head of the hash chain: |
| 1821 */ | 1869 */ |
| 1822 hash_head = NIL; | 1870 hash_head = NIL; |
| 1823 if (s->lookahead >= MIN_MATCH) { | 1871 if (s->lookahead >= MIN_MATCH) { |
| 1824 INSERT_STRING(s, s->strstart, hash_head); | 1872 hash_head = insert_string(s, s->strstart); |
| 1825 } | 1873 } |
| 1826 | 1874 |
| 1827 /* Find the longest match, discarding those <= prev_length. | 1875 /* Find the longest match, discarding those <= prev_length. |
| 1828 */ | 1876 */ |
| 1829 s->prev_length = s->match_length, s->prev_match = s->match_start; | 1877 s->prev_length = s->match_length, s->prev_match = s->match_start; |
| 1830 s->match_length = MIN_MATCH-1; | 1878 s->match_length = MIN_MATCH-1; |
| 1831 | 1879 |
| 1832 if (clas == Z_CLASS_COOKIE && first) { | 1880 if (clas == Z_CLASS_COOKIE && first) { |
| 1833 s->match_length = cookie_match(s, s->strstart, input_length); | 1881 s->match_length = cookie_match(s, s->strstart, input_length); |
| 1834 } else if (clas == Z_CLASS_STANDARD && | 1882 } else if (clas == Z_CLASS_STANDARD && |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1883 | 1931 |
| 1884 /* Insert in hash table all strings up to the end of the match. | 1932 /* Insert in hash table all strings up to the end of the match. |
| 1885 * strstart-1 and strstart are already inserted. If there is not | 1933 * strstart-1 and strstart are already inserted. If there is not |
| 1886 * enough lookahead, the last two strings are not inserted in | 1934 * enough lookahead, the last two strings are not inserted in |
| 1887 * the hash table. | 1935 * the hash table. |
| 1888 */ | 1936 */ |
| 1889 s->lookahead -= s->prev_length-1; | 1937 s->lookahead -= s->prev_length-1; |
| 1890 s->prev_length -= 2; | 1938 s->prev_length -= 2; |
| 1891 do { | 1939 do { |
| 1892 if (++s->strstart <= max_insert) { | 1940 if (++s->strstart <= max_insert) { |
| 1893 INSERT_STRING(s, s->strstart, hash_head); | 1941 hash_head = insert_string(s, s->strstart); |
| 1894 } | 1942 } |
| 1895 } while (--s->prev_length != 0); | 1943 } while (--s->prev_length != 0); |
| 1896 s->match_available = 0; | 1944 s->match_available = 0; |
| 1897 s->match_length = MIN_MATCH-1; | 1945 s->match_length = MIN_MATCH-1; |
| 1898 s->strstart++; | 1946 s->strstart++; |
| 1899 | 1947 |
| 1900 if (bflush) FLUSH_BLOCK(s, 0); | 1948 if (bflush) FLUSH_BLOCK(s, 0); |
| 1901 | 1949 |
| 1902 } else if (s->match_available) { | 1950 } else if (s->match_available) { |
| 1903 /* If there was no match at the previous position, output a | 1951 /* If there was no match at the previous position, output a |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2024 s->match_length = 0; | 2072 s->match_length = 0; |
| 2025 Tracevv((stderr,"%c", s->window[s->strstart])); | 2073 Tracevv((stderr,"%c", s->window[s->strstart])); |
| 2026 _tr_tally_lit (s, s->window[s->strstart], bflush); | 2074 _tr_tally_lit (s, s->window[s->strstart], bflush); |
| 2027 s->lookahead--; | 2075 s->lookahead--; |
| 2028 s->strstart++; | 2076 s->strstart++; |
| 2029 if (bflush) FLUSH_BLOCK(s, 0); | 2077 if (bflush) FLUSH_BLOCK(s, 0); |
| 2030 } | 2078 } |
| 2031 FLUSH_BLOCK(s, flush == Z_FINISH); | 2079 FLUSH_BLOCK(s, flush == Z_FINISH); |
| 2032 return flush == Z_FINISH ? finish_done : block_done; | 2080 return flush == Z_FINISH ? finish_done : block_done; |
| 2033 } | 2081 } |
| OLD | NEW |