Coverage Report

Created: 2026-01-16 06:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/lzo-2.10/src/lzo1x_9x.c
Line
Count
Source
1
/* lzo1x_9x.c -- implementation of the LZO1X-999 compression 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
#if !defined(LZO1X) && !defined(LZO1Y) && !defined(LZO1Z)
30
#  define LZO1X 1
31
#endif
32
33
#if defined(LZO1X)
34
#  include "config1x.h"
35
#elif defined(LZO1Y)
36
#  include "config1y.h"
37
#elif defined(LZO1Z)
38
#  include "config1z.h"
39
#else
40
#  error
41
#endif
42
43
44
/***********************************************************************
45
//
46
************************************************************************/
47
48
4.32k
#define SWD_N           M4_MAX_OFFSET   /* size of ring buffer */
49
46.0M
#define SWD_THRESHOLD       1           /* lower limit for match length */
50
21.6k
#define SWD_F            2048           /* upper limit for match length */
51
52
1.66G
#define SWD_BEST_OFF    (LZO_MAX3( M2_MAX_LEN, M3_MAX_LEN, M4_MAX_LEN ) + 1)
53
54
#if defined(LZO1X)
55
2.66k
#  define LZO_COMPRESS_T                lzo1x_999_t
56
1.33k
#  define lzo_swd_t                     lzo1x_999_swd_t
57
#elif defined(LZO1Y)
58
2.68k
#  define LZO_COMPRESS_T                lzo1y_999_t
59
1.34k
#  define lzo_swd_t                     lzo1y_999_swd_t
60
1.34k
#  define lzo1x_999_compress_internal   lzo1y_999_compress_internal
61
#  define lzo1x_999_compress_dict       lzo1y_999_compress_dict
62
1.34k
#  define lzo1x_999_compress_level      lzo1y_999_compress_level
63
#  define lzo1x_999_compress            lzo1y_999_compress
64
#elif defined(LZO1Z)
65
3.29k
#  define LZO_COMPRESS_T                lzo1z_999_t
66
1.64k
#  define lzo_swd_t                     lzo1z_999_swd_t
67
1.64k
#  define lzo1x_999_compress_internal   lzo1z_999_compress_internal
68
#  define lzo1x_999_compress_dict       lzo1z_999_compress_dict
69
1.64k
#  define lzo1x_999_compress_level      lzo1z_999_compress_level
70
#  define lzo1x_999_compress            lzo1z_999_compress
71
#else
72
#  error
73
#endif
74
75
#if 0
76
#  define HEAD3(b,p) \
77
    ((((((lzo_xint)b[p]<<3)^b[p+1])<<3)^b[p+2]) & (SWD_HSIZE-1))
78
#endif
79
#if 0 && (LZO_OPT_UNALIGNED32) && (LZO_ABI_LITTLE_ENDIAN)
80
#  define HEAD3(b,p) \
81
    (((* (lzo_uint32_tp) &b[p]) ^ ((* (lzo_uint32_tp) &b[p])>>10)) & (SWD_HSIZE-1))
82
#endif
83
84
#include "lzo_mchw.ch"
85
86
87
/* this is a public functions, but there is no prototype in a header file */
88
LZO_EXTERN(int)
89
lzo1x_999_compress_internal ( const lzo_bytep in , lzo_uint  in_len,
90
                                    lzo_bytep out, lzo_uintp out_len,
91
                                    lzo_voidp wrkmem,
92
                              const lzo_bytep dict, lzo_uint dict_len,
93
                                    lzo_callback_p cb,
94
                                    int try_lazy_parm,
95
                                    lzo_uint good_length,
96
                                    lzo_uint max_lazy,
97
                                    lzo_uint nice_length,
98
                                    lzo_uint max_chain,
99
                                    lzo_uint32_t flags );
100
101
102
/***********************************************************************
103
//
104
************************************************************************/
105
106
static lzo_bytep
107
code_match ( LZO_COMPRESS_T *c, lzo_bytep op, lzo_uint m_len, lzo_uint m_off )
108
2.58M
{
109
2.58M
    lzo_uint x_len = m_len;
110
2.58M
    lzo_uint x_off = m_off;
111
112
2.58M
    c->match_bytes += m_len;
113
114
#if 0
115
/*
116
    static lzo_uint last_m_len = 0, last_m_off = 0;
117
    static lzo_uint prev_m_off[4];
118
    static unsigned prev_m_off_ptr = 0;
119
    unsigned i;
120
121
    //if (m_len >= 3 && m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
122
    if (m_len >= 3 && m_len <= M2_MAX_LEN)
123
    {
124
    //if (m_len == last_m_len && m_off == last_m_off)
125
        //printf("last_m_len + last_m_off\n");
126
    //else
127
    if (m_off == last_m_off)
128
        printf("last_m_off\n");
129
    else
130
    {
131
        for (i = 0; i < 4; i++)
132
            if (m_off == prev_m_off[i])
133
                printf("prev_m_off %u: %5ld\n",i,(long)m_off);
134
    }
135
    }
136
    last_m_len = m_len;
137
    last_m_off = prev_m_off[prev_m_off_ptr] = m_off;
138
    prev_m_off_ptr = (prev_m_off_ptr + 1) & 3;
139
*/
140
#endif
141
142
2.58M
    assert(op > c->out);
143
2.58M
    if (m_len == 2)
144
573k
    {
145
573k
        assert(m_off <= M1_MAX_OFFSET);
146
573k
        assert(c->r1_lit > 0); assert(c->r1_lit < 4);
147
573k
        m_off -= 1;
148
#if defined(LZO1Z)
149
206k
        *op++ = LZO_BYTE(M1_MARKER | (m_off >> 6));
150
206k
        *op++ = LZO_BYTE(m_off << 2);
151
#else
152
367k
        *op++ = LZO_BYTE(M1_MARKER | ((m_off & 3) << 2));
153
367k
        *op++ = LZO_BYTE(m_off >> 2);
154
#endif
155
573k
        c->m1a_m++;
156
573k
    }
157
#if defined(LZO1Z)
158
797k
    else if (m_len <= M2_MAX_LEN && (m_off <= M2_MAX_OFFSET || m_off == c->last_m_off))
159
#else
160
1.21M
    else if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
161
626k
#endif
162
993k
    {
163
993k
        assert(m_len >= 3);
164
#if defined(LZO1X)
165
        m_off -= 1;
166
317k
        *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2));
167
317k
        *op++ = LZO_BYTE(m_off >> 3);
168
        assert(op[-2] >= M2_MARKER);
169
#elif defined(LZO1Y)
170
        m_off -= 1;
171
309k
        *op++ = LZO_BYTE(((m_len + 1) << 4) | ((m_off & 3) << 2));
172
309k
        *op++ = LZO_BYTE(m_off >> 2);
173
        assert(op[-2] >= M2_MARKER);
174
#elif defined(LZO1Z)
175
367k
        if (m_off == c->last_m_off)
176
23.2k
            *op++ = LZO_BYTE(((m_len - 1) << 5) | (0x700 >> 6));
177
344k
        else
178
344k
        {
179
344k
            m_off -= 1;
180
344k
            *op++ = LZO_BYTE(((m_len - 1) << 5) | (m_off >> 6));
181
344k
            *op++ = LZO_BYTE(m_off << 2);
182
344k
        }
183
#endif
184
993k
        c->m2_m++;
185
993k
    }
186
1.01M
    else if (m_len == M2_MIN_LEN && m_off <= MX_MAX_OFFSET && c->r1_lit >= 4)
187
12.8k
    {
188
12.8k
        assert(m_len == 3);
189
12.8k
        assert(m_off > M2_MAX_OFFSET);
190
12.8k
        m_off -= 1 + M2_MAX_OFFSET;
191
#if defined(LZO1Z)
192
4.32k
        *op++ = LZO_BYTE(M1_MARKER | (m_off >> 6));
193
4.32k
        *op++ = LZO_BYTE(m_off << 2);
194
#else
195
8.54k
        *op++ = LZO_BYTE(M1_MARKER | ((m_off & 3) << 2));
196
8.54k
        *op++ = LZO_BYTE(m_off >> 2);
197
#endif
198
12.8k
        c->m1b_m++;
199
12.8k
    }
200
1.00M
    else if (m_off <= M3_MAX_OFFSET)
201
774k
    {
202
774k
        assert(m_len >= 3);
203
774k
        m_off -= 1;
204
774k
        if (m_len <= M3_MAX_LEN)
205
646k
            *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
206
127k
        else
207
127k
        {
208
127k
            m_len -= M3_MAX_LEN;
209
127k
            *op++ = M3_MARKER | 0;
210
232k
            while (m_len > 255)
211
105k
            {
212
105k
                m_len -= 255;
213
105k
                *op++ = 0;
214
105k
            }
215
127k
            assert(m_len > 0);
216
127k
            *op++ = LZO_BYTE(m_len);
217
127k
        }
218
#if defined(LZO1Z)
219
314k
        *op++ = LZO_BYTE(m_off >> 6);
220
314k
        *op++ = LZO_BYTE(m_off << 2);
221
#else
222
459k
        *op++ = LZO_BYTE(m_off << 2);
223
459k
        *op++ = LZO_BYTE(m_off >> 6);
224
#endif
225
774k
        c->m3_m++;
226
774k
    }
227
230k
    else
228
230k
    {
229
230k
        lzo_uint k;
230
231
230k
        assert(m_len >= 3);
232
230k
        assert(m_off > 0x4000); assert(m_off <= 0xbfff);
233
230k
        m_off -= 0x4000;
234
230k
        k = (m_off & 0x4000) >> 11;
235
230k
        if (m_len <= M4_MAX_LEN)
236
153k
            *op++ = LZO_BYTE(M4_MARKER | k | (m_len - 2));
237
77.1k
        else
238
77.1k
        {
239
77.1k
            m_len -= M4_MAX_LEN;
240
77.1k
            *op++ = LZO_BYTE(M4_MARKER | k | 0);
241
97.1k
            while (m_len > 255)
242
20.0k
            {
243
20.0k
                m_len -= 255;
244
20.0k
                *op++ = 0;
245
20.0k
            }
246
77.1k
            assert(m_len > 0);
247
77.1k
            *op++ = LZO_BYTE(m_len);
248
77.1k
        }
249
#if defined(LZO1Z)
250
111k
        *op++ = LZO_BYTE(m_off >> 6);
251
111k
        *op++ = LZO_BYTE(m_off << 2);
252
#else
253
118k
        *op++ = LZO_BYTE(m_off << 2);
254
118k
        *op++ = LZO_BYTE(m_off >> 6);
255
#endif
256
230k
        c->m4_m++;
257
230k
    }
258
259
2.58M
    c->last_m_len = x_len;
260
2.58M
    c->last_m_off = x_off;
261
2.58M
    return op;
262
2.58M
}
lzo1x_9x.c:code_match
Line
Count
Source
108
861k
{
109
861k
    lzo_uint x_len = m_len;
110
861k
    lzo_uint x_off = m_off;
111
112
861k
    c->match_bytes += m_len;
113
114
#if 0
115
/*
116
    static lzo_uint last_m_len = 0, last_m_off = 0;
117
    static lzo_uint prev_m_off[4];
118
    static unsigned prev_m_off_ptr = 0;
119
    unsigned i;
120
121
    //if (m_len >= 3 && m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
122
    if (m_len >= 3 && m_len <= M2_MAX_LEN)
123
    {
124
    //if (m_len == last_m_len && m_off == last_m_off)
125
        //printf("last_m_len + last_m_off\n");
126
    //else
127
    if (m_off == last_m_off)
128
        printf("last_m_off\n");
129
    else
130
    {
131
        for (i = 0; i < 4; i++)
132
            if (m_off == prev_m_off[i])
133
                printf("prev_m_off %u: %5ld\n",i,(long)m_off);
134
    }
135
    }
136
    last_m_len = m_len;
137
    last_m_off = prev_m_off[prev_m_off_ptr] = m_off;
138
    prev_m_off_ptr = (prev_m_off_ptr + 1) & 3;
139
*/
140
#endif
141
142
861k
    assert(op > c->out);
143
861k
    if (m_len == 2)
144
230k
    {
145
230k
        assert(m_off <= M1_MAX_OFFSET);
146
230k
        assert(c->r1_lit > 0); assert(c->r1_lit < 4);
147
230k
        m_off -= 1;
148
#if defined(LZO1Z)
149
        *op++ = LZO_BYTE(M1_MARKER | (m_off >> 6));
150
        *op++ = LZO_BYTE(m_off << 2);
151
#else
152
230k
        *op++ = LZO_BYTE(M1_MARKER | ((m_off & 3) << 2));
153
230k
        *op++ = LZO_BYTE(m_off >> 2);
154
230k
#endif
155
230k
        c->m1a_m++;
156
230k
    }
157
#if defined(LZO1Z)
158
    else if (m_len <= M2_MAX_LEN && (m_off <= M2_MAX_OFFSET || m_off == c->last_m_off))
159
#else
160
631k
    else if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
161
317k
#endif
162
317k
    {
163
317k
        assert(m_len >= 3);
164
317k
#if defined(LZO1X)
165
317k
        m_off -= 1;
166
317k
        *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2));
167
317k
        *op++ = LZO_BYTE(m_off >> 3);
168
317k
        assert(op[-2] >= M2_MARKER);
169
#elif defined(LZO1Y)
170
        m_off -= 1;
171
        *op++ = LZO_BYTE(((m_len + 1) << 4) | ((m_off & 3) << 2));
172
        *op++ = LZO_BYTE(m_off >> 2);
173
        assert(op[-2] >= M2_MARKER);
174
#elif defined(LZO1Z)
175
        if (m_off == c->last_m_off)
176
            *op++ = LZO_BYTE(((m_len - 1) << 5) | (0x700 >> 6));
177
        else
178
        {
179
            m_off -= 1;
180
            *op++ = LZO_BYTE(((m_len - 1) << 5) | (m_off >> 6));
181
            *op++ = LZO_BYTE(m_off << 2);
182
        }
183
#endif
184
317k
        c->m2_m++;
185
317k
    }
186
314k
    else if (m_len == M2_MIN_LEN && m_off <= MX_MAX_OFFSET && c->r1_lit >= 4)
187
2.84k
    {
188
2.84k
        assert(m_len == 3);
189
2.84k
        assert(m_off > M2_MAX_OFFSET);
190
2.84k
        m_off -= 1 + M2_MAX_OFFSET;
191
#if defined(LZO1Z)
192
        *op++ = LZO_BYTE(M1_MARKER | (m_off >> 6));
193
        *op++ = LZO_BYTE(m_off << 2);
194
#else
195
2.84k
        *op++ = LZO_BYTE(M1_MARKER | ((m_off & 3) << 2));
196
2.84k
        *op++ = LZO_BYTE(m_off >> 2);
197
2.84k
#endif
198
2.84k
        c->m1b_m++;
199
2.84k
    }
200
311k
    else if (m_off <= M3_MAX_OFFSET)
201
251k
    {
202
251k
        assert(m_len >= 3);
203
251k
        m_off -= 1;
204
251k
        if (m_len <= M3_MAX_LEN)
205
212k
            *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
206
39.5k
        else
207
39.5k
        {
208
39.5k
            m_len -= M3_MAX_LEN;
209
39.5k
            *op++ = M3_MARKER | 0;
210
72.1k
            while (m_len > 255)
211
32.5k
            {
212
32.5k
                m_len -= 255;
213
32.5k
                *op++ = 0;
214
32.5k
            }
215
39.5k
            assert(m_len > 0);
216
39.5k
            *op++ = LZO_BYTE(m_len);
217
39.5k
        }
218
#if defined(LZO1Z)
219
        *op++ = LZO_BYTE(m_off >> 6);
220
        *op++ = LZO_BYTE(m_off << 2);
221
#else
222
251k
        *op++ = LZO_BYTE(m_off << 2);
223
251k
        *op++ = LZO_BYTE(m_off >> 6);
224
251k
#endif
225
251k
        c->m3_m++;
226
251k
    }
227
59.4k
    else
228
59.4k
    {
229
59.4k
        lzo_uint k;
230
231
59.4k
        assert(m_len >= 3);
232
59.4k
        assert(m_off > 0x4000); assert(m_off <= 0xbfff);
233
59.4k
        m_off -= 0x4000;
234
59.4k
        k = (m_off & 0x4000) >> 11;
235
59.4k
        if (m_len <= M4_MAX_LEN)
236
35.7k
            *op++ = LZO_BYTE(M4_MARKER | k | (m_len - 2));
237
23.7k
        else
238
23.7k
        {
239
23.7k
            m_len -= M4_MAX_LEN;
240
23.7k
            *op++ = LZO_BYTE(M4_MARKER | k | 0);
241
30.5k
            while (m_len > 255)
242
6.85k
            {
243
6.85k
                m_len -= 255;
244
6.85k
                *op++ = 0;
245
6.85k
            }
246
23.7k
            assert(m_len > 0);
247
23.7k
            *op++ = LZO_BYTE(m_len);
248
23.7k
        }
249
#if defined(LZO1Z)
250
        *op++ = LZO_BYTE(m_off >> 6);
251
        *op++ = LZO_BYTE(m_off << 2);
252
#else
253
59.4k
        *op++ = LZO_BYTE(m_off << 2);
254
59.4k
        *op++ = LZO_BYTE(m_off >> 6);
255
59.4k
#endif
256
59.4k
        c->m4_m++;
257
59.4k
    }
258
259
861k
    c->last_m_len = x_len;
260
861k
    c->last_m_off = x_off;
261
861k
    return op;
262
861k
}
lzo1y_9x.c:code_match
Line
Count
Source
108
718k
{
109
718k
    lzo_uint x_len = m_len;
110
718k
    lzo_uint x_off = m_off;
111
112
718k
    c->match_bytes += m_len;
113
114
#if 0
115
/*
116
    static lzo_uint last_m_len = 0, last_m_off = 0;
117
    static lzo_uint prev_m_off[4];
118
    static unsigned prev_m_off_ptr = 0;
119
    unsigned i;
120
121
    //if (m_len >= 3 && m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
122
    if (m_len >= 3 && m_len <= M2_MAX_LEN)
123
    {
124
    //if (m_len == last_m_len && m_off == last_m_off)
125
        //printf("last_m_len + last_m_off\n");
126
    //else
127
    if (m_off == last_m_off)
128
        printf("last_m_off\n");
129
    else
130
    {
131
        for (i = 0; i < 4; i++)
132
            if (m_off == prev_m_off[i])
133
                printf("prev_m_off %u: %5ld\n",i,(long)m_off);
134
    }
135
    }
136
    last_m_len = m_len;
137
    last_m_off = prev_m_off[prev_m_off_ptr] = m_off;
138
    prev_m_off_ptr = (prev_m_off_ptr + 1) & 3;
139
*/
140
#endif
141
142
718k
    assert(op > c->out);
143
718k
    if (m_len == 2)
144
136k
    {
145
136k
        assert(m_off <= M1_MAX_OFFSET);
146
136k
        assert(c->r1_lit > 0); assert(c->r1_lit < 4);
147
136k
        m_off -= 1;
148
#if defined(LZO1Z)
149
        *op++ = LZO_BYTE(M1_MARKER | (m_off >> 6));
150
        *op++ = LZO_BYTE(m_off << 2);
151
#else
152
136k
        *op++ = LZO_BYTE(M1_MARKER | ((m_off & 3) << 2));
153
136k
        *op++ = LZO_BYTE(m_off >> 2);
154
136k
#endif
155
136k
        c->m1a_m++;
156
136k
    }
157
#if defined(LZO1Z)
158
    else if (m_len <= M2_MAX_LEN && (m_off <= M2_MAX_OFFSET || m_off == c->last_m_off))
159
#else
160
581k
    else if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
161
309k
#endif
162
309k
    {
163
309k
        assert(m_len >= 3);
164
#if defined(LZO1X)
165
        m_off -= 1;
166
        *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2));
167
        *op++ = LZO_BYTE(m_off >> 3);
168
        assert(op[-2] >= M2_MARKER);
169
#elif defined(LZO1Y)
170
        m_off -= 1;
171
309k
        *op++ = LZO_BYTE(((m_len + 1) << 4) | ((m_off & 3) << 2));
172
309k
        *op++ = LZO_BYTE(m_off >> 2);
173
309k
        assert(op[-2] >= M2_MARKER);
174
#elif defined(LZO1Z)
175
        if (m_off == c->last_m_off)
176
            *op++ = LZO_BYTE(((m_len - 1) << 5) | (0x700 >> 6));
177
        else
178
        {
179
            m_off -= 1;
180
            *op++ = LZO_BYTE(((m_len - 1) << 5) | (m_off >> 6));
181
            *op++ = LZO_BYTE(m_off << 2);
182
        }
183
#endif
184
309k
        c->m2_m++;
185
309k
    }
186
272k
    else if (m_len == M2_MIN_LEN && m_off <= MX_MAX_OFFSET && c->r1_lit >= 4)
187
5.69k
    {
188
5.69k
        assert(m_len == 3);
189
5.69k
        assert(m_off > M2_MAX_OFFSET);
190
5.69k
        m_off -= 1 + M2_MAX_OFFSET;
191
#if defined(LZO1Z)
192
        *op++ = LZO_BYTE(M1_MARKER | (m_off >> 6));
193
        *op++ = LZO_BYTE(m_off << 2);
194
#else
195
5.69k
        *op++ = LZO_BYTE(M1_MARKER | ((m_off & 3) << 2));
196
5.69k
        *op++ = LZO_BYTE(m_off >> 2);
197
5.69k
#endif
198
5.69k
        c->m1b_m++;
199
5.69k
    }
200
267k
    else if (m_off <= M3_MAX_OFFSET)
201
208k
    {
202
208k
        assert(m_len >= 3);
203
208k
        m_off -= 1;
204
208k
        if (m_len <= M3_MAX_LEN)
205
166k
            *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
206
41.6k
        else
207
41.6k
        {
208
41.6k
            m_len -= M3_MAX_LEN;
209
41.6k
            *op++ = M3_MARKER | 0;
210
74.2k
            while (m_len > 255)
211
32.5k
            {
212
32.5k
                m_len -= 255;
213
32.5k
                *op++ = 0;
214
32.5k
            }
215
41.6k
            assert(m_len > 0);
216
41.6k
            *op++ = LZO_BYTE(m_len);
217
41.6k
        }
218
#if defined(LZO1Z)
219
        *op++ = LZO_BYTE(m_off >> 6);
220
        *op++ = LZO_BYTE(m_off << 2);
221
#else
222
208k
        *op++ = LZO_BYTE(m_off << 2);
223
208k
        *op++ = LZO_BYTE(m_off >> 6);
224
208k
#endif
225
208k
        c->m3_m++;
226
208k
    }
227
59.0k
    else
228
59.0k
    {
229
59.0k
        lzo_uint k;
230
231
59.0k
        assert(m_len >= 3);
232
59.0k
        assert(m_off > 0x4000); assert(m_off <= 0xbfff);
233
59.0k
        m_off -= 0x4000;
234
59.0k
        k = (m_off & 0x4000) >> 11;
235
59.0k
        if (m_len <= M4_MAX_LEN)
236
36.0k
            *op++ = LZO_BYTE(M4_MARKER | k | (m_len - 2));
237
23.0k
        else
238
23.0k
        {
239
23.0k
            m_len -= M4_MAX_LEN;
240
23.0k
            *op++ = LZO_BYTE(M4_MARKER | k | 0);
241
29.5k
            while (m_len > 255)
242
6.49k
            {
243
6.49k
                m_len -= 255;
244
6.49k
                *op++ = 0;
245
6.49k
            }
246
23.0k
            assert(m_len > 0);
247
23.0k
            *op++ = LZO_BYTE(m_len);
248
23.0k
        }
249
#if defined(LZO1Z)
250
        *op++ = LZO_BYTE(m_off >> 6);
251
        *op++ = LZO_BYTE(m_off << 2);
252
#else
253
59.0k
        *op++ = LZO_BYTE(m_off << 2);
254
59.0k
        *op++ = LZO_BYTE(m_off >> 6);
255
59.0k
#endif
256
59.0k
        c->m4_m++;
257
59.0k
    }
258
259
718k
    c->last_m_len = x_len;
260
718k
    c->last_m_off = x_off;
261
718k
    return op;
262
718k
}
lzo1z_9x.c:code_match
Line
Count
Source
108
1.00M
{
109
1.00M
    lzo_uint x_len = m_len;
110
1.00M
    lzo_uint x_off = m_off;
111
112
1.00M
    c->match_bytes += m_len;
113
114
#if 0
115
/*
116
    static lzo_uint last_m_len = 0, last_m_off = 0;
117
    static lzo_uint prev_m_off[4];
118
    static unsigned prev_m_off_ptr = 0;
119
    unsigned i;
120
121
    //if (m_len >= 3 && m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
122
    if (m_len >= 3 && m_len <= M2_MAX_LEN)
123
    {
124
    //if (m_len == last_m_len && m_off == last_m_off)
125
        //printf("last_m_len + last_m_off\n");
126
    //else
127
    if (m_off == last_m_off)
128
        printf("last_m_off\n");
129
    else
130
    {
131
        for (i = 0; i < 4; i++)
132
            if (m_off == prev_m_off[i])
133
                printf("prev_m_off %u: %5ld\n",i,(long)m_off);
134
    }
135
    }
136
    last_m_len = m_len;
137
    last_m_off = prev_m_off[prev_m_off_ptr] = m_off;
138
    prev_m_off_ptr = (prev_m_off_ptr + 1) & 3;
139
*/
140
#endif
141
142
1.00M
    assert(op > c->out);
143
1.00M
    if (m_len == 2)
144
206k
    {
145
206k
        assert(m_off <= M1_MAX_OFFSET);
146
206k
        assert(c->r1_lit > 0); assert(c->r1_lit < 4);
147
206k
        m_off -= 1;
148
206k
#if defined(LZO1Z)
149
206k
        *op++ = LZO_BYTE(M1_MARKER | (m_off >> 6));
150
206k
        *op++ = LZO_BYTE(m_off << 2);
151
#else
152
        *op++ = LZO_BYTE(M1_MARKER | ((m_off & 3) << 2));
153
        *op++ = LZO_BYTE(m_off >> 2);
154
#endif
155
206k
        c->m1a_m++;
156
206k
    }
157
797k
#if defined(LZO1Z)
158
797k
    else if (m_len <= M2_MAX_LEN && (m_off <= M2_MAX_OFFSET || m_off == c->last_m_off))
159
#else
160
    else if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
161
#endif
162
367k
    {
163
367k
        assert(m_len >= 3);
164
#if defined(LZO1X)
165
        m_off -= 1;
166
        *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2));
167
        *op++ = LZO_BYTE(m_off >> 3);
168
        assert(op[-2] >= M2_MARKER);
169
#elif defined(LZO1Y)
170
        m_off -= 1;
171
        *op++ = LZO_BYTE(((m_len + 1) << 4) | ((m_off & 3) << 2));
172
        *op++ = LZO_BYTE(m_off >> 2);
173
        assert(op[-2] >= M2_MARKER);
174
#elif defined(LZO1Z)
175
367k
        if (m_off == c->last_m_off)
176
23.2k
            *op++ = LZO_BYTE(((m_len - 1) << 5) | (0x700 >> 6));
177
344k
        else
178
344k
        {
179
344k
            m_off -= 1;
180
344k
            *op++ = LZO_BYTE(((m_len - 1) << 5) | (m_off >> 6));
181
344k
            *op++ = LZO_BYTE(m_off << 2);
182
344k
        }
183
367k
#endif
184
367k
        c->m2_m++;
185
367k
    }
186
430k
    else if (m_len == M2_MIN_LEN && m_off <= MX_MAX_OFFSET && c->r1_lit >= 4)
187
4.32k
    {
188
4.32k
        assert(m_len == 3);
189
4.32k
        assert(m_off > M2_MAX_OFFSET);
190
4.32k
        m_off -= 1 + M2_MAX_OFFSET;
191
4.32k
#if defined(LZO1Z)
192
4.32k
        *op++ = LZO_BYTE(M1_MARKER | (m_off >> 6));
193
4.32k
        *op++ = LZO_BYTE(m_off << 2);
194
#else
195
        *op++ = LZO_BYTE(M1_MARKER | ((m_off & 3) << 2));
196
        *op++ = LZO_BYTE(m_off >> 2);
197
#endif
198
4.32k
        c->m1b_m++;
199
4.32k
    }
200
425k
    else if (m_off <= M3_MAX_OFFSET)
201
314k
    {
202
314k
        assert(m_len >= 3);
203
314k
        m_off -= 1;
204
314k
        if (m_len <= M3_MAX_LEN)
205
268k
            *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
206
46.0k
        else
207
46.0k
        {
208
46.0k
            m_len -= M3_MAX_LEN;
209
46.0k
            *op++ = M3_MARKER | 0;
210
86.1k
            while (m_len > 255)
211
40.1k
            {
212
40.1k
                m_len -= 255;
213
40.1k
                *op++ = 0;
214
40.1k
            }
215
46.0k
            assert(m_len > 0);
216
46.0k
            *op++ = LZO_BYTE(m_len);
217
46.0k
        }
218
314k
#if defined(LZO1Z)
219
314k
        *op++ = LZO_BYTE(m_off >> 6);
220
314k
        *op++ = LZO_BYTE(m_off << 2);
221
#else
222
        *op++ = LZO_BYTE(m_off << 2);
223
        *op++ = LZO_BYTE(m_off >> 6);
224
#endif
225
314k
        c->m3_m++;
226
314k
    }
227
111k
    else
228
111k
    {
229
111k
        lzo_uint k;
230
231
111k
        assert(m_len >= 3);
232
111k
        assert(m_off > 0x4000); assert(m_off <= 0xbfff);
233
111k
        m_off -= 0x4000;
234
111k
        k = (m_off & 0x4000) >> 11;
235
111k
        if (m_len <= M4_MAX_LEN)
236
81.3k
            *op++ = LZO_BYTE(M4_MARKER | k | (m_len - 2));
237
30.3k
        else
238
30.3k
        {
239
30.3k
            m_len -= M4_MAX_LEN;
240
30.3k
            *op++ = LZO_BYTE(M4_MARKER | k | 0);
241
37.1k
            while (m_len > 255)
242
6.70k
            {
243
6.70k
                m_len -= 255;
244
6.70k
                *op++ = 0;
245
6.70k
            }
246
30.3k
            assert(m_len > 0);
247
30.3k
            *op++ = LZO_BYTE(m_len);
248
30.3k
        }
249
111k
#if defined(LZO1Z)
250
111k
        *op++ = LZO_BYTE(m_off >> 6);
251
111k
        *op++ = LZO_BYTE(m_off << 2);
252
#else
253
        *op++ = LZO_BYTE(m_off << 2);
254
        *op++ = LZO_BYTE(m_off >> 6);
255
#endif
256
111k
        c->m4_m++;
257
111k
    }
258
259
1.00M
    c->last_m_len = x_len;
260
1.00M
    c->last_m_off = x_off;
261
1.00M
    return op;
262
1.00M
}
263
264
265
static lzo_bytep
266
STORE_RUN ( LZO_COMPRESS_T *c, lzo_bytep op, const lzo_bytep ii, lzo_uint t )
267
1.75M
{
268
1.75M
    c->lit_bytes += t;
269
270
1.75M
    if (op == c->out && t <= 238)
271
4.19k
    {
272
4.19k
        *op++ = LZO_BYTE(17 + t);
273
4.19k
    }
274
1.75M
    else if (t <= 3)
275
1.58M
    {
276
#if defined(LZO1Z)
277
617k
        op[-1] = LZO_BYTE(op[-1] | t);
278
#else
279
964k
        op[-2] = LZO_BYTE(op[-2] | t);
280
#endif
281
1.58M
        c->lit1_r++;
282
1.58M
    }
283
169k
    else if (t <= 18)
284
110k
    {
285
110k
        *op++ = LZO_BYTE(t - 3);
286
110k
        c->lit2_r++;
287
110k
    }
288
59.3k
    else
289
59.3k
    {
290
59.3k
        lzo_uint tt = t - 18;
291
292
59.3k
        *op++ = 0;
293
185k
        while (tt > 255)
294
126k
        {
295
126k
            tt -= 255;
296
126k
            *op++ = 0;
297
126k
        }
298
59.3k
        assert(tt > 0);
299
59.3k
        *op++ = LZO_BYTE(tt);
300
59.3k
        c->lit3_r++;
301
59.3k
    }
302
40.0M
    do *op++ = *ii++; while (--t > 0);
303
304
1.75M
    return op;
305
1.75M
}
lzo1x_9x.c:STORE_RUN
Line
Count
Source
267
600k
{
268
600k
    c->lit_bytes += t;
269
270
600k
    if (op == c->out && t <= 238)
271
1.30k
    {
272
1.30k
        *op++ = LZO_BYTE(17 + t);
273
1.30k
    }
274
599k
    else if (t <= 3)
275
547k
    {
276
#if defined(LZO1Z)
277
        op[-1] = LZO_BYTE(op[-1] | t);
278
#else
279
547k
        op[-2] = LZO_BYTE(op[-2] | t);
280
547k
#endif
281
547k
        c->lit1_r++;
282
547k
    }
283
51.9k
    else if (t <= 18)
284
36.1k
    {
285
36.1k
        *op++ = LZO_BYTE(t - 3);
286
36.1k
        c->lit2_r++;
287
36.1k
    }
288
15.7k
    else
289
15.7k
    {
290
15.7k
        lzo_uint tt = t - 18;
291
292
15.7k
        *op++ = 0;
293
44.5k
        while (tt > 255)
294
28.7k
        {
295
28.7k
            tt -= 255;
296
28.7k
            *op++ = 0;
297
28.7k
        }
298
15.7k
        assert(tt > 0);
299
15.7k
        *op++ = LZO_BYTE(tt);
300
15.7k
        c->lit3_r++;
301
15.7k
    }
302
9.55M
    do *op++ = *ii++; while (--t > 0);
303
304
600k
    return op;
305
600k
}
lzo1y_9x.c:STORE_RUN
Line
Count
Source
267
479k
{
268
479k
    c->lit_bytes += t;
269
270
479k
    if (op == c->out && t <= 238)
271
1.28k
    {
272
1.28k
        *op++ = LZO_BYTE(17 + t);
273
1.28k
    }
274
478k
    else if (t <= 3)
275
416k
    {
276
#if defined(LZO1Z)
277
        op[-1] = LZO_BYTE(op[-1] | t);
278
#else
279
416k
        op[-2] = LZO_BYTE(op[-2] | t);
280
416k
#endif
281
416k
        c->lit1_r++;
282
416k
    }
283
61.5k
    else if (t <= 18)
284
35.4k
    {
285
35.4k
        *op++ = LZO_BYTE(t - 3);
286
35.4k
        c->lit2_r++;
287
35.4k
    }
288
26.0k
    else
289
26.0k
    {
290
26.0k
        lzo_uint tt = t - 18;
291
292
26.0k
        *op++ = 0;
293
89.0k
        while (tt > 255)
294
62.9k
        {
295
62.9k
            tt -= 255;
296
62.9k
            *op++ = 0;
297
62.9k
        }
298
26.0k
        assert(tt > 0);
299
26.0k
        *op++ = LZO_BYTE(tt);
300
26.0k
        c->lit3_r++;
301
26.0k
    }
302
19.2M
    do *op++ = *ii++; while (--t > 0);
303
304
479k
    return op;
305
479k
}
lzo1z_9x.c:STORE_RUN
Line
Count
Source
267
675k
{
268
675k
    c->lit_bytes += t;
269
270
675k
    if (op == c->out && t <= 238)
271
1.60k
    {
272
1.60k
        *op++ = LZO_BYTE(17 + t);
273
1.60k
    }
274
673k
    else if (t <= 3)
275
617k
    {
276
617k
#if defined(LZO1Z)
277
617k
        op[-1] = LZO_BYTE(op[-1] | t);
278
#else
279
        op[-2] = LZO_BYTE(op[-2] | t);
280
#endif
281
617k
        c->lit1_r++;
282
617k
    }
283
56.3k
    else if (t <= 18)
284
38.8k
    {
285
38.8k
        *op++ = LZO_BYTE(t - 3);
286
38.8k
        c->lit2_r++;
287
38.8k
    }
288
17.5k
    else
289
17.5k
    {
290
17.5k
        lzo_uint tt = t - 18;
291
292
17.5k
        *op++ = 0;
293
51.9k
        while (tt > 255)
294
34.4k
        {
295
34.4k
            tt -= 255;
296
34.4k
            *op++ = 0;
297
34.4k
        }
298
17.5k
        assert(tt > 0);
299
17.5k
        *op++ = LZO_BYTE(tt);
300
17.5k
        c->lit3_r++;
301
17.5k
    }
302
11.2M
    do *op++ = *ii++; while (--t > 0);
303
304
675k
    return op;
305
675k
}
306
307
308
static lzo_bytep
309
code_run ( LZO_COMPRESS_T *c, lzo_bytep op, const lzo_bytep ii,
310
           lzo_uint lit, lzo_uint m_len )
311
2.58M
{
312
2.58M
    if (lit > 0)
313
1.75M
    {
314
1.75M
        assert(m_len >= 2);
315
1.75M
        op = STORE_RUN(c,op,ii,lit);
316
1.75M
        c->r1_m_len = m_len;
317
1.75M
        c->r1_lit = lit;
318
1.75M
    }
319
831k
    else
320
831k
    {
321
831k
        assert(m_len >= 3);
322
831k
        c->r1_m_len = 0;
323
831k
        c->r1_lit = 0;
324
831k
    }
325
326
2.58M
    return op;
327
2.58M
}
lzo1x_9x.c:code_run
Line
Count
Source
311
861k
{
312
861k
    if (lit > 0)
313
600k
    {
314
600k
        assert(m_len >= 2);
315
600k
        op = STORE_RUN(c,op,ii,lit);
316
600k
        c->r1_m_len = m_len;
317
600k
        c->r1_lit = lit;
318
600k
    }
319
261k
    else
320
261k
    {
321
261k
        assert(m_len >= 3);
322
261k
        c->r1_m_len = 0;
323
261k
        c->r1_lit = 0;
324
261k
    }
325
326
861k
    return op;
327
861k
}
lzo1y_9x.c:code_run
Line
Count
Source
311
718k
{
312
718k
    if (lit > 0)
313
478k
    {
314
478k
        assert(m_len >= 2);
315
478k
        op = STORE_RUN(c,op,ii,lit);
316
478k
        c->r1_m_len = m_len;
317
478k
        c->r1_lit = lit;
318
478k
    }
319
240k
    else
320
240k
    {
321
240k
        assert(m_len >= 3);
322
240k
        c->r1_m_len = 0;
323
240k
        c->r1_lit = 0;
324
240k
    }
325
326
718k
    return op;
327
718k
}
lzo1z_9x.c:code_run
Line
Count
Source
311
1.00M
{
312
1.00M
    if (lit > 0)
313
674k
    {
314
674k
        assert(m_len >= 2);
315
674k
        op = STORE_RUN(c,op,ii,lit);
316
674k
        c->r1_m_len = m_len;
317
674k
        c->r1_lit = lit;
318
674k
    }
319
329k
    else
320
329k
    {
321
329k
        assert(m_len >= 3);
322
329k
        c->r1_m_len = 0;
323
329k
        c->r1_lit = 0;
324
329k
    }
325
326
1.00M
    return op;
327
1.00M
}
328
329
330
/***********************************************************************
331
//
332
************************************************************************/
333
334
static lzo_uint
335
len_of_coded_match ( lzo_uint m_len, lzo_uint m_off, lzo_uint lit )
336
5.65M
{
337
5.65M
    lzo_uint n = 4;
338
339
5.65M
    if (m_len < 2)
340
1.05M
        return 0;
341
4.60M
    if (m_len == 2)
342
1.07M
        return (m_off <= M1_MAX_OFFSET && lit > 0 && lit < 4) ? 2 : 0;
343
3.53M
    if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
344
1.54M
        return 2;
345
1.98M
    if (m_len == M2_MIN_LEN && m_off <= MX_MAX_OFFSET && lit >= 4)
346
15.2k
        return 2;
347
1.97M
    if (m_off <= M3_MAX_OFFSET)
348
1.49M
    {
349
1.49M
        if (m_len <= M3_MAX_LEN)
350
1.35M
            return 3;
351
132k
        m_len -= M3_MAX_LEN;
352
137k
        while (m_len > 255)
353
5.63k
        {
354
5.63k
            m_len -= 255;
355
5.63k
            n++;
356
5.63k
        }
357
132k
        return n;
358
1.49M
    }
359
480k
    if (m_off <= M4_MAX_OFFSET)
360
480k
    {
361
480k
        if (m_len <= M4_MAX_LEN)
362
334k
            return 3;
363
146k
        m_len -= M4_MAX_LEN;
364
149k
        while (m_len > 255)
365
2.81k
        {
366
2.81k
            m_len -= 255;
367
2.81k
            n++;
368
2.81k
        }
369
146k
        return n;
370
480k
    }
371
0
    return 0;
372
480k
}
lzo1x_9x.c:len_of_coded_match
Line
Count
Source
336
1.93M
{
337
1.93M
    lzo_uint n = 4;
338
339
1.93M
    if (m_len < 2)
340
382k
        return 0;
341
1.55M
    if (m_len == 2)
342
412k
        return (m_off <= M1_MAX_OFFSET && lit > 0 && lit < 4) ? 2 : 0;
343
1.13M
    if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
344
508k
        return 2;
345
629k
    if (m_len == M2_MIN_LEN && m_off <= MX_MAX_OFFSET && lit >= 4)
346
3.54k
        return 2;
347
625k
    if (m_off <= M3_MAX_OFFSET)
348
488k
    {
349
488k
        if (m_len <= M3_MAX_LEN)
350
447k
            return 3;
351
40.9k
        m_len -= M3_MAX_LEN;
352
43.0k
        while (m_len > 255)
353
2.02k
        {
354
2.02k
            m_len -= 255;
355
2.02k
            n++;
356
2.02k
        }
357
40.9k
        return n;
358
488k
    }
359
137k
    if (m_off <= M4_MAX_OFFSET)
360
137k
    {
361
137k
        if (m_len <= M4_MAX_LEN)
362
88.0k
            return 3;
363
49.5k
        m_len -= M4_MAX_LEN;
364
50.5k
        while (m_len > 255)
365
1.05k
        {
366
1.05k
            m_len -= 255;
367
1.05k
            n++;
368
1.05k
        }
369
49.5k
        return n;
370
137k
    }
371
0
    return 0;
372
137k
}
lzo1y_9x.c:len_of_coded_match
Line
Count
Source
336
1.52M
{
337
1.52M
    lzo_uint n = 4;
338
339
1.52M
    if (m_len < 2)
340
272k
        return 0;
341
1.25M
    if (m_len == 2)
342
243k
        return (m_off <= M1_MAX_OFFSET && lit > 0 && lit < 4) ? 2 : 0;
343
1.00M
    if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
344
485k
        return 2;
345
524k
    if (m_len == M2_MIN_LEN && m_off <= MX_MAX_OFFSET && lit >= 4)
346
6.50k
        return 2;
347
517k
    if (m_off <= M3_MAX_OFFSET)
348
398k
    {
349
398k
        if (m_len <= M3_MAX_LEN)
350
354k
            return 3;
351
44.3k
        m_len -= M3_MAX_LEN;
352
46.2k
        while (m_len > 255)
353
1.90k
        {
354
1.90k
            m_len -= 255;
355
1.90k
            n++;
356
1.90k
        }
357
44.3k
        return n;
358
398k
    }
359
118k
    if (m_off <= M4_MAX_OFFSET)
360
118k
    {
361
118k
        if (m_len <= M4_MAX_LEN)
362
77.5k
            return 3;
363
41.3k
        m_len -= M4_MAX_LEN;
364
42.1k
        while (m_len > 255)
365
843
        {
366
843
            m_len -= 255;
367
843
            n++;
368
843
        }
369
41.3k
        return n;
370
118k
    }
371
0
    return 0;
372
118k
}
lzo1z_9x.c:len_of_coded_match
Line
Count
Source
336
2.19M
{
337
2.19M
    lzo_uint n = 4;
338
339
2.19M
    if (m_len < 2)
340
395k
        return 0;
341
1.80M
    if (m_len == 2)
342
413k
        return (m_off <= M1_MAX_OFFSET && lit > 0 && lit < 4) ? 2 : 0;
343
1.38M
    if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
344
554k
        return 2;
345
834k
    if (m_len == M2_MIN_LEN && m_off <= MX_MAX_OFFSET && lit >= 4)
346
5.18k
        return 2;
347
829k
    if (m_off <= M3_MAX_OFFSET)
348
604k
    {
349
604k
        if (m_len <= M3_MAX_LEN)
350
557k
            return 3;
351
46.9k
        m_len -= M3_MAX_LEN;
352
48.6k
        while (m_len > 255)
353
1.70k
        {
354
1.70k
            m_len -= 255;
355
1.70k
            n++;
356
1.70k
        }
357
46.9k
        return n;
358
604k
    }
359
224k
    if (m_off <= M4_MAX_OFFSET)
360
224k
    {
361
224k
        if (m_len <= M4_MAX_LEN)
362
169k
            return 3;
363
55.3k
        m_len -= M4_MAX_LEN;
364
56.3k
        while (m_len > 255)
365
913
        {
366
913
            m_len -= 255;
367
913
            n++;
368
913
        }
369
55.3k
        return n;
370
224k
    }
371
0
    return 0;
372
224k
}
373
374
375
static lzo_uint
376
min_gain(lzo_uint ahead, lzo_uint lit1, lzo_uint lit2, lzo_uint l1, lzo_uint l2, lzo_uint l3)
377
1.24M
{
378
1.24M
    lzo_uint lazy_match_min_gain;
379
380
1.24M
    assert (ahead >= 1);
381
1.24M
    lazy_match_min_gain = ahead;
382
383
#if 0
384
    if (l3)
385
        lit2 -= ahead;
386
#endif
387
388
1.24M
    if (lit1 <= 3)
389
1.21M
        lazy_match_min_gain += (lit2 <= 3) ? 0 : 2;
390
22.8k
    else if (lit1 <= 18)
391
16.9k
        lazy_match_min_gain += (lit2 <= 18) ? 0 : 1;
392
393
1.24M
    lazy_match_min_gain += (l2 - l1) * 2;
394
1.24M
    if (l3)
395
7.55k
        lazy_match_min_gain -= (ahead - l3) * 2;
396
397
1.24M
    if ((lzo_int) lazy_match_min_gain < 0)
398
101k
        lazy_match_min_gain = 0;
399
400
#if 0
401
    if (l1 == 2)
402
        if (lazy_match_min_gain == 0)
403
            lazy_match_min_gain = 1;
404
#endif
405
406
1.24M
    return lazy_match_min_gain;
407
1.24M
}
lzo1x_9x.c:min_gain
Line
Count
Source
377
436k
{
378
436k
    lzo_uint lazy_match_min_gain;
379
380
436k
    assert (ahead >= 1);
381
436k
    lazy_match_min_gain = ahead;
382
383
#if 0
384
    if (l3)
385
        lit2 -= ahead;
386
#endif
387
388
436k
    if (lit1 <= 3)
389
428k
        lazy_match_min_gain += (lit2 <= 3) ? 0 : 2;
390
7.60k
    else if (lit1 <= 18)
391
5.72k
        lazy_match_min_gain += (lit2 <= 18) ? 0 : 1;
392
393
436k
    lazy_match_min_gain += (l2 - l1) * 2;
394
436k
    if (l3)
395
3.19k
        lazy_match_min_gain -= (ahead - l3) * 2;
396
397
436k
    if ((lzo_int) lazy_match_min_gain < 0)
398
28.3k
        lazy_match_min_gain = 0;
399
400
#if 0
401
    if (l1 == 2)
402
        if (lazy_match_min_gain == 0)
403
            lazy_match_min_gain = 1;
404
#endif
405
406
436k
    return lazy_match_min_gain;
407
436k
}
lzo1y_9x.c:min_gain
Line
Count
Source
377
319k
{
378
319k
    lzo_uint lazy_match_min_gain;
379
380
319k
    assert (ahead >= 1);
381
319k
    lazy_match_min_gain = ahead;
382
383
#if 0
384
    if (l3)
385
        lit2 -= ahead;
386
#endif
387
388
319k
    if (lit1 <= 3)
389
311k
        lazy_match_min_gain += (lit2 <= 3) ? 0 : 2;
390
8.08k
    else if (lit1 <= 18)
391
5.63k
        lazy_match_min_gain += (lit2 <= 18) ? 0 : 1;
392
393
319k
    lazy_match_min_gain += (l2 - l1) * 2;
394
319k
    if (l3)
395
1.11k
        lazy_match_min_gain -= (ahead - l3) * 2;
396
397
319k
    if ((lzo_int) lazy_match_min_gain < 0)
398
35.1k
        lazy_match_min_gain = 0;
399
400
#if 0
401
    if (l1 == 2)
402
        if (lazy_match_min_gain == 0)
403
            lazy_match_min_gain = 1;
404
#endif
405
406
319k
    return lazy_match_min_gain;
407
319k
}
lzo1z_9x.c:min_gain
Line
Count
Source
377
485k
{
378
485k
    lzo_uint lazy_match_min_gain;
379
380
485k
    assert (ahead >= 1);
381
485k
    lazy_match_min_gain = ahead;
382
383
#if 0
384
    if (l3)
385
        lit2 -= ahead;
386
#endif
387
388
485k
    if (lit1 <= 3)
389
477k
        lazy_match_min_gain += (lit2 <= 3) ? 0 : 2;
390
7.20k
    else if (lit1 <= 18)
391
5.60k
        lazy_match_min_gain += (lit2 <= 18) ? 0 : 1;
392
393
485k
    lazy_match_min_gain += (l2 - l1) * 2;
394
485k
    if (l3)
395
3.24k
        lazy_match_min_gain -= (ahead - l3) * 2;
396
397
485k
    if ((lzo_int) lazy_match_min_gain < 0)
398
38.4k
        lazy_match_min_gain = 0;
399
400
#if 0
401
    if (l1 == 2)
402
        if (lazy_match_min_gain == 0)
403
            lazy_match_min_gain = 1;
404
#endif
405
406
485k
    return lazy_match_min_gain;
407
485k
}
408
409
410
/***********************************************************************
411
//
412
************************************************************************/
413
414
#if !defined(NDEBUG)
415
static
416
void assert_match( const lzo_swd_p swd, lzo_uint m_len, lzo_uint m_off )
417
{
418
    const LZO_COMPRESS_T *c = swd->c;
419
    lzo_uint d_off;
420
421
    assert(m_len >= 2);
422
    if (m_off <= (lzo_uint) (c->bp - c->in))
423
    {
424
        assert(c->bp - m_off + m_len < c->ip);
425
        assert(lzo_memcmp(c->bp, c->bp - m_off, m_len) == 0);
426
    }
427
    else
428
    {
429
        assert(swd->dict != NULL);
430
        d_off = m_off - (lzo_uint) (c->bp - c->in);
431
        assert(d_off <= swd->dict_len);
432
        if (m_len > d_off)
433
        {
434
            assert(lzo_memcmp(c->bp, swd->dict_end - d_off, d_off) == 0);
435
            assert(c->in + m_len - d_off < c->ip);
436
            assert(lzo_memcmp(c->bp + d_off, c->in, m_len - d_off) == 0);
437
        }
438
        else
439
        {
440
            assert(lzo_memcmp(c->bp, swd->dict_end - d_off, m_len) == 0);
441
        }
442
    }
443
}
444
#else
445
3.87M
#  define assert_match(a,b,c)   ((void)0)
446
#endif
447
448
449
#if defined(SWD_BEST_OFF)
450
451
static void
452
better_match ( const lzo_swd_p swd, lzo_uint *m_len, lzo_uint *m_off )
453
4.47M
{
454
#if defined(LZO1Z)
455
    const LZO_COMPRESS_T *c = swd->c;
456
#endif
457
458
4.47M
    if (*m_len <= M2_MIN_LEN)
459
1.67M
        return;
460
#if defined(LZO1Z)
461
1.05M
    if (*m_off == c->last_m_off && *m_len <= M2_MAX_LEN)
462
23.6k
        return;
463
1.02M
#if 1
464
1.02M
    if (*m_len >= M2_MIN_LEN + 1 && *m_len <= M2_MAX_LEN + 1 &&
465
678k
        c->last_m_off && swd->best_off[*m_len-1] == c->last_m_off)
466
1.67k
    {
467
1.67k
        *m_len = *m_len - 1;
468
1.67k
        *m_off = swd->best_off[*m_len];
469
1.67k
        return;
470
1.67k
    }
471
1.02M
#endif
472
1.02M
#endif
473
474
2.76M
    if (*m_off <= M2_MAX_OFFSET)
475
1.38M
        return;
476
477
1.37M
#if 1
478
    /* M3/M4 -> M2 */
479
1.37M
    if (*m_off > M2_MAX_OFFSET &&
480
1.37M
        *m_len >= M2_MIN_LEN + 1 && *m_len <= M2_MAX_LEN + 1 &&
481
949k
        swd->best_off[*m_len-1] && swd->best_off[*m_len-1] <= M2_MAX_OFFSET)
482
145k
    {
483
145k
        *m_len = *m_len - 1;
484
145k
        *m_off = swd->best_off[*m_len];
485
145k
        return;
486
145k
    }
487
1.23M
#endif
488
489
1.23M
#if 1
490
    /* M4 -> M2 */
491
1.23M
    if (*m_off > M3_MAX_OFFSET &&
492
437k
        *m_len >= M4_MAX_LEN + 1 && *m_len <= M2_MAX_LEN + 2 &&
493
51.2k
        swd->best_off[*m_len-2] && swd->best_off[*m_len-2] <= M2_MAX_OFFSET)
494
6.05k
    {
495
6.05k
        *m_len = *m_len - 2;
496
6.05k
        *m_off = swd->best_off[*m_len];
497
6.05k
        return;
498
6.05k
    }
499
1.22M
#endif
500
501
1.22M
#if 1
502
    /* M4 -> M3 */
503
1.22M
    if (*m_off > M3_MAX_OFFSET &&
504
431k
        *m_len >= M4_MAX_LEN + 1 && *m_len <= M3_MAX_LEN + 1 &&
505
141k
        swd->best_off[*m_len-1] && swd->best_off[*m_len-1] <= M3_MAX_OFFSET)
506
15.4k
    {
507
15.4k
        *m_len = *m_len - 1;
508
15.4k
        *m_off = swd->best_off[*m_len];
509
15.4k
    }
510
1.22M
#endif
511
1.22M
}
lzo1x_9x.c:better_match
Line
Count
Source
453
1.51M
{
454
#if defined(LZO1Z)
455
    const LZO_COMPRESS_T *c = swd->c;
456
#endif
457
458
1.51M
    if (*m_len <= M2_MIN_LEN)
459
587k
        return;
460
#if defined(LZO1Z)
461
    if (*m_off == c->last_m_off && *m_len <= M2_MAX_LEN)
462
        return;
463
#if 1
464
    if (*m_len >= M2_MIN_LEN + 1 && *m_len <= M2_MAX_LEN + 1 &&
465
        c->last_m_off && swd->best_off[*m_len-1] == c->last_m_off)
466
    {
467
        *m_len = *m_len - 1;
468
        *m_off = swd->best_off[*m_len];
469
        return;
470
    }
471
#endif
472
#endif
473
474
927k
    if (*m_off <= M2_MAX_OFFSET)
475
516k
        return;
476
477
410k
#if 1
478
    /* M3/M4 -> M2 */
479
410k
    if (*m_off > M2_MAX_OFFSET &&
480
410k
        *m_len >= M2_MIN_LEN + 1 && *m_len <= M2_MAX_LEN + 1 &&
481
230k
        swd->best_off[*m_len-1] && swd->best_off[*m_len-1] <= M2_MAX_OFFSET)
482
46.2k
    {
483
46.2k
        *m_len = *m_len - 1;
484
46.2k
        *m_off = swd->best_off[*m_len];
485
46.2k
        return;
486
46.2k
    }
487
364k
#endif
488
489
364k
#if 1
490
    /* M4 -> M2 */
491
364k
    if (*m_off > M3_MAX_OFFSET &&
492
129k
        *m_len >= M4_MAX_LEN + 1 && *m_len <= M2_MAX_LEN + 2 &&
493
10.0k
        swd->best_off[*m_len-2] && swd->best_off[*m_len-2] <= M2_MAX_OFFSET)
494
1.70k
    {
495
1.70k
        *m_len = *m_len - 2;
496
1.70k
        *m_off = swd->best_off[*m_len];
497
1.70k
        return;
498
1.70k
    }
499
362k
#endif
500
501
362k
#if 1
502
    /* M4 -> M3 */
503
362k
    if (*m_off > M3_MAX_OFFSET &&
504
127k
        *m_len >= M4_MAX_LEN + 1 && *m_len <= M3_MAX_LEN + 1 &&
505
50.6k
        swd->best_off[*m_len-1] && swd->best_off[*m_len-1] <= M3_MAX_OFFSET)
506
6.81k
    {
507
6.81k
        *m_len = *m_len - 1;
508
6.81k
        *m_off = swd->best_off[*m_len];
509
6.81k
    }
510
362k
#endif
511
362k
}
lzo1y_9x.c:better_match
Line
Count
Source
453
1.22M
{
454
#if defined(LZO1Z)
455
    const LZO_COMPRESS_T *c = swd->c;
456
#endif
457
458
1.22M
    if (*m_len <= M2_MIN_LEN)
459
408k
        return;
460
#if defined(LZO1Z)
461
    if (*m_off == c->last_m_off && *m_len <= M2_MAX_LEN)
462
        return;
463
#if 1
464
    if (*m_len >= M2_MIN_LEN + 1 && *m_len <= M2_MAX_LEN + 1 &&
465
        c->last_m_off && swd->best_off[*m_len-1] == c->last_m_off)
466
    {
467
        *m_len = *m_len - 1;
468
        *m_off = swd->best_off[*m_len];
469
        return;
470
    }
471
#endif
472
#endif
473
474
815k
    if (*m_off <= M2_MAX_OFFSET)
475
390k
        return;
476
477
425k
#if 1
478
    /* M3/M4 -> M2 */
479
425k
    if (*m_off > M2_MAX_OFFSET &&
480
425k
        *m_len >= M2_MIN_LEN + 1 && *m_len <= M2_MAX_LEN + 1 &&
481
356k
        swd->best_off[*m_len-1] && swd->best_off[*m_len-1] <= M2_MAX_OFFSET)
482
50.8k
    {
483
50.8k
        *m_len = *m_len - 1;
484
50.8k
        *m_off = swd->best_off[*m_len];
485
50.8k
        return;
486
50.8k
    }
487
374k
#endif
488
489
374k
#if 1
490
    /* M4 -> M2 */
491
374k
    if (*m_off > M3_MAX_OFFSET &&
492
109k
        *m_len >= M4_MAX_LEN + 1 && *m_len <= M2_MAX_LEN + 2 &&
493
30.5k
        swd->best_off[*m_len-2] && swd->best_off[*m_len-2] <= M2_MAX_OFFSET)
494
2.48k
    {
495
2.48k
        *m_len = *m_len - 2;
496
2.48k
        *m_off = swd->best_off[*m_len];
497
2.48k
        return;
498
2.48k
    }
499
371k
#endif
500
501
371k
#if 1
502
    /* M4 -> M3 */
503
371k
    if (*m_off > M3_MAX_OFFSET &&
504
107k
        *m_len >= M4_MAX_LEN + 1 && *m_len <= M3_MAX_LEN + 1 &&
505
37.9k
        swd->best_off[*m_len-1] && swd->best_off[*m_len-1] <= M3_MAX_OFFSET)
506
3.37k
    {
507
3.37k
        *m_len = *m_len - 1;
508
3.37k
        *m_off = swd->best_off[*m_len];
509
3.37k
    }
510
371k
#endif
511
371k
}
lzo1z_9x.c:better_match
Line
Count
Source
453
1.73M
{
454
1.73M
#if defined(LZO1Z)
455
1.73M
    const LZO_COMPRESS_T *c = swd->c;
456
1.73M
#endif
457
458
1.73M
    if (*m_len <= M2_MIN_LEN)
459
683k
        return;
460
1.05M
#if defined(LZO1Z)
461
1.05M
    if (*m_off == c->last_m_off && *m_len <= M2_MAX_LEN)
462
23.6k
        return;
463
1.02M
#if 1
464
1.02M
    if (*m_len >= M2_MIN_LEN + 1 && *m_len <= M2_MAX_LEN + 1 &&
465
678k
        c->last_m_off && swd->best_off[*m_len-1] == c->last_m_off)
466
1.67k
    {
467
1.67k
        *m_len = *m_len - 1;
468
1.67k
        *m_off = swd->best_off[*m_len];
469
1.67k
        return;
470
1.67k
    }
471
1.02M
#endif
472
1.02M
#endif
473
474
1.02M
    if (*m_off <= M2_MAX_OFFSET)
475
482k
        return;
476
477
542k
#if 1
478
    /* M3/M4 -> M2 */
479
542k
    if (*m_off > M2_MAX_OFFSET &&
480
542k
        *m_len >= M2_MIN_LEN + 1 && *m_len <= M2_MAX_LEN + 1 &&
481
363k
        swd->best_off[*m_len-1] && swd->best_off[*m_len-1] <= M2_MAX_OFFSET)
482
48.6k
    {
483
48.6k
        *m_len = *m_len - 1;
484
48.6k
        *m_off = swd->best_off[*m_len];
485
48.6k
        return;
486
48.6k
    }
487
493k
#endif
488
489
493k
#if 1
490
    /* M4 -> M2 */
491
493k
    if (*m_off > M3_MAX_OFFSET &&
492
198k
        *m_len >= M4_MAX_LEN + 1 && *m_len <= M2_MAX_LEN + 2 &&
493
10.7k
        swd->best_off[*m_len-2] && swd->best_off[*m_len-2] <= M2_MAX_OFFSET)
494
1.86k
    {
495
1.86k
        *m_len = *m_len - 2;
496
1.86k
        *m_off = swd->best_off[*m_len];
497
1.86k
        return;
498
1.86k
    }
499
491k
#endif
500
501
491k
#if 1
502
    /* M4 -> M3 */
503
491k
    if (*m_off > M3_MAX_OFFSET &&
504
196k
        *m_len >= M4_MAX_LEN + 1 && *m_len <= M3_MAX_LEN + 1 &&
505
52.3k
        swd->best_off[*m_len-1] && swd->best_off[*m_len-1] <= M3_MAX_OFFSET)
506
5.29k
    {
507
5.29k
        *m_len = *m_len - 1;
508
5.29k
        *m_off = swd->best_off[*m_len];
509
5.29k
    }
510
491k
#endif
511
491k
}
512
513
#endif
514
515
516
/***********************************************************************
517
//
518
************************************************************************/
519
520
LZO_PUBLIC(int)
521
lzo1x_999_compress_internal ( const lzo_bytep in , lzo_uint  in_len,
522
                                    lzo_bytep out, lzo_uintp out_len,
523
                                    lzo_voidp wrkmem,
524
                              const lzo_bytep dict, lzo_uint dict_len,
525
                                    lzo_callback_p cb,
526
                                    int try_lazy_parm,
527
                                    lzo_uint good_length,
528
                                    lzo_uint max_lazy,
529
                                    lzo_uint nice_length,
530
                                    lzo_uint max_chain,
531
                                    lzo_uint32_t flags )
532
4.32k
{
533
4.32k
    lzo_bytep op;
534
4.32k
    const lzo_bytep ii;
535
4.32k
    lzo_uint lit;
536
4.32k
    lzo_uint m_len, m_off;
537
4.32k
    LZO_COMPRESS_T cc;
538
4.32k
    LZO_COMPRESS_T * const c = &cc;
539
4.32k
    lzo_swd_p const swd = (lzo_swd_p) wrkmem;
540
4.32k
    lzo_uint try_lazy;
541
4.32k
    int r;
542
543
    /* sanity check */
544
#if defined(LZO1X)
545
1.33k
    LZO_COMPILE_TIME_ASSERT(LZO1X_999_MEM_COMPRESS >= SIZEOF_LZO_SWD_T)
546
#elif defined(LZO1Y)
547
1.34k
    LZO_COMPILE_TIME_ASSERT(LZO1Y_999_MEM_COMPRESS >= SIZEOF_LZO_SWD_T)
548
#elif defined(LZO1Z)
549
1.64k
    LZO_COMPILE_TIME_ASSERT(LZO1Z_999_MEM_COMPRESS >= SIZEOF_LZO_SWD_T)
550
#else
551
#  error
552
#endif
553
554
/* setup parameter defaults */
555
    /* number of lazy match tries */
556
4.32k
    try_lazy = (lzo_uint) try_lazy_parm;
557
4.32k
    if (try_lazy_parm < 0)
558
0
        try_lazy = 1;
559
    /* reduce lazy match search if we already have a match with this length */
560
4.32k
    if (good_length == 0)
561
0
        good_length = 32;
562
    /* do not try a lazy match if we already have a match with this length */
563
4.32k
    if (max_lazy == 0)
564
0
        max_lazy = 32;
565
    /* stop searching for longer matches than this one */
566
4.32k
    if (nice_length == 0)
567
4.32k
        nice_length = 0;
568
    /* don't search more positions than this */
569
4.32k
    if (max_chain == 0)
570
0
        max_chain = SWD_MAX_CHAIN;
571
572
4.32k
    c->init = 0;
573
4.32k
    c->ip = c->in = in;
574
4.32k
    c->in_end = in + in_len;
575
4.32k
    c->out = out;
576
4.32k
    c->cb = cb;
577
4.32k
    c->m1a_m = c->m1b_m = c->m2_m = c->m3_m = c->m4_m = 0;
578
4.32k
    c->lit1_r = c->lit2_r = c->lit3_r = 0;
579
580
4.32k
    op = out;
581
4.32k
    ii = c->ip;             /* point to start of literal run */
582
4.32k
    lit = 0;
583
4.32k
    c->r1_lit = c->r1_m_len = 0;
584
585
4.32k
    r = init_match(c,swd,dict,dict_len,flags);
586
4.32k
    if (r != 0)
587
0
        return r;
588
4.32k
    if (max_chain > 0)
589
4.32k
        swd->max_chain = max_chain;
590
4.32k
    if (nice_length > 0)
591
0
        swd->nice_length = nice_length;
592
593
4.32k
    r = find_match(c,swd,0,0);
594
4.32k
    if (r != 0)
595
0
        return r;
596
42.5M
    while (c->look > 0)
597
42.5M
    {
598
42.5M
        lzo_uint ahead;
599
42.5M
        lzo_uint max_ahead;
600
42.5M
        lzo_uint l1, l2, l3;
601
602
42.5M
        c->codesize = pd(op, out);
603
604
42.5M
        m_len = c->m_len;
605
42.5M
        m_off = c->m_off;
606
607
42.5M
        assert(c->bp == c->ip - c->look);
608
42.5M
        assert(c->bp >= in);
609
42.5M
        if (lit == 0)
610
2.58M
            ii = c->bp;
611
42.5M
        assert(ii + lit == c->bp);
612
42.5M
        assert(swd->b_char == *(c->bp));
613
614
42.5M
        if ( m_len < 2 ||
615
21.1M
            (m_len == 2 && (m_off > M1_MAX_OFFSET || lit == 0 || lit >= 4)) ||
616
3.43M
#if 1
617
            /* Do not accept this match for compressed-data compatibility
618
             * with LZO v1.01 and before
619
             * [ might be a problem for decompress() and optimize() ]
620
             */
621
3.43M
            (m_len == 2 && op == out) ||
622
3.43M
#endif
623
3.43M
            (op == out && lit == 0))
624
39.0M
        {
625
            /* a literal */
626
39.0M
            m_len = 0;
627
39.0M
        }
628
3.43M
        else if (m_len == M2_MIN_LEN)
629
856k
        {
630
            /* compression ratio improves if we code a literal in some cases */
631
856k
            if (m_off > MX_MAX_OFFSET && lit >= 4)
632
205k
                m_len = 0;
633
856k
        }
634
635
42.5M
        if (m_len == 0)
636
39.2M
        {
637
    /* a literal */
638
39.2M
            lit++;
639
39.2M
            swd->max_chain = max_chain;
640
39.2M
            r = find_match(c,swd,1,0);
641
39.2M
            assert(r == 0); LZO_UNUSED(r);
642
39.2M
            continue;
643
39.2M
        }
644
645
    /* a match */
646
3.22M
#if defined(SWD_BEST_OFF)
647
3.22M
        if (swd->use_best_off)
648
3.22M
            better_match(swd,&m_len,&m_off);
649
3.22M
#endif
650
3.22M
        assert_match(swd,m_len,m_off);
651
652
653
        /* shall we try a lazy match ? */
654
3.22M
        ahead = 0;
655
3.22M
        if (try_lazy == 0 || m_len >= max_lazy)
656
54.0k
        {
657
            /* no */
658
54.0k
            l1 = 0;
659
54.0k
            max_ahead = 0;
660
54.0k
        }
661
3.17M
        else
662
3.17M
        {
663
            /* yes, try a lazy match */
664
3.17M
            l1 = len_of_coded_match(m_len,m_off,lit);
665
3.17M
            assert(l1 > 0);
666
3.17M
#if 1
667
3.17M
            max_ahead = LZO_MIN(try_lazy, l1 - 1);
668
#else
669
            max_ahead = LZO_MIN3(try_lazy, l1, m_len - 1);
670
#endif
671
3.17M
        }
672
673
674
6.80M
        while (ahead < max_ahead && c->look > m_len)
675
4.22M
        {
676
4.22M
            lzo_uint lazy_match_min_gain;
677
678
4.22M
            if (m_len >= good_length)
679
215k
                swd->max_chain = max_chain >> 2;
680
4.00M
            else
681
4.00M
                swd->max_chain = max_chain;
682
4.22M
            r = find_match(c,swd,1,0);
683
4.22M
            ahead++;
684
685
4.22M
            assert(r == 0); LZO_UNUSED(r);
686
4.22M
            assert(c->look > 0);
687
4.22M
            assert(ii + lit + ahead == c->bp);
688
689
#if defined(LZO1Z)
690
1.67M
            if (m_off == c->last_m_off && c->m_off != c->last_m_off)
691
148k
                if (m_len >= M2_MIN_LEN && m_len <= M2_MAX_LEN)
692
9.96k
                    c->m_len = 0;
693
#endif
694
4.22M
            if (c->m_len < m_len)
695
2.63M
                continue;
696
1.58M
#if 1
697
1.58M
            if (c->m_len == m_len && c->m_off >= m_off)
698
342k
                continue;
699
1.24M
#endif
700
1.24M
#if defined(SWD_BEST_OFF)
701
1.24M
            if (swd->use_best_off)
702
1.24M
                better_match(swd,&c->m_len,&c->m_off);
703
1.24M
#endif
704
1.24M
            l2 = len_of_coded_match(c->m_len,c->m_off,lit+ahead);
705
1.24M
            if (l2 == 0)
706
4.75k
                continue;
707
#if 0
708
            if (c->m_len == m_len && l2 >= l1)
709
                continue;
710
#endif
711
712
713
1.24M
#if 1
714
            /* compressed-data compatibility [see above] */
715
1.24M
            l3 = (op == out) ? 0 : len_of_coded_match(ahead,m_off,lit);
716
#else
717
            l3 = len_of_coded_match(ahead,m_off,lit);
718
#endif
719
720
1.24M
            lazy_match_min_gain = min_gain(ahead,lit,lit+ahead,l1,l2,l3);
721
1.24M
            if (c->m_len >= m_len + lazy_match_min_gain)
722
646k
            {
723
646k
                c->lazy++;
724
646k
                assert_match(swd,c->m_len,c->m_off);
725
726
646k
                if (l3)
727
4.19k
                {
728
                    /* code previous run */
729
4.19k
                    op = code_run(c,op,ii,lit,ahead);
730
4.19k
                    lit = 0;
731
                    /* code shortened match */
732
4.19k
                    op = code_match(c,op,ahead,m_off);
733
4.19k
                }
734
641k
                else
735
641k
                {
736
641k
                    lit += ahead;
737
641k
                    assert(ii + lit == c->bp);
738
641k
                }
739
646k
                goto lazy_match_done;
740
646k
            }
741
1.24M
        }
742
743
744
3.22M
        assert(ii + lit + ahead == c->bp);
745
746
        /* 1 - code run */
747
2.57M
        op = code_run(c,op,ii,lit,m_len);
748
2.57M
        lit = 0;
749
750
        /* 2 - code match */
751
2.57M
        op = code_match(c,op,m_len,m_off);
752
2.57M
        swd->max_chain = max_chain;
753
2.57M
        r = find_match(c,swd,m_len,1+ahead);
754
2.57M
        assert(r == 0); LZO_UNUSED(r);
755
756
3.22M
lazy_match_done: ;
757
3.22M
    }
758
759
760
    /* store final run */
761
4.32k
    if (lit > 0)
762
2.65k
        op = STORE_RUN(c,op,ii,lit);
763
764
4.32k
#if defined(LZO_EOF_CODE)
765
4.32k
    *op++ = M4_MARKER | 1;
766
4.32k
    *op++ = 0;
767
4.32k
    *op++ = 0;
768
4.32k
#endif
769
770
4.32k
    c->codesize = pd(op, out);
771
4.32k
    assert(c->textsize == in_len);
772
773
4.32k
    *out_len = pd(op, out);
774
775
4.32k
    if (c->cb && c->cb->nprogress)
776
0
        (*c->cb->nprogress)(c->cb, c->textsize, c->codesize, 0);
777
778
#if 0
779
    printf("%ld %ld -> %ld  %ld: %ld %ld %ld %ld %ld  %ld: %ld %ld %ld  %ld\n",
780
        (long) c->textsize, (long) in_len, (long) c->codesize,
781
        c->match_bytes, c->m1a_m, c->m1b_m, c->m2_m, c->m3_m, c->m4_m,
782
        c->lit_bytes, c->lit1_r, c->lit2_r, c->lit3_r, c->lazy);
783
#endif
784
4.32k
    assert(c->lit_bytes + c->match_bytes == in_len);
785
786
4.32k
    return LZO_E_OK;
787
4.32k
}
lzo1x_999_compress_internal
Line
Count
Source
532
1.33k
{
533
1.33k
    lzo_bytep op;
534
1.33k
    const lzo_bytep ii;
535
1.33k
    lzo_uint lit;
536
1.33k
    lzo_uint m_len, m_off;
537
1.33k
    LZO_COMPRESS_T cc;
538
1.33k
    LZO_COMPRESS_T * const c = &cc;
539
1.33k
    lzo_swd_p const swd = (lzo_swd_p) wrkmem;
540
1.33k
    lzo_uint try_lazy;
541
1.33k
    int r;
542
543
    /* sanity check */
544
1.33k
#if defined(LZO1X)
545
1.33k
    LZO_COMPILE_TIME_ASSERT(LZO1X_999_MEM_COMPRESS >= SIZEOF_LZO_SWD_T)
546
#elif defined(LZO1Y)
547
    LZO_COMPILE_TIME_ASSERT(LZO1Y_999_MEM_COMPRESS >= SIZEOF_LZO_SWD_T)
548
#elif defined(LZO1Z)
549
    LZO_COMPILE_TIME_ASSERT(LZO1Z_999_MEM_COMPRESS >= SIZEOF_LZO_SWD_T)
550
#else
551
#  error
552
#endif
553
554
/* setup parameter defaults */
555
    /* number of lazy match tries */
556
1.33k
    try_lazy = (lzo_uint) try_lazy_parm;
557
1.33k
    if (try_lazy_parm < 0)
558
0
        try_lazy = 1;
559
    /* reduce lazy match search if we already have a match with this length */
560
1.33k
    if (good_length == 0)
561
0
        good_length = 32;
562
    /* do not try a lazy match if we already have a match with this length */
563
1.33k
    if (max_lazy == 0)
564
0
        max_lazy = 32;
565
    /* stop searching for longer matches than this one */
566
1.33k
    if (nice_length == 0)
567
1.33k
        nice_length = 0;
568
    /* don't search more positions than this */
569
1.33k
    if (max_chain == 0)
570
0
        max_chain = SWD_MAX_CHAIN;
571
572
1.33k
    c->init = 0;
573
1.33k
    c->ip = c->in = in;
574
1.33k
    c->in_end = in + in_len;
575
1.33k
    c->out = out;
576
1.33k
    c->cb = cb;
577
1.33k
    c->m1a_m = c->m1b_m = c->m2_m = c->m3_m = c->m4_m = 0;
578
1.33k
    c->lit1_r = c->lit2_r = c->lit3_r = 0;
579
580
1.33k
    op = out;
581
1.33k
    ii = c->ip;             /* point to start of literal run */
582
1.33k
    lit = 0;
583
1.33k
    c->r1_lit = c->r1_m_len = 0;
584
585
1.33k
    r = init_match(c,swd,dict,dict_len,flags);
586
1.33k
    if (r != 0)
587
0
        return r;
588
1.33k
    if (max_chain > 0)
589
1.33k
        swd->max_chain = max_chain;
590
1.33k
    if (nice_length > 0)
591
0
        swd->nice_length = nice_length;
592
593
1.33k
    r = find_match(c,swd,0,0);
594
1.33k
    if (r != 0)
595
0
        return r;
596
10.3M
    while (c->look > 0)
597
10.3M
    {
598
10.3M
        lzo_uint ahead;
599
10.3M
        lzo_uint max_ahead;
600
10.3M
        lzo_uint l1, l2, l3;
601
602
10.3M
        c->codesize = pd(op, out);
603
604
10.3M
        m_len = c->m_len;
605
10.3M
        m_off = c->m_off;
606
607
10.3M
        assert(c->bp == c->ip - c->look);
608
10.3M
        assert(c->bp >= in);
609
10.3M
        if (lit == 0)
610
862k
            ii = c->bp;
611
10.3M
        assert(ii + lit == c->bp);
612
10.3M
        assert(swd->b_char == *(c->bp));
613
614
10.3M
        if ( m_len < 2 ||
615
4.97M
            (m_len == 2 && (m_off > M1_MAX_OFFSET || lit == 0 || lit >= 4)) ||
616
1.10M
#if 1
617
            /* Do not accept this match for compressed-data compatibility
618
             * with LZO v1.01 and before
619
             * [ might be a problem for decompress() and optimize() ]
620
             */
621
1.10M
            (m_len == 2 && op == out) ||
622
1.10M
#endif
623
1.10M
            (op == out && lit == 0))
624
9.27M
        {
625
            /* a literal */
626
9.27M
            m_len = 0;
627
9.27M
        }
628
1.10M
        else if (m_len == M2_MIN_LEN)
629
222k
        {
630
            /* compression ratio improves if we code a literal in some cases */
631
222k
            if (m_off > MX_MAX_OFFSET && lit >= 4)
632
33.1k
                m_len = 0;
633
222k
        }
634
635
10.3M
        if (m_len == 0)
636
9.30M
        {
637
    /* a literal */
638
9.30M
            lit++;
639
9.30M
            swd->max_chain = max_chain;
640
9.30M
            r = find_match(c,swd,1,0);
641
9.30M
            assert(r == 0); LZO_UNUSED(r);
642
9.30M
            continue;
643
9.30M
        }
644
645
    /* a match */
646
1.07M
#if defined(SWD_BEST_OFF)
647
1.07M
        if (swd->use_best_off)
648
1.07M
            better_match(swd,&m_len,&m_off);
649
1.07M
#endif
650
1.07M
        assert_match(swd,m_len,m_off);
651
652
653
        /* shall we try a lazy match ? */
654
1.07M
        ahead = 0;
655
1.07M
        if (try_lazy == 0 || m_len >= max_lazy)
656
16.7k
        {
657
            /* no */
658
16.7k
            l1 = 0;
659
16.7k
            max_ahead = 0;
660
16.7k
        }
661
1.05M
        else
662
1.05M
        {
663
            /* yes, try a lazy match */
664
1.05M
            l1 = len_of_coded_match(m_len,m_off,lit);
665
1.05M
            assert(l1 > 0);
666
1.05M
#if 1
667
1.05M
            max_ahead = LZO_MIN(try_lazy, l1 - 1);
668
#else
669
            max_ahead = LZO_MIN3(try_lazy, l1, m_len - 1);
670
#endif
671
1.05M
        }
672
673
674
2.24M
        while (ahead < max_ahead && c->look > m_len)
675
1.38M
        {
676
1.38M
            lzo_uint lazy_match_min_gain;
677
678
1.38M
            if (m_len >= good_length)
679
64.6k
                swd->max_chain = max_chain >> 2;
680
1.31M
            else
681
1.31M
                swd->max_chain = max_chain;
682
1.38M
            r = find_match(c,swd,1,0);
683
1.38M
            ahead++;
684
685
1.38M
            assert(r == 0); LZO_UNUSED(r);
686
1.38M
            assert(c->look > 0);
687
1.38M
            assert(ii + lit + ahead == c->bp);
688
689
#if defined(LZO1Z)
690
            if (m_off == c->last_m_off && c->m_off != c->last_m_off)
691
                if (m_len >= M2_MIN_LEN && m_len <= M2_MAX_LEN)
692
                    c->m_len = 0;
693
#endif
694
1.38M
            if (c->m_len < m_len)
695
840k
                continue;
696
540k
#if 1
697
540k
            if (c->m_len == m_len && c->m_off >= m_off)
698
102k
                continue;
699
438k
#endif
700
438k
#if defined(SWD_BEST_OFF)
701
438k
            if (swd->use_best_off)
702
438k
                better_match(swd,&c->m_len,&c->m_off);
703
438k
#endif
704
438k
            l2 = len_of_coded_match(c->m_len,c->m_off,lit+ahead);
705
438k
            if (l2 == 0)
706
1.82k
                continue;
707
#if 0
708
            if (c->m_len == m_len && l2 >= l1)
709
                continue;
710
#endif
711
712
713
436k
#if 1
714
            /* compressed-data compatibility [see above] */
715
436k
            l3 = (op == out) ? 0 : len_of_coded_match(ahead,m_off,lit);
716
#else
717
            l3 = len_of_coded_match(ahead,m_off,lit);
718
#endif
719
720
436k
            lazy_match_min_gain = min_gain(ahead,lit,lit+ahead,l1,l2,l3);
721
436k
            if (c->m_len >= m_len + lazy_match_min_gain)
722
216k
            {
723
216k
                c->lazy++;
724
216k
                assert_match(swd,c->m_len,c->m_off);
725
726
216k
                if (l3)
727
1.61k
                {
728
                    /* code previous run */
729
1.61k
                    op = code_run(c,op,ii,lit,ahead);
730
1.61k
                    lit = 0;
731
                    /* code shortened match */
732
1.61k
                    op = code_match(c,op,ahead,m_off);
733
1.61k
                }
734
214k
                else
735
214k
                {
736
214k
                    lit += ahead;
737
214k
                    assert(ii + lit == c->bp);
738
214k
                }
739
216k
                goto lazy_match_done;
740
216k
            }
741
436k
        }
742
743
744
1.07M
        assert(ii + lit + ahead == c->bp);
745
746
        /* 1 - code run */
747
859k
        op = code_run(c,op,ii,lit,m_len);
748
859k
        lit = 0;
749
750
        /* 2 - code match */
751
859k
        op = code_match(c,op,m_len,m_off);
752
859k
        swd->max_chain = max_chain;
753
859k
        r = find_match(c,swd,m_len,1+ahead);
754
859k
        assert(r == 0); LZO_UNUSED(r);
755
756
1.07M
lazy_match_done: ;
757
1.07M
    }
758
759
760
    /* store final run */
761
1.33k
    if (lit > 0)
762
794
        op = STORE_RUN(c,op,ii,lit);
763
764
1.33k
#if defined(LZO_EOF_CODE)
765
1.33k
    *op++ = M4_MARKER | 1;
766
1.33k
    *op++ = 0;
767
1.33k
    *op++ = 0;
768
1.33k
#endif
769
770
1.33k
    c->codesize = pd(op, out);
771
1.33k
    assert(c->textsize == in_len);
772
773
1.33k
    *out_len = pd(op, out);
774
775
1.33k
    if (c->cb && c->cb->nprogress)
776
0
        (*c->cb->nprogress)(c->cb, c->textsize, c->codesize, 0);
777
778
#if 0
779
    printf("%ld %ld -> %ld  %ld: %ld %ld %ld %ld %ld  %ld: %ld %ld %ld  %ld\n",
780
        (long) c->textsize, (long) in_len, (long) c->codesize,
781
        c->match_bytes, c->m1a_m, c->m1b_m, c->m2_m, c->m3_m, c->m4_m,
782
        c->lit_bytes, c->lit1_r, c->lit2_r, c->lit3_r, c->lazy);
783
#endif
784
1.33k
    assert(c->lit_bytes + c->match_bytes == in_len);
785
786
1.33k
    return LZO_E_OK;
787
1.33k
}
lzo1y_999_compress_internal
Line
Count
Source
532
1.34k
{
533
1.34k
    lzo_bytep op;
534
1.34k
    const lzo_bytep ii;
535
1.34k
    lzo_uint lit;
536
1.34k
    lzo_uint m_len, m_off;
537
1.34k
    LZO_COMPRESS_T cc;
538
1.34k
    LZO_COMPRESS_T * const c = &cc;
539
1.34k
    lzo_swd_p const swd = (lzo_swd_p) wrkmem;
540
1.34k
    lzo_uint try_lazy;
541
1.34k
    int r;
542
543
    /* sanity check */
544
#if defined(LZO1X)
545
    LZO_COMPILE_TIME_ASSERT(LZO1X_999_MEM_COMPRESS >= SIZEOF_LZO_SWD_T)
546
#elif defined(LZO1Y)
547
1.34k
    LZO_COMPILE_TIME_ASSERT(LZO1Y_999_MEM_COMPRESS >= SIZEOF_LZO_SWD_T)
548
#elif defined(LZO1Z)
549
    LZO_COMPILE_TIME_ASSERT(LZO1Z_999_MEM_COMPRESS >= SIZEOF_LZO_SWD_T)
550
#else
551
#  error
552
#endif
553
554
/* setup parameter defaults */
555
    /* number of lazy match tries */
556
1.34k
    try_lazy = (lzo_uint) try_lazy_parm;
557
1.34k
    if (try_lazy_parm < 0)
558
0
        try_lazy = 1;
559
    /* reduce lazy match search if we already have a match with this length */
560
1.34k
    if (good_length == 0)
561
0
        good_length = 32;
562
    /* do not try a lazy match if we already have a match with this length */
563
1.34k
    if (max_lazy == 0)
564
0
        max_lazy = 32;
565
    /* stop searching for longer matches than this one */
566
1.34k
    if (nice_length == 0)
567
1.34k
        nice_length = 0;
568
    /* don't search more positions than this */
569
1.34k
    if (max_chain == 0)
570
0
        max_chain = SWD_MAX_CHAIN;
571
572
1.34k
    c->init = 0;
573
1.34k
    c->ip = c->in = in;
574
1.34k
    c->in_end = in + in_len;
575
1.34k
    c->out = out;
576
1.34k
    c->cb = cb;
577
1.34k
    c->m1a_m = c->m1b_m = c->m2_m = c->m3_m = c->m4_m = 0;
578
1.34k
    c->lit1_r = c->lit2_r = c->lit3_r = 0;
579
580
1.34k
    op = out;
581
1.34k
    ii = c->ip;             /* point to start of literal run */
582
1.34k
    lit = 0;
583
1.34k
    c->r1_lit = c->r1_m_len = 0;
584
585
1.34k
    r = init_match(c,swd,dict,dict_len,flags);
586
1.34k
    if (r != 0)
587
0
        return r;
588
1.34k
    if (max_chain > 0)
589
1.34k
        swd->max_chain = max_chain;
590
1.34k
    if (nice_length > 0)
591
0
        swd->nice_length = nice_length;
592
593
1.34k
    r = find_match(c,swd,0,0);
594
1.34k
    if (r != 0)
595
0
        return r;
596
19.9M
    while (c->look > 0)
597
19.9M
    {
598
19.9M
        lzo_uint ahead;
599
19.9M
        lzo_uint max_ahead;
600
19.9M
        lzo_uint l1, l2, l3;
601
602
19.9M
        c->codesize = pd(op, out);
603
604
19.9M
        m_len = c->m_len;
605
19.9M
        m_off = c->m_off;
606
607
19.9M
        assert(c->bp == c->ip - c->look);
608
19.9M
        assert(c->bp >= in);
609
19.9M
        if (lit == 0)
610
719k
            ii = c->bp;
611
19.9M
        assert(ii + lit == c->bp);
612
19.9M
        assert(swd->b_char == *(c->bp));
613
614
19.9M
        if ( m_len < 2 ||
615
10.1M
            (m_len == 2 && (m_off > M1_MAX_OFFSET || lit == 0 || lit >= 4)) ||
616
1.03M
#if 1
617
            /* Do not accept this match for compressed-data compatibility
618
             * with LZO v1.01 and before
619
             * [ might be a problem for decompress() and optimize() ]
620
             */
621
1.03M
            (m_len == 2 && op == out) ||
622
1.03M
#endif
623
1.03M
            (op == out && lit == 0))
624
18.8M
        {
625
            /* a literal */
626
18.8M
            m_len = 0;
627
18.8M
        }
628
1.03M
        else if (m_len == M2_MIN_LEN)
629
301k
        {
630
            /* compression ratio improves if we code a literal in some cases */
631
301k
            if (m_off > MX_MAX_OFFSET && lit >= 4)
632
128k
                m_len = 0;
633
301k
        }
634
635
19.9M
        if (m_len == 0)
636
19.0M
        {
637
    /* a literal */
638
19.0M
            lit++;
639
19.0M
            swd->max_chain = max_chain;
640
19.0M
            r = find_match(c,swd,1,0);
641
19.0M
            assert(r == 0); LZO_UNUSED(r);
642
19.0M
            continue;
643
19.0M
        }
644
645
    /* a match */
646
903k
#if defined(SWD_BEST_OFF)
647
903k
        if (swd->use_best_off)
648
903k
            better_match(swd,&m_len,&m_off);
649
903k
#endif
650
903k
        assert_match(swd,m_len,m_off);
651
652
653
        /* shall we try a lazy match ? */
654
903k
        ahead = 0;
655
903k
        if (try_lazy == 0 || m_len >= max_lazy)
656
17.1k
        {
657
            /* no */
658
17.1k
            l1 = 0;
659
17.1k
            max_ahead = 0;
660
17.1k
        }
661
886k
        else
662
886k
        {
663
            /* yes, try a lazy match */
664
886k
            l1 = len_of_coded_match(m_len,m_off,lit);
665
886k
            assert(l1 > 0);
666
886k
#if 1
667
886k
            max_ahead = LZO_MIN(try_lazy, l1 - 1);
668
#else
669
            max_ahead = LZO_MIN3(try_lazy, l1, m_len - 1);
670
#endif
671
886k
        }
672
673
674
1.88M
        while (ahead < max_ahead && c->look > m_len)
675
1.16M
        {
676
1.16M
            lzo_uint lazy_match_min_gain;
677
678
1.16M
            if (m_len >= good_length)
679
72.0k
                swd->max_chain = max_chain >> 2;
680
1.09M
            else
681
1.09M
                swd->max_chain = max_chain;
682
1.16M
            r = find_match(c,swd,1,0);
683
1.16M
            ahead++;
684
685
1.16M
            assert(r == 0); LZO_UNUSED(r);
686
1.16M
            assert(c->look > 0);
687
1.16M
            assert(ii + lit + ahead == c->bp);
688
689
#if defined(LZO1Z)
690
            if (m_off == c->last_m_off && c->m_off != c->last_m_off)
691
                if (m_len >= M2_MIN_LEN && m_len <= M2_MAX_LEN)
692
                    c->m_len = 0;
693
#endif
694
1.16M
            if (c->m_len < m_len)
695
743k
                continue;
696
419k
#if 1
697
419k
            if (c->m_len == m_len && c->m_off >= m_off)
698
98.9k
                continue;
699
320k
#endif
700
320k
#if defined(SWD_BEST_OFF)
701
320k
            if (swd->use_best_off)
702
320k
                better_match(swd,&c->m_len,&c->m_off);
703
320k
#endif
704
320k
            l2 = len_of_coded_match(c->m_len,c->m_off,lit+ahead);
705
320k
            if (l2 == 0)
706
1.43k
                continue;
707
#if 0
708
            if (c->m_len == m_len && l2 >= l1)
709
                continue;
710
#endif
711
712
713
319k
#if 1
714
            /* compressed-data compatibility [see above] */
715
319k
            l3 = (op == out) ? 0 : len_of_coded_match(ahead,m_off,lit);
716
#else
717
            l3 = len_of_coded_match(ahead,m_off,lit);
718
#endif
719
720
319k
            lazy_match_min_gain = min_gain(ahead,lit,lit+ahead,l1,l2,l3);
721
319k
            if (c->m_len >= m_len + lazy_match_min_gain)
722
185k
            {
723
185k
                c->lazy++;
724
185k
                assert_match(swd,c->m_len,c->m_off);
725
726
185k
                if (l3)
727
857
                {
728
                    /* code previous run */
729
857
                    op = code_run(c,op,ii,lit,ahead);
730
857
                    lit = 0;
731
                    /* code shortened match */
732
857
                    op = code_match(c,op,ahead,m_off);
733
857
                }
734
184k
                else
735
184k
                {
736
184k
                    lit += ahead;
737
184k
                    assert(ii + lit == c->bp);
738
184k
                }
739
185k
                goto lazy_match_done;
740
185k
            }
741
319k
        }
742
743
744
903k
        assert(ii + lit + ahead == c->bp);
745
746
        /* 1 - code run */
747
718k
        op = code_run(c,op,ii,lit,m_len);
748
718k
        lit = 0;
749
750
        /* 2 - code match */
751
718k
        op = code_match(c,op,m_len,m_off);
752
718k
        swd->max_chain = max_chain;
753
718k
        r = find_match(c,swd,m_len,1+ahead);
754
718k
        assert(r == 0); LZO_UNUSED(r);
755
756
903k
lazy_match_done: ;
757
903k
    }
758
759
760
    /* store final run */
761
1.34k
    if (lit > 0)
762
817
        op = STORE_RUN(c,op,ii,lit);
763
764
1.34k
#if defined(LZO_EOF_CODE)
765
1.34k
    *op++ = M4_MARKER | 1;
766
1.34k
    *op++ = 0;
767
1.34k
    *op++ = 0;
768
1.34k
#endif
769
770
1.34k
    c->codesize = pd(op, out);
771
1.34k
    assert(c->textsize == in_len);
772
773
1.34k
    *out_len = pd(op, out);
774
775
1.34k
    if (c->cb && c->cb->nprogress)
776
0
        (*c->cb->nprogress)(c->cb, c->textsize, c->codesize, 0);
777
778
#if 0
779
    printf("%ld %ld -> %ld  %ld: %ld %ld %ld %ld %ld  %ld: %ld %ld %ld  %ld\n",
780
        (long) c->textsize, (long) in_len, (long) c->codesize,
781
        c->match_bytes, c->m1a_m, c->m1b_m, c->m2_m, c->m3_m, c->m4_m,
782
        c->lit_bytes, c->lit1_r, c->lit2_r, c->lit3_r, c->lazy);
783
#endif
784
1.34k
    assert(c->lit_bytes + c->match_bytes == in_len);
785
786
1.34k
    return LZO_E_OK;
787
1.34k
}
lzo1z_999_compress_internal
Line
Count
Source
532
1.64k
{
533
1.64k
    lzo_bytep op;
534
1.64k
    const lzo_bytep ii;
535
1.64k
    lzo_uint lit;
536
1.64k
    lzo_uint m_len, m_off;
537
1.64k
    LZO_COMPRESS_T cc;
538
1.64k
    LZO_COMPRESS_T * const c = &cc;
539
1.64k
    lzo_swd_p const swd = (lzo_swd_p) wrkmem;
540
1.64k
    lzo_uint try_lazy;
541
1.64k
    int r;
542
543
    /* sanity check */
544
#if defined(LZO1X)
545
    LZO_COMPILE_TIME_ASSERT(LZO1X_999_MEM_COMPRESS >= SIZEOF_LZO_SWD_T)
546
#elif defined(LZO1Y)
547
    LZO_COMPILE_TIME_ASSERT(LZO1Y_999_MEM_COMPRESS >= SIZEOF_LZO_SWD_T)
548
#elif defined(LZO1Z)
549
1.64k
    LZO_COMPILE_TIME_ASSERT(LZO1Z_999_MEM_COMPRESS >= SIZEOF_LZO_SWD_T)
550
#else
551
#  error
552
#endif
553
554
/* setup parameter defaults */
555
    /* number of lazy match tries */
556
1.64k
    try_lazy = (lzo_uint) try_lazy_parm;
557
1.64k
    if (try_lazy_parm < 0)
558
0
        try_lazy = 1;
559
    /* reduce lazy match search if we already have a match with this length */
560
1.64k
    if (good_length == 0)
561
0
        good_length = 32;
562
    /* do not try a lazy match if we already have a match with this length */
563
1.64k
    if (max_lazy == 0)
564
0
        max_lazy = 32;
565
    /* stop searching for longer matches than this one */
566
1.64k
    if (nice_length == 0)
567
1.64k
        nice_length = 0;
568
    /* don't search more positions than this */
569
1.64k
    if (max_chain == 0)
570
0
        max_chain = SWD_MAX_CHAIN;
571
572
1.64k
    c->init = 0;
573
1.64k
    c->ip = c->in = in;
574
1.64k
    c->in_end = in + in_len;
575
1.64k
    c->out = out;
576
1.64k
    c->cb = cb;
577
1.64k
    c->m1a_m = c->m1b_m = c->m2_m = c->m3_m = c->m4_m = 0;
578
1.64k
    c->lit1_r = c->lit2_r = c->lit3_r = 0;
579
580
1.64k
    op = out;
581
1.64k
    ii = c->ip;             /* point to start of literal run */
582
1.64k
    lit = 0;
583
1.64k
    c->r1_lit = c->r1_m_len = 0;
584
585
1.64k
    r = init_match(c,swd,dict,dict_len,flags);
586
1.64k
    if (r != 0)
587
0
        return r;
588
1.64k
    if (max_chain > 0)
589
1.64k
        swd->max_chain = max_chain;
590
1.64k
    if (nice_length > 0)
591
0
        swd->nice_length = nice_length;
592
593
1.64k
    r = find_match(c,swd,0,0);
594
1.64k
    if (r != 0)
595
0
        return r;
596
12.2M
    while (c->look > 0)
597
12.2M
    {
598
12.2M
        lzo_uint ahead;
599
12.2M
        lzo_uint max_ahead;
600
12.2M
        lzo_uint l1, l2, l3;
601
602
12.2M
        c->codesize = pd(op, out);
603
604
12.2M
        m_len = c->m_len;
605
12.2M
        m_off = c->m_off;
606
607
12.2M
        assert(c->bp == c->ip - c->look);
608
12.2M
        assert(c->bp >= in);
609
12.2M
        if (lit == 0)
610
1.00M
            ii = c->bp;
611
12.2M
        assert(ii + lit == c->bp);
612
12.2M
        assert(swd->b_char == *(c->bp));
613
614
12.2M
        if ( m_len < 2 ||
615
6.01M
            (m_len == 2 && (m_off > M1_MAX_OFFSET || lit == 0 || lit >= 4)) ||
616
1.29M
#if 1
617
            /* Do not accept this match for compressed-data compatibility
618
             * with LZO v1.01 and before
619
             * [ might be a problem for decompress() and optimize() ]
620
             */
621
1.29M
            (m_len == 2 && op == out) ||
622
1.29M
#endif
623
1.29M
            (op == out && lit == 0))
624
10.9M
        {
625
            /* a literal */
626
10.9M
            m_len = 0;
627
10.9M
        }
628
1.29M
        else if (m_len == M2_MIN_LEN)
629
332k
        {
630
            /* compression ratio improves if we code a literal in some cases */
631
332k
            if (m_off > MX_MAX_OFFSET && lit >= 4)
632
44.2k
                m_len = 0;
633
332k
        }
634
635
12.2M
        if (m_len == 0)
636
10.9M
        {
637
    /* a literal */
638
10.9M
            lit++;
639
10.9M
            swd->max_chain = max_chain;
640
10.9M
            r = find_match(c,swd,1,0);
641
10.9M
            assert(r == 0); LZO_UNUSED(r);
642
10.9M
            continue;
643
10.9M
        }
644
645
    /* a match */
646
1.24M
#if defined(SWD_BEST_OFF)
647
1.24M
        if (swd->use_best_off)
648
1.24M
            better_match(swd,&m_len,&m_off);
649
1.24M
#endif
650
1.24M
        assert_match(swd,m_len,m_off);
651
652
653
        /* shall we try a lazy match ? */
654
1.24M
        ahead = 0;
655
1.24M
        if (try_lazy == 0 || m_len >= max_lazy)
656
20.1k
        {
657
            /* no */
658
20.1k
            l1 = 0;
659
20.1k
            max_ahead = 0;
660
20.1k
        }
661
1.22M
        else
662
1.22M
        {
663
            /* yes, try a lazy match */
664
1.22M
            l1 = len_of_coded_match(m_len,m_off,lit);
665
1.22M
            assert(l1 > 0);
666
1.22M
#if 1
667
1.22M
            max_ahead = LZO_MIN(try_lazy, l1 - 1);
668
#else
669
            max_ahead = LZO_MIN3(try_lazy, l1, m_len - 1);
670
#endif
671
1.22M
        }
672
673
674
2.68M
        while (ahead < max_ahead && c->look > m_len)
675
1.67M
        {
676
1.67M
            lzo_uint lazy_match_min_gain;
677
678
1.67M
            if (m_len >= good_length)
679
78.8k
                swd->max_chain = max_chain >> 2;
680
1.59M
            else
681
1.59M
                swd->max_chain = max_chain;
682
1.67M
            r = find_match(c,swd,1,0);
683
1.67M
            ahead++;
684
685
1.67M
            assert(r == 0); LZO_UNUSED(r);
686
1.67M
            assert(c->look > 0);
687
1.67M
            assert(ii + lit + ahead == c->bp);
688
689
1.67M
#if defined(LZO1Z)
690
1.67M
            if (m_off == c->last_m_off && c->m_off != c->last_m_off)
691
148k
                if (m_len >= M2_MIN_LEN && m_len <= M2_MAX_LEN)
692
9.96k
                    c->m_len = 0;
693
1.67M
#endif
694
1.67M
            if (c->m_len < m_len)
695
1.05M
                continue;
696
628k
#if 1
697
628k
            if (c->m_len == m_len && c->m_off >= m_off)
698
141k
                continue;
699
486k
#endif
700
486k
#if defined(SWD_BEST_OFF)
701
486k
            if (swd->use_best_off)
702
486k
                better_match(swd,&c->m_len,&c->m_off);
703
486k
#endif
704
486k
            l2 = len_of_coded_match(c->m_len,c->m_off,lit+ahead);
705
486k
            if (l2 == 0)
706
1.49k
                continue;
707
#if 0
708
            if (c->m_len == m_len && l2 >= l1)
709
                continue;
710
#endif
711
712
713
485k
#if 1
714
            /* compressed-data compatibility [see above] */
715
485k
            l3 = (op == out) ? 0 : len_of_coded_match(ahead,m_off,lit);
716
#else
717
            l3 = len_of_coded_match(ahead,m_off,lit);
718
#endif
719
720
485k
            lazy_match_min_gain = min_gain(ahead,lit,lit+ahead,l1,l2,l3);
721
485k
            if (c->m_len >= m_len + lazy_match_min_gain)
722
244k
            {
723
244k
                c->lazy++;
724
244k
                assert_match(swd,c->m_len,c->m_off);
725
726
244k
                if (l3)
727
1.72k
                {
728
                    /* code previous run */
729
1.72k
                    op = code_run(c,op,ii,lit,ahead);
730
1.72k
                    lit = 0;
731
                    /* code shortened match */
732
1.72k
                    op = code_match(c,op,ahead,m_off);
733
1.72k
                }
734
242k
                else
735
242k
                {
736
242k
                    lit += ahead;
737
242k
                    assert(ii + lit == c->bp);
738
242k
                }
739
244k
                goto lazy_match_done;
740
244k
            }
741
485k
        }
742
743
744
1.24M
        assert(ii + lit + ahead == c->bp);
745
746
        /* 1 - code run */
747
1.00M
        op = code_run(c,op,ii,lit,m_len);
748
1.00M
        lit = 0;
749
750
        /* 2 - code match */
751
1.00M
        op = code_match(c,op,m_len,m_off);
752
1.00M
        swd->max_chain = max_chain;
753
1.00M
        r = find_match(c,swd,m_len,1+ahead);
754
1.00M
        assert(r == 0); LZO_UNUSED(r);
755
756
1.24M
lazy_match_done: ;
757
1.24M
    }
758
759
760
    /* store final run */
761
1.64k
    if (lit > 0)
762
1.03k
        op = STORE_RUN(c,op,ii,lit);
763
764
1.64k
#if defined(LZO_EOF_CODE)
765
1.64k
    *op++ = M4_MARKER | 1;
766
1.64k
    *op++ = 0;
767
1.64k
    *op++ = 0;
768
1.64k
#endif
769
770
1.64k
    c->codesize = pd(op, out);
771
1.64k
    assert(c->textsize == in_len);
772
773
1.64k
    *out_len = pd(op, out);
774
775
1.64k
    if (c->cb && c->cb->nprogress)
776
0
        (*c->cb->nprogress)(c->cb, c->textsize, c->codesize, 0);
777
778
#if 0
779
    printf("%ld %ld -> %ld  %ld: %ld %ld %ld %ld %ld  %ld: %ld %ld %ld  %ld\n",
780
        (long) c->textsize, (long) in_len, (long) c->codesize,
781
        c->match_bytes, c->m1a_m, c->m1b_m, c->m2_m, c->m3_m, c->m4_m,
782
        c->lit_bytes, c->lit1_r, c->lit2_r, c->lit3_r, c->lazy);
783
#endif
784
1.64k
    assert(c->lit_bytes + c->match_bytes == in_len);
785
786
1.64k
    return LZO_E_OK;
787
1.64k
}
788
789
790
/***********************************************************************
791
//
792
************************************************************************/
793
794
LZO_PUBLIC(int)
795
lzo1x_999_compress_level    ( const lzo_bytep in , lzo_uint  in_len,
796
                                    lzo_bytep out, lzo_uintp out_len,
797
                                    lzo_voidp wrkmem,
798
                              const lzo_bytep dict, lzo_uint dict_len,
799
                                    lzo_callback_p cb,
800
                                    int compression_level )
801
4.32k
{
802
4.32k
    static const struct
803
4.32k
    {
804
4.32k
        int try_lazy_parm;
805
4.32k
        lzo_uint good_length;
806
4.32k
        lzo_uint max_lazy;
807
4.32k
        lzo_uint nice_length;
808
4.32k
        lzo_uint max_chain;
809
4.32k
        lzo_uint32_t flags;
810
4.32k
    } c[9] = {
811
        /* faster compression */
812
4.32k
        {   0,     0,     0,     8,    4,   0 },
813
4.32k
        {   0,     0,     0,    16,    8,   0 },
814
4.32k
        {   0,     0,     0,    32,   16,   0 },
815
4.32k
        {   1,     4,     4,    16,   16,   0 },
816
4.32k
        {   1,     8,    16,    32,   32,   0 },
817
4.32k
        {   1,     8,    16,   128,  128,   0 },
818
4.32k
        {   2,     8,    32,   128,  256,   0 },
819
4.32k
        {   2,    32,   128, SWD_F, 2048,   1 },
820
4.32k
        {   2, SWD_F, SWD_F, SWD_F, 4096,   1 }
821
        /* max. compression */
822
4.32k
    };
823
824
4.32k
    if (compression_level < 1 || compression_level > 9)
825
0
        return LZO_E_ERROR;
826
827
4.32k
    compression_level -= 1;
828
4.32k
    return lzo1x_999_compress_internal(in, in_len, out, out_len, wrkmem,
829
4.32k
                                       dict, dict_len, cb,
830
4.32k
                                       c[compression_level].try_lazy_parm,
831
4.32k
                                       c[compression_level].good_length,
832
4.32k
                                       c[compression_level].max_lazy,
833
#if 0
834
                                       c[compression_level].nice_length,
835
#else
836
4.32k
                                       0,
837
4.32k
#endif
838
4.32k
                                       c[compression_level].max_chain,
839
4.32k
                                       c[compression_level].flags);
840
4.32k
}
lzo1x_999_compress_level
Line
Count
Source
801
1.33k
{
802
1.33k
    static const struct
803
1.33k
    {
804
1.33k
        int try_lazy_parm;
805
1.33k
        lzo_uint good_length;
806
1.33k
        lzo_uint max_lazy;
807
1.33k
        lzo_uint nice_length;
808
1.33k
        lzo_uint max_chain;
809
1.33k
        lzo_uint32_t flags;
810
1.33k
    } c[9] = {
811
        /* faster compression */
812
1.33k
        {   0,     0,     0,     8,    4,   0 },
813
1.33k
        {   0,     0,     0,    16,    8,   0 },
814
1.33k
        {   0,     0,     0,    32,   16,   0 },
815
1.33k
        {   1,     4,     4,    16,   16,   0 },
816
1.33k
        {   1,     8,    16,    32,   32,   0 },
817
1.33k
        {   1,     8,    16,   128,  128,   0 },
818
1.33k
        {   2,     8,    32,   128,  256,   0 },
819
1.33k
        {   2,    32,   128, SWD_F, 2048,   1 },
820
1.33k
        {   2, SWD_F, SWD_F, SWD_F, 4096,   1 }
821
        /* max. compression */
822
1.33k
    };
823
824
1.33k
    if (compression_level < 1 || compression_level > 9)
825
0
        return LZO_E_ERROR;
826
827
1.33k
    compression_level -= 1;
828
1.33k
    return lzo1x_999_compress_internal(in, in_len, out, out_len, wrkmem,
829
1.33k
                                       dict, dict_len, cb,
830
1.33k
                                       c[compression_level].try_lazy_parm,
831
1.33k
                                       c[compression_level].good_length,
832
1.33k
                                       c[compression_level].max_lazy,
833
#if 0
834
                                       c[compression_level].nice_length,
835
#else
836
1.33k
                                       0,
837
1.33k
#endif
838
1.33k
                                       c[compression_level].max_chain,
839
1.33k
                                       c[compression_level].flags);
840
1.33k
}
lzo1y_999_compress_level
Line
Count
Source
801
1.34k
{
802
1.34k
    static const struct
803
1.34k
    {
804
1.34k
        int try_lazy_parm;
805
1.34k
        lzo_uint good_length;
806
1.34k
        lzo_uint max_lazy;
807
1.34k
        lzo_uint nice_length;
808
1.34k
        lzo_uint max_chain;
809
1.34k
        lzo_uint32_t flags;
810
1.34k
    } c[9] = {
811
        /* faster compression */
812
1.34k
        {   0,     0,     0,     8,    4,   0 },
813
1.34k
        {   0,     0,     0,    16,    8,   0 },
814
1.34k
        {   0,     0,     0,    32,   16,   0 },
815
1.34k
        {   1,     4,     4,    16,   16,   0 },
816
1.34k
        {   1,     8,    16,    32,   32,   0 },
817
1.34k
        {   1,     8,    16,   128,  128,   0 },
818
1.34k
        {   2,     8,    32,   128,  256,   0 },
819
1.34k
        {   2,    32,   128, SWD_F, 2048,   1 },
820
1.34k
        {   2, SWD_F, SWD_F, SWD_F, 4096,   1 }
821
        /* max. compression */
822
1.34k
    };
823
824
1.34k
    if (compression_level < 1 || compression_level > 9)
825
0
        return LZO_E_ERROR;
826
827
1.34k
    compression_level -= 1;
828
1.34k
    return lzo1x_999_compress_internal(in, in_len, out, out_len, wrkmem,
829
1.34k
                                       dict, dict_len, cb,
830
1.34k
                                       c[compression_level].try_lazy_parm,
831
1.34k
                                       c[compression_level].good_length,
832
1.34k
                                       c[compression_level].max_lazy,
833
#if 0
834
                                       c[compression_level].nice_length,
835
#else
836
1.34k
                                       0,
837
1.34k
#endif
838
1.34k
                                       c[compression_level].max_chain,
839
1.34k
                                       c[compression_level].flags);
840
1.34k
}
lzo1z_999_compress_level
Line
Count
Source
801
1.64k
{
802
1.64k
    static const struct
803
1.64k
    {
804
1.64k
        int try_lazy_parm;
805
1.64k
        lzo_uint good_length;
806
1.64k
        lzo_uint max_lazy;
807
1.64k
        lzo_uint nice_length;
808
1.64k
        lzo_uint max_chain;
809
1.64k
        lzo_uint32_t flags;
810
1.64k
    } c[9] = {
811
        /* faster compression */
812
1.64k
        {   0,     0,     0,     8,    4,   0 },
813
1.64k
        {   0,     0,     0,    16,    8,   0 },
814
1.64k
        {   0,     0,     0,    32,   16,   0 },
815
1.64k
        {   1,     4,     4,    16,   16,   0 },
816
1.64k
        {   1,     8,    16,    32,   32,   0 },
817
1.64k
        {   1,     8,    16,   128,  128,   0 },
818
1.64k
        {   2,     8,    32,   128,  256,   0 },
819
1.64k
        {   2,    32,   128, SWD_F, 2048,   1 },
820
1.64k
        {   2, SWD_F, SWD_F, SWD_F, 4096,   1 }
821
        /* max. compression */
822
1.64k
    };
823
824
1.64k
    if (compression_level < 1 || compression_level > 9)
825
0
        return LZO_E_ERROR;
826
827
1.64k
    compression_level -= 1;
828
1.64k
    return lzo1x_999_compress_internal(in, in_len, out, out_len, wrkmem,
829
1.64k
                                       dict, dict_len, cb,
830
1.64k
                                       c[compression_level].try_lazy_parm,
831
1.64k
                                       c[compression_level].good_length,
832
1.64k
                                       c[compression_level].max_lazy,
833
#if 0
834
                                       c[compression_level].nice_length,
835
#else
836
1.64k
                                       0,
837
1.64k
#endif
838
1.64k
                                       c[compression_level].max_chain,
839
1.64k
                                       c[compression_level].flags);
840
1.64k
}
841
842
843
/***********************************************************************
844
//
845
************************************************************************/
846
847
LZO_PUBLIC(int)
848
lzo1x_999_compress_dict     ( const lzo_bytep in , lzo_uint  in_len,
849
                                    lzo_bytep out, lzo_uintp out_len,
850
                                    lzo_voidp wrkmem,
851
                              const lzo_bytep dict, lzo_uint dict_len )
852
0
{
853
0
    return lzo1x_999_compress_level(in, in_len, out, out_len, wrkmem,
854
0
                                    dict, dict_len, 0, 8);
855
0
}
Unexecuted instantiation: lzo1x_999_compress_dict
Unexecuted instantiation: lzo1y_999_compress_dict
Unexecuted instantiation: lzo1z_999_compress_dict
856
857
LZO_PUBLIC(int)
858
lzo1x_999_compress  ( const lzo_bytep in , lzo_uint  in_len,
859
                            lzo_bytep out, lzo_uintp out_len,
860
                            lzo_voidp wrkmem )
861
4.32k
{
862
4.32k
    return lzo1x_999_compress_level(in, in_len, out, out_len, wrkmem,
863
                                    NULL, 0, (lzo_callback_p) 0, 8);
864
4.32k
}
lzo1x_999_compress
Line
Count
Source
861
1.33k
{
862
1.33k
    return lzo1x_999_compress_level(in, in_len, out, out_len, wrkmem,
863
                                    NULL, 0, (lzo_callback_p) 0, 8);
864
1.33k
}
lzo1y_999_compress
Line
Count
Source
861
1.34k
{
862
1.34k
    return lzo1x_999_compress_level(in, in_len, out, out_len, wrkmem,
863
                                    NULL, 0, (lzo_callback_p) 0, 8);
864
1.34k
}
lzo1z_999_compress
Line
Count
Source
861
1.64k
{
862
1.64k
    return lzo1x_999_compress_level(in, in_len, out, out_len, wrkmem,
863
                                    NULL, 0, (lzo_callback_p) 0, 8);
864
1.64k
}
865
866
867
/* vim:set ts=4 sw=4 et: */