1/* lzo1b_de.h -- definitions for the the LZO1B/LZO1C algorithm 2 3 This file is part of the LZO real-time data compression library. 4 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. 22 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. 27 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. 32 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. 37 38 Markus F.X.J. Oberhumer 39 <markus@oberhumer.com> 40 http://www.oberhumer.com/opensource/lzo/ 41 */ 42 43 44/* WARNING: this file should *not* be used by applications. It is 45 part of the implementation of the library and is subject 46 to change. 47 */ 48 49 50#ifndef __LZO_DEFS_H 51#define __LZO_DEFS_H 1 52 53#ifdef __cplusplus 54extern "C" { 55#endif 56 57 58/*********************************************************************** 59// 60************************************************************************/ 61 62/* 63 Format of the marker byte 64 65 76543210 66 -------- 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) 72 73 M1 is not used ! 74*/ 75 76 77#ifndef R_BITS 78#define R_BITS (5) 79#endif 80 81 82#ifndef M1L_BITS 83#define M1L_BITS (0) 84#endif 85#ifndef M2L_BITS 86#define M2L_BITS (CHAR_BIT - M2O_BITS) 87#endif 88#ifndef M3L_BITS 89#define M3L_BITS (R_BITS) 90#endif 91#ifndef M4L_BITS 92#define M4L_BITS (CHAR_BIT) 93#endif 94 95#ifndef M1O_BITS 96#define M1O_BITS (6) 97#endif 98#ifndef M2O_BITS 99#define M2O_BITS (R_BITS) 100#endif 101#ifndef M3O_BITS 102#define M3O_BITS (CHAR_BIT) 103#endif 104#ifndef M4O_BITS 105#define M4O_BITS (M3O_BITS) /* must be the same */ 106#endif 107 108#ifndef M1X_BITS 109#define M1X_BITS (M1O_BITS) 110#endif 111#ifndef M2X_BITS 112#define M2X_BITS (M2O_BITS + CHAR_BIT) 113#endif 114#ifndef M3X_BITS 115#define M3X_BITS (M3O_BITS + CHAR_BIT) 116#endif 117#ifndef M4X_BITS 118#define M4X_BITS M3X_BITS 119#endif 120 121 122#define __MIN_OFFSET(bits) 1 123#define __MAX_OFFSET(bits) LZO_LSIZE(bits) 124 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 129 130#if defined(LZO_EOF_CODE) && !defined(M3_EOF_OFFSET) 131#define M3_EOF_OFFSET 1 132#else 133#define M3_EOF_OFFSET 0 134#endif 135 136#ifndef _M1_MAX_OFFSET 137#define _M1_MAX_OFFSET __MAX_OFFSET(M1X_BITS) 138#endif 139#ifndef _M2_MAX_OFFSET 140#define _M2_MAX_OFFSET __MAX_OFFSET(M2X_BITS) 141#endif 142#ifndef _M3_MAX_OFFSET 143#define _M3_MAX_OFFSET (__MAX_OFFSET(M3X_BITS) - M3_EOF_OFFSET) 144#endif 145#ifndef _M4_MAX_OFFSET 146#define _M4_MAX_OFFSET _M3_MAX_OFFSET 147#endif 148#ifndef _MAX_OFFSET 149#define _MAX_OFFSET _M4_MAX_OFFSET 150#endif 151 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 155#endif 156#if (_M2_MAX_OFFSET > _M3_MAX_OFFSET) 157# error 158#endif 159 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) 165 166 167#ifndef M1_MIN_LEN 168#define M1_MIN_LEN (2) 169#endif 170#ifndef M2_MIN_LEN 171#define M2_MIN_LEN (3) 172#endif 173#ifndef M3_MIN_LEN 174#if (M3X_BITS == M2X_BITS) 175#define M3_MIN_LEN (M2_MAX_LEN + 1) 176#else 177#define M3_MIN_LEN (4) 178#endif 179#endif 180#ifndef M4_MIN_LEN 181#define M4_MIN_LEN (M3_MAX_LEN + 1) 182#endif 183 184#ifndef M1_MAX_LEN 185#define M1_MAX_LEN (M1_MIN_LEN + LZO_SIZE(M1L_BITS) - 1) 186#endif 187#ifndef M2_MAX_LEN 188#define M2_MAX_LEN (M2_MIN_LEN + LZO_SIZE(M2L_BITS) - 3) 189#endif 190#ifndef M3_MAX_LEN 191#define M3_MAX_LEN (M3_MIN_LEN + LZO_SIZE(M3L_BITS) - 2) 192#endif 193#ifndef M4_MAX_LEN 194#define M4_MAX_LEN (ULONG_MAX) 195#endif 196 197 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) 206 207 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 212 213 214/*********************************************************************** 215// R0 literal run (a long run) 216************************************************************************/ 217 218#ifndef R0MIN 219#define R0MIN (LZO_SIZE(R_BITS)) /* Minimum len of R0 run of literals */ 220#endif 221#define R0MAX (R0MIN + 256 - 1) /* Maximum len of R0 run of literals */ 222 223#if (R0MAX - (R0MAX & ~7u) >= 7) 224#define R0FAST (R0MAX & ~7u) /* R0MAX aligned to 8 byte boundary */ 225#else 226#define R0FAST (R0MAX & ~15u) /* R0MAX aligned to 8 byte boundary */ 227#endif 228 229#if (R0MAX - R0FAST < 7) || ((R0FAST & 7) != 0) 230# error "something went wrong" 231#endif 232#if (R0FAST * 2 < 512) 233# error "R0FAST is not big enough" 234#endif 235 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 239 */ 240 241 242 243/*********************************************************************** 244// matching 245************************************************************************/ 246 247#define PS *m_pos++ != *ip++ 248 249 250/* We already matched M2_MIN_LEN bytes. 251 * Try to match another M2_MAX_LEN - M2_MIN_LEN bytes. */ 252 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) 275#else 276# error "MATCH_M2X not yet implemented" 277#endif 278 279 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 */ 283 284#define MATCH_M2 (MATCH_M2X || PS) 285 286 287/*********************************************************************** 288// copying 289************************************************************************/ 290 291#define _CP *op++ = *m_pos++ 292 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 299#else 300# error "COPY_M2X not yet implemented" 301#endif 302 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 309#else 310# error "COPY_M3X not yet implemented" 311#endif 312 313#define COPY_M2 COPY_M2X; *op++ = *m_pos++ 314#define COPY_M3 COPY_M3X; *op++ = *m_pos++ 315 316 317/*********************************************************************** 318// 319************************************************************************/ 320 321#if defined(LZO_NEED_DICT_H) 322 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" 327 328#ifndef MIN_LOOKAHEAD 329#define MIN_LOOKAHEAD (M2_MAX_LEN + 1) 330#endif 331#ifndef MAX_LOOKBEHIND 332#define MAX_LOOKBEHIND (MAX_OFFSET) 333#endif 334 335#endif /* defined(LZO_NEED_DICT_H) */ 336 337 338#ifdef __cplusplus 339} /* extern "C" */ 340#endif 341 342#endif /* already included */ 343 344/* 345vi:ts=4:et 346*/ 347 348