blob: 843997cb9cfe5969bd30b0db2f602844f27a8b74 [file] [log] [blame]
Denis Vlasenko052ad9a2009-04-29 12:01:51 +00001/*
2 This file is part of the LZO real-time data compression library.
3
4 Copyright (C) 1996..2008 Markus Franz Xaver Johannes Oberhumer
5 All Rights Reserved.
6
7 Markus F.X.J. Oberhumer <markus@oberhumer.com>
8 http://www.oberhumer.com/opensource/lzo/
9
10 The LZO library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2 of
13 the License, or (at your option) any later version.
14
15 The LZO library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with the LZO library; see the file COPYING.
22 If not, write to the Free Software Foundation, Inc.,
23 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 */
25
26#include "liblzo_interface.h"
27
28/* lzo-2.03/src/config1x.h */
29#define M2_MIN_LEN 3
30#define M2_MAX_LEN 8
31#define M3_MAX_LEN 33
32#define M4_MAX_LEN 9
33#define M1_MAX_OFFSET 0x0400
34#define M2_MAX_OFFSET 0x0800
35#define M3_MAX_OFFSET 0x4000
36#define M4_MAX_OFFSET 0xbfff
37#define M1_MARKER 0
38#define M3_MARKER 32
39#define M4_MARKER 16
40
41#define MX_MAX_OFFSET (M1_MAX_OFFSET + M2_MAX_OFFSET)
42#define MIN_LOOKAHEAD (M2_MAX_LEN + 1)
43
44#define LZO_EOF_CODE
45
46/* lzo-2.03/src/lzo_dict.h */
47#define GINDEX(m_pos,m_off,dict,dindex,in) m_pos = dict[dindex]
48#define DX2(p,s1,s2) \
49 (((((unsigned)((p)[2]) << (s2)) ^ (p)[1]) << (s1)) ^ (p)[0])
50//#define DA3(p,s1,s2,s3) ((DA2((p)+1,s2,s3) << (s1)) + (p)[0])
51//#define DS3(p,s1,s2,s3) ((DS2((p)+1,s2,s3) << (s1)) - (p)[0])
52#define DX3(p,s1,s2,s3) ((DX2((p)+1,s2,s3) << (s1)) ^ (p)[0])
53
54#define D_SIZE (1U << D_BITS)
55#define D_MASK ((1U << D_BITS) - 1)
56#define D_HIGH ((D_MASK >> 1) + 1)
57
58#define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \
59 ( \
60 m_pos = ip - (unsigned)(ip - m_pos), \
61 ((uintptr_t)m_pos < (uintptr_t)in \
62 || (m_off = (unsigned)(ip - m_pos)) <= 0 \
63 || m_off > max_offset) \
64 )
65
66#define DENTRY(p,in) (p)
67#define UPDATE_I(dict,drun,index,p,in) dict[index] = DENTRY(p,in)
68
69#define DMS(v,s) ((unsigned) (((v) & (D_MASK >> (s))) << (s)))
70#define DM(v) ((unsigned) ((v) & D_MASK))
71#define DMUL(a,b) ((unsigned) ((a) * (b)))
72
73/* lzo-2.03/src/lzo_ptr.h */
74#define pd(a,b) ((unsigned)((a)-(b)))
75
76# define TEST_IP (ip < ip_end)
77# define NEED_IP(x) \
78 if ((unsigned)(ip_end - ip) < (unsigned)(x)) goto input_overrun
79
80# undef TEST_OP /* don't need both of the tests here */
81# define TEST_OP 1
82# define NEED_OP(x) \
83 if ((unsigned)(op_end - op) < (unsigned)(x)) goto output_overrun
84
85#define HAVE_ANY_OP 1
86
87//#if defined(LZO_TEST_OVERRUN_LOOKBEHIND)
88# define TEST_LB(m_pos) if (m_pos < out || m_pos >= op) goto lookbehind_overrun
89//# define TEST_LBO(m_pos,o) if (m_pos < out || m_pos >= op - (o)) goto lookbehind_overrun
90//#else
91//# define TEST_LB(m_pos) ((void) 0)
92//# define TEST_LBO(m_pos,o) ((void) 0)
93//#endif