kusano 7d535a
/* lzo1b_de.h -- definitions for the the LZO1B/LZO1C algorithm
kusano 7d535a
kusano 7d535a
   This file is part of the LZO real-time data compression library.
kusano 7d535a
kusano 7d535a
   Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   All Rights Reserved.
kusano 7d535a
kusano 7d535a
   The LZO library is free software; you can redistribute it and/or
kusano 7d535a
   modify it under the terms of the GNU General Public License as
kusano 7d535a
   published by the Free Software Foundation; either version 2 of
kusano 7d535a
   the License, or (at your option) any later version.
kusano 7d535a
kusano 7d535a
   The LZO library is distributed in the hope that it will be useful,
kusano 7d535a
   but WITHOUT ANY WARRANTY; without even the implied warranty of
kusano 7d535a
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
kusano 7d535a
   GNU General Public License for more details.
kusano 7d535a
kusano 7d535a
   You should have received a copy of the GNU General Public License
kusano 7d535a
   along with the LZO library; see the file COPYING.
kusano 7d535a
   If not, write to the Free Software Foundation, Inc.,
kusano 7d535a
   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
kusano 7d535a
kusano 7d535a
   Markus F.X.J. Oberhumer
kusano 7d535a
   <markus@oberhumer.com></markus@oberhumer.com>
kusano 7d535a
   http://www.oberhumer.com/opensource/lzo/
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
kusano 7d535a
/* WARNING: this file should *not* be used by applications. It is
kusano 7d535a
   part of the implementation of the library and is subject
kusano 7d535a
   to change.
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
kusano 7d535a
#ifndef __LZO_DEFS_H
kusano 7d535a
#define __LZO_DEFS_H
kusano 7d535a
kusano 7d535a
#ifdef __cplusplus
kusano 7d535a
extern "C" {
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
kusano 7d535a
/***********************************************************************
kusano 7d535a
//
kusano 7d535a
************************************************************************/
kusano 7d535a
kusano 7d535a
/*
kusano 7d535a
     Format of the marker byte
kusano 7d535a
kusano 7d535a
     76543210
kusano 7d535a
     --------
kusano 7d535a
     00000000   R0 - a long literal run ('R0' run)
kusano 7d535a
     000rrrrr   R  - a short literal run with len r
kusano 7d535a
     00100000   M4 - a very long match
kusano 7d535a
     001mmmmm   M3 - a long match  (len = m+M3_MIN_LEN)
kusano 7d535a
     mmmooooo   M2 - a short match (len = m+M2_MIN_LEN, o = offset low bits)
kusano 7d535a
kusano 7d535a
                M1 is not used !
kusano 7d535a
*/
kusano 7d535a
kusano 7d535a
kusano 7d535a
#ifndef R_BITS
kusano 7d535a
#define R_BITS              (5)
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
kusano 7d535a
#ifndef M1L_BITS
kusano 7d535a
#define M1L_BITS            (0)
kusano 7d535a
#endif
kusano 7d535a
#ifndef M2L_BITS
kusano 7d535a
#define M2L_BITS            (CHAR_BIT - M2O_BITS)
kusano 7d535a
#endif
kusano 7d535a
#ifndef M3L_BITS
kusano 7d535a
#define M3L_BITS            (R_BITS)
kusano 7d535a
#endif
kusano 7d535a
#ifndef M4L_BITS
kusano 7d535a
#define M4L_BITS            (CHAR_BIT)
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
#ifndef M1O_BITS
kusano 7d535a
#define M1O_BITS            (6)
kusano 7d535a
#endif
kusano 7d535a
#ifndef M2O_BITS
kusano 7d535a
#define M2O_BITS            (R_BITS)
kusano 7d535a
#endif
kusano 7d535a
#ifndef M3O_BITS
kusano 7d535a
#define M3O_BITS            (CHAR_BIT)
kusano 7d535a
#endif
kusano 7d535a
#ifndef M4O_BITS
kusano 7d535a
#define M4O_BITS            (M3O_BITS)              /* must be the same */
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
#ifndef M1X_BITS
kusano 7d535a
#define M1X_BITS            (M1O_BITS)
kusano 7d535a
#endif
kusano 7d535a
#ifndef M2X_BITS
kusano 7d535a
#define M2X_BITS            (M2O_BITS + CHAR_BIT)
kusano 7d535a
#endif
kusano 7d535a
#ifndef M3X_BITS
kusano 7d535a
#define M3X_BITS            (M3O_BITS + CHAR_BIT)
kusano 7d535a
#endif
kusano 7d535a
#ifndef M4X_BITS
kusano 7d535a
#define M4X_BITS            M3X_BITS
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
kusano 7d535a
#define __MIN_OFFSET(bits)  1
kusano 7d535a
#define __MAX_OFFSET(bits)  LZO_LSIZE(bits)
kusano 7d535a
kusano 7d535a
#define M1_MIN_OFFSET       __MIN_OFFSET(M1X_BITS)
kusano 7d535a
#define M2_MIN_OFFSET       __MIN_OFFSET(M2X_BITS)
kusano 7d535a
#define M3_MIN_OFFSET       __MIN_OFFSET(M3X_BITS)
kusano 7d535a
#define M4_MIN_OFFSET       M3_MIN_OFFSET
kusano 7d535a
kusano 7d535a
#if defined(LZO_EOF_CODE) && !defined(M3_EOF_OFFSET)
kusano 7d535a
#define M3_EOF_OFFSET       1
kusano 7d535a
#else
kusano 7d535a
#define M3_EOF_OFFSET       0
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
#ifndef _M1_MAX_OFFSET
kusano 7d535a
#define _M1_MAX_OFFSET      __MAX_OFFSET(M1X_BITS)
kusano 7d535a
#endif
kusano 7d535a
#ifndef _M2_MAX_OFFSET
kusano 7d535a
#define _M2_MAX_OFFSET      __MAX_OFFSET(M2X_BITS)
kusano 7d535a
#endif
kusano 7d535a
#ifndef _M3_MAX_OFFSET
kusano 7d535a
#define _M3_MAX_OFFSET      (__MAX_OFFSET(M3X_BITS) - M3_EOF_OFFSET)
kusano 7d535a
#endif
kusano 7d535a
#ifndef _M4_MAX_OFFSET
kusano 7d535a
#define _M4_MAX_OFFSET      _M3_MAX_OFFSET
kusano 7d535a
#endif
kusano 7d535a
#ifndef _MAX_OFFSET
kusano 7d535a
#define _MAX_OFFSET         _M4_MAX_OFFSET
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
#if (M3_EOF_OFFSET > 0) && (_M2_MAX_OFFSET == _M3_MAX_OFFSET + M3_EOF_OFFSET)
kusano 7d535a
#  undef _M2_MAX_OFFSET
kusano 7d535a
#  define _M2_MAX_OFFSET    _M3_MAX_OFFSET
kusano 7d535a
#endif
kusano 7d535a
#if (_M2_MAX_OFFSET > _M3_MAX_OFFSET)
kusano 7d535a
#  error
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
#define M1_MAX_OFFSET       ((lzo_uint) _M1_MAX_OFFSET)
kusano 7d535a
#define M2_MAX_OFFSET       ((lzo_uint) _M2_MAX_OFFSET)
kusano 7d535a
#define M3_MAX_OFFSET       ((lzo_uint) _M3_MAX_OFFSET)
kusano 7d535a
#define M4_MAX_OFFSET       ((lzo_uint) _M4_MAX_OFFSET)
kusano 7d535a
#define MAX_OFFSET          ((lzo_uint) _MAX_OFFSET)
kusano 7d535a
kusano 7d535a
kusano 7d535a
#ifndef M1_MIN_LEN
kusano 7d535a
#define M1_MIN_LEN          (2)
kusano 7d535a
#endif
kusano 7d535a
#ifndef M2_MIN_LEN
kusano 7d535a
#define M2_MIN_LEN          (3)
kusano 7d535a
#endif
kusano 7d535a
#ifndef M3_MIN_LEN
kusano 7d535a
#if (M3X_BITS == M2X_BITS)
kusano 7d535a
#define M3_MIN_LEN          (M2_MAX_LEN + 1)
kusano 7d535a
#else
kusano 7d535a
#define M3_MIN_LEN          (4)
kusano 7d535a
#endif
kusano 7d535a
#endif
kusano 7d535a
#ifndef M4_MIN_LEN
kusano 7d535a
#define M4_MIN_LEN          (M3_MAX_LEN + 1)
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
#ifndef M1_MAX_LEN
kusano 7d535a
#define M1_MAX_LEN          (M1_MIN_LEN + LZO_SIZE(M1L_BITS) - 1)
kusano 7d535a
#endif
kusano 7d535a
#ifndef M2_MAX_LEN
kusano 7d535a
#define M2_MAX_LEN          (M2_MIN_LEN + LZO_SIZE(M2L_BITS) - 3)
kusano 7d535a
#endif
kusano 7d535a
#ifndef M3_MAX_LEN
kusano 7d535a
#define M3_MAX_LEN          (M3_MIN_LEN + LZO_SIZE(M3L_BITS) - 2)
kusano 7d535a
#endif
kusano 7d535a
#ifndef M4_MAX_LEN
kusano 7d535a
#define M4_MAX_LEN          (ULONG_MAX)
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
kusano 7d535a
#define M1O_MASK            LZO_MASK(M1O_BITS)
kusano 7d535a
#define M1L_MASK            LZO_MASK(M1L_BITS)
kusano 7d535a
#define M2O_MASK            LZO_MASK(M2O_BITS)
kusano 7d535a
#define M2L_MASK            LZO_MASK(M2L_BITS)
kusano 7d535a
#define M3O_MASK            LZO_MASK(M3O_BITS)
kusano 7d535a
#define M3L_MASK            LZO_MASK(M3L_BITS)
kusano 7d535a
#define M4O_MASK            LZO_MASK(M4O_BITS)
kusano 7d535a
#define M4L_MASK            LZO_MASK(M4L_BITS)
kusano 7d535a
kusano 7d535a
kusano 7d535a
#define M1_MARKER           (1 << M1O_BITS)
kusano 7d535a
#define M2_MARKER           (2 << M2O_BITS)
kusano 7d535a
#define M3_MARKER           (1 << M3L_BITS)
kusano 7d535a
#define M4_MARKER           M3_MARKER
kusano 7d535a
kusano 7d535a
kusano 7d535a
/***********************************************************************
kusano 7d535a
// R0 literal run (a long run)
kusano 7d535a
************************************************************************/
kusano 7d535a
kusano 7d535a
#ifndef R0MIN
kusano 7d535a
#define R0MIN   (LZO_SIZE(R_BITS))  /* Minimum len of R0 run of literals */
kusano 7d535a
#endif
kusano 7d535a
#define R0MAX   (R0MIN + 256 - 1)   /* Maximum len of R0 run of literals */
kusano 7d535a
kusano 7d535a
#if (R0MAX - (R0MAX & ~7u) >= 7)
kusano 7d535a
#define R0FAST  (R0MAX & ~7u)       /* R0MAX aligned to 8 byte boundary */
kusano 7d535a
#else
kusano 7d535a
#define R0FAST  (R0MAX & ~15u)      /* R0MAX aligned to 8 byte boundary */
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
#if (R0MAX - R0FAST < 7) || ((R0FAST & 7) != 0)
kusano 7d535a
#  error "something went wrong"
kusano 7d535a
#endif
kusano 7d535a
#if (R0FAST * 2 < 512)
kusano 7d535a
#  error "R0FAST is not big enough"
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
/* 7 special codes from R0FAST+1 .. R0MAX
kusano 7d535a
 * these codes mean long R0 runs with lengths
kusano 7d535a
 * 512, 1024, 2048, 4096, 8192, 16384, 32768
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
/***********************************************************************
kusano 7d535a
// matching
kusano 7d535a
************************************************************************/
kusano 7d535a
kusano 7d535a
#define PS  *m_pos++ != *ip++
kusano 7d535a
kusano 7d535a
kusano 7d535a
/* We already matched M2_MIN_LEN bytes.
kusano 7d535a
 * Try to match another M2_MAX_LEN - M2_MIN_LEN bytes. */
kusano 7d535a
kusano 7d535a
#if (M2_MAX_LEN - M2_MIN_LEN == 4)
kusano 7d535a
#  define MATCH_M2X     (PS || PS || PS || PS)
kusano 7d535a
#elif (M2_MAX_LEN - M2_MIN_LEN == 5)
kusano 7d535a
#  define MATCH_M2X     (PS || PS || PS || PS || PS)
kusano 7d535a
#elif (M2_MAX_LEN - M2_MIN_LEN == 6)
kusano 7d535a
#  define MATCH_M2X     (PS || PS || PS || PS || PS || PS)
kusano 7d535a
#elif (M2_MAX_LEN - M2_MIN_LEN == 7)
kusano 7d535a
#  define MATCH_M2X     (PS || PS || PS || PS || PS || PS || PS)
kusano 7d535a
#elif (M2_MAX_LEN - M2_MIN_LEN == 13)
kusano 7d535a
#  define MATCH_M2X     (PS || PS || PS || PS || PS || PS || PS || PS || \
kusano 7d535a
                         PS || PS || PS || PS || PS)
kusano 7d535a
#elif (M2_MAX_LEN - M2_MIN_LEN == 14)
kusano 7d535a
#  define MATCH_M2X     (PS || PS || PS || PS || PS || PS || PS || PS || \
kusano 7d535a
                         PS || PS || PS || PS || PS || PS)
kusano 7d535a
#elif (M2_MAX_LEN - M2_MIN_LEN == 16)
kusano 7d535a
#  define MATCH_M2X     (PS || PS || PS || PS || PS || PS || PS || PS || \
kusano 7d535a
                         PS || PS || PS || PS || PS || PS || PS || PS)
kusano 7d535a
#elif (M2_MAX_LEN - M2_MIN_LEN == 29)
kusano 7d535a
#  define MATCH_M2X     (PS || PS || PS || PS || PS || PS || PS || PS || \
kusano 7d535a
                         PS || PS || PS || PS || PS || PS || PS || PS || \
kusano 7d535a
                         PS || PS || PS || PS || PS || PS || PS || PS || \
kusano 7d535a
                         PS || PS || PS || PS || PS)
kusano 7d535a
#else
kusano 7d535a
#  error "MATCH_M2X not yet implemented"
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
kusano 7d535a
/* We already matched M2_MIN_LEN bytes.
kusano 7d535a
 * Try to match another M2_MAX_LEN + 1 - M2_MIN_LEN bytes
kusano 7d535a
 * to see if we get more than a M2 match */
kusano 7d535a
kusano 7d535a
#define MATCH_M2        (MATCH_M2X || PS)
kusano 7d535a
kusano 7d535a
kusano 7d535a
/***********************************************************************
kusano 7d535a
// copying
kusano 7d535a
************************************************************************/
kusano 7d535a
kusano 7d535a
#define _CP             *op++ = *m_pos++
kusano 7d535a
kusano 7d535a
#if (M2_MIN_LEN == 2)
kusano 7d535a
#  define COPY_M2X      _CP
kusano 7d535a
#elif (M2_MIN_LEN == 3)
kusano 7d535a
#  define COPY_M2X      _CP; _CP
kusano 7d535a
#elif (M2_MIN_LEN == 4)
kusano 7d535a
#  define COPY_M2X      _CP; _CP; _CP
kusano 7d535a
#else
kusano 7d535a
#  error "COPY_M2X not yet implemented"
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
#if (M3_MIN_LEN == 3)
kusano 7d535a
#  define COPY_M3X      _CP; _CP
kusano 7d535a
#elif (M3_MIN_LEN == 4)
kusano 7d535a
#  define COPY_M3X      _CP; _CP; _CP
kusano 7d535a
#elif (M3_MIN_LEN == 9)
kusano 7d535a
#  define COPY_M3X      _CP; _CP; _CP; _CP; _CP; _CP; _CP; _CP
kusano 7d535a
#else
kusano 7d535a
#  error "COPY_M3X not yet implemented"
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
#define COPY_M2         COPY_M2X; *op++ = *m_pos++
kusano 7d535a
#define COPY_M3         COPY_M3X; *op++ = *m_pos++
kusano 7d535a
kusano 7d535a
kusano 7d535a
/***********************************************************************
kusano 7d535a
//
kusano 7d535a
************************************************************************/
kusano 7d535a
kusano 7d535a
#if defined(LZO_NEED_DICT_H)
kusano 7d535a
kusano 7d535a
#define DL_MIN_LEN          M2_MIN_LEN
kusano 7d535a
#define D_INDEX1(d,p)       d = DM(DMUL(0x21,DX3(p,5,5,6)) >> 5)
kusano 7d535a
#define D_INDEX2(d,p)       d = (d & (D_MASK & 0x7ff)) ^ (D_HIGH | 0x1f)
kusano 7d535a
#include "lzo_dict.h"
kusano 7d535a
kusano 7d535a
#ifndef MIN_LOOKAHEAD
kusano 7d535a
#define MIN_LOOKAHEAD       (M2_MAX_LEN + 1)
kusano 7d535a
#endif
kusano 7d535a
#ifndef MAX_LOOKBEHIND
kusano 7d535a
#define MAX_LOOKBEHIND      (MAX_OFFSET)
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
#endif /* defined(LZO_NEED_DICT_H) */
kusano 7d535a
kusano 7d535a
kusano 7d535a
#ifdef __cplusplus
kusano 7d535a
} /* extern "C" */
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
#endif /* already included */
kusano 7d535a
kusano 7d535a
/*
kusano 7d535a
vi:ts=4:et
kusano 7d535a
*/
kusano 7d535a