Coverage Report

Created: 2025-10-10 06:56

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/lzo-2.10/src/lzo1x_c.ch
Line
Count
Source
1
/* lzo1x_c.ch -- implementation of the LZO1[XY]-1 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
30
#if 1 && defined(DO_COMPRESS) && !defined(do_compress)
31
   /* choose a unique name to better help PGO optimizations */
32
3.69k
#  define do_compress       LZO_PP_ECONCAT2(DO_COMPRESS,_core)
33
#endif
34
35
36
/***********************************************************************
37
// compress a block of data.
38
************************************************************************/
39
40
static __lzo_noinline lzo_uint
41
do_compress ( const lzo_bytep in , lzo_uint  in_len,
42
                    lzo_bytep out, lzo_uintp out_len,
43
                    lzo_uint  ti,  lzo_voidp wrkmem)
44
3.69k
{
45
3.69k
    const lzo_bytep ip;
46
3.69k
    lzo_bytep op;
47
3.69k
    const lzo_bytep const in_end = in + in_len;
48
3.69k
    const lzo_bytep const ip_end = in + in_len - 20;
49
3.69k
    const lzo_bytep ii;
50
3.69k
    lzo_dict_p const dict = (lzo_dict_p) wrkmem;
51
52
3.69k
    op = out;
53
3.69k
    ip = in;
54
3.69k
    ii = ip;
55
56
3.69k
    ip += ti < 4 ? 4 - ti : 0;
57
3.69k
    for (;;)
58
3.69k
    {
59
3.69k
        const lzo_bytep m_pos;
60
#if !(LZO_DETERMINISTIC)
61
        LZO_DEFINE_UNINITIALIZED_VAR(lzo_uint, m_off, 0);
62
        lzo_uint m_len;
63
        lzo_uint dindex;
64
next:
65
        if __lzo_unlikely(ip >= ip_end)
66
            break;
67
        DINDEX1(dindex,ip);
68
        GINDEX(m_pos,m_off,dict,dindex,in);
69
        if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET))
70
            goto literal;
71
#if 1
72
        if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
73
            goto try_match;
74
        DINDEX2(dindex,ip);
75
#endif
76
        GINDEX(m_pos,m_off,dict,dindex,in);
77
        if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET))
78
            goto literal;
79
        if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
80
            goto try_match;
81
        goto literal;
82
83
try_match:
84
#if (LZO_OPT_UNALIGNED32)
85
        if (UA_GET_NE32(m_pos) != UA_GET_NE32(ip))
86
#else
87
        if (m_pos[0] != ip[0] || m_pos[1] != ip[1] || m_pos[2] != ip[2] || m_pos[3] != ip[3])
88
#endif
89
        {
90
            /* a literal */
91
literal:
92
            UPDATE_I(dict,0,dindex,ip,in);
93
            ip += 1 + ((ip - ii) >> 5);
94
            continue;
95
        }
96
/*match:*/
97
        UPDATE_I(dict,0,dindex,ip,in);
98
#else
99
3.69k
        lzo_uint m_off;
100
3.69k
        lzo_uint m_len;
101
3.69k
        {
102
3.69k
        lzo_uint32_t dv;
103
3.69k
        lzo_uint dindex;
104
4.12M
literal:
105
4.12M
        ip += 1 + ((ip - ii) >> 5);
106
5.31M
next:
107
5.31M
        if __lzo_unlikely(ip >= ip_end)
108
3.69k
            break;
109
5.31M
        dv = UA_GET_LE32(ip);
110
5.31M
        dindex = DINDEX(dv,ip);
111
5.31M
        GINDEX(m_off,m_pos,in+dict,dindex,in);
112
5.31M
        UPDATE_I(dict,0,dindex,ip,in);
113
5.31M
        if __lzo_unlikely(dv != UA_GET_LE32(m_pos))
114
4.12M
            goto literal;
115
5.31M
        }
116
1.19M
#endif
117
118
    /* a match */
119
120
1.19M
        ii -= ti; ti = 0;
121
1.19M
        {
122
1.19M
        lzo_uint t = pd(ip,ii);
123
1.19M
        if (t != 0)
124
489k
        {
125
489k
            if (t <= 3)
126
271k
            {
127
271k
                op[-2] = LZO_BYTE(op[-2] | t);
128
271k
#if (LZO_OPT_UNALIGNED32)
129
271k
                UA_COPY4(op, ii);
130
271k
                op += t;
131
#else
132
                { do *op++ = *ii++; while (--t > 0); }
133
#endif
134
271k
            }
135
217k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
136
217k
            else if (t <= 16)
137
171k
            {
138
171k
                *op++ = LZO_BYTE(t - 3);
139
171k
                UA_COPY8(op, ii);
140
171k
                UA_COPY8(op+8, ii+8);
141
171k
                op += t;
142
171k
            }
143
46.3k
#endif
144
46.3k
            else
145
46.3k
            {
146
46.3k
                if (t <= 18)
147
5.32k
                    *op++ = LZO_BYTE(t - 3);
148
41.0k
                else
149
41.0k
                {
150
41.0k
                    lzo_uint tt = t - 18;
151
41.0k
                    *op++ = 0;
152
142k
                    while __lzo_unlikely(tt > 255)
153
101k
                    {
154
101k
                        tt -= 255;
155
101k
                        UA_SET1(op, 0);
156
101k
                        op++;
157
101k
                    }
158
41.0k
                    assert(tt > 0);
159
41.0k
                    *op++ = LZO_BYTE(tt);
160
41.0k
                }
161
46.3k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
162
1.79M
                do {
163
1.79M
                    UA_COPY8(op, ii);
164
1.79M
                    UA_COPY8(op+8, ii+8);
165
1.79M
                    op += 16; ii += 16; t -= 16;
166
1.79M
                } while (t >= 16); if (t > 0)
167
43.0k
#endif
168
286k
                { do *op++ = *ii++; while (--t > 0); }
169
46.3k
            }
170
489k
        }
171
1.19M
        }
172
1.19M
        m_len = 4;
173
1.19M
        {
174
1.19M
#if (LZO_OPT_UNALIGNED64)
175
1.19M
        lzo_uint64_t v;
176
1.19M
        v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
177
1.19M
        if __lzo_unlikely(v == 0) {
178
5.07M
            do {
179
5.07M
                m_len += 8;
180
5.07M
                v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
181
5.07M
                if __lzo_unlikely(ip + m_len >= ip_end)
182
1.15k
                    goto m_len_done;
183
5.07M
            } while (v == 0);
184
265k
        }
185
#if (LZO_ABI_BIG_ENDIAN) && defined(lzo_bitops_ctlz64)
186
        m_len += lzo_bitops_ctlz64(v) / CHAR_BIT;
187
#elif (LZO_ABI_BIG_ENDIAN)
188
        if ((v >> (64 - CHAR_BIT)) == 0) do {
189
            v <<= CHAR_BIT;
190
            m_len += 1;
191
        } while ((v >> (64 - CHAR_BIT)) == 0);
192
#elif (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_cttz64)
193
1.19M
        m_len += lzo_bitops_cttz64(v) / CHAR_BIT;
194
#elif (LZO_ABI_LITTLE_ENDIAN)
195
        if ((v & UCHAR_MAX) == 0) do {
196
            v >>= CHAR_BIT;
197
            m_len += 1;
198
        } while ((v & UCHAR_MAX) == 0);
199
#else
200
        if (ip[m_len] == m_pos[m_len]) do {
201
            m_len += 1;
202
        } while (ip[m_len] == m_pos[m_len]);
203
#endif
204
#elif (LZO_OPT_UNALIGNED32)
205
        lzo_uint32_t v;
206
        v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len);
207
        if __lzo_unlikely(v == 0) {
208
            do {
209
                m_len += 4;
210
                v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len);
211
                if (v != 0)
212
                    break;
213
                m_len += 4;
214
                v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len);
215
                if __lzo_unlikely(ip + m_len >= ip_end)
216
                    goto m_len_done;
217
            } while (v == 0);
218
        }
219
#if (LZO_ABI_BIG_ENDIAN) && defined(lzo_bitops_ctlz32)
220
        m_len += lzo_bitops_ctlz32(v) / CHAR_BIT;
221
#elif (LZO_ABI_BIG_ENDIAN)
222
        if ((v >> (32 - CHAR_BIT)) == 0) do {
223
            v <<= CHAR_BIT;
224
            m_len += 1;
225
        } while ((v >> (32 - CHAR_BIT)) == 0);
226
#elif (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_cttz32)
227
        m_len += lzo_bitops_cttz32(v) / CHAR_BIT;
228
#elif (LZO_ABI_LITTLE_ENDIAN)
229
        if ((v & UCHAR_MAX) == 0) do {
230
            v >>= CHAR_BIT;
231
            m_len += 1;
232
        } while ((v & UCHAR_MAX) == 0);
233
#else
234
        if (ip[m_len] == m_pos[m_len]) do {
235
            m_len += 1;
236
        } while (ip[m_len] == m_pos[m_len]);
237
#endif
238
#else
239
        if __lzo_unlikely(ip[m_len] == m_pos[m_len]) {
240
            do {
241
                m_len += 1;
242
                if (ip[m_len] != m_pos[m_len])
243
                    break;
244
                m_len += 1;
245
                if (ip[m_len] != m_pos[m_len])
246
                    break;
247
                m_len += 1;
248
                if (ip[m_len] != m_pos[m_len])
249
                    break;
250
                m_len += 1;
251
                if (ip[m_len] != m_pos[m_len])
252
                    break;
253
                m_len += 1;
254
                if (ip[m_len] != m_pos[m_len])
255
                    break;
256
                m_len += 1;
257
                if (ip[m_len] != m_pos[m_len])
258
                    break;
259
                m_len += 1;
260
                if (ip[m_len] != m_pos[m_len])
261
                    break;
262
                m_len += 1;
263
                if __lzo_unlikely(ip + m_len >= ip_end)
264
                    goto m_len_done;
265
            } while (ip[m_len] == m_pos[m_len]);
266
        }
267
#endif
268
1.19M
        }
269
1.19M
m_len_done:
270
1.19M
        m_off = pd(ip,m_pos);
271
1.19M
        ip += m_len;
272
1.19M
        ii = ip;
273
1.19M
        if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
274
641k
        {
275
641k
            m_off -= 1;
276
#if defined(LZO1X)
277
518k
            *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2));
278
518k
            *op++ = LZO_BYTE(m_off >> 3);
279
#elif defined(LZO1Y)
280
122k
            *op++ = LZO_BYTE(((m_len + 1) << 4) | ((m_off & 3) << 2));
281
122k
            *op++ = LZO_BYTE(m_off >> 2);
282
#endif
283
641k
        }
284
550k
        else if (m_off <= M3_MAX_OFFSET)
285
485k
        {
286
485k
            m_off -= 1;
287
485k
            if (m_len <= M3_MAX_LEN)
288
372k
                *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
289
113k
            else
290
113k
            {
291
113k
                m_len -= M3_MAX_LEN;
292
113k
                *op++ = M3_MARKER | 0;
293
205k
                while __lzo_unlikely(m_len > 255)
294
91.9k
                {
295
91.9k
                    m_len -= 255;
296
91.9k
                    UA_SET1(op, 0);
297
91.9k
                    op++;
298
91.9k
                }
299
113k
                *op++ = LZO_BYTE(m_len);
300
113k
            }
301
485k
            *op++ = LZO_BYTE(m_off << 2);
302
485k
            *op++ = LZO_BYTE(m_off >> 6);
303
485k
        }
304
64.8k
        else
305
64.8k
        {
306
64.8k
            m_off -= 0x4000;
307
64.8k
            if (m_len <= M4_MAX_LEN)
308
41.1k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8) | (m_len - 2));
309
23.6k
            else
310
23.6k
            {
311
23.6k
                m_len -= M4_MAX_LEN;
312
23.6k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8));
313
43.3k
                while __lzo_unlikely(m_len > 255)
314
19.6k
                {
315
19.6k
                    m_len -= 255;
316
19.6k
                    UA_SET1(op, 0);
317
19.6k
                    op++;
318
19.6k
                }
319
23.6k
                *op++ = LZO_BYTE(m_len);
320
23.6k
            }
321
64.8k
            *op++ = LZO_BYTE(m_off << 2);
322
64.8k
            *op++ = LZO_BYTE(m_off >> 6);
323
64.8k
        }
324
1.19M
        goto next;
325
1.19M
    }
326
327
3.69k
    *out_len = pd(op, out);
328
3.69k
    return pd(in_end,ii-ti);
329
3.69k
}
lzo1x_1.c:lzo1x_1_compress_core
Line
Count
Source
44
748
{
45
748
    const lzo_bytep ip;
46
748
    lzo_bytep op;
47
748
    const lzo_bytep const in_end = in + in_len;
48
748
    const lzo_bytep const ip_end = in + in_len - 20;
49
748
    const lzo_bytep ii;
50
748
    lzo_dict_p const dict = (lzo_dict_p) wrkmem;
51
52
748
    op = out;
53
748
    ip = in;
54
748
    ii = ip;
55
56
748
    ip += ti < 4 ? 4 - ti : 0;
57
748
    for (;;)
58
748
    {
59
748
        const lzo_bytep m_pos;
60
#if !(LZO_DETERMINISTIC)
61
        LZO_DEFINE_UNINITIALIZED_VAR(lzo_uint, m_off, 0);
62
        lzo_uint m_len;
63
        lzo_uint dindex;
64
next:
65
        if __lzo_unlikely(ip >= ip_end)
66
            break;
67
        DINDEX1(dindex,ip);
68
        GINDEX(m_pos,m_off,dict,dindex,in);
69
        if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET))
70
            goto literal;
71
#if 1
72
        if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
73
            goto try_match;
74
        DINDEX2(dindex,ip);
75
#endif
76
        GINDEX(m_pos,m_off,dict,dindex,in);
77
        if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET))
78
            goto literal;
79
        if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
80
            goto try_match;
81
        goto literal;
82
83
try_match:
84
#if (LZO_OPT_UNALIGNED32)
85
        if (UA_GET_NE32(m_pos) != UA_GET_NE32(ip))
86
#else
87
        if (m_pos[0] != ip[0] || m_pos[1] != ip[1] || m_pos[2] != ip[2] || m_pos[3] != ip[3])
88
#endif
89
        {
90
            /* a literal */
91
literal:
92
            UPDATE_I(dict,0,dindex,ip,in);
93
            ip += 1 + ((ip - ii) >> 5);
94
            continue;
95
        }
96
/*match:*/
97
        UPDATE_I(dict,0,dindex,ip,in);
98
#else
99
748
        lzo_uint m_off;
100
748
        lzo_uint m_len;
101
748
        {
102
748
        lzo_uint32_t dv;
103
748
        lzo_uint dindex;
104
981k
literal:
105
981k
        ip += 1 + ((ip - ii) >> 5);
106
1.35M
next:
107
1.35M
        if __lzo_unlikely(ip >= ip_end)
108
748
            break;
109
1.35M
        dv = UA_GET_LE32(ip);
110
1.35M
        dindex = DINDEX(dv,ip);
111
1.35M
        GINDEX(m_off,m_pos,in+dict,dindex,in);
112
1.35M
        UPDATE_I(dict,0,dindex,ip,in);
113
1.35M
        if __lzo_unlikely(dv != UA_GET_LE32(m_pos))
114
980k
            goto literal;
115
1.35M
        }
116
371k
#endif
117
118
    /* a match */
119
120
371k
        ii -= ti; ti = 0;
121
371k
        {
122
371k
        lzo_uint t = pd(ip,ii);
123
371k
        if (t != 0)
124
124k
        {
125
124k
            if (t <= 3)
126
68.4k
            {
127
68.4k
                op[-2] = LZO_BYTE(op[-2] | t);
128
68.4k
#if (LZO_OPT_UNALIGNED32)
129
68.4k
                UA_COPY4(op, ii);
130
68.4k
                op += t;
131
#else
132
                { do *op++ = *ii++; while (--t > 0); }
133
#endif
134
68.4k
            }
135
55.6k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
136
55.6k
            else if (t <= 16)
137
45.0k
            {
138
45.0k
                *op++ = LZO_BYTE(t - 3);
139
45.0k
                UA_COPY8(op, ii);
140
45.0k
                UA_COPY8(op+8, ii+8);
141
45.0k
                op += t;
142
45.0k
            }
143
10.5k
#endif
144
10.5k
            else
145
10.5k
            {
146
10.5k
                if (t <= 18)
147
1.10k
                    *op++ = LZO_BYTE(t - 3);
148
9.40k
                else
149
9.40k
                {
150
9.40k
                    lzo_uint tt = t - 18;
151
9.40k
                    *op++ = 0;
152
33.5k
                    while __lzo_unlikely(tt > 255)
153
24.1k
                    {
154
24.1k
                        tt -= 255;
155
24.1k
                        UA_SET1(op, 0);
156
24.1k
                        op++;
157
24.1k
                    }
158
9.40k
                    assert(tt > 0);
159
9.40k
                    *op++ = LZO_BYTE(tt);
160
9.40k
                }
161
10.5k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
162
423k
                do {
163
423k
                    UA_COPY8(op, ii);
164
423k
                    UA_COPY8(op+8, ii+8);
165
423k
                    op += 16; ii += 16; t -= 16;
166
423k
                } while (t >= 16); if (t > 0)
167
9.71k
#endif
168
65.4k
                { do *op++ = *ii++; while (--t > 0); }
169
10.5k
            }
170
124k
        }
171
371k
        }
172
371k
        m_len = 4;
173
371k
        {
174
371k
#if (LZO_OPT_UNALIGNED64)
175
371k
        lzo_uint64_t v;
176
371k
        v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
177
371k
        if __lzo_unlikely(v == 0) {
178
1.10M
            do {
179
1.10M
                m_len += 8;
180
1.10M
                v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
181
1.10M
                if __lzo_unlikely(ip + m_len >= ip_end)
182
247
                    goto m_len_done;
183
1.10M
            } while (v == 0);
184
86.0k
        }
185
#if (LZO_ABI_BIG_ENDIAN) && defined(lzo_bitops_ctlz64)
186
        m_len += lzo_bitops_ctlz64(v) / CHAR_BIT;
187
#elif (LZO_ABI_BIG_ENDIAN)
188
        if ((v >> (64 - CHAR_BIT)) == 0) do {
189
            v <<= CHAR_BIT;
190
            m_len += 1;
191
        } while ((v >> (64 - CHAR_BIT)) == 0);
192
#elif (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_cttz64)
193
371k
        m_len += lzo_bitops_cttz64(v) / CHAR_BIT;
194
#elif (LZO_ABI_LITTLE_ENDIAN)
195
        if ((v & UCHAR_MAX) == 0) do {
196
            v >>= CHAR_BIT;
197
            m_len += 1;
198
        } while ((v & UCHAR_MAX) == 0);
199
#else
200
        if (ip[m_len] == m_pos[m_len]) do {
201
            m_len += 1;
202
        } while (ip[m_len] == m_pos[m_len]);
203
#endif
204
#elif (LZO_OPT_UNALIGNED32)
205
        lzo_uint32_t v;
206
        v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len);
207
        if __lzo_unlikely(v == 0) {
208
            do {
209
                m_len += 4;
210
                v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len);
211
                if (v != 0)
212
                    break;
213
                m_len += 4;
214
                v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len);
215
                if __lzo_unlikely(ip + m_len >= ip_end)
216
                    goto m_len_done;
217
            } while (v == 0);
218
        }
219
#if (LZO_ABI_BIG_ENDIAN) && defined(lzo_bitops_ctlz32)
220
        m_len += lzo_bitops_ctlz32(v) / CHAR_BIT;
221
#elif (LZO_ABI_BIG_ENDIAN)
222
        if ((v >> (32 - CHAR_BIT)) == 0) do {
223
            v <<= CHAR_BIT;
224
            m_len += 1;
225
        } while ((v >> (32 - CHAR_BIT)) == 0);
226
#elif (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_cttz32)
227
        m_len += lzo_bitops_cttz32(v) / CHAR_BIT;
228
#elif (LZO_ABI_LITTLE_ENDIAN)
229
        if ((v & UCHAR_MAX) == 0) do {
230
            v >>= CHAR_BIT;
231
            m_len += 1;
232
        } while ((v & UCHAR_MAX) == 0);
233
#else
234
        if (ip[m_len] == m_pos[m_len]) do {
235
            m_len += 1;
236
        } while (ip[m_len] == m_pos[m_len]);
237
#endif
238
#else
239
        if __lzo_unlikely(ip[m_len] == m_pos[m_len]) {
240
            do {
241
                m_len += 1;
242
                if (ip[m_len] != m_pos[m_len])
243
                    break;
244
                m_len += 1;
245
                if (ip[m_len] != m_pos[m_len])
246
                    break;
247
                m_len += 1;
248
                if (ip[m_len] != m_pos[m_len])
249
                    break;
250
                m_len += 1;
251
                if (ip[m_len] != m_pos[m_len])
252
                    break;
253
                m_len += 1;
254
                if (ip[m_len] != m_pos[m_len])
255
                    break;
256
                m_len += 1;
257
                if (ip[m_len] != m_pos[m_len])
258
                    break;
259
                m_len += 1;
260
                if (ip[m_len] != m_pos[m_len])
261
                    break;
262
                m_len += 1;
263
                if __lzo_unlikely(ip + m_len >= ip_end)
264
                    goto m_len_done;
265
            } while (ip[m_len] == m_pos[m_len]);
266
        }
267
#endif
268
371k
        }
269
371k
m_len_done:
270
371k
        m_off = pd(ip,m_pos);
271
371k
        ip += m_len;
272
371k
        ii = ip;
273
371k
        if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
274
178k
        {
275
178k
            m_off -= 1;
276
178k
#if defined(LZO1X)
277
178k
            *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2));
278
178k
            *op++ = LZO_BYTE(m_off >> 3);
279
#elif defined(LZO1Y)
280
            *op++ = LZO_BYTE(((m_len + 1) << 4) | ((m_off & 3) << 2));
281
            *op++ = LZO_BYTE(m_off >> 2);
282
#endif
283
178k
        }
284
193k
        else if (m_off <= M3_MAX_OFFSET)
285
172k
        {
286
172k
            m_off -= 1;
287
172k
            if (m_len <= M3_MAX_LEN)
288
131k
                *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
289
40.7k
            else
290
40.7k
            {
291
40.7k
                m_len -= M3_MAX_LEN;
292
40.7k
                *op++ = M3_MARKER | 0;
293
57.0k
                while __lzo_unlikely(m_len > 255)
294
16.3k
                {
295
16.3k
                    m_len -= 255;
296
16.3k
                    UA_SET1(op, 0);
297
16.3k
                    op++;
298
16.3k
                }
299
40.7k
                *op++ = LZO_BYTE(m_len);
300
40.7k
            }
301
172k
            *op++ = LZO_BYTE(m_off << 2);
302
172k
            *op++ = LZO_BYTE(m_off >> 6);
303
172k
        }
304
20.4k
        else
305
20.4k
        {
306
20.4k
            m_off -= 0x4000;
307
20.4k
            if (m_len <= M4_MAX_LEN)
308
13.7k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8) | (m_len - 2));
309
6.71k
            else
310
6.71k
            {
311
6.71k
                m_len -= M4_MAX_LEN;
312
6.71k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8));
313
11.1k
                while __lzo_unlikely(m_len > 255)
314
4.44k
                {
315
4.44k
                    m_len -= 255;
316
4.44k
                    UA_SET1(op, 0);
317
4.44k
                    op++;
318
4.44k
                }
319
6.71k
                *op++ = LZO_BYTE(m_len);
320
6.71k
            }
321
20.4k
            *op++ = LZO_BYTE(m_off << 2);
322
20.4k
            *op++ = LZO_BYTE(m_off >> 6);
323
20.4k
        }
324
371k
        goto next;
325
371k
    }
326
327
748
    *out_len = pd(op, out);
328
748
    return pd(in_end,ii-ti);
329
748
}
lzo1x_1k.c:lzo1x_1_11_compress_core
Line
Count
Source
44
772
{
45
772
    const lzo_bytep ip;
46
772
    lzo_bytep op;
47
772
    const lzo_bytep const in_end = in + in_len;
48
772
    const lzo_bytep const ip_end = in + in_len - 20;
49
772
    const lzo_bytep ii;
50
772
    lzo_dict_p const dict = (lzo_dict_p) wrkmem;
51
52
772
    op = out;
53
772
    ip = in;
54
772
    ii = ip;
55
56
772
    ip += ti < 4 ? 4 - ti : 0;
57
772
    for (;;)
58
772
    {
59
772
        const lzo_bytep m_pos;
60
#if !(LZO_DETERMINISTIC)
61
        LZO_DEFINE_UNINITIALIZED_VAR(lzo_uint, m_off, 0);
62
        lzo_uint m_len;
63
        lzo_uint dindex;
64
next:
65
        if __lzo_unlikely(ip >= ip_end)
66
            break;
67
        DINDEX1(dindex,ip);
68
        GINDEX(m_pos,m_off,dict,dindex,in);
69
        if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET))
70
            goto literal;
71
#if 1
72
        if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
73
            goto try_match;
74
        DINDEX2(dindex,ip);
75
#endif
76
        GINDEX(m_pos,m_off,dict,dindex,in);
77
        if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET))
78
            goto literal;
79
        if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
80
            goto try_match;
81
        goto literal;
82
83
try_match:
84
#if (LZO_OPT_UNALIGNED32)
85
        if (UA_GET_NE32(m_pos) != UA_GET_NE32(ip))
86
#else
87
        if (m_pos[0] != ip[0] || m_pos[1] != ip[1] || m_pos[2] != ip[2] || m_pos[3] != ip[3])
88
#endif
89
        {
90
            /* a literal */
91
literal:
92
            UPDATE_I(dict,0,dindex,ip,in);
93
            ip += 1 + ((ip - ii) >> 5);
94
            continue;
95
        }
96
/*match:*/
97
        UPDATE_I(dict,0,dindex,ip,in);
98
#else
99
772
        lzo_uint m_off;
100
772
        lzo_uint m_len;
101
772
        {
102
772
        lzo_uint32_t dv;
103
772
        lzo_uint dindex;
104
703k
literal:
105
703k
        ip += 1 + ((ip - ii) >> 5);
106
882k
next:
107
882k
        if __lzo_unlikely(ip >= ip_end)
108
772
            break;
109
882k
        dv = UA_GET_LE32(ip);
110
882k
        dindex = DINDEX(dv,ip);
111
882k
        GINDEX(m_off,m_pos,in+dict,dindex,in);
112
882k
        UPDATE_I(dict,0,dindex,ip,in);
113
882k
        if __lzo_unlikely(dv != UA_GET_LE32(m_pos))
114
703k
            goto literal;
115
882k
        }
116
179k
#endif
117
118
    /* a match */
119
120
179k
        ii -= ti; ti = 0;
121
179k
        {
122
179k
        lzo_uint t = pd(ip,ii);
123
179k
        if (t != 0)
124
77.2k
        {
125
77.2k
            if (t <= 3)
126
43.7k
            {
127
43.7k
                op[-2] = LZO_BYTE(op[-2] | t);
128
43.7k
#if (LZO_OPT_UNALIGNED32)
129
43.7k
                UA_COPY4(op, ii);
130
43.7k
                op += t;
131
#else
132
                { do *op++ = *ii++; while (--t > 0); }
133
#endif
134
43.7k
            }
135
33.4k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
136
33.4k
            else if (t <= 16)
137
25.8k
            {
138
25.8k
                *op++ = LZO_BYTE(t - 3);
139
25.8k
                UA_COPY8(op, ii);
140
25.8k
                UA_COPY8(op+8, ii+8);
141
25.8k
                op += t;
142
25.8k
            }
143
7.65k
#endif
144
7.65k
            else
145
7.65k
            {
146
7.65k
                if (t <= 18)
147
915
                    *op++ = LZO_BYTE(t - 3);
148
6.74k
                else
149
6.74k
                {
150
6.74k
                    lzo_uint tt = t - 18;
151
6.74k
                    *op++ = 0;
152
27.1k
                    while __lzo_unlikely(tt > 255)
153
20.4k
                    {
154
20.4k
                        tt -= 255;
155
20.4k
                        UA_SET1(op, 0);
156
20.4k
                        op++;
157
20.4k
                    }
158
6.74k
                    assert(tt > 0);
159
6.74k
                    *op++ = LZO_BYTE(tt);
160
6.74k
                }
161
7.65k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
162
355k
                do {
163
355k
                    UA_COPY8(op, ii);
164
355k
                    UA_COPY8(op+8, ii+8);
165
355k
                    op += 16; ii += 16; t -= 16;
166
355k
                } while (t >= 16); if (t > 0)
167
7.21k
#endif
168
46.9k
                { do *op++ = *ii++; while (--t > 0); }
169
7.65k
            }
170
77.2k
        }
171
179k
        }
172
179k
        m_len = 4;
173
179k
        {
174
179k
#if (LZO_OPT_UNALIGNED64)
175
179k
        lzo_uint64_t v;
176
179k
        v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
177
179k
        if __lzo_unlikely(v == 0) {
178
856k
            do {
179
856k
                m_len += 8;
180
856k
                v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
181
856k
                if __lzo_unlikely(ip + m_len >= ip_end)
182
189
                    goto m_len_done;
183
856k
            } while (v == 0);
184
34.8k
        }
185
#if (LZO_ABI_BIG_ENDIAN) && defined(lzo_bitops_ctlz64)
186
        m_len += lzo_bitops_ctlz64(v) / CHAR_BIT;
187
#elif (LZO_ABI_BIG_ENDIAN)
188
        if ((v >> (64 - CHAR_BIT)) == 0) do {
189
            v <<= CHAR_BIT;
190
            m_len += 1;
191
        } while ((v >> (64 - CHAR_BIT)) == 0);
192
#elif (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_cttz64)
193
178k
        m_len += lzo_bitops_cttz64(v) / CHAR_BIT;
194
#elif (LZO_ABI_LITTLE_ENDIAN)
195
        if ((v & UCHAR_MAX) == 0) do {
196
            v >>= CHAR_BIT;
197
            m_len += 1;
198
        } while ((v & UCHAR_MAX) == 0);
199
#else
200
        if (ip[m_len] == m_pos[m_len]) do {
201
            m_len += 1;
202
        } while (ip[m_len] == m_pos[m_len]);
203
#endif
204
#elif (LZO_OPT_UNALIGNED32)
205
        lzo_uint32_t v;
206
        v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len);
207
        if __lzo_unlikely(v == 0) {
208
            do {
209
                m_len += 4;
210
                v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len);
211
                if (v != 0)
212
                    break;
213
                m_len += 4;
214
                v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len);
215
                if __lzo_unlikely(ip + m_len >= ip_end)
216
                    goto m_len_done;
217
            } while (v == 0);
218
        }
219
#if (LZO_ABI_BIG_ENDIAN) && defined(lzo_bitops_ctlz32)
220
        m_len += lzo_bitops_ctlz32(v) / CHAR_BIT;
221
#elif (LZO_ABI_BIG_ENDIAN)
222
        if ((v >> (32 - CHAR_BIT)) == 0) do {
223
            v <<= CHAR_BIT;
224
            m_len += 1;
225
        } while ((v >> (32 - CHAR_BIT)) == 0);
226
#elif (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_cttz32)
227
        m_len += lzo_bitops_cttz32(v) / CHAR_BIT;
228
#elif (LZO_ABI_LITTLE_ENDIAN)
229
        if ((v & UCHAR_MAX) == 0) do {
230
            v >>= CHAR_BIT;
231
            m_len += 1;
232
        } while ((v & UCHAR_MAX) == 0);
233
#else
234
        if (ip[m_len] == m_pos[m_len]) do {
235
            m_len += 1;
236
        } while (ip[m_len] == m_pos[m_len]);
237
#endif
238
#else
239
        if __lzo_unlikely(ip[m_len] == m_pos[m_len]) {
240
            do {
241
                m_len += 1;
242
                if (ip[m_len] != m_pos[m_len])
243
                    break;
244
                m_len += 1;
245
                if (ip[m_len] != m_pos[m_len])
246
                    break;
247
                m_len += 1;
248
                if (ip[m_len] != m_pos[m_len])
249
                    break;
250
                m_len += 1;
251
                if (ip[m_len] != m_pos[m_len])
252
                    break;
253
                m_len += 1;
254
                if (ip[m_len] != m_pos[m_len])
255
                    break;
256
                m_len += 1;
257
                if (ip[m_len] != m_pos[m_len])
258
                    break;
259
                m_len += 1;
260
                if (ip[m_len] != m_pos[m_len])
261
                    break;
262
                m_len += 1;
263
                if __lzo_unlikely(ip + m_len >= ip_end)
264
                    goto m_len_done;
265
            } while (ip[m_len] == m_pos[m_len]);
266
        }
267
#endif
268
178k
        }
269
179k
m_len_done:
270
179k
        m_off = pd(ip,m_pos);
271
179k
        ip += m_len;
272
179k
        ii = ip;
273
179k
        if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
274
112k
        {
275
112k
            m_off -= 1;
276
112k
#if defined(LZO1X)
277
112k
            *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2));
278
112k
            *op++ = LZO_BYTE(m_off >> 3);
279
#elif defined(LZO1Y)
280
            *op++ = LZO_BYTE(((m_len + 1) << 4) | ((m_off & 3) << 2));
281
            *op++ = LZO_BYTE(m_off >> 2);
282
#endif
283
112k
        }
284
66.3k
        else if (m_off <= M3_MAX_OFFSET)
285
60.2k
        {
286
60.2k
            m_off -= 1;
287
60.2k
            if (m_len <= M3_MAX_LEN)
288
45.9k
                *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
289
14.3k
            else
290
14.3k
            {
291
14.3k
                m_len -= M3_MAX_LEN;
292
14.3k
                *op++ = M3_MARKER | 0;
293
31.8k
                while __lzo_unlikely(m_len > 255)
294
17.5k
                {
295
17.5k
                    m_len -= 255;
296
17.5k
                    UA_SET1(op, 0);
297
17.5k
                    op++;
298
17.5k
                }
299
14.3k
                *op++ = LZO_BYTE(m_len);
300
14.3k
            }
301
60.2k
            *op++ = LZO_BYTE(m_off << 2);
302
60.2k
            *op++ = LZO_BYTE(m_off >> 6);
303
60.2k
        }
304
6.13k
        else
305
6.13k
        {
306
6.13k
            m_off -= 0x4000;
307
6.13k
            if (m_len <= M4_MAX_LEN)
308
3.57k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8) | (m_len - 2));
309
2.56k
            else
310
2.56k
            {
311
2.56k
                m_len -= M4_MAX_LEN;
312
2.56k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8));
313
5.32k
                while __lzo_unlikely(m_len > 255)
314
2.76k
                {
315
2.76k
                    m_len -= 255;
316
2.76k
                    UA_SET1(op, 0);
317
2.76k
                    op++;
318
2.76k
                }
319
2.56k
                *op++ = LZO_BYTE(m_len);
320
2.56k
            }
321
6.13k
            *op++ = LZO_BYTE(m_off << 2);
322
6.13k
            *op++ = LZO_BYTE(m_off >> 6);
323
6.13k
        }
324
179k
        goto next;
325
178k
    }
326
327
772
    *out_len = pd(op, out);
328
772
    return pd(in_end,ii-ti);
329
772
}
lzo1x_1l.c:lzo1x_1_12_compress_core
Line
Count
Source
44
717
{
45
717
    const lzo_bytep ip;
46
717
    lzo_bytep op;
47
717
    const lzo_bytep const in_end = in + in_len;
48
717
    const lzo_bytep const ip_end = in + in_len - 20;
49
717
    const lzo_bytep ii;
50
717
    lzo_dict_p const dict = (lzo_dict_p) wrkmem;
51
52
717
    op = out;
53
717
    ip = in;
54
717
    ii = ip;
55
56
717
    ip += ti < 4 ? 4 - ti : 0;
57
717
    for (;;)
58
717
    {
59
717
        const lzo_bytep m_pos;
60
#if !(LZO_DETERMINISTIC)
61
        LZO_DEFINE_UNINITIALIZED_VAR(lzo_uint, m_off, 0);
62
        lzo_uint m_len;
63
        lzo_uint dindex;
64
next:
65
        if __lzo_unlikely(ip >= ip_end)
66
            break;
67
        DINDEX1(dindex,ip);
68
        GINDEX(m_pos,m_off,dict,dindex,in);
69
        if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET))
70
            goto literal;
71
#if 1
72
        if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
73
            goto try_match;
74
        DINDEX2(dindex,ip);
75
#endif
76
        GINDEX(m_pos,m_off,dict,dindex,in);
77
        if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET))
78
            goto literal;
79
        if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
80
            goto try_match;
81
        goto literal;
82
83
try_match:
84
#if (LZO_OPT_UNALIGNED32)
85
        if (UA_GET_NE32(m_pos) != UA_GET_NE32(ip))
86
#else
87
        if (m_pos[0] != ip[0] || m_pos[1] != ip[1] || m_pos[2] != ip[2] || m_pos[3] != ip[3])
88
#endif
89
        {
90
            /* a literal */
91
literal:
92
            UPDATE_I(dict,0,dindex,ip,in);
93
            ip += 1 + ((ip - ii) >> 5);
94
            continue;
95
        }
96
/*match:*/
97
        UPDATE_I(dict,0,dindex,ip,in);
98
#else
99
717
        lzo_uint m_off;
100
717
        lzo_uint m_len;
101
717
        {
102
717
        lzo_uint32_t dv;
103
717
        lzo_uint dindex;
104
866k
literal:
105
866k
        ip += 1 + ((ip - ii) >> 5);
106
1.08M
next:
107
1.08M
        if __lzo_unlikely(ip >= ip_end)
108
717
            break;
109
1.08M
        dv = UA_GET_LE32(ip);
110
1.08M
        dindex = DINDEX(dv,ip);
111
1.08M
        GINDEX(m_off,m_pos,in+dict,dindex,in);
112
1.08M
        UPDATE_I(dict,0,dindex,ip,in);
113
1.08M
        if __lzo_unlikely(dv != UA_GET_LE32(m_pos))
114
865k
            goto literal;
115
1.08M
        }
116
219k
#endif
117
118
    /* a match */
119
120
219k
        ii -= ti; ti = 0;
121
219k
        {
122
219k
        lzo_uint t = pd(ip,ii);
123
219k
        if (t != 0)
124
107k
        {
125
107k
            if (t <= 3)
126
60.3k
            {
127
60.3k
                op[-2] = LZO_BYTE(op[-2] | t);
128
60.3k
#if (LZO_OPT_UNALIGNED32)
129
60.3k
                UA_COPY4(op, ii);
130
60.3k
                op += t;
131
#else
132
                { do *op++ = *ii++; while (--t > 0); }
133
#endif
134
60.3k
            }
135
46.9k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
136
46.9k
            else if (t <= 16)
137
37.0k
            {
138
37.0k
                *op++ = LZO_BYTE(t - 3);
139
37.0k
                UA_COPY8(op, ii);
140
37.0k
                UA_COPY8(op+8, ii+8);
141
37.0k
                op += t;
142
37.0k
            }
143
9.95k
#endif
144
9.95k
            else
145
9.95k
            {
146
9.95k
                if (t <= 18)
147
1.23k
                    *op++ = LZO_BYTE(t - 3);
148
8.71k
                else
149
8.71k
                {
150
8.71k
                    lzo_uint tt = t - 18;
151
8.71k
                    *op++ = 0;
152
25.7k
                    while __lzo_unlikely(tt > 255)
153
16.9k
                    {
154
16.9k
                        tt -= 255;
155
16.9k
                        UA_SET1(op, 0);
156
16.9k
                        op++;
157
16.9k
                    }
158
8.71k
                    assert(tt > 0);
159
8.71k
                    *op++ = LZO_BYTE(tt);
160
8.71k
                }
161
9.95k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
162
305k
                do {
163
305k
                    UA_COPY8(op, ii);
164
305k
                    UA_COPY8(op+8, ii+8);
165
305k
                    op += 16; ii += 16; t -= 16;
166
305k
                } while (t >= 16); if (t > 0)
167
9.35k
#endif
168
62.4k
                { do *op++ = *ii++; while (--t > 0); }
169
9.95k
            }
170
107k
        }
171
219k
        }
172
219k
        m_len = 4;
173
219k
        {
174
219k
#if (LZO_OPT_UNALIGNED64)
175
219k
        lzo_uint64_t v;
176
219k
        v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
177
219k
        if __lzo_unlikely(v == 0) {
178
994k
            do {
179
994k
                m_len += 8;
180
994k
                v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
181
994k
                if __lzo_unlikely(ip + m_len >= ip_end)
182
238
                    goto m_len_done;
183
994k
            } while (v == 0);
184
57.8k
        }
185
#if (LZO_ABI_BIG_ENDIAN) && defined(lzo_bitops_ctlz64)
186
        m_len += lzo_bitops_ctlz64(v) / CHAR_BIT;
187
#elif (LZO_ABI_BIG_ENDIAN)
188
        if ((v >> (64 - CHAR_BIT)) == 0) do {
189
            v <<= CHAR_BIT;
190
            m_len += 1;
191
        } while ((v >> (64 - CHAR_BIT)) == 0);
192
#elif (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_cttz64)
193
219k
        m_len += lzo_bitops_cttz64(v) / CHAR_BIT;
194
#elif (LZO_ABI_LITTLE_ENDIAN)
195
        if ((v & UCHAR_MAX) == 0) do {
196
            v >>= CHAR_BIT;
197
            m_len += 1;
198
        } while ((v & UCHAR_MAX) == 0);
199
#else
200
        if (ip[m_len] == m_pos[m_len]) do {
201
            m_len += 1;
202
        } while (ip[m_len] == m_pos[m_len]);
203
#endif
204
#elif (LZO_OPT_UNALIGNED32)
205
        lzo_uint32_t v;
206
        v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len);
207
        if __lzo_unlikely(v == 0) {
208
            do {
209
                m_len += 4;
210
                v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len);
211
                if (v != 0)
212
                    break;
213
                m_len += 4;
214
                v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len);
215
                if __lzo_unlikely(ip + m_len >= ip_end)
216
                    goto m_len_done;
217
            } while (v == 0);
218
        }
219
#if (LZO_ABI_BIG_ENDIAN) && defined(lzo_bitops_ctlz32)
220
        m_len += lzo_bitops_ctlz32(v) / CHAR_BIT;
221
#elif (LZO_ABI_BIG_ENDIAN)
222
        if ((v >> (32 - CHAR_BIT)) == 0) do {
223
            v <<= CHAR_BIT;
224
            m_len += 1;
225
        } while ((v >> (32 - CHAR_BIT)) == 0);
226
#elif (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_cttz32)
227
        m_len += lzo_bitops_cttz32(v) / CHAR_BIT;
228
#elif (LZO_ABI_LITTLE_ENDIAN)
229
        if ((v & UCHAR_MAX) == 0) do {
230
            v >>= CHAR_BIT;
231
            m_len += 1;
232
        } while ((v & UCHAR_MAX) == 0);
233
#else
234
        if (ip[m_len] == m_pos[m_len]) do {
235
            m_len += 1;
236
        } while (ip[m_len] == m_pos[m_len]);
237
#endif
238
#else
239
        if __lzo_unlikely(ip[m_len] == m_pos[m_len]) {
240
            do {
241
                m_len += 1;
242
                if (ip[m_len] != m_pos[m_len])
243
                    break;
244
                m_len += 1;
245
                if (ip[m_len] != m_pos[m_len])
246
                    break;
247
                m_len += 1;
248
                if (ip[m_len] != m_pos[m_len])
249
                    break;
250
                m_len += 1;
251
                if (ip[m_len] != m_pos[m_len])
252
                    break;
253
                m_len += 1;
254
                if (ip[m_len] != m_pos[m_len])
255
                    break;
256
                m_len += 1;
257
                if (ip[m_len] != m_pos[m_len])
258
                    break;
259
                m_len += 1;
260
                if (ip[m_len] != m_pos[m_len])
261
                    break;
262
                m_len += 1;
263
                if __lzo_unlikely(ip + m_len >= ip_end)
264
                    goto m_len_done;
265
            } while (ip[m_len] == m_pos[m_len]);
266
        }
267
#endif
268
219k
        }
269
219k
m_len_done:
270
219k
        m_off = pd(ip,m_pos);
271
219k
        ip += m_len;
272
219k
        ii = ip;
273
219k
        if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
274
108k
        {
275
108k
            m_off -= 1;
276
108k
#if defined(LZO1X)
277
108k
            *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2));
278
108k
            *op++ = LZO_BYTE(m_off >> 3);
279
#elif defined(LZO1Y)
280
            *op++ = LZO_BYTE(((m_len + 1) << 4) | ((m_off & 3) << 2));
281
            *op++ = LZO_BYTE(m_off >> 2);
282
#endif
283
108k
        }
284
110k
        else if (m_off <= M3_MAX_OFFSET)
285
97.2k
        {
286
97.2k
            m_off -= 1;
287
97.2k
            if (m_len <= M3_MAX_LEN)
288
73.5k
                *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
289
23.7k
            else
290
23.7k
            {
291
23.7k
                m_len -= M3_MAX_LEN;
292
23.7k
                *op++ = M3_MARKER | 0;
293
40.4k
                while __lzo_unlikely(m_len > 255)
294
16.6k
                {
295
16.6k
                    m_len -= 255;
296
16.6k
                    UA_SET1(op, 0);
297
16.6k
                    op++;
298
16.6k
                }
299
23.7k
                *op++ = LZO_BYTE(m_len);
300
23.7k
            }
301
97.2k
            *op++ = LZO_BYTE(m_off << 2);
302
97.2k
            *op++ = LZO_BYTE(m_off >> 6);
303
97.2k
        }
304
13.7k
        else
305
13.7k
        {
306
13.7k
            m_off -= 0x4000;
307
13.7k
            if (m_len <= M4_MAX_LEN)
308
7.81k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8) | (m_len - 2));
309
5.91k
            else
310
5.91k
            {
311
5.91k
                m_len -= M4_MAX_LEN;
312
5.91k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8));
313
9.88k
                while __lzo_unlikely(m_len > 255)
314
3.97k
                {
315
3.97k
                    m_len -= 255;
316
3.97k
                    UA_SET1(op, 0);
317
3.97k
                    op++;
318
3.97k
                }
319
5.91k
                *op++ = LZO_BYTE(m_len);
320
5.91k
            }
321
13.7k
            *op++ = LZO_BYTE(m_off << 2);
322
13.7k
            *op++ = LZO_BYTE(m_off >> 6);
323
13.7k
        }
324
219k
        goto next;
325
219k
    }
326
327
717
    *out_len = pd(op, out);
328
717
    return pd(in_end,ii-ti);
329
717
}
lzo1x_1o.c:lzo1x_1_15_compress_core
Line
Count
Source
44
604
{
45
604
    const lzo_bytep ip;
46
604
    lzo_bytep op;
47
604
    const lzo_bytep const in_end = in + in_len;
48
604
    const lzo_bytep const ip_end = in + in_len - 20;
49
604
    const lzo_bytep ii;
50
604
    lzo_dict_p const dict = (lzo_dict_p) wrkmem;
51
52
604
    op = out;
53
604
    ip = in;
54
604
    ii = ip;
55
56
604
    ip += ti < 4 ? 4 - ti : 0;
57
604
    for (;;)
58
604
    {
59
604
        const lzo_bytep m_pos;
60
#if !(LZO_DETERMINISTIC)
61
        LZO_DEFINE_UNINITIALIZED_VAR(lzo_uint, m_off, 0);
62
        lzo_uint m_len;
63
        lzo_uint dindex;
64
next:
65
        if __lzo_unlikely(ip >= ip_end)
66
            break;
67
        DINDEX1(dindex,ip);
68
        GINDEX(m_pos,m_off,dict,dindex,in);
69
        if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET))
70
            goto literal;
71
#if 1
72
        if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
73
            goto try_match;
74
        DINDEX2(dindex,ip);
75
#endif
76
        GINDEX(m_pos,m_off,dict,dindex,in);
77
        if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET))
78
            goto literal;
79
        if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
80
            goto try_match;
81
        goto literal;
82
83
try_match:
84
#if (LZO_OPT_UNALIGNED32)
85
        if (UA_GET_NE32(m_pos) != UA_GET_NE32(ip))
86
#else
87
        if (m_pos[0] != ip[0] || m_pos[1] != ip[1] || m_pos[2] != ip[2] || m_pos[3] != ip[3])
88
#endif
89
        {
90
            /* a literal */
91
literal:
92
            UPDATE_I(dict,0,dindex,ip,in);
93
            ip += 1 + ((ip - ii) >> 5);
94
            continue;
95
        }
96
/*match:*/
97
        UPDATE_I(dict,0,dindex,ip,in);
98
#else
99
604
        lzo_uint m_off;
100
604
        lzo_uint m_len;
101
604
        {
102
604
        lzo_uint32_t dv;
103
604
        lzo_uint dindex;
104
703k
literal:
105
703k
        ip += 1 + ((ip - ii) >> 5);
106
906k
next:
107
906k
        if __lzo_unlikely(ip >= ip_end)
108
604
            break;
109
905k
        dv = UA_GET_LE32(ip);
110
905k
        dindex = DINDEX(dv,ip);
111
905k
        GINDEX(m_off,m_pos,in+dict,dindex,in);
112
905k
        UPDATE_I(dict,0,dindex,ip,in);
113
905k
        if __lzo_unlikely(dv != UA_GET_LE32(m_pos))
114
703k
            goto literal;
115
905k
        }
116
202k
#endif
117
118
    /* a match */
119
120
202k
        ii -= ti; ti = 0;
121
202k
        {
122
202k
        lzo_uint t = pd(ip,ii);
123
202k
        if (t != 0)
124
80.6k
        {
125
80.6k
            if (t <= 3)
126
44.8k
            {
127
44.8k
                op[-2] = LZO_BYTE(op[-2] | t);
128
44.8k
#if (LZO_OPT_UNALIGNED32)
129
44.8k
                UA_COPY4(op, ii);
130
44.8k
                op += t;
131
#else
132
                { do *op++ = *ii++; while (--t > 0); }
133
#endif
134
44.8k
            }
135
35.7k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
136
35.7k
            else if (t <= 16)
137
27.1k
            {
138
27.1k
                *op++ = LZO_BYTE(t - 3);
139
27.1k
                UA_COPY8(op, ii);
140
27.1k
                UA_COPY8(op+8, ii+8);
141
27.1k
                op += t;
142
27.1k
            }
143
8.56k
#endif
144
8.56k
            else
145
8.56k
            {
146
8.56k
                if (t <= 18)
147
905
                    *op++ = LZO_BYTE(t - 3);
148
7.65k
                else
149
7.65k
                {
150
7.65k
                    lzo_uint tt = t - 18;
151
7.65k
                    *op++ = 0;
152
19.6k
                    while __lzo_unlikely(tt > 255)
153
11.9k
                    {
154
11.9k
                        tt -= 255;
155
11.9k
                        UA_SET1(op, 0);
156
11.9k
                        op++;
157
11.9k
                    }
158
7.65k
                    assert(tt > 0);
159
7.65k
                    *op++ = LZO_BYTE(tt);
160
7.65k
                }
161
8.56k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
162
222k
                do {
163
222k
                    UA_COPY8(op, ii);
164
222k
                    UA_COPY8(op+8, ii+8);
165
222k
                    op += 16; ii += 16; t -= 16;
166
222k
                } while (t >= 16); if (t > 0)
167
7.89k
#endif
168
53.0k
                { do *op++ = *ii++; while (--t > 0); }
169
8.56k
            }
170
80.6k
        }
171
202k
        }
172
202k
        m_len = 4;
173
202k
        {
174
202k
#if (LZO_OPT_UNALIGNED64)
175
202k
        lzo_uint64_t v;
176
202k
        v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
177
202k
        if __lzo_unlikely(v == 0) {
178
978k
            do {
179
978k
                m_len += 8;
180
978k
                v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
181
978k
                if __lzo_unlikely(ip + m_len >= ip_end)
182
213
                    goto m_len_done;
183
978k
            } while (v == 0);
184
37.0k
        }
185
#if (LZO_ABI_BIG_ENDIAN) && defined(lzo_bitops_ctlz64)
186
        m_len += lzo_bitops_ctlz64(v) / CHAR_BIT;
187
#elif (LZO_ABI_BIG_ENDIAN)
188
        if ((v >> (64 - CHAR_BIT)) == 0) do {
189
            v <<= CHAR_BIT;
190
            m_len += 1;
191
        } while ((v >> (64 - CHAR_BIT)) == 0);
192
#elif (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_cttz64)
193
202k
        m_len += lzo_bitops_cttz64(v) / CHAR_BIT;
194
#elif (LZO_ABI_LITTLE_ENDIAN)
195
        if ((v & UCHAR_MAX) == 0) do {
196
            v >>= CHAR_BIT;
197
            m_len += 1;
198
        } while ((v & UCHAR_MAX) == 0);
199
#else
200
        if (ip[m_len] == m_pos[m_len]) do {
201
            m_len += 1;
202
        } while (ip[m_len] == m_pos[m_len]);
203
#endif
204
#elif (LZO_OPT_UNALIGNED32)
205
        lzo_uint32_t v;
206
        v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len);
207
        if __lzo_unlikely(v == 0) {
208
            do {
209
                m_len += 4;
210
                v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len);
211
                if (v != 0)
212
                    break;
213
                m_len += 4;
214
                v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len);
215
                if __lzo_unlikely(ip + m_len >= ip_end)
216
                    goto m_len_done;
217
            } while (v == 0);
218
        }
219
#if (LZO_ABI_BIG_ENDIAN) && defined(lzo_bitops_ctlz32)
220
        m_len += lzo_bitops_ctlz32(v) / CHAR_BIT;
221
#elif (LZO_ABI_BIG_ENDIAN)
222
        if ((v >> (32 - CHAR_BIT)) == 0) do {
223
            v <<= CHAR_BIT;
224
            m_len += 1;
225
        } while ((v >> (32 - CHAR_BIT)) == 0);
226
#elif (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_cttz32)
227
        m_len += lzo_bitops_cttz32(v) / CHAR_BIT;
228
#elif (LZO_ABI_LITTLE_ENDIAN)
229
        if ((v & UCHAR_MAX) == 0) do {
230
            v >>= CHAR_BIT;
231
            m_len += 1;
232
        } while ((v & UCHAR_MAX) == 0);
233
#else
234
        if (ip[m_len] == m_pos[m_len]) do {
235
            m_len += 1;
236
        } while (ip[m_len] == m_pos[m_len]);
237
#endif
238
#else
239
        if __lzo_unlikely(ip[m_len] == m_pos[m_len]) {
240
            do {
241
                m_len += 1;
242
                if (ip[m_len] != m_pos[m_len])
243
                    break;
244
                m_len += 1;
245
                if (ip[m_len] != m_pos[m_len])
246
                    break;
247
                m_len += 1;
248
                if (ip[m_len] != m_pos[m_len])
249
                    break;
250
                m_len += 1;
251
                if (ip[m_len] != m_pos[m_len])
252
                    break;
253
                m_len += 1;
254
                if (ip[m_len] != m_pos[m_len])
255
                    break;
256
                m_len += 1;
257
                if (ip[m_len] != m_pos[m_len])
258
                    break;
259
                m_len += 1;
260
                if (ip[m_len] != m_pos[m_len])
261
                    break;
262
                m_len += 1;
263
                if __lzo_unlikely(ip + m_len >= ip_end)
264
                    goto m_len_done;
265
            } while (ip[m_len] == m_pos[m_len]);
266
        }
267
#endif
268
202k
        }
269
202k
m_len_done:
270
202k
        m_off = pd(ip,m_pos);
271
202k
        ip += m_len;
272
202k
        ii = ip;
273
202k
        if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
274
118k
        {
275
118k
            m_off -= 1;
276
118k
#if defined(LZO1X)
277
118k
            *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2));
278
118k
            *op++ = LZO_BYTE(m_off >> 3);
279
#elif defined(LZO1Y)
280
            *op++ = LZO_BYTE(((m_len + 1) << 4) | ((m_off & 3) << 2));
281
            *op++ = LZO_BYTE(m_off >> 2);
282
#endif
283
118k
        }
284
84.2k
        else if (m_off <= M3_MAX_OFFSET)
285
72.0k
        {
286
72.0k
            m_off -= 1;
287
72.0k
            if (m_len <= M3_MAX_LEN)
288
57.5k
                *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
289
14.5k
            else
290
14.5k
            {
291
14.5k
                m_len -= M3_MAX_LEN;
292
14.5k
                *op++ = M3_MARKER | 0;
293
34.0k
                while __lzo_unlikely(m_len > 255)
294
19.4k
                {
295
19.4k
                    m_len -= 255;
296
19.4k
                    UA_SET1(op, 0);
297
19.4k
                    op++;
298
19.4k
                }
299
14.5k
                *op++ = LZO_BYTE(m_len);
300
14.5k
            }
301
72.0k
            *op++ = LZO_BYTE(m_off << 2);
302
72.0k
            *op++ = LZO_BYTE(m_off >> 6);
303
72.0k
        }
304
12.1k
        else
305
12.1k
        {
306
12.1k
            m_off -= 0x4000;
307
12.1k
            if (m_len <= M4_MAX_LEN)
308
8.22k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8) | (m_len - 2));
309
3.95k
            else
310
3.95k
            {
311
3.95k
                m_len -= M4_MAX_LEN;
312
3.95k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8));
313
7.95k
                while __lzo_unlikely(m_len > 255)
314
3.99k
                {
315
3.99k
                    m_len -= 255;
316
3.99k
                    UA_SET1(op, 0);
317
3.99k
                    op++;
318
3.99k
                }
319
3.95k
                *op++ = LZO_BYTE(m_len);
320
3.95k
            }
321
12.1k
            *op++ = LZO_BYTE(m_off << 2);
322
12.1k
            *op++ = LZO_BYTE(m_off >> 6);
323
12.1k
        }
324
202k
        goto next;
325
202k
    }
326
327
604
    *out_len = pd(op, out);
328
604
    return pd(in_end,ii-ti);
329
604
}
lzo1y_1.c:lzo1y_1_compress_core
Line
Count
Source
44
855
{
45
855
    const lzo_bytep ip;
46
855
    lzo_bytep op;
47
855
    const lzo_bytep const in_end = in + in_len;
48
855
    const lzo_bytep const ip_end = in + in_len - 20;
49
855
    const lzo_bytep ii;
50
855
    lzo_dict_p const dict = (lzo_dict_p) wrkmem;
51
52
855
    op = out;
53
855
    ip = in;
54
855
    ii = ip;
55
56
855
    ip += ti < 4 ? 4 - ti : 0;
57
855
    for (;;)
58
855
    {
59
855
        const lzo_bytep m_pos;
60
#if !(LZO_DETERMINISTIC)
61
        LZO_DEFINE_UNINITIALIZED_VAR(lzo_uint, m_off, 0);
62
        lzo_uint m_len;
63
        lzo_uint dindex;
64
next:
65
        if __lzo_unlikely(ip >= ip_end)
66
            break;
67
        DINDEX1(dindex,ip);
68
        GINDEX(m_pos,m_off,dict,dindex,in);
69
        if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET))
70
            goto literal;
71
#if 1
72
        if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
73
            goto try_match;
74
        DINDEX2(dindex,ip);
75
#endif
76
        GINDEX(m_pos,m_off,dict,dindex,in);
77
        if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET))
78
            goto literal;
79
        if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
80
            goto try_match;
81
        goto literal;
82
83
try_match:
84
#if (LZO_OPT_UNALIGNED32)
85
        if (UA_GET_NE32(m_pos) != UA_GET_NE32(ip))
86
#else
87
        if (m_pos[0] != ip[0] || m_pos[1] != ip[1] || m_pos[2] != ip[2] || m_pos[3] != ip[3])
88
#endif
89
        {
90
            /* a literal */
91
literal:
92
            UPDATE_I(dict,0,dindex,ip,in);
93
            ip += 1 + ((ip - ii) >> 5);
94
            continue;
95
        }
96
/*match:*/
97
        UPDATE_I(dict,0,dindex,ip,in);
98
#else
99
855
        lzo_uint m_off;
100
855
        lzo_uint m_len;
101
855
        {
102
855
        lzo_uint32_t dv;
103
855
        lzo_uint dindex;
104
869k
literal:
105
869k
        ip += 1 + ((ip - ii) >> 5);
106
1.08M
next:
107
1.08M
        if __lzo_unlikely(ip >= ip_end)
108
855
            break;
109
1.08M
        dv = UA_GET_LE32(ip);
110
1.08M
        dindex = DINDEX(dv,ip);
111
1.08M
        GINDEX(m_off,m_pos,in+dict,dindex,in);
112
1.08M
        UPDATE_I(dict,0,dindex,ip,in);
113
1.08M
        if __lzo_unlikely(dv != UA_GET_LE32(m_pos))
114
869k
            goto literal;
115
1.08M
        }
116
218k
#endif
117
118
    /* a match */
119
120
218k
        ii -= ti; ti = 0;
121
218k
        {
122
218k
        lzo_uint t = pd(ip,ii);
123
218k
        if (t != 0)
124
99.8k
        {
125
99.8k
            if (t <= 3)
126
53.6k
            {
127
53.6k
                op[-2] = LZO_BYTE(op[-2] | t);
128
53.6k
#if (LZO_OPT_UNALIGNED32)
129
53.6k
                UA_COPY4(op, ii);
130
53.6k
                op += t;
131
#else
132
                { do *op++ = *ii++; while (--t > 0); }
133
#endif
134
53.6k
            }
135
46.1k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
136
46.1k
            else if (t <= 16)
137
36.4k
            {
138
36.4k
                *op++ = LZO_BYTE(t - 3);
139
36.4k
                UA_COPY8(op, ii);
140
36.4k
                UA_COPY8(op+8, ii+8);
141
36.4k
                op += t;
142
36.4k
            }
143
9.69k
#endif
144
9.69k
            else
145
9.69k
            {
146
9.69k
                if (t <= 18)
147
1.15k
                    *op++ = LZO_BYTE(t - 3);
148
8.54k
                else
149
8.54k
                {
150
8.54k
                    lzo_uint tt = t - 18;
151
8.54k
                    *op++ = 0;
152
36.9k
                    while __lzo_unlikely(tt > 255)
153
28.3k
                    {
154
28.3k
                        tt -= 255;
155
28.3k
                        UA_SET1(op, 0);
156
28.3k
                        op++;
157
28.3k
                    }
158
8.54k
                    assert(tt > 0);
159
8.54k
                    *op++ = LZO_BYTE(tt);
160
8.54k
                }
161
9.69k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
162
486k
                do {
163
486k
                    UA_COPY8(op, ii);
164
486k
                    UA_COPY8(op+8, ii+8);
165
486k
                    op += 16; ii += 16; t -= 16;
166
486k
                } while (t >= 16); if (t > 0)
167
8.87k
#endif
168
58.4k
                { do *op++ = *ii++; while (--t > 0); }
169
9.69k
            }
170
99.8k
        }
171
218k
        }
172
218k
        m_len = 4;
173
218k
        {
174
218k
#if (LZO_OPT_UNALIGNED64)
175
218k
        lzo_uint64_t v;
176
218k
        v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
177
218k
        if __lzo_unlikely(v == 0) {
178
1.14M
            do {
179
1.14M
                m_len += 8;
180
1.14M
                v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
181
1.14M
                if __lzo_unlikely(ip + m_len >= ip_end)
182
263
                    goto m_len_done;
183
1.14M
            } while (v == 0);
184
49.9k
        }
185
#if (LZO_ABI_BIG_ENDIAN) && defined(lzo_bitops_ctlz64)
186
        m_len += lzo_bitops_ctlz64(v) / CHAR_BIT;
187
#elif (LZO_ABI_BIG_ENDIAN)
188
        if ((v >> (64 - CHAR_BIT)) == 0) do {
189
            v <<= CHAR_BIT;
190
            m_len += 1;
191
        } while ((v >> (64 - CHAR_BIT)) == 0);
192
#elif (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_cttz64)
193
218k
        m_len += lzo_bitops_cttz64(v) / CHAR_BIT;
194
#elif (LZO_ABI_LITTLE_ENDIAN)
195
        if ((v & UCHAR_MAX) == 0) do {
196
            v >>= CHAR_BIT;
197
            m_len += 1;
198
        } while ((v & UCHAR_MAX) == 0);
199
#else
200
        if (ip[m_len] == m_pos[m_len]) do {
201
            m_len += 1;
202
        } while (ip[m_len] == m_pos[m_len]);
203
#endif
204
#elif (LZO_OPT_UNALIGNED32)
205
        lzo_uint32_t v;
206
        v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len);
207
        if __lzo_unlikely(v == 0) {
208
            do {
209
                m_len += 4;
210
                v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len);
211
                if (v != 0)
212
                    break;
213
                m_len += 4;
214
                v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len);
215
                if __lzo_unlikely(ip + m_len >= ip_end)
216
                    goto m_len_done;
217
            } while (v == 0);
218
        }
219
#if (LZO_ABI_BIG_ENDIAN) && defined(lzo_bitops_ctlz32)
220
        m_len += lzo_bitops_ctlz32(v) / CHAR_BIT;
221
#elif (LZO_ABI_BIG_ENDIAN)
222
        if ((v >> (32 - CHAR_BIT)) == 0) do {
223
            v <<= CHAR_BIT;
224
            m_len += 1;
225
        } while ((v >> (32 - CHAR_BIT)) == 0);
226
#elif (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_cttz32)
227
        m_len += lzo_bitops_cttz32(v) / CHAR_BIT;
228
#elif (LZO_ABI_LITTLE_ENDIAN)
229
        if ((v & UCHAR_MAX) == 0) do {
230
            v >>= CHAR_BIT;
231
            m_len += 1;
232
        } while ((v & UCHAR_MAX) == 0);
233
#else
234
        if (ip[m_len] == m_pos[m_len]) do {
235
            m_len += 1;
236
        } while (ip[m_len] == m_pos[m_len]);
237
#endif
238
#else
239
        if __lzo_unlikely(ip[m_len] == m_pos[m_len]) {
240
            do {
241
                m_len += 1;
242
                if (ip[m_len] != m_pos[m_len])
243
                    break;
244
                m_len += 1;
245
                if (ip[m_len] != m_pos[m_len])
246
                    break;
247
                m_len += 1;
248
                if (ip[m_len] != m_pos[m_len])
249
                    break;
250
                m_len += 1;
251
                if (ip[m_len] != m_pos[m_len])
252
                    break;
253
                m_len += 1;
254
                if (ip[m_len] != m_pos[m_len])
255
                    break;
256
                m_len += 1;
257
                if (ip[m_len] != m_pos[m_len])
258
                    break;
259
                m_len += 1;
260
                if (ip[m_len] != m_pos[m_len])
261
                    break;
262
                m_len += 1;
263
                if __lzo_unlikely(ip + m_len >= ip_end)
264
                    goto m_len_done;
265
            } while (ip[m_len] == m_pos[m_len]);
266
        }
267
#endif
268
218k
        }
269
218k
m_len_done:
270
218k
        m_off = pd(ip,m_pos);
271
218k
        ip += m_len;
272
218k
        ii = ip;
273
218k
        if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
274
122k
        {
275
122k
            m_off -= 1;
276
#if defined(LZO1X)
277
            *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2));
278
            *op++ = LZO_BYTE(m_off >> 3);
279
#elif defined(LZO1Y)
280
122k
            *op++ = LZO_BYTE(((m_len + 1) << 4) | ((m_off & 3) << 2));
281
122k
            *op++ = LZO_BYTE(m_off >> 2);
282
122k
#endif
283
122k
        }
284
95.4k
        else if (m_off <= M3_MAX_OFFSET)
285
83.1k
        {
286
83.1k
            m_off -= 1;
287
83.1k
            if (m_len <= M3_MAX_LEN)
288
63.2k
                *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
289
19.8k
            else
290
19.8k
            {
291
19.8k
                m_len -= M3_MAX_LEN;
292
19.8k
                *op++ = M3_MARKER | 0;
293
41.7k
                while __lzo_unlikely(m_len > 255)
294
21.8k
                {
295
21.8k
                    m_len -= 255;
296
21.8k
                    UA_SET1(op, 0);
297
21.8k
                    op++;
298
21.8k
                }
299
19.8k
                *op++ = LZO_BYTE(m_len);
300
19.8k
            }
301
83.1k
            *op++ = LZO_BYTE(m_off << 2);
302
83.1k
            *op++ = LZO_BYTE(m_off >> 6);
303
83.1k
        }
304
12.3k
        else
305
12.3k
        {
306
12.3k
            m_off -= 0x4000;
307
12.3k
            if (m_len <= M4_MAX_LEN)
308
7.80k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8) | (m_len - 2));
309
4.53k
            else
310
4.53k
            {
311
4.53k
                m_len -= M4_MAX_LEN;
312
4.53k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8));
313
9.00k
                while __lzo_unlikely(m_len > 255)
314
4.47k
                {
315
4.47k
                    m_len -= 255;
316
4.47k
                    UA_SET1(op, 0);
317
4.47k
                    op++;
318
4.47k
                }
319
4.53k
                *op++ = LZO_BYTE(m_len);
320
4.53k
            }
321
12.3k
            *op++ = LZO_BYTE(m_off << 2);
322
12.3k
            *op++ = LZO_BYTE(m_off >> 6);
323
12.3k
        }
324
218k
        goto next;
325
218k
    }
326
327
855
    *out_len = pd(op, out);
328
855
    return pd(in_end,ii-ti);
329
855
}
330
331
332
/***********************************************************************
333
// public entry point
334
************************************************************************/
335
336
LZO_PUBLIC(int)
337
DO_COMPRESS      ( const lzo_bytep in , lzo_uint  in_len,
338
                         lzo_bytep out, lzo_uintp out_len,
339
                         lzo_voidp wrkmem )
340
1.83k
{
341
1.83k
    const lzo_bytep ip = in;
342
1.83k
    lzo_bytep op = out;
343
1.83k
    lzo_uint l = in_len;
344
1.83k
    lzo_uint t = 0;
345
346
5.53k
    while (l > 20)
347
3.71k
    {
348
3.71k
        lzo_uint ll = l;
349
3.71k
        lzo_uintptr_t ll_end;
350
3.71k
#if 0 || (LZO_DETERMINISTIC)
351
3.71k
        ll = LZO_MIN(ll, 49152);
352
3.71k
#endif
353
3.71k
        ll_end = (lzo_uintptr_t)ip + ll;
354
3.71k
        if ((ll_end + ((t + ll) >> 5)) <= ll_end || (const lzo_bytep)(ll_end + ((t + ll) >> 5)) <= ip + ll)
355
18
            break;
356
3.69k
#if (LZO_DETERMINISTIC)
357
3.69k
        lzo_memset(wrkmem, 0, ((lzo_uint)1 << D_BITS) * sizeof(lzo_dict_t));
358
3.69k
#endif
359
3.69k
        t = do_compress(ip,ll,op,out_len,t,wrkmem);
360
3.69k
        ip += ll;
361
3.69k
        op += *out_len;
362
3.69k
        l  -= ll;
363
3.69k
    }
364
1.83k
    t += l;
365
366
1.83k
    if (t > 0)
367
1.83k
    {
368
1.83k
        const lzo_bytep ii = in + in_len - t;
369
370
1.83k
        if (op == out && t <= 238)
371
109
            *op++ = LZO_BYTE(17 + t);
372
1.72k
        else if (t <= 3)
373
0
            op[-2] = LZO_BYTE(op[-2] | t);
374
1.72k
        else if (t <= 18)
375
911
            *op++ = LZO_BYTE(t - 3);
376
810
        else
377
810
        {
378
810
            lzo_uint tt = t - 18;
379
380
810
            *op++ = 0;
381
115k
            while (tt > 255)
382
114k
            {
383
114k
                tt -= 255;
384
114k
                UA_SET1(op, 0);
385
114k
                op++;
386
114k
            }
387
810
            assert(tt > 0);
388
810
            *op++ = LZO_BYTE(tt);
389
810
        }
390
1.83k
        UA_COPYN(op, ii, t);
391
1.83k
        op += t;
392
1.83k
    }
393
394
1.83k
    *op++ = M4_MARKER | 1;
395
1.83k
    *op++ = 0;
396
1.83k
    *op++ = 0;
397
398
1.83k
    *out_len = pd(op, out);
399
1.83k
    return LZO_E_OK;
400
1.83k
}
lzo1x_1_compress
Line
Count
Source
340
351
{
341
351
    const lzo_bytep ip = in;
342
351
    lzo_bytep op = out;
343
351
    lzo_uint l = in_len;
344
351
    lzo_uint t = 0;
345
346
1.09k
    while (l > 20)
347
751
    {
348
751
        lzo_uint ll = l;
349
751
        lzo_uintptr_t ll_end;
350
751
#if 0 || (LZO_DETERMINISTIC)
351
751
        ll = LZO_MIN(ll, 49152);
352
751
#endif
353
751
        ll_end = (lzo_uintptr_t)ip + ll;
354
751
        if ((ll_end + ((t + ll) >> 5)) <= ll_end || (const lzo_bytep)(ll_end + ((t + ll) >> 5)) <= ip + ll)
355
3
            break;
356
748
#if (LZO_DETERMINISTIC)
357
748
        lzo_memset(wrkmem, 0, ((lzo_uint)1 << D_BITS) * sizeof(lzo_dict_t));
358
748
#endif
359
748
        t = do_compress(ip,ll,op,out_len,t,wrkmem);
360
748
        ip += ll;
361
748
        op += *out_len;
362
748
        l  -= ll;
363
748
    }
364
351
    t += l;
365
366
351
    if (t > 0)
367
350
    {
368
350
        const lzo_bytep ii = in + in_len - t;
369
370
350
        if (op == out && t <= 238)
371
21
            *op++ = LZO_BYTE(17 + t);
372
329
        else if (t <= 3)
373
0
            op[-2] = LZO_BYTE(op[-2] | t);
374
329
        else if (t <= 18)
375
195
            *op++ = LZO_BYTE(t - 3);
376
134
        else
377
134
        {
378
134
            lzo_uint tt = t - 18;
379
380
134
            *op++ = 0;
381
17.0k
            while (tt > 255)
382
16.8k
            {
383
16.8k
                tt -= 255;
384
16.8k
                UA_SET1(op, 0);
385
16.8k
                op++;
386
16.8k
            }
387
134
            assert(tt > 0);
388
134
            *op++ = LZO_BYTE(tt);
389
134
        }
390
350
        UA_COPYN(op, ii, t);
391
350
        op += t;
392
350
    }
393
394
351
    *op++ = M4_MARKER | 1;
395
351
    *op++ = 0;
396
351
    *op++ = 0;
397
398
351
    *out_len = pd(op, out);
399
351
    return LZO_E_OK;
400
351
}
lzo1x_1_11_compress
Line
Count
Source
340
348
{
341
348
    const lzo_bytep ip = in;
342
348
    lzo_bytep op = out;
343
348
    lzo_uint l = in_len;
344
348
    lzo_uint t = 0;
345
346
1.12k
    while (l > 20)
347
774
    {
348
774
        lzo_uint ll = l;
349
774
        lzo_uintptr_t ll_end;
350
774
#if 0 || (LZO_DETERMINISTIC)
351
774
        ll = LZO_MIN(ll, 49152);
352
774
#endif
353
774
        ll_end = (lzo_uintptr_t)ip + ll;
354
774
        if ((ll_end + ((t + ll) >> 5)) <= ll_end || (const lzo_bytep)(ll_end + ((t + ll) >> 5)) <= ip + ll)
355
2
            break;
356
772
#if (LZO_DETERMINISTIC)
357
772
        lzo_memset(wrkmem, 0, ((lzo_uint)1 << D_BITS) * sizeof(lzo_dict_t));
358
772
#endif
359
772
        t = do_compress(ip,ll,op,out_len,t,wrkmem);
360
772
        ip += ll;
361
772
        op += *out_len;
362
772
        l  -= ll;
363
772
    }
364
348
    t += l;
365
366
348
    if (t > 0)
367
347
    {
368
347
        const lzo_bytep ii = in + in_len - t;
369
370
347
        if (op == out && t <= 238)
371
19
            *op++ = LZO_BYTE(17 + t);
372
328
        else if (t <= 3)
373
0
            op[-2] = LZO_BYTE(op[-2] | t);
374
328
        else if (t <= 18)
375
171
            *op++ = LZO_BYTE(t - 3);
376
157
        else
377
157
        {
378
157
            lzo_uint tt = t - 18;
379
380
157
            *op++ = 0;
381
39.4k
            while (tt > 255)
382
39.3k
            {
383
39.3k
                tt -= 255;
384
39.3k
                UA_SET1(op, 0);
385
39.3k
                op++;
386
39.3k
            }
387
157
            assert(tt > 0);
388
157
            *op++ = LZO_BYTE(tt);
389
157
        }
390
347
        UA_COPYN(op, ii, t);
391
347
        op += t;
392
347
    }
393
394
348
    *op++ = M4_MARKER | 1;
395
348
    *op++ = 0;
396
348
    *op++ = 0;
397
398
348
    *out_len = pd(op, out);
399
348
    return LZO_E_OK;
400
348
}
lzo1x_1_12_compress
Line
Count
Source
340
384
{
341
384
    const lzo_bytep ip = in;
342
384
    lzo_bytep op = out;
343
384
    lzo_uint l = in_len;
344
384
    lzo_uint t = 0;
345
346
1.10k
    while (l > 20)
347
723
    {
348
723
        lzo_uint ll = l;
349
723
        lzo_uintptr_t ll_end;
350
723
#if 0 || (LZO_DETERMINISTIC)
351
723
        ll = LZO_MIN(ll, 49152);
352
723
#endif
353
723
        ll_end = (lzo_uintptr_t)ip + ll;
354
723
        if ((ll_end + ((t + ll) >> 5)) <= ll_end || (const lzo_bytep)(ll_end + ((t + ll) >> 5)) <= ip + ll)
355
6
            break;
356
717
#if (LZO_DETERMINISTIC)
357
717
        lzo_memset(wrkmem, 0, ((lzo_uint)1 << D_BITS) * sizeof(lzo_dict_t));
358
717
#endif
359
717
        t = do_compress(ip,ll,op,out_len,t,wrkmem);
360
717
        ip += ll;
361
717
        op += *out_len;
362
717
        l  -= ll;
363
717
    }
364
384
    t += l;
365
366
384
    if (t > 0)
367
383
    {
368
383
        const lzo_bytep ii = in + in_len - t;
369
370
383
        if (op == out && t <= 238)
371
22
            *op++ = LZO_BYTE(17 + t);
372
361
        else if (t <= 3)
373
0
            op[-2] = LZO_BYTE(op[-2] | t);
374
361
        else if (t <= 18)
375
190
            *op++ = LZO_BYTE(t - 3);
376
171
        else
377
171
        {
378
171
            lzo_uint tt = t - 18;
379
380
171
            *op++ = 0;
381
21.1k
            while (tt > 255)
382
21.0k
            {
383
21.0k
                tt -= 255;
384
21.0k
                UA_SET1(op, 0);
385
21.0k
                op++;
386
21.0k
            }
387
171
            assert(tt > 0);
388
171
            *op++ = LZO_BYTE(tt);
389
171
        }
390
383
        UA_COPYN(op, ii, t);
391
383
        op += t;
392
383
    }
393
394
384
    *op++ = M4_MARKER | 1;
395
384
    *op++ = 0;
396
384
    *op++ = 0;
397
398
384
    *out_len = pd(op, out);
399
384
    return LZO_E_OK;
400
384
}
lzo1x_1_15_compress
Line
Count
Source
340
349
{
341
349
    const lzo_bytep ip = in;
342
349
    lzo_bytep op = out;
343
349
    lzo_uint l = in_len;
344
349
    lzo_uint t = 0;
345
346
953
    while (l > 20)
347
609
    {
348
609
        lzo_uint ll = l;
349
609
        lzo_uintptr_t ll_end;
350
609
#if 0 || (LZO_DETERMINISTIC)
351
609
        ll = LZO_MIN(ll, 49152);
352
609
#endif
353
609
        ll_end = (lzo_uintptr_t)ip + ll;
354
609
        if ((ll_end + ((t + ll) >> 5)) <= ll_end || (const lzo_bytep)(ll_end + ((t + ll) >> 5)) <= ip + ll)
355
5
            break;
356
604
#if (LZO_DETERMINISTIC)
357
604
        lzo_memset(wrkmem, 0, ((lzo_uint)1 << D_BITS) * sizeof(lzo_dict_t));
358
604
#endif
359
604
        t = do_compress(ip,ll,op,out_len,t,wrkmem);
360
604
        ip += ll;
361
604
        op += *out_len;
362
604
        l  -= ll;
363
604
    }
364
349
    t += l;
365
366
349
    if (t > 0)
367
348
    {
368
348
        const lzo_bytep ii = in + in_len - t;
369
370
348
        if (op == out && t <= 238)
371
29
            *op++ = LZO_BYTE(17 + t);
372
319
        else if (t <= 3)
373
0
            op[-2] = LZO_BYTE(op[-2] | t);
374
319
        else if (t <= 18)
375
159
            *op++ = LZO_BYTE(t - 3);
376
160
        else
377
160
        {
378
160
            lzo_uint tt = t - 18;
379
380
160
            *op++ = 0;
381
10.2k
            while (tt > 255)
382
10.1k
            {
383
10.1k
                tt -= 255;
384
10.1k
                UA_SET1(op, 0);
385
10.1k
                op++;
386
10.1k
            }
387
160
            assert(tt > 0);
388
160
            *op++ = LZO_BYTE(tt);
389
160
        }
390
348
        UA_COPYN(op, ii, t);
391
348
        op += t;
392
348
    }
393
394
349
    *op++ = M4_MARKER | 1;
395
349
    *op++ = 0;
396
349
    *op++ = 0;
397
398
349
    *out_len = pd(op, out);
399
349
    return LZO_E_OK;
400
349
}
lzo1y_1_compress
Line
Count
Source
340
403
{
341
403
    const lzo_bytep ip = in;
342
403
    lzo_bytep op = out;
343
403
    lzo_uint l = in_len;
344
403
    lzo_uint t = 0;
345
346
1.25k
    while (l > 20)
347
857
    {
348
857
        lzo_uint ll = l;
349
857
        lzo_uintptr_t ll_end;
350
857
#if 0 || (LZO_DETERMINISTIC)
351
857
        ll = LZO_MIN(ll, 49152);
352
857
#endif
353
857
        ll_end = (lzo_uintptr_t)ip + ll;
354
857
        if ((ll_end + ((t + ll) >> 5)) <= ll_end || (const lzo_bytep)(ll_end + ((t + ll) >> 5)) <= ip + ll)
355
2
            break;
356
855
#if (LZO_DETERMINISTIC)
357
855
        lzo_memset(wrkmem, 0, ((lzo_uint)1 << D_BITS) * sizeof(lzo_dict_t));
358
855
#endif
359
855
        t = do_compress(ip,ll,op,out_len,t,wrkmem);
360
855
        ip += ll;
361
855
        op += *out_len;
362
855
        l  -= ll;
363
855
    }
364
403
    t += l;
365
366
403
    if (t > 0)
367
402
    {
368
402
        const lzo_bytep ii = in + in_len - t;
369
370
402
        if (op == out && t <= 238)
371
18
            *op++ = LZO_BYTE(17 + t);
372
384
        else if (t <= 3)
373
0
            op[-2] = LZO_BYTE(op[-2] | t);
374
384
        else if (t <= 18)
375
196
            *op++ = LZO_BYTE(t - 3);
376
188
        else
377
188
        {
378
188
            lzo_uint tt = t - 18;
379
380
188
            *op++ = 0;
381
27.1k
            while (tt > 255)
382
26.9k
            {
383
26.9k
                tt -= 255;
384
26.9k
                UA_SET1(op, 0);
385
26.9k
                op++;
386
26.9k
            }
387
188
            assert(tt > 0);
388
188
            *op++ = LZO_BYTE(tt);
389
188
        }
390
402
        UA_COPYN(op, ii, t);
391
402
        op += t;
392
402
    }
393
394
403
    *op++ = M4_MARKER | 1;
395
403
    *op++ = 0;
396
403
    *op++ = 0;
397
398
403
    *out_len = pd(op, out);
399
403
    return LZO_E_OK;
400
403
}
401
402
403
/* vim:set ts=4 sw=4 et: */