1 /* lzo1a_de.h -- definitions for the the LZO1A algorithm
2 
3    This file is part of the LZO real-time data compression library.
4 
5    Copyright (C) 1996-2017 Markus Franz Xaver Johannes Oberhumer
6    All Rights Reserved.
7 
8    The LZO library is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2 of
11    the License, or (at your option) any later version.
12 
13    The LZO library is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17 
18    You should have received a copy of the GNU General Public License
19    along with the LZO library; see the file COPYING.
20    If not, write to the Free Software Foundation, Inc.,
21    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 
23    Markus F.X.J. Oberhumer
24    <markus@oberhumer.com>
25    http://www.oberhumer.com/opensource/lzo/
26  */
27 
28 
29 /* WARNING: this file should *not* be used by applications. It is
30    part of the implementation of the LZO package and is subject
31    to change.
32  */
33 
34 
35 #ifndef __LZO_DEFS_H
36 #define __LZO_DEFS_H 1
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 
43 /***********************************************************************
44 //
45 ************************************************************************/
46 
47 /*
48      Format of the marker byte
49 
50 
51      76543210
52      --------
53      00000000   a long literal run ('R0' run) - there are short and long R0 runs
54      000rrrrr   a short literal run with len r
55      mmmooooo   a short match (len = 2+m, o = offset low bits)
56      111ooooo   a long match (o = offset low bits)
57 */
58 
59 
60 #define RSIZE   (1 << RBITS)
61 #define RMASK   (RSIZE - 1)
62 
63 #define MBITS   (8 - OBITS)
64 #define MSIZE   (1 << MBITS)
65 #define MMASK   (MSIZE - 1)
66 
67 #define OBITS   RBITS               /* offset and run-length use same bits */
68 #define OSIZE   (1 << OBITS)
69 #define OMASK   (OSIZE - 1)
70 
71 
72 /* additional bits for coding the length in a long match */
73 #define LBITS   8
74 #define LSIZE   (1 << LBITS)
75 #define LMASK   (LSIZE - 1)
76 
77 
78 /***********************************************************************
79 // some macros to improve readability
80 ************************************************************************/
81 
82 /* Minimum len of a match */
83 #define MIN_MATCH           3
84 #define THRESHOLD           (MIN_MATCH - 1)
85 
86 /* Min-/Maximum len of a match coded in 2 bytes */
87 #define MIN_MATCH_SHORT     (MIN_MATCH)
88 #define MAX_MATCH_SHORT     (MIN_MATCH_SHORT + (MSIZE - 2) - 1)
89 /* why (MSIZE - 2) ? because 0 is used to mark runs,
90  *                   and MSIZE-1 is used to mark a long match */
91 
92 /* Min-/Maximum len of a match coded in 3 bytes */
93 #define MIN_MATCH_LONG      (MAX_MATCH_SHORT + 1)
94 #define MAX_MATCH_LONG      (MIN_MATCH_LONG + LSIZE - 1)
95 
96 /* Min-/Maximum offset of a match */
97 #define MIN_OFFSET          1
98 #define MAX_OFFSET          (1 << (CHAR_BIT + OBITS))
99 
100 
101 /* R0 literal run (a long run) */
102 
103 #define R0MIN   (RSIZE)             /* Minimum len of R0 run of literals */
104 #define R0MAX   (R0MIN + 255)       /* Maximum len of R0 run of literals */
105 #define R0FAST  (R0MAX & ~7)        /* R0MAX aligned to 8 byte boundary */
106 
107 #if (R0MAX - R0FAST != 7) || ((R0FAST & 7) != 0)
108 #  error "something went wrong"
109 #endif
110 
111 /* 7 special codes from R0FAST+1 .. R0MAX
112  * these codes mean long R0 runs with lengths
113  * 512, 1024, 2048, 4096, 8192, 16384, 32768 */
114 
115 
116 /*
117 
118 RBITS | MBITS  MIN  THR.  MSIZE  MAXS  MINL  MAXL   MAXO  R0MAX R0FAST
119 ======+===============================================================
120   3   |   5      3    2     32    32    33    288   2048    263   256
121   4   |   4      3    2     16    16    17    272   4096    271   264
122   5   |   3      3    2      8     8     9    264   8192    287   280
123 
124  */
125 
126 
127 /***********************************************************************
128 //
129 ************************************************************************/
130 
131 #define DBITS       13
132 #include "lzo_dict.h"
133 #define DVAL_LEN    DVAL_LOOKAHEAD
134 
135 
136 
137 #ifdef __cplusplus
138 } /* extern "C" */
139 #endif
140 
141 #endif /* already included */
142 
143 
144 /* vim:set ts=4 sw=4 et: */
145