Upgraded GRUB2 to 2.00 release.
[AROS.git] / arch / all-pc / boot / grub2-aros / grub-core / lib / minilzo / minilzo.c
blobb73d22a6bade6068f69be8604f63847390c6c5f4
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 != 0x2050)
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$\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 #if 0
2565 #define WANT_lzo_bitops_clz32 1
2566 #define WANT_lzo_bitops_clz64 1
2567 #endif
2568 #define WANT_lzo_bitops_ctz32 1
2569 #define WANT_lzo_bitops_ctz64 1
2571 #if (defined(_WIN32) || defined(_WIN64)) && ((LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || (LZO_CC_MSC && (_MSC_VER >= 1400)))
2572 #include <intrin.h>
2573 #if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32) && 0
2574 #pragma intrinsic(_BitScanReverse)
2575 static __lzo_inline unsigned lzo_bitops_clz32(lzo_uint32 v)
2577 unsigned long r;
2578 (void) _BitScanReverse(&r, v);
2579 return (unsigned) r;
2581 #define lzo_bitops_clz32 lzo_bitops_clz32
2582 #endif
2583 #if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX) && 0
2584 #pragma intrinsic(_BitScanReverse64)
2585 static __lzo_inline unsigned lzo_bitops_clz64(lzo_uint64 v)
2587 unsigned long r;
2588 (void) _BitScanReverse64(&r, v);
2589 return (unsigned) r;
2591 #define lzo_bitops_clz64 lzo_bitops_clz64
2592 #endif
2593 #if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32)
2594 #pragma intrinsic(_BitScanForward)
2595 static __lzo_inline unsigned lzo_bitops_ctz32(lzo_uint32 v)
2597 unsigned long r;
2598 (void) _BitScanForward(&r, v);
2599 return (unsigned) r;
2601 #define lzo_bitops_ctz32 lzo_bitops_ctz32
2602 #endif
2603 #if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX)
2604 #pragma intrinsic(_BitScanForward64)
2605 static __lzo_inline unsigned lzo_bitops_ctz64(lzo_uint64 v)
2607 unsigned long r;
2608 (void) _BitScanForward64(&r, v);
2609 return (unsigned) r;
2611 #define lzo_bitops_ctz64 lzo_bitops_ctz64
2612 #endif
2614 #elif (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x030400ul) || (LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || LZO_CC_LLVM)
2615 #if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32)
2616 #define lzo_bitops_clz32(v) ((unsigned) __builtin_clz(v))
2617 #endif
2618 #if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX)
2619 #define lzo_bitops_clz64(v) ((unsigned) __builtin_clzll(v))
2620 #endif
2621 #if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32)
2622 #define lzo_bitops_ctz32(v) ((unsigned) __builtin_ctz(v))
2623 #endif
2624 #if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX)
2625 #define lzo_bitops_ctz64(v) ((unsigned) __builtin_ctzll(v))
2626 #endif
2627 #if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount32)
2628 #define lzo_bitops_popcount32(v) ((unsigned) __builtin_popcount(v))
2629 #endif
2630 #if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount64) && defined(LZO_UINT64_MAX)
2631 #define lzo_bitops_popcount64(v) ((unsigned) __builtin_popcountll(v))
2632 #endif
2633 #endif
2635 #if 0
2636 #define u2p(ptr,off) ((lzo_voidp) (((lzo_bytep)(lzo_voidp)(ptr)) + (off)))
2637 #else
2638 static __lzo_noinline lzo_voidp u2p(lzo_voidp ptr, lzo_uint off)
2640 return (lzo_voidp) ((lzo_bytep) ptr + off);
2642 #endif
2644 LZO_PUBLIC(int)
2645 _lzo_config_check(void)
2647 lzo_bool r = 1;
2648 union {
2649 lzo_xint a[2]; unsigned char b[2*LZO_MAX(8,sizeof(lzo_xint))];
2650 #if defined(LZO_UNALIGNED_OK_8)
2651 lzo_uint64 c[2];
2652 #endif
2653 unsigned short x[2]; lzo_uint32 y[2]; lzo_uint z[2];
2654 } u;
2655 lzo_voidp p;
2657 u.a[0] = u.a[1] = 0;
2658 p = u2p(&u, 0);
2659 r &= ((* (lzo_bytep) p) == 0);
2660 #if !defined(LZO_CFG_NO_CONFIG_CHECK)
2661 #if defined(LZO_ABI_BIG_ENDIAN)
2662 u.a[0] = u.a[1] = 0; u.b[sizeof(lzo_uint) - 1] = 128;
2663 p = u2p(&u, 0);
2664 r &= ((* (lzo_uintp) p) == 128);
2665 #endif
2666 #if defined(LZO_ABI_LITTLE_ENDIAN)
2667 u.a[0] = u.a[1] = 0; u.b[0] = 128;
2668 p = u2p(&u, 0);
2669 r &= ((* (lzo_uintp) p) == 128);
2670 #endif
2671 #if defined(LZO_UNALIGNED_OK_2)
2672 u.a[0] = u.a[1] = 0;
2673 u.b[0] = 1; u.b[sizeof(unsigned short) + 1] = 2;
2674 p = u2p(&u, 1);
2675 r &= ((* (lzo_ushortp) p) == 0);
2676 #endif
2677 #if defined(LZO_UNALIGNED_OK_4)
2678 u.a[0] = u.a[1] = 0;
2679 u.b[0] = 3; u.b[sizeof(lzo_uint32) + 1] = 4;
2680 p = u2p(&u, 1);
2681 r &= ((* (lzo_uint32p) p) == 0);
2682 #endif
2683 #if defined(LZO_UNALIGNED_OK_8)
2684 u.c[0] = u.c[1] = 0;
2685 u.b[0] = 5; u.b[sizeof(lzo_uint64) + 1] = 6;
2686 p = u2p(&u, 1);
2687 r &= ((* (lzo_uint64p) p) == 0);
2688 #endif
2689 #if defined(lzo_bitops_clz32)
2690 { unsigned i; lzo_uint32 v = 1;
2691 for (i = 0; i < 31; i++, v <<= 1)
2692 r &= lzo_bitops_clz32(v) == 31 - i;
2694 #endif
2695 #if defined(lzo_bitops_clz64)
2696 { unsigned i; lzo_uint64 v = 1;
2697 for (i = 0; i < 63; i++, v <<= 1)
2698 r &= lzo_bitops_clz64(v) == 63 - i;
2700 #endif
2701 #if defined(lzo_bitops_ctz32)
2702 { unsigned i; lzo_uint32 v = 1;
2703 for (i = 0; i < 31; i++, v <<= 1)
2704 r &= lzo_bitops_ctz32(v) == i;
2706 #endif
2707 #if defined(lzo_bitops_ctz64)
2708 { unsigned i; lzo_uint64 v = 1;
2709 for (i = 0; i < 63; i++, v <<= 1)
2710 r &= lzo_bitops_ctz64(v) == i;
2712 #endif
2713 #endif
2715 return r == 1 ? LZO_E_OK : LZO_E_ERROR;
2718 LZO_PUBLIC(int)
2719 __lzo_init_v2(unsigned v, int s1, int s2, int s3, int s4, int s5,
2720 int s6, int s7, int s8, int s9)
2722 int r;
2724 #if defined(__LZO_IN_MINILZO)
2725 #elif (LZO_CC_MSC && ((_MSC_VER) < 700))
2726 #else
2727 #define ACC_WANT_ACC_CHK_CH 1
2728 #undef ACCCHK_ASSERT
2729 #define ACCCHK_ASSERT(expr) LZO_COMPILE_TIME_ASSERT(expr)
2730 #endif
2731 #undef ACCCHK_ASSERT
2733 if (v == 0)
2734 return LZO_E_ERROR;
2736 r = (s1 == -1 || s1 == (int) sizeof(short)) &&
2737 (s2 == -1 || s2 == (int) sizeof(int)) &&
2738 (s3 == -1 || s3 == (int) sizeof(long)) &&
2739 (s4 == -1 || s4 == (int) sizeof(lzo_uint32)) &&
2740 (s5 == -1 || s5 == (int) sizeof(lzo_uint)) &&
2741 (s6 == -1 || s6 == (int) lzo_sizeof_dict_t) &&
2742 (s7 == -1 || s7 == (int) sizeof(char *)) &&
2743 (s8 == -1 || s8 == (int) sizeof(lzo_voidp)) &&
2744 (s9 == -1 || s9 == (int) sizeof(lzo_callback_t));
2745 if (!r)
2746 return LZO_E_ERROR;
2748 r = _lzo_config_check();
2749 if (r != LZO_E_OK)
2750 return r;
2752 return r;
2755 #if !defined(__LZO_IN_MINILZO)
2757 #if (LZO_OS_WIN16 && LZO_CC_WATCOMC) && defined(__SW_BD)
2759 #if 0
2760 BOOL FAR PASCAL LibMain ( HANDLE hInstance, WORD wDataSegment,
2761 WORD wHeapSize, LPSTR lpszCmdLine )
2762 #else
2763 int __far __pascal LibMain ( int a, short b, short c, long d )
2764 #endif
2766 LZO_UNUSED(a); LZO_UNUSED(b); LZO_UNUSED(c); LZO_UNUSED(d);
2767 return 1;
2770 #endif
2772 #endif
2774 #endif
2776 #define LZO1X 1
2777 #define LZO_EOF_CODE 1
2778 #define M2_MAX_OFFSET 0x0800
2780 #if !defined(MINILZO_CFG_SKIP_LZO1X_1_COMPRESS)
2782 #if 1 && defined(UA_GET32)
2783 #undef LZO_DICT_USE_PTR
2784 #define LZO_DICT_USE_PTR 0
2785 #undef lzo_dict_t
2786 #define lzo_dict_t unsigned short
2787 #endif
2789 #define LZO_NEED_DICT_H 1
2790 #ifndef D_BITS
2791 #define D_BITS 14
2792 #endif
2793 #define D_INDEX1(d,p) d = DM(DMUL(0x21,DX3(p,5,5,6)) >> 5)
2794 #define D_INDEX2(d,p) d = (d & (D_MASK & 0x7ff)) ^ (D_HIGH | 0x1f)
2795 #if 1
2796 #define DINDEX(dv,p) DM(((DMUL(0x1824429d,dv)) >> (32-D_BITS)))
2797 #else
2798 #define DINDEX(dv,p) DM((dv) + ((dv) >> (32-D_BITS)))
2799 #endif
2801 #ifndef __LZO_CONFIG1X_H
2802 #define __LZO_CONFIG1X_H 1
2804 #if !defined(LZO1X) && !defined(LZO1Y) && !defined(LZO1Z)
2805 # define LZO1X 1
2806 #endif
2808 #if !defined(__LZO_IN_MINILZO)
2809 #include "lzo/lzo1x.h"
2810 #endif
2812 #ifndef LZO_EOF_CODE
2813 #define LZO_EOF_CODE 1
2814 #endif
2815 #undef LZO_DETERMINISTIC
2817 #define M1_MAX_OFFSET 0x0400
2818 #ifndef M2_MAX_OFFSET
2819 #define M2_MAX_OFFSET 0x0800
2820 #endif
2821 #define M3_MAX_OFFSET 0x4000
2822 #define M4_MAX_OFFSET 0xbfff
2824 #define MX_MAX_OFFSET (M1_MAX_OFFSET + M2_MAX_OFFSET)
2826 #define M1_MIN_LEN 2
2827 #define M1_MAX_LEN 2
2828 #define M2_MIN_LEN 3
2829 #ifndef M2_MAX_LEN
2830 #define M2_MAX_LEN 8
2831 #endif
2832 #define M3_MIN_LEN 3
2833 #define M3_MAX_LEN 33
2834 #define M4_MIN_LEN 3
2835 #define M4_MAX_LEN 9
2837 #define M1_MARKER 0
2838 #define M2_MARKER 64
2839 #define M3_MARKER 32
2840 #define M4_MARKER 16
2842 #ifndef MIN_LOOKAHEAD
2843 #define MIN_LOOKAHEAD (M2_MAX_LEN + 1)
2844 #endif
2846 #if defined(LZO_NEED_DICT_H)
2848 #ifndef LZO_HASH
2849 #define LZO_HASH LZO_HASH_LZO_INCREMENTAL_B
2850 #endif
2851 #define DL_MIN_LEN M2_MIN_LEN
2853 #ifndef __LZO_DICT_H
2854 #define __LZO_DICT_H 1
2856 #ifdef __cplusplus
2857 extern "C" {
2858 #endif
2860 #if !defined(D_BITS) && defined(DBITS)
2861 # define D_BITS DBITS
2862 #endif
2863 #if !defined(D_BITS)
2864 # error "D_BITS is not defined"
2865 #endif
2866 #if (D_BITS < 16)
2867 # define D_SIZE LZO_SIZE(D_BITS)
2868 # define D_MASK LZO_MASK(D_BITS)
2869 #else
2870 # define D_SIZE LZO_USIZE(D_BITS)
2871 # define D_MASK LZO_UMASK(D_BITS)
2872 #endif
2873 #define D_HIGH ((D_MASK >> 1) + 1)
2875 #if !defined(DD_BITS)
2876 # define DD_BITS 0
2877 #endif
2878 #define DD_SIZE LZO_SIZE(DD_BITS)
2879 #define DD_MASK LZO_MASK(DD_BITS)
2881 #if !defined(DL_BITS)
2882 # define DL_BITS (D_BITS - DD_BITS)
2883 #endif
2884 #if (DL_BITS < 16)
2885 # define DL_SIZE LZO_SIZE(DL_BITS)
2886 # define DL_MASK LZO_MASK(DL_BITS)
2887 #else
2888 # define DL_SIZE LZO_USIZE(DL_BITS)
2889 # define DL_MASK LZO_UMASK(DL_BITS)
2890 #endif
2892 #if (D_BITS != DL_BITS + DD_BITS)
2893 # error "D_BITS does not match"
2894 #endif
2895 #if (D_BITS < 6 || D_BITS > 18)
2896 # error "invalid D_BITS"
2897 #endif
2898 #if (DL_BITS < 6 || DL_BITS > 20)
2899 # error "invalid DL_BITS"
2900 #endif
2901 #if (DD_BITS < 0 || DD_BITS > 6)
2902 # error "invalid DD_BITS"
2903 #endif
2905 #if !defined(DL_MIN_LEN)
2906 # define DL_MIN_LEN 3
2907 #endif
2908 #if !defined(DL_SHIFT)
2909 # define DL_SHIFT ((DL_BITS + (DL_MIN_LEN - 1)) / DL_MIN_LEN)
2910 #endif
2912 #define LZO_HASH_GZIP 1
2913 #define LZO_HASH_GZIP_INCREMENTAL 2
2914 #define LZO_HASH_LZO_INCREMENTAL_A 3
2915 #define LZO_HASH_LZO_INCREMENTAL_B 4
2917 #if !defined(LZO_HASH)
2918 # error "choose a hashing strategy"
2919 #endif
2921 #undef DM
2922 #undef DX
2924 #if (DL_MIN_LEN == 3)
2925 # define _DV2_A(p,shift1,shift2) \
2926 (((( (lzo_xint)((p)[0]) << shift1) ^ (p)[1]) << shift2) ^ (p)[2])
2927 # define _DV2_B(p,shift1,shift2) \
2928 (((( (lzo_xint)((p)[2]) << shift1) ^ (p)[1]) << shift2) ^ (p)[0])
2929 # define _DV3_B(p,shift1,shift2,shift3) \
2930 ((_DV2_B((p)+1,shift1,shift2) << (shift3)) ^ (p)[0])
2931 #elif (DL_MIN_LEN == 2)
2932 # define _DV2_A(p,shift1,shift2) \
2933 (( (lzo_xint)(p[0]) << shift1) ^ p[1])
2934 # define _DV2_B(p,shift1,shift2) \
2935 (( (lzo_xint)(p[1]) << shift1) ^ p[2])
2936 #else
2937 # error "invalid DL_MIN_LEN"
2938 #endif
2939 #define _DV_A(p,shift) _DV2_A(p,shift,shift)
2940 #define _DV_B(p,shift) _DV2_B(p,shift,shift)
2941 #define DA2(p,s1,s2) \
2942 (((((lzo_xint)((p)[2]) << (s2)) + (p)[1]) << (s1)) + (p)[0])
2943 #define DS2(p,s1,s2) \
2944 (((((lzo_xint)((p)[2]) << (s2)) - (p)[1]) << (s1)) - (p)[0])
2945 #define DX2(p,s1,s2) \
2946 (((((lzo_xint)((p)[2]) << (s2)) ^ (p)[1]) << (s1)) ^ (p)[0])
2947 #define DA3(p,s1,s2,s3) ((DA2((p)+1,s2,s3) << (s1)) + (p)[0])
2948 #define DS3(p,s1,s2,s3) ((DS2((p)+1,s2,s3) << (s1)) - (p)[0])
2949 #define DX3(p,s1,s2,s3) ((DX2((p)+1,s2,s3) << (s1)) ^ (p)[0])
2950 #define DMS(v,s) ((lzo_uint) (((v) & (D_MASK >> (s))) << (s)))
2951 #define DM(v) DMS(v,0)
2953 #if (LZO_HASH == LZO_HASH_GZIP)
2954 # define _DINDEX(dv,p) (_DV_A((p),DL_SHIFT))
2956 #elif (LZO_HASH == LZO_HASH_GZIP_INCREMENTAL)
2957 # define __LZO_HASH_INCREMENTAL 1
2958 # define DVAL_FIRST(dv,p) dv = _DV_A((p),DL_SHIFT)
2959 # define DVAL_NEXT(dv,p) dv = (((dv) << DL_SHIFT) ^ p[2])
2960 # define _DINDEX(dv,p) (dv)
2961 # define DVAL_LOOKAHEAD DL_MIN_LEN
2963 #elif (LZO_HASH == LZO_HASH_LZO_INCREMENTAL_A)
2964 # define __LZO_HASH_INCREMENTAL 1
2965 # define DVAL_FIRST(dv,p) dv = _DV_A((p),5)
2966 # define DVAL_NEXT(dv,p) \
2967 dv ^= (lzo_xint)(p[-1]) << (2*5); dv = (((dv) << 5) ^ p[2])
2968 # define _DINDEX(dv,p) ((DMUL(0x9f5f,dv)) >> 5)
2969 # define DVAL_LOOKAHEAD DL_MIN_LEN
2971 #elif (LZO_HASH == LZO_HASH_LZO_INCREMENTAL_B)
2972 # define __LZO_HASH_INCREMENTAL 1
2973 # define DVAL_FIRST(dv,p) dv = _DV_B((p),5)
2974 # define DVAL_NEXT(dv,p) \
2975 dv ^= p[-1]; dv = (((dv) >> 5) ^ ((lzo_xint)(p[2]) << (2*5)))
2976 # define _DINDEX(dv,p) ((DMUL(0x9f5f,dv)) >> 5)
2977 # define DVAL_LOOKAHEAD DL_MIN_LEN
2979 #else
2980 # error "choose a hashing strategy"
2981 #endif
2983 #ifndef DINDEX
2984 #define DINDEX(dv,p) ((lzo_uint)((_DINDEX(dv,p)) & DL_MASK) << DD_BITS)
2985 #endif
2986 #if !defined(DINDEX1) && defined(D_INDEX1)
2987 #define DINDEX1 D_INDEX1
2988 #endif
2989 #if !defined(DINDEX2) && defined(D_INDEX2)
2990 #define DINDEX2 D_INDEX2
2991 #endif
2993 #if !defined(__LZO_HASH_INCREMENTAL)
2994 # define DVAL_FIRST(dv,p) ((void) 0)
2995 # define DVAL_NEXT(dv,p) ((void) 0)
2996 # define DVAL_LOOKAHEAD 0
2997 #endif
2999 #if !defined(DVAL_ASSERT)
3000 #if defined(__LZO_HASH_INCREMENTAL) && !defined(NDEBUG)
3001 #if (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x020700ul) || LZO_CC_LLVM)
3002 static void __attribute__((__unused__))
3003 #else
3004 static void
3005 #endif
3006 DVAL_ASSERT(lzo_xint dv, const lzo_bytep p)
3008 lzo_xint df;
3009 DVAL_FIRST(df,(p));
3010 assert(DINDEX(dv,p) == DINDEX(df,p));
3012 #else
3013 # define DVAL_ASSERT(dv,p) ((void) 0)
3014 #endif
3015 #endif
3017 #if (LZO_DICT_USE_PTR)
3018 # define DENTRY(p,in) (p)
3019 # define GINDEX(m_pos,m_off,dict,dindex,in) m_pos = dict[dindex]
3020 #else
3021 # define DENTRY(p,in) ((lzo_dict_t) pd(p, in))
3022 # define GINDEX(m_pos,m_off,dict,dindex,in) m_off = dict[dindex]
3023 #endif
3025 #if (DD_BITS == 0)
3027 # define UPDATE_D(dict,drun,dv,p,in) dict[ DINDEX(dv,p) ] = DENTRY(p,in)
3028 # define UPDATE_I(dict,drun,index,p,in) dict[index] = DENTRY(p,in)
3029 # define UPDATE_P(ptr,drun,p,in) (ptr)[0] = DENTRY(p,in)
3031 #else
3033 # define UPDATE_D(dict,drun,dv,p,in) \
3034 dict[ DINDEX(dv,p) + drun++ ] = DENTRY(p,in); drun &= DD_MASK
3035 # define UPDATE_I(dict,drun,index,p,in) \
3036 dict[ (index) + drun++ ] = DENTRY(p,in); drun &= DD_MASK
3037 # define UPDATE_P(ptr,drun,p,in) \
3038 (ptr) [ drun++ ] = DENTRY(p,in); drun &= DD_MASK
3040 #endif
3042 #if (LZO_DICT_USE_PTR)
3044 #define LZO_CHECK_MPOS_DET(m_pos,m_off,in,ip,max_offset) \
3045 (m_pos == NULL || (m_off = pd(ip, m_pos)) > max_offset)
3047 #define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \
3048 (BOUNDS_CHECKING_OFF_IN_EXPR(( \
3049 m_pos = ip - (lzo_uint) PTR_DIFF(ip,m_pos), \
3050 PTR_LT(m_pos,in) || \
3051 (m_off = (lzo_uint) PTR_DIFF(ip,m_pos)) == 0 || \
3052 m_off > max_offset )))
3054 #else
3056 #define LZO_CHECK_MPOS_DET(m_pos,m_off,in,ip,max_offset) \
3057 (m_off == 0 || \
3058 ((m_off = pd(ip, in) - m_off) > max_offset) || \
3059 (m_pos = (ip) - (m_off), 0) )
3061 #define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \
3062 (pd(ip, in) <= m_off || \
3063 ((m_off = pd(ip, in) - m_off) > max_offset) || \
3064 (m_pos = (ip) - (m_off), 0) )
3066 #endif
3068 #if (LZO_DETERMINISTIC)
3069 # define LZO_CHECK_MPOS LZO_CHECK_MPOS_DET
3070 #else
3071 # define LZO_CHECK_MPOS LZO_CHECK_MPOS_NON_DET
3072 #endif
3074 #ifdef __cplusplus
3076 #endif
3078 #endif
3080 #endif
3082 #endif
3084 #define LZO_DETERMINISTIC !(LZO_DICT_USE_PTR)
3086 #ifndef DO_COMPRESS
3087 #define DO_COMPRESS lzo1x_1_compress
3088 #endif
3090 #if 1 && defined(DO_COMPRESS) && !defined(do_compress)
3091 # define do_compress LZO_CPP_ECONCAT2(DO_COMPRESS,_core)
3092 #endif
3094 #if defined(UA_GET64)
3095 # define WANT_lzo_bitops_ctz64 1
3096 #elif defined(UA_GET32)
3097 # define WANT_lzo_bitops_ctz32 1
3098 #endif
3100 #if (defined(_WIN32) || defined(_WIN64)) && ((LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || (LZO_CC_MSC && (_MSC_VER >= 1400)))
3101 #include <intrin.h>
3102 #if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32) && 0
3103 #pragma intrinsic(_BitScanReverse)
3104 static __lzo_inline unsigned lzo_bitops_clz32(lzo_uint32 v)
3106 unsigned long r;
3107 (void) _BitScanReverse(&r, v);
3108 return (unsigned) r;
3110 #define lzo_bitops_clz32 lzo_bitops_clz32
3111 #endif
3112 #if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX) && 0
3113 #pragma intrinsic(_BitScanReverse64)
3114 static __lzo_inline unsigned lzo_bitops_clz64(lzo_uint64 v)
3116 unsigned long r;
3117 (void) _BitScanReverse64(&r, v);
3118 return (unsigned) r;
3120 #define lzo_bitops_clz64 lzo_bitops_clz64
3121 #endif
3122 #if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32)
3123 #pragma intrinsic(_BitScanForward)
3124 static __lzo_inline unsigned lzo_bitops_ctz32(lzo_uint32 v)
3126 unsigned long r;
3127 (void) _BitScanForward(&r, v);
3128 return (unsigned) r;
3130 #define lzo_bitops_ctz32 lzo_bitops_ctz32
3131 #endif
3132 #if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX)
3133 #pragma intrinsic(_BitScanForward64)
3134 static __lzo_inline unsigned lzo_bitops_ctz64(lzo_uint64 v)
3136 unsigned long r;
3137 (void) _BitScanForward64(&r, v);
3138 return (unsigned) r;
3140 #define lzo_bitops_ctz64 lzo_bitops_ctz64
3141 #endif
3143 #elif (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x030400ul) || (LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || LZO_CC_LLVM)
3144 #if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32)
3145 #define lzo_bitops_clz32(v) ((unsigned) __builtin_clz(v))
3146 #endif
3147 #if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX)
3148 #define lzo_bitops_clz64(v) ((unsigned) __builtin_clzll(v))
3149 #endif
3150 #if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32)
3151 #define lzo_bitops_ctz32(v) ((unsigned) __builtin_ctz(v))
3152 #endif
3153 #if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX)
3154 #define lzo_bitops_ctz64(v) ((unsigned) __builtin_ctzll(v))
3155 #endif
3156 #if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount32)
3157 #define lzo_bitops_popcount32(v) ((unsigned) __builtin_popcount(v))
3158 #endif
3159 #if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount64) && defined(LZO_UINT64_MAX)
3160 #define lzo_bitops_popcount64(v) ((unsigned) __builtin_popcountll(v))
3161 #endif
3162 #endif
3164 static __lzo_noinline lzo_uint
3165 do_compress ( const lzo_bytep in , lzo_uint in_len,
3166 lzo_bytep out, lzo_uintp out_len,
3167 lzo_uint ti, lzo_voidp wrkmem)
3169 register const lzo_bytep ip;
3170 lzo_bytep op;
3171 const lzo_bytep const in_end = in + in_len;
3172 const lzo_bytep const ip_end = in + in_len - 20;
3173 const lzo_bytep ii;
3174 lzo_dict_p const dict = (lzo_dict_p) wrkmem;
3176 op = out;
3177 ip = in;
3178 ii = ip - ti;
3180 ip += ti < 4 ? 4 - ti : 0;
3181 for (;;)
3183 const lzo_bytep m_pos;
3184 #if !(LZO_DETERMINISTIC)
3185 LZO_DEFINE_UNINITIALIZED_VAR(lzo_uint, m_off, 0);
3186 lzo_uint m_len;
3187 lzo_uint dindex;
3188 next:
3189 if __lzo_unlikely(ip >= ip_end)
3190 break;
3191 DINDEX1(dindex,ip);
3192 GINDEX(m_pos,m_off,dict,dindex,in);
3193 if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET))
3194 goto literal;
3195 #if 1
3196 if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
3197 goto try_match;
3198 DINDEX2(dindex,ip);
3199 #endif
3200 GINDEX(m_pos,m_off,dict,dindex,in);
3201 if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET))
3202 goto literal;
3203 if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
3204 goto try_match;
3205 goto literal;
3207 try_match:
3208 #if defined(UA_GET32)
3209 if (UA_GET32(m_pos) != UA_GET32(ip))
3210 #else
3211 if (m_pos[0] != ip[0] || m_pos[1] != ip[1] || m_pos[2] != ip[2] || m_pos[3] != ip[3])
3212 #endif
3214 literal:
3215 UPDATE_I(dict,0,dindex,ip,in);
3216 ip += 1 + ((ip - ii) >> 5);
3217 continue;
3219 UPDATE_I(dict,0,dindex,ip,in);
3220 #else
3221 lzo_uint m_off;
3222 lzo_uint m_len;
3224 lzo_uint32 dv;
3225 lzo_uint dindex;
3226 literal:
3227 ip += 1 + ((ip - ii) >> 5);
3228 next:
3229 if __lzo_unlikely(ip >= ip_end)
3230 break;
3231 dv = UA_GET32(ip);
3232 dindex = DINDEX(dv,ip);
3233 GINDEX(m_off,m_pos,in+dict,dindex,in);
3234 UPDATE_I(dict,0,dindex,ip,in);
3235 if __lzo_unlikely(dv != UA_GET32(m_pos))
3236 goto literal;
3238 #endif
3241 register lzo_uint t = pd(ip,ii);
3242 if (t != 0)
3244 if (t <= 3)
3246 op[-2] |= LZO_BYTE(t);
3247 #if defined(UA_COPY32)
3248 UA_COPY32(op, ii);
3249 op += t;
3250 #else
3251 { do *op++ = *ii++; while (--t > 0); }
3252 #endif
3254 #if defined(UA_COPY32) || defined(UA_COPY64)
3255 else if (t <= 16)
3257 *op++ = LZO_BYTE(t - 3);
3258 #if defined(UA_COPY64)
3259 UA_COPY64(op, ii);
3260 UA_COPY64(op+8, ii+8);
3261 #else
3262 UA_COPY32(op, ii);
3263 UA_COPY32(op+4, ii+4);
3264 UA_COPY32(op+8, ii+8);
3265 UA_COPY32(op+12, ii+12);
3266 #endif
3267 op += t;
3269 #endif
3270 else
3272 if (t <= 18)
3273 *op++ = LZO_BYTE(t - 3);
3274 else
3276 register lzo_uint tt = t - 18;
3277 *op++ = 0;
3278 while __lzo_unlikely(tt > 255)
3280 tt -= 255;
3281 #if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400))
3282 * (volatile unsigned char *) op++ = 0;
3283 #else
3284 *op++ = 0;
3285 #endif
3287 assert(tt > 0);
3288 *op++ = LZO_BYTE(tt);
3290 #if defined(UA_COPY32) || defined(UA_COPY64)
3291 do {
3292 #if defined(UA_COPY64)
3293 UA_COPY64(op, ii);
3294 UA_COPY64(op+8, ii+8);
3295 #else
3296 UA_COPY32(op, ii);
3297 UA_COPY32(op+4, ii+4);
3298 UA_COPY32(op+8, ii+8);
3299 UA_COPY32(op+12, ii+12);
3300 #endif
3301 op += 16; ii += 16; t -= 16;
3302 } while (t >= 16); if (t > 0)
3303 #endif
3304 { do *op++ = *ii++; while (--t > 0); }
3308 m_len = 4;
3310 #if defined(UA_GET64)
3311 lzo_uint64 v;
3312 v = UA_GET64(ip + m_len) ^ UA_GET64(m_pos + m_len);
3313 if __lzo_unlikely(v == 0) {
3314 do {
3315 m_len += 8;
3316 v = UA_GET64(ip + m_len) ^ UA_GET64(m_pos + m_len);
3317 if __lzo_unlikely(ip + m_len >= ip_end)
3318 goto m_len_done;
3319 } while (v == 0);
3321 #if (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_ctz64)
3322 m_len += lzo_bitops_ctz64(v) / CHAR_BIT;
3323 #elif (LZO_ABI_LITTLE_ENDIAN)
3324 if ((v & UCHAR_MAX) == 0) do {
3325 v >>= CHAR_BIT;
3326 m_len += 1;
3327 } while ((v & UCHAR_MAX) == 0);
3328 #else
3329 if (ip[m_len] == m_pos[m_len]) do {
3330 m_len += 1;
3331 } while (ip[m_len] == m_pos[m_len]);
3332 #endif
3333 #elif defined(UA_GET32)
3334 lzo_uint32 v;
3335 v = UA_GET32(ip + m_len) ^ UA_GET32(m_pos + m_len);
3336 if __lzo_unlikely(v == 0) {
3337 do {
3338 m_len += 4;
3339 v = UA_GET32(ip + m_len) ^ UA_GET32(m_pos + m_len);
3340 if __lzo_unlikely(ip + m_len >= ip_end)
3341 goto m_len_done;
3342 } while (v == 0);
3344 #if (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_ctz32)
3345 m_len += lzo_bitops_ctz32(v) / CHAR_BIT;
3346 #elif (LZO_ABI_LITTLE_ENDIAN)
3347 if ((v & UCHAR_MAX) == 0) do {
3348 v >>= CHAR_BIT;
3349 m_len += 1;
3350 } while ((v & UCHAR_MAX) == 0);
3351 #else
3352 if (ip[m_len] == m_pos[m_len]) do {
3353 m_len += 1;
3354 } while (ip[m_len] == m_pos[m_len]);
3355 #endif
3356 #else
3357 if __lzo_unlikely(ip[m_len] == m_pos[m_len]) {
3358 do {
3359 m_len += 1;
3360 if __lzo_unlikely(ip + m_len >= ip_end)
3361 goto m_len_done;
3362 } while (ip[m_len] == m_pos[m_len]);
3364 #endif
3366 m_len_done:
3367 m_off = pd(ip,m_pos);
3368 ip += m_len;
3369 ii = ip;
3370 if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
3372 m_off -= 1;
3373 #if defined(LZO1X)
3374 *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2));
3375 *op++ = LZO_BYTE(m_off >> 3);
3376 #elif defined(LZO1Y)
3377 *op++ = LZO_BYTE(((m_len + 1) << 4) | ((m_off & 3) << 2));
3378 *op++ = LZO_BYTE(m_off >> 2);
3379 #endif
3381 else if (m_off <= M3_MAX_OFFSET)
3383 m_off -= 1;
3384 if (m_len <= M3_MAX_LEN)
3385 *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
3386 else
3388 m_len -= M3_MAX_LEN;
3389 *op++ = M3_MARKER | 0;
3390 while __lzo_unlikely(m_len > 255)
3392 m_len -= 255;
3393 #if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400))
3394 * (volatile unsigned char *) op++ = 0;
3395 #else
3396 *op++ = 0;
3397 #endif
3399 *op++ = LZO_BYTE(m_len);
3401 *op++ = LZO_BYTE(m_off << 2);
3402 *op++ = LZO_BYTE(m_off >> 6);
3404 else
3406 m_off -= 0x4000;
3407 if (m_len <= M4_MAX_LEN)
3408 *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8) | (m_len - 2));
3409 else
3411 m_len -= M4_MAX_LEN;
3412 *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8));
3413 while __lzo_unlikely(m_len > 255)
3415 m_len -= 255;
3416 #if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400))
3417 * (volatile unsigned char *) op++ = 0;
3418 #else
3419 *op++ = 0;
3420 #endif
3422 *op++ = LZO_BYTE(m_len);
3424 *op++ = LZO_BYTE(m_off << 2);
3425 *op++ = LZO_BYTE(m_off >> 6);
3427 goto next;
3430 *out_len = pd(op, out);
3431 return pd(in_end,ii);
3434 LZO_PUBLIC(int)
3435 DO_COMPRESS ( const lzo_bytep in , lzo_uint in_len,
3436 lzo_bytep out, lzo_uintp out_len,
3437 lzo_voidp wrkmem )
3439 const lzo_bytep ip = in;
3440 lzo_bytep op = out;
3441 lzo_uint l = in_len;
3442 lzo_uint t = 0;
3444 while (l > 20)
3446 lzo_uint ll = l;
3447 lzo_uintptr_t ll_end;
3448 #if 0 || (LZO_DETERMINISTIC)
3449 ll = LZO_MIN(ll, 49152);
3450 #endif
3451 ll_end = (lzo_uintptr_t)ip + ll;
3452 if ((ll_end + ((t + ll) >> 5)) <= ll_end || (const lzo_bytep)(ll_end + ((t + ll) >> 5)) <= ip + ll)
3453 break;
3454 #if (LZO_DETERMINISTIC)
3455 lzo_memset(wrkmem, 0, ((lzo_uint)1 << D_BITS) * sizeof(lzo_dict_t));
3456 #endif
3457 t = do_compress(ip,ll,op,out_len,t,wrkmem);
3458 ip += ll;
3459 op += *out_len;
3460 l -= ll;
3462 t += l;
3464 if (t > 0)
3466 const lzo_bytep ii = in + in_len - t;
3468 if (op == out && t <= 238)
3469 *op++ = LZO_BYTE(17 + t);
3470 else if (t <= 3)
3471 op[-2] |= LZO_BYTE(t);
3472 else if (t <= 18)
3473 *op++ = LZO_BYTE(t - 3);
3474 else
3476 lzo_uint tt = t - 18;
3478 *op++ = 0;
3479 while (tt > 255)
3481 tt -= 255;
3482 #if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400))
3484 * (volatile unsigned char *) op++ = 0;
3485 #else
3486 *op++ = 0;
3487 #endif
3489 assert(tt > 0);
3490 *op++ = LZO_BYTE(tt);
3492 do *op++ = *ii++; while (--t > 0);
3495 *op++ = M4_MARKER | 1;
3496 *op++ = 0;
3497 *op++ = 0;
3499 *out_len = pd(op, out);
3500 return LZO_E_OK;
3503 #endif
3505 #undef do_compress
3506 #undef DO_COMPRESS
3507 #undef LZO_HASH
3509 #undef LZO_TEST_OVERRUN
3510 #undef DO_DECOMPRESS
3511 #define DO_DECOMPRESS lzo1x_decompress
3513 #if !defined(MINILZO_CFG_SKIP_LZO1X_DECOMPRESS)
3515 #if defined(LZO_TEST_OVERRUN)
3516 # if !defined(LZO_TEST_OVERRUN_INPUT)
3517 # define LZO_TEST_OVERRUN_INPUT 2
3518 # endif
3519 # if !defined(LZO_TEST_OVERRUN_OUTPUT)
3520 # define LZO_TEST_OVERRUN_OUTPUT 2
3521 # endif
3522 # if !defined(LZO_TEST_OVERRUN_LOOKBEHIND)
3523 # define LZO_TEST_OVERRUN_LOOKBEHIND 1
3524 # endif
3525 #endif
3527 #undef TEST_IP
3528 #undef TEST_OP
3529 #undef TEST_LB
3530 #undef TEST_LBO
3531 #undef NEED_IP
3532 #undef NEED_OP
3533 #undef HAVE_TEST_IP
3534 #undef HAVE_TEST_OP
3535 #undef HAVE_NEED_IP
3536 #undef HAVE_NEED_OP
3537 #undef HAVE_ANY_IP
3538 #undef HAVE_ANY_OP
3540 #if defined(LZO_TEST_OVERRUN_INPUT)
3541 # if (LZO_TEST_OVERRUN_INPUT >= 1)
3542 # define TEST_IP (ip < ip_end)
3543 # endif
3544 # if (LZO_TEST_OVERRUN_INPUT >= 2)
3545 # define NEED_IP(x) \
3546 if ((lzo_uint)(ip_end - ip) < (lzo_uint)(x)) goto input_overrun
3547 # endif
3548 #endif
3550 #if defined(LZO_TEST_OVERRUN_OUTPUT)
3551 # if (LZO_TEST_OVERRUN_OUTPUT >= 1)
3552 # define TEST_OP (op <= op_end)
3553 # endif
3554 # if (LZO_TEST_OVERRUN_OUTPUT >= 2)
3555 # undef TEST_OP
3556 # define NEED_OP(x) \
3557 if ((lzo_uint)(op_end - op) < (lzo_uint)(x)) goto output_overrun
3558 # endif
3559 #endif
3561 #if defined(LZO_TEST_OVERRUN_LOOKBEHIND)
3562 # define TEST_LB(m_pos) if (m_pos < out || m_pos >= op) goto lookbehind_overrun
3563 # define TEST_LBO(m_pos,o) if (m_pos < out || m_pos >= op - (o)) goto lookbehind_overrun
3564 #else
3565 # define TEST_LB(m_pos) ((void) 0)
3566 # define TEST_LBO(m_pos,o) ((void) 0)
3567 #endif
3569 #if !defined(LZO_EOF_CODE) && !defined(TEST_IP)
3570 # define TEST_IP (ip < ip_end)
3571 #endif
3573 #if defined(TEST_IP)
3574 # define HAVE_TEST_IP 1
3575 #else
3576 # define TEST_IP 1
3577 #endif
3578 #if defined(TEST_OP)
3579 # define HAVE_TEST_OP 1
3580 #else
3581 # define TEST_OP 1
3582 #endif
3584 #if defined(NEED_IP)
3585 # define HAVE_NEED_IP 1
3586 #else
3587 # define NEED_IP(x) ((void) 0)
3588 #endif
3589 #if defined(NEED_OP)
3590 # define HAVE_NEED_OP 1
3591 #else
3592 # define NEED_OP(x) ((void) 0)
3593 #endif
3595 #if defined(HAVE_TEST_IP) || defined(HAVE_NEED_IP)
3596 # define HAVE_ANY_IP 1
3597 #endif
3598 #if defined(HAVE_TEST_OP) || defined(HAVE_NEED_OP)
3599 # define HAVE_ANY_OP 1
3600 #endif
3602 #if defined(DO_DECOMPRESS)
3603 LZO_PUBLIC(int)
3604 DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len,
3605 lzo_bytep out, lzo_uintp out_len,
3606 lzo_voidp wrkmem )
3607 #endif
3609 register lzo_bytep op;
3610 register const lzo_bytep ip;
3611 register lzo_uint t;
3612 #if defined(COPY_DICT)
3613 lzo_uint m_off;
3614 const lzo_bytep dict_end;
3615 #else
3616 register const lzo_bytep m_pos;
3617 #endif
3619 const lzo_bytep const ip_end = in + in_len;
3620 #if defined(HAVE_ANY_OP)
3621 lzo_bytep const op_end = out + *out_len;
3622 #endif
3623 #if defined(LZO1Z)
3624 lzo_uint last_m_off = 0;
3625 #endif
3627 LZO_UNUSED(wrkmem);
3629 #if defined(COPY_DICT)
3630 if (dict)
3632 if (dict_len > M4_MAX_OFFSET)
3634 dict += dict_len - M4_MAX_OFFSET;
3635 dict_len = M4_MAX_OFFSET;
3637 dict_end = dict + dict_len;
3639 else
3641 dict_len = 0;
3642 dict_end = NULL;
3644 #endif
3646 *out_len = 0;
3648 op = out;
3649 ip = in;
3651 if (*ip > 17)
3653 t = *ip++ - 17;
3654 if (t < 4)
3655 goto match_next;
3656 assert(t > 0); NEED_OP(t); NEED_IP(t+1);
3657 do *op++ = *ip++; while (--t > 0);
3658 goto first_literal_run;
3661 while (TEST_IP && TEST_OP)
3663 t = *ip++;
3664 if (t >= 16)
3665 goto match;
3666 if (t == 0)
3668 NEED_IP(1);
3669 while (*ip == 0)
3671 t += 255;
3672 ip++;
3673 NEED_IP(1);
3675 t += 15 + *ip++;
3677 assert(t > 0); NEED_OP(t+3); NEED_IP(t+4);
3678 #if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4)
3679 t += 3;
3680 if (t >= 8) do
3682 UA_COPY64(op,ip);
3683 op += 8; ip += 8; t -= 8;
3684 } while (t >= 8);
3685 if (t >= 4)
3687 UA_COPY32(op,ip);
3688 op += 4; ip += 4; t -= 4;
3690 if (t > 0)
3692 *op++ = *ip++;
3693 if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } }
3695 #elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
3696 #if !defined(LZO_UNALIGNED_OK_4)
3697 if (PTR_ALIGNED2_4(op,ip))
3699 #endif
3700 UA_COPY32(op,ip);
3701 op += 4; ip += 4;
3702 if (--t > 0)
3704 if (t >= 4)
3706 do {
3707 UA_COPY32(op,ip);
3708 op += 4; ip += 4; t -= 4;
3709 } while (t >= 4);
3710 if (t > 0) do *op++ = *ip++; while (--t > 0);
3712 else
3713 do *op++ = *ip++; while (--t > 0);
3715 #if !defined(LZO_UNALIGNED_OK_4)
3717 else
3718 #endif
3719 #endif
3720 #if !defined(LZO_UNALIGNED_OK_4) && !defined(LZO_UNALIGNED_OK_8)
3722 *op++ = *ip++; *op++ = *ip++; *op++ = *ip++;
3723 do *op++ = *ip++; while (--t > 0);
3725 #endif
3727 first_literal_run:
3729 t = *ip++;
3730 if (t >= 16)
3731 goto match;
3732 #if defined(COPY_DICT)
3733 #if defined(LZO1Z)
3734 m_off = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2);
3735 last_m_off = m_off;
3736 #else
3737 m_off = (1 + M2_MAX_OFFSET) + (t >> 2) + (*ip++ << 2);
3738 #endif
3739 NEED_OP(3);
3740 t = 3; COPY_DICT(t,m_off)
3741 #else
3742 #if defined(LZO1Z)
3743 t = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2);
3744 m_pos = op - t;
3745 last_m_off = t;
3746 #else
3747 m_pos = op - (1 + M2_MAX_OFFSET);
3748 m_pos -= t >> 2;
3749 m_pos -= *ip++ << 2;
3750 #endif
3751 TEST_LB(m_pos); NEED_OP(3);
3752 *op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos;
3753 #endif
3754 goto match_done;
3756 do {
3757 match:
3758 if (t >= 64)
3760 #if defined(COPY_DICT)
3761 #if defined(LZO1X)
3762 m_off = 1 + ((t >> 2) & 7) + (*ip++ << 3);
3763 t = (t >> 5) - 1;
3764 #elif defined(LZO1Y)
3765 m_off = 1 + ((t >> 2) & 3) + (*ip++ << 2);
3766 t = (t >> 4) - 3;
3767 #elif defined(LZO1Z)
3768 m_off = t & 0x1f;
3769 if (m_off >= 0x1c)
3770 m_off = last_m_off;
3771 else
3773 m_off = 1 + (m_off << 6) + (*ip++ >> 2);
3774 last_m_off = m_off;
3776 t = (t >> 5) - 1;
3777 #endif
3778 #else
3779 #if defined(LZO1X)
3780 m_pos = op - 1;
3781 m_pos -= (t >> 2) & 7;
3782 m_pos -= *ip++ << 3;
3783 t = (t >> 5) - 1;
3784 #elif defined(LZO1Y)
3785 m_pos = op - 1;
3786 m_pos -= (t >> 2) & 3;
3787 m_pos -= *ip++ << 2;
3788 t = (t >> 4) - 3;
3789 #elif defined(LZO1Z)
3791 lzo_uint off = t & 0x1f;
3792 m_pos = op;
3793 if (off >= 0x1c)
3795 assert(last_m_off > 0);
3796 m_pos -= last_m_off;
3798 else
3800 off = 1 + (off << 6) + (*ip++ >> 2);
3801 m_pos -= off;
3802 last_m_off = off;
3805 t = (t >> 5) - 1;
3806 #endif
3807 TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1);
3808 goto copy_match;
3809 #endif
3811 else if (t >= 32)
3813 t &= 31;
3814 if (t == 0)
3816 NEED_IP(1);
3817 while (*ip == 0)
3819 t += 255;
3820 ip++;
3821 NEED_IP(1);
3823 t += 31 + *ip++;
3825 #if defined(COPY_DICT)
3826 #if defined(LZO1Z)
3827 m_off = 1 + (ip[0] << 6) + (ip[1] >> 2);
3828 last_m_off = m_off;
3829 #else
3830 m_off = 1 + (ip[0] >> 2) + (ip[1] << 6);
3831 #endif
3832 #else
3833 #if defined(LZO1Z)
3835 lzo_uint off = 1 + (ip[0] << 6) + (ip[1] >> 2);
3836 m_pos = op - off;
3837 last_m_off = off;
3839 #elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN)
3840 m_pos = op - 1;
3841 m_pos -= UA_GET16(ip) >> 2;
3842 #else
3843 m_pos = op - 1;
3844 m_pos -= (ip[0] >> 2) + (ip[1] << 6);
3845 #endif
3846 #endif
3847 ip += 2;
3849 else if (t >= 16)
3851 #if defined(COPY_DICT)
3852 m_off = (t & 8) << 11;
3853 #else
3854 m_pos = op;
3855 m_pos -= (t & 8) << 11;
3856 #endif
3857 t &= 7;
3858 if (t == 0)
3860 NEED_IP(1);
3861 while (*ip == 0)
3863 t += 255;
3864 ip++;
3865 NEED_IP(1);
3867 t += 7 + *ip++;
3869 #if defined(COPY_DICT)
3870 #if defined(LZO1Z)
3871 m_off += (ip[0] << 6) + (ip[1] >> 2);
3872 #else
3873 m_off += (ip[0] >> 2) + (ip[1] << 6);
3874 #endif
3875 ip += 2;
3876 if (m_off == 0)
3877 goto eof_found;
3878 m_off += 0x4000;
3879 #if defined(LZO1Z)
3880 last_m_off = m_off;
3881 #endif
3882 #else
3883 #if defined(LZO1Z)
3884 m_pos -= (ip[0] << 6) + (ip[1] >> 2);
3885 #elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN)
3886 m_pos -= UA_GET16(ip) >> 2;
3887 #else
3888 m_pos -= (ip[0] >> 2) + (ip[1] << 6);
3889 #endif
3890 ip += 2;
3891 if (m_pos == op)
3892 goto eof_found;
3893 m_pos -= 0x4000;
3894 #if defined(LZO1Z)
3895 last_m_off = pd((const lzo_bytep)op, m_pos);
3896 #endif
3897 #endif
3899 else
3901 #if defined(COPY_DICT)
3902 #if defined(LZO1Z)
3903 m_off = 1 + (t << 6) + (*ip++ >> 2);
3904 last_m_off = m_off;
3905 #else
3906 m_off = 1 + (t >> 2) + (*ip++ << 2);
3907 #endif
3908 NEED_OP(2);
3909 t = 2; COPY_DICT(t,m_off)
3910 #else
3911 #if defined(LZO1Z)
3912 t = 1 + (t << 6) + (*ip++ >> 2);
3913 m_pos = op - t;
3914 last_m_off = t;
3915 #else
3916 m_pos = op - 1;
3917 m_pos -= t >> 2;
3918 m_pos -= *ip++ << 2;
3919 #endif
3920 TEST_LB(m_pos); NEED_OP(2);
3921 *op++ = *m_pos++; *op++ = *m_pos;
3922 #endif
3923 goto match_done;
3926 #if defined(COPY_DICT)
3928 NEED_OP(t+3-1);
3929 t += 3-1; COPY_DICT(t,m_off)
3931 #else
3933 TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1);
3934 #if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4)
3935 if (op - m_pos >= 8)
3937 t += (3 - 1);
3938 if (t >= 8) do
3940 UA_COPY64(op,m_pos);
3941 op += 8; m_pos += 8; t -= 8;
3942 } while (t >= 8);
3943 if (t >= 4)
3945 UA_COPY32(op,m_pos);
3946 op += 4; m_pos += 4; t -= 4;
3948 if (t > 0)
3950 *op++ = m_pos[0];
3951 if (t > 1) { *op++ = m_pos[1]; if (t > 2) { *op++ = m_pos[2]; } }
3954 else
3955 #elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
3956 #if !defined(LZO_UNALIGNED_OK_4)
3957 if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos))
3959 assert((op - m_pos) >= 4);
3960 #else
3961 if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4)
3963 #endif
3964 UA_COPY32(op,m_pos);
3965 op += 4; m_pos += 4; t -= 4 - (3 - 1);
3966 do {
3967 UA_COPY32(op,m_pos);
3968 op += 4; m_pos += 4; t -= 4;
3969 } while (t >= 4);
3970 if (t > 0) do *op++ = *m_pos++; while (--t > 0);
3972 else
3973 #endif
3975 copy_match:
3976 *op++ = *m_pos++; *op++ = *m_pos++;
3977 do *op++ = *m_pos++; while (--t > 0);
3980 #endif
3982 match_done:
3983 #if defined(LZO1Z)
3984 t = ip[-1] & 3;
3985 #else
3986 t = ip[-2] & 3;
3987 #endif
3988 if (t == 0)
3989 break;
3991 match_next:
3992 assert(t > 0); assert(t < 4); NEED_OP(t); NEED_IP(t+1);
3993 #if 0
3994 do *op++ = *ip++; while (--t > 0);
3995 #else
3996 *op++ = *ip++;
3997 if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } }
3998 #endif
3999 t = *ip++;
4000 } while (TEST_IP && TEST_OP);
4003 #if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP)
4004 *out_len = pd(op, out);
4005 return LZO_E_EOF_NOT_FOUND;
4006 #endif
4008 eof_found:
4009 assert(t == 1);
4010 *out_len = pd(op, out);
4011 return (ip == ip_end ? LZO_E_OK :
4012 (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN));
4014 #if defined(HAVE_NEED_IP)
4015 input_overrun:
4016 *out_len = pd(op, out);
4017 return LZO_E_INPUT_OVERRUN;
4018 #endif
4020 #if defined(HAVE_NEED_OP)
4021 output_overrun:
4022 *out_len = pd(op, out);
4023 return LZO_E_OUTPUT_OVERRUN;
4024 #endif
4026 #if defined(LZO_TEST_OVERRUN_LOOKBEHIND)
4027 lookbehind_overrun:
4028 *out_len = pd(op, out);
4029 return LZO_E_LOOKBEHIND_OVERRUN;
4030 #endif
4033 #endif
4035 #define LZO_TEST_OVERRUN 1
4036 #undef DO_DECOMPRESS
4037 #define DO_DECOMPRESS lzo1x_decompress_safe
4039 #if !defined(MINILZO_CFG_SKIP_LZO1X_DECOMPRESS_SAFE)
4041 #if defined(LZO_TEST_OVERRUN)
4042 # if !defined(LZO_TEST_OVERRUN_INPUT)
4043 # define LZO_TEST_OVERRUN_INPUT 2
4044 # endif
4045 # if !defined(LZO_TEST_OVERRUN_OUTPUT)
4046 # define LZO_TEST_OVERRUN_OUTPUT 2
4047 # endif
4048 # if !defined(LZO_TEST_OVERRUN_LOOKBEHIND)
4049 # define LZO_TEST_OVERRUN_LOOKBEHIND 1
4050 # endif
4051 #endif
4053 #undef TEST_IP
4054 #undef TEST_OP
4055 #undef TEST_LB
4056 #undef TEST_LBO
4057 #undef NEED_IP
4058 #undef NEED_OP
4059 #undef HAVE_TEST_IP
4060 #undef HAVE_TEST_OP
4061 #undef HAVE_NEED_IP
4062 #undef HAVE_NEED_OP
4063 #undef HAVE_ANY_IP
4064 #undef HAVE_ANY_OP
4066 #if defined(LZO_TEST_OVERRUN_INPUT)
4067 # if (LZO_TEST_OVERRUN_INPUT >= 1)
4068 # define TEST_IP (ip < ip_end)
4069 # endif
4070 # if (LZO_TEST_OVERRUN_INPUT >= 2)
4071 # define NEED_IP(x) \
4072 if ((lzo_uint)(ip_end - ip) < (lzo_uint)(x)) goto input_overrun
4073 # endif
4074 #endif
4076 #if defined(LZO_TEST_OVERRUN_OUTPUT)
4077 # if (LZO_TEST_OVERRUN_OUTPUT >= 1)
4078 # define TEST_OP (op <= op_end)
4079 # endif
4080 # if (LZO_TEST_OVERRUN_OUTPUT >= 2)
4081 # undef TEST_OP
4082 # define NEED_OP(x) \
4083 if ((lzo_uint)(op_end - op) < (lzo_uint)(x)) goto output_overrun
4084 # endif
4085 #endif
4087 #if defined(LZO_TEST_OVERRUN_LOOKBEHIND)
4088 # define TEST_LB(m_pos) if (m_pos < out || m_pos >= op) goto lookbehind_overrun
4089 # define TEST_LBO(m_pos,o) if (m_pos < out || m_pos >= op - (o)) goto lookbehind_overrun
4090 #else
4091 # define TEST_LB(m_pos) ((void) 0)
4092 # define TEST_LBO(m_pos,o) ((void) 0)
4093 #endif
4095 #if !defined(LZO_EOF_CODE) && !defined(TEST_IP)
4096 # define TEST_IP (ip < ip_end)
4097 #endif
4099 #if defined(TEST_IP)
4100 # define HAVE_TEST_IP 1
4101 #else
4102 # define TEST_IP 1
4103 #endif
4104 #if defined(TEST_OP)
4105 # define HAVE_TEST_OP 1
4106 #else
4107 # define TEST_OP 1
4108 #endif
4110 #if defined(NEED_IP)
4111 # define HAVE_NEED_IP 1
4112 #else
4113 # define NEED_IP(x) ((void) 0)
4114 #endif
4115 #if defined(NEED_OP)
4116 # define HAVE_NEED_OP 1
4117 #else
4118 # define NEED_OP(x) ((void) 0)
4119 #endif
4121 #if defined(HAVE_TEST_IP) || defined(HAVE_NEED_IP)
4122 # define HAVE_ANY_IP 1
4123 #endif
4124 #if defined(HAVE_TEST_OP) || defined(HAVE_NEED_OP)
4125 # define HAVE_ANY_OP 1
4126 #endif
4128 #if defined(DO_DECOMPRESS)
4129 LZO_PUBLIC(int)
4130 DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len,
4131 lzo_bytep out, lzo_uintp out_len,
4132 lzo_voidp wrkmem )
4133 #endif
4135 register lzo_bytep op;
4136 register const lzo_bytep ip;
4137 register lzo_uint t;
4138 #if defined(COPY_DICT)
4139 lzo_uint m_off;
4140 const lzo_bytep dict_end;
4141 #else
4142 register const lzo_bytep m_pos;
4143 #endif
4145 const lzo_bytep const ip_end = in + in_len;
4146 #if defined(HAVE_ANY_OP)
4147 lzo_bytep const op_end = out + *out_len;
4148 #endif
4149 #if defined(LZO1Z)
4150 lzo_uint last_m_off = 0;
4151 #endif
4153 LZO_UNUSED(wrkmem);
4155 #if defined(COPY_DICT)
4156 if (dict)
4158 if (dict_len > M4_MAX_OFFSET)
4160 dict += dict_len - M4_MAX_OFFSET;
4161 dict_len = M4_MAX_OFFSET;
4163 dict_end = dict + dict_len;
4165 else
4167 dict_len = 0;
4168 dict_end = NULL;
4170 #endif
4172 *out_len = 0;
4174 op = out;
4175 ip = in;
4177 if (*ip > 17)
4179 t = *ip++ - 17;
4180 if (t < 4)
4181 goto match_next;
4182 assert(t > 0); NEED_OP(t); NEED_IP(t+1);
4183 do *op++ = *ip++; while (--t > 0);
4184 goto first_literal_run;
4187 while (TEST_IP && TEST_OP)
4189 t = *ip++;
4190 if (t >= 16)
4191 goto match;
4192 if (t == 0)
4194 NEED_IP(1);
4195 while (*ip == 0)
4197 t += 255;
4198 ip++;
4199 NEED_IP(1);
4201 t += 15 + *ip++;
4203 assert(t > 0); NEED_OP(t+3); NEED_IP(t+4);
4204 #if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4)
4205 t += 3;
4206 if (t >= 8) do
4208 UA_COPY64(op,ip);
4209 op += 8; ip += 8; t -= 8;
4210 } while (t >= 8);
4211 if (t >= 4)
4213 UA_COPY32(op,ip);
4214 op += 4; ip += 4; t -= 4;
4216 if (t > 0)
4218 *op++ = *ip++;
4219 if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } }
4221 #elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
4222 #if !defined(LZO_UNALIGNED_OK_4)
4223 if (PTR_ALIGNED2_4(op,ip))
4225 #endif
4226 UA_COPY32(op,ip);
4227 op += 4; ip += 4;
4228 if (--t > 0)
4230 if (t >= 4)
4232 do {
4233 UA_COPY32(op,ip);
4234 op += 4; ip += 4; t -= 4;
4235 } while (t >= 4);
4236 if (t > 0) do *op++ = *ip++; while (--t > 0);
4238 else
4239 do *op++ = *ip++; while (--t > 0);
4241 #if !defined(LZO_UNALIGNED_OK_4)
4243 else
4244 #endif
4245 #endif
4246 #if !defined(LZO_UNALIGNED_OK_4) && !defined(LZO_UNALIGNED_OK_8)
4248 *op++ = *ip++; *op++ = *ip++; *op++ = *ip++;
4249 do *op++ = *ip++; while (--t > 0);
4251 #endif
4253 first_literal_run:
4255 t = *ip++;
4256 if (t >= 16)
4257 goto match;
4258 #if defined(COPY_DICT)
4259 #if defined(LZO1Z)
4260 m_off = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2);
4261 last_m_off = m_off;
4262 #else
4263 m_off = (1 + M2_MAX_OFFSET) + (t >> 2) + (*ip++ << 2);
4264 #endif
4265 NEED_OP(3);
4266 t = 3; COPY_DICT(t,m_off)
4267 #else
4268 #if defined(LZO1Z)
4269 t = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2);
4270 m_pos = op - t;
4271 last_m_off = t;
4272 #else
4273 m_pos = op - (1 + M2_MAX_OFFSET);
4274 m_pos -= t >> 2;
4275 m_pos -= *ip++ << 2;
4276 #endif
4277 TEST_LB(m_pos); NEED_OP(3);
4278 *op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos;
4279 #endif
4280 goto match_done;
4282 do {
4283 match:
4284 if (t >= 64)
4286 #if defined(COPY_DICT)
4287 #if defined(LZO1X)
4288 m_off = 1 + ((t >> 2) & 7) + (*ip++ << 3);
4289 t = (t >> 5) - 1;
4290 #elif defined(LZO1Y)
4291 m_off = 1 + ((t >> 2) & 3) + (*ip++ << 2);
4292 t = (t >> 4) - 3;
4293 #elif defined(LZO1Z)
4294 m_off = t & 0x1f;
4295 if (m_off >= 0x1c)
4296 m_off = last_m_off;
4297 else
4299 m_off = 1 + (m_off << 6) + (*ip++ >> 2);
4300 last_m_off = m_off;
4302 t = (t >> 5) - 1;
4303 #endif
4304 #else
4305 #if defined(LZO1X)
4306 m_pos = op - 1;
4307 m_pos -= (t >> 2) & 7;
4308 m_pos -= *ip++ << 3;
4309 t = (t >> 5) - 1;
4310 #elif defined(LZO1Y)
4311 m_pos = op - 1;
4312 m_pos -= (t >> 2) & 3;
4313 m_pos -= *ip++ << 2;
4314 t = (t >> 4) - 3;
4315 #elif defined(LZO1Z)
4317 lzo_uint off = t & 0x1f;
4318 m_pos = op;
4319 if (off >= 0x1c)
4321 assert(last_m_off > 0);
4322 m_pos -= last_m_off;
4324 else
4326 off = 1 + (off << 6) + (*ip++ >> 2);
4327 m_pos -= off;
4328 last_m_off = off;
4331 t = (t >> 5) - 1;
4332 #endif
4333 TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1);
4334 goto copy_match;
4335 #endif
4337 else if (t >= 32)
4339 t &= 31;
4340 if (t == 0)
4342 NEED_IP(1);
4343 while (*ip == 0)
4345 t += 255;
4346 ip++;
4347 NEED_IP(1);
4349 t += 31 + *ip++;
4351 #if defined(COPY_DICT)
4352 #if defined(LZO1Z)
4353 m_off = 1 + (ip[0] << 6) + (ip[1] >> 2);
4354 last_m_off = m_off;
4355 #else
4356 m_off = 1 + (ip[0] >> 2) + (ip[1] << 6);
4357 #endif
4358 #else
4359 #if defined(LZO1Z)
4361 lzo_uint off = 1 + (ip[0] << 6) + (ip[1] >> 2);
4362 m_pos = op - off;
4363 last_m_off = off;
4365 #elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN)
4366 m_pos = op - 1;
4367 m_pos -= UA_GET16(ip) >> 2;
4368 #else
4369 m_pos = op - 1;
4370 m_pos -= (ip[0] >> 2) + (ip[1] << 6);
4371 #endif
4372 #endif
4373 ip += 2;
4375 else if (t >= 16)
4377 #if defined(COPY_DICT)
4378 m_off = (t & 8) << 11;
4379 #else
4380 m_pos = op;
4381 m_pos -= (t & 8) << 11;
4382 #endif
4383 t &= 7;
4384 if (t == 0)
4386 NEED_IP(1);
4387 while (*ip == 0)
4389 t += 255;
4390 ip++;
4391 NEED_IP(1);
4393 t += 7 + *ip++;
4395 #if defined(COPY_DICT)
4396 #if defined(LZO1Z)
4397 m_off += (ip[0] << 6) + (ip[1] >> 2);
4398 #else
4399 m_off += (ip[0] >> 2) + (ip[1] << 6);
4400 #endif
4401 ip += 2;
4402 if (m_off == 0)
4403 goto eof_found;
4404 m_off += 0x4000;
4405 #if defined(LZO1Z)
4406 last_m_off = m_off;
4407 #endif
4408 #else
4409 #if defined(LZO1Z)
4410 m_pos -= (ip[0] << 6) + (ip[1] >> 2);
4411 #elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN)
4412 m_pos -= UA_GET16(ip) >> 2;
4413 #else
4414 m_pos -= (ip[0] >> 2) + (ip[1] << 6);
4415 #endif
4416 ip += 2;
4417 if (m_pos == op)
4418 goto eof_found;
4419 m_pos -= 0x4000;
4420 #if defined(LZO1Z)
4421 last_m_off = pd((const lzo_bytep)op, m_pos);
4422 #endif
4423 #endif
4425 else
4427 #if defined(COPY_DICT)
4428 #if defined(LZO1Z)
4429 m_off = 1 + (t << 6) + (*ip++ >> 2);
4430 last_m_off = m_off;
4431 #else
4432 m_off = 1 + (t >> 2) + (*ip++ << 2);
4433 #endif
4434 NEED_OP(2);
4435 t = 2; COPY_DICT(t,m_off)
4436 #else
4437 #if defined(LZO1Z)
4438 t = 1 + (t << 6) + (*ip++ >> 2);
4439 m_pos = op - t;
4440 last_m_off = t;
4441 #else
4442 m_pos = op - 1;
4443 m_pos -= t >> 2;
4444 m_pos -= *ip++ << 2;
4445 #endif
4446 TEST_LB(m_pos); NEED_OP(2);
4447 *op++ = *m_pos++; *op++ = *m_pos;
4448 #endif
4449 goto match_done;
4452 #if defined(COPY_DICT)
4454 NEED_OP(t+3-1);
4455 t += 3-1; COPY_DICT(t,m_off)
4457 #else
4459 TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1);
4460 #if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4)
4461 if (op - m_pos >= 8)
4463 t += (3 - 1);
4464 if (t >= 8) do
4466 UA_COPY64(op,m_pos);
4467 op += 8; m_pos += 8; t -= 8;
4468 } while (t >= 8);
4469 if (t >= 4)
4471 UA_COPY32(op,m_pos);
4472 op += 4; m_pos += 4; t -= 4;
4474 if (t > 0)
4476 *op++ = m_pos[0];
4477 if (t > 1) { *op++ = m_pos[1]; if (t > 2) { *op++ = m_pos[2]; } }
4480 else
4481 #elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
4482 #if !defined(LZO_UNALIGNED_OK_4)
4483 if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos))
4485 assert((op - m_pos) >= 4);
4486 #else
4487 if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4)
4489 #endif
4490 UA_COPY32(op,m_pos);
4491 op += 4; m_pos += 4; t -= 4 - (3 - 1);
4492 do {
4493 UA_COPY32(op,m_pos);
4494 op += 4; m_pos += 4; t -= 4;
4495 } while (t >= 4);
4496 if (t > 0) do *op++ = *m_pos++; while (--t > 0);
4498 else
4499 #endif
4501 copy_match:
4502 *op++ = *m_pos++; *op++ = *m_pos++;
4503 do *op++ = *m_pos++; while (--t > 0);
4506 #endif
4508 match_done:
4509 #if defined(LZO1Z)
4510 t = ip[-1] & 3;
4511 #else
4512 t = ip[-2] & 3;
4513 #endif
4514 if (t == 0)
4515 break;
4517 match_next:
4518 assert(t > 0); assert(t < 4); NEED_OP(t); NEED_IP(t+1);
4519 #if 0
4520 do *op++ = *ip++; while (--t > 0);
4521 #else
4522 *op++ = *ip++;
4523 if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } }
4524 #endif
4525 t = *ip++;
4526 } while (TEST_IP && TEST_OP);
4529 #if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP)
4530 *out_len = pd(op, out);
4531 return LZO_E_EOF_NOT_FOUND;
4532 #endif
4534 eof_found:
4535 assert(t == 1);
4536 *out_len = pd(op, out);
4537 return (ip == ip_end ? LZO_E_OK :
4538 (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN));
4540 #if defined(HAVE_NEED_IP)
4541 input_overrun:
4542 *out_len = pd(op, out);
4543 return LZO_E_INPUT_OVERRUN;
4544 #endif
4546 #if defined(HAVE_NEED_OP)
4547 output_overrun:
4548 *out_len = pd(op, out);
4549 return LZO_E_OUTPUT_OVERRUN;
4550 #endif
4552 #if defined(LZO_TEST_OVERRUN_LOOKBEHIND)
4553 lookbehind_overrun:
4554 *out_len = pd(op, out);
4555 return LZO_E_LOOKBEHIND_OVERRUN;
4556 #endif
4559 #endif
4561 /***** End of minilzo.c *****/