Updates to Tomato RAF including NGINX && PHP
[tomato.git] / release / src / router / lzo / minilzo / minilzo.c
blob34ce0f090bdfc6ae460e2ebecbd7f5299cc585cd
1 /* minilzo.c -- mini subset of the LZO real-time data compression library
3 This file is part of the LZO real-time data compression library.
5 Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer
6 Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer
7 Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer
8 Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
9 Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
10 Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
11 Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
12 Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer
13 Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
14 Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
15 Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
16 Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
17 Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
18 Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
19 Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
20 Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
21 All Rights Reserved.
23 The LZO library is free software; you can redistribute it and/or
24 modify it under the terms of the GNU General Public License as
25 published by the Free Software Foundation; either version 2 of
26 the License, or (at your option) any later version.
28 The LZO library is distributed in the hope that it will be useful,
29 but WITHOUT ANY WARRANTY; without even the implied warranty of
30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 GNU General Public License for more details.
33 You should have received a copy of the GNU General Public License
34 along with the LZO library; see the file COPYING.
35 If not, write to the Free Software Foundation, Inc.,
36 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
38 Markus F.X.J. Oberhumer
39 <markus@oberhumer.com>
40 http://www.oberhumer.com/opensource/lzo/
44 * NOTE:
45 * the full LZO package can be found at
46 * http://www.oberhumer.com/opensource/lzo/
49 #define __LZO_IN_MINILZO 1
51 #if defined(LZO_CFG_FREESTANDING)
52 # undef MINILZO_HAVE_CONFIG_H
53 # define LZO_LIBC_FREESTANDING 1
54 # define LZO_OS_FREESTANDING 1
55 #endif
57 #ifdef MINILZO_HAVE_CONFIG_H
58 # include <config.h>
59 #endif
60 #include <limits.h>
61 #include <stddef.h>
62 #if defined(MINILZO_CFG_USE_INTERNAL_LZODEFS)
64 #ifndef __LZODEFS_H_INCLUDED
65 #define __LZODEFS_H_INCLUDED 1
67 #if defined(__CYGWIN32__) && !defined(__CYGWIN__)
68 # define __CYGWIN__ __CYGWIN32__
69 #endif
70 #if defined(__IBMCPP__) && !defined(__IBMC__)
71 # define __IBMC__ __IBMCPP__
72 #endif
73 #if defined(__ICL) && defined(_WIN32) && !defined(__INTEL_COMPILER)
74 # define __INTEL_COMPILER __ICL
75 #endif
76 #if 1 && defined(__INTERIX) && defined(__GNUC__) && !defined(_ALL_SOURCE)
77 # define _ALL_SOURCE 1
78 #endif
79 #if defined(__mips__) && defined(__R5900__)
80 # if !defined(__LONG_MAX__)
81 # define __LONG_MAX__ 9223372036854775807L
82 # endif
83 #endif
84 #if defined(__INTEL_COMPILER) && defined(__linux__)
85 # pragma warning(disable: 193)
86 #endif
87 #if defined(__KEIL__) && defined(__C166__)
88 # pragma warning disable = 322
89 #elif 0 && defined(__C251__)
90 # pragma warning disable = 322
91 #endif
92 #if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__)
93 # if (_MSC_VER >= 1300)
94 # pragma warning(disable: 4668)
95 # endif
96 #endif
97 #if 0 && defined(__WATCOMC__)
98 # if (__WATCOMC__ >= 1050) && (__WATCOMC__ < 1060)
99 # pragma warning 203 9
100 # endif
101 #endif
102 #if defined(__BORLANDC__) && defined(__MSDOS__) && !defined(__FLAT__)
103 # pragma option -h
104 #endif
105 #if 0
106 #define LZO_0xffffL 0xfffful
107 #define LZO_0xffffffffL 0xfffffffful
108 #else
109 #define LZO_0xffffL 65535ul
110 #define LZO_0xffffffffL 4294967295ul
111 #endif
112 #if (LZO_0xffffL == LZO_0xffffffffL)
113 # error "your preprocessor is broken 1"
114 #endif
115 #if (16ul * 16384ul != 262144ul)
116 # error "your preprocessor is broken 2"
117 #endif
118 #if 0
119 #if (32767 >= 4294967295ul)
120 # error "your preprocessor is broken 3"
121 #endif
122 #if (65535u >= 4294967295ul)
123 # error "your preprocessor is broken 4"
124 #endif
125 #endif
126 #if (UINT_MAX == LZO_0xffffL)
127 #if defined(__ZTC__) && defined(__I86__) && !defined(__OS2__)
128 # if !defined(MSDOS)
129 # define MSDOS 1
130 # endif
131 # if !defined(_MSDOS)
132 # define _MSDOS 1
133 # endif
134 #elif 0 && defined(__VERSION) && defined(MB_LEN_MAX)
135 # if (__VERSION == 520) && (MB_LEN_MAX == 1)
136 # if !defined(__AZTEC_C__)
137 # define __AZTEC_C__ __VERSION
138 # endif
139 # if !defined(__DOS__)
140 # define __DOS__ 1
141 # endif
142 # endif
143 #endif
144 #endif
145 #if defined(_MSC_VER) && defined(M_I86HM) && (UINT_MAX == LZO_0xffffL)
146 # define ptrdiff_t long
147 # define _PTRDIFF_T_DEFINED 1
148 #endif
149 #if (UINT_MAX == LZO_0xffffL)
150 # undef __LZO_RENAME_A
151 # undef __LZO_RENAME_B
152 # if defined(__AZTEC_C__) && defined(__DOS__)
153 # define __LZO_RENAME_A 1
154 # elif defined(_MSC_VER) && defined(MSDOS)
155 # if (_MSC_VER < 600)
156 # define __LZO_RENAME_A 1
157 # elif (_MSC_VER < 700)
158 # define __LZO_RENAME_B 1
159 # endif
160 # elif defined(__TSC__) && defined(__OS2__)
161 # define __LZO_RENAME_A 1
162 # elif defined(__MSDOS__) && defined(__TURBOC__) && (__TURBOC__ < 0x0410)
163 # define __LZO_RENAME_A 1
164 # elif defined(__PACIFIC__) && defined(DOS)
165 # if !defined(__far)
166 # define __far far
167 # endif
168 # if !defined(__near)
169 # define __near near
170 # endif
171 # endif
172 # if defined(__LZO_RENAME_A)
173 # if !defined(__cdecl)
174 # define __cdecl cdecl
175 # endif
176 # if !defined(__far)
177 # define __far far
178 # endif
179 # if !defined(__huge)
180 # define __huge huge
181 # endif
182 # if !defined(__near)
183 # define __near near
184 # endif
185 # if !defined(__pascal)
186 # define __pascal pascal
187 # endif
188 # if !defined(__huge)
189 # define __huge huge
190 # endif
191 # elif defined(__LZO_RENAME_B)
192 # if !defined(__cdecl)
193 # define __cdecl _cdecl
194 # endif
195 # if !defined(__far)
196 # define __far _far
197 # endif
198 # if !defined(__huge)
199 # define __huge _huge
200 # endif
201 # if !defined(__near)
202 # define __near _near
203 # endif
204 # if !defined(__pascal)
205 # define __pascal _pascal
206 # endif
207 # elif (defined(__PUREC__) || defined(__TURBOC__)) && defined(__TOS__)
208 # if !defined(__cdecl)
209 # define __cdecl cdecl
210 # endif
211 # if !defined(__pascal)
212 # define __pascal pascal
213 # endif
214 # endif
215 # undef __LZO_RENAME_A
216 # undef __LZO_RENAME_B
217 #endif
218 #if (UINT_MAX == LZO_0xffffL)
219 #if defined(__AZTEC_C__) && defined(__DOS__)
220 # define LZO_BROKEN_CDECL_ALT_SYNTAX 1
221 #elif defined(_MSC_VER) && defined(MSDOS)
222 # if (_MSC_VER < 600)
223 # define LZO_BROKEN_INTEGRAL_CONSTANTS 1
224 # endif
225 # if (_MSC_VER < 700)
226 # define LZO_BROKEN_INTEGRAL_PROMOTION 1
227 # define LZO_BROKEN_SIZEOF 1
228 # endif
229 #elif defined(__PACIFIC__) && defined(DOS)
230 # define LZO_BROKEN_INTEGRAL_CONSTANTS 1
231 #elif defined(__TURBOC__) && defined(__MSDOS__)
232 # if (__TURBOC__ < 0x0150)
233 # define LZO_BROKEN_CDECL_ALT_SYNTAX 1
234 # define LZO_BROKEN_INTEGRAL_CONSTANTS 1
235 # define LZO_BROKEN_INTEGRAL_PROMOTION 1
236 # endif
237 # if (__TURBOC__ < 0x0200)
238 # define LZO_BROKEN_SIZEOF 1
239 # endif
240 # if (__TURBOC__ < 0x0400) && defined(__cplusplus)
241 # define LZO_BROKEN_CDECL_ALT_SYNTAX 1
242 # endif
243 #elif (defined(__PUREC__) || defined(__TURBOC__)) && defined(__TOS__)
244 # define LZO_BROKEN_CDECL_ALT_SYNTAX 1
245 # define LZO_BROKEN_SIZEOF 1
246 #endif
247 #endif
248 #if defined(__WATCOMC__) && (__WATCOMC__ < 900)
249 # define LZO_BROKEN_INTEGRAL_CONSTANTS 1
250 #endif
251 #if defined(_CRAY) && defined(_CRAY1)
252 # define LZO_BROKEN_SIGNED_RIGHT_SHIFT 1
253 #endif
254 #define LZO_PP_STRINGIZE(x) #x
255 #define LZO_PP_MACRO_EXPAND(x) LZO_PP_STRINGIZE(x)
256 #define LZO_PP_CONCAT2(a,b) a ## b
257 #define LZO_PP_CONCAT3(a,b,c) a ## b ## c
258 #define LZO_PP_CONCAT4(a,b,c,d) a ## b ## c ## d
259 #define LZO_PP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e
260 #define LZO_PP_ECONCAT2(a,b) LZO_PP_CONCAT2(a,b)
261 #define LZO_PP_ECONCAT3(a,b,c) LZO_PP_CONCAT3(a,b,c)
262 #define LZO_PP_ECONCAT4(a,b,c,d) LZO_PP_CONCAT4(a,b,c,d)
263 #define LZO_PP_ECONCAT5(a,b,c,d,e) LZO_PP_CONCAT5(a,b,c,d,e)
264 #if 1
265 #define LZO_CPP_STRINGIZE(x) #x
266 #define LZO_CPP_MACRO_EXPAND(x) LZO_CPP_STRINGIZE(x)
267 #define LZO_CPP_CONCAT2(a,b) a ## b
268 #define LZO_CPP_CONCAT3(a,b,c) a ## b ## c
269 #define LZO_CPP_CONCAT4(a,b,c,d) a ## b ## c ## d
270 #define LZO_CPP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e
271 #define LZO_CPP_ECONCAT2(a,b) LZO_CPP_CONCAT2(a,b)
272 #define LZO_CPP_ECONCAT3(a,b,c) LZO_CPP_CONCAT3(a,b,c)
273 #define LZO_CPP_ECONCAT4(a,b,c,d) LZO_CPP_CONCAT4(a,b,c,d)
274 #define LZO_CPP_ECONCAT5(a,b,c,d,e) LZO_CPP_CONCAT5(a,b,c,d,e)
275 #endif
276 #define __LZO_MASK_GEN(o,b) (((((o) << ((b)-1)) - (o)) << 1) + (o))
277 #if 1 && defined(__cplusplus)
278 # if !defined(__STDC_CONSTANT_MACROS)
279 # define __STDC_CONSTANT_MACROS 1
280 # endif
281 # if !defined(__STDC_LIMIT_MACROS)
282 # define __STDC_LIMIT_MACROS 1
283 # endif
284 #endif
285 #if defined(__cplusplus)
286 # define LZO_EXTERN_C extern "C"
287 #else
288 # define LZO_EXTERN_C extern
289 #endif
290 #if !defined(__LZO_OS_OVERRIDE)
291 #if (LZO_OS_FREESTANDING)
292 # define LZO_INFO_OS "freestanding"
293 #elif (LZO_OS_EMBEDDED)
294 # define LZO_INFO_OS "embedded"
295 #elif 1 && defined(__IAR_SYSTEMS_ICC__)
296 # define LZO_OS_EMBEDDED 1
297 # define LZO_INFO_OS "embedded"
298 #elif defined(__CYGWIN__) && defined(__GNUC__)
299 # define LZO_OS_CYGWIN 1
300 # define LZO_INFO_OS "cygwin"
301 #elif defined(__EMX__) && defined(__GNUC__)
302 # define LZO_OS_EMX 1
303 # define LZO_INFO_OS "emx"
304 #elif defined(__BEOS__)
305 # define LZO_OS_BEOS 1
306 # define LZO_INFO_OS "beos"
307 #elif defined(__Lynx__)
308 # define LZO_OS_LYNXOS 1
309 # define LZO_INFO_OS "lynxos"
310 #elif defined(__OS400__)
311 # define LZO_OS_OS400 1
312 # define LZO_INFO_OS "os400"
313 #elif defined(__QNX__)
314 # define LZO_OS_QNX 1
315 # define LZO_INFO_OS "qnx"
316 #elif defined(__BORLANDC__) && defined(__DPMI32__) && (__BORLANDC__ >= 0x0460)
317 # define LZO_OS_DOS32 1
318 # define LZO_INFO_OS "dos32"
319 #elif defined(__BORLANDC__) && defined(__DPMI16__)
320 # define LZO_OS_DOS16 1
321 # define LZO_INFO_OS "dos16"
322 #elif defined(__ZTC__) && defined(DOS386)
323 # define LZO_OS_DOS32 1
324 # define LZO_INFO_OS "dos32"
325 #elif defined(__OS2__) || defined(__OS2V2__)
326 # if (UINT_MAX == LZO_0xffffL)
327 # define LZO_OS_OS216 1
328 # define LZO_INFO_OS "os216"
329 # elif (UINT_MAX == LZO_0xffffffffL)
330 # define LZO_OS_OS2 1
331 # define LZO_INFO_OS "os2"
332 # else
333 # error "check your limits.h header"
334 # endif
335 #elif defined(__WIN64__) || defined(_WIN64) || defined(WIN64)
336 # define LZO_OS_WIN64 1
337 # define LZO_INFO_OS "win64"
338 #elif defined(__WIN32__) || defined(_WIN32) || defined(WIN32) || defined(__WINDOWS_386__)
339 # define LZO_OS_WIN32 1
340 # define LZO_INFO_OS "win32"
341 #elif defined(__MWERKS__) && defined(__INTEL__)
342 # define LZO_OS_WIN32 1
343 # define LZO_INFO_OS "win32"
344 #elif defined(__WINDOWS__) || defined(_WINDOWS) || defined(_Windows)
345 # if (UINT_MAX == LZO_0xffffL)
346 # define LZO_OS_WIN16 1
347 # define LZO_INFO_OS "win16"
348 # elif (UINT_MAX == LZO_0xffffffffL)
349 # define LZO_OS_WIN32 1
350 # define LZO_INFO_OS "win32"
351 # else
352 # error "check your limits.h header"
353 # endif
354 #elif defined(__DOS__) || defined(__MSDOS__) || defined(_MSDOS) || defined(MSDOS) || (defined(__PACIFIC__) && defined(DOS))
355 # if (UINT_MAX == LZO_0xffffL)
356 # define LZO_OS_DOS16 1
357 # define LZO_INFO_OS "dos16"
358 # elif (UINT_MAX == LZO_0xffffffffL)
359 # define LZO_OS_DOS32 1
360 # define LZO_INFO_OS "dos32"
361 # else
362 # error "check your limits.h header"
363 # endif
364 #elif defined(__WATCOMC__)
365 # if defined(__NT__) && (UINT_MAX == LZO_0xffffL)
366 # define LZO_OS_DOS16 1
367 # define LZO_INFO_OS "dos16"
368 # elif defined(__NT__) && (__WATCOMC__ < 1100)
369 # define LZO_OS_WIN32 1
370 # define LZO_INFO_OS "win32"
371 # elif defined(__linux__) || defined(__LINUX__)
372 # define LZO_OS_POSIX 1
373 # define LZO_INFO_OS "posix"
374 # else
375 # error "please specify a target using the -bt compiler option"
376 # endif
377 #elif defined(__palmos__)
378 # define LZO_OS_PALMOS 1
379 # define LZO_INFO_OS "palmos"
380 #elif defined(__TOS__) || defined(__atarist__)
381 # define LZO_OS_TOS 1
382 # define LZO_INFO_OS "tos"
383 #elif defined(macintosh) && !defined(__ppc__)
384 # define LZO_OS_MACCLASSIC 1
385 # define LZO_INFO_OS "macclassic"
386 #elif defined(__VMS)
387 # define LZO_OS_VMS 1
388 # define LZO_INFO_OS "vms"
389 #elif ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__))
390 # define LZO_OS_CONSOLE 1
391 # define LZO_OS_CONSOLE_PS2 1
392 # define LZO_INFO_OS "console"
393 # define LZO_INFO_OS_CONSOLE "ps2"
394 #elif (defined(__mips__) && defined(__psp__))
395 # define LZO_OS_CONSOLE 1
396 # define LZO_OS_CONSOLE_PSP 1
397 # define LZO_INFO_OS "console"
398 # define LZO_INFO_OS_CONSOLE "psp"
399 #else
400 # define LZO_OS_POSIX 1
401 # define LZO_INFO_OS "posix"
402 #endif
403 #if (LZO_OS_POSIX)
404 # if defined(_AIX) || defined(__AIX__) || defined(__aix__)
405 # define LZO_OS_POSIX_AIX 1
406 # define LZO_INFO_OS_POSIX "aix"
407 # elif defined(__FreeBSD__)
408 # define LZO_OS_POSIX_FREEBSD 1
409 # define LZO_INFO_OS_POSIX "freebsd"
410 # elif defined(__hpux__) || defined(__hpux)
411 # define LZO_OS_POSIX_HPUX 1
412 # define LZO_INFO_OS_POSIX "hpux"
413 # elif defined(__INTERIX)
414 # define LZO_OS_POSIX_INTERIX 1
415 # define LZO_INFO_OS_POSIX "interix"
416 # elif defined(__IRIX__) || defined(__irix__)
417 # define LZO_OS_POSIX_IRIX 1
418 # define LZO_INFO_OS_POSIX "irix"
419 # elif defined(__linux__) || defined(__linux) || defined(__LINUX__)
420 # define LZO_OS_POSIX_LINUX 1
421 # define LZO_INFO_OS_POSIX "linux"
422 # elif defined(__APPLE__) || defined(__MACOS__)
423 # define LZO_OS_POSIX_MACOSX 1
424 # define LZO_INFO_OS_POSIX "macosx"
425 # elif defined(__minix__) || defined(__minix)
426 # define LZO_OS_POSIX_MINIX 1
427 # define LZO_INFO_OS_POSIX "minix"
428 # elif defined(__NetBSD__)
429 # define LZO_OS_POSIX_NETBSD 1
430 # define LZO_INFO_OS_POSIX "netbsd"
431 # elif defined(__OpenBSD__)
432 # define LZO_OS_POSIX_OPENBSD 1
433 # define LZO_INFO_OS_POSIX "openbsd"
434 # elif defined(__osf__)
435 # define LZO_OS_POSIX_OSF 1
436 # define LZO_INFO_OS_POSIX "osf"
437 # elif defined(__solaris__) || defined(__sun)
438 # if defined(__SVR4) || defined(__svr4__)
439 # define LZO_OS_POSIX_SOLARIS 1
440 # define LZO_INFO_OS_POSIX "solaris"
441 # else
442 # define LZO_OS_POSIX_SUNOS 1
443 # define LZO_INFO_OS_POSIX "sunos"
444 # endif
445 # elif defined(__ultrix__) || defined(__ultrix)
446 # define LZO_OS_POSIX_ULTRIX 1
447 # define LZO_INFO_OS_POSIX "ultrix"
448 # elif defined(_UNICOS)
449 # define LZO_OS_POSIX_UNICOS 1
450 # define LZO_INFO_OS_POSIX "unicos"
451 # else
452 # define LZO_OS_POSIX_UNKNOWN 1
453 # define LZO_INFO_OS_POSIX "unknown"
454 # endif
455 #endif
456 #endif
457 #if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16)
458 # if (UINT_MAX != LZO_0xffffL)
459 # error "this should not happen"
460 # endif
461 # if (ULONG_MAX != LZO_0xffffffffL)
462 # error "this should not happen"
463 # endif
464 #endif
465 #if (LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_WIN32 || LZO_OS_WIN64)
466 # if (UINT_MAX != LZO_0xffffffffL)
467 # error "this should not happen"
468 # endif
469 # if (ULONG_MAX != LZO_0xffffffffL)
470 # error "this should not happen"
471 # endif
472 #endif
473 #if defined(CIL) && defined(_GNUCC) && defined(__GNUC__)
474 # define LZO_CC_CILLY 1
475 # define LZO_INFO_CC "Cilly"
476 # if defined(__CILLY__)
477 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__CILLY__)
478 # else
479 # define LZO_INFO_CCVER "unknown"
480 # endif
481 #elif 0 && defined(SDCC) && defined(__VERSION__) && !defined(__GNUC__)
482 # define LZO_CC_SDCC 1
483 # define LZO_INFO_CC "sdcc"
484 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(SDCC)
485 #elif defined(__PATHSCALE__) && defined(__PATHCC_PATCHLEVEL__)
486 # define LZO_CC_PATHSCALE (__PATHCC__ * 0x10000L + __PATHCC_MINOR__ * 0x100 + __PATHCC_PATCHLEVEL__)
487 # define LZO_INFO_CC "Pathscale C"
488 # define LZO_INFO_CCVER __PATHSCALE__
489 #elif defined(__INTEL_COMPILER)
490 # define LZO_CC_INTELC 1
491 # define LZO_INFO_CC "Intel C"
492 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__INTEL_COMPILER)
493 # if defined(_WIN32) || defined(_WIN64)
494 # define LZO_CC_SYNTAX_MSC 1
495 # else
496 # define LZO_CC_SYNTAX_GNUC 1
497 # endif
498 #elif defined(__POCC__) && defined(_WIN32)
499 # define LZO_CC_PELLESC 1
500 # define LZO_INFO_CC "Pelles C"
501 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__POCC__)
502 #elif defined(__clang__) && defined(__llvm__) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__)
503 # if defined(__GNUC_PATCHLEVEL__)
504 # define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__)
505 # else
506 # define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100)
507 # endif
508 # if defined(__clang_major__) && defined(__clang_minor__) && defined(__clang_patchlevel__)
509 # define LZO_CC_CLANG_CLANG (__clang_major__ * 0x10000L + __clang_minor__ * 0x100 + __clang_patchlevel__)
510 # else
511 # define LZO_CC_CLANG_CLANG 0x010000L
512 # endif
513 # define LZO_CC_CLANG LZO_CC_CLANG_GNUC
514 # define LZO_INFO_CC "clang"
515 # define LZO_INFO_CCVER __VERSION__
516 #elif defined(__llvm__) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__)
517 # if defined(__GNUC_PATCHLEVEL__)
518 # define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__)
519 # else
520 # define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100)
521 # endif
522 # define LZO_CC_LLVM LZO_CC_LLVM_GNUC
523 # define LZO_INFO_CC "llvm-gcc"
524 # define LZO_INFO_CCVER __VERSION__
525 #elif defined(__GNUC__) && defined(__VERSION__)
526 # if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
527 # define LZO_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__)
528 # elif defined(__GNUC_MINOR__)
529 # define LZO_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100)
530 # else
531 # define LZO_CC_GNUC (__GNUC__ * 0x10000L)
532 # endif
533 # define LZO_INFO_CC "gcc"
534 # define LZO_INFO_CCVER __VERSION__
535 #elif defined(__ACK__) && defined(_ACK)
536 # define LZO_CC_ACK 1
537 # define LZO_INFO_CC "Amsterdam Compiler Kit C"
538 # define LZO_INFO_CCVER "unknown"
539 #elif defined(__AZTEC_C__)
540 # define LZO_CC_AZTECC 1
541 # define LZO_INFO_CC "Aztec C"
542 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__AZTEC_C__)
543 #elif defined(__CODEGEARC__)
544 # define LZO_CC_CODEGEARC 1
545 # define LZO_INFO_CC "CodeGear C"
546 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__CODEGEARC__)
547 #elif defined(__BORLANDC__)
548 # define LZO_CC_BORLANDC 1
549 # define LZO_INFO_CC "Borland C"
550 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__BORLANDC__)
551 #elif defined(_CRAYC) && defined(_RELEASE)
552 # define LZO_CC_CRAYC 1
553 # define LZO_INFO_CC "Cray C"
554 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_RELEASE)
555 #elif defined(__DMC__) && defined(__SC__)
556 # define LZO_CC_DMC 1
557 # define LZO_INFO_CC "Digital Mars C"
558 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__DMC__)
559 #elif defined(__DECC)
560 # define LZO_CC_DECC 1
561 # define LZO_INFO_CC "DEC C"
562 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__DECC)
563 #elif defined(__HIGHC__)
564 # define LZO_CC_HIGHC 1
565 # define LZO_INFO_CC "MetaWare High C"
566 # define LZO_INFO_CCVER "unknown"
567 #elif defined(__IAR_SYSTEMS_ICC__)
568 # define LZO_CC_IARC 1
569 # define LZO_INFO_CC "IAR C"
570 # if defined(__VER__)
571 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__VER__)
572 # else
573 # define LZO_INFO_CCVER "unknown"
574 # endif
575 #elif defined(__IBMC__)
576 # define LZO_CC_IBMC 1
577 # define LZO_INFO_CC "IBM C"
578 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__IBMC__)
579 #elif defined(__KEIL__) && defined(__C166__)
580 # define LZO_CC_KEILC 1
581 # define LZO_INFO_CC "Keil C"
582 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__C166__)
583 #elif defined(__LCC__) && defined(_WIN32) && defined(__LCCOPTIMLEVEL)
584 # define LZO_CC_LCCWIN32 1
585 # define LZO_INFO_CC "lcc-win32"
586 # define LZO_INFO_CCVER "unknown"
587 #elif defined(__LCC__)
588 # define LZO_CC_LCC 1
589 # define LZO_INFO_CC "lcc"
590 # if defined(__LCC_VERSION__)
591 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__LCC_VERSION__)
592 # else
593 # define LZO_INFO_CCVER "unknown"
594 # endif
595 #elif defined(_MSC_VER)
596 # define LZO_CC_MSC 1
597 # define LZO_INFO_CC "Microsoft C"
598 # if defined(_MSC_FULL_VER)
599 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) "." LZO_PP_MACRO_EXPAND(_MSC_FULL_VER)
600 # else
601 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER)
602 # endif
603 #elif defined(__MWERKS__)
604 # define LZO_CC_MWERKS 1
605 # define LZO_INFO_CC "Metrowerks C"
606 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__MWERKS__)
607 #elif (defined(__NDPC__) || defined(__NDPX__)) && defined(__i386)
608 # define LZO_CC_NDPC 1
609 # define LZO_INFO_CC "Microway NDP C"
610 # define LZO_INFO_CCVER "unknown"
611 #elif defined(__PACIFIC__)
612 # define LZO_CC_PACIFICC 1
613 # define LZO_INFO_CC "Pacific C"
614 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PACIFIC__)
615 #elif defined(__PGI) && (defined(__linux__) || defined(__WIN32__))
616 # define LZO_CC_PGI 1
617 # define LZO_INFO_CC "Portland Group PGI C"
618 # define LZO_INFO_CCVER "unknown"
619 #elif defined(__PUREC__) && defined(__TOS__)
620 # define LZO_CC_PUREC 1
621 # define LZO_INFO_CC "Pure C"
622 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PUREC__)
623 #elif defined(__SC__) && defined(__ZTC__)
624 # define LZO_CC_SYMANTECC 1
625 # define LZO_INFO_CC "Symantec C"
626 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SC__)
627 #elif defined(__SUNPRO_C)
628 # define LZO_INFO_CC "SunPro C"
629 # if ((__SUNPRO_C)+0 > 0)
630 # define LZO_CC_SUNPROC __SUNPRO_C
631 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SUNPRO_C)
632 # else
633 # define LZO_CC_SUNPROC 1
634 # define LZO_INFO_CCVER "unknown"
635 # endif
636 #elif defined(__SUNPRO_CC)
637 # define LZO_INFO_CC "SunPro C"
638 # if ((__SUNPRO_CC)+0 > 0)
639 # define LZO_CC_SUNPROC __SUNPRO_CC
640 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SUNPRO_CC)
641 # else
642 # define LZO_CC_SUNPROC 1
643 # define LZO_INFO_CCVER "unknown"
644 # endif
645 #elif defined(__TINYC__)
646 # define LZO_CC_TINYC 1
647 # define LZO_INFO_CC "Tiny C"
648 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__TINYC__)
649 #elif defined(__TSC__)
650 # define LZO_CC_TOPSPEEDC 1
651 # define LZO_INFO_CC "TopSpeed C"
652 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__TSC__)
653 #elif defined(__WATCOMC__)
654 # define LZO_CC_WATCOMC 1
655 # define LZO_INFO_CC "Watcom C"
656 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__WATCOMC__)
657 #elif defined(__TURBOC__)
658 # define LZO_CC_TURBOC 1
659 # define LZO_INFO_CC "Turbo C"
660 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__TURBOC__)
661 #elif defined(__ZTC__)
662 # define LZO_CC_ZORTECHC 1
663 # define LZO_INFO_CC "Zortech C"
664 # if (__ZTC__ == 0x310)
665 # define LZO_INFO_CCVER "0x310"
666 # else
667 # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__ZTC__)
668 # endif
669 #else
670 # define LZO_CC_UNKNOWN 1
671 # define LZO_INFO_CC "unknown"
672 # define LZO_INFO_CCVER "unknown"
673 #endif
674 #if 0 && (LZO_CC_MSC && (_MSC_VER >= 1200)) && !defined(_MSC_FULL_VER)
675 # error "LZO_CC_MSC: _MSC_FULL_VER is not defined"
676 #endif
677 #if !defined(__LZO_ARCH_OVERRIDE) && !(LZO_ARCH_GENERIC) && defined(_CRAY)
678 # if (UINT_MAX > LZO_0xffffffffL) && defined(_CRAY)
679 # if defined(_CRAYMPP) || defined(_CRAYT3D) || defined(_CRAYT3E)
680 # define LZO_ARCH_CRAY_MPP 1
681 # elif defined(_CRAY1)
682 # define LZO_ARCH_CRAY_PVP 1
683 # endif
684 # endif
685 #endif
686 #if !defined(__LZO_ARCH_OVERRIDE)
687 #if (LZO_ARCH_GENERIC)
688 # define LZO_INFO_ARCH "generic"
689 #elif (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16)
690 # define LZO_ARCH_I086 1
691 # define LZO_ARCH_IA16 1
692 # define LZO_INFO_ARCH "i086"
693 #elif defined(__alpha__) || defined(__alpha) || defined(_M_ALPHA)
694 # define LZO_ARCH_ALPHA 1
695 # define LZO_INFO_ARCH "alpha"
696 #elif (LZO_ARCH_CRAY_MPP) && (defined(_CRAYT3D) || defined(_CRAYT3E))
697 # define LZO_ARCH_ALPHA 1
698 # define LZO_INFO_ARCH "alpha"
699 #elif defined(__amd64__) || defined(__x86_64__) || defined(_M_AMD64)
700 # define LZO_ARCH_AMD64 1
701 # define LZO_INFO_ARCH "amd64"
702 #elif defined(__thumb__) || (defined(_M_ARM) && defined(_M_THUMB))
703 # define LZO_ARCH_ARM 1
704 # define LZO_ARCH_ARM_THUMB 1
705 # define LZO_INFO_ARCH "arm_thumb"
706 #elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCARM__)
707 # define LZO_ARCH_ARM 1
708 # if defined(__CPU_MODE__) && ((__CPU_MODE__)+0 == 1)
709 # define LZO_ARCH_ARM_THUMB 1
710 # define LZO_INFO_ARCH "arm_thumb"
711 # elif defined(__CPU_MODE__) && ((__CPU_MODE__)+0 == 2)
712 # define LZO_INFO_ARCH "arm"
713 # else
714 # define LZO_INFO_ARCH "arm"
715 # endif
716 #elif defined(__arm__) || defined(_M_ARM)
717 # define LZO_ARCH_ARM 1
718 # define LZO_INFO_ARCH "arm"
719 #elif (UINT_MAX <= LZO_0xffffL) && defined(__AVR__)
720 # define LZO_ARCH_AVR 1
721 # define LZO_INFO_ARCH "avr"
722 #elif defined(__avr32__) || defined(__AVR32__)
723 # define LZO_ARCH_AVR32 1
724 # define LZO_INFO_ARCH "avr32"
725 #elif defined(__bfin__)
726 # define LZO_ARCH_BLACKFIN 1
727 # define LZO_INFO_ARCH "blackfin"
728 #elif (UINT_MAX == LZO_0xffffL) && defined(__C166__)
729 # define LZO_ARCH_C166 1
730 # define LZO_INFO_ARCH "c166"
731 #elif defined(__cris__)
732 # define LZO_ARCH_CRIS 1
733 # define LZO_INFO_ARCH "cris"
734 #elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCEZ80__)
735 # define LZO_ARCH_EZ80 1
736 # define LZO_INFO_ARCH "ez80"
737 #elif defined(__H8300__) || defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__)
738 # define LZO_ARCH_H8300 1
739 # define LZO_INFO_ARCH "h8300"
740 #elif defined(__hppa__) || defined(__hppa)
741 # define LZO_ARCH_HPPA 1
742 # define LZO_INFO_ARCH "hppa"
743 #elif defined(__386__) || defined(__i386__) || defined(__i386) || defined(_M_IX86) || defined(_M_I386)
744 # define LZO_ARCH_I386 1
745 # define LZO_ARCH_IA32 1
746 # define LZO_INFO_ARCH "i386"
747 #elif (LZO_CC_ZORTECHC && defined(__I86__))
748 # define LZO_ARCH_I386 1
749 # define LZO_ARCH_IA32 1
750 # define LZO_INFO_ARCH "i386"
751 #elif (LZO_OS_DOS32 && LZO_CC_HIGHC) && defined(_I386)
752 # define LZO_ARCH_I386 1
753 # define LZO_ARCH_IA32 1
754 # define LZO_INFO_ARCH "i386"
755 #elif defined(__ia64__) || defined(__ia64) || defined(_M_IA64)
756 # define LZO_ARCH_IA64 1
757 # define LZO_INFO_ARCH "ia64"
758 #elif (UINT_MAX == LZO_0xffffL) && defined(__m32c__)
759 # define LZO_ARCH_M16C 1
760 # define LZO_INFO_ARCH "m16c"
761 #elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCM16C__)
762 # define LZO_ARCH_M16C 1
763 # define LZO_INFO_ARCH "m16c"
764 #elif defined(__m32r__)
765 # define LZO_ARCH_M32R 1
766 # define LZO_INFO_ARCH "m32r"
767 #elif (LZO_OS_TOS) || defined(__m68k__) || defined(__m68000__) || defined(__mc68000__) || defined(__mc68020__) || defined(_M_M68K)
768 # define LZO_ARCH_M68K 1
769 # define LZO_INFO_ARCH "m68k"
770 #elif (UINT_MAX == LZO_0xffffL) && defined(__C251__)
771 # define LZO_ARCH_MCS251 1
772 # define LZO_INFO_ARCH "mcs251"
773 #elif (UINT_MAX == LZO_0xffffL) && defined(__C51__)
774 # define LZO_ARCH_MCS51 1
775 # define LZO_INFO_ARCH "mcs51"
776 #elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICC8051__)
777 # define LZO_ARCH_MCS51 1
778 # define LZO_INFO_ARCH "mcs51"
779 #elif defined(__mips__) || defined(__mips) || defined(_MIPS_ARCH) || defined(_M_MRX000)
780 # define LZO_ARCH_MIPS 1
781 # define LZO_INFO_ARCH "mips"
782 #elif (UINT_MAX == LZO_0xffffL) && defined(__MSP430__)
783 # define LZO_ARCH_MSP430 1
784 # define LZO_INFO_ARCH "msp430"
785 #elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICC430__)
786 # define LZO_ARCH_MSP430 1
787 # define LZO_INFO_ARCH "msp430"
788 #elif defined(__powerpc__) || defined(__powerpc) || defined(__ppc__) || defined(__PPC__) || defined(_M_PPC) || defined(_ARCH_PPC) || defined(_ARCH_PWR)
789 # define LZO_ARCH_POWERPC 1
790 # define LZO_INFO_ARCH "powerpc"
791 #elif defined(__s390__) || defined(__s390) || defined(__s390x__) || defined(__s390x)
792 # define LZO_ARCH_S390 1
793 # define LZO_INFO_ARCH "s390"
794 #elif defined(__sh__) || defined(_M_SH)
795 # define LZO_ARCH_SH 1
796 # define LZO_INFO_ARCH "sh"
797 #elif defined(__sparc__) || defined(__sparc) || defined(__sparcv8)
798 # define LZO_ARCH_SPARC 1
799 # define LZO_INFO_ARCH "sparc"
800 #elif defined(__SPU__)
801 # define LZO_ARCH_SPU 1
802 # define LZO_INFO_ARCH "spu"
803 #elif (UINT_MAX == LZO_0xffffL) && defined(__z80)
804 # define LZO_ARCH_Z80 1
805 # define LZO_INFO_ARCH "z80"
806 #elif (LZO_ARCH_CRAY_PVP)
807 # if defined(_CRAYSV1)
808 # define LZO_ARCH_CRAY_SV1 1
809 # define LZO_INFO_ARCH "cray_sv1"
810 # elif (_ADDR64)
811 # define LZO_ARCH_CRAY_T90 1
812 # define LZO_INFO_ARCH "cray_t90"
813 # elif (_ADDR32)
814 # define LZO_ARCH_CRAY_YMP 1
815 # define LZO_INFO_ARCH "cray_ymp"
816 # else
817 # define LZO_ARCH_CRAY_XMP 1
818 # define LZO_INFO_ARCH "cray_xmp"
819 # endif
820 #else
821 # define LZO_ARCH_UNKNOWN 1
822 # define LZO_INFO_ARCH "unknown"
823 #endif
824 #endif
825 #if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_DOS32 || LZO_OS_OS2)
826 # error "FIXME - missing define for CPU architecture"
827 #endif
828 #if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN32)
829 # error "FIXME - missing WIN32 define for CPU architecture"
830 #endif
831 #if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN64)
832 # error "FIXME - missing WIN64 define for CPU architecture"
833 #endif
834 #if (LZO_OS_OS216 || LZO_OS_WIN16)
835 # define LZO_ARCH_I086PM 1
836 # define LZO_ARCH_IA16PM 1
837 #elif 1 && (LZO_OS_DOS16 && defined(BLX286))
838 # define LZO_ARCH_I086PM 1
839 # define LZO_ARCH_IA16PM 1
840 #elif 1 && (LZO_OS_DOS16 && defined(DOSX286))
841 # define LZO_ARCH_I086PM 1
842 # define LZO_ARCH_IA16PM 1
843 #elif 1 && (LZO_OS_DOS16 && LZO_CC_BORLANDC && defined(__DPMI16__))
844 # define LZO_ARCH_I086PM 1
845 # define LZO_ARCH_IA16PM 1
846 #endif
847 #if (LZO_ARCH_ARM_THUMB) && !(LZO_ARCH_ARM)
848 # error "this should not happen"
849 #endif
850 #if (LZO_ARCH_I086PM) && !(LZO_ARCH_I086)
851 # error "this should not happen"
852 #endif
853 #if (LZO_ARCH_I086)
854 # if (UINT_MAX != LZO_0xffffL)
855 # error "this should not happen"
856 # endif
857 # if (ULONG_MAX != LZO_0xffffffffL)
858 # error "this should not happen"
859 # endif
860 #endif
861 #if (LZO_ARCH_I386)
862 # if (UINT_MAX != LZO_0xffffL) && defined(__i386_int16__)
863 # error "this should not happen"
864 # endif
865 # if (UINT_MAX != LZO_0xffffffffL) && !defined(__i386_int16__)
866 # error "this should not happen"
867 # endif
868 # if (ULONG_MAX != LZO_0xffffffffL)
869 # error "this should not happen"
870 # endif
871 #endif
872 #if !defined(__LZO_MM_OVERRIDE)
873 #if (LZO_ARCH_I086)
874 #if (UINT_MAX != LZO_0xffffL)
875 # error "this should not happen"
876 #endif
877 #if defined(__TINY__) || defined(M_I86TM) || defined(_M_I86TM)
878 # define LZO_MM_TINY 1
879 #elif defined(__HUGE__) || defined(_HUGE_) || defined(M_I86HM) || defined(_M_I86HM)
880 # define LZO_MM_HUGE 1
881 #elif defined(__SMALL__) || defined(M_I86SM) || defined(_M_I86SM) || defined(SMALL_MODEL)
882 # define LZO_MM_SMALL 1
883 #elif defined(__MEDIUM__) || defined(M_I86MM) || defined(_M_I86MM)
884 # define LZO_MM_MEDIUM 1
885 #elif defined(__COMPACT__) || defined(M_I86CM) || defined(_M_I86CM)
886 # define LZO_MM_COMPACT 1
887 #elif defined(__LARGE__) || defined(M_I86LM) || defined(_M_I86LM) || defined(LARGE_MODEL)
888 # define LZO_MM_LARGE 1
889 #elif (LZO_CC_AZTECC)
890 # if defined(_LARGE_CODE) && defined(_LARGE_DATA)
891 # define LZO_MM_LARGE 1
892 # elif defined(_LARGE_CODE)
893 # define LZO_MM_MEDIUM 1
894 # elif defined(_LARGE_DATA)
895 # define LZO_MM_COMPACT 1
896 # else
897 # define LZO_MM_SMALL 1
898 # endif
899 #elif (LZO_CC_ZORTECHC && defined(__VCM__))
900 # define LZO_MM_LARGE 1
901 #else
902 # error "unknown memory model"
903 #endif
904 #if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16)
905 #define LZO_HAVE_MM_HUGE_PTR 1
906 #define LZO_HAVE_MM_HUGE_ARRAY 1
907 #if (LZO_MM_TINY)
908 # undef LZO_HAVE_MM_HUGE_ARRAY
909 #endif
910 #if (LZO_CC_AZTECC || LZO_CC_PACIFICC || LZO_CC_ZORTECHC)
911 # undef LZO_HAVE_MM_HUGE_PTR
912 # undef LZO_HAVE_MM_HUGE_ARRAY
913 #elif (LZO_CC_DMC || LZO_CC_SYMANTECC)
914 # undef LZO_HAVE_MM_HUGE_ARRAY
915 #elif (LZO_CC_MSC && defined(_QC))
916 # undef LZO_HAVE_MM_HUGE_ARRAY
917 # if (_MSC_VER < 600)
918 # undef LZO_HAVE_MM_HUGE_PTR
919 # endif
920 #elif (LZO_CC_TURBOC && (__TURBOC__ < 0x0295))
921 # undef LZO_HAVE_MM_HUGE_ARRAY
922 #endif
923 #if (LZO_ARCH_I086PM) && !(LZO_HAVE_MM_HUGE_PTR)
924 # if (LZO_OS_DOS16)
925 # error "this should not happen"
926 # elif (LZO_CC_ZORTECHC)
927 # else
928 # error "this should not happen"
929 # endif
930 #endif
931 #ifdef __cplusplus
932 extern "C" {
933 #endif
934 #if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0200))
935 extern void __near __cdecl _AHSHIFT(void);
936 # define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT)
937 #elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC)
938 extern void __near __cdecl _AHSHIFT(void);
939 # define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT)
940 #elif (LZO_CC_MSC || LZO_CC_TOPSPEEDC)
941 extern void __near __cdecl _AHSHIFT(void);
942 # define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT)
943 #elif (LZO_CC_TURBOC && (__TURBOC__ >= 0x0295))
944 extern void __near __cdecl _AHSHIFT(void);
945 # define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT)
946 #elif ((LZO_CC_AZTECC || LZO_CC_PACIFICC || LZO_CC_TURBOC) && LZO_OS_DOS16)
947 # define LZO_MM_AHSHIFT 12
948 #elif (LZO_CC_WATCOMC)
949 extern unsigned char _HShift;
950 # define LZO_MM_AHSHIFT ((unsigned) _HShift)
951 #else
952 # error "FIXME - implement LZO_MM_AHSHIFT"
953 #endif
954 #ifdef __cplusplus
956 #endif
957 #endif
958 #elif (LZO_ARCH_C166)
959 #if !defined(__MODEL__)
960 # error "FIXME - C166 __MODEL__"
961 #elif ((__MODEL__) == 0)
962 # define LZO_MM_SMALL 1
963 #elif ((__MODEL__) == 1)
964 # define LZO_MM_SMALL 1
965 #elif ((__MODEL__) == 2)
966 # define LZO_MM_LARGE 1
967 #elif ((__MODEL__) == 3)
968 # define LZO_MM_TINY 1
969 #elif ((__MODEL__) == 4)
970 # define LZO_MM_XTINY 1
971 #elif ((__MODEL__) == 5)
972 # define LZO_MM_XSMALL 1
973 #else
974 # error "FIXME - C166 __MODEL__"
975 #endif
976 #elif (LZO_ARCH_MCS251)
977 #if !defined(__MODEL__)
978 # error "FIXME - MCS251 __MODEL__"
979 #elif ((__MODEL__) == 0)
980 # define LZO_MM_SMALL 1
981 #elif ((__MODEL__) == 2)
982 # define LZO_MM_LARGE 1
983 #elif ((__MODEL__) == 3)
984 # define LZO_MM_TINY 1
985 #elif ((__MODEL__) == 4)
986 # define LZO_MM_XTINY 1
987 #elif ((__MODEL__) == 5)
988 # define LZO_MM_XSMALL 1
989 #else
990 # error "FIXME - MCS251 __MODEL__"
991 #endif
992 #elif (LZO_ARCH_MCS51)
993 #if !defined(__MODEL__)
994 # error "FIXME - MCS51 __MODEL__"
995 #elif ((__MODEL__) == 1)
996 # define LZO_MM_SMALL 1
997 #elif ((__MODEL__) == 2)
998 # define LZO_MM_LARGE 1
999 #elif ((__MODEL__) == 3)
1000 # define LZO_MM_TINY 1
1001 #elif ((__MODEL__) == 4)
1002 # define LZO_MM_XTINY 1
1003 #elif ((__MODEL__) == 5)
1004 # define LZO_MM_XSMALL 1
1005 #else
1006 # error "FIXME - MCS51 __MODEL__"
1007 #endif
1008 #elif (LZO_ARCH_CRAY_PVP)
1009 # define LZO_MM_PVP 1
1010 #else
1011 # define LZO_MM_FLAT 1
1012 #endif
1013 #if (LZO_MM_COMPACT)
1014 # define LZO_INFO_MM "compact"
1015 #elif (LZO_MM_FLAT)
1016 # define LZO_INFO_MM "flat"
1017 #elif (LZO_MM_HUGE)
1018 # define LZO_INFO_MM "huge"
1019 #elif (LZO_MM_LARGE)
1020 # define LZO_INFO_MM "large"
1021 #elif (LZO_MM_MEDIUM)
1022 # define LZO_INFO_MM "medium"
1023 #elif (LZO_MM_PVP)
1024 # define LZO_INFO_MM "pvp"
1025 #elif (LZO_MM_SMALL)
1026 # define LZO_INFO_MM "small"
1027 #elif (LZO_MM_TINY)
1028 # define LZO_INFO_MM "tiny"
1029 #else
1030 # error "unknown memory model"
1031 #endif
1032 #endif
1033 #if defined(SIZEOF_SHORT)
1034 # define LZO_SIZEOF_SHORT (SIZEOF_SHORT)
1035 #endif
1036 #if defined(SIZEOF_INT)
1037 # define LZO_SIZEOF_INT (SIZEOF_INT)
1038 #endif
1039 #if defined(SIZEOF_LONG)
1040 # define LZO_SIZEOF_LONG (SIZEOF_LONG)
1041 #endif
1042 #if defined(SIZEOF_LONG_LONG)
1043 # define LZO_SIZEOF_LONG_LONG (SIZEOF_LONG_LONG)
1044 #endif
1045 #if defined(SIZEOF___INT16)
1046 # define LZO_SIZEOF___INT16 (SIZEOF___INT16)
1047 #endif
1048 #if defined(SIZEOF___INT32)
1049 # define LZO_SIZEOF___INT32 (SIZEOF___INT32)
1050 #endif
1051 #if defined(SIZEOF___INT64)
1052 # define LZO_SIZEOF___INT64 (SIZEOF___INT64)
1053 #endif
1054 #if defined(SIZEOF_VOID_P)
1055 # define LZO_SIZEOF_VOID_P (SIZEOF_VOID_P)
1056 #endif
1057 #if defined(SIZEOF_SIZE_T)
1058 # define LZO_SIZEOF_SIZE_T (SIZEOF_SIZE_T)
1059 #endif
1060 #if defined(SIZEOF_PTRDIFF_T)
1061 # define LZO_SIZEOF_PTRDIFF_T (SIZEOF_PTRDIFF_T)
1062 #endif
1063 #define __LZO_LSR(x,b) (((x)+0ul) >> (b))
1064 #if !defined(LZO_SIZEOF_SHORT)
1065 # if (LZO_ARCH_CRAY_PVP)
1066 # define LZO_SIZEOF_SHORT 8
1067 # elif (USHRT_MAX == LZO_0xffffL)
1068 # define LZO_SIZEOF_SHORT 2
1069 # elif (__LZO_LSR(USHRT_MAX,7) == 1)
1070 # define LZO_SIZEOF_SHORT 1
1071 # elif (__LZO_LSR(USHRT_MAX,15) == 1)
1072 # define LZO_SIZEOF_SHORT 2
1073 # elif (__LZO_LSR(USHRT_MAX,31) == 1)
1074 # define LZO_SIZEOF_SHORT 4
1075 # elif (__LZO_LSR(USHRT_MAX,63) == 1)
1076 # define LZO_SIZEOF_SHORT 8
1077 # elif (__LZO_LSR(USHRT_MAX,127) == 1)
1078 # define LZO_SIZEOF_SHORT 16
1079 # else
1080 # error "LZO_SIZEOF_SHORT"
1081 # endif
1082 #endif
1083 #if !defined(LZO_SIZEOF_INT)
1084 # if (LZO_ARCH_CRAY_PVP)
1085 # define LZO_SIZEOF_INT 8
1086 # elif (UINT_MAX == LZO_0xffffL)
1087 # define LZO_SIZEOF_INT 2
1088 # elif (UINT_MAX == LZO_0xffffffffL)
1089 # define LZO_SIZEOF_INT 4
1090 # elif (__LZO_LSR(UINT_MAX,7) == 1)
1091 # define LZO_SIZEOF_INT 1
1092 # elif (__LZO_LSR(UINT_MAX,15) == 1)
1093 # define LZO_SIZEOF_INT 2
1094 # elif (__LZO_LSR(UINT_MAX,31) == 1)
1095 # define LZO_SIZEOF_INT 4
1096 # elif (__LZO_LSR(UINT_MAX,63) == 1)
1097 # define LZO_SIZEOF_INT 8
1098 # elif (__LZO_LSR(UINT_MAX,127) == 1)
1099 # define LZO_SIZEOF_INT 16
1100 # else
1101 # error "LZO_SIZEOF_INT"
1102 # endif
1103 #endif
1104 #if !defined(LZO_SIZEOF_LONG)
1105 # if (ULONG_MAX == LZO_0xffffffffL)
1106 # define LZO_SIZEOF_LONG 4
1107 # elif (__LZO_LSR(ULONG_MAX,7) == 1)
1108 # define LZO_SIZEOF_LONG 1
1109 # elif (__LZO_LSR(ULONG_MAX,15) == 1)
1110 # define LZO_SIZEOF_LONG 2
1111 # elif (__LZO_LSR(ULONG_MAX,31) == 1)
1112 # define LZO_SIZEOF_LONG 4
1113 # elif (__LZO_LSR(ULONG_MAX,63) == 1)
1114 # define LZO_SIZEOF_LONG 8
1115 # elif (__LZO_LSR(ULONG_MAX,127) == 1)
1116 # define LZO_SIZEOF_LONG 16
1117 # else
1118 # error "LZO_SIZEOF_LONG"
1119 # endif
1120 #endif
1121 #if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64)
1122 #if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8)
1123 # if defined(__LONG_MAX__) && defined(__LONG_LONG_MAX__)
1124 # if (LZO_CC_GNUC >= 0x030300ul)
1125 # if ((__LONG_MAX__)+0 == (__LONG_LONG_MAX__)+0)
1126 # define LZO_SIZEOF_LONG_LONG LZO_SIZEOF_LONG
1127 # elif (__LZO_LSR(__LONG_LONG_MAX__,30) == 1)
1128 # define LZO_SIZEOF_LONG_LONG 4
1129 # endif
1130 # endif
1131 # endif
1132 #endif
1133 #endif
1134 #if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64)
1135 #if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8)
1136 #if (LZO_ARCH_I086 && LZO_CC_DMC)
1137 #elif (LZO_CC_CILLY) && defined(__GNUC__)
1138 # define LZO_SIZEOF_LONG_LONG 8
1139 #elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE)
1140 # define LZO_SIZEOF_LONG_LONG 8
1141 #elif ((LZO_OS_WIN32 || LZO_OS_WIN64 || defined(_WIN32)) && LZO_CC_MSC && (_MSC_VER >= 1400))
1142 # define LZO_SIZEOF_LONG_LONG 8
1143 #elif (LZO_OS_WIN64 || defined(_WIN64))
1144 # define LZO_SIZEOF___INT64 8
1145 #elif (LZO_ARCH_I386 && (LZO_CC_DMC))
1146 # define LZO_SIZEOF_LONG_LONG 8
1147 #elif (LZO_ARCH_I386 && (LZO_CC_SYMANTECC && (__SC__ >= 0x700)))
1148 # define LZO_SIZEOF_LONG_LONG 8
1149 #elif (LZO_ARCH_I386 && (LZO_CC_INTELC && defined(__linux__)))
1150 # define LZO_SIZEOF_LONG_LONG 8
1151 #elif (LZO_ARCH_I386 && (LZO_CC_MWERKS || LZO_CC_PELLESC || LZO_CC_PGI || LZO_CC_SUNPROC))
1152 # define LZO_SIZEOF_LONG_LONG 8
1153 #elif (LZO_ARCH_I386 && (LZO_CC_INTELC || LZO_CC_MSC))
1154 # define LZO_SIZEOF___INT64 8
1155 #elif ((LZO_OS_WIN32 || defined(_WIN32)) && (LZO_CC_MSC))
1156 # define LZO_SIZEOF___INT64 8
1157 #elif (LZO_ARCH_I386 && (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0520)))
1158 # define LZO_SIZEOF___INT64 8
1159 #elif (LZO_ARCH_I386 && (LZO_CC_WATCOMC && (__WATCOMC__ >= 1100)))
1160 # define LZO_SIZEOF___INT64 8
1161 #elif (LZO_CC_WATCOMC && defined(_INTEGRAL_MAX_BITS) && (_INTEGRAL_MAX_BITS == 64))
1162 # define LZO_SIZEOF___INT64 8
1163 #elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__)
1164 # define LZO_SIZEOF_LONG_LONG 8
1165 #elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64)
1166 # define LZO_SIZEOF_LONG_LONG 8
1167 #elif (LZO_CC_SDCC) && (LZO_SIZEOF_INT == 2)
1168 #elif 1 && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
1169 # define LZO_SIZEOF_LONG_LONG 8
1170 #endif
1171 #endif
1172 #endif
1173 #if defined(__cplusplus) && (LZO_CC_GNUC)
1174 # if (LZO_CC_GNUC < 0x020800ul)
1175 # undef LZO_SIZEOF_LONG_LONG
1176 # endif
1177 #endif
1178 #if (LZO_CFG_NO_LONG_LONG) || defined(__NO_LONG_LONG)
1179 # undef LZO_SIZEOF_LONG_LONG
1180 #endif
1181 #if !defined(LZO_SIZEOF_VOID_P)
1182 #if (LZO_ARCH_I086)
1183 # define __LZO_WORDSIZE 2
1184 # if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM)
1185 # define LZO_SIZEOF_VOID_P 2
1186 # elif (LZO_MM_COMPACT || LZO_MM_LARGE || LZO_MM_HUGE)
1187 # define LZO_SIZEOF_VOID_P 4
1188 # else
1189 # error "LZO_MM"
1190 # endif
1191 #elif (LZO_ARCH_AVR || LZO_ARCH_Z80)
1192 # define __LZO_WORDSIZE 1
1193 # define LZO_SIZEOF_VOID_P 2
1194 #elif (LZO_ARCH_C166 || LZO_ARCH_MCS51 || LZO_ARCH_MCS251 || LZO_ARCH_MSP430)
1195 # define LZO_SIZEOF_VOID_P 2
1196 #elif (LZO_ARCH_H8300)
1197 # if defined(__NORMAL_MODE__)
1198 # define __LZO_WORDSIZE 4
1199 # define LZO_SIZEOF_VOID_P 2
1200 # elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__)
1201 # define __LZO_WORDSIZE 4
1202 # define LZO_SIZEOF_VOID_P 4
1203 # else
1204 # define __LZO_WORDSIZE 2
1205 # define LZO_SIZEOF_VOID_P 2
1206 # endif
1207 # if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x040000ul)) && (LZO_SIZEOF_INT == 4)
1208 # define LZO_SIZEOF_SIZE_T LZO_SIZEOF_INT
1209 # define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_INT
1210 # endif
1211 #elif (LZO_ARCH_M16C)
1212 # define __LZO_WORDSIZE 2
1213 # if defined(__m32c_cpu__) || defined(__m32cm_cpu__)
1214 # define LZO_SIZEOF_VOID_P 4
1215 # else
1216 # define LZO_SIZEOF_VOID_P 2
1217 # endif
1218 #elif (LZO_SIZEOF_LONG == 8) && ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__))
1219 # define __LZO_WORDSIZE 8
1220 # define LZO_SIZEOF_VOID_P 4
1221 #elif defined(__LLP64__) || defined(__LLP64) || defined(_LLP64) || defined(_WIN64)
1222 # define __LZO_WORDSIZE 8
1223 # define LZO_SIZEOF_VOID_P 8
1224 #elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__)
1225 # define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG
1226 # define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG
1227 # define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG
1228 #elif (LZO_OS_OS400 || defined(__OS400__))
1229 # define __LZO_WORDSIZE LZO_SIZEOF_LONG
1230 # define LZO_SIZEOF_VOID_P 16
1231 # define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG
1232 # define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG
1233 #elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64)
1234 # define LZO_SIZEOF_VOID_P 8
1235 # define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG
1236 # define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG
1237 #elif (LZO_ARCH_SPU)
1238 # if 0
1239 # define __LZO_WORDSIZE 16
1240 # endif
1241 # define LZO_SIZEOF_VOID_P 4
1242 #else
1243 # define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG
1244 #endif
1245 #endif
1246 #if !defined(LZO_WORDSIZE)
1247 # if defined(__LZO_WORDSIZE)
1248 # define LZO_WORDSIZE __LZO_WORDSIZE
1249 # else
1250 # define LZO_WORDSIZE LZO_SIZEOF_VOID_P
1251 # endif
1252 #endif
1253 #if !defined(LZO_SIZEOF_SIZE_T)
1254 #if (LZO_ARCH_I086 || LZO_ARCH_M16C)
1255 # define LZO_SIZEOF_SIZE_T 2
1256 #else
1257 # define LZO_SIZEOF_SIZE_T LZO_SIZEOF_VOID_P
1258 #endif
1259 #endif
1260 #if !defined(LZO_SIZEOF_PTRDIFF_T)
1261 #if (LZO_ARCH_I086)
1262 # if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM || LZO_MM_HUGE)
1263 # define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_VOID_P
1264 # elif (LZO_MM_COMPACT || LZO_MM_LARGE)
1265 # if (LZO_CC_BORLANDC || LZO_CC_TURBOC)
1266 # define LZO_SIZEOF_PTRDIFF_T 4
1267 # else
1268 # define LZO_SIZEOF_PTRDIFF_T 2
1269 # endif
1270 # else
1271 # error "LZO_MM"
1272 # endif
1273 #else
1274 # define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_SIZE_T
1275 #endif
1276 #endif
1277 #if (LZO_ABI_NEUTRAL_ENDIAN)
1278 # undef LZO_ABI_BIG_ENDIAN
1279 # undef LZO_ABI_LITTLE_ENDIAN
1280 #elif !(LZO_ABI_BIG_ENDIAN) && !(LZO_ABI_LITTLE_ENDIAN)
1281 #if (LZO_ARCH_ALPHA) && (LZO_ARCH_CRAY_MPP)
1282 # define LZO_ABI_BIG_ENDIAN 1
1283 #elif (LZO_ARCH_IA64) && (LZO_OS_POSIX_LINUX || LZO_OS_WIN64)
1284 # define LZO_ABI_LITTLE_ENDIAN 1
1285 #elif (LZO_ARCH_ALPHA || LZO_ARCH_AMD64 || LZO_ARCH_BLACKFIN || LZO_ARCH_CRIS || LZO_ARCH_I086 || LZO_ARCH_I386 || LZO_ARCH_MSP430)
1286 # define LZO_ABI_LITTLE_ENDIAN 1
1287 #elif (LZO_ARCH_AVR32 || LZO_ARCH_M68K || LZO_ARCH_S390)
1288 # define LZO_ABI_BIG_ENDIAN 1
1289 #elif 1 && defined(__IAR_SYSTEMS_ICC__) && defined(__LITTLE_ENDIAN__)
1290 # if (__LITTLE_ENDIAN__ == 1)
1291 # define LZO_ABI_LITTLE_ENDIAN 1
1292 # else
1293 # define LZO_ABI_BIG_ENDIAN 1
1294 # endif
1295 #elif 1 && defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)
1296 # define LZO_ABI_BIG_ENDIAN 1
1297 #elif 1 && defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
1298 # define LZO_ABI_LITTLE_ENDIAN 1
1299 #elif 1 && (LZO_ARCH_ARM) && defined(__ARMEB__) && !defined(__ARMEL__)
1300 # define LZO_ABI_BIG_ENDIAN 1
1301 #elif 1 && (LZO_ARCH_ARM) && defined(__ARMEL__) && !defined(__ARMEB__)
1302 # define LZO_ABI_LITTLE_ENDIAN 1
1303 #elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEB__) && !defined(__MIPSEL__)
1304 # define LZO_ABI_BIG_ENDIAN 1
1305 #elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEL__) && !defined(__MIPSEB__)
1306 # define LZO_ABI_LITTLE_ENDIAN 1
1307 #endif
1308 #endif
1309 #if (LZO_ABI_BIG_ENDIAN) && (LZO_ABI_LITTLE_ENDIAN)
1310 # error "this should not happen"
1311 #endif
1312 #if (LZO_ABI_BIG_ENDIAN)
1313 # define LZO_INFO_ABI_ENDIAN "be"
1314 #elif (LZO_ABI_LITTLE_ENDIAN)
1315 # define LZO_INFO_ABI_ENDIAN "le"
1316 #elif (LZO_ABI_NEUTRAL_ENDIAN)
1317 # define LZO_INFO_ABI_ENDIAN "neutral"
1318 #endif
1319 #if (LZO_SIZEOF_INT == 1 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2)
1320 # define LZO_ABI_I8LP16 1
1321 # define LZO_INFO_ABI_PM "i8lp16"
1322 #elif (LZO_SIZEOF_INT == 2 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2)
1323 # define LZO_ABI_ILP16 1
1324 # define LZO_INFO_ABI_PM "ilp16"
1325 #elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 4)
1326 # define LZO_ABI_ILP32 1
1327 # define LZO_INFO_ABI_PM "ilp32"
1328 #elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 8 && LZO_SIZEOF_SIZE_T == 8)
1329 # define LZO_ABI_LLP64 1
1330 # define LZO_INFO_ABI_PM "llp64"
1331 #elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8)
1332 # define LZO_ABI_LP64 1
1333 # define LZO_INFO_ABI_PM "lp64"
1334 #elif (LZO_SIZEOF_INT == 8 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8)
1335 # define LZO_ABI_ILP64 1
1336 # define LZO_INFO_ABI_PM "ilp64"
1337 #elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 4)
1338 # define LZO_ABI_IP32L64 1
1339 # define LZO_INFO_ABI_PM "ip32l64"
1340 #endif
1341 #if !defined(__LZO_LIBC_OVERRIDE)
1342 #if (LZO_LIBC_NAKED)
1343 # define LZO_INFO_LIBC "naked"
1344 #elif (LZO_LIBC_FREESTANDING)
1345 # define LZO_INFO_LIBC "freestanding"
1346 #elif (LZO_LIBC_MOSTLY_FREESTANDING)
1347 # define LZO_INFO_LIBC "mfreestanding"
1348 #elif (LZO_LIBC_ISOC90)
1349 # define LZO_INFO_LIBC "isoc90"
1350 #elif (LZO_LIBC_ISOC99)
1351 # define LZO_INFO_LIBC "isoc99"
1352 #elif defined(__dietlibc__)
1353 # define LZO_LIBC_DIETLIBC 1
1354 # define LZO_INFO_LIBC "dietlibc"
1355 #elif defined(_NEWLIB_VERSION)
1356 # define LZO_LIBC_NEWLIB 1
1357 # define LZO_INFO_LIBC "newlib"
1358 #elif defined(__UCLIBC__) && defined(__UCLIBC_MAJOR__) && defined(__UCLIBC_MINOR__)
1359 # if defined(__UCLIBC_SUBLEVEL__)
1360 # define LZO_LIBC_UCLIBC (__UCLIBC_MAJOR__ * 0x10000L + __UCLIBC_MINOR__ * 0x100 + __UCLIBC_SUBLEVEL__)
1361 # else
1362 # define LZO_LIBC_UCLIBC 0x00090bL
1363 # endif
1364 # define LZO_INFO_LIBC "uclibc"
1365 #elif defined(__GLIBC__) && defined(__GLIBC_MINOR__)
1366 # define LZO_LIBC_GLIBC (__GLIBC__ * 0x10000L + __GLIBC_MINOR__ * 0x100)
1367 # define LZO_INFO_LIBC "glibc"
1368 #elif (LZO_CC_MWERKS) && defined(__MSL__)
1369 # define LZO_LIBC_MSL __MSL__
1370 # define LZO_INFO_LIBC "msl"
1371 #elif 1 && defined(__IAR_SYSTEMS_ICC__)
1372 # define LZO_LIBC_ISOC90 1
1373 # define LZO_INFO_LIBC "isoc90"
1374 #else
1375 # define LZO_LIBC_DEFAULT 1
1376 # define LZO_INFO_LIBC "default"
1377 #endif
1378 #endif
1379 #if !defined(__lzo_gnuc_extension__)
1380 #if (LZO_CC_GNUC >= 0x020800ul)
1381 # define __lzo_gnuc_extension__ __extension__
1382 #elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE)
1383 # define __lzo_gnuc_extension__ __extension__
1384 #else
1385 # define __lzo_gnuc_extension__ /*empty*/
1386 #endif
1387 #endif
1388 #if !defined(__lzo_ua_volatile)
1389 # define __lzo_ua_volatile volatile
1390 #endif
1391 #if !defined(__lzo_alignof)
1392 #if (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI)
1393 # define __lzo_alignof(e) __alignof__(e)
1394 #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 700))
1395 # define __lzo_alignof(e) __alignof__(e)
1396 #elif (LZO_CC_MSC && (_MSC_VER >= 1300))
1397 # define __lzo_alignof(e) __alignof(e)
1398 #elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100))
1399 # define __lzo_alignof(e) __alignof__(e)
1400 #endif
1401 #endif
1402 #if defined(__lzo_alignof)
1403 # define __lzo_HAVE_alignof 1
1404 #endif
1405 #if !defined(__lzo_constructor)
1406 #if (LZO_CC_GNUC >= 0x030400ul)
1407 # define __lzo_constructor __attribute__((__constructor__,__used__))
1408 #elif (LZO_CC_GNUC >= 0x020700ul)
1409 # define __lzo_constructor __attribute__((__constructor__))
1410 #elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE)
1411 # define __lzo_constructor __attribute__((__constructor__))
1412 #endif
1413 #endif
1414 #if defined(__lzo_constructor)
1415 # define __lzo_HAVE_constructor 1
1416 #endif
1417 #if !defined(__lzo_destructor)
1418 #if (LZO_CC_GNUC >= 0x030400ul)
1419 # define __lzo_destructor __attribute__((__destructor__,__used__))
1420 #elif (LZO_CC_GNUC >= 0x020700ul)
1421 # define __lzo_destructor __attribute__((__destructor__))
1422 #elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE)
1423 # define __lzo_destructor __attribute__((__destructor__))
1424 #endif
1425 #endif
1426 #if defined(__lzo_destructor)
1427 # define __lzo_HAVE_destructor 1
1428 #endif
1429 #if (__lzo_HAVE_destructor) && !(__lzo_HAVE_constructor)
1430 # error "this should not happen"
1431 #endif
1432 #if !defined(__lzo_inline)
1433 #if (LZO_CC_TURBOC && (__TURBOC__ <= 0x0295))
1434 #elif defined(__cplusplus)
1435 # define __lzo_inline inline
1436 #elif (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0550))
1437 # define __lzo_inline __inline
1438 #elif (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI)
1439 # define __lzo_inline __inline__
1440 #elif (LZO_CC_DMC)
1441 # define __lzo_inline __inline
1442 #elif (LZO_CC_INTELC)
1443 # define __lzo_inline __inline
1444 #elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x2405))
1445 # define __lzo_inline __inline
1446 #elif (LZO_CC_MSC && (_MSC_VER >= 900))
1447 # define __lzo_inline __inline
1448 #elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100))
1449 # define __lzo_inline __inline__
1450 #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
1451 # define __lzo_inline inline
1452 #endif
1453 #endif
1454 #if defined(__lzo_inline)
1455 # define __lzo_HAVE_inline 1
1456 #else
1457 # define __lzo_inline /*empty*/
1458 #endif
1459 #if !defined(__lzo_forceinline)
1460 #if (LZO_CC_GNUC >= 0x030200ul)
1461 # define __lzo_forceinline __inline__ __attribute__((__always_inline__))
1462 #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC)
1463 # define __lzo_forceinline __forceinline
1464 #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC)
1465 # define __lzo_forceinline __inline__ __attribute__((__always_inline__))
1466 #elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE)
1467 # define __lzo_forceinline __inline__ __attribute__((__always_inline__))
1468 #elif (LZO_CC_MSC && (_MSC_VER >= 1200))
1469 # define __lzo_forceinline __forceinline
1470 #elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100))
1471 # define __lzo_forceinline __inline__ __attribute__((__always_inline__))
1472 #endif
1473 #endif
1474 #if defined(__lzo_forceinline)
1475 # define __lzo_HAVE_forceinline 1
1476 #else
1477 # define __lzo_forceinline /*empty*/
1478 #endif
1479 #if !defined(__lzo_noinline)
1480 #if 1 && (LZO_ARCH_I386) && (LZO_CC_GNUC >= 0x040000ul) && (LZO_CC_GNUC < 0x040003ul)
1481 # define __lzo_noinline __attribute__((__noinline__,__used__))
1482 #elif (LZO_CC_GNUC >= 0x030200ul)
1483 # define __lzo_noinline __attribute__((__noinline__))
1484 #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_MSC)
1485 # define __lzo_noinline __declspec(noinline)
1486 #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC)
1487 # define __lzo_noinline __attribute__((__noinline__))
1488 #elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE)
1489 # define __lzo_noinline __attribute__((__noinline__))
1490 #elif (LZO_CC_MSC && (_MSC_VER >= 1300))
1491 # define __lzo_noinline __declspec(noinline)
1492 #elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x3200) && (LZO_OS_WIN32 || LZO_OS_WIN64))
1493 # if defined(__cplusplus)
1494 # else
1495 # define __lzo_noinline __declspec(noinline)
1496 # endif
1497 #elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100))
1498 # define __lzo_noinline __attribute__((__noinline__))
1499 #endif
1500 #endif
1501 #if defined(__lzo_noinline)
1502 # define __lzo_HAVE_noinline 1
1503 #else
1504 # define __lzo_noinline /*empty*/
1505 #endif
1506 #if (__lzo_HAVE_forceinline || __lzo_HAVE_noinline) && !(__lzo_HAVE_inline)
1507 # error "this should not happen"
1508 #endif
1509 #if !defined(__lzo_noreturn)
1510 #if (LZO_CC_GNUC >= 0x020700ul)
1511 # define __lzo_noreturn __attribute__((__noreturn__))
1512 #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC)
1513 # define __lzo_noreturn __declspec(noreturn)
1514 #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_GNUC)
1515 # define __lzo_noreturn __attribute__((__noreturn__))
1516 #elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE)
1517 # define __lzo_noreturn __attribute__((__noreturn__))
1518 #elif (LZO_CC_MSC && (_MSC_VER >= 1200))
1519 # define __lzo_noreturn __declspec(noreturn)
1520 #endif
1521 #endif
1522 #if defined(__lzo_noreturn)
1523 # define __lzo_HAVE_noreturn 1
1524 #else
1525 # define __lzo_noreturn /*empty*/
1526 #endif
1527 #if !defined(__lzo_nothrow)
1528 #if (LZO_CC_GNUC >= 0x030300ul)
1529 # define __lzo_nothrow __attribute__((__nothrow__))
1530 #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) && defined(__cplusplus)
1531 # define __lzo_nothrow __declspec(nothrow)
1532 #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 900) && LZO_CC_SYNTAX_GNUC)
1533 # define __lzo_nothrow __attribute__((__nothrow__))
1534 #elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE)
1535 # define __lzo_nothrow __attribute__((__nothrow__))
1536 #elif (LZO_CC_MSC && (_MSC_VER >= 1200)) && defined(__cplusplus)
1537 # define __lzo_nothrow __declspec(nothrow)
1538 #endif
1539 #endif
1540 #if defined(__lzo_nothrow)
1541 # define __lzo_HAVE_nothrow 1
1542 #else
1543 # define __lzo_nothrow /*empty*/
1544 #endif
1545 #if !defined(__lzo_restrict)
1546 #if (LZO_CC_GNUC >= 0x030400ul)
1547 # define __lzo_restrict __restrict__
1548 #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_GNUC)
1549 # define __lzo_restrict __restrict__
1550 #elif (LZO_CC_CLANG || LZO_CC_LLVM)
1551 # define __lzo_restrict __restrict__
1552 #elif (LZO_CC_MSC && (_MSC_VER >= 1400))
1553 # define __lzo_restrict __restrict
1554 #endif
1555 #endif
1556 #if defined(__lzo_restrict)
1557 # define __lzo_HAVE_restrict 1
1558 #else
1559 # define __lzo_restrict /*empty*/
1560 #endif
1561 #if !defined(__lzo_likely) && !defined(__lzo_unlikely)
1562 #if (LZO_CC_GNUC >= 0x030200ul)
1563 # define __lzo_likely(e) (__builtin_expect(!!(e),1))
1564 # define __lzo_unlikely(e) (__builtin_expect(!!(e),0))
1565 #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800))
1566 # define __lzo_likely(e) (__builtin_expect(!!(e),1))
1567 # define __lzo_unlikely(e) (__builtin_expect(!!(e),0))
1568 #elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE)
1569 # define __lzo_likely(e) (__builtin_expect(!!(e),1))
1570 # define __lzo_unlikely(e) (__builtin_expect(!!(e),0))
1571 #endif
1572 #endif
1573 #if defined(__lzo_likely)
1574 # define __lzo_HAVE_likely 1
1575 #else
1576 # define __lzo_likely(e) (e)
1577 #endif
1578 #if defined(__lzo_unlikely)
1579 # define __lzo_HAVE_unlikely 1
1580 #else
1581 # define __lzo_unlikely(e) (e)
1582 #endif
1583 #if !defined(LZO_UNUSED)
1584 # if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600))
1585 # define LZO_UNUSED(var) ((void) &var)
1586 # elif (LZO_CC_BORLANDC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PELLESC || LZO_CC_TURBOC)
1587 # define LZO_UNUSED(var) if (&var) ; else
1588 # elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE)
1589 # define LZO_UNUSED(var) ((void) var)
1590 # elif (LZO_CC_MSC && (_MSC_VER < 900))
1591 # define LZO_UNUSED(var) if (&var) ; else
1592 # elif (LZO_CC_KEILC)
1593 # define LZO_UNUSED(var) {extern int __lzo_unused[1-2*!(sizeof(var)>0)];}
1594 # elif (LZO_CC_PACIFICC)
1595 # define LZO_UNUSED(var) ((void) sizeof(var))
1596 # elif (LZO_CC_WATCOMC) && defined(__cplusplus)
1597 # define LZO_UNUSED(var) ((void) var)
1598 # else
1599 # define LZO_UNUSED(var) ((void) &var)
1600 # endif
1601 #endif
1602 #if !defined(LZO_UNUSED_FUNC)
1603 # if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600))
1604 # define LZO_UNUSED_FUNC(func) ((void) func)
1605 # elif (LZO_CC_BORLANDC || LZO_CC_NDPC || LZO_CC_TURBOC)
1606 # define LZO_UNUSED_FUNC(func) if (func) ; else
1607 # elif (LZO_CC_CLANG || LZO_CC_LLVM)
1608 # define LZO_UNUSED_FUNC(func) ((void) &func)
1609 # elif (LZO_CC_MSC && (_MSC_VER < 900))
1610 # define LZO_UNUSED_FUNC(func) if (func) ; else
1611 # elif (LZO_CC_MSC)
1612 # define LZO_UNUSED_FUNC(func) ((void) &func)
1613 # elif (LZO_CC_KEILC || LZO_CC_PELLESC)
1614 # define LZO_UNUSED_FUNC(func) {extern int __lzo_unused[1-2*!(sizeof((int)func)>0)];}
1615 # else
1616 # define LZO_UNUSED_FUNC(func) ((void) func)
1617 # endif
1618 #endif
1619 #if !defined(LZO_UNUSED_LABEL)
1620 # if (LZO_CC_WATCOMC) && defined(__cplusplus)
1621 # define LZO_UNUSED_LABEL(l) switch(0) case 1:goto l
1622 # elif (LZO_CC_CLANG || LZO_CC_INTELC || LZO_CC_WATCOMC)
1623 # define LZO_UNUSED_LABEL(l) if (0) goto l
1624 # else
1625 # define LZO_UNUSED_LABEL(l) switch(0) case 1:goto l
1626 # endif
1627 #endif
1628 #if !defined(LZO_DEFINE_UNINITIALIZED_VAR)
1629 # if 0
1630 # define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var
1631 # elif 0 && (LZO_CC_GNUC)
1632 # define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = var
1633 # else
1634 # define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = init
1635 # endif
1636 #endif
1637 #if !defined(LZO_UNCONST_CAST)
1638 # if 0 && defined(__cplusplus)
1639 # define LZO_UNCONST_CAST(t,e) (const_cast<t> (e))
1640 # elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE)
1641 # define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((char *) ((lzo_uintptr_t) ((const void *) (e))))))
1642 # else
1643 # define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((char *) ((const void *) (e)))))
1644 # endif
1645 #endif
1646 #if !defined(LZO_COMPILE_TIME_ASSERT_HEADER)
1647 # if (LZO_CC_AZTECC || LZO_CC_ZORTECHC)
1648 # define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-!(e)];
1649 # elif (LZO_CC_DMC || LZO_CC_SYMANTECC)
1650 # define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1u-2*!(e)];
1651 # elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295))
1652 # define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-!(e)];
1653 # else
1654 # define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-2*!(e)];
1655 # endif
1656 #endif
1657 #if !defined(LZO_COMPILE_TIME_ASSERT)
1658 # if (LZO_CC_AZTECC)
1659 # define LZO_COMPILE_TIME_ASSERT(e) {typedef int __lzo_cta_t[1-!(e)];}
1660 # elif (LZO_CC_DMC || LZO_CC_PACIFICC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC)
1661 # define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break;
1662 # elif (LZO_CC_MSC && (_MSC_VER < 900))
1663 # define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break;
1664 # elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295))
1665 # define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break;
1666 # else
1667 # define LZO_COMPILE_TIME_ASSERT(e) {typedef int __lzo_cta_t[1-2*!(e)];}
1668 # endif
1669 #endif
1670 #if (LZO_ARCH_I086 || LZO_ARCH_I386) && (LZO_OS_DOS16 || LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_OS216 || LZO_OS_WIN16 || LZO_OS_WIN32 || LZO_OS_WIN64)
1671 # if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC)
1672 # elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC)
1673 # define __lzo_cdecl __cdecl
1674 # define __lzo_cdecl_atexit /*empty*/
1675 # define __lzo_cdecl_main __cdecl
1676 # if (LZO_OS_OS2 && (LZO_CC_DMC || LZO_CC_SYMANTECC))
1677 # define __lzo_cdecl_qsort __pascal
1678 # elif (LZO_OS_OS2 && (LZO_CC_ZORTECHC))
1679 # define __lzo_cdecl_qsort _stdcall
1680 # else
1681 # define __lzo_cdecl_qsort __cdecl
1682 # endif
1683 # elif (LZO_CC_WATCOMC)
1684 # define __lzo_cdecl __cdecl
1685 # else
1686 # define __lzo_cdecl __cdecl
1687 # define __lzo_cdecl_atexit __cdecl
1688 # define __lzo_cdecl_main __cdecl
1689 # define __lzo_cdecl_qsort __cdecl
1690 # endif
1691 # if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC || LZO_CC_WATCOMC)
1692 # elif (LZO_OS_OS2 && (LZO_CC_DMC || LZO_CC_SYMANTECC))
1693 # define __lzo_cdecl_sighandler __pascal
1694 # elif (LZO_OS_OS2 && (LZO_CC_ZORTECHC))
1695 # define __lzo_cdecl_sighandler _stdcall
1696 # elif (LZO_CC_MSC && (_MSC_VER >= 1400)) && defined(_M_CEE_PURE)
1697 # define __lzo_cdecl_sighandler __clrcall
1698 # elif (LZO_CC_MSC && (_MSC_VER >= 600 && _MSC_VER < 700))
1699 # if defined(_DLL)
1700 # define __lzo_cdecl_sighandler _far _cdecl _loadds
1701 # elif defined(_MT)
1702 # define __lzo_cdecl_sighandler _far _cdecl
1703 # else
1704 # define __lzo_cdecl_sighandler _cdecl
1705 # endif
1706 # else
1707 # define __lzo_cdecl_sighandler __cdecl
1708 # endif
1709 #elif (LZO_ARCH_I386) && (LZO_CC_WATCOMC)
1710 # define __lzo_cdecl __cdecl
1711 #elif (LZO_ARCH_M68K && LZO_OS_TOS && (LZO_CC_PUREC || LZO_CC_TURBOC))
1712 # define __lzo_cdecl cdecl
1713 #endif
1714 #if !defined(__lzo_cdecl)
1715 # define __lzo_cdecl /*empty*/
1716 #endif
1717 #if !defined(__lzo_cdecl_atexit)
1718 # define __lzo_cdecl_atexit /*empty*/
1719 #endif
1720 #if !defined(__lzo_cdecl_main)
1721 # define __lzo_cdecl_main /*empty*/
1722 #endif
1723 #if !defined(__lzo_cdecl_qsort)
1724 # define __lzo_cdecl_qsort /*empty*/
1725 #endif
1726 #if !defined(__lzo_cdecl_sighandler)
1727 # define __lzo_cdecl_sighandler /*empty*/
1728 #endif
1729 #if !defined(__lzo_cdecl_va)
1730 # define __lzo_cdecl_va __lzo_cdecl
1731 #endif
1732 #if !(LZO_CFG_NO_WINDOWS_H)
1733 #if (LZO_OS_CYGWIN || (LZO_OS_EMX && defined(__RSXNT__)) || LZO_OS_WIN32 || LZO_OS_WIN64)
1734 # if (LZO_CC_WATCOMC && (__WATCOMC__ < 1000))
1735 # elif (LZO_OS_WIN32 && LZO_CC_GNUC) && defined(__PW32__)
1736 # elif ((LZO_OS_CYGWIN || defined(__MINGW32__)) && (LZO_CC_GNUC && (LZO_CC_GNUC < 0x025f00ul)))
1737 # else
1738 # define LZO_HAVE_WINDOWS_H 1
1739 # endif
1740 #endif
1741 #endif
1742 #if (LZO_ARCH_ALPHA)
1743 # define LZO_OPT_AVOID_UINT_INDEX 1
1744 # define LZO_OPT_AVOID_SHORT 1
1745 # define LZO_OPT_AVOID_USHORT 1
1746 #elif (LZO_ARCH_AMD64)
1747 # define LZO_OPT_AVOID_INT_INDEX 1
1748 # define LZO_OPT_AVOID_UINT_INDEX 1
1749 # define LZO_OPT_UNALIGNED16 1
1750 # define LZO_OPT_UNALIGNED32 1
1751 # define LZO_OPT_UNALIGNED64 1
1752 #elif (LZO_ARCH_ARM && LZO_ARCH_ARM_THUMB)
1753 #elif (LZO_ARCH_ARM)
1754 # define LZO_OPT_AVOID_SHORT 1
1755 # define LZO_OPT_AVOID_USHORT 1
1756 #elif (LZO_ARCH_CRIS)
1757 # define LZO_OPT_UNALIGNED16 1
1758 # define LZO_OPT_UNALIGNED32 1
1759 #elif (LZO_ARCH_I386)
1760 # define LZO_OPT_UNALIGNED16 1
1761 # define LZO_OPT_UNALIGNED32 1
1762 #elif (LZO_ARCH_IA64)
1763 # define LZO_OPT_AVOID_INT_INDEX 1
1764 # define LZO_OPT_AVOID_UINT_INDEX 1
1765 # define LZO_OPT_PREFER_POSTINC 1
1766 #elif (LZO_ARCH_M68K)
1767 # define LZO_OPT_PREFER_POSTINC 1
1768 # define LZO_OPT_PREFER_PREDEC 1
1769 # if defined(__mc68020__) && !defined(__mcoldfire__)
1770 # define LZO_OPT_UNALIGNED16 1
1771 # define LZO_OPT_UNALIGNED32 1
1772 # endif
1773 #elif (LZO_ARCH_MIPS)
1774 # define LZO_OPT_AVOID_UINT_INDEX 1
1775 #elif (LZO_ARCH_POWERPC)
1776 # define LZO_OPT_PREFER_PREINC 1
1777 # define LZO_OPT_PREFER_PREDEC 1
1778 # if (LZO_ABI_BIG_ENDIAN)
1779 # define LZO_OPT_UNALIGNED16 1
1780 # define LZO_OPT_UNALIGNED32 1
1781 # endif
1782 #elif (LZO_ARCH_S390)
1783 # define LZO_OPT_UNALIGNED16 1
1784 # define LZO_OPT_UNALIGNED32 1
1785 # if (LZO_SIZEOF_SIZE_T == 8)
1786 # define LZO_OPT_UNALIGNED64 1
1787 # endif
1788 #elif (LZO_ARCH_SH)
1789 # define LZO_OPT_PREFER_POSTINC 1
1790 # define LZO_OPT_PREFER_PREDEC 1
1791 #endif
1792 #ifndef LZO_CFG_NO_INLINE_ASM
1793 #if (LZO_CC_LLVM)
1794 # define LZO_CFG_NO_INLINE_ASM 1
1795 #endif
1796 #endif
1797 #ifndef LZO_CFG_NO_UNALIGNED
1798 #if (LZO_ABI_NEUTRAL_ENDIAN) || (LZO_ARCH_GENERIC)
1799 # define LZO_CFG_NO_UNALIGNED 1
1800 #endif
1801 #endif
1802 #if (LZO_CFG_NO_UNALIGNED)
1803 # undef LZO_OPT_UNALIGNED16
1804 # undef LZO_OPT_UNALIGNED32
1805 # undef LZO_OPT_UNALIGNED64
1806 #endif
1807 #if (LZO_CFG_NO_INLINE_ASM)
1808 #elif (LZO_ARCH_I386 && (LZO_OS_DOS32 || LZO_OS_WIN32) && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC))
1809 # define LZO_ASM_SYNTAX_MSC 1
1810 #elif (LZO_OS_WIN64 && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC))
1811 #elif (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC == 0x011f00ul))
1812 #elif (LZO_ARCH_I386 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE))
1813 # define LZO_ASM_SYNTAX_GNUC 1
1814 #elif (LZO_ARCH_AMD64 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE))
1815 # define LZO_ASM_SYNTAX_GNUC 1
1816 #endif
1817 #if (LZO_ASM_SYNTAX_GNUC)
1818 #if (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC < 0x020000ul))
1819 # define __LZO_ASM_CLOBBER "ax"
1820 #elif (LZO_CC_INTELC)
1821 # define __LZO_ASM_CLOBBER "memory"
1822 #else
1823 # define __LZO_ASM_CLOBBER "cc", "memory"
1824 #endif
1825 #endif
1826 #if defined(__LZO_INFOSTR_MM)
1827 #elif (LZO_MM_FLAT) && (defined(__LZO_INFOSTR_PM) || defined(LZO_INFO_ABI_PM))
1828 # define __LZO_INFOSTR_MM ""
1829 #elif defined(LZO_INFO_MM)
1830 # define __LZO_INFOSTR_MM "." LZO_INFO_MM
1831 #else
1832 # define __LZO_INFOSTR_MM ""
1833 #endif
1834 #if defined(__LZO_INFOSTR_PM)
1835 #elif defined(LZO_INFO_ABI_PM)
1836 # define __LZO_INFOSTR_PM "." LZO_INFO_ABI_PM
1837 #else
1838 # define __LZO_INFOSTR_PM ""
1839 #endif
1840 #if defined(__LZO_INFOSTR_ENDIAN)
1841 #elif defined(LZO_INFO_ABI_ENDIAN)
1842 # define __LZO_INFOSTR_ENDIAN "." LZO_INFO_ABI_ENDIAN
1843 #else
1844 # define __LZO_INFOSTR_ENDIAN ""
1845 #endif
1846 #if defined(__LZO_INFOSTR_OSNAME)
1847 #elif defined(LZO_INFO_OS_CONSOLE)
1848 # define __LZO_INFOSTR_OSNAME LZO_INFO_OS "." LZO_INFO_OS_CONSOLE
1849 #elif defined(LZO_INFO_OS_POSIX)
1850 # define __LZO_INFOSTR_OSNAME LZO_INFO_OS "." LZO_INFO_OS_POSIX
1851 #else
1852 # define __LZO_INFOSTR_OSNAME LZO_INFO_OS
1853 #endif
1854 #if defined(__LZO_INFOSTR_LIBC)
1855 #elif defined(LZO_INFO_LIBC)
1856 # define __LZO_INFOSTR_LIBC "." LZO_INFO_LIBC
1857 #else
1858 # define __LZO_INFOSTR_LIBC ""
1859 #endif
1860 #if defined(__LZO_INFOSTR_CCVER)
1861 #elif defined(LZO_INFO_CCVER)
1862 # define __LZO_INFOSTR_CCVER " " LZO_INFO_CCVER
1863 #else
1864 # define __LZO_INFOSTR_CCVER ""
1865 #endif
1866 #define LZO_INFO_STRING \
1867 LZO_INFO_ARCH __LZO_INFOSTR_MM __LZO_INFOSTR_PM __LZO_INFOSTR_ENDIAN \
1868 " " __LZO_INFOSTR_OSNAME __LZO_INFOSTR_LIBC " " LZO_INFO_CC __LZO_INFOSTR_CCVER
1870 #endif
1872 #endif
1874 #undef LZO_HAVE_CONFIG_H
1875 #include "minilzo.h"
1877 #if !defined(MINILZO_VERSION) || (MINILZO_VERSION != 0x2060)
1878 # error "version mismatch in miniLZO source files"
1879 #endif
1881 #ifdef MINILZO_HAVE_CONFIG_H
1882 # define LZO_HAVE_CONFIG_H 1
1883 #endif
1885 #ifndef __LZO_CONF_H
1886 #define __LZO_CONF_H 1
1888 #if !defined(__LZO_IN_MINILZO)
1889 #if (LZO_CFG_FREESTANDING)
1890 # define LZO_LIBC_FREESTANDING 1
1891 # define LZO_OS_FREESTANDING 1
1892 # define ACC_LIBC_FREESTANDING 1
1893 # define ACC_OS_FREESTANDING 1
1894 #endif
1895 #if (LZO_CFG_NO_UNALIGNED)
1896 # define ACC_CFG_NO_UNALIGNED 1
1897 #endif
1898 #if (LZO_ARCH_GENERIC)
1899 # define ACC_ARCH_GENERIC 1
1900 #endif
1901 #if (LZO_ABI_NEUTRAL_ENDIAN)
1902 # define ACC_ABI_NEUTRAL_ENDIAN 1
1903 #endif
1904 #if (LZO_HAVE_CONFIG_H)
1905 # define ACC_CONFIG_NO_HEADER 1
1906 #endif
1907 #if defined(LZO_CFG_EXTRA_CONFIG_HEADER)
1908 # include LZO_CFG_EXTRA_CONFIG_HEADER
1909 #endif
1910 #if defined(__LZOCONF_H) || defined(__LZOCONF_H_INCLUDED)
1911 # error "include this file first"
1912 #endif
1913 #include "lzo/lzoconf.h"
1914 #endif
1916 #if (LZO_VERSION < 0x02000) || !defined(__LZOCONF_H_INCLUDED)
1917 # error "version mismatch"
1918 #endif
1920 #if (LZO_CC_BORLANDC && LZO_ARCH_I086)
1921 # pragma option -h
1922 #endif
1924 #if (LZO_CC_MSC && (_MSC_VER >= 1000))
1925 # pragma warning(disable: 4127 4701)
1926 #endif
1927 #if (LZO_CC_MSC && (_MSC_VER >= 1300))
1928 # pragma warning(disable: 4820)
1929 # pragma warning(disable: 4514 4710 4711)
1930 #endif
1932 #if (LZO_CC_SUNPROC)
1933 #if !defined(__cplusplus)
1934 # pragma error_messages(off,E_END_OF_LOOP_CODE_NOT_REACHED)
1935 # pragma error_messages(off,E_LOOP_NOT_ENTERED_AT_TOP)
1936 # pragma error_messages(off,E_STATEMENT_NOT_REACHED)
1937 #endif
1938 #endif
1940 #if (__LZO_MMODEL_HUGE) && !(LZO_HAVE_MM_HUGE_PTR)
1941 # error "this should not happen - check defines for __huge"
1942 #endif
1944 #if defined(__LZO_IN_MINILZO) || defined(LZO_CFG_FREESTANDING)
1945 #elif (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16)
1946 # define ACC_WANT_ACC_INCD_H 1
1947 # define ACC_WANT_ACC_INCE_H 1
1948 # define ACC_WANT_ACC_INCI_H 1
1949 #elif 1
1950 # include <string.h>
1951 #else
1952 # define ACC_WANT_ACC_INCD_H 1
1953 #endif
1955 #if (LZO_ARCH_I086)
1956 # define ACC_MM_AHSHIFT LZO_MM_AHSHIFT
1957 # define ACC_PTR_FP_OFF(x) (((const unsigned __far*)&(x))[0])
1958 # define ACC_PTR_FP_SEG(x) (((const unsigned __far*)&(x))[1])
1959 # define ACC_PTR_MK_FP(s,o) ((void __far*)(((unsigned long)(s)<<16)+(unsigned)(o)))
1960 #endif
1962 #if !defined(lzo_uintptr_t)
1963 # if defined(__LZO_MMODEL_HUGE)
1964 # define lzo_uintptr_t unsigned long
1965 # elif 1 && defined(LZO_OS_OS400) && (LZO_SIZEOF_VOID_P == 16)
1966 # define __LZO_UINTPTR_T_IS_POINTER 1
1967 typedef char* lzo_uintptr_t;
1968 # define lzo_uintptr_t lzo_uintptr_t
1969 # elif (LZO_SIZEOF_SIZE_T == LZO_SIZEOF_VOID_P)
1970 # define lzo_uintptr_t size_t
1971 # elif (LZO_SIZEOF_LONG == LZO_SIZEOF_VOID_P)
1972 # define lzo_uintptr_t unsigned long
1973 # elif (LZO_SIZEOF_INT == LZO_SIZEOF_VOID_P)
1974 # define lzo_uintptr_t unsigned int
1975 # elif (LZO_SIZEOF_LONG_LONG == LZO_SIZEOF_VOID_P)
1976 # define lzo_uintptr_t unsigned long long
1977 # else
1978 # define lzo_uintptr_t size_t
1979 # endif
1980 #endif
1981 LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uintptr_t) >= sizeof(lzo_voidp))
1983 #if 1 && !defined(LZO_CFG_FREESTANDING)
1984 #if 1 && !defined(HAVE_STRING_H)
1985 #define HAVE_STRING_H 1
1986 #endif
1987 #if 1 && !defined(HAVE_MEMCMP)
1988 #define HAVE_MEMCMP 1
1989 #endif
1990 #if 1 && !defined(HAVE_MEMCPY)
1991 #define HAVE_MEMCPY 1
1992 #endif
1993 #if 1 && !defined(HAVE_MEMMOVE)
1994 #define HAVE_MEMMOVE 1
1995 #endif
1996 #if 1 && !defined(HAVE_MEMSET)
1997 #define HAVE_MEMSET 1
1998 #endif
1999 #endif
2001 #if 1 && defined(HAVE_STRING_H)
2002 #include <string.h>
2003 #endif
2005 #if (LZO_CFG_FREESTANDING)
2006 # undef HAVE_MEMCMP
2007 # undef HAVE_MEMCPY
2008 # undef HAVE_MEMMOVE
2009 # undef HAVE_MEMSET
2010 #endif
2012 #if !(HAVE_MEMCMP)
2013 # undef memcmp
2014 # define memcmp(a,b,c) lzo_memcmp(a,b,c)
2015 #elif !(__LZO_MMODEL_HUGE)
2016 # undef lzo_memcmp
2017 # define lzo_memcmp(a,b,c) memcmp(a,b,c)
2018 #endif
2019 #if !(HAVE_MEMCPY)
2020 # undef memcpy
2021 # define memcpy(a,b,c) lzo_memcpy(a,b,c)
2022 #elif !(__LZO_MMODEL_HUGE)
2023 # undef lzo_memcpy
2024 # define lzo_memcpy(a,b,c) memcpy(a,b,c)
2025 #endif
2026 #if !(HAVE_MEMMOVE)
2027 # undef memmove
2028 # define memmove(a,b,c) lzo_memmove(a,b,c)
2029 #elif !(__LZO_MMODEL_HUGE)
2030 # undef lzo_memmove
2031 # define lzo_memmove(a,b,c) memmove(a,b,c)
2032 #endif
2033 #if !(HAVE_MEMSET)
2034 # undef memset
2035 # define memset(a,b,c) lzo_memset(a,b,c)
2036 #elif !(__LZO_MMODEL_HUGE)
2037 # undef lzo_memset
2038 # define lzo_memset(a,b,c) memset(a,b,c)
2039 #endif
2041 #undef NDEBUG
2042 #if (LZO_CFG_FREESTANDING)
2043 # undef LZO_DEBUG
2044 # define NDEBUG 1
2045 # undef assert
2046 # define assert(e) ((void)0)
2047 #else
2048 # if !defined(LZO_DEBUG)
2049 # define NDEBUG 1
2050 # endif
2051 # include <assert.h>
2052 #endif
2054 #if 0 && defined(__BOUNDS_CHECKING_ON)
2055 # include <unchecked.h>
2056 #else
2057 # define BOUNDS_CHECKING_OFF_DURING(stmt) stmt
2058 # define BOUNDS_CHECKING_OFF_IN_EXPR(expr) (expr)
2059 #endif
2061 #if !defined(__lzo_inline)
2062 # define __lzo_inline /*empty*/
2063 #endif
2064 #if !defined(__lzo_forceinline)
2065 # define __lzo_forceinline /*empty*/
2066 #endif
2067 #if !defined(__lzo_noinline)
2068 # define __lzo_noinline /*empty*/
2069 #endif
2071 #if (LZO_CFG_PGO)
2072 # undef __acc_likely
2073 # undef __acc_unlikely
2074 # undef __lzo_likely
2075 # undef __lzo_unlikely
2076 # define __acc_likely(e) (e)
2077 # define __acc_unlikely(e) (e)
2078 # define __lzo_likely(e) (e)
2079 # define __lzo_unlikely(e) (e)
2080 #endif
2082 #if 1
2083 # define LZO_BYTE(x) ((unsigned char) (x))
2084 #else
2085 # define LZO_BYTE(x) ((unsigned char) ((x) & 0xff))
2086 #endif
2088 #define LZO_MAX(a,b) ((a) >= (b) ? (a) : (b))
2089 #define LZO_MIN(a,b) ((a) <= (b) ? (a) : (b))
2090 #define LZO_MAX3(a,b,c) ((a) >= (b) ? LZO_MAX(a,c) : LZO_MAX(b,c))
2091 #define LZO_MIN3(a,b,c) ((a) <= (b) ? LZO_MIN(a,c) : LZO_MIN(b,c))
2093 #define lzo_sizeof(type) ((lzo_uint) (sizeof(type)))
2095 #define LZO_HIGH(array) ((lzo_uint) (sizeof(array)/sizeof(*(array))))
2097 #define LZO_SIZE(bits) (1u << (bits))
2098 #define LZO_MASK(bits) (LZO_SIZE(bits) - 1)
2100 #define LZO_LSIZE(bits) (1ul << (bits))
2101 #define LZO_LMASK(bits) (LZO_LSIZE(bits) - 1)
2103 #define LZO_USIZE(bits) ((lzo_uint) 1 << (bits))
2104 #define LZO_UMASK(bits) (LZO_USIZE(bits) - 1)
2106 #if !defined(DMUL)
2107 #if 0
2109 # define DMUL(a,b) ((lzo_xint) ((lzo_uint32)(a) * (lzo_uint32)(b)))
2110 #else
2111 # define DMUL(a,b) ((lzo_xint) ((a) * (b)))
2112 #endif
2113 #endif
2115 #if 1 && (LZO_ARCH_AMD64 || LZO_ARCH_I386 || LZO_ARCH_POWERPC)
2116 # if (LZO_SIZEOF_SHORT == 2)
2117 # define LZO_UNALIGNED_OK_2 1
2118 # endif
2119 # if (LZO_SIZEOF_INT == 4)
2120 # define LZO_UNALIGNED_OK_4 1
2121 # endif
2122 #endif
2123 #if 1 && (LZO_ARCH_AMD64)
2124 # if defined(LZO_UINT64_MAX)
2125 # define LZO_UNALIGNED_OK_8 1
2126 # endif
2127 #endif
2128 #if (LZO_CFG_NO_UNALIGNED)
2129 # undef LZO_UNALIGNED_OK_2
2130 # undef LZO_UNALIGNED_OK_4
2131 # undef LZO_UNALIGNED_OK_8
2132 #endif
2134 #undef UA_GET16
2135 #undef UA_SET16
2136 #undef UA_COPY16
2137 #undef UA_GET32
2138 #undef UA_SET32
2139 #undef UA_COPY32
2140 #undef UA_GET64
2141 #undef UA_SET64
2142 #undef UA_COPY64
2143 #if defined(LZO_UNALIGNED_OK_2)
2144 LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(unsigned short) == 2)
2145 # if 1 && defined(ACC_UA_COPY16)
2146 # define UA_GET16 ACC_UA_GET16
2147 # define UA_SET16 ACC_UA_SET16
2148 # define UA_COPY16 ACC_UA_COPY16
2149 # else
2150 # define UA_GET16(p) (* (__lzo_ua_volatile const lzo_ushortp) (__lzo_ua_volatile const lzo_voidp) (p))
2151 # define UA_SET16(p,v) ((* (__lzo_ua_volatile lzo_ushortp) (__lzo_ua_volatile lzo_voidp) (p)) = (unsigned short) (v))
2152 # define UA_COPY16(d,s) UA_SET16(d, UA_GET16(s))
2153 # endif
2154 #endif
2155 #if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
2156 LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint32) == 4)
2157 # if 1 && defined(ACC_UA_COPY32)
2158 # define UA_GET32 ACC_UA_GET32
2159 # define UA_SET32 ACC_UA_SET32
2160 # define UA_COPY32 ACC_UA_COPY32
2161 # else
2162 # define UA_GET32(p) (* (__lzo_ua_volatile const lzo_uint32p) (__lzo_ua_volatile const lzo_voidp) (p))
2163 # define UA_SET32(p,v) ((* (__lzo_ua_volatile lzo_uint32p) (__lzo_ua_volatile lzo_voidp) (p)) = (lzo_uint32) (v))
2164 # define UA_COPY32(d,s) UA_SET32(d, UA_GET32(s))
2165 # endif
2166 #endif
2167 #if defined(LZO_UNALIGNED_OK_8)
2168 LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint64) == 8)
2169 # if 1 && defined(ACC_UA_COPY64)
2170 # define UA_GET64 ACC_UA_GET64
2171 # define UA_SET64 ACC_UA_SET64
2172 # define UA_COPY64 ACC_UA_COPY64
2173 # else
2174 # define UA_GET64(p) (* (__lzo_ua_volatile const lzo_uint64p) (__lzo_ua_volatile const lzo_voidp) (p))
2175 # define UA_SET64(p,v) ((* (__lzo_ua_volatile lzo_uint64p) (__lzo_ua_volatile lzo_voidp) (p)) = (lzo_uint64) (v))
2176 # define UA_COPY64(d,s) UA_SET64(d, UA_GET64(s))
2177 # endif
2178 #endif
2180 #define MEMCPY8_DS(dest,src,len) \
2181 lzo_memcpy(dest,src,len); dest += len; src += len
2183 #define BZERO8_PTR(s,l,n) \
2184 lzo_memset((lzo_voidp)(s),0,(lzo_uint)(l)*(n))
2186 #define MEMCPY_DS(dest,src,len) \
2187 do *dest++ = *src++; while (--len > 0)
2189 LZO_EXTERN(const lzo_bytep) lzo_copyright(void);
2191 #ifndef __LZO_PTR_H
2192 #define __LZO_PTR_H 1
2194 #ifdef __cplusplus
2195 extern "C" {
2196 #endif
2198 #if !defined(lzo_uintptr_t)
2199 # if (__LZO_MMODEL_HUGE)
2200 # define lzo_uintptr_t unsigned long
2201 # else
2202 # define lzo_uintptr_t acc_uintptr_t
2203 # ifdef __ACC_INTPTR_T_IS_POINTER
2204 # define __LZO_UINTPTR_T_IS_POINTER 1
2205 # endif
2206 # endif
2207 #endif
2209 #if (LZO_ARCH_I086)
2210 #define PTR(a) ((lzo_bytep) (a))
2211 #define PTR_ALIGNED_4(a) ((ACC_PTR_FP_OFF(a) & 3) == 0)
2212 #define PTR_ALIGNED2_4(a,b) (((ACC_PTR_FP_OFF(a) | ACC_PTR_FP_OFF(b)) & 3) == 0)
2213 #elif (LZO_MM_PVP)
2214 #define PTR(a) ((lzo_bytep) (a))
2215 #define PTR_ALIGNED_8(a) ((((lzo_uintptr_t)(a)) >> 61) == 0)
2216 #define PTR_ALIGNED2_8(a,b) ((((lzo_uintptr_t)(a)|(lzo_uintptr_t)(b)) >> 61) == 0)
2217 #else
2218 #define PTR(a) ((lzo_uintptr_t) (a))
2219 #define PTR_LINEAR(a) PTR(a)
2220 #define PTR_ALIGNED_4(a) ((PTR_LINEAR(a) & 3) == 0)
2221 #define PTR_ALIGNED_8(a) ((PTR_LINEAR(a) & 7) == 0)
2222 #define PTR_ALIGNED2_4(a,b) (((PTR_LINEAR(a) | PTR_LINEAR(b)) & 3) == 0)
2223 #define PTR_ALIGNED2_8(a,b) (((PTR_LINEAR(a) | PTR_LINEAR(b)) & 7) == 0)
2224 #endif
2226 #define PTR_LT(a,b) (PTR(a) < PTR(b))
2227 #define PTR_GE(a,b) (PTR(a) >= PTR(b))
2228 #define PTR_DIFF(a,b) (PTR(a) - PTR(b))
2229 #define pd(a,b) ((lzo_uint) ((a)-(b)))
2231 LZO_EXTERN(lzo_uintptr_t)
2232 __lzo_ptr_linear(const lzo_voidp ptr);
2234 typedef union
2236 char a_char;
2237 unsigned char a_uchar;
2238 short a_short;
2239 unsigned short a_ushort;
2240 int a_int;
2241 unsigned int a_uint;
2242 long a_long;
2243 unsigned long a_ulong;
2244 lzo_int a_lzo_int;
2245 lzo_uint a_lzo_uint;
2246 lzo_int32 a_lzo_int32;
2247 lzo_uint32 a_lzo_uint32;
2248 #if defined(LZO_UINT64_MAX)
2249 lzo_int64 a_lzo_int64;
2250 lzo_uint64 a_lzo_uint64;
2251 #endif
2252 ptrdiff_t a_ptrdiff_t;
2253 lzo_uintptr_t a_lzo_uintptr_t;
2254 lzo_voidp a_lzo_voidp;
2255 void * a_void_p;
2256 lzo_bytep a_lzo_bytep;
2257 lzo_bytepp a_lzo_bytepp;
2258 lzo_uintp a_lzo_uintp;
2259 lzo_uint * a_lzo_uint_p;
2260 lzo_uint32p a_lzo_uint32p;
2261 lzo_uint32 * a_lzo_uint32_p;
2262 unsigned char * a_uchar_p;
2263 char * a_char_p;
2265 lzo_full_align_t;
2267 #ifdef __cplusplus
2269 #endif
2271 #endif
2273 #ifndef LZO_DETERMINISTIC
2274 #define LZO_DETERMINISTIC 1
2275 #endif
2277 #ifndef LZO_DICT_USE_PTR
2278 #define LZO_DICT_USE_PTR 1
2279 #if 0 && (LZO_ARCH_I086)
2280 # undef LZO_DICT_USE_PTR
2281 # define LZO_DICT_USE_PTR 0
2282 #endif
2283 #endif
2285 #if (LZO_DICT_USE_PTR)
2286 # define lzo_dict_t const lzo_bytep
2287 # define lzo_dict_p lzo_dict_t __LZO_MMODEL *
2288 #else
2289 # define lzo_dict_t lzo_uint
2290 # define lzo_dict_p lzo_dict_t __LZO_MMODEL *
2291 #endif
2293 #endif
2295 #if !defined(MINILZO_CFG_SKIP_LZO_PTR)
2297 LZO_PUBLIC(lzo_uintptr_t)
2298 __lzo_ptr_linear(const lzo_voidp ptr)
2300 lzo_uintptr_t p;
2302 #if (LZO_ARCH_I086)
2303 p = (((lzo_uintptr_t)(ACC_PTR_FP_SEG(ptr))) << (16 - ACC_MM_AHSHIFT)) + (ACC_PTR_FP_OFF(ptr));
2304 #elif (LZO_MM_PVP)
2305 p = (lzo_uintptr_t) (ptr);
2306 p = (p << 3) | (p >> 61);
2307 #else
2308 p = (lzo_uintptr_t) PTR_LINEAR(ptr);
2309 #endif
2311 return p;
2314 LZO_PUBLIC(unsigned)
2315 __lzo_align_gap(const lzo_voidp ptr, lzo_uint size)
2317 #if defined(__LZO_UINTPTR_T_IS_POINTER)
2318 size_t n = (size_t) ptr;
2319 n = (((n + size - 1) / size) * size) - n;
2320 #else
2321 lzo_uintptr_t p, n;
2322 p = __lzo_ptr_linear(ptr);
2323 n = (((p + size - 1) / size) * size) - p;
2324 #endif
2326 assert(size > 0);
2327 assert((long)n >= 0);
2328 assert(n <= size);
2329 return (unsigned)n;
2332 #endif
2333 #if !defined(MINILZO_CFG_SKIP_LZO_UTIL)
2335 /* If you use the LZO library in a product, I would appreciate that you
2336 * keep this copyright string in the executable of your product.
2339 static const char __lzo_copyright[] =
2340 #if !defined(__LZO_IN_MINLZO)
2341 LZO_VERSION_STRING;
2342 #else
2343 "\r\n\n"
2344 "LZO data compression library.\n"
2345 "$Copyright: LZO Copyright (C) 1996-2011 Markus Franz Xaver Johannes Oberhumer\n"
2346 "<markus@oberhumer.com>\n"
2347 "http://www.oberhumer.com $\n\n"
2348 "$Id: LZO version: v" LZO_VERSION_STRING ", " LZO_VERSION_DATE " $\n"
2349 "$Info: " LZO_INFO_STRING " $\n";
2350 #endif
2352 LZO_PUBLIC(const lzo_bytep)
2353 lzo_copyright(void)
2355 #if (LZO_OS_DOS16 && LZO_CC_TURBOC)
2356 return (lzo_voidp) __lzo_copyright;
2357 #else
2358 return (const lzo_bytep) __lzo_copyright;
2359 #endif
2362 LZO_PUBLIC(unsigned)
2363 lzo_version(void)
2365 return LZO_VERSION;
2368 LZO_PUBLIC(const char *)
2369 lzo_version_string(void)
2371 return LZO_VERSION_STRING;
2374 LZO_PUBLIC(const char *)
2375 lzo_version_date(void)
2377 return LZO_VERSION_DATE;
2380 LZO_PUBLIC(const lzo_charp)
2381 _lzo_version_string(void)
2383 return LZO_VERSION_STRING;
2386 LZO_PUBLIC(const lzo_charp)
2387 _lzo_version_date(void)
2389 return LZO_VERSION_DATE;
2392 #define LZO_BASE 65521u
2393 #define LZO_NMAX 5552
2395 #define LZO_DO1(buf,i) s1 += buf[i]; s2 += s1
2396 #define LZO_DO2(buf,i) LZO_DO1(buf,i); LZO_DO1(buf,i+1);
2397 #define LZO_DO4(buf,i) LZO_DO2(buf,i); LZO_DO2(buf,i+2);
2398 #define LZO_DO8(buf,i) LZO_DO4(buf,i); LZO_DO4(buf,i+4);
2399 #define LZO_DO16(buf,i) LZO_DO8(buf,i); LZO_DO8(buf,i+8);
2401 LZO_PUBLIC(lzo_uint32)
2402 lzo_adler32(lzo_uint32 adler, const lzo_bytep buf, lzo_uint len)
2404 lzo_uint32 s1 = adler & 0xffff;
2405 lzo_uint32 s2 = (adler >> 16) & 0xffff;
2406 unsigned k;
2408 if (buf == NULL)
2409 return 1;
2411 while (len > 0)
2413 k = len < LZO_NMAX ? (unsigned) len : LZO_NMAX;
2414 len -= k;
2415 if (k >= 16) do
2417 LZO_DO16(buf,0);
2418 buf += 16;
2419 k -= 16;
2420 } while (k >= 16);
2421 if (k != 0) do
2423 s1 += *buf++;
2424 s2 += s1;
2425 } while (--k > 0);
2426 s1 %= LZO_BASE;
2427 s2 %= LZO_BASE;
2429 return (s2 << 16) | s1;
2432 #undef LZO_DO1
2433 #undef LZO_DO2
2434 #undef LZO_DO4
2435 #undef LZO_DO8
2436 #undef LZO_DO16
2438 #endif
2439 #if !defined(MINILZO_CFG_SKIP_LZO_STRING)
2440 #undef lzo_memcmp
2441 #undef lzo_memcpy
2442 #undef lzo_memmove
2443 #undef lzo_memset
2444 #if !defined(__LZO_MMODEL_HUGE)
2445 # undef LZO_HAVE_MM_HUGE_PTR
2446 #endif
2447 #define lzo_hsize_t lzo_uint
2448 #define lzo_hvoid_p lzo_voidp
2449 #define lzo_hbyte_p lzo_bytep
2450 #define LZOLIB_PUBLIC(r,f) LZO_PUBLIC(r) f
2451 #define lzo_hmemcmp lzo_memcmp
2452 #define lzo_hmemcpy lzo_memcpy
2453 #define lzo_hmemmove lzo_memmove
2454 #define lzo_hmemset lzo_memset
2455 #define __LZOLIB_HMEMCPY_CH_INCLUDED 1
2456 #if !defined(LZOLIB_PUBLIC)
2457 # define LZOLIB_PUBLIC(r,f) r __LZOLIB_FUNCNAME(f)
2458 #endif
2459 LZOLIB_PUBLIC(int, lzo_hmemcmp) (const lzo_hvoid_p s1, const lzo_hvoid_p s2, lzo_hsize_t len)
2461 #if (LZO_HAVE_MM_HUGE_PTR) || !(HAVE_MEMCMP)
2462 const lzo_hbyte_p p1 = (const lzo_hbyte_p) s1;
2463 const lzo_hbyte_p p2 = (const lzo_hbyte_p) s2;
2464 if __lzo_likely(len > 0) do
2466 int d = *p1 - *p2;
2467 if (d != 0)
2468 return d;
2469 p1++; p2++;
2470 } while __lzo_likely(--len > 0);
2471 return 0;
2472 #else
2473 return memcmp(s1, s2, len);
2474 #endif
2476 LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemcpy) (lzo_hvoid_p dest, const lzo_hvoid_p src, lzo_hsize_t len)
2478 #if (LZO_HAVE_MM_HUGE_PTR) || !(HAVE_MEMCPY)
2479 lzo_hbyte_p p1 = (lzo_hbyte_p) dest;
2480 const lzo_hbyte_p p2 = (const lzo_hbyte_p) src;
2481 if (!(len > 0) || p1 == p2)
2482 return dest;
2484 *p1++ = *p2++;
2485 while __lzo_likely(--len > 0);
2486 return dest;
2487 #else
2488 return memcpy(dest, src, len);
2489 #endif
2491 LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemmove) (lzo_hvoid_p dest, const lzo_hvoid_p src, lzo_hsize_t len)
2493 #if (LZO_HAVE_MM_HUGE_PTR) || !(HAVE_MEMMOVE)
2494 lzo_hbyte_p p1 = (lzo_hbyte_p) dest;
2495 const lzo_hbyte_p p2 = (const lzo_hbyte_p) src;
2496 if (!(len > 0) || p1 == p2)
2497 return dest;
2498 if (p1 < p2)
2501 *p1++ = *p2++;
2502 while __lzo_likely(--len > 0);
2504 else
2506 p1 += len;
2507 p2 += len;
2509 *--p1 = *--p2;
2510 while __lzo_likely(--len > 0);
2512 return dest;
2513 #else
2514 return memmove(dest, src, len);
2515 #endif
2517 LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemset) (lzo_hvoid_p s, int c, lzo_hsize_t len)
2519 #if (LZO_HAVE_MM_HUGE_PTR) || !(HAVE_MEMSET)
2520 lzo_hbyte_p p = (lzo_hbyte_p) s;
2521 if __lzo_likely(len > 0) do
2522 *p++ = (unsigned char) c;
2523 while __lzo_likely(--len > 0);
2524 return s;
2525 #else
2526 return memset(s, c, len);
2527 #endif
2529 #undef LZOLIB_PUBLIC
2530 #endif
2531 #if !defined(MINILZO_CFG_SKIP_LZO_INIT)
2533 #if !defined(__LZO_IN_MINILZO)
2535 #define ACC_WANT_ACC_CHK_CH 1
2536 #undef ACCCHK_ASSERT
2538 ACCCHK_ASSERT_IS_SIGNED_T(lzo_int)
2539 ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint)
2541 ACCCHK_ASSERT_IS_SIGNED_T(lzo_int32)
2542 ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint32)
2543 ACCCHK_ASSERT((LZO_UINT32_C(1) << (int)(8*sizeof(LZO_UINT32_C(1))-1)) > 0)
2544 ACCCHK_ASSERT(sizeof(lzo_uint32) >= 4)
2545 #if defined(LZO_UINT64_MAX)
2546 ACCCHK_ASSERT(sizeof(lzo_uint64) == 8)
2547 ACCCHK_ASSERT_IS_SIGNED_T(lzo_int64)
2548 ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint64)
2549 #endif
2551 #if !defined(__LZO_UINTPTR_T_IS_POINTER)
2552 ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uintptr_t)
2553 #endif
2554 ACCCHK_ASSERT(sizeof(lzo_uintptr_t) >= sizeof(lzo_voidp))
2556 ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_xint)
2557 ACCCHK_ASSERT(sizeof(lzo_xint) >= sizeof(lzo_uint32))
2558 ACCCHK_ASSERT(sizeof(lzo_xint) >= sizeof(lzo_uint))
2559 ACCCHK_ASSERT(sizeof(lzo_xint) == sizeof(lzo_uint32) || sizeof(lzo_xint) == sizeof(lzo_uint))
2561 #endif
2562 #undef ACCCHK_ASSERT
2564 #define WANT_lzo_bitops_clz32 1
2565 #define WANT_lzo_bitops_clz64 1
2566 #define WANT_lzo_bitops_ctz32 1
2567 #define WANT_lzo_bitops_ctz64 1
2569 #if (defined(_WIN32) || defined(_WIN64)) && ((LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || (LZO_CC_MSC && (_MSC_VER >= 1400)))
2570 #include <intrin.h>
2571 #if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32) && 0
2572 #pragma intrinsic(_BitScanReverse)
2573 static __lzo_inline unsigned lzo_bitops_clz32(lzo_uint32 v)
2575 unsigned long r;
2576 (void) _BitScanReverse(&r, v);
2577 return (unsigned) r;
2579 #define lzo_bitops_clz32 lzo_bitops_clz32
2580 #endif
2581 #if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX) && 0
2582 #pragma intrinsic(_BitScanReverse64)
2583 static __lzo_inline unsigned lzo_bitops_clz64(lzo_uint64 v)
2585 unsigned long r;
2586 (void) _BitScanReverse64(&r, v);
2587 return (unsigned) r;
2589 #define lzo_bitops_clz64 lzo_bitops_clz64
2590 #endif
2591 #if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32)
2592 #pragma intrinsic(_BitScanForward)
2593 static __lzo_inline unsigned lzo_bitops_ctz32(lzo_uint32 v)
2595 unsigned long r;
2596 (void) _BitScanForward(&r, v);
2597 return (unsigned) r;
2599 #define lzo_bitops_ctz32 lzo_bitops_ctz32
2600 #endif
2601 #if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX)
2602 #pragma intrinsic(_BitScanForward64)
2603 static __lzo_inline unsigned lzo_bitops_ctz64(lzo_uint64 v)
2605 unsigned long r;
2606 (void) _BitScanForward64(&r, v);
2607 return (unsigned) r;
2609 #define lzo_bitops_ctz64 lzo_bitops_ctz64
2610 #endif
2612 #elif (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x030400ul) || (LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || (LZO_CC_LLVM && (!defined(__llvm_tools_version__) || (__llvm_tools_version__+0 >= 0x010500ul))))
2613 #if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32)
2614 #define lzo_bitops_clz32(v) ((unsigned) __builtin_clz(v))
2615 #endif
2616 #if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX)
2617 #define lzo_bitops_clz64(v) ((unsigned) __builtin_clzll(v))
2618 #endif
2619 #if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32)
2620 #define lzo_bitops_ctz32(v) ((unsigned) __builtin_ctz(v))
2621 #endif
2622 #if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX)
2623 #define lzo_bitops_ctz64(v) ((unsigned) __builtin_ctzll(v))
2624 #endif
2625 #if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount32)
2626 #define lzo_bitops_popcount32(v) ((unsigned) __builtin_popcount(v))
2627 #endif
2628 #if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount64) && defined(LZO_UINT64_MAX)
2629 #define lzo_bitops_popcount64(v) ((unsigned) __builtin_popcountll(v))
2630 #endif
2631 #endif
2633 #if 0
2634 #define u2p(ptr,off) ((lzo_voidp) (((lzo_bytep)(lzo_voidp)(ptr)) + (off)))
2635 #else
2636 static __lzo_noinline lzo_voidp u2p(lzo_voidp ptr, lzo_uint off)
2638 return (lzo_voidp) ((lzo_bytep) ptr + off);
2640 #endif
2642 LZO_PUBLIC(int)
2643 _lzo_config_check(void)
2645 lzo_bool r = 1;
2646 union {
2647 lzo_xint a[2]; unsigned char b[2*LZO_MAX(8,sizeof(lzo_xint))];
2648 #if defined(LZO_UNALIGNED_OK_8)
2649 lzo_uint64 c[2];
2650 #endif
2651 unsigned short x[2]; lzo_uint32 y[2]; lzo_uint z[2];
2652 } u;
2653 lzo_voidp p;
2655 u.a[0] = u.a[1] = 0;
2656 p = u2p(&u, 0);
2657 r &= ((* (lzo_bytep) p) == 0);
2658 #if !defined(LZO_CFG_NO_CONFIG_CHECK)
2659 #if defined(LZO_ABI_BIG_ENDIAN)
2660 u.a[0] = u.a[1] = 0; u.b[sizeof(lzo_uint) - 1] = 128;
2661 p = u2p(&u, 0);
2662 r &= ((* (lzo_uintp) p) == 128);
2663 #endif
2664 #if defined(LZO_ABI_LITTLE_ENDIAN)
2665 u.a[0] = u.a[1] = 0; u.b[0] = 128;
2666 p = u2p(&u, 0);
2667 r &= ((* (lzo_uintp) p) == 128);
2668 #endif
2669 #if defined(LZO_UNALIGNED_OK_2)
2670 u.a[0] = u.a[1] = 0;
2671 u.b[0] = 1; u.b[sizeof(unsigned short) + 1] = 2;
2672 p = u2p(&u, 1);
2673 r &= ((* (lzo_ushortp) p) == 0);
2674 #endif
2675 #if defined(LZO_UNALIGNED_OK_4)
2676 u.a[0] = u.a[1] = 0;
2677 u.b[0] = 3; u.b[sizeof(lzo_uint32) + 1] = 4;
2678 p = u2p(&u, 1);
2679 r &= ((* (lzo_uint32p) p) == 0);
2680 #endif
2681 #if defined(LZO_UNALIGNED_OK_8)
2682 u.c[0] = u.c[1] = 0;
2683 u.b[0] = 5; u.b[sizeof(lzo_uint64) + 1] = 6;
2684 p = u2p(&u, 1);
2685 r &= ((* (lzo_uint64p) p) == 0);
2686 #endif
2687 #if defined(lzo_bitops_clz32)
2688 { unsigned i; lzo_uint32 v = 1;
2689 for (i = 0; i < 32; i++, v <<= 1)
2690 r &= lzo_bitops_clz32(v) == 31 - i;
2692 #endif
2693 #if defined(lzo_bitops_clz64)
2694 { unsigned i; lzo_uint64 v = 1;
2695 for (i = 0; i < 64; i++, v <<= 1)
2696 r &= lzo_bitops_clz64(v) == 63 - i;
2698 #endif
2699 #if defined(lzo_bitops_ctz32)
2700 { unsigned i; lzo_uint32 v = 1;
2701 for (i = 0; i < 32; i++, v <<= 1)
2702 r &= lzo_bitops_ctz32(v) == i;
2704 #endif
2705 #if defined(lzo_bitops_ctz64)
2706 { unsigned i; lzo_uint64 v = 1;
2707 for (i = 0; i < 64; i++, v <<= 1)
2708 r &= lzo_bitops_ctz64(v) == i;
2710 #endif
2711 #endif
2713 return r == 1 ? LZO_E_OK : LZO_E_ERROR;
2716 LZO_PUBLIC(int)
2717 __lzo_init_v2(unsigned v, int s1, int s2, int s3, int s4, int s5,
2718 int s6, int s7, int s8, int s9)
2720 int r;
2722 #if defined(__LZO_IN_MINILZO)
2723 #elif (LZO_CC_MSC && ((_MSC_VER) < 700))
2724 #else
2725 #define ACC_WANT_ACC_CHK_CH 1
2726 #undef ACCCHK_ASSERT
2727 #define ACCCHK_ASSERT(expr) LZO_COMPILE_TIME_ASSERT(expr)
2728 #endif
2729 #undef ACCCHK_ASSERT
2731 if (v == 0)
2732 return LZO_E_ERROR;
2734 r = (s1 == -1 || s1 == (int) sizeof(short)) &&
2735 (s2 == -1 || s2 == (int) sizeof(int)) &&
2736 (s3 == -1 || s3 == (int) sizeof(long)) &&
2737 (s4 == -1 || s4 == (int) sizeof(lzo_uint32)) &&
2738 (s5 == -1 || s5 == (int) sizeof(lzo_uint)) &&
2739 (s6 == -1 || s6 == (int) lzo_sizeof_dict_t) &&
2740 (s7 == -1 || s7 == (int) sizeof(char *)) &&
2741 (s8 == -1 || s8 == (int) sizeof(lzo_voidp)) &&
2742 (s9 == -1 || s9 == (int) sizeof(lzo_callback_t));
2743 if (!r)
2744 return LZO_E_ERROR;
2746 r = _lzo_config_check();
2747 if (r != LZO_E_OK)
2748 return r;
2750 return r;
2753 #if !defined(__LZO_IN_MINILZO)
2755 #if (LZO_OS_WIN16 && LZO_CC_WATCOMC) && defined(__SW_BD)
2757 #if 0
2758 BOOL FAR PASCAL LibMain ( HANDLE hInstance, WORD wDataSegment,
2759 WORD wHeapSize, LPSTR lpszCmdLine )
2760 #else
2761 int __far __pascal LibMain ( int a, short b, short c, long d )
2762 #endif
2764 LZO_UNUSED(a); LZO_UNUSED(b); LZO_UNUSED(c); LZO_UNUSED(d);
2765 return 1;
2768 #endif
2770 #endif
2772 #endif
2774 #define LZO1X 1
2775 #define LZO_EOF_CODE 1
2776 #define M2_MAX_OFFSET 0x0800
2778 #if !defined(MINILZO_CFG_SKIP_LZO1X_1_COMPRESS)
2780 #if 1 && defined(UA_GET32)
2781 #undef LZO_DICT_USE_PTR
2782 #define LZO_DICT_USE_PTR 0
2783 #undef lzo_dict_t
2784 #define lzo_dict_t unsigned short
2785 #endif
2787 #define LZO_NEED_DICT_H 1
2788 #ifndef D_BITS
2789 #define D_BITS 14
2790 #endif
2791 #define D_INDEX1(d,p) d = DM(DMUL(0x21,DX3(p,5,5,6)) >> 5)
2792 #define D_INDEX2(d,p) d = (d & (D_MASK & 0x7ff)) ^ (D_HIGH | 0x1f)
2793 #if 1
2794 #define DINDEX(dv,p) DM(((DMUL(0x1824429d,dv)) >> (32-D_BITS)))
2795 #else
2796 #define DINDEX(dv,p) DM((dv) + ((dv) >> (32-D_BITS)))
2797 #endif
2799 #ifndef __LZO_CONFIG1X_H
2800 #define __LZO_CONFIG1X_H 1
2802 #if !defined(LZO1X) && !defined(LZO1Y) && !defined(LZO1Z)
2803 # define LZO1X 1
2804 #endif
2806 #if !defined(__LZO_IN_MINILZO)
2807 #include "lzo/lzo1x.h"
2808 #endif
2810 #ifndef LZO_EOF_CODE
2811 #define LZO_EOF_CODE 1
2812 #endif
2813 #undef LZO_DETERMINISTIC
2815 #define M1_MAX_OFFSET 0x0400
2816 #ifndef M2_MAX_OFFSET
2817 #define M2_MAX_OFFSET 0x0800
2818 #endif
2819 #define M3_MAX_OFFSET 0x4000
2820 #define M4_MAX_OFFSET 0xbfff
2822 #define MX_MAX_OFFSET (M1_MAX_OFFSET + M2_MAX_OFFSET)
2824 #define M1_MIN_LEN 2
2825 #define M1_MAX_LEN 2
2826 #define M2_MIN_LEN 3
2827 #ifndef M2_MAX_LEN
2828 #define M2_MAX_LEN 8
2829 #endif
2830 #define M3_MIN_LEN 3
2831 #define M3_MAX_LEN 33
2832 #define M4_MIN_LEN 3
2833 #define M4_MAX_LEN 9
2835 #define M1_MARKER 0
2836 #define M2_MARKER 64
2837 #define M3_MARKER 32
2838 #define M4_MARKER 16
2840 #ifndef MIN_LOOKAHEAD
2841 #define MIN_LOOKAHEAD (M2_MAX_LEN + 1)
2842 #endif
2844 #if defined(LZO_NEED_DICT_H)
2846 #ifndef LZO_HASH
2847 #define LZO_HASH LZO_HASH_LZO_INCREMENTAL_B
2848 #endif
2849 #define DL_MIN_LEN M2_MIN_LEN
2851 #ifndef __LZO_DICT_H
2852 #define __LZO_DICT_H 1
2854 #ifdef __cplusplus
2855 extern "C" {
2856 #endif
2858 #if !defined(D_BITS) && defined(DBITS)
2859 # define D_BITS DBITS
2860 #endif
2861 #if !defined(D_BITS)
2862 # error "D_BITS is not defined"
2863 #endif
2864 #if (D_BITS < 16)
2865 # define D_SIZE LZO_SIZE(D_BITS)
2866 # define D_MASK LZO_MASK(D_BITS)
2867 #else
2868 # define D_SIZE LZO_USIZE(D_BITS)
2869 # define D_MASK LZO_UMASK(D_BITS)
2870 #endif
2871 #define D_HIGH ((D_MASK >> 1) + 1)
2873 #if !defined(DD_BITS)
2874 # define DD_BITS 0
2875 #endif
2876 #define DD_SIZE LZO_SIZE(DD_BITS)
2877 #define DD_MASK LZO_MASK(DD_BITS)
2879 #if !defined(DL_BITS)
2880 # define DL_BITS (D_BITS - DD_BITS)
2881 #endif
2882 #if (DL_BITS < 16)
2883 # define DL_SIZE LZO_SIZE(DL_BITS)
2884 # define DL_MASK LZO_MASK(DL_BITS)
2885 #else
2886 # define DL_SIZE LZO_USIZE(DL_BITS)
2887 # define DL_MASK LZO_UMASK(DL_BITS)
2888 #endif
2890 #if (D_BITS != DL_BITS + DD_BITS)
2891 # error "D_BITS does not match"
2892 #endif
2893 #if (D_BITS < 6 || D_BITS > 18)
2894 # error "invalid D_BITS"
2895 #endif
2896 #if (DL_BITS < 6 || DL_BITS > 20)
2897 # error "invalid DL_BITS"
2898 #endif
2899 #if (DD_BITS < 0 || DD_BITS > 6)
2900 # error "invalid DD_BITS"
2901 #endif
2903 #if !defined(DL_MIN_LEN)
2904 # define DL_MIN_LEN 3
2905 #endif
2906 #if !defined(DL_SHIFT)
2907 # define DL_SHIFT ((DL_BITS + (DL_MIN_LEN - 1)) / DL_MIN_LEN)
2908 #endif
2910 #define LZO_HASH_GZIP 1
2911 #define LZO_HASH_GZIP_INCREMENTAL 2
2912 #define LZO_HASH_LZO_INCREMENTAL_A 3
2913 #define LZO_HASH_LZO_INCREMENTAL_B 4
2915 #if !defined(LZO_HASH)
2916 # error "choose a hashing strategy"
2917 #endif
2919 #undef DM
2920 #undef DX
2922 #if (DL_MIN_LEN == 3)
2923 # define _DV2_A(p,shift1,shift2) \
2924 (((( (lzo_xint)((p)[0]) << shift1) ^ (p)[1]) << shift2) ^ (p)[2])
2925 # define _DV2_B(p,shift1,shift2) \
2926 (((( (lzo_xint)((p)[2]) << shift1) ^ (p)[1]) << shift2) ^ (p)[0])
2927 # define _DV3_B(p,shift1,shift2,shift3) \
2928 ((_DV2_B((p)+1,shift1,shift2) << (shift3)) ^ (p)[0])
2929 #elif (DL_MIN_LEN == 2)
2930 # define _DV2_A(p,shift1,shift2) \
2931 (( (lzo_xint)(p[0]) << shift1) ^ p[1])
2932 # define _DV2_B(p,shift1,shift2) \
2933 (( (lzo_xint)(p[1]) << shift1) ^ p[2])
2934 #else
2935 # error "invalid DL_MIN_LEN"
2936 #endif
2937 #define _DV_A(p,shift) _DV2_A(p,shift,shift)
2938 #define _DV_B(p,shift) _DV2_B(p,shift,shift)
2939 #define DA2(p,s1,s2) \
2940 (((((lzo_xint)((p)[2]) << (s2)) + (p)[1]) << (s1)) + (p)[0])
2941 #define DS2(p,s1,s2) \
2942 (((((lzo_xint)((p)[2]) << (s2)) - (p)[1]) << (s1)) - (p)[0])
2943 #define DX2(p,s1,s2) \
2944 (((((lzo_xint)((p)[2]) << (s2)) ^ (p)[1]) << (s1)) ^ (p)[0])
2945 #define DA3(p,s1,s2,s3) ((DA2((p)+1,s2,s3) << (s1)) + (p)[0])
2946 #define DS3(p,s1,s2,s3) ((DS2((p)+1,s2,s3) << (s1)) - (p)[0])
2947 #define DX3(p,s1,s2,s3) ((DX2((p)+1,s2,s3) << (s1)) ^ (p)[0])
2948 #define DMS(v,s) ((lzo_uint) (((v) & (D_MASK >> (s))) << (s)))
2949 #define DM(v) DMS(v,0)
2951 #if (LZO_HASH == LZO_HASH_GZIP)
2952 # define _DINDEX(dv,p) (_DV_A((p),DL_SHIFT))
2954 #elif (LZO_HASH == LZO_HASH_GZIP_INCREMENTAL)
2955 # define __LZO_HASH_INCREMENTAL 1
2956 # define DVAL_FIRST(dv,p) dv = _DV_A((p),DL_SHIFT)
2957 # define DVAL_NEXT(dv,p) dv = (((dv) << DL_SHIFT) ^ p[2])
2958 # define _DINDEX(dv,p) (dv)
2959 # define DVAL_LOOKAHEAD DL_MIN_LEN
2961 #elif (LZO_HASH == LZO_HASH_LZO_INCREMENTAL_A)
2962 # define __LZO_HASH_INCREMENTAL 1
2963 # define DVAL_FIRST(dv,p) dv = _DV_A((p),5)
2964 # define DVAL_NEXT(dv,p) \
2965 dv ^= (lzo_xint)(p[-1]) << (2*5); dv = (((dv) << 5) ^ p[2])
2966 # define _DINDEX(dv,p) ((DMUL(0x9f5f,dv)) >> 5)
2967 # define DVAL_LOOKAHEAD DL_MIN_LEN
2969 #elif (LZO_HASH == LZO_HASH_LZO_INCREMENTAL_B)
2970 # define __LZO_HASH_INCREMENTAL 1
2971 # define DVAL_FIRST(dv,p) dv = _DV_B((p),5)
2972 # define DVAL_NEXT(dv,p) \
2973 dv ^= p[-1]; dv = (((dv) >> 5) ^ ((lzo_xint)(p[2]) << (2*5)))
2974 # define _DINDEX(dv,p) ((DMUL(0x9f5f,dv)) >> 5)
2975 # define DVAL_LOOKAHEAD DL_MIN_LEN
2977 #else
2978 # error "choose a hashing strategy"
2979 #endif
2981 #ifndef DINDEX
2982 #define DINDEX(dv,p) ((lzo_uint)((_DINDEX(dv,p)) & DL_MASK) << DD_BITS)
2983 #endif
2984 #if !defined(DINDEX1) && defined(D_INDEX1)
2985 #define DINDEX1 D_INDEX1
2986 #endif
2987 #if !defined(DINDEX2) && defined(D_INDEX2)
2988 #define DINDEX2 D_INDEX2
2989 #endif
2991 #if !defined(__LZO_HASH_INCREMENTAL)
2992 # define DVAL_FIRST(dv,p) ((void) 0)
2993 # define DVAL_NEXT(dv,p) ((void) 0)
2994 # define DVAL_LOOKAHEAD 0
2995 #endif
2997 #if !defined(DVAL_ASSERT)
2998 #if defined(__LZO_HASH_INCREMENTAL) && !defined(NDEBUG)
2999 #if (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x020700ul) || LZO_CC_LLVM)
3000 static void __attribute__((__unused__))
3001 #else
3002 static void
3003 #endif
3004 DVAL_ASSERT(lzo_xint dv, const lzo_bytep p)
3006 lzo_xint df;
3007 DVAL_FIRST(df,(p));
3008 assert(DINDEX(dv,p) == DINDEX(df,p));
3010 #else
3011 # define DVAL_ASSERT(dv,p) ((void) 0)
3012 #endif
3013 #endif
3015 #if (LZO_DICT_USE_PTR)
3016 # define DENTRY(p,in) (p)
3017 # define GINDEX(m_pos,m_off,dict,dindex,in) m_pos = dict[dindex]
3018 #else
3019 # define DENTRY(p,in) ((lzo_dict_t) pd(p, in))
3020 # define GINDEX(m_pos,m_off,dict,dindex,in) m_off = dict[dindex]
3021 #endif
3023 #if (DD_BITS == 0)
3025 # define UPDATE_D(dict,drun,dv,p,in) dict[ DINDEX(dv,p) ] = DENTRY(p,in)
3026 # define UPDATE_I(dict,drun,index,p,in) dict[index] = DENTRY(p,in)
3027 # define UPDATE_P(ptr,drun,p,in) (ptr)[0] = DENTRY(p,in)
3029 #else
3031 # define UPDATE_D(dict,drun,dv,p,in) \
3032 dict[ DINDEX(dv,p) + drun++ ] = DENTRY(p,in); drun &= DD_MASK
3033 # define UPDATE_I(dict,drun,index,p,in) \
3034 dict[ (index) + drun++ ] = DENTRY(p,in); drun &= DD_MASK
3035 # define UPDATE_P(ptr,drun,p,in) \
3036 (ptr) [ drun++ ] = DENTRY(p,in); drun &= DD_MASK
3038 #endif
3040 #if (LZO_DICT_USE_PTR)
3042 #define LZO_CHECK_MPOS_DET(m_pos,m_off,in,ip,max_offset) \
3043 (m_pos == NULL || (m_off = pd(ip, m_pos)) > max_offset)
3045 #define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \
3046 (BOUNDS_CHECKING_OFF_IN_EXPR(( \
3047 m_pos = ip - (lzo_uint) PTR_DIFF(ip,m_pos), \
3048 PTR_LT(m_pos,in) || \
3049 (m_off = (lzo_uint) PTR_DIFF(ip,m_pos)) == 0 || \
3050 m_off > max_offset )))
3052 #else
3054 #define LZO_CHECK_MPOS_DET(m_pos,m_off,in,ip,max_offset) \
3055 (m_off == 0 || \
3056 ((m_off = pd(ip, in) - m_off) > max_offset) || \
3057 (m_pos = (ip) - (m_off), 0) )
3059 #define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \
3060 (pd(ip, in) <= m_off || \
3061 ((m_off = pd(ip, in) - m_off) > max_offset) || \
3062 (m_pos = (ip) - (m_off), 0) )
3064 #endif
3066 #if (LZO_DETERMINISTIC)
3067 # define LZO_CHECK_MPOS LZO_CHECK_MPOS_DET
3068 #else
3069 # define LZO_CHECK_MPOS LZO_CHECK_MPOS_NON_DET
3070 #endif
3072 #ifdef __cplusplus
3074 #endif
3076 #endif
3078 #endif
3080 #endif
3082 #define LZO_DETERMINISTIC !(LZO_DICT_USE_PTR)
3084 #ifndef DO_COMPRESS
3085 #define DO_COMPRESS lzo1x_1_compress
3086 #endif
3088 #if 1 && defined(DO_COMPRESS) && !defined(do_compress)
3089 # define do_compress LZO_CPP_ECONCAT2(DO_COMPRESS,_core)
3090 #endif
3092 #if defined(UA_GET64) && (LZO_ABI_BIG_ENDIAN)
3093 # define WANT_lzo_bitops_clz64 1
3094 #elif defined(UA_GET64) && (LZO_ABI_LITTLE_ENDIAN)
3095 # define WANT_lzo_bitops_ctz64 1
3096 #elif defined(UA_GET32) && (LZO_ABI_BIG_ENDIAN)
3097 # define WANT_lzo_bitops_clz32 1
3098 #elif defined(UA_GET32) && (LZO_ABI_LITTLE_ENDIAN)
3099 # define WANT_lzo_bitops_ctz32 1
3100 #endif
3102 #if (defined(_WIN32) || defined(_WIN64)) && ((LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || (LZO_CC_MSC && (_MSC_VER >= 1400)))
3103 #include <intrin.h>
3104 #if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32) && 0
3105 #pragma intrinsic(_BitScanReverse)
3106 static __lzo_inline unsigned lzo_bitops_clz32(lzo_uint32 v)
3108 unsigned long r;
3109 (void) _BitScanReverse(&r, v);
3110 return (unsigned) r;
3112 #define lzo_bitops_clz32 lzo_bitops_clz32
3113 #endif
3114 #if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX) && 0
3115 #pragma intrinsic(_BitScanReverse64)
3116 static __lzo_inline unsigned lzo_bitops_clz64(lzo_uint64 v)
3118 unsigned long r;
3119 (void) _BitScanReverse64(&r, v);
3120 return (unsigned) r;
3122 #define lzo_bitops_clz64 lzo_bitops_clz64
3123 #endif
3124 #if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32)
3125 #pragma intrinsic(_BitScanForward)
3126 static __lzo_inline unsigned lzo_bitops_ctz32(lzo_uint32 v)
3128 unsigned long r;
3129 (void) _BitScanForward(&r, v);
3130 return (unsigned) r;
3132 #define lzo_bitops_ctz32 lzo_bitops_ctz32
3133 #endif
3134 #if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX)
3135 #pragma intrinsic(_BitScanForward64)
3136 static __lzo_inline unsigned lzo_bitops_ctz64(lzo_uint64 v)
3138 unsigned long r;
3139 (void) _BitScanForward64(&r, v);
3140 return (unsigned) r;
3142 #define lzo_bitops_ctz64 lzo_bitops_ctz64
3143 #endif
3145 #elif (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x030400ul) || (LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || (LZO_CC_LLVM && (!defined(__llvm_tools_version__) || (__llvm_tools_version__+0 >= 0x010500ul))))
3146 #if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32)
3147 #define lzo_bitops_clz32(v) ((unsigned) __builtin_clz(v))
3148 #endif
3149 #if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX)
3150 #define lzo_bitops_clz64(v) ((unsigned) __builtin_clzll(v))
3151 #endif
3152 #if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32)
3153 #define lzo_bitops_ctz32(v) ((unsigned) __builtin_ctz(v))
3154 #endif
3155 #if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX)
3156 #define lzo_bitops_ctz64(v) ((unsigned) __builtin_ctzll(v))
3157 #endif
3158 #if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount32)
3159 #define lzo_bitops_popcount32(v) ((unsigned) __builtin_popcount(v))
3160 #endif
3161 #if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount64) && defined(LZO_UINT64_MAX)
3162 #define lzo_bitops_popcount64(v) ((unsigned) __builtin_popcountll(v))
3163 #endif
3164 #endif
3166 static __lzo_noinline lzo_uint
3167 do_compress ( const lzo_bytep in , lzo_uint in_len,
3168 lzo_bytep out, lzo_uintp out_len,
3169 lzo_uint ti, lzo_voidp wrkmem)
3171 register const lzo_bytep ip;
3172 lzo_bytep op;
3173 const lzo_bytep const in_end = in + in_len;
3174 const lzo_bytep const ip_end = in + in_len - 20;
3175 const lzo_bytep ii;
3176 lzo_dict_p const dict = (lzo_dict_p) wrkmem;
3178 op = out;
3179 ip = in;
3180 ii = ip;
3182 ip += ti < 4 ? 4 - ti : 0;
3183 for (;;)
3185 const lzo_bytep m_pos;
3186 #if !(LZO_DETERMINISTIC)
3187 LZO_DEFINE_UNINITIALIZED_VAR(lzo_uint, m_off, 0);
3188 lzo_uint m_len;
3189 lzo_uint dindex;
3190 next:
3191 if __lzo_unlikely(ip >= ip_end)
3192 break;
3193 DINDEX1(dindex,ip);
3194 GINDEX(m_pos,m_off,dict,dindex,in);
3195 if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET))
3196 goto literal;
3197 #if 1
3198 if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
3199 goto try_match;
3200 DINDEX2(dindex,ip);
3201 #endif
3202 GINDEX(m_pos,m_off,dict,dindex,in);
3203 if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET))
3204 goto literal;
3205 if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
3206 goto try_match;
3207 goto literal;
3209 try_match:
3210 #if defined(UA_GET32)
3211 if (UA_GET32(m_pos) != UA_GET32(ip))
3212 #else
3213 if (m_pos[0] != ip[0] || m_pos[1] != ip[1] || m_pos[2] != ip[2] || m_pos[3] != ip[3])
3214 #endif
3216 literal:
3217 UPDATE_I(dict,0,dindex,ip,in);
3218 ip += 1 + ((ip - ii) >> 5);
3219 continue;
3221 UPDATE_I(dict,0,dindex,ip,in);
3222 #else
3223 lzo_uint m_off;
3224 lzo_uint m_len;
3226 lzo_uint32 dv;
3227 lzo_uint dindex;
3228 literal:
3229 ip += 1 + ((ip - ii) >> 5);
3230 next:
3231 if __lzo_unlikely(ip >= ip_end)
3232 break;
3233 dv = UA_GET32(ip);
3234 dindex = DINDEX(dv,ip);
3235 GINDEX(m_off,m_pos,in+dict,dindex,in);
3236 UPDATE_I(dict,0,dindex,ip,in);
3237 if __lzo_unlikely(dv != UA_GET32(m_pos))
3238 goto literal;
3240 #endif
3242 ii -= ti; ti = 0;
3244 register lzo_uint t = pd(ip,ii);
3245 if (t != 0)
3247 if (t <= 3)
3249 op[-2] |= LZO_BYTE(t);
3250 #if defined(UA_COPY32)
3251 UA_COPY32(op, ii);
3252 op += t;
3253 #else
3254 { do *op++ = *ii++; while (--t > 0); }
3255 #endif
3257 #if defined(UA_COPY32) || defined(UA_COPY64)
3258 else if (t <= 16)
3260 *op++ = LZO_BYTE(t - 3);
3261 #if defined(UA_COPY64)
3262 UA_COPY64(op, ii);
3263 UA_COPY64(op+8, ii+8);
3264 #else
3265 UA_COPY32(op, ii);
3266 UA_COPY32(op+4, ii+4);
3267 UA_COPY32(op+8, ii+8);
3268 UA_COPY32(op+12, ii+12);
3269 #endif
3270 op += t;
3272 #endif
3273 else
3275 if (t <= 18)
3276 *op++ = LZO_BYTE(t - 3);
3277 else
3279 register lzo_uint tt = t - 18;
3280 *op++ = 0;
3281 while __lzo_unlikely(tt > 255)
3283 tt -= 255;
3284 #if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400))
3285 * (volatile unsigned char *) op++ = 0;
3286 #else
3287 *op++ = 0;
3288 #endif
3290 assert(tt > 0);
3291 *op++ = LZO_BYTE(tt);
3293 #if defined(UA_COPY32) || defined(UA_COPY64)
3294 do {
3295 #if defined(UA_COPY64)
3296 UA_COPY64(op, ii);
3297 UA_COPY64(op+8, ii+8);
3298 #else
3299 UA_COPY32(op, ii);
3300 UA_COPY32(op+4, ii+4);
3301 UA_COPY32(op+8, ii+8);
3302 UA_COPY32(op+12, ii+12);
3303 #endif
3304 op += 16; ii += 16; t -= 16;
3305 } while (t >= 16); if (t > 0)
3306 #endif
3307 { do *op++ = *ii++; while (--t > 0); }
3311 m_len = 4;
3313 #if defined(UA_GET64)
3314 lzo_uint64 v;
3315 v = UA_GET64(ip + m_len) ^ UA_GET64(m_pos + m_len);
3316 if __lzo_unlikely(v == 0) {
3317 do {
3318 m_len += 8;
3319 v = UA_GET64(ip + m_len) ^ UA_GET64(m_pos + m_len);
3320 if __lzo_unlikely(ip + m_len >= ip_end)
3321 goto m_len_done;
3322 } while (v == 0);
3324 #if (LZO_ABI_BIG_ENDIAN) && defined(lzo_bitops_clz64)
3325 m_len += lzo_bitops_clz64(v) / CHAR_BIT;
3326 #elif (LZO_ABI_BIG_ENDIAN)
3327 if ((v >> (64 - CHAR_BIT)) == 0) do {
3328 v <<= CHAR_BIT;
3329 m_len += 1;
3330 } while ((v >> (64 - CHAR_BIT)) == 0);
3331 #elif (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_ctz64)
3332 m_len += lzo_bitops_ctz64(v) / CHAR_BIT;
3333 #elif (LZO_ABI_LITTLE_ENDIAN)
3334 if ((v & UCHAR_MAX) == 0) do {
3335 v >>= CHAR_BIT;
3336 m_len += 1;
3337 } while ((v & UCHAR_MAX) == 0);
3338 #else
3339 if (ip[m_len] == m_pos[m_len]) do {
3340 m_len += 1;
3341 } while (ip[m_len] == m_pos[m_len]);
3342 #endif
3343 #elif defined(UA_GET32)
3344 lzo_uint32 v;
3345 v = UA_GET32(ip + m_len) ^ UA_GET32(m_pos + m_len);
3346 if __lzo_unlikely(v == 0) {
3347 do {
3348 m_len += 4;
3349 v = UA_GET32(ip + m_len) ^ UA_GET32(m_pos + m_len);
3350 if __lzo_unlikely(ip + m_len >= ip_end)
3351 goto m_len_done;
3352 } while (v == 0);
3354 #if (LZO_ABI_BIG_ENDIAN) && defined(lzo_bitops_clz32)
3355 m_len += lzo_bitops_clz32(v) / CHAR_BIT;
3356 #elif (LZO_ABI_BIG_ENDIAN)
3357 if ((v >> (32 - CHAR_BIT)) == 0) do {
3358 v <<= CHAR_BIT;
3359 m_len += 1;
3360 } while ((v >> (32 - CHAR_BIT)) == 0);
3361 #elif (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_ctz32)
3362 m_len += lzo_bitops_ctz32(v) / CHAR_BIT;
3363 #elif (LZO_ABI_LITTLE_ENDIAN)
3364 if ((v & UCHAR_MAX) == 0) do {
3365 v >>= CHAR_BIT;
3366 m_len += 1;
3367 } while ((v & UCHAR_MAX) == 0);
3368 #else
3369 if (ip[m_len] == m_pos[m_len]) do {
3370 m_len += 1;
3371 } while (ip[m_len] == m_pos[m_len]);
3372 #endif
3373 #else
3374 if __lzo_unlikely(ip[m_len] == m_pos[m_len]) {
3375 do {
3376 m_len += 1;
3377 if __lzo_unlikely(ip + m_len >= ip_end)
3378 goto m_len_done;
3379 } while (ip[m_len] == m_pos[m_len]);
3381 #endif
3383 m_len_done:
3384 m_off = pd(ip,m_pos);
3385 ip += m_len;
3386 ii = ip;
3387 if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
3389 m_off -= 1;
3390 #if defined(LZO1X)
3391 *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2));
3392 *op++ = LZO_BYTE(m_off >> 3);
3393 #elif defined(LZO1Y)
3394 *op++ = LZO_BYTE(((m_len + 1) << 4) | ((m_off & 3) << 2));
3395 *op++ = LZO_BYTE(m_off >> 2);
3396 #endif
3398 else if (m_off <= M3_MAX_OFFSET)
3400 m_off -= 1;
3401 if (m_len <= M3_MAX_LEN)
3402 *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
3403 else
3405 m_len -= M3_MAX_LEN;
3406 *op++ = M3_MARKER | 0;
3407 while __lzo_unlikely(m_len > 255)
3409 m_len -= 255;
3410 #if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400))
3411 * (volatile unsigned char *) op++ = 0;
3412 #else
3413 *op++ = 0;
3414 #endif
3416 *op++ = LZO_BYTE(m_len);
3418 *op++ = LZO_BYTE(m_off << 2);
3419 *op++ = LZO_BYTE(m_off >> 6);
3421 else
3423 m_off -= 0x4000;
3424 if (m_len <= M4_MAX_LEN)
3425 *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8) | (m_len - 2));
3426 else
3428 m_len -= M4_MAX_LEN;
3429 *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8));
3430 while __lzo_unlikely(m_len > 255)
3432 m_len -= 255;
3433 #if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400))
3434 * (volatile unsigned char *) op++ = 0;
3435 #else
3436 *op++ = 0;
3437 #endif
3439 *op++ = LZO_BYTE(m_len);
3441 *op++ = LZO_BYTE(m_off << 2);
3442 *op++ = LZO_BYTE(m_off >> 6);
3444 goto next;
3447 *out_len = pd(op, out);
3448 return pd(in_end,ii-ti);
3451 LZO_PUBLIC(int)
3452 DO_COMPRESS ( const lzo_bytep in , lzo_uint in_len,
3453 lzo_bytep out, lzo_uintp out_len,
3454 lzo_voidp wrkmem )
3456 const lzo_bytep ip = in;
3457 lzo_bytep op = out;
3458 lzo_uint l = in_len;
3459 lzo_uint t = 0;
3461 while (l > 20)
3463 lzo_uint ll = l;
3464 lzo_uintptr_t ll_end;
3465 #if 0 || (LZO_DETERMINISTIC)
3466 ll = LZO_MIN(ll, 49152);
3467 #endif
3468 ll_end = (lzo_uintptr_t)ip + ll;
3469 if ((ll_end + ((t + ll) >> 5)) <= ll_end || (const lzo_bytep)(ll_end + ((t + ll) >> 5)) <= ip + ll)
3470 break;
3471 #if (LZO_DETERMINISTIC)
3472 lzo_memset(wrkmem, 0, ((lzo_uint)1 << D_BITS) * sizeof(lzo_dict_t));
3473 #endif
3474 t = do_compress(ip,ll,op,out_len,t,wrkmem);
3475 ip += ll;
3476 op += *out_len;
3477 l -= ll;
3479 t += l;
3481 if (t > 0)
3483 const lzo_bytep ii = in + in_len - t;
3485 if (op == out && t <= 238)
3486 *op++ = LZO_BYTE(17 + t);
3487 else if (t <= 3)
3488 op[-2] |= LZO_BYTE(t);
3489 else if (t <= 18)
3490 *op++ = LZO_BYTE(t - 3);
3491 else
3493 lzo_uint tt = t - 18;
3495 *op++ = 0;
3496 while (tt > 255)
3498 tt -= 255;
3499 #if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400))
3501 * (volatile unsigned char *) op++ = 0;
3502 #else
3503 *op++ = 0;
3504 #endif
3506 assert(tt > 0);
3507 *op++ = LZO_BYTE(tt);
3509 do *op++ = *ii++; while (--t > 0);
3512 *op++ = M4_MARKER | 1;
3513 *op++ = 0;
3514 *op++ = 0;
3516 *out_len = pd(op, out);
3517 return LZO_E_OK;
3520 #endif
3522 #undef do_compress
3523 #undef DO_COMPRESS
3524 #undef LZO_HASH
3526 #undef LZO_TEST_OVERRUN
3527 #undef DO_DECOMPRESS
3528 #define DO_DECOMPRESS lzo1x_decompress
3530 #if !defined(MINILZO_CFG_SKIP_LZO1X_DECOMPRESS)
3532 #if defined(LZO_TEST_OVERRUN)
3533 # if !defined(LZO_TEST_OVERRUN_INPUT)
3534 # define LZO_TEST_OVERRUN_INPUT 2
3535 # endif
3536 # if !defined(LZO_TEST_OVERRUN_OUTPUT)
3537 # define LZO_TEST_OVERRUN_OUTPUT 2
3538 # endif
3539 # if !defined(LZO_TEST_OVERRUN_LOOKBEHIND)
3540 # define LZO_TEST_OVERRUN_LOOKBEHIND 1
3541 # endif
3542 #endif
3544 #undef TEST_IP
3545 #undef TEST_OP
3546 #undef TEST_LB
3547 #undef TEST_LBO
3548 #undef NEED_IP
3549 #undef NEED_OP
3550 #undef HAVE_TEST_IP
3551 #undef HAVE_TEST_OP
3552 #undef HAVE_NEED_IP
3553 #undef HAVE_NEED_OP
3554 #undef HAVE_ANY_IP
3555 #undef HAVE_ANY_OP
3557 #if defined(LZO_TEST_OVERRUN_INPUT)
3558 # if (LZO_TEST_OVERRUN_INPUT >= 1)
3559 # define TEST_IP (ip < ip_end)
3560 # endif
3561 # if (LZO_TEST_OVERRUN_INPUT >= 2)
3562 # define NEED_IP(x) \
3563 if ((lzo_uint)(ip_end - ip) < (lzo_uint)(x)) goto input_overrun
3564 # endif
3565 #endif
3567 #if defined(LZO_TEST_OVERRUN_OUTPUT)
3568 # if (LZO_TEST_OVERRUN_OUTPUT >= 1)
3569 # define TEST_OP (op <= op_end)
3570 # endif
3571 # if (LZO_TEST_OVERRUN_OUTPUT >= 2)
3572 # undef TEST_OP
3573 # define NEED_OP(x) \
3574 if ((lzo_uint)(op_end - op) < (lzo_uint)(x)) goto output_overrun
3575 # endif
3576 #endif
3578 #if defined(LZO_TEST_OVERRUN_LOOKBEHIND)
3579 # define TEST_LB(m_pos) if (m_pos < out || m_pos >= op) goto lookbehind_overrun
3580 # define TEST_LBO(m_pos,o) if (m_pos < out || m_pos >= op - (o)) goto lookbehind_overrun
3581 #else
3582 # define TEST_LB(m_pos) ((void) 0)
3583 # define TEST_LBO(m_pos,o) ((void) 0)
3584 #endif
3586 #if !defined(LZO_EOF_CODE) && !defined(TEST_IP)
3587 # define TEST_IP (ip < ip_end)
3588 #endif
3590 #if defined(TEST_IP)
3591 # define HAVE_TEST_IP 1
3592 #else
3593 # define TEST_IP 1
3594 #endif
3595 #if defined(TEST_OP)
3596 # define HAVE_TEST_OP 1
3597 #else
3598 # define TEST_OP 1
3599 #endif
3601 #if defined(NEED_IP)
3602 # define HAVE_NEED_IP 1
3603 #else
3604 # define NEED_IP(x) ((void) 0)
3605 #endif
3606 #if defined(NEED_OP)
3607 # define HAVE_NEED_OP 1
3608 #else
3609 # define NEED_OP(x) ((void) 0)
3610 #endif
3612 #if defined(HAVE_TEST_IP) || defined(HAVE_NEED_IP)
3613 # define HAVE_ANY_IP 1
3614 #endif
3615 #if defined(HAVE_TEST_OP) || defined(HAVE_NEED_OP)
3616 # define HAVE_ANY_OP 1
3617 #endif
3619 #if defined(DO_DECOMPRESS)
3620 LZO_PUBLIC(int)
3621 DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len,
3622 lzo_bytep out, lzo_uintp out_len,
3623 lzo_voidp wrkmem )
3624 #endif
3626 register lzo_bytep op;
3627 register const lzo_bytep ip;
3628 register lzo_uint t;
3629 #if defined(COPY_DICT)
3630 lzo_uint m_off;
3631 const lzo_bytep dict_end;
3632 #else
3633 register const lzo_bytep m_pos;
3634 #endif
3636 const lzo_bytep const ip_end = in + in_len;
3637 #if defined(HAVE_ANY_OP)
3638 lzo_bytep const op_end = out + *out_len;
3639 #endif
3640 #if defined(LZO1Z)
3641 lzo_uint last_m_off = 0;
3642 #endif
3644 LZO_UNUSED(wrkmem);
3646 #if defined(COPY_DICT)
3647 if (dict)
3649 if (dict_len > M4_MAX_OFFSET)
3651 dict += dict_len - M4_MAX_OFFSET;
3652 dict_len = M4_MAX_OFFSET;
3654 dict_end = dict + dict_len;
3656 else
3658 dict_len = 0;
3659 dict_end = NULL;
3661 #endif
3663 *out_len = 0;
3665 op = out;
3666 ip = in;
3668 if (*ip > 17)
3670 t = *ip++ - 17;
3671 if (t < 4)
3672 goto match_next;
3673 assert(t > 0); NEED_OP(t); NEED_IP(t+1);
3674 do *op++ = *ip++; while (--t > 0);
3675 goto first_literal_run;
3678 while (TEST_IP && TEST_OP)
3680 t = *ip++;
3681 if (t >= 16)
3682 goto match;
3683 if (t == 0)
3685 NEED_IP(1);
3686 while (*ip == 0)
3688 t += 255;
3689 ip++;
3690 NEED_IP(1);
3692 t += 15 + *ip++;
3694 assert(t > 0); NEED_OP(t+3); NEED_IP(t+4);
3695 #if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4)
3696 t += 3;
3697 if (t >= 8) do
3699 UA_COPY64(op,ip);
3700 op += 8; ip += 8; t -= 8;
3701 } while (t >= 8);
3702 if (t >= 4)
3704 UA_COPY32(op,ip);
3705 op += 4; ip += 4; t -= 4;
3707 if (t > 0)
3709 *op++ = *ip++;
3710 if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } }
3712 #elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
3713 #if !defined(LZO_UNALIGNED_OK_4)
3714 if (PTR_ALIGNED2_4(op,ip))
3716 #endif
3717 UA_COPY32(op,ip);
3718 op += 4; ip += 4;
3719 if (--t > 0)
3721 if (t >= 4)
3723 do {
3724 UA_COPY32(op,ip);
3725 op += 4; ip += 4; t -= 4;
3726 } while (t >= 4);
3727 if (t > 0) do *op++ = *ip++; while (--t > 0);
3729 else
3730 do *op++ = *ip++; while (--t > 0);
3732 #if !defined(LZO_UNALIGNED_OK_4)
3734 else
3735 #endif
3736 #endif
3737 #if !defined(LZO_UNALIGNED_OK_4) && !defined(LZO_UNALIGNED_OK_8)
3739 *op++ = *ip++; *op++ = *ip++; *op++ = *ip++;
3740 do *op++ = *ip++; while (--t > 0);
3742 #endif
3744 first_literal_run:
3746 t = *ip++;
3747 if (t >= 16)
3748 goto match;
3749 #if defined(COPY_DICT)
3750 #if defined(LZO1Z)
3751 m_off = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2);
3752 last_m_off = m_off;
3753 #else
3754 m_off = (1 + M2_MAX_OFFSET) + (t >> 2) + (*ip++ << 2);
3755 #endif
3756 NEED_OP(3);
3757 t = 3; COPY_DICT(t,m_off)
3758 #else
3759 #if defined(LZO1Z)
3760 t = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2);
3761 m_pos = op - t;
3762 last_m_off = t;
3763 #else
3764 m_pos = op - (1 + M2_MAX_OFFSET);
3765 m_pos -= t >> 2;
3766 m_pos -= *ip++ << 2;
3767 #endif
3768 TEST_LB(m_pos); NEED_OP(3);
3769 *op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos;
3770 #endif
3771 goto match_done;
3773 do {
3774 match:
3775 if (t >= 64)
3777 #if defined(COPY_DICT)
3778 #if defined(LZO1X)
3779 m_off = 1 + ((t >> 2) & 7) + (*ip++ << 3);
3780 t = (t >> 5) - 1;
3781 #elif defined(LZO1Y)
3782 m_off = 1 + ((t >> 2) & 3) + (*ip++ << 2);
3783 t = (t >> 4) - 3;
3784 #elif defined(LZO1Z)
3785 m_off = t & 0x1f;
3786 if (m_off >= 0x1c)
3787 m_off = last_m_off;
3788 else
3790 m_off = 1 + (m_off << 6) + (*ip++ >> 2);
3791 last_m_off = m_off;
3793 t = (t >> 5) - 1;
3794 #endif
3795 #else
3796 #if defined(LZO1X)
3797 m_pos = op - 1;
3798 m_pos -= (t >> 2) & 7;
3799 m_pos -= *ip++ << 3;
3800 t = (t >> 5) - 1;
3801 #elif defined(LZO1Y)
3802 m_pos = op - 1;
3803 m_pos -= (t >> 2) & 3;
3804 m_pos -= *ip++ << 2;
3805 t = (t >> 4) - 3;
3806 #elif defined(LZO1Z)
3808 lzo_uint off = t & 0x1f;
3809 m_pos = op;
3810 if (off >= 0x1c)
3812 assert(last_m_off > 0);
3813 m_pos -= last_m_off;
3815 else
3817 off = 1 + (off << 6) + (*ip++ >> 2);
3818 m_pos -= off;
3819 last_m_off = off;
3822 t = (t >> 5) - 1;
3823 #endif
3824 TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1);
3825 goto copy_match;
3826 #endif
3828 else if (t >= 32)
3830 t &= 31;
3831 if (t == 0)
3833 NEED_IP(1);
3834 while (*ip == 0)
3836 t += 255;
3837 ip++;
3838 NEED_IP(1);
3840 t += 31 + *ip++;
3842 #if defined(COPY_DICT)
3843 #if defined(LZO1Z)
3844 m_off = 1 + (ip[0] << 6) + (ip[1] >> 2);
3845 last_m_off = m_off;
3846 #else
3847 m_off = 1 + (ip[0] >> 2) + (ip[1] << 6);
3848 #endif
3849 #else
3850 #if defined(LZO1Z)
3852 lzo_uint off = 1 + (ip[0] << 6) + (ip[1] >> 2);
3853 m_pos = op - off;
3854 last_m_off = off;
3856 #elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN)
3857 m_pos = op - 1;
3858 m_pos -= UA_GET16(ip) >> 2;
3859 #else
3860 m_pos = op - 1;
3861 m_pos -= (ip[0] >> 2) + (ip[1] << 6);
3862 #endif
3863 #endif
3864 ip += 2;
3866 else if (t >= 16)
3868 #if defined(COPY_DICT)
3869 m_off = (t & 8) << 11;
3870 #else
3871 m_pos = op;
3872 m_pos -= (t & 8) << 11;
3873 #endif
3874 t &= 7;
3875 if (t == 0)
3877 NEED_IP(1);
3878 while (*ip == 0)
3880 t += 255;
3881 ip++;
3882 NEED_IP(1);
3884 t += 7 + *ip++;
3886 #if defined(COPY_DICT)
3887 #if defined(LZO1Z)
3888 m_off += (ip[0] << 6) + (ip[1] >> 2);
3889 #else
3890 m_off += (ip[0] >> 2) + (ip[1] << 6);
3891 #endif
3892 ip += 2;
3893 if (m_off == 0)
3894 goto eof_found;
3895 m_off += 0x4000;
3896 #if defined(LZO1Z)
3897 last_m_off = m_off;
3898 #endif
3899 #else
3900 #if defined(LZO1Z)
3901 m_pos -= (ip[0] << 6) + (ip[1] >> 2);
3902 #elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN)
3903 m_pos -= UA_GET16(ip) >> 2;
3904 #else
3905 m_pos -= (ip[0] >> 2) + (ip[1] << 6);
3906 #endif
3907 ip += 2;
3908 if (m_pos == op)
3909 goto eof_found;
3910 m_pos -= 0x4000;
3911 #if defined(LZO1Z)
3912 last_m_off = pd((const lzo_bytep)op, m_pos);
3913 #endif
3914 #endif
3916 else
3918 #if defined(COPY_DICT)
3919 #if defined(LZO1Z)
3920 m_off = 1 + (t << 6) + (*ip++ >> 2);
3921 last_m_off = m_off;
3922 #else
3923 m_off = 1 + (t >> 2) + (*ip++ << 2);
3924 #endif
3925 NEED_OP(2);
3926 t = 2; COPY_DICT(t,m_off)
3927 #else
3928 #if defined(LZO1Z)
3929 t = 1 + (t << 6) + (*ip++ >> 2);
3930 m_pos = op - t;
3931 last_m_off = t;
3932 #else
3933 m_pos = op - 1;
3934 m_pos -= t >> 2;
3935 m_pos -= *ip++ << 2;
3936 #endif
3937 TEST_LB(m_pos); NEED_OP(2);
3938 *op++ = *m_pos++; *op++ = *m_pos;
3939 #endif
3940 goto match_done;
3943 #if defined(COPY_DICT)
3945 NEED_OP(t+3-1);
3946 t += 3-1; COPY_DICT(t,m_off)
3948 #else
3950 TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1);
3951 #if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4)
3952 if (op - m_pos >= 8)
3954 t += (3 - 1);
3955 if (t >= 8) do
3957 UA_COPY64(op,m_pos);
3958 op += 8; m_pos += 8; t -= 8;
3959 } while (t >= 8);
3960 if (t >= 4)
3962 UA_COPY32(op,m_pos);
3963 op += 4; m_pos += 4; t -= 4;
3965 if (t > 0)
3967 *op++ = m_pos[0];
3968 if (t > 1) { *op++ = m_pos[1]; if (t > 2) { *op++ = m_pos[2]; } }
3971 else
3972 #elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
3973 #if !defined(LZO_UNALIGNED_OK_4)
3974 if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos))
3976 assert((op - m_pos) >= 4);
3977 #else
3978 if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4)
3980 #endif
3981 UA_COPY32(op,m_pos);
3982 op += 4; m_pos += 4; t -= 4 - (3 - 1);
3983 do {
3984 UA_COPY32(op,m_pos);
3985 op += 4; m_pos += 4; t -= 4;
3986 } while (t >= 4);
3987 if (t > 0) do *op++ = *m_pos++; while (--t > 0);
3989 else
3990 #endif
3992 copy_match:
3993 *op++ = *m_pos++; *op++ = *m_pos++;
3994 do *op++ = *m_pos++; while (--t > 0);
3997 #endif
3999 match_done:
4000 #if defined(LZO1Z)
4001 t = ip[-1] & 3;
4002 #else
4003 t = ip[-2] & 3;
4004 #endif
4005 if (t == 0)
4006 break;
4008 match_next:
4009 assert(t > 0); assert(t < 4); NEED_OP(t); NEED_IP(t+1);
4010 #if 0
4011 do *op++ = *ip++; while (--t > 0);
4012 #else
4013 *op++ = *ip++;
4014 if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } }
4015 #endif
4016 t = *ip++;
4017 } while (TEST_IP && TEST_OP);
4020 #if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP)
4021 *out_len = pd(op, out);
4022 return LZO_E_EOF_NOT_FOUND;
4023 #endif
4025 eof_found:
4026 assert(t == 1);
4027 *out_len = pd(op, out);
4028 return (ip == ip_end ? LZO_E_OK :
4029 (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN));
4031 #if defined(HAVE_NEED_IP)
4032 input_overrun:
4033 *out_len = pd(op, out);
4034 return LZO_E_INPUT_OVERRUN;
4035 #endif
4037 #if defined(HAVE_NEED_OP)
4038 output_overrun:
4039 *out_len = pd(op, out);
4040 return LZO_E_OUTPUT_OVERRUN;
4041 #endif
4043 #if defined(LZO_TEST_OVERRUN_LOOKBEHIND)
4044 lookbehind_overrun:
4045 *out_len = pd(op, out);
4046 return LZO_E_LOOKBEHIND_OVERRUN;
4047 #endif
4050 #endif
4052 #define LZO_TEST_OVERRUN 1
4053 #undef DO_DECOMPRESS
4054 #define DO_DECOMPRESS lzo1x_decompress_safe
4056 #if !defined(MINILZO_CFG_SKIP_LZO1X_DECOMPRESS_SAFE)
4058 #if defined(LZO_TEST_OVERRUN)
4059 # if !defined(LZO_TEST_OVERRUN_INPUT)
4060 # define LZO_TEST_OVERRUN_INPUT 2
4061 # endif
4062 # if !defined(LZO_TEST_OVERRUN_OUTPUT)
4063 # define LZO_TEST_OVERRUN_OUTPUT 2
4064 # endif
4065 # if !defined(LZO_TEST_OVERRUN_LOOKBEHIND)
4066 # define LZO_TEST_OVERRUN_LOOKBEHIND 1
4067 # endif
4068 #endif
4070 #undef TEST_IP
4071 #undef TEST_OP
4072 #undef TEST_LB
4073 #undef TEST_LBO
4074 #undef NEED_IP
4075 #undef NEED_OP
4076 #undef HAVE_TEST_IP
4077 #undef HAVE_TEST_OP
4078 #undef HAVE_NEED_IP
4079 #undef HAVE_NEED_OP
4080 #undef HAVE_ANY_IP
4081 #undef HAVE_ANY_OP
4083 #if defined(LZO_TEST_OVERRUN_INPUT)
4084 # if (LZO_TEST_OVERRUN_INPUT >= 1)
4085 # define TEST_IP (ip < ip_end)
4086 # endif
4087 # if (LZO_TEST_OVERRUN_INPUT >= 2)
4088 # define NEED_IP(x) \
4089 if ((lzo_uint)(ip_end - ip) < (lzo_uint)(x)) goto input_overrun
4090 # endif
4091 #endif
4093 #if defined(LZO_TEST_OVERRUN_OUTPUT)
4094 # if (LZO_TEST_OVERRUN_OUTPUT >= 1)
4095 # define TEST_OP (op <= op_end)
4096 # endif
4097 # if (LZO_TEST_OVERRUN_OUTPUT >= 2)
4098 # undef TEST_OP
4099 # define NEED_OP(x) \
4100 if ((lzo_uint)(op_end - op) < (lzo_uint)(x)) goto output_overrun
4101 # endif
4102 #endif
4104 #if defined(LZO_TEST_OVERRUN_LOOKBEHIND)
4105 # define TEST_LB(m_pos) if (m_pos < out || m_pos >= op) goto lookbehind_overrun
4106 # define TEST_LBO(m_pos,o) if (m_pos < out || m_pos >= op - (o)) goto lookbehind_overrun
4107 #else
4108 # define TEST_LB(m_pos) ((void) 0)
4109 # define TEST_LBO(m_pos,o) ((void) 0)
4110 #endif
4112 #if !defined(LZO_EOF_CODE) && !defined(TEST_IP)
4113 # define TEST_IP (ip < ip_end)
4114 #endif
4116 #if defined(TEST_IP)
4117 # define HAVE_TEST_IP 1
4118 #else
4119 # define TEST_IP 1
4120 #endif
4121 #if defined(TEST_OP)
4122 # define HAVE_TEST_OP 1
4123 #else
4124 # define TEST_OP 1
4125 #endif
4127 #if defined(NEED_IP)
4128 # define HAVE_NEED_IP 1
4129 #else
4130 # define NEED_IP(x) ((void) 0)
4131 #endif
4132 #if defined(NEED_OP)
4133 # define HAVE_NEED_OP 1
4134 #else
4135 # define NEED_OP(x) ((void) 0)
4136 #endif
4138 #if defined(HAVE_TEST_IP) || defined(HAVE_NEED_IP)
4139 # define HAVE_ANY_IP 1
4140 #endif
4141 #if defined(HAVE_TEST_OP) || defined(HAVE_NEED_OP)
4142 # define HAVE_ANY_OP 1
4143 #endif
4145 #if defined(DO_DECOMPRESS)
4146 LZO_PUBLIC(int)
4147 DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len,
4148 lzo_bytep out, lzo_uintp out_len,
4149 lzo_voidp wrkmem )
4150 #endif
4152 register lzo_bytep op;
4153 register const lzo_bytep ip;
4154 register lzo_uint t;
4155 #if defined(COPY_DICT)
4156 lzo_uint m_off;
4157 const lzo_bytep dict_end;
4158 #else
4159 register const lzo_bytep m_pos;
4160 #endif
4162 const lzo_bytep const ip_end = in + in_len;
4163 #if defined(HAVE_ANY_OP)
4164 lzo_bytep const op_end = out + *out_len;
4165 #endif
4166 #if defined(LZO1Z)
4167 lzo_uint last_m_off = 0;
4168 #endif
4170 LZO_UNUSED(wrkmem);
4172 #if defined(COPY_DICT)
4173 if (dict)
4175 if (dict_len > M4_MAX_OFFSET)
4177 dict += dict_len - M4_MAX_OFFSET;
4178 dict_len = M4_MAX_OFFSET;
4180 dict_end = dict + dict_len;
4182 else
4184 dict_len = 0;
4185 dict_end = NULL;
4187 #endif
4189 *out_len = 0;
4191 op = out;
4192 ip = in;
4194 if (*ip > 17)
4196 t = *ip++ - 17;
4197 if (t < 4)
4198 goto match_next;
4199 assert(t > 0); NEED_OP(t); NEED_IP(t+1);
4200 do *op++ = *ip++; while (--t > 0);
4201 goto first_literal_run;
4204 while (TEST_IP && TEST_OP)
4206 t = *ip++;
4207 if (t >= 16)
4208 goto match;
4209 if (t == 0)
4211 NEED_IP(1);
4212 while (*ip == 0)
4214 t += 255;
4215 ip++;
4216 NEED_IP(1);
4218 t += 15 + *ip++;
4220 assert(t > 0); NEED_OP(t+3); NEED_IP(t+4);
4221 #if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4)
4222 t += 3;
4223 if (t >= 8) do
4225 UA_COPY64(op,ip);
4226 op += 8; ip += 8; t -= 8;
4227 } while (t >= 8);
4228 if (t >= 4)
4230 UA_COPY32(op,ip);
4231 op += 4; ip += 4; t -= 4;
4233 if (t > 0)
4235 *op++ = *ip++;
4236 if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } }
4238 #elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
4239 #if !defined(LZO_UNALIGNED_OK_4)
4240 if (PTR_ALIGNED2_4(op,ip))
4242 #endif
4243 UA_COPY32(op,ip);
4244 op += 4; ip += 4;
4245 if (--t > 0)
4247 if (t >= 4)
4249 do {
4250 UA_COPY32(op,ip);
4251 op += 4; ip += 4; t -= 4;
4252 } while (t >= 4);
4253 if (t > 0) do *op++ = *ip++; while (--t > 0);
4255 else
4256 do *op++ = *ip++; while (--t > 0);
4258 #if !defined(LZO_UNALIGNED_OK_4)
4260 else
4261 #endif
4262 #endif
4263 #if !defined(LZO_UNALIGNED_OK_4) && !defined(LZO_UNALIGNED_OK_8)
4265 *op++ = *ip++; *op++ = *ip++; *op++ = *ip++;
4266 do *op++ = *ip++; while (--t > 0);
4268 #endif
4270 first_literal_run:
4272 t = *ip++;
4273 if (t >= 16)
4274 goto match;
4275 #if defined(COPY_DICT)
4276 #if defined(LZO1Z)
4277 m_off = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2);
4278 last_m_off = m_off;
4279 #else
4280 m_off = (1 + M2_MAX_OFFSET) + (t >> 2) + (*ip++ << 2);
4281 #endif
4282 NEED_OP(3);
4283 t = 3; COPY_DICT(t,m_off)
4284 #else
4285 #if defined(LZO1Z)
4286 t = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2);
4287 m_pos = op - t;
4288 last_m_off = t;
4289 #else
4290 m_pos = op - (1 + M2_MAX_OFFSET);
4291 m_pos -= t >> 2;
4292 m_pos -= *ip++ << 2;
4293 #endif
4294 TEST_LB(m_pos); NEED_OP(3);
4295 *op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos;
4296 #endif
4297 goto match_done;
4299 do {
4300 match:
4301 if (t >= 64)
4303 #if defined(COPY_DICT)
4304 #if defined(LZO1X)
4305 m_off = 1 + ((t >> 2) & 7) + (*ip++ << 3);
4306 t = (t >> 5) - 1;
4307 #elif defined(LZO1Y)
4308 m_off = 1 + ((t >> 2) & 3) + (*ip++ << 2);
4309 t = (t >> 4) - 3;
4310 #elif defined(LZO1Z)
4311 m_off = t & 0x1f;
4312 if (m_off >= 0x1c)
4313 m_off = last_m_off;
4314 else
4316 m_off = 1 + (m_off << 6) + (*ip++ >> 2);
4317 last_m_off = m_off;
4319 t = (t >> 5) - 1;
4320 #endif
4321 #else
4322 #if defined(LZO1X)
4323 m_pos = op - 1;
4324 m_pos -= (t >> 2) & 7;
4325 m_pos -= *ip++ << 3;
4326 t = (t >> 5) - 1;
4327 #elif defined(LZO1Y)
4328 m_pos = op - 1;
4329 m_pos -= (t >> 2) & 3;
4330 m_pos -= *ip++ << 2;
4331 t = (t >> 4) - 3;
4332 #elif defined(LZO1Z)
4334 lzo_uint off = t & 0x1f;
4335 m_pos = op;
4336 if (off >= 0x1c)
4338 assert(last_m_off > 0);
4339 m_pos -= last_m_off;
4341 else
4343 off = 1 + (off << 6) + (*ip++ >> 2);
4344 m_pos -= off;
4345 last_m_off = off;
4348 t = (t >> 5) - 1;
4349 #endif
4350 TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1);
4351 goto copy_match;
4352 #endif
4354 else if (t >= 32)
4356 t &= 31;
4357 if (t == 0)
4359 NEED_IP(1);
4360 while (*ip == 0)
4362 t += 255;
4363 ip++;
4364 NEED_IP(1);
4366 t += 31 + *ip++;
4368 #if defined(COPY_DICT)
4369 #if defined(LZO1Z)
4370 m_off = 1 + (ip[0] << 6) + (ip[1] >> 2);
4371 last_m_off = m_off;
4372 #else
4373 m_off = 1 + (ip[0] >> 2) + (ip[1] << 6);
4374 #endif
4375 #else
4376 #if defined(LZO1Z)
4378 lzo_uint off = 1 + (ip[0] << 6) + (ip[1] >> 2);
4379 m_pos = op - off;
4380 last_m_off = off;
4382 #elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN)
4383 m_pos = op - 1;
4384 m_pos -= UA_GET16(ip) >> 2;
4385 #else
4386 m_pos = op - 1;
4387 m_pos -= (ip[0] >> 2) + (ip[1] << 6);
4388 #endif
4389 #endif
4390 ip += 2;
4392 else if (t >= 16)
4394 #if defined(COPY_DICT)
4395 m_off = (t & 8) << 11;
4396 #else
4397 m_pos = op;
4398 m_pos -= (t & 8) << 11;
4399 #endif
4400 t &= 7;
4401 if (t == 0)
4403 NEED_IP(1);
4404 while (*ip == 0)
4406 t += 255;
4407 ip++;
4408 NEED_IP(1);
4410 t += 7 + *ip++;
4412 #if defined(COPY_DICT)
4413 #if defined(LZO1Z)
4414 m_off += (ip[0] << 6) + (ip[1] >> 2);
4415 #else
4416 m_off += (ip[0] >> 2) + (ip[1] << 6);
4417 #endif
4418 ip += 2;
4419 if (m_off == 0)
4420 goto eof_found;
4421 m_off += 0x4000;
4422 #if defined(LZO1Z)
4423 last_m_off = m_off;
4424 #endif
4425 #else
4426 #if defined(LZO1Z)
4427 m_pos -= (ip[0] << 6) + (ip[1] >> 2);
4428 #elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN)
4429 m_pos -= UA_GET16(ip) >> 2;
4430 #else
4431 m_pos -= (ip[0] >> 2) + (ip[1] << 6);
4432 #endif
4433 ip += 2;
4434 if (m_pos == op)
4435 goto eof_found;
4436 m_pos -= 0x4000;
4437 #if defined(LZO1Z)
4438 last_m_off = pd((const lzo_bytep)op, m_pos);
4439 #endif
4440 #endif
4442 else
4444 #if defined(COPY_DICT)
4445 #if defined(LZO1Z)
4446 m_off = 1 + (t << 6) + (*ip++ >> 2);
4447 last_m_off = m_off;
4448 #else
4449 m_off = 1 + (t >> 2) + (*ip++ << 2);
4450 #endif
4451 NEED_OP(2);
4452 t = 2; COPY_DICT(t,m_off)
4453 #else
4454 #if defined(LZO1Z)
4455 t = 1 + (t << 6) + (*ip++ >> 2);
4456 m_pos = op - t;
4457 last_m_off = t;
4458 #else
4459 m_pos = op - 1;
4460 m_pos -= t >> 2;
4461 m_pos -= *ip++ << 2;
4462 #endif
4463 TEST_LB(m_pos); NEED_OP(2);
4464 *op++ = *m_pos++; *op++ = *m_pos;
4465 #endif
4466 goto match_done;
4469 #if defined(COPY_DICT)
4471 NEED_OP(t+3-1);
4472 t += 3-1; COPY_DICT(t,m_off)
4474 #else
4476 TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1);
4477 #if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4)
4478 if (op - m_pos >= 8)
4480 t += (3 - 1);
4481 if (t >= 8) do
4483 UA_COPY64(op,m_pos);
4484 op += 8; m_pos += 8; t -= 8;
4485 } while (t >= 8);
4486 if (t >= 4)
4488 UA_COPY32(op,m_pos);
4489 op += 4; m_pos += 4; t -= 4;
4491 if (t > 0)
4493 *op++ = m_pos[0];
4494 if (t > 1) { *op++ = m_pos[1]; if (t > 2) { *op++ = m_pos[2]; } }
4497 else
4498 #elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
4499 #if !defined(LZO_UNALIGNED_OK_4)
4500 if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos))
4502 assert((op - m_pos) >= 4);
4503 #else
4504 if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4)
4506 #endif
4507 UA_COPY32(op,m_pos);
4508 op += 4; m_pos += 4; t -= 4 - (3 - 1);
4509 do {
4510 UA_COPY32(op,m_pos);
4511 op += 4; m_pos += 4; t -= 4;
4512 } while (t >= 4);
4513 if (t > 0) do *op++ = *m_pos++; while (--t > 0);
4515 else
4516 #endif
4518 copy_match:
4519 *op++ = *m_pos++; *op++ = *m_pos++;
4520 do *op++ = *m_pos++; while (--t > 0);
4523 #endif
4525 match_done:
4526 #if defined(LZO1Z)
4527 t = ip[-1] & 3;
4528 #else
4529 t = ip[-2] & 3;
4530 #endif
4531 if (t == 0)
4532 break;
4534 match_next:
4535 assert(t > 0); assert(t < 4); NEED_OP(t); NEED_IP(t+1);
4536 #if 0
4537 do *op++ = *ip++; while (--t > 0);
4538 #else
4539 *op++ = *ip++;
4540 if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } }
4541 #endif
4542 t = *ip++;
4543 } while (TEST_IP && TEST_OP);
4546 #if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP)
4547 *out_len = pd(op, out);
4548 return LZO_E_EOF_NOT_FOUND;
4549 #endif
4551 eof_found:
4552 assert(t == 1);
4553 *out_len = pd(op, out);
4554 return (ip == ip_end ? LZO_E_OK :
4555 (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN));
4557 #if defined(HAVE_NEED_IP)
4558 input_overrun:
4559 *out_len = pd(op, out);
4560 return LZO_E_INPUT_OVERRUN;
4561 #endif
4563 #if defined(HAVE_NEED_OP)
4564 output_overrun:
4565 *out_len = pd(op, out);
4566 return LZO_E_OUTPUT_OVERRUN;
4567 #endif
4569 #if defined(LZO_TEST_OVERRUN_LOOKBEHIND)
4570 lookbehind_overrun:
4571 *out_len = pd(op, out);
4572 return LZO_E_LOOKBEHIND_OVERRUN;
4573 #endif
4576 #endif
4578 /***** End of minilzo.c *****/