1 /* lzo1b_de.h -- definitions for the the LZO1B/LZO1C algorithm
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
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 /* WARNING: this file should *not* be used by applications. It is
45 part of the implementation of the library and is subject
51 #define __LZO_DEFS_H 1
58 /***********************************************************************
60 ************************************************************************/
63 Format of the marker byte
67 00000000 R0 - a long literal run ('R0' run)
68 000rrrrr R - a short literal run with len r
69 00100000 M4 - a very long match
70 001mmmmm M3 - a long match (len = m+M3_MIN_LEN)
71 mmmooooo M2 - a short match (len = m+M2_MIN_LEN, o = offset low bits)
86 #define M2L_BITS (CHAR_BIT - M2O_BITS)
89 #define M3L_BITS (R_BITS)
92 #define M4L_BITS (CHAR_BIT)
99 #define M2O_BITS (R_BITS)
102 #define M3O_BITS (CHAR_BIT)
105 #define M4O_BITS (M3O_BITS) /* must be the same */
109 #define M1X_BITS (M1O_BITS)
112 #define M2X_BITS (M2O_BITS + CHAR_BIT)
115 #define M3X_BITS (M3O_BITS + CHAR_BIT)
118 #define M4X_BITS M3X_BITS
122 #define __MIN_OFFSET(bits) 1
123 #define __MAX_OFFSET(bits) LZO_LSIZE(bits)
125 #define M1_MIN_OFFSET __MIN_OFFSET(M1X_BITS)
126 #define M2_MIN_OFFSET __MIN_OFFSET(M2X_BITS)
127 #define M3_MIN_OFFSET __MIN_OFFSET(M3X_BITS)
128 #define M4_MIN_OFFSET M3_MIN_OFFSET
130 #if defined(LZO_EOF_CODE) && !defined(M3_EOF_OFFSET)
131 #define M3_EOF_OFFSET 1
133 #define M3_EOF_OFFSET 0
136 #ifndef _M1_MAX_OFFSET
137 #define _M1_MAX_OFFSET __MAX_OFFSET(M1X_BITS)
139 #ifndef _M2_MAX_OFFSET
140 #define _M2_MAX_OFFSET __MAX_OFFSET(M2X_BITS)
142 #ifndef _M3_MAX_OFFSET
143 #define _M3_MAX_OFFSET (__MAX_OFFSET(M3X_BITS) - M3_EOF_OFFSET)
145 #ifndef _M4_MAX_OFFSET
146 #define _M4_MAX_OFFSET _M3_MAX_OFFSET
149 #define _MAX_OFFSET _M4_MAX_OFFSET
152 #if (M3_EOF_OFFSET > 0) && (_M2_MAX_OFFSET == _M3_MAX_OFFSET + M3_EOF_OFFSET)
153 # undef _M2_MAX_OFFSET
154 # define _M2_MAX_OFFSET _M3_MAX_OFFSET
156 #if (_M2_MAX_OFFSET > _M3_MAX_OFFSET)
160 #define M1_MAX_OFFSET ((lzo_uint) _M1_MAX_OFFSET)
161 #define M2_MAX_OFFSET ((lzo_uint) _M2_MAX_OFFSET)
162 #define M3_MAX_OFFSET ((lzo_uint) _M3_MAX_OFFSET)
163 #define M4_MAX_OFFSET ((lzo_uint) _M4_MAX_OFFSET)
164 #define MAX_OFFSET ((lzo_uint) _MAX_OFFSET)
168 #define M1_MIN_LEN (2)
171 #define M2_MIN_LEN (3)
174 #if (M3X_BITS == M2X_BITS)
175 #define M3_MIN_LEN (M2_MAX_LEN + 1)
177 #define M3_MIN_LEN (4)
181 #define M4_MIN_LEN (M3_MAX_LEN + 1)
185 #define M1_MAX_LEN (M1_MIN_LEN + LZO_SIZE(M1L_BITS) - 1)
188 #define M2_MAX_LEN (M2_MIN_LEN + LZO_SIZE(M2L_BITS) - 3)
191 #define M3_MAX_LEN (M3_MIN_LEN + LZO_SIZE(M3L_BITS) - 2)
194 #define M4_MAX_LEN (ULONG_MAX)
198 #define M1O_MASK LZO_MASK(M1O_BITS)
199 #define M1L_MASK LZO_MASK(M1L_BITS)
200 #define M2O_MASK LZO_MASK(M2O_BITS)
201 #define M2L_MASK LZO_MASK(M2L_BITS)
202 #define M3O_MASK LZO_MASK(M3O_BITS)
203 #define M3L_MASK LZO_MASK(M3L_BITS)
204 #define M4O_MASK LZO_MASK(M4O_BITS)
205 #define M4L_MASK LZO_MASK(M4L_BITS)
208 #define M1_MARKER (1 << M1O_BITS)
209 #define M2_MARKER (2 << M2O_BITS)
210 #define M3_MARKER (1 << M3L_BITS)
211 #define M4_MARKER M3_MARKER
214 /***********************************************************************
215 // R0 literal run (a long run)
216 ************************************************************************/
219 #define R0MIN (LZO_SIZE(R_BITS)) /* Minimum len of R0 run of literals */
221 #define R0MAX (R0MIN + 256 - 1) /* Maximum len of R0 run of literals */
223 #if (R0MAX - (R0MAX & ~7u) >= 7)
224 #define R0FAST (R0MAX & ~7u) /* R0MAX aligned to 8 byte boundary */
226 #define R0FAST (R0MAX & ~15u) /* R0MAX aligned to 8 byte boundary */
229 #if (R0MAX - R0FAST < 7) || ((R0FAST & 7) != 0)
230 # error "something went wrong"
232 #if (R0FAST * 2 < 512)
233 # error "R0FAST is not big enough"
236 /* 7 special codes from R0FAST+1 .. R0MAX
237 * these codes mean long R0 runs with lengths
238 * 512, 1024, 2048, 4096, 8192, 16384, 32768
243 /***********************************************************************
245 ************************************************************************/
247 #define PS *m_pos++ != *ip++
250 /* We already matched M2_MIN_LEN bytes.
251 * Try to match another M2_MAX_LEN - M2_MIN_LEN bytes. */
253 #if (M2_MAX_LEN - M2_MIN_LEN == 4)
254 # define MATCH_M2X (PS || PS || PS || PS)
255 #elif (M2_MAX_LEN - M2_MIN_LEN == 5)
256 # define MATCH_M2X (PS || PS || PS || PS || PS)
257 #elif (M2_MAX_LEN - M2_MIN_LEN == 6)
258 # define MATCH_M2X (PS || PS || PS || PS || PS || PS)
259 #elif (M2_MAX_LEN - M2_MIN_LEN == 7)
260 # define MATCH_M2X (PS || PS || PS || PS || PS || PS || PS)
261 #elif (M2_MAX_LEN - M2_MIN_LEN == 13)
262 # define MATCH_M2X (PS || PS || PS || PS || PS || PS || PS || PS || \
263 PS || PS || PS || PS || PS)
264 #elif (M2_MAX_LEN - M2_MIN_LEN == 14)
265 # define MATCH_M2X (PS || PS || PS || PS || PS || PS || PS || PS || \
266 PS || PS || PS || PS || PS || PS)
267 #elif (M2_MAX_LEN - M2_MIN_LEN == 16)
268 # define MATCH_M2X (PS || PS || PS || PS || PS || PS || PS || PS || \
269 PS || PS || PS || PS || PS || PS || PS || PS)
270 #elif (M2_MAX_LEN - M2_MIN_LEN == 29)
271 # define MATCH_M2X (PS || PS || PS || PS || PS || PS || PS || PS || \
272 PS || PS || PS || PS || PS || PS || PS || PS || \
273 PS || PS || PS || PS || PS || PS || PS || PS || \
274 PS || PS || PS || PS || PS)
276 # error "MATCH_M2X not yet implemented"
280 /* We already matched M2_MIN_LEN bytes.
281 * Try to match another M2_MAX_LEN + 1 - M2_MIN_LEN bytes
282 * to see if we get more than a M2 match */
284 #define MATCH_M2 (MATCH_M2X || PS)
287 /***********************************************************************
289 ************************************************************************/
291 #define _CP *op++ = *m_pos++
293 #if (M2_MIN_LEN == 2)
294 # define COPY_M2X _CP
295 #elif (M2_MIN_LEN == 3)
296 # define COPY_M2X _CP; _CP
297 #elif (M2_MIN_LEN == 4)
298 # define COPY_M2X _CP; _CP; _CP
300 # error "COPY_M2X not yet implemented"
303 #if (M3_MIN_LEN == 3)
304 # define COPY_M3X _CP; _CP
305 #elif (M3_MIN_LEN == 4)
306 # define COPY_M3X _CP; _CP; _CP
307 #elif (M3_MIN_LEN == 9)
308 # define COPY_M3X _CP; _CP; _CP; _CP; _CP; _CP; _CP; _CP
310 # error "COPY_M3X not yet implemented"
313 #define COPY_M2 COPY_M2X; *op++ = *m_pos++
314 #define COPY_M3 COPY_M3X; *op++ = *m_pos++
317 /***********************************************************************
319 ************************************************************************/
321 #if defined(LZO_NEED_DICT_H)
323 #define DL_MIN_LEN M2_MIN_LEN
324 #define D_INDEX1(d,p) d = DM(DMUL(0x21,DX3(p,5,5,6)) >> 5)
325 #define D_INDEX2(d,p) d = (d & (D_MASK & 0x7ff)) ^ (D_HIGH | 0x1f)
326 #include "lzo_dict.h"
328 #ifndef MIN_LOOKAHEAD
329 #define MIN_LOOKAHEAD (M2_MAX_LEN + 1)
331 #ifndef MAX_LOOKBEHIND
332 #define MAX_LOOKBEHIND (MAX_OFFSET)
335 #endif /* defined(LZO_NEED_DICT_H) */
342 #endif /* already included */