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