author | peter1138 |
Sun, 03 Aug 2008 17:35:08 +0000 | |
changeset 9834 | 7474149531c1 |
parent 9543 | a60fb4bacc66 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
9111
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
3 |
/** |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
4 |
* @file minilzo.cpp -- mini subset of the LZO real-time data compression library |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
5 |
* |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
6 |
* This file is part of the LZO real-time data compression library. |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
7 |
* |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
8 |
* Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
9 |
* Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
10 |
* Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
11 |
* Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
12 |
* Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
13 |
* Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
14 |
* Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
15 |
* All Rights Reserved. |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
16 |
* |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
17 |
* The LZO library is free software; you can redistribute it and/or |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
18 |
* modify it under the terms of the GNU General Public License as |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
19 |
* published by the Free Software Foundation; either version 2 of |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
20 |
* the License, or (at your option) any later version. |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
21 |
* |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
22 |
* The LZO library is distributed in the hope that it will be useful, |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
23 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
24 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
25 |
* GNU General Public License for more details. |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
26 |
* |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
27 |
* You should have received a copy of the GNU General Public License |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
28 |
* along with the LZO library; see the file COPYING. |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
29 |
* If not, write to the Free Software Foundation, Inc., |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
30 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
31 |
* |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
32 |
* Markus F.X.J. Oberhumer |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
33 |
* <markus@oberhumer.com> |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
34 |
* http://www.oberhumer.com/opensource/lzo/ |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
7405
diff
changeset
|
35 |
* |
0 | 36 |
* NOTE: |
37 |
* the full LZO package can be found at |
|
38 |
* http://www.oberhumer.com/opensource/lzo/ |
|
39 |
*/ |
|
40 |
||
41 |
#define LZO_DISABLE_CHECKS |
|
42 |
#define LZO1X |
|
43 |
||
44 |
#define __LZO_IN_MINILZO |
|
45 |
#define LZO_BUILD |
|
46 |
||
47 |
#ifdef MINILZO_HAVE_CONFIG_H |
|
48 |
# include <config.h> |
|
49 |
#endif |
|
50 |
||
51 |
#undef LZO_HAVE_CONFIG_H |
|
52 |
#include "minilzo.h" |
|
53 |
||
54 |
#if !defined(MINILZO_VERSION) || (MINILZO_VERSION != 0x1080) |
|
55 |
# error "version mismatch in miniLZO source files" |
|
56 |
#endif |
|
57 |
||
58 |
#ifdef MINILZO_HAVE_CONFIG_H |
|
59 |
# define LZO_HAVE_CONFIG_H |
|
60 |
#endif |
|
61 |
||
7405
2fd57f130eca
(svn r10778) -Fix: one-liners to allow MSVC and WINCE to work together (or anyway, a step towards that goal)
truelight
parents:
6247
diff
changeset
|
62 |
#if !defined(LZO_NO_SYS_TYPES_H) && !defined(WINCE) |
0 | 63 |
# include <sys/types.h> |
64 |
#endif |
|
65 |
#include <stdio.h> |
|
66 |
||
67 |
#ifndef __LZO_CONF_H |
|
68 |
#define __LZO_CONF_H |
|
69 |
||
70 |
#if defined(__BOUNDS_CHECKING_ON) |
|
71 |
# include <unchecked.h> |
|
72 |
#else |
|
73 |
# define BOUNDS_CHECKING_OFF_DURING(stmt) stmt |
|
74 |
# define BOUNDS_CHECKING_OFF_IN_EXPR(expr) (expr) |
|
75 |
#endif |
|
76 |
||
77 |
#if !defined(LZO_HAVE_CONFIG_H) |
|
78 |
# include <stddef.h> |
|
79 |
# include <string.h> |
|
80 |
# if !defined(NO_STDLIB_H) |
|
81 |
# include <stdlib.h> |
|
82 |
# endif |
|
83 |
# define HAVE_MEMCMP |
|
84 |
# define HAVE_MEMCPY |
|
85 |
# define HAVE_MEMMOVE |
|
86 |
# define HAVE_MEMSET |
|
87 |
#else |
|
88 |
# include <sys/types.h> |
|
89 |
# if defined(HAVE_STDDEF_H) |
|
90 |
# include <stddef.h> |
|
91 |
# endif |
|
92 |
# if defined(STDC_HEADERS) |
|
93 |
# include <string.h> |
|
94 |
# include <stdlib.h> |
|
95 |
# endif |
|
96 |
#endif |
|
97 |
||
98 |
#if defined(__LZO_DOS16) || defined(__LZO_WIN16) |
|
99 |
# define HAVE_MALLOC_H |
|
100 |
# define HAVE_HALLOC |
|
101 |
#endif |
|
102 |
||
103 |
#undef NDEBUG |
|
104 |
#if !defined(LZO_DEBUG) |
|
105 |
# define NDEBUG |
|
106 |
#endif |
|
107 |
#if defined(LZO_DEBUG) || !defined(NDEBUG) |
|
108 |
# if !defined(NO_STDIO_H) |
|
109 |
# include <stdio.h> |
|
110 |
# endif |
|
111 |
#endif |
|
112 |
#include <assert.h> |
|
113 |
||
114 |
#if !defined(LZO_COMPILE_TIME_ASSERT) |
|
115 |
# define LZO_COMPILE_TIME_ASSERT(expr) \ |
|
116 |
{ typedef int __lzo_compile_time_assert_fail[1 - 2 * !(expr)]; } |
|
117 |
#endif |
|
118 |
||
119 |
#if !defined(LZO_UNUSED) |
|
120 |
# if 1 |
|
121 |
# define LZO_UNUSED(var) ((void)&var) |
|
122 |
# elif 0 |
|
123 |
# define LZO_UNUSED(var) { typedef int __lzo_unused[sizeof(var) ? 2 : 1]; } |
|
124 |
# else |
|
125 |
# define LZO_UNUSED(parm) (parm = parm) |
|
126 |
# endif |
|
127 |
#endif |
|
128 |
||
129 |
#if !defined(__inline__) && !defined(__GNUC__) |
|
130 |
# if defined(__cplusplus) |
|
131 |
# define __inline__ inline |
|
132 |
# else |
|
133 |
# define __inline__ |
|
134 |
# endif |
|
135 |
#endif |
|
136 |
||
137 |
#if defined(NO_MEMCMP) |
|
138 |
# undef HAVE_MEMCMP |
|
139 |
#endif |
|
140 |
||
141 |
#if 0 |
|
142 |
# define LZO_BYTE(x) ((unsigned char) (x)) |
|
143 |
#else |
|
144 |
# define LZO_BYTE(x) ((unsigned char) ((x) & 0xff)) |
|
145 |
#endif |
|
146 |
||
147 |
#define LZO_MAX(a,b) ((a) >= (b) ? (a) : (b)) |
|
148 |
#define LZO_MIN(a,b) ((a) <= (b) ? (a) : (b)) |
|
149 |
#define LZO_MAX3(a,b,c) ((a) >= (b) ? LZO_MAX(a,c) : LZO_MAX(b,c)) |
|
150 |
#define LZO_MIN3(a,b,c) ((a) <= (b) ? LZO_MIN(a,c) : LZO_MIN(b,c)) |
|
151 |
||
152 |
#define lzo_sizeof(type) ((lzo_uint) (sizeof(type))) |
|
153 |
||
154 |
#define LZO_HIGH(array) ((lzo_uint) (sizeof(array)/sizeof(*(array)))) |
|
155 |
||
156 |
#define LZO_SIZE(bits) (1u << (bits)) |
|
157 |
#define LZO_MASK(bits) (LZO_SIZE(bits) - 1) |
|
158 |
||
159 |
#define LZO_LSIZE(bits) (1ul << (bits)) |
|
160 |
#define LZO_LMASK(bits) (LZO_LSIZE(bits) - 1) |
|
161 |
||
162 |
#define LZO_USIZE(bits) ((lzo_uint) 1 << (bits)) |
|
163 |
#define LZO_UMASK(bits) (LZO_USIZE(bits) - 1) |
|
164 |
||
165 |
#define LZO_STYPE_MAX(b) (((1l << (8*(b)-2)) - 1l) + (1l << (8*(b)-2))) |
|
166 |
#define LZO_UTYPE_MAX(b) (((1ul << (8*(b)-1)) - 1ul) + (1ul << (8*(b)-1))) |
|
167 |
||
168 |
#if !defined(SIZEOF_UNSIGNED) |
|
169 |
# if (UINT_MAX == 0xffff) |
|
170 |
# define SIZEOF_UNSIGNED 2 |
|
171 |
# elif (UINT_MAX == LZO_0xffffffffL) |
|
172 |
# define SIZEOF_UNSIGNED 4 |
|
173 |
# elif (UINT_MAX >= LZO_0xffffffffL) |
|
174 |
# define SIZEOF_UNSIGNED 8 |
|
175 |
# else |
|
176 |
# error "SIZEOF_UNSIGNED" |
|
177 |
# endif |
|
178 |
#endif |
|
179 |
||
180 |
#if !defined(SIZEOF_UNSIGNED_LONG) |
|
181 |
# if (ULONG_MAX == LZO_0xffffffffL) |
|
182 |
# define SIZEOF_UNSIGNED_LONG 4 |
|
183 |
# elif (ULONG_MAX >= LZO_0xffffffffL) |
|
184 |
# define SIZEOF_UNSIGNED_LONG 8 |
|
185 |
# else |
|
186 |
# error "SIZEOF_UNSIGNED_LONG" |
|
187 |
# endif |
|
188 |
#endif |
|
189 |
||
190 |
#if !defined(SIZEOF_SIZE_T) |
|
191 |
# define SIZEOF_SIZE_T SIZEOF_UNSIGNED |
|
192 |
#endif |
|
193 |
#if !defined(SIZE_T_MAX) |
|
194 |
# define SIZE_T_MAX LZO_UTYPE_MAX(SIZEOF_SIZE_T) |
|
195 |
#endif |
|
196 |
||
197 |
#if 1 && defined(__LZO_i386) && (UINT_MAX == LZO_0xffffffffL) |
|
198 |
# if !defined(LZO_UNALIGNED_OK_2) && (USHRT_MAX == 0xffff) |
|
199 |
# define LZO_UNALIGNED_OK_2 |
|
200 |
# endif |
|
201 |
# if !defined(LZO_UNALIGNED_OK_4) && (LZO_UINT32_MAX == LZO_0xffffffffL) |
|
202 |
# define LZO_UNALIGNED_OK_4 |
|
203 |
# endif |
|
204 |
#endif |
|
205 |
||
206 |
#if defined(LZO_UNALIGNED_OK_2) || defined(LZO_UNALIGNED_OK_4) |
|
207 |
# if !defined(LZO_UNALIGNED_OK) |
|
208 |
# define LZO_UNALIGNED_OK |
|
209 |
# endif |
|
210 |
#endif |
|
211 |
||
212 |
#if defined(__LZO_NO_UNALIGNED) |
|
213 |
# undef LZO_UNALIGNED_OK |
|
214 |
# undef LZO_UNALIGNED_OK_2 |
|
215 |
# undef LZO_UNALIGNED_OK_4 |
|
216 |
#endif |
|
217 |
||
218 |
#if defined(LZO_UNALIGNED_OK_2) && (USHRT_MAX != 0xffff) |
|
219 |
# error "LZO_UNALIGNED_OK_2 must not be defined on this system" |
|
220 |
#endif |
|
221 |
#if defined(LZO_UNALIGNED_OK_4) && (LZO_UINT32_MAX != LZO_0xffffffffL) |
|
222 |
# error "LZO_UNALIGNED_OK_4 must not be defined on this system" |
|
223 |
#endif |
|
224 |
||
225 |
#if defined(__LZO_NO_ALIGNED) |
|
226 |
# undef LZO_ALIGNED_OK_4 |
|
227 |
#endif |
|
228 |
||
229 |
#if defined(LZO_ALIGNED_OK_4) && (LZO_UINT32_MAX != LZO_0xffffffffL) |
|
230 |
# error "LZO_ALIGNED_OK_4 must not be defined on this system" |
|
231 |
#endif |
|
232 |
||
9543
a60fb4bacc66
(svn r13552) -Codechange: use TTD_ENDIAN comparations instead of tests if TTD_[BIG/LITTLE]_ENDIAN is defined
smatz
parents:
9390
diff
changeset
|
233 |
#define LZO_LITTLE_ENDIAN 1234 |
a60fb4bacc66
(svn r13552) -Codechange: use TTD_ENDIAN comparations instead of tests if TTD_[BIG/LITTLE]_ENDIAN is defined
smatz
parents:
9390
diff
changeset
|
234 |
#define LZO_BIG_ENDIAN 4321 |
a60fb4bacc66
(svn r13552) -Codechange: use TTD_ENDIAN comparations instead of tests if TTD_[BIG/LITTLE]_ENDIAN is defined
smatz
parents:
9390
diff
changeset
|
235 |
#define LZO_PDP_ENDIAN 3412 |
0 | 236 |
|
237 |
#if !defined(LZO_BYTE_ORDER) |
|
238 |
# if defined(MFX_BYTE_ORDER) |
|
239 |
# define LZO_BYTE_ORDER MFX_BYTE_ORDER |
|
240 |
# elif defined(__LZO_i386) |
|
241 |
# define LZO_BYTE_ORDER LZO_LITTLE_ENDIAN |
|
242 |
# elif defined(BYTE_ORDER) |
|
243 |
# define LZO_BYTE_ORDER BYTE_ORDER |
|
244 |
# elif defined(__BYTE_ORDER) |
|
245 |
# define LZO_BYTE_ORDER __BYTE_ORDER |
|
246 |
# endif |
|
247 |
#endif |
|
248 |
||
249 |
#if defined(LZO_BYTE_ORDER) |
|
250 |
# if (LZO_BYTE_ORDER != LZO_LITTLE_ENDIAN) && \ |
|
251 |
(LZO_BYTE_ORDER != LZO_BIG_ENDIAN) |
|
252 |
# error "invalid LZO_BYTE_ORDER" |
|
253 |
# endif |
|
254 |
#endif |
|
255 |
||
256 |
#if defined(LZO_UNALIGNED_OK) && !defined(LZO_BYTE_ORDER) |
|
257 |
# error "LZO_BYTE_ORDER is not defined" |
|
258 |
#endif |
|
259 |
||
260 |
#define LZO_OPTIMIZE_GNUC_i386_IS_BUGGY |
|
261 |
||
262 |
#if defined(NDEBUG) && !defined(LZO_DEBUG) && !defined(__LZO_CHECKER) |
|
263 |
# if defined(__GNUC__) && defined(__i386__) |
|
264 |
# if !defined(LZO_OPTIMIZE_GNUC_i386_IS_BUGGY) |
|
265 |
# define LZO_OPTIMIZE_GNUC_i386 |
|
266 |
# endif |
|
267 |
# endif |
|
268 |
#endif |
|
269 |
||
270 |
__LZO_EXTERN_C int __lzo_init_done; |
|
271 |
__LZO_EXTERN_C const lzo_byte __lzo_copyright[]; |
|
6247 | 272 |
LZO_EXTERN(const lzo_byte *) lzo_copyright(); |
0 | 273 |
__LZO_EXTERN_C const lzo_uint32 _lzo_crc32_table[256]; |
274 |
||
275 |
#define _LZO_STRINGIZE(x) #x |
|
276 |
#define _LZO_MEXPAND(x) _LZO_STRINGIZE(x) |
|
277 |
||
278 |
#define _LZO_CONCAT2(a,b) a ## b |
|
279 |
#define _LZO_CONCAT3(a,b,c) a ## b ## c |
|
280 |
#define _LZO_CONCAT4(a,b,c,d) a ## b ## c ## d |
|
281 |
#define _LZO_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e |
|
282 |
||
283 |
#define _LZO_ECONCAT2(a,b) _LZO_CONCAT2(a,b) |
|
284 |
#define _LZO_ECONCAT3(a,b,c) _LZO_CONCAT3(a,b,c) |
|
285 |
#define _LZO_ECONCAT4(a,b,c,d) _LZO_CONCAT4(a,b,c,d) |
|
286 |
#define _LZO_ECONCAT5(a,b,c,d,e) _LZO_CONCAT5(a,b,c,d,e) |
|
287 |
||
288 |
#ifndef __LZO_PTR_H |
|
289 |
#define __LZO_PTR_H |
|
290 |
||
291 |
#ifdef __cplusplus |
|
292 |
extern "C" { |
|
293 |
#endif |
|
294 |
||
295 |
#if defined(__LZO_DOS16) || defined(__LZO_WIN16) |
|
296 |
# include <dos.h> |
|
297 |
# if 1 && defined(__WATCOMC__) |
|
298 |
# include <i86.h> |
|
299 |
__LZO_EXTERN_C unsigned char _HShift; |
|
300 |
# define __LZO_HShift _HShift |
|
301 |
# elif 1 && defined(_MSC_VER) |
|
302 |
__LZO_EXTERN_C unsigned short __near _AHSHIFT; |
|
303 |
# define __LZO_HShift ((unsigned) &_AHSHIFT) |
|
304 |
# elif defined(__LZO_WIN16) |
|
305 |
# define __LZO_HShift 3 |
|
306 |
# else |
|
307 |
# define __LZO_HShift 12 |
|
308 |
# endif |
|
309 |
# if !defined(_FP_SEG) && defined(FP_SEG) |
|
310 |
# define _FP_SEG FP_SEG |
|
311 |
# endif |
|
312 |
# if !defined(_FP_OFF) && defined(FP_OFF) |
|
313 |
# define _FP_OFF FP_OFF |
|
314 |
# endif |
|
315 |
#endif |
|
316 |
||
317 |
#if !defined(lzo_ptrdiff_t) |
|
318 |
# if (UINT_MAX >= LZO_0xffffffffL) |
|
319 |
typedef ptrdiff_t lzo_ptrdiff_t; |
|
320 |
# else |
|
321 |
typedef long lzo_ptrdiff_t; |
|
322 |
# endif |
|
323 |
#endif |
|
324 |
||
325 |
#if !defined(__LZO_HAVE_PTR_T) |
|
326 |
# if defined(lzo_ptr_t) |
|
327 |
# define __LZO_HAVE_PTR_T |
|
328 |
# endif |
|
329 |
#endif |
|
330 |
#if !defined(__LZO_HAVE_PTR_T) |
|
2482
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2186
diff
changeset
|
331 |
# if defined(_WIN64) |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2186
diff
changeset
|
332 |
typedef unsigned __int64 lzo_ptr_t; |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2186
diff
changeset
|
333 |
typedef signed __int64 lzo_sptr_r; |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2186
diff
changeset
|
334 |
# define __LZO_HAVE_PTR_T |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2186
diff
changeset
|
335 |
# endif |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2186
diff
changeset
|
336 |
#endif |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2186
diff
changeset
|
337 |
#if !defined(__LZO_HAVE_PTR_T) |
0 | 338 |
# if defined(SIZEOF_CHAR_P) && defined(SIZEOF_UNSIGNED_LONG) |
339 |
# if (SIZEOF_CHAR_P == SIZEOF_UNSIGNED_LONG) |
|
340 |
typedef unsigned long lzo_ptr_t; |
|
341 |
typedef long lzo_sptr_t; |
|
342 |
# define __LZO_HAVE_PTR_T |
|
343 |
# endif |
|
344 |
# endif |
|
345 |
#endif |
|
346 |
#if !defined(__LZO_HAVE_PTR_T) |
|
347 |
# if defined(SIZEOF_CHAR_P) && defined(SIZEOF_UNSIGNED) |
|
348 |
# if (SIZEOF_CHAR_P == SIZEOF_UNSIGNED) |
|
349 |
typedef unsigned int lzo_ptr_t; |
|
350 |
typedef int lzo_sptr_t; |
|
351 |
# define __LZO_HAVE_PTR_T |
|
352 |
# endif |
|
353 |
# endif |
|
354 |
#endif |
|
355 |
#if !defined(__LZO_HAVE_PTR_T) |
|
356 |
# if defined(SIZEOF_CHAR_P) && defined(SIZEOF_UNSIGNED_SHORT) |
|
357 |
# if (SIZEOF_CHAR_P == SIZEOF_UNSIGNED_SHORT) |
|
358 |
typedef unsigned short lzo_ptr_t; |
|
359 |
typedef short lzo_sptr_t; |
|
360 |
# define __LZO_HAVE_PTR_T |
|
361 |
# endif |
|
362 |
# endif |
|
363 |
#endif |
|
364 |
#if !defined(__LZO_HAVE_PTR_T) |
|
365 |
# if defined(LZO_HAVE_CONFIG_H) || defined(SIZEOF_CHAR_P) |
|
366 |
# error "no suitable type for lzo_ptr_t" |
|
367 |
# else |
|
368 |
typedef unsigned long lzo_ptr_t; |
|
369 |
typedef long lzo_sptr_t; |
|
370 |
# define __LZO_HAVE_PTR_T |
|
371 |
# endif |
|
372 |
#endif |
|
373 |
||
374 |
#if defined(__LZO_DOS16) || defined(__LZO_WIN16) |
|
375 |
#define PTR(a) ((lzo_bytep) (a)) |
|
376 |
#define PTR_ALIGNED_4(a) ((_FP_OFF(a) & 3) == 0) |
|
377 |
#define PTR_ALIGNED2_4(a,b) (((_FP_OFF(a) | _FP_OFF(b)) & 3) == 0) |
|
378 |
#else |
|
379 |
#define PTR(a) ((lzo_ptr_t) (a)) |
|
380 |
#define PTR_LINEAR(a) PTR(a) |
|
381 |
#define PTR_ALIGNED_4(a) ((PTR_LINEAR(a) & 3) == 0) |
|
382 |
#define PTR_ALIGNED_8(a) ((PTR_LINEAR(a) & 7) == 0) |
|
383 |
#define PTR_ALIGNED2_4(a,b) (((PTR_LINEAR(a) | PTR_LINEAR(b)) & 3) == 0) |
|
384 |
#define PTR_ALIGNED2_8(a,b) (((PTR_LINEAR(a) | PTR_LINEAR(b)) & 7) == 0) |
|
385 |
#endif |
|
386 |
||
387 |
#define PTR_LT(a,b) (PTR(a) < PTR(b)) |
|
388 |
#define PTR_GE(a,b) (PTR(a) >= PTR(b)) |
|
389 |
#define PTR_DIFF(a,b) ((lzo_ptrdiff_t) (PTR(a) - PTR(b))) |
|
390 |
#define pd(a,b) ((lzo_uint) ((a)-(b))) |
|
391 |
||
392 |
LZO_EXTERN(lzo_ptr_t) |
|
393 |
__lzo_ptr_linear(const lzo_voidp ptr); |
|
394 |
||
395 |
typedef union |
|
396 |
{ |
|
397 |
char a_char; |
|
398 |
unsigned char a_uchar; |
|
399 |
short a_short; |
|
400 |
unsigned short a_ushort; |
|
401 |
int a_int; |
|
402 |
unsigned int a_uint; |
|
403 |
long a_long; |
|
404 |
unsigned long a_ulong; |
|
405 |
lzo_int a_lzo_int; |
|
406 |
lzo_uint a_lzo_uint; |
|
407 |
lzo_int32 a_lzo_int32; |
|
408 |
lzo_uint32 a_lzo_uint32; |
|
409 |
ptrdiff_t a_ptrdiff_t; |
|
410 |
lzo_ptrdiff_t a_lzo_ptrdiff_t; |
|
411 |
lzo_ptr_t a_lzo_ptr_t; |
|
412 |
lzo_voidp a_lzo_voidp; |
|
413 |
void * a_void_p; |
|
414 |
lzo_bytep a_lzo_bytep; |
|
415 |
lzo_bytepp a_lzo_bytepp; |
|
416 |
lzo_uintp a_lzo_uintp; |
|
417 |
lzo_uint * a_lzo_uint_p; |
|
418 |
lzo_uint32p a_lzo_uint32p; |
|
419 |
lzo_uint32 * a_lzo_uint32_p; |
|
420 |
unsigned char * a_uchar_p; |
|
421 |
char * a_char_p; |
|
422 |
} |
|
423 |
lzo_full_align_t; |
|
424 |
||
425 |
#ifdef __cplusplus |
|
426 |
} |
|
427 |
#endif |
|
428 |
||
429 |
#endif |
|
430 |
||
431 |
#define LZO_DETERMINISTIC |
|
432 |
||
433 |
#define LZO_DICT_USE_PTR |
|
434 |
#if defined(__LZO_DOS16) || defined(__LZO_WIN16) || defined(__LZO_STRICT_16BIT) |
|
435 |
# undef LZO_DICT_USE_PTR |
|
436 |
#endif |
|
437 |
||
438 |
#if defined(LZO_DICT_USE_PTR) |
|
439 |
# define lzo_dict_t const lzo_bytep |
|
440 |
# define lzo_dict_p lzo_dict_t __LZO_MMODEL * |
|
441 |
#else |
|
442 |
# define lzo_dict_t lzo_uint |
|
443 |
# define lzo_dict_p lzo_dict_t __LZO_MMODEL * |
|
444 |
#endif |
|
445 |
||
446 |
#if !defined(lzo_moff_t) |
|
447 |
#define lzo_moff_t lzo_uint |
|
448 |
#endif |
|
449 |
||
450 |
#endif |
|
451 |
||
452 |
||
453 |
#ifndef __LZO_UTIL_H |
|
454 |
#define __LZO_UTIL_H |
|
455 |
||
456 |
#ifndef __LZO_CONF_H |
|
457 |
#endif |
|
458 |
||
459 |
#ifdef __cplusplus |
|
460 |
extern "C" { |
|
461 |
#endif |
|
462 |
||
463 |
#if 1 && defined(HAVE_MEMCPY) |
|
464 |
#if !defined(__LZO_DOS16) && !defined(__LZO_WIN16) |
|
465 |
||
466 |
#define MEMCPY8_DS(dest,src,len) \ |
|
467 |
memcpy(dest,src,len); \ |
|
468 |
dest += len; \ |
|
469 |
src += len |
|
470 |
||
471 |
#endif |
|
472 |
#endif |
|
473 |
||
474 |
#if 0 && !defined(MEMCPY8_DS) |
|
475 |
||
476 |
#define MEMCPY8_DS(dest,src,len) \ |
|
477 |
{ do { \ |
|
478 |
*dest++ = *src++; \ |
|
479 |
*dest++ = *src++; \ |
|
480 |
*dest++ = *src++; \ |
|
481 |
*dest++ = *src++; \ |
|
482 |
*dest++ = *src++; \ |
|
483 |
*dest++ = *src++; \ |
|
484 |
*dest++ = *src++; \ |
|
485 |
*dest++ = *src++; \ |
|
486 |
len -= 8; \ |
|
487 |
} while (len > 0); } |
|
488 |
||
489 |
#endif |
|
490 |
||
491 |
#if !defined(MEMCPY8_DS) |
|
492 |
||
493 |
#define MEMCPY8_DS(dest,src,len) \ |
|
494 |
{ register lzo_uint __l = (len) / 8; \ |
|
495 |
do { \ |
|
496 |
*dest++ = *src++; \ |
|
497 |
*dest++ = *src++; \ |
|
498 |
*dest++ = *src++; \ |
|
499 |
*dest++ = *src++; \ |
|
500 |
*dest++ = *src++; \ |
|
501 |
*dest++ = *src++; \ |
|
502 |
*dest++ = *src++; \ |
|
503 |
*dest++ = *src++; \ |
|
504 |
} while (--__l > 0); } |
|
505 |
||
506 |
#endif |
|
507 |
||
508 |
#define MEMCPY_DS(dest,src,len) \ |
|
509 |
do *dest++ = *src++; \ |
|
510 |
while (--len > 0) |
|
511 |
||
512 |
#define MEMMOVE_DS(dest,src,len) \ |
|
513 |
do *dest++ = *src++; \ |
|
514 |
while (--len > 0) |
|
515 |
||
516 |
#if 0 && defined(LZO_OPTIMIZE_GNUC_i386) |
|
517 |
||
518 |
#define BZERO8_PTR(s,l,n) \ |
|
519 |
__asm__ __volatile__( \ |
|
520 |
"movl %0,%%eax \n" \ |
|
521 |
"movl %1,%%edi \n" \ |
|
522 |
"movl %2,%%ecx \n" \ |
|
523 |
"cld \n" \ |
|
524 |
"rep \n" \ |
|
525 |
"stosl %%eax,(%%edi) \n" \ |
|
526 |
: \ |
|
527 |
:"g" (0),"g" (s),"g" (n) \ |
|
528 |
:"eax","edi","ecx", "memory", "cc" \ |
|
529 |
) |
|
530 |
||
531 |
#elif (LZO_UINT_MAX <= SIZE_T_MAX) && defined(HAVE_MEMSET) |
|
532 |
||
533 |
#if 1 |
|
534 |
#define BZERO8_PTR(s,l,n) memset((s),0,(lzo_uint)(l)*(n)) |
|
535 |
#else |
|
536 |
#define BZERO8_PTR(s,l,n) memset((lzo_voidp)(s),0,(lzo_uint)(l)*(n)) |
|
537 |
#endif |
|
538 |
||
539 |
#else |
|
540 |
||
541 |
#define BZERO8_PTR(s,l,n) \ |
|
542 |
lzo_memset((lzo_voidp)(s),0,(lzo_uint)(l)*(n)) |
|
543 |
||
544 |
#endif |
|
545 |
||
546 |
#if 0 |
|
547 |
#if defined(__GNUC__) && defined(__i386__) |
|
548 |
||
549 |
unsigned char lzo_rotr8(unsigned char value, int shift); |
|
550 |
extern __inline__ unsigned char lzo_rotr8(unsigned char value, int shift) |
|
551 |
{ |
|
552 |
unsigned char result; |
|
553 |
||
554 |
__asm__ __volatile__ ("movb %b1, %b0; rorb %b2, %b0" |
|
555 |
: "=a"(result) : "g"(value), "c"(shift)); |
|
556 |
return result; |
|
557 |
} |
|
558 |
||
559 |
unsigned short lzo_rotr16(unsigned short value, int shift); |
|
560 |
extern __inline__ unsigned short lzo_rotr16(unsigned short value, int shift) |
|
561 |
{ |
|
562 |
unsigned short result; |
|
563 |
||
564 |
__asm__ __volatile__ ("movw %b1, %b0; rorw %b2, %b0" |
|
565 |
: "=a"(result) : "g"(value), "c"(shift)); |
|
566 |
return result; |
|
567 |
} |
|
568 |
||
569 |
#endif |
|
570 |
#endif |
|
571 |
||
572 |
#ifdef __cplusplus |
|
573 |
} |
|
574 |
#endif |
|
575 |
||
576 |
#endif |
|
577 |
||
578 |
||
579 |
/* If you use the LZO library in a product, you *must* keep this |
|
580 |
* copyright string in the executable of your product. |
|
581 |
*/ |
|
582 |
||
1277
afb2d6a3aa25
(svn r1781) Fix static declaration after non-static declaration of same symbol
tron
parents:
0
diff
changeset
|
583 |
const lzo_byte __lzo_copyright[] = |
0 | 584 |
#if !defined(__LZO_IN_MINLZO) |
585 |
LZO_VERSION_STRING; |
|
586 |
#else |
|
587 |
"\n\n\n" |
|
588 |
"LZO real-time data compression library.\n" |
|
589 |
"Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002 Markus Franz Xaver Johannes Oberhumer\n" |
|
590 |
"<markus.oberhumer@jk.uni-linz.ac.at>\n" |
|
591 |
"http://www.oberhumer.com/opensource/lzo/\n" |
|
592 |
"\n" |
|
593 |
"LZO version: v" LZO_VERSION_STRING ", " LZO_VERSION_DATE "\n" |
|
594 |
"LZO build date: " __DATE__ " " __TIME__ "\n\n" |
|
595 |
"LZO special compilation options:\n" |
|
596 |
#ifdef __cplusplus |
|
597 |
" __cplusplus\n" |
|
598 |
#endif |
|
599 |
#if defined(__PIC__) |
|
600 |
" __PIC__\n" |
|
601 |
#elif defined(__pic__) |
|
602 |
" __pic__\n" |
|
603 |
#endif |
|
604 |
#if (UINT_MAX < LZO_0xffffffffL) |
|
605 |
" 16BIT\n" |
|
606 |
#endif |
|
607 |
#if defined(__LZO_STRICT_16BIT) |
|
608 |
" __LZO_STRICT_16BIT\n" |
|
609 |
#endif |
|
610 |
#if (UINT_MAX > LZO_0xffffffffL) |
|
611 |
" UINT_MAX=" _LZO_MEXPAND(UINT_MAX) "\n" |
|
612 |
#endif |
|
613 |
#if (ULONG_MAX > LZO_0xffffffffL) |
|
614 |
" ULONG_MAX=" _LZO_MEXPAND(ULONG_MAX) "\n" |
|
615 |
#endif |
|
616 |
#if defined(LZO_BYTE_ORDER) |
|
617 |
" LZO_BYTE_ORDER=" _LZO_MEXPAND(LZO_BYTE_ORDER) "\n" |
|
618 |
#endif |
|
619 |
#if defined(LZO_UNALIGNED_OK_2) |
|
620 |
" LZO_UNALIGNED_OK_2\n" |
|
621 |
#endif |
|
622 |
#if defined(LZO_UNALIGNED_OK_4) |
|
623 |
" LZO_UNALIGNED_OK_4\n" |
|
624 |
#endif |
|
625 |
#if defined(LZO_ALIGNED_OK_4) |
|
626 |
" LZO_ALIGNED_OK_4\n" |
|
627 |
#endif |
|
628 |
#if defined(LZO_DICT_USE_PTR) |
|
629 |
" LZO_DICT_USE_PTR\n" |
|
630 |
#endif |
|
631 |
#if defined(__LZO_QUERY_COMPRESS) |
|
632 |
" __LZO_QUERY_COMPRESS\n" |
|
633 |
#endif |
|
634 |
#if defined(__LZO_QUERY_DECOMPRESS) |
|
635 |
" __LZO_QUERY_DECOMPRESS\n" |
|
636 |
#endif |
|
637 |
#if defined(__LZO_IN_MINILZO) |
|
638 |
" __LZO_IN_MINILZO\n" |
|
639 |
#endif |
|
640 |
"\n\n" |
|
641 |
"$Id: LZO " LZO_VERSION_STRING " built " __DATE__ " " __TIME__ |
|
642 |
#if defined(__GNUC__) && defined(__VERSION__) |
|
643 |
" by gcc " __VERSION__ |
|
644 |
#elif defined(__BORLANDC__) |
|
645 |
" by Borland C " _LZO_MEXPAND(__BORLANDC__) |
|
646 |
#elif defined(_MSC_VER) |
|
647 |
" by Microsoft C " _LZO_MEXPAND(_MSC_VER) |
|
648 |
#elif defined(__PUREC__) |
|
649 |
" by Pure C " _LZO_MEXPAND(__PUREC__) |
|
650 |
#elif defined(__SC__) |
|
651 |
" by Symantec C " _LZO_MEXPAND(__SC__) |
|
652 |
#elif defined(__TURBOC__) |
|
653 |
" by Turbo C " _LZO_MEXPAND(__TURBOC__) |
|
654 |
#elif defined(__WATCOMC__) |
|
655 |
" by Watcom C " _LZO_MEXPAND(__WATCOMC__) |
|
656 |
#endif |
|
657 |
" $\n" |
|
658 |
"$Copyright: LZO (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002 Markus Franz Xaver Johannes Oberhumer $\n"; |
|
659 |
#endif |
|
660 |
||
661 |
#define LZO_BASE 65521u |
|
662 |
#define LZO_NMAX 5552 |
|
663 |
||
664 |
#define LZO_DO1(buf,i) {s1 += buf[i]; s2 += s1;} |
|
665 |
#define LZO_DO2(buf,i) LZO_DO1(buf,i); LZO_DO1(buf,i+1); |
|
666 |
#define LZO_DO4(buf,i) LZO_DO2(buf,i); LZO_DO2(buf,i+2); |
|
667 |
#define LZO_DO8(buf,i) LZO_DO4(buf,i); LZO_DO4(buf,i+4); |
|
668 |
#define LZO_DO16(buf,i) LZO_DO8(buf,i); LZO_DO8(buf,i+8); |
|
669 |
||
670 |
LZO_PUBLIC(lzo_uint32) |
|
671 |
lzo_adler32(lzo_uint32 adler, const lzo_byte *buf, lzo_uint len) |
|
672 |
{ |
|
673 |
lzo_uint32 s1 = adler & 0xffff; |
|
674 |
lzo_uint32 s2 = (adler >> 16) & 0xffff; |
|
675 |
int k; |
|
676 |
||
677 |
if (buf == NULL) |
|
678 |
return 1; |
|
679 |
||
680 |
while (len > 0) |
|
681 |
{ |
|
682 |
k = len < LZO_NMAX ? (int) len : LZO_NMAX; |
|
683 |
len -= k; |
|
684 |
if (k >= 16) do |
|
685 |
{ |
|
686 |
LZO_DO16(buf,0); |
|
687 |
buf += 16; |
|
688 |
k -= 16; |
|
689 |
} while (k >= 16); |
|
690 |
if (k != 0) do |
|
691 |
{ |
|
692 |
s1 += *buf++; |
|
693 |
s2 += s1; |
|
694 |
} while (--k > 0); |
|
695 |
s1 %= LZO_BASE; |
|
696 |
s2 %= LZO_BASE; |
|
697 |
} |
|
698 |
return (s2 << 16) | s1; |
|
699 |
} |
|
700 |
||
701 |
#if 0 |
|
702 |
# define IS_SIGNED(type) (((type) (1ul << (8 * sizeof(type) - 1))) < 0) |
|
703 |
# define IS_UNSIGNED(type) (((type) (1ul << (8 * sizeof(type) - 1))) > 0) |
|
704 |
#else |
|
705 |
# define IS_SIGNED(type) (((type) (-1)) < ((type) 0)) |
|
706 |
# define IS_UNSIGNED(type) (((type) (-1)) > ((type) 0)) |
|
707 |
#endif |
|
708 |
||
709 |
#define IS_POWER_OF_2(x) (((x) & ((x) - 1)) == 0) |
|
710 |
||
6247 | 711 |
// static lzo_bool schedule_insns_bug(); |
0 | 712 |
// static lzo_bool strength_reduce_bug(int *); |
713 |
||
714 |
#if 0 || defined(LZO_DEBUG) |
|
715 |
#include <stdio.h> |
|
716 |
static lzo_bool __lzo_assert_fail(const char *s, unsigned line) |
|
717 |
{ |
|
718 |
#if defined(__palmos__) |
|
719 |
printf("LZO assertion failed in line %u: '%s'\n",line,s); |
|
720 |
#else |
|
721 |
fprintf(stderr,"LZO assertion failed in line %u: '%s'\n",line,s); |
|
722 |
#endif |
|
723 |
return 0; |
|
724 |
} |
|
725 |
# define __lzo_assert(x) ((x) ? 1 : __lzo_assert_fail(#x,__LINE__)) |
|
726 |
#else |
|
727 |
# define __lzo_assert(x) ((x) ? 1 : 0) |
|
728 |
#endif |
|
729 |
||
730 |
#undef COMPILE_TIME_ASSERT |
|
731 |
#if 0 |
|
732 |
# define COMPILE_TIME_ASSERT(expr) r &= __lzo_assert(expr) |
|
733 |
#else |
|
734 |
# define COMPILE_TIME_ASSERT(expr) LZO_COMPILE_TIME_ASSERT(expr) |
|
735 |
#endif |
|
736 |
||
737 |
||
738 |
#define do_compress _lzo1x_1_do_compress |
|
739 |
||
740 |
#define LZO_NEED_DICT_H |
|
741 |
#define D_BITS 12 |
|
742 |
#define D_INDEX1(d,p) d = DM((0x21*DX3(p,5,5,6)) >> 5) |
|
743 |
#define D_INDEX2(d,p) d = (d & (D_MASK & 0x7ff)) ^ (D_HIGH | 0x1f) |
|
744 |
||
745 |
#ifndef __LZO_CONFIG1X_H |
|
746 |
#define __LZO_CONFIG1X_H |
|
747 |
||
748 |
#define LZO_EOF_CODE |
|
749 |
#undef LZO_DETERMINISTIC |
|
750 |
||
751 |
#define M1_MAX_OFFSET 0x0400 |
|
752 |
#ifndef M2_MAX_OFFSET |
|
753 |
#define M2_MAX_OFFSET 0x0800 |
|
754 |
#endif |
|
755 |
#define M3_MAX_OFFSET 0x4000 |
|
756 |
#define M4_MAX_OFFSET 0xbfff |
|
757 |
||
758 |
#define MX_MAX_OFFSET (M1_MAX_OFFSET + M2_MAX_OFFSET) |
|
759 |
||
760 |
#define M1_MIN_LEN 2 |
|
761 |
#define M1_MAX_LEN 2 |
|
762 |
#define M2_MIN_LEN 3 |
|
763 |
#ifndef M2_MAX_LEN |
|
764 |
#define M2_MAX_LEN 8 |
|
765 |
#endif |
|
766 |
#define M3_MIN_LEN 3 |
|
767 |
#define M3_MAX_LEN 33 |
|
768 |
#define M4_MIN_LEN 3 |
|
769 |
#define M4_MAX_LEN 9 |
|
770 |
||
771 |
#define M1_MARKER 0 |
|
772 |
#define M2_MARKER 64 |
|
773 |
#define M3_MARKER 32 |
|
774 |
#define M4_MARKER 16 |
|
775 |
||
776 |
#ifndef MIN_LOOKAHEAD |
|
777 |
#define MIN_LOOKAHEAD (M2_MAX_LEN + 1) |
|
778 |
#endif |
|
779 |
||
780 |
#if defined(LZO_NEED_DICT_H) |
|
781 |
||
782 |
#ifndef LZO_HASH |
|
783 |
#define LZO_HASH LZO_HASH_LZO_INCREMENTAL_B |
|
784 |
#endif |
|
785 |
#define DL_MIN_LEN M2_MIN_LEN |
|
786 |
||
787 |
#ifndef __LZO_DICT_H |
|
788 |
#define __LZO_DICT_H |
|
789 |
||
790 |
#ifdef __cplusplus |
|
791 |
extern "C" { |
|
792 |
#endif |
|
793 |
||
794 |
#if !defined(D_BITS) && defined(DBITS) |
|
795 |
# define D_BITS DBITS |
|
796 |
#endif |
|
797 |
#if !defined(D_BITS) |
|
798 |
# error "D_BITS is not defined" |
|
799 |
#endif |
|
800 |
#if (D_BITS < 16) |
|
801 |
# define D_SIZE LZO_SIZE(D_BITS) |
|
802 |
# define D_MASK LZO_MASK(D_BITS) |
|
803 |
#else |
|
804 |
# define D_SIZE LZO_USIZE(D_BITS) |
|
805 |
# define D_MASK LZO_UMASK(D_BITS) |
|
806 |
#endif |
|
807 |
#define D_HIGH ((D_MASK >> 1) + 1) |
|
808 |
||
809 |
#if !defined(DD_BITS) |
|
810 |
# define DD_BITS 0 |
|
811 |
#endif |
|
812 |
#define DD_SIZE LZO_SIZE(DD_BITS) |
|
813 |
#define DD_MASK LZO_MASK(DD_BITS) |
|
814 |
||
815 |
#if !defined(DL_BITS) |
|
816 |
# define DL_BITS (D_BITS - DD_BITS) |
|
817 |
#endif |
|
818 |
#if (DL_BITS < 16) |
|
819 |
# define DL_SIZE LZO_SIZE(DL_BITS) |
|
820 |
# define DL_MASK LZO_MASK(DL_BITS) |
|
821 |
#else |
|
822 |
# define DL_SIZE LZO_USIZE(DL_BITS) |
|
823 |
# define DL_MASK LZO_UMASK(DL_BITS) |
|
824 |
#endif |
|
825 |
||
826 |
#if (D_BITS != DL_BITS + DD_BITS) |
|
827 |
# error "D_BITS does not match" |
|
828 |
#endif |
|
829 |
#if (D_BITS < 8 || D_BITS > 18) |
|
830 |
# error "invalid D_BITS" |
|
831 |
#endif |
|
832 |
#if (DL_BITS < 8 || DL_BITS > 20) |
|
833 |
# error "invalid DL_BITS" |
|
834 |
#endif |
|
835 |
#if (DD_BITS < 0 || DD_BITS > 6) |
|
836 |
# error "invalid DD_BITS" |
|
837 |
#endif |
|
838 |
||
839 |
#if !defined(DL_MIN_LEN) |
|
840 |
# define DL_MIN_LEN 3 |
|
841 |
#endif |
|
842 |
#if !defined(DL_SHIFT) |
|
843 |
# define DL_SHIFT ((DL_BITS + (DL_MIN_LEN - 1)) / DL_MIN_LEN) |
|
844 |
#endif |
|
845 |
||
846 |
#define LZO_HASH_GZIP 1 |
|
847 |
#define LZO_HASH_GZIP_INCREMENTAL 2 |
|
848 |
#define LZO_HASH_LZO_INCREMENTAL_A 3 |
|
849 |
#define LZO_HASH_LZO_INCREMENTAL_B 4 |
|
850 |
||
851 |
#if !defined(LZO_HASH) |
|
852 |
# error "choose a hashing strategy" |
|
853 |
#endif |
|
854 |
||
855 |
#if (DL_MIN_LEN == 3) |
|
856 |
# define _DV2_A(p,shift1,shift2) \ |
|
857 |
(((( (lzo_uint32)((p)[0]) << shift1) ^ (p)[1]) << shift2) ^ (p)[2]) |
|
858 |
# define _DV2_B(p,shift1,shift2) \ |
|
859 |
(((( (lzo_uint32)((p)[2]) << shift1) ^ (p)[1]) << shift2) ^ (p)[0]) |
|
860 |
# define _DV3_B(p,shift1,shift2,shift3) \ |
|
861 |
((_DV2_B((p)+1,shift1,shift2) << (shift3)) ^ (p)[0]) |
|
862 |
#elif (DL_MIN_LEN == 2) |
|
863 |
# define _DV2_A(p,shift1,shift2) \ |
|
864 |
(( (lzo_uint32)(p[0]) << shift1) ^ p[1]) |
|
865 |
# define _DV2_B(p,shift1,shift2) \ |
|
866 |
(( (lzo_uint32)(p[1]) << shift1) ^ p[2]) |
|
867 |
#else |
|
868 |
# error "invalid DL_MIN_LEN" |
|
869 |
#endif |
|
870 |
#define _DV_A(p,shift) _DV2_A(p,shift,shift) |
|
871 |
#define _DV_B(p,shift) _DV2_B(p,shift,shift) |
|
872 |
#define DA2(p,s1,s2) \ |
|
873 |
(((((lzo_uint32)((p)[2]) << (s2)) + (p)[1]) << (s1)) + (p)[0]) |
|
874 |
#define DS2(p,s1,s2) \ |
|
875 |
(((((lzo_uint32)((p)[2]) << (s2)) - (p)[1]) << (s1)) - (p)[0]) |
|
876 |
#define DX2(p,s1,s2) \ |
|
877 |
(((((lzo_uint32)((p)[2]) << (s2)) ^ (p)[1]) << (s1)) ^ (p)[0]) |
|
878 |
#define DA3(p,s1,s2,s3) ((DA2((p)+1,s2,s3) << (s1)) + (p)[0]) |
|
879 |
#define DS3(p,s1,s2,s3) ((DS2((p)+1,s2,s3) << (s1)) - (p)[0]) |
|
880 |
#define DX3(p,s1,s2,s3) ((DX2((p)+1,s2,s3) << (s1)) ^ (p)[0]) |
|
881 |
#define DMS(v,s) ((lzo_uint) (((v) & (D_MASK >> (s))) << (s))) |
|
882 |
#define DM(v) DMS(v,0) |
|
883 |
||
884 |
#if (LZO_HASH == LZO_HASH_GZIP) |
|
885 |
# define _DINDEX(dv,p) (_DV_A((p),DL_SHIFT)) |
|
886 |
||
887 |
#elif (LZO_HASH == LZO_HASH_GZIP_INCREMENTAL) |
|
888 |
# define __LZO_HASH_INCREMENTAL |
|
889 |
# define DVAL_FIRST(dv,p) dv = _DV_A((p),DL_SHIFT) |
|
890 |
# define DVAL_NEXT(dv,p) dv = (((dv) << DL_SHIFT) ^ p[2]) |
|
891 |
# define _DINDEX(dv,p) (dv) |
|
892 |
# define DVAL_LOOKAHEAD DL_MIN_LEN |
|
893 |
||
894 |
#elif (LZO_HASH == LZO_HASH_LZO_INCREMENTAL_A) |
|
895 |
# define __LZO_HASH_INCREMENTAL |
|
896 |
# define DVAL_FIRST(dv,p) dv = _DV_A((p),5) |
|
897 |
# define DVAL_NEXT(dv,p) \ |
|
898 |
dv ^= (lzo_uint32)(p[-1]) << (2*5); dv = (((dv) << 5) ^ p[2]) |
|
899 |
# define _DINDEX(dv,p) ((0x9f5f * (dv)) >> 5) |
|
900 |
# define DVAL_LOOKAHEAD DL_MIN_LEN |
|
901 |
||
902 |
#elif (LZO_HASH == LZO_HASH_LZO_INCREMENTAL_B) |
|
903 |
# define __LZO_HASH_INCREMENTAL |
|
904 |
# define DVAL_FIRST(dv,p) dv = _DV_B((p),5) |
|
905 |
# define DVAL_NEXT(dv,p) \ |
|
906 |
dv ^= p[-1]; dv = (((dv) >> 5) ^ ((lzo_uint32)(p[2]) << (2*5))) |
|
907 |
# define _DINDEX(dv,p) ((0x9f5f * (dv)) >> 5) |
|
908 |
# define DVAL_LOOKAHEAD DL_MIN_LEN |
|
909 |
||
910 |
#else |
|
911 |
# error "choose a hashing strategy" |
|
912 |
#endif |
|
913 |
||
914 |
#ifndef DINDEX |
|
915 |
#define DINDEX(dv,p) ((lzo_uint)((_DINDEX(dv,p)) & DL_MASK) << DD_BITS) |
|
916 |
#endif |
|
917 |
#if !defined(DINDEX1) && defined(D_INDEX1) |
|
918 |
#define DINDEX1 D_INDEX1 |
|
919 |
#endif |
|
920 |
#if !defined(DINDEX2) && defined(D_INDEX2) |
|
921 |
#define DINDEX2 D_INDEX2 |
|
922 |
#endif |
|
923 |
||
924 |
#if !defined(__LZO_HASH_INCREMENTAL) |
|
925 |
# define DVAL_FIRST(dv,p) ((void) 0) |
|
926 |
# define DVAL_NEXT(dv,p) ((void) 0) |
|
927 |
# define DVAL_LOOKAHEAD 0 |
|
928 |
#endif |
|
929 |
||
930 |
#if !defined(DVAL_ASSERT) |
|
931 |
#if defined(__LZO_HASH_INCREMENTAL) && !defined(NDEBUG) |
|
932 |
static void DVAL_ASSERT(lzo_uint32 dv, const lzo_byte *p) |
|
933 |
{ |
|
934 |
lzo_uint32 df; |
|
935 |
DVAL_FIRST(df,(p)); |
|
936 |
assert(DINDEX(dv,p) == DINDEX(df,p)); |
|
937 |
} |
|
938 |
#else |
|
939 |
# define DVAL_ASSERT(dv,p) ((void) 0) |
|
940 |
#endif |
|
941 |
#endif |
|
942 |
||
943 |
#if defined(LZO_DICT_USE_PTR) |
|
944 |
# define DENTRY(p,in) (p) |
|
945 |
# define GINDEX(m_pos,m_off,dict,dindex,in) m_pos = dict[dindex] |
|
946 |
#else |
|
947 |
# define DENTRY(p,in) ((lzo_uint) ((p)-(in))) |
|
948 |
# define GINDEX(m_pos,m_off,dict,dindex,in) m_off = dict[dindex] |
|
949 |
#endif |
|
950 |
||
951 |
#if (DD_BITS == 0) |
|
952 |
||
953 |
# define UPDATE_D(dict,drun,dv,p,in) dict[ DINDEX(dv,p) ] = DENTRY(p,in) |
|
954 |
# define UPDATE_I(dict,drun,index,p,in) dict[index] = DENTRY(p,in) |
|
955 |
# define UPDATE_P(ptr,drun,p,in) (ptr)[0] = DENTRY(p,in) |
|
956 |
||
957 |
#else |
|
958 |
||
959 |
# define UPDATE_D(dict,drun,dv,p,in) \ |
|
960 |
dict[ DINDEX(dv,p) + drun++ ] = DENTRY(p,in); drun &= DD_MASK |
|
961 |
# define UPDATE_I(dict,drun,index,p,in) \ |
|
962 |
dict[ (index) + drun++ ] = DENTRY(p,in); drun &= DD_MASK |
|
963 |
# define UPDATE_P(ptr,drun,p,in) \ |
|
964 |
(ptr) [ drun++ ] = DENTRY(p,in); drun &= DD_MASK |
|
965 |
||
966 |
#endif |
|
967 |
||
968 |
#if defined(LZO_DICT_USE_PTR) |
|
969 |
||
970 |
#define LZO_CHECK_MPOS_DET(m_pos,m_off,in,ip,max_offset) \ |
|
971 |
(m_pos == NULL || (m_off = (lzo_moff_t) (ip - m_pos)) > max_offset) |
|
972 |
||
973 |
#define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \ |
|
974 |
(BOUNDS_CHECKING_OFF_IN_EXPR( \ |
|
975 |
(PTR_LT(m_pos,in) || \ |
|
976 |
(m_off = (lzo_moff_t) PTR_DIFF(ip,m_pos)) <= 0 || \ |
|
977 |
m_off > max_offset) )) |
|
978 |
||
979 |
#else |
|
980 |
||
981 |
#define LZO_CHECK_MPOS_DET(m_pos,m_off,in,ip,max_offset) \ |
|
982 |
(m_off == 0 || \ |
|
983 |
((m_off = (lzo_moff_t) ((ip)-(in)) - m_off) > max_offset) || \ |
|
984 |
(m_pos = (ip) - (m_off), 0) ) |
|
985 |
||
986 |
#define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \ |
|
987 |
((lzo_moff_t) ((ip)-(in)) <= m_off || \ |
|
988 |
((m_off = (lzo_moff_t) ((ip)-(in)) - m_off) > max_offset) || \ |
|
989 |
(m_pos = (ip) - (m_off), 0) ) |
|
990 |
||
991 |
#endif |
|
992 |
||
993 |
#if defined(LZO_DETERMINISTIC) |
|
994 |
# define LZO_CHECK_MPOS LZO_CHECK_MPOS_DET |
|
995 |
#else |
|
996 |
# define LZO_CHECK_MPOS LZO_CHECK_MPOS_NON_DET |
|
997 |
#endif |
|
998 |
||
999 |
#ifdef __cplusplus |
|
1000 |
} |
|
1001 |
#endif |
|
1002 |
||
1003 |
#endif |
|
1004 |
||
1005 |
#endif |
|
1006 |
||
1007 |
#endif |
|
1008 |
||
1009 |
#define DO_COMPRESS lzo1x_1_compress |
|
1010 |
||
1011 |
static |
|
1012 |
lzo_uint do_compress ( const lzo_byte *in , lzo_uint in_len, |
|
1013 |
lzo_byte *out, lzo_uintp out_len, |
|
1014 |
lzo_voidp wrkmem ) |
|
1015 |
{ |
|
1016 |
register const lzo_byte *ip; |
|
1017 |
lzo_byte *op; |
|
1018 |
const lzo_byte * const in_end = in + in_len; |
|
1019 |
const lzo_byte * const ip_end = in + in_len - M2_MAX_LEN - 5; |
|
1020 |
const lzo_byte *ii; |
|
1021 |
lzo_dict_p const dict = (lzo_dict_p) wrkmem; |
|
1022 |
||
1023 |
op = out; |
|
1024 |
ip = in; |
|
1025 |
ii = ip; |
|
1026 |
||
1027 |
ip += 4; |
|
1028 |
for (;;) |
|
1029 |
{ |
|
1030 |
register const lzo_byte *m_pos; |
|
1031 |
lzo_moff_t m_off; |
|
9156
b9618a02f28b
(svn r13019) -Fix [FS#1997]: silence some more MSVC x64 warnings (michi_cc)
glx
parents:
9111
diff
changeset
|
1032 |
lzo_ptrdiff_t m_len; |
0 | 1033 |
lzo_uint dindex; |
1034 |
||
1035 |
DINDEX1(dindex,ip); |
|
1036 |
GINDEX(m_pos,m_off,dict,dindex,in); |
|
1037 |
if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET)) |
|
1038 |
goto literal; |
|
1039 |
if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3]) |
|
1040 |
goto try_match; |
|
1041 |
DINDEX2(dindex,ip); |
|
1042 |
GINDEX(m_pos,m_off,dict,dindex,in); |
|
1043 |
if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET)) |
|
1044 |
goto literal; |
|
1045 |
if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3]) |
|
1046 |
goto try_match; |
|
1047 |
goto literal; |
|
1048 |
||
1049 |
try_match: |
|
1050 |
#if 1 && defined(LZO_UNALIGNED_OK_2) |
|
1051 |
if (* (const lzo_ushortp) m_pos != * (const lzo_ushortp) ip) |
|
1052 |
#else |
|
1053 |
if (m_pos[0] != ip[0] || m_pos[1] != ip[1]) |
|
1054 |
#endif |
|
1055 |
{ |
|
1056 |
} |
|
1057 |
else |
|
1058 |
{ |
|
1059 |
if (m_pos[2] == ip[2]) |
|
1060 |
{ |
|
1061 |
goto match; |
|
1062 |
} |
|
1063 |
} |
|
1064 |
||
1065 |
literal: |
|
1066 |
UPDATE_I(dict,0,dindex,ip,in); |
|
1067 |
++ip; |
|
1068 |
if (ip >= ip_end) |
|
1069 |
break; |
|
1070 |
continue; |
|
1071 |
||
1072 |
match: |
|
1073 |
UPDATE_I(dict,0,dindex,ip,in); |
|
1074 |
if (pd(ip,ii) > 0) |
|
1075 |
{ |
|
1076 |
register lzo_uint t = pd(ip,ii); |
|
1077 |
||
1078 |
if (t <= 3) |
|
1079 |
{ |
|
1080 |
assert(op - 2 > out); |
|
1081 |
op[-2] |= LZO_BYTE(t); |
|
1082 |
} |
|
1083 |
else if (t <= 18) |
|
1084 |
*op++ = LZO_BYTE(t - 3); |
|
1085 |
else |
|
1086 |
{ |
|
1087 |
register lzo_uint tt = t - 18; |
|
1088 |
||
1089 |
*op++ = 0; |
|
1090 |
while (tt > 255) |
|
1091 |
{ |
|
1092 |
tt -= 255; |
|
1093 |
*op++ = 0; |
|
1094 |
} |
|
1095 |
assert(tt > 0); |
|
1096 |
*op++ = LZO_BYTE(tt); |
|
1097 |
} |
|
1098 |
do *op++ = *ii++; while (--t > 0); |
|
1099 |
} |
|
1100 |
||
1101 |
assert(ii == ip); |
|
1102 |
ip += 3; |
|
1103 |
if (m_pos[3] != *ip++ || m_pos[4] != *ip++ || m_pos[5] != *ip++ || |
|
1104 |
m_pos[6] != *ip++ || m_pos[7] != *ip++ || m_pos[8] != *ip++) { |
|
1105 |
||
1106 |
--ip; |
|
1107 |
m_len = ip - ii; |
|
1108 |
assert(m_len >= 3); assert(m_len <= M2_MAX_LEN); |
|
1109 |
||
1110 |
if (m_off <= M2_MAX_OFFSET) |
|
1111 |
{ |
|
1112 |
m_off -= 1; |
|
1113 |
*op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2)); |
|
1114 |
*op++ = LZO_BYTE(m_off >> 3); |
|
1115 |
} |
|
1116 |
else if (m_off <= M3_MAX_OFFSET) |
|
1117 |
{ |
|
1118 |
m_off -= 1; |
|
1119 |
*op++ = LZO_BYTE(M3_MARKER | (m_len - 2)); |
|
1120 |
goto m3_m4_offset; |
|
1121 |
} |
|
1122 |
else |
|
1123 |
{ |
|
1124 |
m_off -= 0x4000; |
|
1125 |
assert(m_off > 0); assert(m_off <= 0x7fff); |
|
1126 |
*op++ = LZO_BYTE(M4_MARKER | |
|
1127 |
((m_off & 0x4000) >> 11) | (m_len - 2)); |
|
1128 |
goto m3_m4_offset; |
|
1129 |
} |
|
1130 |
} |
|
1131 |
else |
|
1132 |
{ |
|
1133 |
{ |
|
1134 |
const lzo_byte *end = in_end; |
|
1135 |
const lzo_byte *m = m_pos + M2_MAX_LEN + 1; |
|
1136 |
while (ip < end && *m == *ip) |
|
1137 |
m++, ip++; |
|
1138 |
m_len = (ip - ii); |
|
1139 |
} |
|
1140 |
assert(m_len > M2_MAX_LEN); |
|
1141 |
||
1142 |
if (m_off <= M3_MAX_OFFSET) |
|
1143 |
{ |
|
1144 |
m_off -= 1; |
|
1145 |
if (m_len <= 33) |
|
1146 |
*op++ = LZO_BYTE(M3_MARKER | (m_len - 2)); |
|
1147 |
else |
|
1148 |
{ |
|
1149 |
m_len -= 33; |
|
1150 |
*op++ = M3_MARKER | 0; |
|
1151 |
goto m3_m4_len; |
|
1152 |
} |
|
1153 |
} |
|
1154 |
else |
|
1155 |
{ |
|
1156 |
m_off -= 0x4000; |
|
1157 |
assert(m_off > 0); assert(m_off <= 0x7fff); |
|
1158 |
if (m_len <= M4_MAX_LEN) |
|
1159 |
*op++ = LZO_BYTE(M4_MARKER | |
|
1160 |
((m_off & 0x4000) >> 11) | (m_len - 2)); |
|
1161 |
else |
|
1162 |
{ |
|
1163 |
m_len -= M4_MAX_LEN; |
|
1164 |
*op++ = LZO_BYTE(M4_MARKER | ((m_off & 0x4000) >> 11)); |
|
1165 |
m3_m4_len: |
|
1166 |
while (m_len > 255) |
|
1167 |
{ |
|
1168 |
m_len -= 255; |
|
1169 |
*op++ = 0; |
|
1170 |
} |
|
1171 |
assert(m_len > 0); |
|
1172 |
*op++ = LZO_BYTE(m_len); |
|
1173 |
} |
|
1174 |
} |
|
1175 |
||
1176 |
m3_m4_offset: |
|
1177 |
*op++ = LZO_BYTE((m_off & 63) << 2); |
|
1178 |
*op++ = LZO_BYTE(m_off >> 6); |
|
1179 |
} |
|
1180 |
||
1181 |
ii = ip; |
|
1182 |
if (ip >= ip_end) |
|
1183 |
break; |
|
1184 |
} |
|
1185 |
||
9390
88d36f907e96
(svn r13301) -Fix [FS#1997]: resolve more MSVC 9 x64 warnings.
rubidium
parents:
9156
diff
changeset
|
1186 |
*out_len = (lzo_uint)(op - out); |
0 | 1187 |
return pd(in_end,ii); |
1188 |
} |
|
1189 |
||
1190 |
LZO_PUBLIC(int) |
|
1191 |
DO_COMPRESS ( const lzo_byte *in , lzo_uint in_len, |
|
1192 |
lzo_byte *out, lzo_uintp out_len, |
|
1193 |
lzo_voidp wrkmem ) |
|
1194 |
{ |
|
1195 |
lzo_byte *op = out; |
|
1196 |
lzo_uint t; |
|
1197 |
||
1198 |
if (in_len <= M2_MAX_LEN + 5) |
|
1199 |
t = in_len; |
|
1200 |
else |
|
1201 |
{ |
|
1202 |
t = do_compress(in,in_len,op,out_len,wrkmem); |
|
1203 |
op += *out_len; |
|
1204 |
} |
|
1205 |
||
1206 |
if (t > 0) |
|
1207 |
{ |
|
1208 |
const lzo_byte *ii = in + in_len - t; |
|
1209 |
||
1210 |
if (op == out && t <= 238) |
|
1211 |
*op++ = LZO_BYTE(17 + t); |
|
1212 |
else if (t <= 3) |
|
1213 |
op[-2] |= LZO_BYTE(t); |
|
1214 |
else if (t <= 18) |
|
1215 |
*op++ = LZO_BYTE(t - 3); |
|
1216 |
else |
|
1217 |
{ |
|
1218 |
lzo_uint tt = t - 18; |
|
1219 |
||
1220 |
*op++ = 0; |
|
1221 |
while (tt > 255) |
|
1222 |
{ |
|
1223 |
tt -= 255; |
|
1224 |
*op++ = 0; |
|
1225 |
} |
|
1226 |
assert(tt > 0); |
|
1227 |
*op++ = LZO_BYTE(tt); |
|
1228 |
} |
|
1229 |
do *op++ = *ii++; while (--t > 0); |
|
1230 |
} |
|
1231 |
||
1232 |
*op++ = M4_MARKER | 1; |
|
1233 |
*op++ = 0; |
|
1234 |
*op++ = 0; |
|
1235 |
||
9390
88d36f907e96
(svn r13301) -Fix [FS#1997]: resolve more MSVC 9 x64 warnings.
rubidium
parents:
9156
diff
changeset
|
1236 |
*out_len = (lzo_uint)(op - out); |
0 | 1237 |
return LZO_E_OK; |
1238 |
} |
|
1239 |
||
1240 |
#undef do_compress |
|
1241 |
#undef DO_COMPRESS |
|
1242 |
#undef LZO_HASH |
|
1243 |
||
1244 |
#undef LZO_TEST_DECOMPRESS_OVERRUN |
|
1245 |
#undef LZO_TEST_DECOMPRESS_OVERRUN_INPUT |
|
1246 |
#undef LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT |
|
1247 |
#undef LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND |
|
1248 |
#undef DO_DECOMPRESS |
|
1249 |
#define DO_DECOMPRESS lzo1x_decompress |
|
1250 |
||
1251 |
#if defined(LZO_TEST_DECOMPRESS_OVERRUN) |
|
1252 |
# if !defined(LZO_TEST_DECOMPRESS_OVERRUN_INPUT) |
|
1253 |
# define LZO_TEST_DECOMPRESS_OVERRUN_INPUT 2 |
|
1254 |
# endif |
|
1255 |
# if !defined(LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT) |
|
1256 |
# define LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT 2 |
|
1257 |
# endif |
|
1258 |
# if !defined(LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND) |
|
1259 |
# define LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND |
|
1260 |
# endif |
|
1261 |
#endif |
|
1262 |
||
1263 |
#undef TEST_IP |
|
1264 |
#undef TEST_OP |
|
1265 |
#undef TEST_LOOKBEHIND |
|
1266 |
#undef NEED_IP |
|
1267 |
#undef NEED_OP |
|
1268 |
#undef HAVE_TEST_IP |
|
1269 |
#undef HAVE_TEST_OP |
|
1270 |
#undef HAVE_NEED_IP |
|
1271 |
#undef HAVE_NEED_OP |
|
1272 |
#undef HAVE_ANY_IP |
|
1273 |
#undef HAVE_ANY_OP |
|
1274 |
||
1275 |
#if defined(LZO_TEST_DECOMPRESS_OVERRUN_INPUT) |
|
1276 |
# if (LZO_TEST_DECOMPRESS_OVERRUN_INPUT >= 1) |
|
1277 |
# define TEST_IP (ip < ip_end) |
|
1278 |
# endif |
|
1279 |
# if (LZO_TEST_DECOMPRESS_OVERRUN_INPUT >= 2) |
|
1280 |
# define NEED_IP(x) \ |
|
1281 |
if ((lzo_uint)(ip_end - ip) < (lzo_uint)(x)) goto input_overrun |
|
1282 |
# endif |
|
1283 |
#endif |
|
1284 |
||
1285 |
#if defined(LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT) |
|
1286 |
# if (LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT >= 1) |
|
1287 |
# define TEST_OP (op <= op_end) |
|
1288 |
# endif |
|
1289 |
# if (LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT >= 2) |
|
1290 |
# undef TEST_OP |
|
1291 |
# define NEED_OP(x) \ |
|
1292 |
if ((lzo_uint)(op_end - op) < (lzo_uint)(x)) goto output_overrun |
|
1293 |
# endif |
|
1294 |
#endif |
|
1295 |
||
1296 |
#if defined(LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND) |
|
1297 |
# define TEST_LOOKBEHIND(m_pos,out) if (m_pos < out) goto lookbehind_overrun |
|
1298 |
#else |
|
1299 |
# define TEST_LOOKBEHIND(m_pos,op) ((void) 0) |
|
1300 |
#endif |
|
1301 |
||
1302 |
#if !defined(LZO_EOF_CODE) && !defined(TEST_IP) |
|
1303 |
# define TEST_IP (ip < ip_end) |
|
1304 |
#endif |
|
1305 |
||
1306 |
#if defined(TEST_IP) |
|
1307 |
# define HAVE_TEST_IP |
|
1308 |
#else |
|
1309 |
# define TEST_IP 1 |
|
1310 |
#endif |
|
1311 |
#if defined(TEST_OP) |
|
1312 |
# define HAVE_TEST_OP |
|
1313 |
#else |
|
1314 |
# define TEST_OP 1 |
|
1315 |
#endif |
|
1316 |
||
1317 |
#if defined(NEED_IP) |
|
1318 |
# define HAVE_NEED_IP |
|
1319 |
#else |
|
1320 |
# define NEED_IP(x) ((void) 0) |
|
1321 |
#endif |
|
1322 |
#if defined(NEED_OP) |
|
1323 |
# define HAVE_NEED_OP |
|
1324 |
#else |
|
1325 |
# define NEED_OP(x) ((void) 0) |
|
1326 |
#endif |
|
1327 |
||
1328 |
#if defined(HAVE_TEST_IP) || defined(HAVE_NEED_IP) |
|
1329 |
# define HAVE_ANY_IP |
|
1330 |
#endif |
|
1331 |
#if defined(HAVE_TEST_OP) || defined(HAVE_NEED_OP) |
|
1332 |
# define HAVE_ANY_OP |
|
1333 |
#endif |
|
1334 |
||
1335 |
#undef __COPY4 |
|
1336 |
#define __COPY4(dst,src) * (lzo_uint32p)(dst) = * (const lzo_uint32p)(src) |
|
1337 |
||
1338 |
#undef COPY4 |
|
1339 |
#if defined(LZO_UNALIGNED_OK_4) |
|
1340 |
# define COPY4(dst,src) __COPY4(dst,src) |
|
1341 |
#elif defined(LZO_ALIGNED_OK_4) |
|
1342 |
# define COPY4(dst,src) __COPY4((lzo_ptr_t)(dst),(lzo_ptr_t)(src)) |
|
1343 |
#endif |
|
1344 |
||
1345 |
#if defined(DO_DECOMPRESS) |
|
1346 |
LZO_PUBLIC(int) |
|
1347 |
DO_DECOMPRESS ( const lzo_byte *in , lzo_uint in_len, |
|
1348 |
lzo_byte *out, lzo_uintp out_len, |
|
1349 |
lzo_voidp wrkmem ) |
|
1350 |
#endif |
|
1351 |
{ |
|
1352 |
register lzo_byte *op; |
|
1353 |
register const lzo_byte *ip; |
|
1354 |
register lzo_uint t; |
|
1355 |
register const lzo_byte *m_pos; |
|
1356 |
||
1357 |
const lzo_byte * const ip_end = in + in_len; |
|
1358 |
#if defined(HAVE_ANY_OP) |
|
1359 |
lzo_byte * const op_end = out + *out_len; |
|
1360 |
#endif |
|
1361 |
||
1362 |
LZO_UNUSED(wrkmem); |
|
1363 |
||
1364 |
*out_len = 0; |
|
1365 |
||
1366 |
op = out; |
|
1367 |
ip = in; |
|
1368 |
||
1369 |
if (*ip > 17) |
|
1370 |
{ |
|
1371 |
t = *ip++ - 17; |
|
1372 |
if (t < 4) |
|
1373 |
goto match_next; |
|
1374 |
assert(t > 0); NEED_OP(t); NEED_IP(t+1); |
|
1375 |
do *op++ = *ip++; while (--t > 0); |
|
1376 |
goto first_literal_run; |
|
1377 |
} |
|
1378 |
||
1379 |
while (TEST_IP && TEST_OP) |
|
1380 |
{ |
|
1381 |
t = *ip++; |
|
1382 |
if (t >= 16) |
|
1383 |
goto match; |
|
1384 |
if (t == 0) |
|
1385 |
{ |
|
1386 |
NEED_IP(1); |
|
1387 |
while (*ip == 0) |
|
1388 |
{ |
|
1389 |
t += 255; |
|
1390 |
ip++; |
|
1391 |
NEED_IP(1); |
|
1392 |
} |
|
1393 |
t += 15 + *ip++; |
|
1394 |
} |
|
1395 |
assert(t > 0); NEED_OP(t+3); NEED_IP(t+4); |
|
1396 |
#if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) |
|
1397 |
#if !defined(LZO_UNALIGNED_OK_4) |
|
1398 |
if (PTR_ALIGNED2_4(op,ip)) |
|
1399 |
{ |
|
1400 |
#endif |
|
1401 |
COPY4(op,ip); |
|
1402 |
op += 4; ip += 4; |
|
1403 |
if (--t > 0) |
|
1404 |
{ |
|
1405 |
if (t >= 4) |
|
1406 |
{ |
|
1407 |
do { |
|
1408 |
COPY4(op,ip); |
|
1409 |
op += 4; ip += 4; t -= 4; |
|
1410 |
} while (t >= 4); |
|
1411 |
if (t > 0) do *op++ = *ip++; while (--t > 0); |
|
1412 |
} |
|
1413 |
else |
|
1414 |
do *op++ = *ip++; while (--t > 0); |
|
1415 |
} |
|
1416 |
#if !defined(LZO_UNALIGNED_OK_4) |
|
1417 |
} |
|
1418 |
else |
|
1419 |
#endif |
|
1420 |
#endif |
|
1421 |
#if !defined(LZO_UNALIGNED_OK_4) |
|
1422 |
{ |
|
1423 |
*op++ = *ip++; *op++ = *ip++; *op++ = *ip++; |
|
1424 |
do *op++ = *ip++; while (--t > 0); |
|
1425 |
} |
|
1426 |
#endif |
|
1427 |
||
1428 |
first_literal_run: |
|
1429 |
||
1430 |
t = *ip++; |
|
1431 |
if (t >= 16) |
|
1432 |
goto match; |
|
1433 |
m_pos = op - (1 + M2_MAX_OFFSET); |
|
1434 |
m_pos -= t >> 2; |
|
1435 |
m_pos -= *ip++ << 2; |
|
1436 |
TEST_LOOKBEHIND(m_pos,out); NEED_OP(3); |
|
1437 |
*op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos; |
|
1438 |
goto match_done; |
|
1439 |
||
1440 |
while (TEST_IP && TEST_OP) |
|
1441 |
{ |
|
1442 |
match: |
|
1443 |
if (t >= 64) |
|
1444 |
{ |
|
1445 |
#if defined(LZO1X) |
|
1446 |
m_pos = op - 1; |
|
1447 |
m_pos -= (t >> 2) & 7; |
|
1448 |
m_pos -= *ip++ << 3; |
|
1449 |
t = (t >> 5) - 1; |
|
1450 |
#endif |
|
1451 |
TEST_LOOKBEHIND(m_pos,out); assert(t > 0); NEED_OP(t+3-1); |
|
1452 |
goto copy_match; |
|
1453 |
} |
|
1454 |
else if (t >= 32) |
|
1455 |
{ |
|
1456 |
t &= 31; |
|
1457 |
if (t == 0) |
|
1458 |
{ |
|
1459 |
NEED_IP(1); |
|
1460 |
while (*ip == 0) |
|
1461 |
{ |
|
1462 |
t += 255; |
|
1463 |
ip++; |
|
1464 |
NEED_IP(1); |
|
1465 |
} |
|
1466 |
t += 31 + *ip++; |
|
1467 |
} |
|
1468 |
#if defined(LZO_UNALIGNED_OK_2) && (LZO_BYTE_ORDER == LZO_LITTLE_ENDIAN) |
|
1469 |
m_pos = op - 1; |
|
1470 |
m_pos -= (* (const lzo_ushortp) ip) >> 2; |
|
1471 |
#else |
|
1472 |
m_pos = op - 1; |
|
1473 |
m_pos -= (ip[0] >> 2) + (ip[1] << 6); |
|
1474 |
#endif |
|
1475 |
ip += 2; |
|
1476 |
} |
|
1477 |
else if (t >= 16) |
|
1478 |
{ |
|
1479 |
m_pos = op; |
|
1480 |
m_pos -= (t & 8) << 11; |
|
1481 |
t &= 7; |
|
1482 |
if (t == 0) |
|
1483 |
{ |
|
1484 |
NEED_IP(1); |
|
1485 |
while (*ip == 0) |
|
1486 |
{ |
|
1487 |
t += 255; |
|
1488 |
ip++; |
|
1489 |
NEED_IP(1); |
|
1490 |
} |
|
1491 |
t += 7 + *ip++; |
|
1492 |
} |
|
1493 |
#if defined(LZO_UNALIGNED_OK_2) && (LZO_BYTE_ORDER == LZO_LITTLE_ENDIAN) |
|
1494 |
m_pos -= (* (const lzo_ushortp) ip) >> 2; |
|
1495 |
#else |
|
1496 |
m_pos -= (ip[0] >> 2) + (ip[1] << 6); |
|
1497 |
#endif |
|
1498 |
ip += 2; |
|
1499 |
if (m_pos == op) |
|
1500 |
goto eof_found; |
|
1501 |
m_pos -= 0x4000; |
|
1502 |
} |
|
1503 |
else |
|
1504 |
{ |
|
1505 |
m_pos = op - 1; |
|
1506 |
m_pos -= t >> 2; |
|
1507 |
m_pos -= *ip++ << 2; |
|
1508 |
TEST_LOOKBEHIND(m_pos,out); NEED_OP(2); |
|
1509 |
*op++ = *m_pos++; *op++ = *m_pos; |
|
1510 |
goto match_done; |
|
1511 |
} |
|
1512 |
||
1513 |
TEST_LOOKBEHIND(m_pos,out); assert(t > 0); NEED_OP(t+3-1); |
|
1514 |
#if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) |
|
1515 |
#if !defined(LZO_UNALIGNED_OK_4) |
|
1516 |
if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos)) |
|
1517 |
{ |
|
1518 |
assert((op - m_pos) >= 4); |
|
1519 |
#else |
|
1520 |
if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4) |
|
1521 |
{ |
|
1522 |
#endif |
|
1523 |
COPY4(op,m_pos); |
|
1524 |
op += 4; m_pos += 4; t -= 4 - (3 - 1); |
|
1525 |
do { |
|
1526 |
COPY4(op,m_pos); |
|
1527 |
op += 4; m_pos += 4; t -= 4; |
|
1528 |
} while (t >= 4); |
|
1529 |
if (t > 0) do *op++ = *m_pos++; while (--t > 0); |
|
1530 |
} |
|
1531 |
else |
|
1532 |
#endif |
|
1533 |
{ |
|
1534 |
copy_match: |
|
1535 |
*op++ = *m_pos++; *op++ = *m_pos++; |
|
1536 |
do *op++ = *m_pos++; while (--t > 0); |
|
1537 |
} |
|
1538 |
||
1539 |
match_done: |
|
1540 |
t = ip[-2] & 3; |
|
1541 |
if (t == 0) |
|
1542 |
break; |
|
1543 |
||
1544 |
match_next: |
|
1545 |
assert(t > 0); NEED_OP(t); NEED_IP(t+1); |
|
1546 |
do *op++ = *ip++; while (--t > 0); |
|
1547 |
t = *ip++; |
|
1548 |
} |
|
1549 |
} |
|
1550 |
||
1551 |
#if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP) |
|
1552 |
*out_len = op - out; |
|
1553 |
return LZO_E_EOF_NOT_FOUND; |
|
1554 |
#endif |
|
1555 |
||
1556 |
eof_found: |
|
1557 |
assert(t == 1); |
|
9390
88d36f907e96
(svn r13301) -Fix [FS#1997]: resolve more MSVC 9 x64 warnings.
rubidium
parents:
9156
diff
changeset
|
1558 |
*out_len = (lzo_uint)(op - out); |
0 | 1559 |
return (ip == ip_end ? LZO_E_OK : |
1560 |
(ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN)); |
|
1561 |
||
1562 |
#if defined(HAVE_NEED_IP) |
|
1563 |
input_overrun: |
|
1564 |
*out_len = op - out; |
|
1565 |
return LZO_E_INPUT_OVERRUN; |
|
1566 |
#endif |
|
1567 |
||
1568 |
#if defined(HAVE_NEED_OP) |
|
1569 |
output_overrun: |
|
1570 |
*out_len = op - out; |
|
1571 |
return LZO_E_OUTPUT_OVERRUN; |
|
1572 |
#endif |
|
1573 |
||
1574 |
#if defined(LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND) |
|
1575 |
lookbehind_overrun: |
|
1576 |
*out_len = op - out; |
|
1577 |
return LZO_E_LOOKBEHIND_OVERRUN; |
|
1578 |
#endif |
|
1579 |
} |
|
1580 |
||
1581 |
#define LZO_TEST_DECOMPRESS_OVERRUN |
|
1582 |
#undef DO_DECOMPRESS |
|
1583 |
#define DO_DECOMPRESS lzo1x_decompress_safe |
|
1584 |
||
1585 |
#if defined(LZO_TEST_DECOMPRESS_OVERRUN) |
|
1586 |
# if !defined(LZO_TEST_DECOMPRESS_OVERRUN_INPUT) |
|
1587 |
# define LZO_TEST_DECOMPRESS_OVERRUN_INPUT 2 |
|
1588 |
# endif |
|
1589 |
# if !defined(LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT) |
|
1590 |
# define LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT 2 |
|
1591 |
# endif |
|
1592 |
# if !defined(LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND) |
|
1593 |
# define LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND |
|
1594 |
# endif |
|
1595 |
#endif |
|
1596 |
||
1597 |
#undef TEST_IP |
|
1598 |
#undef TEST_OP |
|
1599 |
#undef TEST_LOOKBEHIND |
|
1600 |
#undef NEED_IP |
|
1601 |
#undef NEED_OP |
|
1602 |
#undef HAVE_TEST_IP |
|
1603 |
#undef HAVE_TEST_OP |
|
1604 |
#undef HAVE_NEED_IP |
|
1605 |
#undef HAVE_NEED_OP |
|
1606 |
#undef HAVE_ANY_IP |
|
1607 |
#undef HAVE_ANY_OP |
|
1608 |
||
1609 |
||
1610 |
#if 0 |
|
1611 |
||
1612 |
#if defined(LZO_TEST_DECOMPRESS_OVERRUN_INPUT) |
|
1613 |
# if (LZO_TEST_DECOMPRESS_OVERRUN_INPUT >= 1) |
|
1614 |
# define TEST_IP (ip < ip_end) |
|
1615 |
# endif |
|
1616 |
# if (LZO_TEST_DECOMPRESS_OVERRUN_INPUT >= 2) |
|
1617 |
# define NEED_IP(x) \ |
|
1618 |
if ((lzo_uint)(ip_end - ip) < (lzo_uint)(x)) goto input_overrun |
|
1619 |
# endif |
|
1620 |
#endif |
|
1621 |
||
1622 |
#if defined(LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT) |
|
1623 |
# if (LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT >= 1) |
|
1624 |
# define TEST_OP (op <= op_end) |
|
1625 |
# endif |
|
1626 |
# if (LZO_TEST_DECOMPRESS_OVERRUN_OUTPUT >= 2) |
|
1627 |
# undef TEST_OP |
|
1628 |
# define NEED_OP(x) \ |
|
1629 |
if ((lzo_uint)(op_end - op) < (lzo_uint)(x)) goto output_overrun |
|
1630 |
# endif |
|
1631 |
#endif |
|
1632 |
||
1633 |
#if defined(LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND) |
|
1634 |
# define TEST_LOOKBEHIND(m_pos,out) if (m_pos < out) goto lookbehind_overrun |
|
1635 |
#else |
|
1636 |
# define TEST_LOOKBEHIND(m_pos,op) ((void) 0) |
|
1637 |
#endif |
|
1638 |
||
1639 |
#if !defined(LZO_EOF_CODE) && !defined(TEST_IP) |
|
1640 |
# define TEST_IP (ip < ip_end) |
|
1641 |
#endif |
|
1642 |
||
1643 |
#if defined(TEST_IP) |
|
1644 |
# define HAVE_TEST_IP |
|
1645 |
#else |
|
1646 |
# define TEST_IP 1 |
|
1647 |
#endif |
|
1648 |
#if defined(TEST_OP) |
|
1649 |
# define HAVE_TEST_OP |
|
1650 |
#else |
|
1651 |
# define TEST_OP 1 |
|
1652 |
#endif |
|
1653 |
||
1654 |
#if defined(NEED_IP) |
|
1655 |
# define HAVE_NEED_IP |
|
1656 |
#else |
|
1657 |
# define NEED_IP(x) ((void) 0) |
|
1658 |
#endif |
|
1659 |
#if defined(NEED_OP) |
|
1660 |
# define HAVE_NEED_OP |
|
1661 |
#else |
|
1662 |
# define NEED_OP(x) ((void) 0) |
|
1663 |
#endif |
|
1664 |
||
1665 |
#if defined(HAVE_TEST_IP) || defined(HAVE_NEED_IP) |
|
1666 |
# define HAVE_ANY_IP |
|
1667 |
#endif |
|
1668 |
#if defined(HAVE_TEST_OP) || defined(HAVE_NEED_OP) |
|
1669 |
# define HAVE_ANY_OP |
|
1670 |
#endif |
|
1671 |
||
1672 |
#undef __COPY4 |
|
1673 |
#define __COPY4(dst,src) * (lzo_uint32p)(dst) = * (const lzo_uint32p)(src) |
|
1674 |
||
1675 |
#undef COPY4 |
|
1676 |
#if defined(LZO_UNALIGNED_OK_4) |
|
1677 |
# define COPY4(dst,src) __COPY4(dst,src) |
|
1678 |
#elif defined(LZO_ALIGNED_OK_4) |
|
1679 |
# define COPY4(dst,src) __COPY4((lzo_ptr_t)(dst),(lzo_ptr_t)(src)) |
|
1680 |
#endif |
|
1681 |
||
1682 |
#if defined(DO_DECOMPRESS) |
|
1683 |
LZO_PUBLIC(int) |
|
1684 |
DO_DECOMPRESS ( const lzo_byte *in , lzo_uint in_len, |
|
1685 |
lzo_byte *out, lzo_uintp out_len, |
|
1686 |
lzo_voidp wrkmem ) |
|
1687 |
#endif |
|
1688 |
{ |
|
1689 |
register lzo_byte *op; |
|
1690 |
register const lzo_byte *ip; |
|
1691 |
register lzo_uint t; |
|
1692 |
register const lzo_byte *m_pos; |
|
1693 |
||
1694 |
const lzo_byte * const ip_end = in + in_len; |
|
1695 |
#if defined(HAVE_ANY_OP) |
|
1696 |
lzo_byte * const op_end = out + *out_len; |
|
1697 |
#endif |
|
1698 |
||
1699 |
LZO_UNUSED(wrkmem); |
|
1700 |
||
1701 |
*out_len = 0; |
|
1702 |
||
1703 |
op = out; |
|
1704 |
ip = in; |
|
1705 |
||
1706 |
if (*ip > 17) |
|
1707 |
{ |
|
1708 |
t = *ip++ - 17; |
|
1709 |
if (t < 4) |
|
1710 |
goto match_next; |
|
1711 |
assert(t > 0); NEED_OP(t); NEED_IP(t+1); |
|
1712 |
do *op++ = *ip++; while (--t > 0); |
|
1713 |
goto first_literal_run; |
|
1714 |
} |
|
1715 |
||
1716 |
while (TEST_IP && TEST_OP) |
|
1717 |
{ |
|
1718 |
t = *ip++; |
|
1719 |
if (t >= 16) |
|
1720 |
goto match; |
|
1721 |
if (t == 0) |
|
1722 |
{ |
|
1723 |
NEED_IP(1); |
|
1724 |
while (*ip == 0) |
|
1725 |
{ |
|
1726 |
t += 255; |
|
1727 |
ip++; |
|
1728 |
NEED_IP(1); |
|
1729 |
} |
|
1730 |
t += 15 + *ip++; |
|
1731 |
} |
|
1732 |
assert(t > 0); NEED_OP(t+3); NEED_IP(t+4); |
|
1733 |
#if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) |
|
1734 |
#if !defined(LZO_UNALIGNED_OK_4) |
|
1735 |
if (PTR_ALIGNED2_4(op,ip)) |
|
1736 |
{ |
|
1737 |
#endif |
|
1738 |
COPY4(op,ip); |
|
1739 |
op += 4; ip += 4; |
|
1740 |
if (--t > 0) |
|
1741 |
{ |
|
1742 |
if (t >= 4) |
|
1743 |
{ |
|
1744 |
do { |
|
1745 |
COPY4(op,ip); |
|
1746 |
op += 4; ip += 4; t -= 4; |
|
1747 |
} while (t >= 4); |
|
1748 |
if (t > 0) do *op++ = *ip++; while (--t > 0); |
|
1749 |
} |
|
1750 |
else |
|
1751 |
do *op++ = *ip++; while (--t > 0); |
|
1752 |
} |
|
1753 |
#if !defined(LZO_UNALIGNED_OK_4) |
|
1754 |
} |
|
1755 |
else |
|
1756 |
#endif |
|
1757 |
#endif |
|
1758 |
#if !defined(LZO_UNALIGNED_OK_4) |
|
1759 |
{ |
|
1760 |
*op++ = *ip++; *op++ = *ip++; *op++ = *ip++; |
|
1761 |
do *op++ = *ip++; while (--t > 0); |
|
1762 |
} |
|
1763 |
#endif |
|
1764 |
||
1765 |
first_literal_run: |
|
1766 |
||
1767 |
t = *ip++; |
|
1768 |
if (t >= 16) |
|
1769 |
goto match; |
|
1770 |
#if defined(LZO1Z) |
|
1771 |
t = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2); |
|
1772 |
m_pos = op - t; |
|
1773 |
last_m_off = t; |
|
1774 |
#else |
|
1775 |
m_pos = op - (1 + M2_MAX_OFFSET); |
|
1776 |
m_pos -= t >> 2; |
|
1777 |
m_pos -= *ip++ << 2; |
|
1778 |
#endif |
|
1779 |
TEST_LOOKBEHIND(m_pos,out); NEED_OP(3); |
|
1780 |
*op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos; |
|
1781 |
goto match_done; |
|
1782 |
||
1783 |
while (TEST_IP && TEST_OP) |
|
1784 |
{ |
|
1785 |
match: |
|
1786 |
if (t >= 64) |
|
1787 |
{ |
|
1788 |
#if defined(LZO1X) |
|
1789 |
m_pos = op - 1; |
|
1790 |
m_pos -= (t >> 2) & 7; |
|
1791 |
m_pos -= *ip++ << 3; |
|
1792 |
t = (t >> 5) - 1; |
|
1793 |
#elif defined(LZO1Y) |
|
1794 |
m_pos = op - 1; |
|
1795 |
m_pos -= (t >> 2) & 3; |
|
1796 |
m_pos -= *ip++ << 2; |
|
1797 |
t = (t >> 4) - 3; |
|
1798 |
#elif defined(LZO1Z) |
|
1799 |
{ |
|
1800 |
lzo_uint off = t & 0x1f; |
|
1801 |
m_pos = op; |
|
1802 |
if (off >= 0x1c) |
|
1803 |
{ |
|
1804 |
assert(last_m_off > 0); |
|
1805 |
m_pos -= last_m_off; |
|
1806 |
} |
|
1807 |
else |
|
1808 |
{ |
|
1809 |
off = 1 + (off << 6) + (*ip++ >> 2); |
|
1810 |
m_pos -= off; |
|
1811 |
last_m_off = off; |
|
1812 |
} |
|
1813 |
} |
|
1814 |
t = (t >> 5) - 1; |
|
1815 |
#endif |
|
1816 |
TEST_LOOKBEHIND(m_pos,out); assert(t > 0); NEED_OP(t+3-1); |
|
1817 |
goto copy_match; |
|
1818 |
} |
|
1819 |
else if (t >= 32) |
|
1820 |
{ |
|
1821 |
t &= 31; |
|
1822 |
if (t == 0) |
|
1823 |
{ |
|
1824 |
NEED_IP(1); |
|
1825 |
while (*ip == 0) |
|
1826 |
{ |
|
1827 |
t += 255; |
|
1828 |
ip++; |
|
1829 |
NEED_IP(1); |
|
1830 |
} |
|
1831 |
t += 31 + *ip++; |
|
1832 |
} |
|
1833 |
#if defined(LZO1Z) |
|
1834 |
{ |
|
1835 |
lzo_uint off = 1 + (ip[0] << 6) + (ip[1] >> 2); |
|
1836 |
m_pos = op - off; |
|
1837 |
last_m_off = off; |
|
1838 |
} |
|
1839 |
#elif defined(LZO_UNALIGNED_OK_2) && (LZO_BYTE_ORDER == LZO_LITTLE_ENDIAN) |
|
1840 |
m_pos = op - 1; |
|
1841 |
m_pos -= (* (const lzo_ushortp) ip) >> 2; |
|
1842 |
#else |
|
1843 |
m_pos = op - 1; |
|
1844 |
m_pos -= (ip[0] >> 2) + (ip[1] << 6); |
|
1845 |
#endif |
|
1846 |
ip += 2; |
|
1847 |
} |
|
1848 |
else if (t >= 16) |
|
1849 |
{ |
|
1850 |
m_pos = op; |
|
1851 |
m_pos -= (t & 8) << 11; |
|
1852 |
t &= 7; |
|
1853 |
if (t == 0) |
|
1854 |
{ |
|
1855 |
NEED_IP(1); |
|
1856 |
while (*ip == 0) |
|
1857 |
{ |
|
1858 |
t += 255; |
|
1859 |
ip++; |
|
1860 |
NEED_IP(1); |
|
1861 |
} |
|
1862 |
t += 7 + *ip++; |
|
1863 |
} |
|
1864 |
#if defined(LZO1Z) |
|
1865 |
m_pos -= (ip[0] << 6) + (ip[1] >> 2); |
|
1866 |
#elif defined(LZO_UNALIGNED_OK_2) && (LZO_BYTE_ORDER == LZO_LITTLE_ENDIAN) |
|
1867 |
m_pos -= (* (const lzo_ushortp) ip) >> 2; |
|
1868 |
#else |
|
1869 |
m_pos -= (ip[0] >> 2) + (ip[1] << 6); |
|
1870 |
#endif |
|
1871 |
ip += 2; |
|
1872 |
if (m_pos == op) |
|
1873 |
goto eof_found; |
|
1874 |
m_pos -= 0x4000; |
|
1875 |
#if defined(LZO1Z) |
|
1876 |
last_m_off = op - m_pos; |
|
1877 |
#endif |
|
1878 |
} |
|
1879 |
else |
|
1880 |
{ |
|
1881 |
#if defined(LZO1Z) |
|
1882 |
t = 1 + (t << 6) + (*ip++ >> 2); |
|
1883 |
m_pos = op - t; |
|
1884 |
last_m_off = t; |
|
1885 |
#else |
|
1886 |
m_pos = op - 1; |
|
1887 |
m_pos -= t >> 2; |
|
1888 |
m_pos -= *ip++ << 2; |
|
1889 |
#endif |
|
1890 |
TEST_LOOKBEHIND(m_pos,out); NEED_OP(2); |
|
1891 |
*op++ = *m_pos++; *op++ = *m_pos; |
|
1892 |
goto match_done; |
|
1893 |
} |
|
1894 |
||
1895 |
TEST_LOOKBEHIND(m_pos,out); assert(t > 0); NEED_OP(t+3-1); |
|
1896 |
#if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) |
|
1897 |
#if !defined(LZO_UNALIGNED_OK_4) |
|
1898 |
if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos)) |
|
1899 |
{ |
|
1900 |
assert((op - m_pos) >= 4); |
|
1901 |
#else |
|
1902 |
if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4) |
|
1903 |
{ |
|
1904 |
#endif |
|
1905 |
COPY4(op,m_pos); |
|
1906 |
op += 4; m_pos += 4; t -= 4 - (3 - 1); |
|
1907 |
do { |
|
1908 |
COPY4(op,m_pos); |
|
1909 |
op += 4; m_pos += 4; t -= 4; |
|
1910 |
} while (t >= 4); |
|
1911 |
if (t > 0) do *op++ = *m_pos++; while (--t > 0); |
|
1912 |
} |
|
1913 |
else |
|
1914 |
#endif |
|
1915 |
{ |
|
1916 |
copy_match: |
|
1917 |
*op++ = *m_pos++; *op++ = *m_pos++; |
|
1918 |
do *op++ = *m_pos++; while (--t > 0); |
|
1919 |
} |
|
1920 |
||
1921 |
||
1922 |
match_done: |
|
1923 |
#if defined(LZO1Z) |
|
1924 |
t = ip[-1] & 3; |
|
1925 |
#else |
|
1926 |
t = ip[-2] & 3; |
|
1927 |
#endif |
|
1928 |
if (t == 0) |
|
1929 |
break; |
|
1930 |
||
1931 |
match_next: |
|
1932 |
assert(t > 0); NEED_OP(t); NEED_IP(t+1); |
|
1933 |
do *op++ = *ip++; while (--t > 0); |
|
1934 |
t = *ip++; |
|
1935 |
} |
|
1936 |
} |
|
1937 |
||
1938 |
#if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP) |
|
1939 |
*out_len = op - out; |
|
1940 |
return LZO_E_EOF_NOT_FOUND; |
|
1941 |
#endif |
|
1942 |
||
1943 |
eof_found: |
|
1944 |
assert(t == 1); |
|
1945 |
*out_len = op - out; |
|
1946 |
return (ip == ip_end ? LZO_E_OK : |
|
1947 |
(ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN)); |
|
1948 |
||
1949 |
#if defined(HAVE_NEED_IP) |
|
1950 |
input_overrun: |
|
1951 |
*out_len = op - out; |
|
1952 |
return LZO_E_INPUT_OVERRUN; |
|
1953 |
#endif |
|
1954 |
||
1955 |
#if defined(HAVE_NEED_OP) |
|
1956 |
output_overrun: |
|
1957 |
*out_len = op - out; |
|
1958 |
return LZO_E_OUTPUT_OVERRUN; |
|
1959 |
#endif |
|
1960 |
||
1961 |
#if defined(LZO_TEST_DECOMPRESS_OVERRUN_LOOKBEHIND) |
|
1962 |
lookbehind_overrun: |
|
1963 |
*out_len = op - out; |
|
1964 |
return LZO_E_LOOKBEHIND_OVERRUN; |
|
1965 |
#endif |
|
1966 |
} |
|
1967 |
||
1968 |
#endif |
|
1969 |
||
1970 |
/***** End of minilzo.c *****/ |