1 | /* minilzo.c -- mini version of the LZO real-time data compression library
|
---|
2 |
|
---|
3 | This file is part of the LZO real-time data compression library.
|
---|
4 |
|
---|
5 | Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
|
---|
6 | Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
|
---|
7 |
|
---|
8 | The LZO library is free software; you can redistribute it and/or
|
---|
9 | modify it under the terms of the GNU General Public License as
|
---|
10 | published by the Free Software Foundation; either version 2 of
|
---|
11 | the License, or (at your option) any later version.
|
---|
12 |
|
---|
13 | The LZO library is distributed in the hope that it will be useful,
|
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
16 | GNU General Public License for more details.
|
---|
17 |
|
---|
18 | You should have received a copy of the GNU General Public License
|
---|
19 | along with the LZO library; see the file COPYING.
|
---|
20 | If not, write to the Free Software Foundation, Inc.,
|
---|
21 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
---|
22 |
|
---|
23 | Markus F.X.J. Oberhumer
|
---|
24 | markus.oberhumer@jk.uni-linz.ac.at
|
---|
25 | */
|
---|
26 |
|
---|
27 | /*
|
---|
28 | * NOTE:
|
---|
29 | * the full LZO package can be found at
|
---|
30 | * http://www.infosys.tuwien.ac.at/Staff/lux/marco/lzo.html
|
---|
31 | */
|
---|
32 |
|
---|
33 | #ifdef MINILZO_HAVE_CONFIG_H
|
---|
34 | # include <config.h>
|
---|
35 | #endif
|
---|
36 |
|
---|
37 | #undef LZO_HAVE_CONFIG_H
|
---|
38 |
|
---|
39 | #include "minilzo.h"
|
---|
40 |
|
---|
41 | #ifdef MINILZO_HAVE_CONFIG_H
|
---|
42 | # define LZO_HAVE_CONFIG_H
|
---|
43 | #endif
|
---|
44 |
|
---|
45 | #define __LZO_IN_MINILZO
|
---|
46 |
|
---|
47 | #if !defined(LZO_NO_SYS_TYPES_H)
|
---|
48 | # include <sys/types.h>
|
---|
49 | #endif
|
---|
50 |
|
---|
51 | #ifndef __LZO_CONF_H
|
---|
52 | #define __LZO_CONF_H
|
---|
53 |
|
---|
54 | #ifndef __LZOCONF_H
|
---|
55 | # include <lzoconf.h>
|
---|
56 | #endif
|
---|
57 |
|
---|
58 | #if defined(__LZO_DOS16) || defined(__LZO_WIN16)
|
---|
59 |
|
---|
60 | # if defined(__TURBOC__) && (__TURBOC__ < 0x452)
|
---|
61 | # error You need a newer compiler version
|
---|
62 | # endif
|
---|
63 | #endif
|
---|
64 |
|
---|
65 | #if !defined(LZO_HAVE_CONFIG_H)
|
---|
66 | # include <stddef.h>
|
---|
67 | # include <string.h>
|
---|
68 | # include <stdlib.h>
|
---|
69 | # define HAVE_MEMCMP
|
---|
70 | # define HAVE_MEMCPY
|
---|
71 | # define HAVE_MEMMOVE
|
---|
72 | # define HAVE_MEMSET
|
---|
73 | #else
|
---|
74 | # include <sys/types.h>
|
---|
75 | # if defined(STDC_HEADERS)
|
---|
76 | # include <string.h>
|
---|
77 | # include <stdlib.h>
|
---|
78 | # endif
|
---|
79 | # if defined(HAVE_STDDEF_H)
|
---|
80 | # include <stddef.h>
|
---|
81 | # endif
|
---|
82 | # if defined(HAVE_MEMORY_H)
|
---|
83 | # include <memory.h>
|
---|
84 | # endif
|
---|
85 | #endif
|
---|
86 |
|
---|
87 | #if defined(MFX_MEMCMP_BROKEN)
|
---|
88 | # undef HAVE_MEMCMP
|
---|
89 | #endif
|
---|
90 |
|
---|
91 | #undef NDEBUG
|
---|
92 | #if !defined(LZO_DEBUG)
|
---|
93 | # define NDEBUG
|
---|
94 | #endif
|
---|
95 | #if defined(LZO_DEBUG) || !defined(NDEBUG)
|
---|
96 | # include <stdio.h>
|
---|
97 | #endif
|
---|
98 | #include <assert.h>
|
---|
99 |
|
---|
100 | #if defined(__BOUNDS_CHECKING_ON)
|
---|
101 | # include <unchecked.h>
|
---|
102 | #else
|
---|
103 | # define BOUNDS_CHECKING_OFF_DURING(stmt) stmt
|
---|
104 | # define BOUNDS_CHECKING_OFF_IN_EXPR(expr) (expr)
|
---|
105 | #endif
|
---|
106 |
|
---|
107 | #if !defined(LZO_UNUSED)
|
---|
108 | # define LZO_UNUSED(parm) (parm = parm)
|
---|
109 | #endif
|
---|
110 |
|
---|
111 | #if !defined(__inline__) && !defined(__GNUC__)
|
---|
112 | # if defined(__cplusplus)
|
---|
113 | # define __inline__ inline
|
---|
114 | # else
|
---|
115 | # define __inline__
|
---|
116 | # endif
|
---|
117 | #endif
|
---|
118 |
|
---|
119 | #if 1
|
---|
120 | # define LZO_BYTE(x) ((unsigned char) (x))
|
---|
121 | #else
|
---|
122 | # define LZO_BYTE(x) ((unsigned char) ((x) & 0xff))
|
---|
123 | #endif
|
---|
124 | #if 0
|
---|
125 | # define LZO_USHORT(x) ((unsigned short) (x))
|
---|
126 | #else
|
---|
127 | # define LZO_USHORT(x) ((unsigned short) ((x) & 0xffff))
|
---|
128 | #endif
|
---|
129 |
|
---|
130 | #define LZO_MAX(a,b) ((a) >= (b) ? (a) : (b))
|
---|
131 | #define LZO_MIN(a,b) ((a) <= (b) ? (a) : (b))
|
---|
132 |
|
---|
133 | #define lzo_sizeof(type) ((lzo_uint) (sizeof(type)))
|
---|
134 |
|
---|
135 | #define LZO_HIGH(array) ((lzo_uint) (sizeof(array)/sizeof(*(array))))
|
---|
136 |
|
---|
137 | #define LZO_SIZE(bits) (1u << (bits))
|
---|
138 | #define LZO_MASK(bits) (LZO_SIZE(bits) - 1)
|
---|
139 |
|
---|
140 | #define LZO_LSIZE(bits) (1ul << (bits))
|
---|
141 | #define LZO_LMASK(bits) (LZO_LSIZE(bits) - 1)
|
---|
142 |
|
---|
143 | #define LZO_USIZE(bits) ((lzo_uint) 1 << (bits))
|
---|
144 | #define LZO_UMASK(bits) (LZO_USIZE(bits) - 1)
|
---|
145 |
|
---|
146 | #define LZO_STYPE_MAX(b) (((1l << (8*(b)-2)) - 1l) + (1l << (8*(b)-2)))
|
---|
147 | #define LZO_UTYPE_MAX(b) (((1ul << (8*(b)-1)) - 1ul) + (1ul << (8*(b)-1)))
|
---|
148 |
|
---|
149 | #if !defined(SIZEOF_UNSIGNED)
|
---|
150 | # if (UINT_MAX == 0xffff)
|
---|
151 | # define SIZEOF_UNSIGNED 2
|
---|
152 | # elif (UINT_MAX == 0xffffffffL)
|
---|
153 | # define SIZEOF_UNSIGNED 4
|
---|
154 | # else
|
---|
155 | # define SIZEOF_UNSIGNED 8
|
---|
156 | # endif
|
---|
157 | #endif
|
---|
158 |
|
---|
159 | #if !defined(SIZEOF_UNSIGNED_LONG)
|
---|
160 | # if (ULONG_MAX == 0xffffffffL)
|
---|
161 | # define SIZEOF_UNSIGNED_LONG 4
|
---|
162 | # else
|
---|
163 | # define SIZEOF_UNSIGNED_LONG 8
|
---|
164 | # endif
|
---|
165 | #endif
|
---|
166 |
|
---|
167 | #if !defined(SIZEOF_SIZE_T)
|
---|
168 | # define SIZEOF_SIZE_T SIZEOF_UNSIGNED
|
---|
169 | #endif
|
---|
170 | #if !defined(SIZE_T_MAX)
|
---|
171 | # define SIZE_T_MAX LZO_UTYPE_MAX(SIZEOF_SIZE_T)
|
---|
172 | #endif
|
---|
173 |
|
---|
174 | #if 1 && defined(__LZO_i386) && (UINT_MAX == 0xffffffffL)
|
---|
175 | # if !defined(LZO_UNALIGNED_OK_2) && (USHRT_MAX == 0xffff)
|
---|
176 | # define LZO_UNALIGNED_OK_2
|
---|
177 | # endif
|
---|
178 | # if !defined(LZO_UNALIGNED_OK_4) && (LZO_UINT32_MAX == 0xffffffffL)
|
---|
179 | # define LZO_UNALIGNED_OK_4
|
---|
180 | # endif
|
---|
181 | #endif
|
---|
182 |
|
---|
183 | #if defined(LZO_UNALIGNED_OK_2) || defined(LZO_UNALIGNED_OK_4)
|
---|
184 | # if !defined(LZO_UNALIGNED_OK)
|
---|
185 | # define LZO_UNALIGNED_OK
|
---|
186 | # endif
|
---|
187 | #endif
|
---|
188 |
|
---|
189 | #if defined(LZO_ALIGNED_OK_4) && (LZO_UINT32_MAX != 0xffffffffL)
|
---|
190 | # error LZO_ALIGNED_OK_4 is defined
|
---|
191 | #endif
|
---|
192 |
|
---|
193 | #define LZO_LITTLE_ENDIAN 1234
|
---|
194 | #define LZO_BIG_ENDIAN 4321
|
---|
195 | #define LZO_PDP_ENDIAN 3412
|
---|
196 |
|
---|
197 | #if !defined(LZO_BYTE_ORDER)
|
---|
198 | # if defined(MFX_BYTE_ORDER)
|
---|
199 | # define LZO_BYTE_ORDER MFX_BYTE_ORDER
|
---|
200 | # elif defined(__LZO_i386)
|
---|
201 | # define LZO_BYTE_ORDER LZO_LITTLE_ENDIAN
|
---|
202 | # elif defined(BYTE_ORDER)
|
---|
203 | # define LZO_BYTE_ORDER BYTE_ORDER
|
---|
204 | # elif defined(__BYTE_ORDER)
|
---|
205 | # define LZO_BYTE_ORDER __BYTE_ORDER
|
---|
206 | # endif
|
---|
207 | #endif
|
---|
208 |
|
---|
209 | #if defined(LZO_BYTE_ORDER)
|
---|
210 | # if (LZO_BYTE_ORDER != LZO_LITTLE_ENDIAN) && \
|
---|
211 | (LZO_BYTE_ORDER != LZO_BIG_ENDIAN)
|
---|
212 | # error invalid LZO_BYTE_ORDER
|
---|
213 | # endif
|
---|
214 | #endif
|
---|
215 |
|
---|
216 | #if defined(LZO_UNALIGNED_OK) && !defined(LZO_BYTE_ORDER)
|
---|
217 | # error LZO_BYTE_ORDER is not defined
|
---|
218 | #endif
|
---|
219 |
|
---|
220 | #define LZO_OPTIMIZE_GNUC_i386_IS_BUGGY
|
---|
221 |
|
---|
222 | #if defined(NDEBUG) && !defined(LZO_DEBUG) && !defined(__BOUNDS_CHECKING_ON)
|
---|
223 | # if defined(__GNUC__) && defined(__i386__)
|
---|
224 | # if !defined(LZO_OPTIMIZE_GNUC_i386_IS_BUGGY)
|
---|
225 | # define LZO_OPTIMIZE_GNUC_i386
|
---|
226 | # endif
|
---|
227 | # endif
|
---|
228 | #endif
|
---|
229 |
|
---|
230 | __LZO_EXTERN_C int __lzo_init_done;
|
---|
231 | __LZO_EXTERN_C const lzo_byte __lzo_copyright[];
|
---|
232 | __LZO_EXTERN_C const lzo_uint32 _lzo_crc32_table[256];
|
---|
233 |
|
---|
234 | #define _LZO_STRINGIZE(x) #x
|
---|
235 | #define _LZO_MEXPAND(x) _LZO_STRINGIZE(x)
|
---|
236 |
|
---|
237 | #define _LZO_CONCAT2(a,b) a ## b
|
---|
238 | #define _LZO_CONCAT3(a,b,c) a ## b ## c
|
---|
239 | #define _LZO_CONCAT4(a,b,c,d) a ## b ## c ## d
|
---|
240 | #define _LZO_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e
|
---|
241 |
|
---|
242 | #define _LZO_ECONCAT2(a,b) _LZO_CONCAT2(a,b)
|
---|
243 | #define _LZO_ECONCAT3(a,b,c) _LZO_CONCAT3(a,b,c)
|
---|
244 | #define _LZO_ECONCAT4(a,b,c,d) _LZO_CONCAT4(a,b,c,d)
|
---|
245 | #define _LZO_ECONCAT5(a,b,c,d,e) _LZO_CONCAT5(a,b,c,d,e)
|
---|
246 |
|
---|
247 | #ifndef __LZO_PTR_H
|
---|
248 | #define __LZO_PTR_H
|
---|
249 |
|
---|
250 | #ifdef __cplusplus
|
---|
251 | extern "C" {
|
---|
252 | #endif
|
---|
253 |
|
---|
254 | #if defined(__LZO_DOS16) || defined(__LZO_WIN16)
|
---|
255 | # include <dos.h>
|
---|
256 | # if 1 && defined(__WATCOMC__)
|
---|
257 | # include <i86.h>
|
---|
258 | __LZO_EXTERN_C unsigned char _HShift;
|
---|
259 | # define __LZO_HShift _HShift
|
---|
260 | # elif 1 && defined(_MSC_VER)
|
---|
261 | __LZO_EXTERN_C unsigned short __near _AHSHIFT;
|
---|
262 | # define __LZO_HShift ((unsigned) &_AHSHIFT)
|
---|
263 | # elif defined(__LZO_WIN16)
|
---|
264 | # define __LZO_HShift 3
|
---|
265 | # else
|
---|
266 | # define __LZO_HShift 12
|
---|
267 | # endif
|
---|
268 | # if !defined(_FP_SEG) && defined(FP_SEG)
|
---|
269 | # define _FP_SEG FP_SEG
|
---|
270 | # endif
|
---|
271 | # if !defined(_FP_OFF) && defined(FP_OFF)
|
---|
272 | # define _FP_OFF FP_OFF
|
---|
273 | # endif
|
---|
274 | #endif
|
---|
275 |
|
---|
276 | #if (UINT_MAX >= 0xffffffffL)
|
---|
277 | typedef ptrdiff_t lzo_ptrdiff_t;
|
---|
278 | #else
|
---|
279 | typedef long lzo_ptrdiff_t;
|
---|
280 | #endif
|
---|
281 |
|
---|
282 | #if !defined(__LZO_HAVE_PTR_T)
|
---|
283 | # if defined(lzo_ptr_t)
|
---|
284 | # define __LZO_HAVE_PTR_T
|
---|
285 | # endif
|
---|
286 | #endif
|
---|
287 | #if !defined(__LZO_HAVE_PTR_T)
|
---|
288 | # if defined(SIZEOF_CHAR_P) && defined(SIZEOF_UNSIGNED_LONG)
|
---|
289 | # if (SIZEOF_CHAR_P == SIZEOF_UNSIGNED_LONG)
|
---|
290 | typedef unsigned long lzo_ptr_t;
|
---|
291 | typedef long lzo_sptr_t;
|
---|
292 | # define __LZO_HAVE_PTR_T
|
---|
293 | # endif
|
---|
294 | # endif
|
---|
295 | #endif
|
---|
296 | #if !defined(__LZO_HAVE_PTR_T)
|
---|
297 | # if defined(SIZEOF_CHAR_P) && defined(SIZEOF_UNSIGNED)
|
---|
298 | # if (SIZEOF_CHAR_P == SIZEOF_UNSIGNED)
|
---|
299 | typedef unsigned int lzo_ptr_t;
|
---|
300 | typedef int lzo_sptr_t;
|
---|
301 | # define __LZO_HAVE_PTR_T
|
---|
302 | # endif
|
---|
303 | # endif
|
---|
304 | #endif
|
---|
305 | #if !defined(__LZO_HAVE_PTR_T)
|
---|
306 | # if defined(SIZEOF_CHAR_P) && defined(SIZEOF_UNSIGNED_SHORT)
|
---|
307 | # if (SIZEOF_CHAR_P == SIZEOF_UNSIGNED_SHORT)
|
---|
308 | typedef unsigned short lzo_ptr_t;
|
---|
309 | typedef short lzo_sptr_t;
|
---|
310 | # define __LZO_HAVE_PTR_T
|
---|
311 | # endif
|
---|
312 | # endif
|
---|
313 | #endif
|
---|
314 | #if !defined(__LZO_HAVE_PTR_T)
|
---|
315 | # if defined(LZO_HAVE_CONFIG_H) || defined(SIZEOF_CHAR_P)
|
---|
316 | # error no suitable type for lzo_ptr_t
|
---|
317 | # else
|
---|
318 | typedef unsigned long lzo_ptr_t;
|
---|
319 | typedef long lzo_sptr_t;
|
---|
320 | # define __LZO_HAVE_PTR_T
|
---|
321 | # endif
|
---|
322 | #endif
|
---|
323 |
|
---|
324 | #if defined(__LZO_DOS16) || defined(__LZO_WIN16)
|
---|
325 | #define PTR(a) ((lzo_bytep) (a))
|
---|
326 |
|
---|
327 | #define PTR_ALIGNED_4(a) ((_FP_OFF(a) & 3) == 0)
|
---|
328 | #define PTR_ALIGNED2_4(a,b) (((_FP_OFF(a) | _FP_OFF(b)) & 3) == 0)
|
---|
329 | #else
|
---|
330 | #define PTR(a) ((lzo_ptr_t) (a))
|
---|
331 | #define PTR_LINEAR(a) PTR(a)
|
---|
332 | #define PTR_ALIGNED_4(a) ((PTR_LINEAR(a) & 3) == 0)
|
---|
333 | #define PTR_ALIGNED2_4(a,b) (((PTR_LINEAR(a) | PTR_LINEAR(b)) & 3) == 0)
|
---|
334 | #endif
|
---|
335 |
|
---|
336 | #define PTR_LT(a,b) (PTR(a) < PTR(b))
|
---|
337 | #define PTR_GE(a,b) (PTR(a) >= PTR(b))
|
---|
338 | #define PTR_DIFF(a,b) ((lzo_ptrdiff_t) (PTR(a) - PTR(b)))
|
---|
339 |
|
---|
340 | LZO_EXTERN(lzo_ptr_t)
|
---|
341 | __lzo_ptr_linear(const lzo_voidp ptr);
|
---|
342 |
|
---|
343 | typedef union
|
---|
344 | {
|
---|
345 | short a_short;
|
---|
346 | int a_int;
|
---|
347 | long a_long;
|
---|
348 | char * a_char_p;
|
---|
349 | lzo_uint a_lzo_uint;
|
---|
350 | lzo_uint32 a_lzo_uint32;
|
---|
351 | lzo_ptrdiff_t a_lzo_ptrdiff_t;
|
---|
352 | lzo_ptr_t a_lzo_ptr_t;
|
---|
353 | lzo_bytep a_lzo_bytep;
|
---|
354 | lzo_bytepp a_lzo_bytepp;
|
---|
355 | }
|
---|
356 | lzo_align_t;
|
---|
357 |
|
---|
358 | #ifdef __cplusplus
|
---|
359 | }
|
---|
360 | #endif
|
---|
361 |
|
---|
362 | #endif
|
---|
363 |
|
---|
364 | #define LZO_DETERMINISTIC
|
---|
365 |
|
---|
366 | #define LZO_DICT_USE_PTR
|
---|
367 | #if 0 || defined(__LZO_DOS16) || defined(__LZO_WIN16)
|
---|
368 | # undef LZO_DICT_USE_PTR
|
---|
369 | #endif
|
---|
370 |
|
---|
371 | #if !defined(lzo_moff_t)
|
---|
372 | #if 1
|
---|
373 | #define lzo_moff_t lzo_uint
|
---|
374 | #define lzo_cmoff_t lzo_uint
|
---|
375 | #else
|
---|
376 | #define lzo_moff_t lzo_ptrdiff_t
|
---|
377 | #define lzo_cmoff_t lzo_ptrdiff_t
|
---|
378 | #endif
|
---|
379 | #endif
|
---|
380 |
|
---|
381 | #endif
|
---|
382 |
|
---|
383 | LZO_PUBLIC(lzo_ptr_t)
|
---|
384 | __lzo_ptr_linear(const lzo_voidp ptr)
|
---|
385 | {
|
---|
386 | lzo_ptr_t p;
|
---|
387 |
|
---|
388 | #if defined(__LZO_DOS16) || defined(__LZO_WIN16)
|
---|
389 | p = (((lzo_ptr_t)(_FP_SEG(ptr))) << (16 - __LZO_HShift)) + (_FP_OFF(ptr));
|
---|
390 | #else
|
---|
391 | p = PTR_LINEAR(ptr);
|
---|
392 | #endif
|
---|
393 |
|
---|
394 | return p;
|
---|
395 | }
|
---|
396 |
|
---|
397 | LZO_PUBLIC(unsigned)
|
---|
398 | __lzo_align_gap(const lzo_voidp ptr, lzo_uint size)
|
---|
399 | {
|
---|
400 | lzo_ptr_t p, s, n;
|
---|
401 |
|
---|
402 | assert(size > 0);
|
---|
403 |
|
---|
404 | p = __lzo_ptr_linear(ptr);
|
---|
405 | s = (lzo_ptr_t) (size - 1);
|
---|
406 | #if 0
|
---|
407 | assert((size & (size - 1)) == 0);
|
---|
408 | n = ((p + s) & ~s) - p;
|
---|
409 | #else
|
---|
410 | n = (((p + s) / size) * size) - p;
|
---|
411 | #endif
|
---|
412 |
|
---|
413 | assert((long)n >= 0);
|
---|
414 | assert(n <= s);
|
---|
415 |
|
---|
416 | return (unsigned)n;
|
---|
417 | }
|
---|
418 |
|
---|
419 | #ifndef __LZO_UTIL_H
|
---|
420 | #define __LZO_UTIL_H
|
---|
421 |
|
---|
422 | #ifndef __LZO_CONF_H
|
---|
423 |
|
---|
424 | #endif
|
---|
425 |
|
---|
426 | #ifdef __cplusplus
|
---|
427 | extern "C" {
|
---|
428 | #endif
|
---|
429 |
|
---|
430 | #if 1 && defined(HAVE_MEMCPY)
|
---|
431 | #if !defined(__LZO_DOS16) && !defined(__LZO_WIN16)
|
---|
432 |
|
---|
433 | #define MEMCPY8_DS(dest,src,len) \
|
---|
434 | memcpy(dest,src,len); \
|
---|
435 | dest += len; \
|
---|
436 | src += len
|
---|
437 |
|
---|
438 | #endif
|
---|
439 | #endif
|
---|
440 |
|
---|
441 | #if !defined(MEMCPY8_DS)
|
---|
442 |
|
---|
443 | #define MEMCPY8_DS(dest,src,len) \
|
---|
444 | { register lzo_uint __l = (len) / 8; \
|
---|
445 | do { \
|
---|
446 | *dest++ = *src++; \
|
---|
447 | *dest++ = *src++; \
|
---|
448 | *dest++ = *src++; \
|
---|
449 | *dest++ = *src++; \
|
---|
450 | *dest++ = *src++; \
|
---|
451 | *dest++ = *src++; \
|
---|
452 | *dest++ = *src++; \
|
---|
453 | *dest++ = *src++; \
|
---|
454 | } while (--__l > 0); }
|
---|
455 |
|
---|
456 | #endif
|
---|
457 |
|
---|
458 | #define MEMCPY_DS(dest,src,len) \
|
---|
459 | do *dest++ = *src++; \
|
---|
460 | while (--len > 0)
|
---|
461 |
|
---|
462 | #define MEMMOVE_DS(dest,src,len) \
|
---|
463 | do *dest++ = *src++; \
|
---|
464 | while (--len > 0)
|
---|
465 |
|
---|
466 | #if defined(LZO_OPTIMIZE_GNUC_i386)
|
---|
467 |
|
---|
468 | #define BZERO8_PTR(s,n) \
|
---|
469 | __asm__ __volatile__( \
|
---|
470 | "movl %0,%%eax \n" \
|
---|
471 | "movl %1,%%edi \n" \
|
---|
472 | "movl %2,%%ecx \n" \
|
---|
473 | "cld \n" \
|
---|
474 | "rep \n" \
|
---|
475 | "stosl %%eax,(%%edi) \n" \
|
---|
476 | : \
|
---|
477 | :"g" (0),"g" (s),"g" (n) \
|
---|
478 | :"eax","edi","ecx", "memory", "cc" \
|
---|
479 | )
|
---|
480 |
|
---|
481 | #elif (LZO_UINT_MAX <= SIZE_T_MAX) && defined(HAVE_MEMSET)
|
---|
482 |
|
---|
483 | #define BZERO8_PTR(s,n) \
|
---|
484 | memset((lzo_voidp)(s),0,(n)*sizeof(lzo_byte *))
|
---|
485 |
|
---|
486 | #else
|
---|
487 |
|
---|
488 | #define BZERO8_PTR(s,n) \
|
---|
489 | lzo_memset((lzo_voidp)(s),0,(n)*lzo_sizeof(lzo_byte *))
|
---|
490 |
|
---|
491 | #endif
|
---|
492 |
|
---|
493 | #if 0
|
---|
494 | #if defined(__GNUC__) && defined(__i386__)
|
---|
495 |
|
---|
496 | unsigned char lzo_rotr8(unsigned char value, int shift);
|
---|
497 | extern __inline__ unsigned char lzo_rotr8(unsigned char value, int shift)
|
---|
498 | {
|
---|
499 | unsigned char result;
|
---|
500 |
|
---|
501 | __asm__ __volatile__ ("movb %b1, %b0; rorb %b2, %b0"
|
---|
502 | : "=a"(result) : "g"(value), "c"(shift));
|
---|
503 | return result;
|
---|
504 | }
|
---|
505 |
|
---|
506 | unsigned short lzo_rotr16(unsigned short value, int shift);
|
---|
507 | extern __inline__ unsigned short lzo_rotr16(unsigned short value, int shift)
|
---|
508 | {
|
---|
509 | unsigned short result;
|
---|
510 |
|
---|
511 | __asm__ __volatile__ ("movw %b1, %b0; rorw %b2, %b0"
|
---|
512 | : "=a"(result) : "g"(value), "c"(shift));
|
---|
513 | return result;
|
---|
514 | }
|
---|
515 |
|
---|
516 | #endif
|
---|
517 | #endif
|
---|
518 |
|
---|
519 | #ifdef __cplusplus
|
---|
520 | }
|
---|
521 | #endif
|
---|
522 |
|
---|
523 | #endif
|
---|
524 |
|
---|
525 | LZO_PUBLIC(lzo_bool)
|
---|
526 | lzo_assert(int expr)
|
---|
527 | {
|
---|
528 | return (expr) ? 1 : 0;
|
---|
529 | }
|
---|
530 |
|
---|
531 | /* If you use the LZO library in a product, you *must* keep this
|
---|
532 | * copyright string in the executable of your product.
|
---|
533 | */
|
---|
534 |
|
---|
535 | const lzo_byte __lzo_copyright[] =
|
---|
536 | "\n\n\n"
|
---|
537 | "LZO real-time data compression library.\n"
|
---|
538 | "Copyright (C) 1996, 1997 Markus Franz Xaver Johannes Oberhumer\n"
|
---|
539 | "<markus.oberhumer@jk.uni-linz.ac.at>\n"
|
---|
540 | "http://www.infosys.tuwien.ac.at/Staff/lux/marco/lzo.html\n"
|
---|
541 | "\n"
|
---|
542 | "LZO version: v" LZO_VERSION_STRING ", " LZO_VERSION_DATE "\n"
|
---|
543 | "LZO special compilation options:\n"
|
---|
544 | #ifdef __cplusplus
|
---|
545 | " __cplusplus\n"
|
---|
546 | #endif
|
---|
547 | #ifdef __pic__
|
---|
548 | " __pic__\n"
|
---|
549 | #endif
|
---|
550 | #ifdef __PIC__
|
---|
551 | " __PIC__\n"
|
---|
552 | #endif
|
---|
553 | #if (UINT_MAX < 0xffffffffL)
|
---|
554 | " 16BIT\n"
|
---|
555 | #endif
|
---|
556 | #if (LZO_UINT_MAX < 0xffffffffL)
|
---|
557 | " LZO_16BIT\n"
|
---|
558 | #endif
|
---|
559 | #if (UINT_MAX > 0xffffffffL)
|
---|
560 | " UINT_MAX=" _LZO_MEXPAND(UINT_MAX) "\n"
|
---|
561 | #endif
|
---|
562 | #if (ULONG_MAX > 0xffffffffL)
|
---|
563 | " UINT_MAX=" _LZO_MEXPAND(ULONG_MAX) "\n"
|
---|
564 | #endif
|
---|
565 | #if defined(LZO_BYTE_ORDER)
|
---|
566 | " LZO_BYTE_ORDER=" _LZO_MEXPAND(LZO_BYTE_ORDER) "\n"
|
---|
567 | #endif
|
---|
568 | #if defined(LZO_UNALIGNED_OK_2)
|
---|
569 | " LZO_UNALIGNED_OK_2\n"
|
---|
570 | #endif
|
---|
571 | #if defined(LZO_UNALIGNED_OK_4)
|
---|
572 | " LZO_UNALIGNED_OK_4\n"
|
---|
573 | #endif
|
---|
574 | #if defined(LZO_ALIGNED_OK_4)
|
---|
575 | " LZO_ALIGNED_OK_4\n"
|
---|
576 | #endif
|
---|
577 | #if defined(LZO_DICT_USE_PTR)
|
---|
578 | " LZO_DICT_USE_PTR\n"
|
---|
579 | #endif
|
---|
580 | #if defined(__LZO_IN_MINILZO)
|
---|
581 | " __LZO_IN_MINILZO\n"
|
---|
582 | #endif
|
---|
583 | "\n\n"
|
---|
584 |
|
---|
585 | #if defined(__GNUC__) && defined(__VERSION__)
|
---|
586 | " by gcc " __VERSION__
|
---|
587 | #elif defined(__BORLANDC__)
|
---|
588 | " by Borland C " _LZO_MEXPAND(__BORLANDC__)
|
---|
589 | #elif defined(_MSC_VER)
|
---|
590 | " by Microsoft C " _LZO_MEXPAND(_MSC_VER)
|
---|
591 | #elif defined(__PUREC__)
|
---|
592 | " by Pure C " _LZO_MEXPAND(__PUREC__)
|
---|
593 | #elif defined(__SC__)
|
---|
594 | " by Symantec C " _LZO_MEXPAND(__SC__)
|
---|
595 | #elif defined(__TURBOC__)
|
---|
596 | " by Turbo C " _LZO_MEXPAND(__TURBOC__)
|
---|
597 | #elif defined(__WATCOMC__)
|
---|
598 | " by Watcom C " _LZO_MEXPAND(__WATCOMC__)
|
---|
599 | #endif
|
---|
600 | " $\n"
|
---|
601 | "$Copyright: LZO (C) 1996, 1997 Markus Franz Xaver Johannes Oberhumer $\n";
|
---|
602 |
|
---|
603 | LZO_PUBLIC(unsigned)
|
---|
604 | lzo_version(void)
|
---|
605 | {
|
---|
606 | return LZO_VERSION;
|
---|
607 | }
|
---|
608 |
|
---|
609 | LZO_PUBLIC(const char *)
|
---|
610 | lzo_version_string(void)
|
---|
611 | {
|
---|
612 | return LZO_VERSION_STRING;
|
---|
613 | }
|
---|
614 |
|
---|
615 | LZO_PUBLIC(const char *)
|
---|
616 | lzo_version_date(void)
|
---|
617 | {
|
---|
618 | return LZO_VERSION_DATE;
|
---|
619 | }
|
---|
620 |
|
---|
621 | LZO_PUBLIC(const lzo_charp)
|
---|
622 | _lzo_version_string(void)
|
---|
623 | {
|
---|
624 | return LZO_VERSION_STRING;
|
---|
625 | }
|
---|
626 |
|
---|
627 | LZO_PUBLIC(const lzo_charp)
|
---|
628 | _lzo_version_date(void)
|
---|
629 | {
|
---|
630 | return LZO_VERSION_DATE;
|
---|
631 | }
|
---|
632 |
|
---|
633 | #define LZO_BASE 65521u
|
---|
634 | #define LZO_NMAX 5552
|
---|
635 |
|
---|
636 | #define LZO_DO1(buf,i) {s1 += buf[i]; s2 += s1;}
|
---|
637 | #define LZO_DO2(buf,i) LZO_DO1(buf,i); LZO_DO1(buf,i+1);
|
---|
638 | #define LZO_DO4(buf,i) LZO_DO2(buf,i); LZO_DO2(buf,i+2);
|
---|
639 | #define LZO_DO8(buf,i) LZO_DO4(buf,i); LZO_DO4(buf,i+4);
|
---|
640 | #define LZO_DO16(buf,i) LZO_DO8(buf,i); LZO_DO8(buf,i+8);
|
---|
641 |
|
---|
642 | LZO_PUBLIC(lzo_uint32)
|
---|
643 | lzo_adler32(lzo_uint32 adler, const lzo_byte *buf, lzo_uint len)
|
---|
644 | {
|
---|
645 | lzo_uint32 s1 = adler & 0xffff;
|
---|
646 | lzo_uint32 s2 = (adler >> 16) & 0xffff;
|
---|
647 | int k;
|
---|
648 |
|
---|
649 | if (buf == NULL)
|
---|
650 | return 1;
|
---|
651 |
|
---|
652 | while (len > 0)
|
---|
653 | {
|
---|
654 | k = len < LZO_NMAX ? (int) len : LZO_NMAX;
|
---|
655 | len -= k;
|
---|
656 | if (k >= 16) do
|
---|
657 | {
|
---|
658 | LZO_DO16(buf,0);
|
---|
659 | buf += 16;
|
---|
660 | k -= 16;
|
---|
661 | } while (k >= 16);
|
---|
662 | if (k != 0) do
|
---|
663 | {
|
---|
664 | s1 += *buf++;
|
---|
665 | s2 += s1;
|
---|
666 | } while (--k > 0);
|
---|
667 | s1 %= LZO_BASE;
|
---|
668 | s2 %= LZO_BASE;
|
---|
669 | }
|
---|
670 | return (s2 << 16) | s1;
|
---|
671 | }
|
---|
672 |
|
---|
673 | LZO_PUBLIC(int)
|
---|
674 | lzo_memcmp(const lzo_voidp s1, const lzo_voidp s2, lzo_uint len)
|
---|
675 | {
|
---|
676 | #if (LZO_UINT_MAX <= SIZE_T_MAX) && defined(HAVE_MEMCMP)
|
---|
677 | return memcmp(s1,s2,len);
|
---|
678 | #else
|
---|
679 | const lzo_byte *p1 = (const lzo_byte *) s1;
|
---|
680 | const lzo_byte *p2 = (const lzo_byte *) s2;
|
---|
681 | int d;
|
---|
682 |
|
---|
683 | if (len > 0) do
|
---|
684 | {
|
---|
685 | d = *p1 - *p2;
|
---|
686 | if (d != 0)
|
---|
687 | return d;
|
---|
688 | p1++;
|
---|
689 | p2++;
|
---|
690 | }
|
---|
691 | while (--len > 0);
|
---|
692 | return 0;
|
---|
693 | #endif
|
---|
694 | }
|
---|
695 |
|
---|
696 | LZO_PUBLIC(lzo_voidp)
|
---|
697 | lzo_memcpy(lzo_voidp dest, const lzo_voidp src, lzo_uint len)
|
---|
698 | {
|
---|
699 | #if (LZO_UINT_MAX <= SIZE_T_MAX) && defined(HAVE_MEMCPY)
|
---|
700 | return memcpy(dest,src,len);
|
---|
701 | #else
|
---|
702 | lzo_byte *p1 = (lzo_byte *) dest;
|
---|
703 | const lzo_byte *p2 = (const lzo_byte *) src;
|
---|
704 |
|
---|
705 | if (len <= 0 || p1 == p2)
|
---|
706 | return dest;
|
---|
707 | do
|
---|
708 | *p1++ = *p2++;
|
---|
709 | while (--len > 0);
|
---|
710 | return dest;
|
---|
711 | #endif
|
---|
712 | }
|
---|
713 |
|
---|
714 | #if !defined(__LZO_IN_MINILZO)
|
---|
715 | LZO_PUBLIC(lzo_voidp)
|
---|
716 | lzo_memmove(lzo_voidp dest, const lzo_voidp src, lzo_uint len)
|
---|
717 | {
|
---|
718 | #if (LZO_UINT_MAX <= SIZE_T_MAX) && defined(HAVE_MEMMOVE)
|
---|
719 | return memmove(dest,src,len);
|
---|
720 | #else
|
---|
721 | lzo_byte *p1 = (lzo_byte *) dest;
|
---|
722 | const lzo_byte *p2 = (const lzo_byte *) src;
|
---|
723 |
|
---|
724 | if (len <= 0 || p1 == p2)
|
---|
725 | return dest;
|
---|
726 |
|
---|
727 | if (p1 < p2)
|
---|
728 | {
|
---|
729 | do
|
---|
730 | *p1++ = *p2++;
|
---|
731 | while (--len > 0);
|
---|
732 | }
|
---|
733 | else
|
---|
734 | {
|
---|
735 | p1 += len;
|
---|
736 | p2 += len;
|
---|
737 | do
|
---|
738 | *--p1 = *--p2;
|
---|
739 | while (--len > 0);
|
---|
740 | }
|
---|
741 | return dest;
|
---|
742 | #endif
|
---|
743 | }
|
---|
744 | #endif
|
---|
745 |
|
---|
746 | LZO_PUBLIC(lzo_voidp)
|
---|
747 | lzo_memset(lzo_voidp s, int c, lzo_uint len)
|
---|
748 | {
|
---|
749 | #if (LZO_UINT_MAX <= SIZE_T_MAX) && defined(HAVE_MEMSET)
|
---|
750 | return memset(s,c,len);
|
---|
751 | #else
|
---|
752 | lzo_byte *p = (lzo_byte *) s;
|
---|
753 |
|
---|
754 | if (len > 0) do
|
---|
755 | *p++ = LZO_BYTE(c);
|
---|
756 | while (--len > 0);
|
---|
757 | return s;
|
---|
758 | #endif
|
---|
759 | }
|
---|
760 |
|
---|
761 | #include <stdio.h>
|
---|
762 |
|
---|
763 | #if 0
|
---|
764 | # define IS_SIGNED(type) (((type) (1ul << (8 * sizeof(type) - 1))) < 0)
|
---|
765 | # define IS_UNSIGNED(type) (((type) (1ul << (8 * sizeof(type) - 1))) > 0)
|
---|
766 | #else
|
---|
767 | # define IS_SIGNED(type) (((type) (-1)) < ((type) 0))
|
---|
768 | # define IS_UNSIGNED(type) (((type) (-1)) > ((type) 0))
|
---|
769 | #endif
|
---|
770 |
|
---|
771 | static lzo_bool schedule_insns_bug(void);
|
---|
772 | static lzo_bool strength_reduce_bug(int *);
|
---|
773 |
|
---|
774 | #if 0 || defined(LZO_DEBUG)
|
---|
775 | static lzo_bool __lzo_assert_fail(const char *s, unsigned line)
|
---|
776 | {
|
---|
777 | fprintf(stderr,"LZO assertion failed in line %u: '%s'\n",line,s);
|
---|
778 | return 0;
|
---|
779 | }
|
---|
780 | # define __lzo_assert(x) ((x) ? 1 : __lzo_assert_fail(#x,__LINE__))
|
---|
781 | #else
|
---|
782 | # define __lzo_assert(x) ((x) ? 1 : 0)
|
---|
783 | #endif
|
---|
784 |
|
---|
785 | static lzo_bool basic_integral_check(void)
|
---|
786 | {
|
---|
787 | lzo_bool r = 1;
|
---|
788 | lzo_bool sanity;
|
---|
789 |
|
---|
790 | r &= __lzo_assert(CHAR_BIT == 8);
|
---|
791 | r &= __lzo_assert(sizeof(char) == 1);
|
---|
792 |
|
---|
793 | r &= __lzo_assert(sizeof(lzo_uint32) >= 4);
|
---|
794 | r &= __lzo_assert(sizeof(lzo_uint32) >= sizeof(unsigned));
|
---|
795 | r &= __lzo_assert(sizeof(lzo_uint) >= sizeof(unsigned));
|
---|
796 |
|
---|
797 | #if defined(SIZEOF_UNSIGNED)
|
---|
798 | r &= __lzo_assert(SIZEOF_UNSIGNED == sizeof(unsigned));
|
---|
799 | #endif
|
---|
800 | #if defined(SIZEOF_UNSIGNED_LONG)
|
---|
801 | r &= __lzo_assert(SIZEOF_UNSIGNED_LONG == sizeof(unsigned long));
|
---|
802 | #endif
|
---|
803 | #if defined(SIZEOF_UNSIGNED_SHORT)
|
---|
804 | r &= __lzo_assert(SIZEOF_UNSIGNED_SHORT == sizeof(unsigned short));
|
---|
805 | #endif
|
---|
806 | #if !defined(__LZO_IN_MINILZO)
|
---|
807 | #if defined(SIZEOF_SIZE_T)
|
---|
808 | r &= __lzo_assert(SIZEOF_SIZE_T == sizeof(size_t));
|
---|
809 | #endif
|
---|
810 | #endif
|
---|
811 |
|
---|
812 | sanity = IS_UNSIGNED(unsigned short) && IS_UNSIGNED(unsigned) &&
|
---|
813 | IS_UNSIGNED(unsigned long) &&
|
---|
814 | IS_SIGNED(short) && IS_SIGNED(int) && IS_SIGNED(long);
|
---|
815 | if (sanity)
|
---|
816 | {
|
---|
817 | r &= __lzo_assert(IS_UNSIGNED(lzo_uint32));
|
---|
818 | r &= __lzo_assert(IS_UNSIGNED(lzo_uint));
|
---|
819 | r &= __lzo_assert(IS_SIGNED(lzo_int32));
|
---|
820 | r &= __lzo_assert(IS_SIGNED(lzo_int));
|
---|
821 |
|
---|
822 | r &= __lzo_assert(INT_MAX == LZO_STYPE_MAX(sizeof(int)));
|
---|
823 | r &= __lzo_assert(UINT_MAX == LZO_UTYPE_MAX(sizeof(unsigned)));
|
---|
824 | r &= __lzo_assert(LONG_MAX == LZO_STYPE_MAX(sizeof(long)));
|
---|
825 | r &= __lzo_assert(ULONG_MAX == LZO_UTYPE_MAX(sizeof(unsigned long)));
|
---|
826 | r &= __lzo_assert(SHRT_MAX == LZO_STYPE_MAX(sizeof(short)));
|
---|
827 | r &= __lzo_assert(USHRT_MAX == LZO_UTYPE_MAX(sizeof(unsigned short)));
|
---|
828 | r &= __lzo_assert(LZO_UINT32_MAX == LZO_UTYPE_MAX(sizeof(lzo_uint32)));
|
---|
829 | r &= __lzo_assert(LZO_UINT_MAX == LZO_UTYPE_MAX(sizeof(lzo_uint)));
|
---|
830 | #if !defined(__LZO_IN_MINILZO)
|
---|
831 | r &= __lzo_assert(SIZE_T_MAX == LZO_UTYPE_MAX(sizeof(size_t)));
|
---|
832 | #endif
|
---|
833 | }
|
---|
834 |
|
---|
835 | #if 0
|
---|
836 |
|
---|
837 | r &= __lzo_assert(LZO_BYTE(257) == 1);
|
---|
838 | r &= __lzo_assert(LZO_USHORT(65537L) == 1);
|
---|
839 | #endif
|
---|
840 |
|
---|
841 | return r;
|
---|
842 | }
|
---|
843 |
|
---|
844 | static lzo_bool basic_ptr_check(void)
|
---|
845 | {
|
---|
846 | lzo_bool r = 1;
|
---|
847 | lzo_bool sanity;
|
---|
848 |
|
---|
849 | r &= __lzo_assert(sizeof(lzo_voidp) == sizeof(lzo_byte *));
|
---|
850 | r &= __lzo_assert(sizeof(lzo_voidp) == sizeof(lzo_voidpp));
|
---|
851 | r &= __lzo_assert(sizeof(lzo_voidp) == sizeof(lzo_bytepp));
|
---|
852 | r &= __lzo_assert(sizeof(lzo_voidp) >= sizeof(lzo_uint));
|
---|
853 |
|
---|
854 | r &= __lzo_assert(sizeof(lzo_ptr_t) == sizeof(lzo_voidp));
|
---|
855 | r &= __lzo_assert(sizeof(lzo_ptr_t) >= sizeof(lzo_uint));
|
---|
856 |
|
---|
857 | r &= __lzo_assert(sizeof(lzo_ptrdiff_t) >= 4);
|
---|
858 | r &= __lzo_assert(sizeof(lzo_ptrdiff_t) >= sizeof(ptrdiff_t));
|
---|
859 |
|
---|
860 | #if defined(SIZEOF_CHAR_P)
|
---|
861 | r &= __lzo_assert(SIZEOF_CHAR_P == sizeof(char *));
|
---|
862 | #endif
|
---|
863 | #if defined(SIZEOF_PTRDIFF_T)
|
---|
864 | r &= __lzo_assert(SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t));
|
---|
865 | #endif
|
---|
866 |
|
---|
867 | sanity = IS_UNSIGNED(unsigned short) && IS_UNSIGNED(unsigned) &&
|
---|
868 | IS_UNSIGNED(unsigned long) &&
|
---|
869 | IS_SIGNED(short) && IS_SIGNED(int) && IS_SIGNED(long);
|
---|
870 | if (sanity)
|
---|
871 | {
|
---|
872 | r &= __lzo_assert(IS_UNSIGNED(lzo_ptr_t));
|
---|
873 | r &= __lzo_assert(IS_SIGNED(lzo_ptrdiff_t));
|
---|
874 | r &= __lzo_assert(IS_SIGNED(lzo_sptr_t));
|
---|
875 | }
|
---|
876 |
|
---|
877 | return r;
|
---|
878 | }
|
---|
879 |
|
---|
880 | static lzo_bool ptr_check(void)
|
---|
881 | {
|
---|
882 | lzo_bool r = 1;
|
---|
883 | int i;
|
---|
884 | char _wrkmem[10 * sizeof(lzo_byte *) + sizeof(lzo_align_t)];
|
---|
885 | lzo_byte *wrkmem;
|
---|
886 | const lzo_bytepp dict;
|
---|
887 | unsigned char x[4 * sizeof(lzo_align_t)];
|
---|
888 | long d;
|
---|
889 |
|
---|
890 | for (i = 0; i < (int) sizeof(x); i++)
|
---|
891 | x[i] = LZO_BYTE(i);
|
---|
892 |
|
---|
893 | wrkmem = (lzo_byte *) LZO_ALIGN(_wrkmem,sizeof(lzo_align_t));
|
---|
894 | dict = (const lzo_bytepp) wrkmem;
|
---|
895 |
|
---|
896 | d = (long) ((lzo_bytep) dict - (lzo_bytep) _wrkmem);
|
---|
897 | r &= __lzo_assert(d >= 0);
|
---|
898 | r &= __lzo_assert(d < (long) sizeof(lzo_align_t));
|
---|
899 |
|
---|
900 | if (r == 1)
|
---|
901 | {
|
---|
902 | for (i = 0; i < 8; i++)
|
---|
903 | r &= __lzo_assert((lzo_voidp) (&dict[i]) == (lzo_voidp) (&wrkmem[i * sizeof(lzo_byte *)]));
|
---|
904 | }
|
---|
905 |
|
---|
906 | r &= __lzo_assert(NULL == 0);
|
---|
907 | if (r == 1)
|
---|
908 | {
|
---|
909 | for (i = 0; i < 10; i++)
|
---|
910 | dict[i] = wrkmem;
|
---|
911 | BZERO8_PTR(dict+1,8);
|
---|
912 | r &= __lzo_assert(dict[0] == wrkmem);
|
---|
913 | for (i = 1; i < 9; i++)
|
---|
914 | r &= __lzo_assert(dict[i] == NULL);
|
---|
915 | r &= __lzo_assert(dict[9] == wrkmem);
|
---|
916 | }
|
---|
917 |
|
---|
918 | if (r == 1)
|
---|
919 | {
|
---|
920 | unsigned k = 1;
|
---|
921 | const unsigned n = (unsigned) sizeof(lzo_uint32);
|
---|
922 | lzo_byte *p0;
|
---|
923 | lzo_byte *p1;
|
---|
924 |
|
---|
925 | k += __lzo_align_gap(&x[k],n);
|
---|
926 | p0 = (lzo_bytep) &x[k];
|
---|
927 | #if defined(PTR_LINEAR)
|
---|
928 | r &= __lzo_assert((PTR_LINEAR(p0) & (n-1)) == 0);
|
---|
929 | #else
|
---|
930 | r &= __lzo_assert(n == 4);
|
---|
931 | r &= __lzo_assert(PTR_ALIGNED_4(p0));
|
---|
932 | #endif
|
---|
933 |
|
---|
934 | r &= __lzo_assert(k >= 1);
|
---|
935 | p1 = (lzo_bytep) &x[1];
|
---|
936 | r &= __lzo_assert(PTR_GE(p0,p1));
|
---|
937 |
|
---|
938 | r &= __lzo_assert(k < 1+n);
|
---|
939 | p1 = (lzo_bytep) &x[1+n];
|
---|
940 | r &= __lzo_assert(PTR_LT(p0,p1));
|
---|
941 |
|
---|
942 | if (r == 1)
|
---|
943 | {
|
---|
944 | lzo_uint32 v0 = * (lzo_uint32 *) &x[k];
|
---|
945 | lzo_uint32 v1 = * (lzo_uint32 *) &x[k+n];
|
---|
946 |
|
---|
947 | r &= __lzo_assert(v0 > 0);
|
---|
948 | r &= __lzo_assert(v1 > 0);
|
---|
949 | }
|
---|
950 | }
|
---|
951 |
|
---|
952 | return r;
|
---|
953 | }
|
---|
954 |
|
---|
955 | LZO_PUBLIC(int)
|
---|
956 | _lzo_config_check(void)
|
---|
957 | {
|
---|
958 | lzo_bool r = 1;
|
---|
959 | int i;
|
---|
960 | lzo_uint32 adler;
|
---|
961 | union {
|
---|
962 | lzo_uint32 a;
|
---|
963 | unsigned short b;
|
---|
964 | lzo_uint32 aa[4];
|
---|
965 | unsigned char x[4*sizeof(lzo_align_t)];
|
---|
966 | } u;
|
---|
967 |
|
---|
968 | #if 0
|
---|
969 |
|
---|
970 | r &= __lzo_assert((const void *)&u == (const void *)&u.a);
|
---|
971 | r &= __lzo_assert((const void *)&u == (const void *)&u.b);
|
---|
972 | r &= __lzo_assert((const void *)&u == (const void *)&u.x[0]);
|
---|
973 | r &= __lzo_assert((const void *)&u == (const void *)&u.aa[0]);
|
---|
974 | #endif
|
---|
975 |
|
---|
976 | r &= basic_integral_check();
|
---|
977 | r &= basic_ptr_check();
|
---|
978 | if (r != 1)
|
---|
979 | return LZO_E_ERROR;
|
---|
980 |
|
---|
981 | for (i = 0; i < (int) sizeof(u.x); i++)
|
---|
982 | u.x[i] = LZO_BYTE(i);
|
---|
983 |
|
---|
984 | #if 0
|
---|
985 |
|
---|
986 | r &= __lzo_assert( (int) (unsigned char) ((char) -1) == 255);
|
---|
987 | #endif
|
---|
988 |
|
---|
989 | #if defined(LZO_BYTE_ORDER)
|
---|
990 | if (r == 1)
|
---|
991 | {
|
---|
992 | # if (LZO_BYTE_ORDER == LZO_LITTLE_ENDIAN)
|
---|
993 | lzo_uint32 a = (lzo_uint32) (u.a & 0xffffffffL);
|
---|
994 | unsigned short b = (unsigned short) (u.b & 0xffff);
|
---|
995 | r &= __lzo_assert(a == 0x03020100L);
|
---|
996 | r &= __lzo_assert(b == 0x0100);
|
---|
997 | # elif (LZO_BYTE_ORDER == LZO_BIG_ENDIAN)
|
---|
998 | lzo_uint32 a = u.a >> (8 * sizeof(u.a) - 32);
|
---|
999 | unsigned short b = u.b >> (8 * sizeof(u.b) - 16);
|
---|
1000 | r &= __lzo_assert(a == 0x00010203L);
|
---|
1001 | r &= __lzo_assert(b == 0x0001);
|
---|
1002 | # else
|
---|
1003 | # error invalid LZO_BYTE_ORDER
|
---|
1004 | # endif
|
---|
1005 | }
|
---|
1006 | #endif
|
---|
1007 |
|
---|
1008 | #if defined(LZO_UNALIGNED_OK_2)
|
---|
1009 | r &= __lzo_assert(sizeof(short) == 2);
|
---|
1010 | if (r == 1)
|
---|
1011 | {
|
---|
1012 | unsigned short b[4];
|
---|
1013 |
|
---|
1014 | for (i = 0; i < 4; i++)
|
---|
1015 | b[i] = * (const unsigned short *) &u.x[i];
|
---|
1016 |
|
---|
1017 | # if (LZO_BYTE_ORDER == LZO_LITTLE_ENDIAN)
|
---|
1018 | r &= __lzo_assert(b[0] == 0x0100);
|
---|
1019 | r &= __lzo_assert(b[1] == 0x0201);
|
---|
1020 | r &= __lzo_assert(b[2] == 0x0302);
|
---|
1021 | r &= __lzo_assert(b[3] == 0x0403);
|
---|
1022 | # elif (LZO_BYTE_ORDER == LZO_BIG_ENDIAN)
|
---|
1023 | r &= __lzo_assert(b[0] == 0x0001);
|
---|
1024 | r &= __lzo_assert(b[1] == 0x0102);
|
---|
1025 | r &= __lzo_assert(b[2] == 0x0203);
|
---|
1026 | r &= __lzo_assert(b[3] == 0x0304);
|
---|
1027 | # endif
|
---|
1028 | }
|
---|
1029 | #endif
|
---|
1030 |
|
---|
1031 | #if defined(LZO_UNALIGNED_OK_4)
|
---|
1032 | r &= __lzo_assert(sizeof(lzo_uint32) == 4);
|
---|
1033 | if (r == 1)
|
---|
1034 | {
|
---|
1035 | lzo_uint32 a[4];
|
---|
1036 |
|
---|
1037 | for (i = 0; i < 4; i++)
|
---|
1038 | a[i] = * (const lzo_uint32 *) &u.x[i];
|
---|
1039 |
|
---|
1040 | # if (LZO_BYTE_ORDER == LZO_LITTLE_ENDIAN)
|
---|
1041 | r &= __lzo_assert(a[0] == 0x03020100L);
|
---|
1042 | r &= __lzo_assert(a[1] == 0x04030201L);
|
---|
1043 | r &= __lzo_assert(a[2] == 0x05040302L);
|
---|
1044 | r &= __lzo_assert(a[3] == 0x06050403L);
|
---|
1045 | # elif (LZO_BYTE_ORDER == LZO_BIG_ENDIAN)
|
---|
1046 | r &= __lzo_assert(a[0] == 0x00010203L);
|
---|
1047 | r &= __lzo_assert(a[1] == 0x01020304L);
|
---|
1048 | r &= __lzo_assert(a[2] == 0x02030405L);
|
---|
1049 | r &= __lzo_assert(a[3] == 0x03040506L);
|
---|
1050 | # endif
|
---|
1051 | }
|
---|
1052 | #endif
|
---|
1053 |
|
---|
1054 | #if defined(LZO_ALIGNED_OK_4)
|
---|
1055 | r &= __lzo_assert(sizeof(lzo_uint32) == 4);
|
---|
1056 | #endif
|
---|
1057 |
|
---|
1058 | #if !defined(LZO_DICT_USE_PTR)
|
---|
1059 |
|
---|
1060 | r &= __lzo_assert(sizeof(lzo_bytep) >= sizeof(lzo_uint));
|
---|
1061 | #endif
|
---|
1062 |
|
---|
1063 | if (r == 1)
|
---|
1064 | {
|
---|
1065 | adler = lzo_adler32(0, NULL, 0);
|
---|
1066 | adler = lzo_adler32(adler, __lzo_copyright, 200);
|
---|
1067 | r &= __lzo_assert(adler == 0x918C45AAL);
|
---|
1068 | }
|
---|
1069 |
|
---|
1070 | if (r == 1)
|
---|
1071 | {
|
---|
1072 | r &= __lzo_assert(!schedule_insns_bug());
|
---|
1073 | }
|
---|
1074 |
|
---|
1075 | if (r == 1)
|
---|
1076 | {
|
---|
1077 | static int x[3];
|
---|
1078 | static unsigned xn = 3;
|
---|
1079 | register unsigned j;
|
---|
1080 |
|
---|
1081 | for (j = 0; j < xn; j++)
|
---|
1082 | x[j] = (int)j - 3;
|
---|
1083 | r &= __lzo_assert(!strength_reduce_bug(x));
|
---|
1084 | }
|
---|
1085 |
|
---|
1086 | if (r == 1)
|
---|
1087 | {
|
---|
1088 | r &= ptr_check();
|
---|
1089 | }
|
---|
1090 |
|
---|
1091 | return r == 1 ? LZO_E_OK : LZO_E_ERROR;
|
---|
1092 | }
|
---|
1093 |
|
---|
1094 | static lzo_bool schedule_insns_bug(void)
|
---|
1095 | {
|
---|
1096 | #if 1
|
---|
1097 | const int clone[] = {1, 2, 0};
|
---|
1098 | const int *q;
|
---|
1099 | q = clone;
|
---|
1100 | if (*q)
|
---|
1101 | return 0;
|
---|
1102 | return 1;
|
---|
1103 | #else
|
---|
1104 | return 0;
|
---|
1105 | #endif
|
---|
1106 | }
|
---|
1107 |
|
---|
1108 | static lzo_bool strength_reduce_bug(int *x)
|
---|
1109 | {
|
---|
1110 | return x[0] != -3 || x[1] != -2 || x[2] != -1;
|
---|
1111 | }
|
---|
1112 |
|
---|
1113 | int __lzo_init_done = 0;
|
---|
1114 |
|
---|
1115 | LZO_PUBLIC(int)
|
---|
1116 | __lzo_init(unsigned v,int s1,int s2,int s3,int s4,int s5,int s6,int s7)
|
---|
1117 | {
|
---|
1118 | int r;
|
---|
1119 |
|
---|
1120 | __lzo_init_done = 1;
|
---|
1121 |
|
---|
1122 | #if 0
|
---|
1123 | if (v != LZO_VERSION)
|
---|
1124 | return LZO_E_ERROR;
|
---|
1125 | #else
|
---|
1126 | if (v == 0)
|
---|
1127 | return LZO_E_ERROR;
|
---|
1128 | #endif
|
---|
1129 |
|
---|
1130 | r = (s1 == (int) sizeof(short)) &&
|
---|
1131 | (s2 == (int) sizeof(int)) &&
|
---|
1132 | (s3 == (int) sizeof(long)) &&
|
---|
1133 | (s4 == (int) sizeof(lzo_uint32)) &&
|
---|
1134 | (s5 == (int) sizeof(lzo_uint)) &&
|
---|
1135 | (s6 == (int) sizeof(lzo_voidp)) &&
|
---|
1136 | (s7 == (int) sizeof(lzo_compress_t));
|
---|
1137 | if (!r)
|
---|
1138 | return LZO_E_ERROR;
|
---|
1139 |
|
---|
1140 | r = _lzo_config_check();
|
---|
1141 | if (r != LZO_E_OK)
|
---|
1142 | return r;
|
---|
1143 |
|
---|
1144 | return r;
|
---|
1145 | }
|
---|
1146 |
|
---|
1147 | #define LZO_NEED_DICT_H
|
---|
1148 | #define D_BITS 14
|
---|
1149 |
|
---|
1150 | #ifndef __LZO_CONFIG1X_H
|
---|
1151 | #define __LZO_CONFIG1X_H
|
---|
1152 |
|
---|
1153 | #if !defined(LZO1X) && !defined(LZO1Y)
|
---|
1154 | # define LZO1X
|
---|
1155 | #endif
|
---|
1156 |
|
---|
1157 | #if !defined(__LZO_IN_MINILZO)
|
---|
1158 | #include <lzo1x.h>
|
---|
1159 | #endif
|
---|
1160 |
|
---|
1161 | #define LZO_EOF_CODE
|
---|
1162 | #undef LZO_DETERMINISTIC
|
---|
1163 |
|
---|
1164 | #define M1_MAX_OFFSET 0x0400
|
---|
1165 | #ifndef M2_MAX_OFFSET
|
---|
1166 | #define M2_MAX_OFFSET 0x0800
|
---|
1167 | #endif
|
---|
1168 | #define M3_MAX_OFFSET 0x4000
|
---|
1169 | #define M4_MAX_OFFSET 0xbfff
|
---|
1170 |
|
---|
1171 | #define MX_MAX_OFFSET (M1_MAX_OFFSET + M2_MAX_OFFSET)
|
---|
1172 |
|
---|
1173 | #define M1_MIN_LEN 2
|
---|
1174 | #define M1_MAX_LEN 2
|
---|
1175 | #define M2_MIN_LEN 3
|
---|
1176 | #ifndef M2_MAX_LEN
|
---|
1177 | #define M2_MAX_LEN 8
|
---|
1178 | #endif
|
---|
1179 | #define M3_MIN_LEN 3
|
---|
1180 | #define M3_MAX_LEN 33
|
---|
1181 | #define M4_MIN_LEN 3
|
---|
1182 | #define M4_MAX_LEN 9
|
---|
1183 |
|
---|
1184 | #define M1_MARKER 0
|
---|
1185 | #define M2_MARKER 64
|
---|
1186 | #define M3_MARKER 32
|
---|
1187 | #define M4_MARKER 16
|
---|
1188 |
|
---|
1189 | #ifndef MIN_LOOKAHEAD
|
---|
1190 | #define MIN_LOOKAHEAD (M2_MAX_LEN + 1)
|
---|
1191 | #endif
|
---|
1192 |
|
---|
1193 | #if defined(LZO_NEED_DICT_H)
|
---|
1194 |
|
---|
1195 | #ifndef LZO_HASH
|
---|
1196 | #define LZO_HASH LZO_HASH_LZO_INCREMENTAL_B
|
---|
1197 | #endif
|
---|
1198 | #define DL_MIN_LEN M2_MIN_LEN
|
---|
1199 |
|
---|
1200 | #ifndef __LZO_DICT_H
|
---|
1201 | #define __LZO_DICT_H
|
---|
1202 |
|
---|
1203 | #ifdef __cplusplus
|
---|
1204 | extern "C" {
|
---|
1205 | #endif
|
---|
1206 |
|
---|
1207 | #if !defined(D_BITS) && defined(DBITS)
|
---|
1208 | # define D_BITS DBITS
|
---|
1209 | #endif
|
---|
1210 | #if !defined(D_BITS)
|
---|
1211 | # error D_BITS is not defined
|
---|
1212 | #endif
|
---|
1213 | #if (D_BITS < 16)
|
---|
1214 | # define D_SIZE LZO_SIZE(D_BITS)
|
---|
1215 | # define D_MASK LZO_MASK(D_BITS)
|
---|
1216 | #else
|
---|
1217 | # define D_SIZE LZO_USIZE(D_BITS)
|
---|
1218 | # define D_MASK LZO_UMASK(D_BITS)
|
---|
1219 | #endif
|
---|
1220 |
|
---|
1221 | #if !defined(DD_BITS)
|
---|
1222 | # define DD_BITS 0
|
---|
1223 | #endif
|
---|
1224 | #define DD_SIZE LZO_SIZE(DD_BITS)
|
---|
1225 | #define DD_MASK LZO_MASK(DD_BITS)
|
---|
1226 |
|
---|
1227 | #if !defined(DL_BITS)
|
---|
1228 | # define DL_BITS (D_BITS - DD_BITS)
|
---|
1229 | #endif
|
---|
1230 | #if (DL_BITS < 16)
|
---|
1231 | # define DL_SIZE LZO_SIZE(DL_BITS)
|
---|
1232 | # define DL_MASK LZO_MASK(DL_BITS)
|
---|
1233 | #else
|
---|
1234 | # define DL_SIZE LZO_USIZE(DL_BITS)
|
---|
1235 | # define DL_MASK LZO_UMASK(DL_BITS)
|
---|
1236 | #endif
|
---|
1237 |
|
---|
1238 | #if (D_BITS != DL_BITS + DD_BITS)
|
---|
1239 | # error D_BITS does not match
|
---|
1240 | #endif
|
---|
1241 | #if (D_BITS < 8 || D_BITS > 18)
|
---|
1242 | # error invalid D_BITS
|
---|
1243 | #endif
|
---|
1244 | #if (DL_BITS < 8 || DL_BITS > 18)
|
---|
1245 | # error invalid DL_BITS
|
---|
1246 | #endif
|
---|
1247 | #if (DD_BITS < 0 || DD_BITS > 6)
|
---|
1248 | # error invalid DD_BITS
|
---|
1249 | #endif
|
---|
1250 |
|
---|
1251 | #if !defined(DL_MIN_LEN)
|
---|
1252 | # define DL_MIN_LEN 3
|
---|
1253 | #endif
|
---|
1254 | #if !defined(DL_SHIFT)
|
---|
1255 | # define DL_SHIFT ((DL_BITS + (DL_MIN_LEN - 1)) / DL_MIN_LEN)
|
---|
1256 | #endif
|
---|
1257 |
|
---|
1258 | #define LZO_HASH_GZIP 1
|
---|
1259 | #define LZO_HASH_GZIP_INCREMENTAL 2
|
---|
1260 | #define LZO_HASH_LZO_INCREMENTAL_A 3
|
---|
1261 | #define LZO_HASH_LZO_INCREMENTAL_B 4
|
---|
1262 |
|
---|
1263 | #if !defined(LZO_HASH)
|
---|
1264 | # error choose a hashing strategy
|
---|
1265 | #endif
|
---|
1266 |
|
---|
1267 | #if (DL_MIN_LEN == 3)
|
---|
1268 | # define _DV2_A(p,shift1,shift2) \
|
---|
1269 | (((( (lzo_uint32)(p[0]) << shift1) ^ p[1]) << shift2) ^ p[2])
|
---|
1270 | # define _DV2_B(p,shift1,shift2) \
|
---|
1271 | (((( (lzo_uint32)(p[2]) << shift1) ^ p[1]) << shift2) ^ p[0])
|
---|
1272 | #elif (DL_MIN_LEN == 2)
|
---|
1273 | # define _DV2_A(p,shift1,shift2) \
|
---|
1274 | (( (lzo_uint32)(p[0]) << shift1) ^ p[1])
|
---|
1275 | # define _DV2_B(p,shift1,shift2) \
|
---|
1276 | (( (lzo_uint32)(p[1]) << shift1) ^ p[2])
|
---|
1277 | #else
|
---|
1278 | # error invalid DL_MIN_LEN
|
---|
1279 | #endif
|
---|
1280 |
|
---|
1281 | #define _DV_A(p,shift) _DV2_A(p,shift,shift)
|
---|
1282 | #define _DV_B(p,shift) _DV2_B(p,shift,shift)
|
---|
1283 |
|
---|
1284 | #if (LZO_HASH == LZO_HASH_GZIP)
|
---|
1285 |
|
---|
1286 | # define _DINDEX(dv,p) (_DV_A((p),DL_SHIFT))
|
---|
1287 |
|
---|
1288 | #elif (LZO_HASH == LZO_HASH_GZIP_INCREMENTAL)
|
---|
1289 |
|
---|
1290 | # define __LZO_HASH_INCREMENTAL
|
---|
1291 | # define DVAL_FIRST(dv,p) dv = _DV_A((p),DL_SHIFT)
|
---|
1292 | # define DVAL_NEXT(dv,p) dv = (((dv) << DL_SHIFT) ^ p[2])
|
---|
1293 | # define _DINDEX(dv,p) (dv)
|
---|
1294 | # define DVAL_LOOKAHEAD DL_MIN_LEN
|
---|
1295 |
|
---|
1296 | #elif (LZO_HASH == LZO_HASH_LZO_INCREMENTAL_A)
|
---|
1297 |
|
---|
1298 | # define __LZO_HASH_INCREMENTAL
|
---|
1299 | # define DVAL_FIRST(dv,p) dv = _DV_A((p),5)
|
---|
1300 | # define DVAL_NEXT(dv,p) \
|
---|
1301 | dv ^= (lzo_uint32)(p[-1]) << (2*5); dv = (((dv) << 5) ^ p[2])
|
---|
1302 | # define _DINDEX(dv,p) ((0x9f5f * (dv)) >> 5)
|
---|
1303 | # define DVAL_LOOKAHEAD DL_MIN_LEN
|
---|
1304 |
|
---|
1305 | #elif (LZO_HASH == LZO_HASH_LZO_INCREMENTAL_B)
|
---|
1306 |
|
---|
1307 | # define __LZO_HASH_INCREMENTAL
|
---|
1308 | # define DVAL_FIRST(dv,p) dv = _DV_B((p),5)
|
---|
1309 | # define DVAL_NEXT(dv,p) \
|
---|
1310 | dv ^= p[-1]; dv = (((dv) >> 5) ^ ((lzo_uint32)(p[2]) << (2*5)))
|
---|
1311 | # define _DINDEX(dv,p) ((0x9f5f * (dv)) >> 5)
|
---|
1312 | # define DVAL_LOOKAHEAD DL_MIN_LEN
|
---|
1313 |
|
---|
1314 | #else
|
---|
1315 | # error choose a hashing strategy
|
---|
1316 | #endif
|
---|
1317 |
|
---|
1318 | #ifndef DINDEX
|
---|
1319 | #define DINDEX(dv,p) (((_DINDEX(dv,p)) & DL_MASK) << DD_BITS)
|
---|
1320 | #endif
|
---|
1321 |
|
---|
1322 | #if !defined(__LZO_HASH_INCREMENTAL)
|
---|
1323 | # define DVAL_FIRST(dv,p) ((void) 0)
|
---|
1324 | # define DVAL_NEXT(dv,p) ((void) 0)
|
---|
1325 | # define DVAL_LOOKAHEAD 0
|
---|
1326 | #endif
|
---|
1327 |
|
---|
1328 | #if !defined(DVAL_ASSERT)
|
---|
1329 | #if defined(__LZO_HASH_INCREMENTAL) && !defined(NDEBUG)
|
---|
1330 | static void DVAL_ASSERT(lzo_uint32 dv, const lzo_byte *p)
|
---|
1331 | {
|
---|
1332 | lzo_uint32 df;
|
---|
1333 | DVAL_FIRST(df,(p));
|
---|
1334 | assert(DINDEX(dv,p) == DINDEX(df,p));
|
---|
1335 | }
|
---|
1336 | #else
|
---|
1337 | # define DVAL_ASSERT(dv,p) ((void) 0)
|
---|
1338 | #endif
|
---|
1339 | #endif
|
---|
1340 |
|
---|
1341 | #if defined(LZO_DICT_USE_PTR)
|
---|
1342 | # define lzo_dict_p const lzo_bytepp
|
---|
1343 | # define DENTRY(p,in) (p)
|
---|
1344 | # define GINDEX(m_pos,m_off,dict,dindex,in) m_pos = dict[dindex]
|
---|
1345 | #else
|
---|
1346 | # define lzo_dict_p lzo_uintp
|
---|
1347 | # define DENTRY(p,in) ((lzo_uint) ((p)-(in)))
|
---|
1348 | # define GINDEX(m_pos,m_off,dict,dindex,in) m_off = dict[dindex]
|
---|
1349 | #endif
|
---|
1350 |
|
---|
1351 | #if (DD_BITS == 0)
|
---|
1352 |
|
---|
1353 | # define UPDATE_D(dict,cycle,dv,p,in) dict[ DINDEX(dv,p) ] = DENTRY(p,in)
|
---|
1354 | # define UPDATE_I(dict,cycle,index,p,in) dict[index] = DENTRY(p,in)
|
---|
1355 | # define UPDATE_P(ptr,cycle,p,in) (ptr)[0] = DENTRY(p,in)
|
---|
1356 |
|
---|
1357 | #else
|
---|
1358 |
|
---|
1359 | # define UPDATE_D(dict,cycle,dv,p,in) \
|
---|
1360 | dict[ DINDEX(dv,p) + cycle++ ] = DENTRY(p,in); cycle &= DD_MASK
|
---|
1361 | # define UPDATE_I(dict,cycle,index,p,in) \
|
---|
1362 | dict[ (index) + cycle++ ] = DENTRY(p,in); cycle &= DD_MASK
|
---|
1363 | # define UPDATE_P(ptr,cycle,p,in) \
|
---|
1364 | (ptr) [ cycle++ ] = DENTRY(p,in); cycle &= DD_MASK
|
---|
1365 |
|
---|
1366 | #endif
|
---|
1367 |
|
---|
1368 | #if defined(LZO_DICT_USE_PTR)
|
---|
1369 |
|
---|
1370 | #define LZO_CHECK_MPOS_DET(m_pos,m_off,in,ip,max_offset) \
|
---|
1371 | (m_pos == NULL || (m_off = (lzo_moff_t) (ip - m_pos)) > max_offset)
|
---|
1372 |
|
---|
1373 | #define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \
|
---|
1374 | (BOUNDS_CHECKING_OFF_IN_EXPR( \
|
---|
1375 | (PTR_LT(m_pos,in) || \
|
---|
1376 | (lzo_cmoff_t) (m_off = (lzo_moff_t) PTR_DIFF(ip,m_pos)) <= 0 || \
|
---|
1377 | m_off > max_offset) ))
|
---|
1378 |
|
---|
1379 | #else
|
---|
1380 |
|
---|
1381 | #define LZO_CHECK_MPOS_DET(m_pos,m_off,in,ip,max_offset) \
|
---|
1382 | (m_off == 0 || \
|
---|
1383 | ((m_off = (lzo_moff_t) ((ip)-(in)) - m_off) > max_offset) || \
|
---|
1384 | (m_pos = (ip) - (m_off), 0) )
|
---|
1385 |
|
---|
1386 | #define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \
|
---|
1387 | ( (lzo_cmoff_t) ((m_off = (lzo_moff_t) ((ip)-(in)) - m_off) <= 0) || \
|
---|
1388 | (m_off > max_offset) || (m_pos = (ip) - (m_off), 0) )
|
---|
1389 |
|
---|
1390 | #endif
|
---|
1391 |
|
---|
1392 | #if defined(LZO_DETERMINISTIC)
|
---|
1393 | # define LZO_CHECK_MPOS LZO_CHECK_MPOS_DET
|
---|
1394 | #else
|
---|
1395 | # define LZO_CHECK_MPOS LZO_CHECK_MPOS_NON_DET
|
---|
1396 | #endif
|
---|
1397 |
|
---|
1398 | #ifdef __cplusplus
|
---|
1399 | }
|
---|
1400 | #endif
|
---|
1401 |
|
---|
1402 | #endif
|
---|
1403 |
|
---|
1404 | #endif
|
---|
1405 |
|
---|
1406 | #endif
|
---|
1407 |
|
---|
1408 | #define DO_COMPRESS lzo1x_1_compress
|
---|
1409 |
|
---|
1410 | static
|
---|
1411 | int do_compress ( const lzo_byte *in , lzo_uint in_len,
|
---|
1412 | lzo_byte *out, lzo_uint *out_len,
|
---|
1413 | lzo_voidp wrkmem )
|
---|
1414 | {
|
---|
1415 | #if 1 && defined(__GNUC__) && defined(__i386__)
|
---|
1416 | register const lzo_byte *ip __asm__("%esi");
|
---|
1417 | #else
|
---|
1418 | register const lzo_byte *ip;
|
---|
1419 | #endif
|
---|
1420 | lzo_uint32 dv;
|
---|
1421 | lzo_byte *op;
|
---|
1422 | const lzo_byte * const in_end = in + in_len;
|
---|
1423 | const lzo_byte * const ip_end = in + in_len - M2_MAX_LEN - 5;
|
---|
1424 | const lzo_byte *ii;
|
---|
1425 | lzo_dict_p const dict = (lzo_dict_p) wrkmem;
|
---|
1426 |
|
---|
1427 | op = out;
|
---|
1428 | ip = in;
|
---|
1429 | ii = ip;
|
---|
1430 |
|
---|
1431 | DVAL_FIRST(dv,ip); UPDATE_D(dict,cycle,dv,ip,in); ip++;
|
---|
1432 | DVAL_NEXT(dv,ip); UPDATE_D(dict,cycle,dv,ip,in); ip++;
|
---|
1433 | DVAL_NEXT(dv,ip); UPDATE_D(dict,cycle,dv,ip,in); ip++;
|
---|
1434 | DVAL_NEXT(dv,ip); UPDATE_D(dict,cycle,dv,ip,in); ip++;
|
---|
1435 |
|
---|
1436 | while (1)
|
---|
1437 | {
|
---|
1438 | #if 1 && defined(__GNUC__) && defined(__i386__)
|
---|
1439 | register const lzo_byte *m_pos __asm__("%edi");
|
---|
1440 | #else
|
---|
1441 | register const lzo_byte *m_pos;
|
---|
1442 | #endif
|
---|
1443 | lzo_uint m_len;
|
---|
1444 | lzo_moff_t m_off;
|
---|
1445 | lzo_uint lit;
|
---|
1446 |
|
---|
1447 | {
|
---|
1448 | lzo_uint dindex = DINDEX(dv,ip);
|
---|
1449 | GINDEX(m_pos,m_off,dict,dindex,in);
|
---|
1450 | UPDATE_I(dict,cycle,dindex,ip,in);
|
---|
1451 | }
|
---|
1452 |
|
---|
1453 | if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET))
|
---|
1454 | {
|
---|
1455 | }
|
---|
1456 | #if defined(LZO_UNALIGNED_OK_2)
|
---|
1457 | else if (* (const lzo_ushortp) m_pos != * (const lzo_ushortp) ip)
|
---|
1458 | #else
|
---|
1459 | else if (m_pos[0] != ip[0] || m_pos[1] != ip[1])
|
---|
1460 | #endif
|
---|
1461 | {
|
---|
1462 | }
|
---|
1463 | else
|
---|
1464 | {
|
---|
1465 | if (m_pos[2] == ip[2])
|
---|
1466 | {
|
---|
1467 | lit = ip - ii;
|
---|
1468 | m_pos += 3;
|
---|
1469 | if (m_off <= M2_MAX_OFFSET)
|
---|
1470 | goto match;
|
---|
1471 | #if 0
|
---|
1472 | if (lit <= 3)
|
---|
1473 | goto match;
|
---|
1474 | #else
|
---|
1475 | if (lit == 3)
|
---|
1476 | {
|
---|
1477 | assert(op - 2 > out); op[-2] |= LZO_BYTE(3);
|
---|
1478 | *op++ = *ii++; *op++ = *ii++; *op++ = *ii++;
|
---|
1479 | goto code_match;
|
---|
1480 | }
|
---|
1481 | #endif
|
---|
1482 | if (*m_pos == ip[3])
|
---|
1483 | goto match;
|
---|
1484 | }
|
---|
1485 | else
|
---|
1486 | {
|
---|
1487 |
|
---|
1488 | #if 0
|
---|
1489 |
|
---|
1490 | #if 0
|
---|
1491 | if (m_off <= M1_MAX_OFFSET && lit > 0 && lit <= 3)
|
---|
1492 | #else
|
---|
1493 | if (m_off <= M1_MAX_OFFSET && lit == 3)
|
---|
1494 | #endif
|
---|
1495 | {
|
---|
1496 | register lzo_uint t;
|
---|
1497 |
|
---|
1498 | t = lit;
|
---|
1499 | assert(op - 2 > out); op[-2] |= LZO_BYTE(t);
|
---|
1500 | do *op++ = *ii++; while (--t > 0);
|
---|
1501 | assert(ii == ip);
|
---|
1502 | m_off -= 1;
|
---|
1503 | *op++ = LZO_BYTE(M1_MARKER | ((m_off & 3) << 2));
|
---|
1504 | *op++ = LZO_BYTE(m_off >> 2);
|
---|
1505 | ip += 2;
|
---|
1506 | goto match_done;
|
---|
1507 | }
|
---|
1508 | #endif
|
---|
1509 | }
|
---|
1510 | }
|
---|
1511 |
|
---|
1512 | ++ip;
|
---|
1513 | if (ip >= ip_end)
|
---|
1514 | break;
|
---|
1515 | DVAL_NEXT(dv,ip);
|
---|
1516 | continue;
|
---|
1517 |
|
---|
1518 | match:
|
---|
1519 |
|
---|
1520 | if (lit > 0)
|
---|
1521 | {
|
---|
1522 | register lzo_uint t = lit;
|
---|
1523 |
|
---|
1524 | if (t <= 3)
|
---|
1525 | {
|
---|
1526 | assert(op - 2 > out);
|
---|
1527 | op[-2] |= LZO_BYTE(t);
|
---|
1528 | }
|
---|
1529 | else if (t <= 18)
|
---|
1530 | *op++ = LZO_BYTE(t - 3);
|
---|
1531 | else
|
---|
1532 | {
|
---|
1533 | register lzo_uint tt = t - 18;
|
---|
1534 |
|
---|
1535 | *op++ = 0;
|
---|
1536 | while (tt > 255)
|
---|
1537 | {
|
---|
1538 | tt -= 255;
|
---|
1539 | *op++ = 0;
|
---|
1540 | }
|
---|
1541 | assert(tt > 0);
|
---|
1542 | *op++ = LZO_BYTE(tt);
|
---|
1543 | }
|
---|
1544 | do *op++ = *ii++; while (--t > 0);
|
---|
1545 | }
|
---|
1546 |
|
---|
1547 | code_match:
|
---|
1548 | assert(ii == ip);
|
---|
1549 | ip += 3;
|
---|
1550 | if (*m_pos++ != *ip++ || *m_pos++ != *ip++ || *m_pos++ != *ip++ ||
|
---|
1551 | *m_pos++ != *ip++ || *m_pos++ != *ip++ || *m_pos++ != *ip++
|
---|
1552 | #ifdef LZO1Y
|
---|
1553 | || *m_pos++ != *ip++ || *m_pos++ != *ip++ || *m_pos++ != *ip++
|
---|
1554 | || *m_pos++ != *ip++ || *m_pos++ != *ip++ || *m_pos++ != *ip++
|
---|
1555 | #endif
|
---|
1556 | )
|
---|
1557 | {
|
---|
1558 | --ip;
|
---|
1559 | m_len = ip - ii;
|
---|
1560 | assert(m_len >= 3); assert(m_len <= M2_MAX_LEN);
|
---|
1561 |
|
---|
1562 | if (m_off <= M2_MAX_OFFSET)
|
---|
1563 | {
|
---|
1564 | m_off -= 1;
|
---|
1565 | #if defined(LZO1X)
|
---|
1566 | *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2));
|
---|
1567 | *op++ = LZO_BYTE(m_off >> 3);
|
---|
1568 | #elif defined(LZO1Y)
|
---|
1569 | *op++ = LZO_BYTE(((m_len + 1) << 4) | ((m_off & 3) << 2));
|
---|
1570 | *op++ = LZO_BYTE(m_off >> 2);
|
---|
1571 | #endif
|
---|
1572 | }
|
---|
1573 | else if (m_off <= M3_MAX_OFFSET)
|
---|
1574 | {
|
---|
1575 | m_off -= 1;
|
---|
1576 | *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
|
---|
1577 | goto m3_m4_offset;
|
---|
1578 | }
|
---|
1579 | else
|
---|
1580 | #if defined(LZO1X)
|
---|
1581 | {
|
---|
1582 | m_off -= 0x4000;
|
---|
1583 | assert(m_off > 0); assert(m_off <= 0x7fff);
|
---|
1584 | *op++ = LZO_BYTE(M4_MARKER |
|
---|
1585 | ((m_off & 0x4000) >> 11) | (m_len - 2));
|
---|
1586 | goto m3_m4_offset;
|
---|
1587 | }
|
---|
1588 | #elif defined(LZO1Y)
|
---|
1589 | goto m4_match;
|
---|
1590 | #endif
|
---|
1591 | }
|
---|
1592 | else
|
---|
1593 | {
|
---|
1594 | {
|
---|
1595 | const lzo_byte *end;
|
---|
1596 | end = in_end;
|
---|
1597 | while (ip < end && *m_pos == *ip)
|
---|
1598 | m_pos++, ip++;
|
---|
1599 | m_len = (ip - ii);
|
---|
1600 | }
|
---|
1601 | assert(m_len > M2_MAX_LEN);
|
---|
1602 |
|
---|
1603 | if (m_off <= M3_MAX_OFFSET)
|
---|
1604 | {
|
---|
1605 | m_off -= 1;
|
---|
1606 | if (m_len <= 33)
|
---|
1607 | *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
|
---|
1608 | else
|
---|
1609 | {
|
---|
1610 | m_len -= 33;
|
---|
1611 | *op++ = M3_MARKER | 0;
|
---|
1612 | goto m3_m4_len;
|
---|
1613 | }
|
---|
1614 | }
|
---|
1615 | else
|
---|
1616 | {
|
---|
1617 | #if defined(LZO1Y)
|
---|
1618 | m4_match:
|
---|
1619 | #endif
|
---|
1620 | m_off -= 0x4000;
|
---|
1621 | assert(m_off > 0); assert(m_off <= 0x7fff);
|
---|
1622 | if (m_len <= M4_MAX_LEN)
|
---|
1623 | *op++ = LZO_BYTE(M4_MARKER |
|
---|
1624 | ((m_off & 0x4000) >> 11) | (m_len - 2));
|
---|
1625 | else
|
---|
1626 | {
|
---|
1627 | m_len -= M4_MAX_LEN;
|
---|
1628 | *op++ = LZO_BYTE(M4_MARKER | ((m_off & 0x4000) >> 11));
|
---|
1629 | m3_m4_len:
|
---|
1630 | while (m_len > 255)
|
---|
1631 | {
|
---|
1632 | m_len -= 255;
|
---|
1633 | *op++ = 0;
|
---|
1634 | }
|
---|
1635 | assert(m_len > 0);
|
---|
1636 | *op++ = LZO_BYTE(m_len);
|
---|
1637 | }
|
---|
1638 | }
|
---|
1639 |
|
---|
1640 | m3_m4_offset:
|
---|
1641 | *op++ = LZO_BYTE((m_off & 63) << 2);
|
---|
1642 | *op++ = LZO_BYTE(m_off >> 6);
|
---|
1643 | }
|
---|
1644 |
|
---|
1645 | #if 0
|
---|
1646 | match_done:
|
---|
1647 | #endif
|
---|
1648 | ii = ip;
|
---|
1649 | if (ip >= ip_end)
|
---|
1650 | break;
|
---|
1651 | DVAL_FIRST(dv,ip);
|
---|
1652 | }
|
---|
1653 |
|
---|
1654 | if (in_end - ii > 0)
|
---|
1655 | {
|
---|
1656 | register lzo_uint t = in_end - ii;
|
---|
1657 |
|
---|
1658 | if (op == out && t <= 238)
|
---|
1659 | *op++ = LZO_BYTE(17 + t);
|
---|
1660 | else if (t <= 3)
|
---|
1661 | op[-2] |= LZO_BYTE(t);
|
---|
1662 | else if (t <= 18)
|
---|
1663 | *op++ = LZO_BYTE(t - 3);
|
---|
1664 | else
|
---|
1665 | {
|
---|
1666 | register lzo_uint tt = t - 18;
|
---|
1667 |
|
---|
1668 | *op++ = 0;
|
---|
1669 | while (tt > 255)
|
---|
1670 | {
|
---|
1671 | tt -= 255;
|
---|
1672 | *op++ = 0;
|
---|
1673 | }
|
---|
1674 | assert(tt > 0);
|
---|
1675 | *op++ = LZO_BYTE(tt);
|
---|
1676 | }
|
---|
1677 | do *op++ = *ii++; while (--t > 0);
|
---|
1678 | }
|
---|
1679 |
|
---|
1680 | *out_len = op - out;
|
---|
1681 | return LZO_E_OK;
|
---|
1682 | }
|
---|
1683 |
|
---|
1684 | LZO_PUBLIC(int)
|
---|
1685 | DO_COMPRESS ( const lzo_byte *in , lzo_uint in_len,
|
---|
1686 | lzo_byte *out, lzo_uint *out_len,
|
---|
1687 | lzo_voidp wrkmem )
|
---|
1688 | {
|
---|
1689 | lzo_byte *op = out;
|
---|
1690 | int r = LZO_E_OK;
|
---|
1691 |
|
---|
1692 | if (in_len <= 0)
|
---|
1693 | *out_len = 0;
|
---|
1694 | else if (in_len <= M2_MAX_LEN + 5)
|
---|
1695 | {
|
---|
1696 | *op++ = LZO_BYTE(17 + in_len);
|
---|
1697 | do *op++ = *in++; while (--in_len > 0);
|
---|
1698 | *out_len = op - out;
|
---|
1699 | }
|
---|
1700 | else
|
---|
1701 | r = do_compress(in,in_len,out,out_len,wrkmem);
|
---|
1702 |
|
---|
1703 | if (r == LZO_E_OK)
|
---|
1704 | {
|
---|
1705 | op = out + *out_len;
|
---|
1706 | *op++ = M4_MARKER | 1;
|
---|
1707 | *op++ = 0;
|
---|
1708 | *op++ = 0;
|
---|
1709 | *out_len += 3;
|
---|
1710 | }
|
---|
1711 |
|
---|
1712 | return r;
|
---|
1713 | }
|
---|
1714 |
|
---|
1715 | #undef LZO_TEST_DECOMPRESS_OVERRUN
|
---|
1716 | #undef LZO_TEST_DECOMPRESS_OVERRUN_INPUT
|
---|
1717 | #undef LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT
|
---|
1718 | #undef LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND
|
---|
1719 | #undef DO_DECOMPRESS
|
---|
1720 | #define DO_DECOMPRESS lzo1x_decompress
|
---|
1721 |
|
---|
1722 | #if defined(LZO_TEST_DECOMPRESS_OVERRUN)
|
---|
1723 | # if !defined(LZO_TEST_DECOMPRESS_OVERRUN_INPUT)
|
---|
1724 | # define LZO_TEST_DECOMPRESS_OVERRUN_INPUT 2
|
---|
1725 | # endif
|
---|
1726 | # if !defined(LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT)
|
---|
1727 | # define LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT 2
|
---|
1728 | # endif
|
---|
1729 | # if !defined(LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND)
|
---|
1730 | # define LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND
|
---|
1731 | # endif
|
---|
1732 | #endif
|
---|
1733 |
|
---|
1734 | #undef TEST_IP
|
---|
1735 | #undef TEST_OP
|
---|
1736 | #undef TEST_LOOKBEHIND
|
---|
1737 | #undef NEED_IP
|
---|
1738 | #undef NEED_OP
|
---|
1739 | #undef HAVE_TEST_IP
|
---|
1740 | #undef HAVE_TEST_OP
|
---|
1741 | #undef HAVE_NEED_IP
|
---|
1742 | #undef HAVE_NEED_OP
|
---|
1743 | #undef HAVE_ANY_IP
|
---|
1744 | #undef HAVE_ANY_OP
|
---|
1745 |
|
---|
1746 | #if defined(LZO_TEST_DECOMPRESS_OVERRUN_INPUT)
|
---|
1747 | # if (LZO_TEST_DECOMPRESS_OVERRUN_INPUT >= 1)
|
---|
1748 | # define TEST_IP (ip < ip_end)
|
---|
1749 | # endif
|
---|
1750 | # if (LZO_TEST_DECOMPRESS_OVERRUN_INPUT >= 2)
|
---|
1751 | # define NEED_IP(x) \
|
---|
1752 | if (ip_end - ip < (lzo_ptrdiff_t)(x)) goto input_overrun
|
---|
1753 | # endif
|
---|
1754 | #endif
|
---|
1755 |
|
---|
1756 | #if defined(LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT)
|
---|
1757 | # if (LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT >= 1)
|
---|
1758 | # define TEST_OP (op <= op_end)
|
---|
1759 | # endif
|
---|
1760 | # if (LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT >= 2)
|
---|
1761 | # undef TEST_OP
|
---|
1762 | # define NEED_OP(x) \
|
---|
1763 | if (op_end - op < (lzo_ptrdiff_t)(x)) goto output_overrun
|
---|
1764 | # endif
|
---|
1765 | #endif
|
---|
1766 |
|
---|
1767 | #if defined(LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND)
|
---|
1768 | # define TEST_LOOKBEHIND(m_pos,out) if (m_pos < out) goto lookbehind_overrun
|
---|
1769 | #else
|
---|
1770 | # define TEST_LOOKBEHIND(m_pos,op) ((void) 0)
|
---|
1771 | #endif
|
---|
1772 |
|
---|
1773 | #if !defined(LZO_EOF_CODE) && !defined(TEST_IP)
|
---|
1774 |
|
---|
1775 | # define TEST_IP (ip < ip_end)
|
---|
1776 | #endif
|
---|
1777 |
|
---|
1778 | #if defined(TEST_IP)
|
---|
1779 | # define HAVE_TEST_IP
|
---|
1780 | #else
|
---|
1781 | # define TEST_IP 1
|
---|
1782 | #endif
|
---|
1783 | #if defined(TEST_OP)
|
---|
1784 | # define HAVE_TEST_OP
|
---|
1785 | #else
|
---|
1786 | # define TEST_OP 1
|
---|
1787 | #endif
|
---|
1788 |
|
---|
1789 | #if defined(NEED_IP)
|
---|
1790 | # define HAVE_NEED_IP
|
---|
1791 | #else
|
---|
1792 | # define NEED_IP(x) ((void) 0)
|
---|
1793 | #endif
|
---|
1794 | #if defined(NEED_OP)
|
---|
1795 | # define HAVE_NEED_OP
|
---|
1796 | #else
|
---|
1797 | # define NEED_OP(x) ((void) 0)
|
---|
1798 | #endif
|
---|
1799 |
|
---|
1800 | #if defined(HAVE_TEST_IP) || defined(HAVE_NEED_IP)
|
---|
1801 | # define HAVE_ANY_IP
|
---|
1802 | #endif
|
---|
1803 | #if defined(HAVE_TEST_OP) || defined(HAVE_NEED_OP)
|
---|
1804 | # define HAVE_ANY_OP
|
---|
1805 | #endif
|
---|
1806 |
|
---|
1807 | #if defined(HAVE_ANY_IP) && defined(HAVE_ANY_OP)
|
---|
1808 |
|
---|
1809 | # undef LZO_OPTIMIZE_GNUC_i386
|
---|
1810 | #endif
|
---|
1811 |
|
---|
1812 | LZO_PUBLIC(int)
|
---|
1813 | DO_DECOMPRESS ( const lzo_byte *in , lzo_uint in_len,
|
---|
1814 | lzo_byte *out, lzo_uint *out_len,
|
---|
1815 | lzo_voidp wrkmem )
|
---|
1816 | {
|
---|
1817 | #if 0 && defined(__GNUC__) && defined(__i386__)
|
---|
1818 | register lzo_byte *op __asm__("%edi");
|
---|
1819 | register const lzo_byte *ip __asm__("%esi");
|
---|
1820 | register lzo_uint t __asm__("%ecx");
|
---|
1821 | register const lzo_byte *m_pos __asm__("%ebx");
|
---|
1822 | #else
|
---|
1823 | register lzo_byte *op;
|
---|
1824 | register const lzo_byte *ip;
|
---|
1825 | register lzo_uint t;
|
---|
1826 | register const lzo_byte *m_pos;
|
---|
1827 | #endif
|
---|
1828 |
|
---|
1829 | const lzo_byte * const ip_end = in + in_len;
|
---|
1830 | #if defined(HAVE_ANY_OP)
|
---|
1831 | lzo_byte * const op_end = out + *out_len;
|
---|
1832 | #endif
|
---|
1833 |
|
---|
1834 | LZO_UNUSED(wrkmem);
|
---|
1835 |
|
---|
1836 | *out_len = 0;
|
---|
1837 |
|
---|
1838 | op = out;
|
---|
1839 | ip = in;
|
---|
1840 |
|
---|
1841 | if (*ip > 17)
|
---|
1842 | {
|
---|
1843 | t = *ip++ - 17;
|
---|
1844 | assert(t > 0); NEED_OP(t); NEED_IP(t+1);
|
---|
1845 | do *op++ = *ip++; while (--t > 0);
|
---|
1846 | goto first_literal_run;
|
---|
1847 | }
|
---|
1848 |
|
---|
1849 | while (TEST_IP && TEST_OP)
|
---|
1850 | {
|
---|
1851 | t = *ip++;
|
---|
1852 | if (t >= 16)
|
---|
1853 | goto match;
|
---|
1854 |
|
---|
1855 | if (t == 0)
|
---|
1856 | {
|
---|
1857 | NEED_IP(1);
|
---|
1858 | while (*ip == 0)
|
---|
1859 | {
|
---|
1860 | t += 255;
|
---|
1861 | ip++;
|
---|
1862 | NEED_IP(1);
|
---|
1863 | }
|
---|
1864 | t += 15 + *ip++;
|
---|
1865 | }
|
---|
1866 |
|
---|
1867 | assert(t > 0); NEED_OP(t+3); NEED_IP(t+4);
|
---|
1868 | #if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
|
---|
1869 | #if !defined(LZO_UNALIGNED_OK_4)
|
---|
1870 | if (PTR_ALIGNED2_4(op,ip))
|
---|
1871 | {
|
---|
1872 | #endif
|
---|
1873 | * (lzo_uint32p) op = * (const lzo_uint32p) ip;
|
---|
1874 | op += 4; ip += 4;
|
---|
1875 | if (--t > 0)
|
---|
1876 | {
|
---|
1877 | if (t >= 4)
|
---|
1878 | {
|
---|
1879 | do {
|
---|
1880 | * (lzo_uint32p) op = * (const lzo_uint32p) ip;
|
---|
1881 | op += 4; ip += 4; t -= 4;
|
---|
1882 | } while (t >= 4);
|
---|
1883 | if (t > 0) do *op++ = *ip++; while (--t > 0);
|
---|
1884 | }
|
---|
1885 | else
|
---|
1886 | do *op++ = *ip++; while (--t > 0);
|
---|
1887 | }
|
---|
1888 | #if !defined(LZO_UNALIGNED_OK_4)
|
---|
1889 | }
|
---|
1890 | else
|
---|
1891 | #endif
|
---|
1892 | #endif
|
---|
1893 | #if !defined(LZO_UNALIGNED_OK_4)
|
---|
1894 | {
|
---|
1895 | *op++ = *ip++; *op++ = *ip++; *op++ = *ip++;
|
---|
1896 | do *op++ = *ip++; while (--t > 0);
|
---|
1897 | }
|
---|
1898 | #endif
|
---|
1899 |
|
---|
1900 | first_literal_run:
|
---|
1901 |
|
---|
1902 | t = *ip++;
|
---|
1903 |
|
---|
1904 | #if defined(LZO1X_0) || defined(LZO1Y_0)
|
---|
1905 | assert(t >= 16);
|
---|
1906 | goto match;
|
---|
1907 | #else
|
---|
1908 | if (t >= 16)
|
---|
1909 | goto match;
|
---|
1910 | m_pos = op - 1 - M2_MAX_OFFSET;
|
---|
1911 | m_pos -= t >> 2;
|
---|
1912 | m_pos -= *ip++ << 2;
|
---|
1913 | TEST_LOOKBEHIND(m_pos,out); NEED_OP(3);
|
---|
1914 | *op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos;
|
---|
1915 | goto match_done;
|
---|
1916 | #endif
|
---|
1917 |
|
---|
1918 | while (TEST_IP && TEST_OP)
|
---|
1919 | {
|
---|
1920 | match:
|
---|
1921 | if (t >= 64)
|
---|
1922 | {
|
---|
1923 | m_pos = op - 1;
|
---|
1924 | #if defined(LZO1X)
|
---|
1925 | m_pos -= (t >> 2) & 7;
|
---|
1926 | m_pos -= *ip++ << 3;
|
---|
1927 | t = (t >> 5) - 1;
|
---|
1928 | #elif defined(LZO1Y)
|
---|
1929 | m_pos -= (t >> 2) & 3;
|
---|
1930 | m_pos -= *ip++ << 2;
|
---|
1931 | t = (t >> 4) - 3;
|
---|
1932 | #endif
|
---|
1933 | TEST_LOOKBEHIND(m_pos,out); assert(t > 0); NEED_OP(t+3-1);
|
---|
1934 | goto copy_match;
|
---|
1935 | }
|
---|
1936 | else if (t >= 32)
|
---|
1937 | {
|
---|
1938 | t &= 31;
|
---|
1939 | if (t == 0)
|
---|
1940 | {
|
---|
1941 | NEED_IP(1);
|
---|
1942 | while (*ip == 0)
|
---|
1943 | {
|
---|
1944 | t += 255;
|
---|
1945 | ip++;
|
---|
1946 | NEED_IP(1);
|
---|
1947 | }
|
---|
1948 | t += 31 + *ip++;
|
---|
1949 | }
|
---|
1950 | m_pos = op - 1;
|
---|
1951 | #if defined(LZO_UNALIGNED_OK_2) && (LZO_BYTE_ORDER == LZO_LITTLE_ENDIAN)
|
---|
1952 | m_pos -= (* (const lzo_ushortp) ip) >> 2;
|
---|
1953 | ip += 2;
|
---|
1954 | #else
|
---|
1955 | m_pos -= *ip++ >> 2;
|
---|
1956 | m_pos -= *ip++ << 6;
|
---|
1957 | #endif
|
---|
1958 | }
|
---|
1959 | #if defined(LZO1X_0) || defined(LZO1Y_0)
|
---|
1960 | else
|
---|
1961 | {
|
---|
1962 | assert(t >= 16);
|
---|
1963 | #else
|
---|
1964 | else if (t >= 16)
|
---|
1965 | {
|
---|
1966 | #endif
|
---|
1967 | m_pos = op;
|
---|
1968 | m_pos -= (t & 8) << 11;
|
---|
1969 | t &= 7;
|
---|
1970 | if (t == 0)
|
---|
1971 | {
|
---|
1972 | NEED_IP(1);
|
---|
1973 | while (*ip == 0)
|
---|
1974 | {
|
---|
1975 | t += 255;
|
---|
1976 | ip++;
|
---|
1977 | NEED_IP(1);
|
---|
1978 | }
|
---|
1979 | t += 7 + *ip++;
|
---|
1980 | }
|
---|
1981 | #if defined(LZO_UNALIGNED_OK_2) && (LZO_BYTE_ORDER == LZO_LITTLE_ENDIAN)
|
---|
1982 | m_pos -= (* (const lzo_ushortp) ip) >> 2;
|
---|
1983 | ip += 2;
|
---|
1984 | #else
|
---|
1985 | m_pos -= *ip++ >> 2;
|
---|
1986 | m_pos -= *ip++ << 6;
|
---|
1987 | #endif
|
---|
1988 | if (m_pos == op)
|
---|
1989 | goto eof_found;
|
---|
1990 | m_pos -= 0x4000;
|
---|
1991 | }
|
---|
1992 | #if !defined(LZO1X_0) && !defined(LZO1Y_0)
|
---|
1993 | else
|
---|
1994 | {
|
---|
1995 | m_pos = op - 1;
|
---|
1996 | m_pos -= t >> 2;
|
---|
1997 | m_pos -= *ip++ << 2;
|
---|
1998 | TEST_LOOKBEHIND(m_pos,out); NEED_OP(2);
|
---|
1999 | *op++ = *m_pos++; *op++ = *m_pos;
|
---|
2000 | goto match_done;
|
---|
2001 | }
|
---|
2002 | #endif
|
---|
2003 |
|
---|
2004 | TEST_LOOKBEHIND(m_pos,out); assert(t > 0); NEED_OP(t+3-1);
|
---|
2005 | #if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
|
---|
2006 | #if !defined(LZO_UNALIGNED_OK_4)
|
---|
2007 | if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos))
|
---|
2008 | {
|
---|
2009 | assert((op - m_pos) >= 4);
|
---|
2010 | #else
|
---|
2011 | if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4)
|
---|
2012 | {
|
---|
2013 | #endif
|
---|
2014 | * (lzo_uint32p) op = * (const lzo_uint32p) m_pos;
|
---|
2015 | op += 4; m_pos += 4; t -= 4 - (3 - 1);
|
---|
2016 | do {
|
---|
2017 | * (lzo_uint32p) op = * (const lzo_uint32p) m_pos;
|
---|
2018 | op += 4; m_pos += 4; t -= 4;
|
---|
2019 | } while (t >= 4);
|
---|
2020 | if (t > 0) do *op++ = *m_pos++; while (--t > 0);
|
---|
2021 | }
|
---|
2022 | else
|
---|
2023 | #endif
|
---|
2024 | {
|
---|
2025 | copy_match:
|
---|
2026 | *op++ = *m_pos++; *op++ = *m_pos++;
|
---|
2027 | do *op++ = *m_pos++; while (--t > 0);
|
---|
2028 | }
|
---|
2029 |
|
---|
2030 | match_done:
|
---|
2031 | t = ip[-2] & 3;
|
---|
2032 | if (t == 0)
|
---|
2033 | break;
|
---|
2034 |
|
---|
2035 | assert(t > 0); NEED_OP(t); NEED_IP(t+1);
|
---|
2036 | do *op++ = *ip++; while (--t > 0);
|
---|
2037 | t = *ip++;
|
---|
2038 | }
|
---|
2039 | }
|
---|
2040 |
|
---|
2041 | #if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP)
|
---|
2042 |
|
---|
2043 | *out_len = op - out;
|
---|
2044 | return LZO_E_EOF_NOT_FOUND;
|
---|
2045 | #endif
|
---|
2046 |
|
---|
2047 | eof_found:
|
---|
2048 | assert(t == 1);
|
---|
2049 | *out_len = op - out;
|
---|
2050 | return (ip == ip_end ? LZO_E_OK :
|
---|
2051 | (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN));
|
---|
2052 |
|
---|
2053 | #if defined(HAVE_NEED_IP)
|
---|
2054 | input_overrun:
|
---|
2055 | *out_len = op - out;
|
---|
2056 | return LZO_E_INPUT_OVERRUN;
|
---|
2057 | #endif
|
---|
2058 |
|
---|
2059 | #if defined(HAVE_NEED_OP)
|
---|
2060 | output_overrun:
|
---|
2061 | *out_len = op - out;
|
---|
2062 | return LZO_E_OUTPUT_OVERRUN;
|
---|
2063 | #endif
|
---|
2064 |
|
---|
2065 | #if defined(LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND)
|
---|
2066 | lookbehind_overrun:
|
---|
2067 | *out_len = op - out;
|
---|
2068 | return LZO_E_LOOKBEHIND_OVERRUN;
|
---|
2069 | #endif
|
---|
2070 | }
|
---|
2071 |
|
---|
2072 | #define LZO_TEST_DECOMPRESS_OVERRUN
|
---|
2073 | #undef DO_DECOMPRESS
|
---|
2074 | #define DO_DECOMPRESS lzo1x_decompress_safe
|
---|
2075 |
|
---|
2076 | #if defined(LZO_TEST_DECOMPRESS_OVERRUN)
|
---|
2077 | # if !defined(LZO_TEST_DECOMPRESS_OVERRUN_INPUT)
|
---|
2078 | # define LZO_TEST_DECOMPRESS_OVERRUN_INPUT 2
|
---|
2079 | # endif
|
---|
2080 | # if !defined(LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT)
|
---|
2081 | # define LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT 2
|
---|
2082 | # endif
|
---|
2083 | # if !defined(LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND)
|
---|
2084 | # define LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND
|
---|
2085 | # endif
|
---|
2086 | #endif
|
---|
2087 |
|
---|
2088 | #undef TEST_IP
|
---|
2089 | #undef TEST_OP
|
---|
2090 | #undef TEST_LOOKBEHIND
|
---|
2091 | #undef NEED_IP
|
---|
2092 | #undef NEED_OP
|
---|
2093 | #undef HAVE_TEST_IP
|
---|
2094 | #undef HAVE_TEST_OP
|
---|
2095 | #undef HAVE_NEED_IP
|
---|
2096 | #undef HAVE_NEED_OP
|
---|
2097 | #undef HAVE_ANY_IP
|
---|
2098 | #undef HAVE_ANY_OP
|
---|
2099 |
|
---|
2100 | #if defined(LZO_TEST_DECOMPRESS_OVERRUN_INPUT)
|
---|
2101 | # if (LZO_TEST_DECOMPRESS_OVERRUN_INPUT >= 1)
|
---|
2102 | # define TEST_IP (ip < ip_end)
|
---|
2103 | # endif
|
---|
2104 | # if (LZO_TEST_DECOMPRESS_OVERRUN_INPUT >= 2)
|
---|
2105 | # define NEED_IP(x) \
|
---|
2106 | if (ip_end - ip < (lzo_ptrdiff_t)(x)) goto input_overrun
|
---|
2107 | # endif
|
---|
2108 | #endif
|
---|
2109 |
|
---|
2110 | #if defined(LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT)
|
---|
2111 | # if (LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT >= 1)
|
---|
2112 | # define TEST_OP (op <= op_end)
|
---|
2113 | # endif
|
---|
2114 | # if (LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT >= 2)
|
---|
2115 | # undef TEST_OP
|
---|
2116 | # define NEED_OP(x) \
|
---|
2117 | if (op_end - op < (lzo_ptrdiff_t)(x)) goto output_overrun
|
---|
2118 | # endif
|
---|
2119 | #endif
|
---|
2120 |
|
---|
2121 | #if defined(LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND)
|
---|
2122 | # define TEST_LOOKBEHIND(m_pos,out) if (m_pos < out) goto lookbehind_overrun
|
---|
2123 | #else
|
---|
2124 | # define TEST_LOOKBEHIND(m_pos,op) ((void) 0)
|
---|
2125 | #endif
|
---|
2126 |
|
---|
2127 | #if !defined(LZO_EOF_CODE) && !defined(TEST_IP)
|
---|
2128 |
|
---|
2129 | # define TEST_IP (ip < ip_end)
|
---|
2130 | #endif
|
---|
2131 |
|
---|
2132 | #if defined(TEST_IP)
|
---|
2133 | # define HAVE_TEST_IP
|
---|
2134 | #else
|
---|
2135 | # define TEST_IP 1
|
---|
2136 | #endif
|
---|
2137 | #if defined(TEST_OP)
|
---|
2138 | # define HAVE_TEST_OP
|
---|
2139 | #else
|
---|
2140 | # define TEST_OP 1
|
---|
2141 | #endif
|
---|
2142 |
|
---|
2143 | #if defined(NEED_IP)
|
---|
2144 | # define HAVE_NEED_IP
|
---|
2145 | #else
|
---|
2146 | # define NEED_IP(x) ((void) 0)
|
---|
2147 | #endif
|
---|
2148 | #if defined(NEED_OP)
|
---|
2149 | # define HAVE_NEED_OP
|
---|
2150 | #else
|
---|
2151 | # define NEED_OP(x) ((void) 0)
|
---|
2152 | #endif
|
---|
2153 |
|
---|
2154 | #if defined(HAVE_TEST_IP) || defined(HAVE_NEED_IP)
|
---|
2155 | # define HAVE_ANY_IP
|
---|
2156 | #endif
|
---|
2157 | #if defined(HAVE_TEST_OP) || defined(HAVE_NEED_OP)
|
---|
2158 | # define HAVE_ANY_OP
|
---|
2159 | #endif
|
---|
2160 |
|
---|
2161 | #if defined(HAVE_ANY_IP) && defined(HAVE_ANY_OP)
|
---|
2162 |
|
---|
2163 | # undef LZO_OPTIMIZE_GNUC_i386
|
---|
2164 | #endif
|
---|
2165 |
|
---|
2166 | LZO_PUBLIC(int)
|
---|
2167 | DO_DECOMPRESS ( const lzo_byte *in , lzo_uint in_len,
|
---|
2168 | lzo_byte *out, lzo_uint *out_len,
|
---|
2169 | lzo_voidp wrkmem )
|
---|
2170 | {
|
---|
2171 | #if 0 && defined(__GNUC__) && defined(__i386__)
|
---|
2172 | register lzo_byte *op __asm__("%edi");
|
---|
2173 | register const lzo_byte *ip __asm__("%esi");
|
---|
2174 | register lzo_uint t __asm__("%ecx");
|
---|
2175 | register const lzo_byte *m_pos __asm__("%ebx");
|
---|
2176 | #else
|
---|
2177 | register lzo_byte *op;
|
---|
2178 | register const lzo_byte *ip;
|
---|
2179 | register lzo_uint t;
|
---|
2180 | register const lzo_byte *m_pos;
|
---|
2181 | #endif
|
---|
2182 |
|
---|
2183 | const lzo_byte * const ip_end = in + in_len;
|
---|
2184 | #if defined(HAVE_ANY_OP)
|
---|
2185 | lzo_byte * const op_end = out + *out_len;
|
---|
2186 | #endif
|
---|
2187 |
|
---|
2188 | LZO_UNUSED(wrkmem);
|
---|
2189 |
|
---|
2190 | *out_len = 0;
|
---|
2191 |
|
---|
2192 | op = out;
|
---|
2193 | ip = in;
|
---|
2194 |
|
---|
2195 | if (*ip > 17)
|
---|
2196 | {
|
---|
2197 | t = *ip++ - 17;
|
---|
2198 | assert(t > 0); NEED_OP(t); NEED_IP(t+1);
|
---|
2199 | do *op++ = *ip++; while (--t > 0);
|
---|
2200 | goto first_literal_run;
|
---|
2201 | }
|
---|
2202 |
|
---|
2203 | while (TEST_IP && TEST_OP)
|
---|
2204 | {
|
---|
2205 | t = *ip++;
|
---|
2206 | if (t >= 16)
|
---|
2207 | goto match;
|
---|
2208 |
|
---|
2209 | if (t == 0)
|
---|
2210 | {
|
---|
2211 | NEED_IP(1);
|
---|
2212 | while (*ip == 0)
|
---|
2213 | {
|
---|
2214 | t += 255;
|
---|
2215 | ip++;
|
---|
2216 | NEED_IP(1);
|
---|
2217 | }
|
---|
2218 | t += 15 + *ip++;
|
---|
2219 | }
|
---|
2220 |
|
---|
2221 | assert(t > 0); NEED_OP(t+3); NEED_IP(t+4);
|
---|
2222 | #if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
|
---|
2223 | #if !defined(LZO_UNALIGNED_OK_4)
|
---|
2224 | if (PTR_ALIGNED2_4(op,ip))
|
---|
2225 | {
|
---|
2226 | #endif
|
---|
2227 | * (lzo_uint32p) op = * (const lzo_uint32p) ip;
|
---|
2228 | op += 4; ip += 4;
|
---|
2229 | if (--t > 0)
|
---|
2230 | {
|
---|
2231 | if (t >= 4)
|
---|
2232 | {
|
---|
2233 | do {
|
---|
2234 | * (lzo_uint32p) op = * (const lzo_uint32p) ip;
|
---|
2235 | op += 4; ip += 4; t -= 4;
|
---|
2236 | } while (t >= 4);
|
---|
2237 | if (t > 0) do *op++ = *ip++; while (--t > 0);
|
---|
2238 | }
|
---|
2239 | else
|
---|
2240 | do *op++ = *ip++; while (--t > 0);
|
---|
2241 | }
|
---|
2242 | #if !defined(LZO_UNALIGNED_OK_4)
|
---|
2243 | }
|
---|
2244 | else
|
---|
2245 | #endif
|
---|
2246 | #endif
|
---|
2247 | #if !defined(LZO_UNALIGNED_OK_4)
|
---|
2248 | {
|
---|
2249 | *op++ = *ip++; *op++ = *ip++; *op++ = *ip++;
|
---|
2250 | do *op++ = *ip++; while (--t > 0);
|
---|
2251 | }
|
---|
2252 | #endif
|
---|
2253 |
|
---|
2254 | first_literal_run:
|
---|
2255 |
|
---|
2256 | t = *ip++;
|
---|
2257 |
|
---|
2258 | #if defined(LZO1X_0) || defined(LZO1Y_0)
|
---|
2259 | assert(t >= 16);
|
---|
2260 | goto match;
|
---|
2261 | #else
|
---|
2262 | if (t >= 16)
|
---|
2263 | goto match;
|
---|
2264 | m_pos = op - 1 - M2_MAX_OFFSET;
|
---|
2265 | m_pos -= t >> 2;
|
---|
2266 | m_pos -= *ip++ << 2;
|
---|
2267 | TEST_LOOKBEHIND(m_pos,out); NEED_OP(3);
|
---|
2268 | *op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos;
|
---|
2269 | goto match_done;
|
---|
2270 | #endif
|
---|
2271 |
|
---|
2272 | while (TEST_IP && TEST_OP)
|
---|
2273 | {
|
---|
2274 | match:
|
---|
2275 | if (t >= 64)
|
---|
2276 | {
|
---|
2277 | m_pos = op - 1;
|
---|
2278 | #if defined(LZO1X)
|
---|
2279 | m_pos -= (t >> 2) & 7;
|
---|
2280 | m_pos -= *ip++ << 3;
|
---|
2281 | t = (t >> 5) - 1;
|
---|
2282 | #elif defined(LZO1Y)
|
---|
2283 | m_pos -= (t >> 2) & 3;
|
---|
2284 | m_pos -= *ip++ << 2;
|
---|
2285 | t = (t >> 4) - 3;
|
---|
2286 | #endif
|
---|
2287 | TEST_LOOKBEHIND(m_pos,out); assert(t > 0); NEED_OP(t+3-1);
|
---|
2288 | goto copy_match;
|
---|
2289 | }
|
---|
2290 | else if (t >= 32)
|
---|
2291 | {
|
---|
2292 | t &= 31;
|
---|
2293 | if (t == 0)
|
---|
2294 | {
|
---|
2295 | NEED_IP(1);
|
---|
2296 | while (*ip == 0)
|
---|
2297 | {
|
---|
2298 | t += 255;
|
---|
2299 | ip++;
|
---|
2300 | NEED_IP(1);
|
---|
2301 | }
|
---|
2302 | t += 31 + *ip++;
|
---|
2303 | }
|
---|
2304 | m_pos = op - 1;
|
---|
2305 | #if defined(LZO_UNALIGNED_OK_2) && (LZO_BYTE_ORDER == LZO_LITTLE_ENDIAN)
|
---|
2306 | m_pos -= (* (const lzo_ushortp) ip) >> 2;
|
---|
2307 | ip += 2;
|
---|
2308 | #else
|
---|
2309 | m_pos -= *ip++ >> 2;
|
---|
2310 | m_pos -= *ip++ << 6;
|
---|
2311 | #endif
|
---|
2312 | }
|
---|
2313 | #if defined(LZO1X_0) || defined(LZO1Y_0)
|
---|
2314 | else
|
---|
2315 | {
|
---|
2316 | assert(t >= 16);
|
---|
2317 | #else
|
---|
2318 | else if (t >= 16)
|
---|
2319 | {
|
---|
2320 | #endif
|
---|
2321 | m_pos = op;
|
---|
2322 | m_pos -= (t & 8) << 11;
|
---|
2323 | t &= 7;
|
---|
2324 | if (t == 0)
|
---|
2325 | {
|
---|
2326 | NEED_IP(1);
|
---|
2327 | while (*ip == 0)
|
---|
2328 | {
|
---|
2329 | t += 255;
|
---|
2330 | ip++;
|
---|
2331 | NEED_IP(1);
|
---|
2332 | }
|
---|
2333 | t += 7 + *ip++;
|
---|
2334 | }
|
---|
2335 | #if defined(LZO_UNALIGNED_OK_2) && (LZO_BYTE_ORDER == LZO_LITTLE_ENDIAN)
|
---|
2336 | m_pos -= (* (const lzo_ushortp) ip) >> 2;
|
---|
2337 | ip += 2;
|
---|
2338 | #else
|
---|
2339 | m_pos -= *ip++ >> 2;
|
---|
2340 | m_pos -= *ip++ << 6;
|
---|
2341 | #endif
|
---|
2342 | if (m_pos == op)
|
---|
2343 | goto eof_found;
|
---|
2344 | m_pos -= 0x4000;
|
---|
2345 | }
|
---|
2346 | #if !defined(LZO1X_0) && !defined(LZO1Y_0)
|
---|
2347 | else
|
---|
2348 | {
|
---|
2349 | m_pos = op - 1;
|
---|
2350 | m_pos -= t >> 2;
|
---|
2351 | m_pos -= *ip++ << 2;
|
---|
2352 | TEST_LOOKBEHIND(m_pos,out); NEED_OP(2);
|
---|
2353 | *op++ = *m_pos++; *op++ = *m_pos;
|
---|
2354 | goto match_done;
|
---|
2355 | }
|
---|
2356 | #endif
|
---|
2357 |
|
---|
2358 | TEST_LOOKBEHIND(m_pos,out); assert(t > 0); NEED_OP(t+3-1);
|
---|
2359 | #if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
|
---|
2360 | #if !defined(LZO_UNALIGNED_OK_4)
|
---|
2361 | if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos))
|
---|
2362 | {
|
---|
2363 | assert((op - m_pos) >= 4);
|
---|
2364 | #else
|
---|
2365 | if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4)
|
---|
2366 | {
|
---|
2367 | #endif
|
---|
2368 | * (lzo_uint32p) op = * (const lzo_uint32p) m_pos;
|
---|
2369 | op += 4; m_pos += 4; t -= 4 - (3 - 1);
|
---|
2370 | do {
|
---|
2371 | * (lzo_uint32p) op = * (const lzo_uint32p) m_pos;
|
---|
2372 | op += 4; m_pos += 4; t -= 4;
|
---|
2373 | } while (t >= 4);
|
---|
2374 | if (t > 0) do *op++ = *m_pos++; while (--t > 0);
|
---|
2375 | }
|
---|
2376 | else
|
---|
2377 | #endif
|
---|
2378 | {
|
---|
2379 | copy_match:
|
---|
2380 | *op++ = *m_pos++; *op++ = *m_pos++;
|
---|
2381 | do *op++ = *m_pos++; while (--t > 0);
|
---|
2382 | }
|
---|
2383 |
|
---|
2384 | match_done:
|
---|
2385 | t = ip[-2] & 3;
|
---|
2386 | if (t == 0)
|
---|
2387 | break;
|
---|
2388 |
|
---|
2389 | assert(t > 0); NEED_OP(t); NEED_IP(t+1);
|
---|
2390 | do *op++ = *ip++; while (--t > 0);
|
---|
2391 | t = *ip++;
|
---|
2392 | }
|
---|
2393 | }
|
---|
2394 |
|
---|
2395 | #if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP)
|
---|
2396 |
|
---|
2397 | *out_len = op - out;
|
---|
2398 | return LZO_E_EOF_NOT_FOUND;
|
---|
2399 | #endif
|
---|
2400 |
|
---|
2401 | eof_found:
|
---|
2402 | assert(t == 1);
|
---|
2403 | *out_len = op - out;
|
---|
2404 | return (ip == ip_end ? LZO_E_OK :
|
---|
2405 | (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN));
|
---|
2406 |
|
---|
2407 | #if defined(HAVE_NEED_IP)
|
---|
2408 | input_overrun:
|
---|
2409 | *out_len = op - out;
|
---|
2410 | return LZO_E_INPUT_OVERRUN;
|
---|
2411 | #endif
|
---|
2412 |
|
---|
2413 | #if defined(HAVE_NEED_OP)
|
---|
2414 | output_overrun:
|
---|
2415 | *out_len = op - out;
|
---|
2416 | return LZO_E_OUTPUT_OVERRUN;
|
---|
2417 | #endif
|
---|
2418 |
|
---|
2419 | #if defined(LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND)
|
---|
2420 | lookbehind_overrun:
|
---|
2421 | *out_len = op - out;
|
---|
2422 | return LZO_E_LOOKBEHIND_OVERRUN;
|
---|
2423 | #endif
|
---|
2424 | }
|
---|
2425 |
|
---|
2426 | /***** End of minilzo.c *****/
|
---|
2427 |
|
---|