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