Coverage Report

Created: 2026-04-29 06:48

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
7.08k
#  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
7.08k
{
45
7.08k
    const lzo_bytep ip;
46
7.08k
    lzo_bytep op;
47
7.08k
    const lzo_bytep const in_end = in + in_len;
48
7.08k
    const lzo_bytep const ip_end = in + in_len - 20;
49
7.08k
    const lzo_bytep ii;
50
7.08k
    lzo_dict_p const dict = (lzo_dict_p) wrkmem;
51
52
7.08k
    op = out;
53
7.08k
    ip = in;
54
7.08k
    ii = ip;
55
56
7.08k
    ip += ti < 4 ? 4 - ti : 0;
57
7.08k
    for (;;)
58
7.08k
    {
59
7.08k
        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
7.08k
        lzo_uint m_off;
100
7.08k
        lzo_uint m_len;
101
7.08k
        {
102
7.08k
        lzo_uint32_t dv;
103
7.08k
        lzo_uint dindex;
104
4.72M
literal:
105
4.72M
        ip += 1 + ((ip - ii) >> 5);
106
5.48M
next:
107
5.48M
        if __lzo_unlikely(ip >= ip_end)
108
7.08k
            break;
109
5.47M
        dv = UA_GET_LE32(ip);
110
5.47M
        dindex = DINDEX(dv,ip);
111
5.47M
        GINDEX(m_off,m_pos,in+dict,dindex,in);
112
5.47M
        UPDATE_I(dict,0,dindex,ip,in);
113
5.47M
        if __lzo_unlikely(dv != UA_GET_LE32(m_pos))
114
4.71M
            goto literal;
115
5.47M
        }
116
760k
#endif
117
118
    /* a match */
119
120
760k
        ii -= ti; ti = 0;
121
760k
        {
122
760k
        lzo_uint t = pd(ip,ii);
123
760k
        if (t != 0)
124
377k
        {
125
377k
            if (t <= 3)
126
197k
            {
127
197k
                op[-2] = LZO_BYTE(op[-2] | t);
128
197k
#if (LZO_OPT_UNALIGNED32)
129
197k
                UA_COPY4(op, ii);
130
197k
                op += t;
131
#else
132
                { do *op++ = *ii++; while (--t > 0); }
133
#endif
134
197k
            }
135
180k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
136
180k
            else if (t <= 16)
137
123k
            {
138
123k
                *op++ = LZO_BYTE(t - 3);
139
123k
                UA_COPY8(op, ii);
140
123k
                UA_COPY8(op+8, ii+8);
141
123k
                op += t;
142
123k
            }
143
56.8k
#endif
144
56.8k
            else
145
56.8k
            {
146
56.8k
                if (t <= 18)
147
6.59k
                    *op++ = LZO_BYTE(t - 3);
148
50.2k
                else
149
50.2k
                {
150
50.2k
                    lzo_uint tt = t - 18;
151
50.2k
                    *op++ = 0;
152
302k
                    while __lzo_unlikely(tt > 255)
153
252k
                    {
154
252k
                        tt -= 255;
155
252k
                        UA_SET1(op, 0);
156
252k
                        op++;
157
252k
                    }
158
50.2k
                    assert(tt > 0);
159
50.2k
                    *op++ = LZO_BYTE(tt);
160
50.2k
                }
161
56.8k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
162
4.21M
                do {
163
4.21M
                    UA_COPY8(op, ii);
164
4.21M
                    UA_COPY8(op+8, ii+8);
165
4.21M
                    op += 16; ii += 16; t -= 16;
166
4.21M
                } while (t >= 16); if (t > 0)
167
52.3k
#endif
168
353k
                { do *op++ = *ii++; while (--t > 0); }
169
56.8k
            }
170
377k
        }
171
760k
        }
172
760k
        m_len = 4;
173
760k
        {
174
760k
#if (LZO_OPT_UNALIGNED64)
175
760k
        lzo_uint64_t v;
176
760k
        v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
177
760k
        if __lzo_unlikely(v == 0) {
178
5.72M
            do {
179
5.72M
                m_len += 8;
180
5.72M
                v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
181
5.72M
                if __lzo_unlikely(ip + m_len >= ip_end)
182
1.31k
                    goto m_len_done;
183
5.72M
            } while (v == 0);
184
186k
        }
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
759k
        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
759k
        }
269
760k
m_len_done:
270
760k
        m_off = pd(ip,m_pos);
271
760k
        ip += m_len;
272
760k
        ii = ip;
273
760k
        if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
274
394k
        {
275
394k
            m_off -= 1;
276
#if defined(LZO1X)
277
332k
            *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2));
278
332k
            *op++ = LZO_BYTE(m_off >> 3);
279
#elif defined(LZO1Y)
280
61.5k
            *op++ = LZO_BYTE(((m_len + 1) << 4) | ((m_off & 3) << 2));
281
61.5k
            *op++ = LZO_BYTE(m_off >> 2);
282
#endif
283
394k
        }
284
366k
        else if (m_off <= M3_MAX_OFFSET)
285
319k
        {
286
319k
            m_off -= 1;
287
319k
            if (m_len <= M3_MAX_LEN)
288
239k
                *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
289
80.0k
            else
290
80.0k
            {
291
80.0k
                m_len -= M3_MAX_LEN;
292
80.0k
                *op++ = M3_MARKER | 0;
293
200k
                while __lzo_unlikely(m_len > 255)
294
120k
                {
295
120k
                    m_len -= 255;
296
120k
                    UA_SET1(op, 0);
297
120k
                    op++;
298
120k
                }
299
80.0k
                *op++ = LZO_BYTE(m_len);
300
80.0k
            }
301
319k
            *op++ = LZO_BYTE(m_off << 2);
302
319k
            *op++ = LZO_BYTE(m_off >> 6);
303
319k
        }
304
46.5k
        else
305
46.5k
        {
306
46.5k
            m_off -= 0x4000;
307
46.5k
            if (m_len <= M4_MAX_LEN)
308
27.3k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8) | (m_len - 2));
309
19.1k
            else
310
19.1k
            {
311
19.1k
                m_len -= M4_MAX_LEN;
312
19.1k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8));
313
43.1k
                while __lzo_unlikely(m_len > 255)
314
23.9k
                {
315
23.9k
                    m_len -= 255;
316
23.9k
                    UA_SET1(op, 0);
317
23.9k
                    op++;
318
23.9k
                }
319
19.1k
                *op++ = LZO_BYTE(m_len);
320
19.1k
            }
321
46.5k
            *op++ = LZO_BYTE(m_off << 2);
322
46.5k
            *op++ = LZO_BYTE(m_off >> 6);
323
46.5k
        }
324
760k
        goto next;
325
759k
    }
326
327
7.08k
    *out_len = pd(op, out);
328
7.08k
    return pd(in_end,ii-ti);
329
7.08k
}
lzo1x_1.c:lzo1x_1_compress_core
Line
Count
Source
44
3.28k
{
45
3.28k
    const lzo_bytep ip;
46
3.28k
    lzo_bytep op;
47
3.28k
    const lzo_bytep const in_end = in + in_len;
48
3.28k
    const lzo_bytep const ip_end = in + in_len - 20;
49
3.28k
    const lzo_bytep ii;
50
3.28k
    lzo_dict_p const dict = (lzo_dict_p) wrkmem;
51
52
3.28k
    op = out;
53
3.28k
    ip = in;
54
3.28k
    ii = ip;
55
56
3.28k
    ip += ti < 4 ? 4 - ti : 0;
57
3.28k
    for (;;)
58
3.28k
    {
59
3.28k
        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.28k
        lzo_uint m_off;
100
3.28k
        lzo_uint m_len;
101
3.28k
        {
102
3.28k
        lzo_uint32_t dv;
103
3.28k
        lzo_uint dindex;
104
2.27M
literal:
105
2.27M
        ip += 1 + ((ip - ii) >> 5);
106
2.60M
next:
107
2.60M
        if __lzo_unlikely(ip >= ip_end)
108
3.28k
            break;
109
2.60M
        dv = UA_GET_LE32(ip);
110
2.60M
        dindex = DINDEX(dv,ip);
111
2.60M
        GINDEX(m_off,m_pos,in+dict,dindex,in);
112
2.60M
        UPDATE_I(dict,0,dindex,ip,in);
113
2.60M
        if __lzo_unlikely(dv != UA_GET_LE32(m_pos))
114
2.27M
            goto literal;
115
2.60M
        }
116
329k
#endif
117
118
    /* a match */
119
120
329k
        ii -= ti; ti = 0;
121
329k
        {
122
329k
        lzo_uint t = pd(ip,ii);
123
329k
        if (t != 0)
124
175k
        {
125
175k
            if (t <= 3)
126
89.3k
            {
127
89.3k
                op[-2] = LZO_BYTE(op[-2] | t);
128
89.3k
#if (LZO_OPT_UNALIGNED32)
129
89.3k
                UA_COPY4(op, ii);
130
89.3k
                op += t;
131
#else
132
                { do *op++ = *ii++; while (--t > 0); }
133
#endif
134
89.3k
            }
135
85.7k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
136
85.7k
            else if (t <= 16)
137
58.8k
            {
138
58.8k
                *op++ = LZO_BYTE(t - 3);
139
58.8k
                UA_COPY8(op, ii);
140
58.8k
                UA_COPY8(op+8, ii+8);
141
58.8k
                op += t;
142
58.8k
            }
143
26.8k
#endif
144
26.8k
            else
145
26.8k
            {
146
26.8k
                if (t <= 18)
147
3.67k
                    *op++ = LZO_BYTE(t - 3);
148
23.1k
                else
149
23.1k
                {
150
23.1k
                    lzo_uint tt = t - 18;
151
23.1k
                    *op++ = 0;
152
158k
                    while __lzo_unlikely(tt > 255)
153
135k
                    {
154
135k
                        tt -= 255;
155
135k
                        UA_SET1(op, 0);
156
135k
                        op++;
157
135k
                    }
158
23.1k
                    assert(tt > 0);
159
23.1k
                    *op++ = LZO_BYTE(tt);
160
23.1k
                }
161
26.8k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
162
2.24M
                do {
163
2.24M
                    UA_COPY8(op, ii);
164
2.24M
                    UA_COPY8(op+8, ii+8);
165
2.24M
                    op += 16; ii += 16; t -= 16;
166
2.24M
                } while (t >= 16); if (t > 0)
167
24.8k
#endif
168
164k
                { do *op++ = *ii++; while (--t > 0); }
169
26.8k
            }
170
175k
        }
171
329k
        }
172
329k
        m_len = 4;
173
329k
        {
174
329k
#if (LZO_OPT_UNALIGNED64)
175
329k
        lzo_uint64_t v;
176
329k
        v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
177
329k
        if __lzo_unlikely(v == 0) {
178
1.96M
            do {
179
1.96M
                m_len += 8;
180
1.96M
                v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
181
1.96M
                if __lzo_unlikely(ip + m_len >= ip_end)
182
493
                    goto m_len_done;
183
1.96M
            } while (v == 0);
184
89.3k
        }
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
329k
        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
329k
        }
269
329k
m_len_done:
270
329k
        m_off = pd(ip,m_pos);
271
329k
        ip += m_len;
272
329k
        ii = ip;
273
329k
        if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
274
145k
        {
275
145k
            m_off -= 1;
276
145k
#if defined(LZO1X)
277
145k
            *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2));
278
145k
            *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
145k
        }
284
183k
        else if (m_off <= M3_MAX_OFFSET)
285
157k
        {
286
157k
            m_off -= 1;
287
157k
            if (m_len <= M3_MAX_LEN)
288
120k
                *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
289
37.3k
            else
290
37.3k
            {
291
37.3k
                m_len -= M3_MAX_LEN;
292
37.3k
                *op++ = M3_MARKER | 0;
293
71.8k
                while __lzo_unlikely(m_len > 255)
294
34.4k
                {
295
34.4k
                    m_len -= 255;
296
34.4k
                    UA_SET1(op, 0);
297
34.4k
                    op++;
298
34.4k
                }
299
37.3k
                *op++ = LZO_BYTE(m_len);
300
37.3k
            }
301
157k
            *op++ = LZO_BYTE(m_off << 2);
302
157k
            *op++ = LZO_BYTE(m_off >> 6);
303
157k
        }
304
26.3k
        else
305
26.3k
        {
306
26.3k
            m_off -= 0x4000;
307
26.3k
            if (m_len <= M4_MAX_LEN)
308
15.9k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8) | (m_len - 2));
309
10.3k
            else
310
10.3k
            {
311
10.3k
                m_len -= M4_MAX_LEN;
312
10.3k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8));
313
20.1k
                while __lzo_unlikely(m_len > 255)
314
9.75k
                {
315
9.75k
                    m_len -= 255;
316
9.75k
                    UA_SET1(op, 0);
317
9.75k
                    op++;
318
9.75k
                }
319
10.3k
                *op++ = LZO_BYTE(m_len);
320
10.3k
            }
321
26.3k
            *op++ = LZO_BYTE(m_off << 2);
322
26.3k
            *op++ = LZO_BYTE(m_off >> 6);
323
26.3k
        }
324
329k
        goto next;
325
329k
    }
326
327
3.28k
    *out_len = pd(op, out);
328
3.28k
    return pd(in_end,ii-ti);
329
3.28k
}
lzo1x_1k.c:lzo1x_1_11_compress_core
Line
Count
Source
44
872
{
45
872
    const lzo_bytep ip;
46
872
    lzo_bytep op;
47
872
    const lzo_bytep const in_end = in + in_len;
48
872
    const lzo_bytep const ip_end = in + in_len - 20;
49
872
    const lzo_bytep ii;
50
872
    lzo_dict_p const dict = (lzo_dict_p) wrkmem;
51
52
872
    op = out;
53
872
    ip = in;
54
872
    ii = ip;
55
56
872
    ip += ti < 4 ? 4 - ti : 0;
57
872
    for (;;)
58
872
    {
59
872
        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
872
        lzo_uint m_off;
100
872
        lzo_uint m_len;
101
872
        {
102
872
        lzo_uint32_t dv;
103
872
        lzo_uint dindex;
104
506k
literal:
105
506k
        ip += 1 + ((ip - ii) >> 5);
106
583k
next:
107
583k
        if __lzo_unlikely(ip >= ip_end)
108
872
            break;
109
583k
        dv = UA_GET_LE32(ip);
110
583k
        dindex = DINDEX(dv,ip);
111
583k
        GINDEX(m_off,m_pos,in+dict,dindex,in);
112
583k
        UPDATE_I(dict,0,dindex,ip,in);
113
583k
        if __lzo_unlikely(dv != UA_GET_LE32(m_pos))
114
505k
            goto literal;
115
583k
        }
116
77.1k
#endif
117
118
    /* a match */
119
120
77.1k
        ii -= ti; ti = 0;
121
77.1k
        {
122
77.1k
        lzo_uint t = pd(ip,ii);
123
77.1k
        if (t != 0)
124
39.2k
        {
125
39.2k
            if (t <= 3)
126
19.7k
            {
127
19.7k
                op[-2] = LZO_BYTE(op[-2] | t);
128
19.7k
#if (LZO_OPT_UNALIGNED32)
129
19.7k
                UA_COPY4(op, ii);
130
19.7k
                op += t;
131
#else
132
                { do *op++ = *ii++; while (--t > 0); }
133
#endif
134
19.7k
            }
135
19.4k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
136
19.4k
            else if (t <= 16)
137
13.1k
            {
138
13.1k
                *op++ = LZO_BYTE(t - 3);
139
13.1k
                UA_COPY8(op, ii);
140
13.1k
                UA_COPY8(op+8, ii+8);
141
13.1k
                op += t;
142
13.1k
            }
143
6.28k
#endif
144
6.28k
            else
145
6.28k
            {
146
6.28k
                if (t <= 18)
147
679
                    *op++ = LZO_BYTE(t - 3);
148
5.60k
                else
149
5.60k
                {
150
5.60k
                    lzo_uint tt = t - 18;
151
5.60k
                    *op++ = 0;
152
33.0k
                    while __lzo_unlikely(tt > 255)
153
27.4k
                    {
154
27.4k
                        tt -= 255;
155
27.4k
                        UA_SET1(op, 0);
156
27.4k
                        op++;
157
27.4k
                    }
158
5.60k
                    assert(tt > 0);
159
5.60k
                    *op++ = LZO_BYTE(tt);
160
5.60k
                }
161
6.28k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
162
459k
                do {
163
459k
                    UA_COPY8(op, ii);
164
459k
                    UA_COPY8(op+8, ii+8);
165
459k
                    op += 16; ii += 16; t -= 16;
166
459k
                } while (t >= 16); if (t > 0)
167
5.75k
#endif
168
39.3k
                { do *op++ = *ii++; while (--t > 0); }
169
6.28k
            }
170
39.2k
        }
171
77.1k
        }
172
77.1k
        m_len = 4;
173
77.1k
        {
174
77.1k
#if (LZO_OPT_UNALIGNED64)
175
77.1k
        lzo_uint64_t v;
176
77.1k
        v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
177
77.1k
        if __lzo_unlikely(v == 0) {
178
1.11M
            do {
179
1.11M
                m_len += 8;
180
1.11M
                v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
181
1.11M
                if __lzo_unlikely(ip + m_len >= ip_end)
182
216
                    goto m_len_done;
183
1.11M
            } while (v == 0);
184
22.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
76.9k
        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
76.9k
        }
269
77.1k
m_len_done:
270
77.1k
        m_off = pd(ip,m_pos);
271
77.1k
        ip += m_len;
272
77.1k
        ii = ip;
273
77.1k
        if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
274
41.7k
        {
275
41.7k
            m_off -= 1;
276
41.7k
#if defined(LZO1X)
277
41.7k
            *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2));
278
41.7k
            *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
41.7k
        }
284
35.3k
        else if (m_off <= M3_MAX_OFFSET)
285
32.5k
        {
286
32.5k
            m_off -= 1;
287
32.5k
            if (m_len <= M3_MAX_LEN)
288
21.2k
                *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
289
11.3k
            else
290
11.3k
            {
291
11.3k
                m_len -= M3_MAX_LEN;
292
11.3k
                *op++ = M3_MARKER | 0;
293
37.9k
                while __lzo_unlikely(m_len > 255)
294
26.5k
                {
295
26.5k
                    m_len -= 255;
296
26.5k
                    UA_SET1(op, 0);
297
26.5k
                    op++;
298
26.5k
                }
299
11.3k
                *op++ = LZO_BYTE(m_len);
300
11.3k
            }
301
32.5k
            *op++ = LZO_BYTE(m_off << 2);
302
32.5k
            *op++ = LZO_BYTE(m_off >> 6);
303
32.5k
        }
304
2.79k
        else
305
2.79k
        {
306
2.79k
            m_off -= 0x4000;
307
2.79k
            if (m_len <= M4_MAX_LEN)
308
1.01k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8) | (m_len - 2));
309
1.78k
            else
310
1.78k
            {
311
1.78k
                m_len -= M4_MAX_LEN;
312
1.78k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8));
313
5.17k
                while __lzo_unlikely(m_len > 255)
314
3.39k
                {
315
3.39k
                    m_len -= 255;
316
3.39k
                    UA_SET1(op, 0);
317
3.39k
                    op++;
318
3.39k
                }
319
1.78k
                *op++ = LZO_BYTE(m_len);
320
1.78k
            }
321
2.79k
            *op++ = LZO_BYTE(m_off << 2);
322
2.79k
            *op++ = LZO_BYTE(m_off >> 6);
323
2.79k
        }
324
77.1k
        goto next;
325
76.9k
    }
326
327
872
    *out_len = pd(op, out);
328
872
    return pd(in_end,ii-ti);
329
872
}
lzo1x_1l.c:lzo1x_1_12_compress_core
Line
Count
Source
44
987
{
45
987
    const lzo_bytep ip;
46
987
    lzo_bytep op;
47
987
    const lzo_bytep const in_end = in + in_len;
48
987
    const lzo_bytep const ip_end = in + in_len - 20;
49
987
    const lzo_bytep ii;
50
987
    lzo_dict_p const dict = (lzo_dict_p) wrkmem;
51
52
987
    op = out;
53
987
    ip = in;
54
987
    ii = ip;
55
56
987
    ip += ti < 4 ? 4 - ti : 0;
57
987
    for (;;)
58
987
    {
59
987
        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
987
        lzo_uint m_off;
100
987
        lzo_uint m_len;
101
987
        {
102
987
        lzo_uint32_t dv;
103
987
        lzo_uint dindex;
104
627k
literal:
105
627k
        ip += 1 + ((ip - ii) >> 5);
106
735k
next:
107
735k
        if __lzo_unlikely(ip >= ip_end)
108
987
            break;
109
734k
        dv = UA_GET_LE32(ip);
110
734k
        dindex = DINDEX(dv,ip);
111
734k
        GINDEX(m_off,m_pos,in+dict,dindex,in);
112
734k
        UPDATE_I(dict,0,dindex,ip,in);
113
734k
        if __lzo_unlikely(dv != UA_GET_LE32(m_pos))
114
626k
            goto literal;
115
734k
        }
116
108k
#endif
117
118
    /* a match */
119
120
108k
        ii -= ti; ti = 0;
121
108k
        {
122
108k
        lzo_uint t = pd(ip,ii);
123
108k
        if (t != 0)
124
51.1k
        {
125
51.1k
            if (t <= 3)
126
26.8k
            {
127
26.8k
                op[-2] = LZO_BYTE(op[-2] | t);
128
26.8k
#if (LZO_OPT_UNALIGNED32)
129
26.8k
                UA_COPY4(op, ii);
130
26.8k
                op += t;
131
#else
132
                { do *op++ = *ii++; while (--t > 0); }
133
#endif
134
26.8k
            }
135
24.2k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
136
24.2k
            else if (t <= 16)
137
16.5k
            {
138
16.5k
                *op++ = LZO_BYTE(t - 3);
139
16.5k
                UA_COPY8(op, ii);
140
16.5k
                UA_COPY8(op+8, ii+8);
141
16.5k
                op += t;
142
16.5k
            }
143
7.76k
#endif
144
7.76k
            else
145
7.76k
            {
146
7.76k
                if (t <= 18)
147
756
                    *op++ = LZO_BYTE(t - 3);
148
7.00k
                else
149
7.00k
                {
150
7.00k
                    lzo_uint tt = t - 18;
151
7.00k
                    *op++ = 0;
152
34.3k
                    while __lzo_unlikely(tt > 255)
153
27.3k
                    {
154
27.3k
                        tt -= 255;
155
27.3k
                        UA_SET1(op, 0);
156
27.3k
                        op++;
157
27.3k
                    }
158
7.00k
                    assert(tt > 0);
159
7.00k
                    *op++ = LZO_BYTE(tt);
160
7.00k
                }
161
7.76k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
162
460k
                do {
163
460k
                    UA_COPY8(op, ii);
164
460k
                    UA_COPY8(op+8, ii+8);
165
460k
                    op += 16; ii += 16; t -= 16;
166
460k
                } while (t >= 16); if (t > 0)
167
7.11k
#endif
168
48.7k
                { do *op++ = *ii++; while (--t > 0); }
169
7.76k
            }
170
51.1k
        }
171
108k
        }
172
108k
        m_len = 4;
173
108k
        {
174
108k
#if (LZO_OPT_UNALIGNED64)
175
108k
        lzo_uint64_t v;
176
108k
        v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
177
108k
        if __lzo_unlikely(v == 0) {
178
548k
            do {
179
548k
                m_len += 8;
180
548k
                v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
181
548k
                if __lzo_unlikely(ip + m_len >= ip_end)
182
140
                    goto m_len_done;
183
548k
            } while (v == 0);
184
26.4k
        }
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
107k
        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
107k
        }
269
108k
m_len_done:
270
108k
        m_off = pd(ip,m_pos);
271
108k
        ip += m_len;
272
108k
        ii = ip;
273
108k
        if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
274
62.8k
        {
275
62.8k
            m_off -= 1;
276
62.8k
#if defined(LZO1X)
277
62.8k
            *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2));
278
62.8k
            *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
62.8k
        }
284
45.2k
        else if (m_off <= M3_MAX_OFFSET)
285
40.7k
        {
286
40.7k
            m_off -= 1;
287
40.7k
            if (m_len <= M3_MAX_LEN)
288
30.1k
                *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
289
10.5k
            else
290
10.5k
            {
291
10.5k
                m_len -= M3_MAX_LEN;
292
10.5k
                *op++ = M3_MARKER | 0;
293
20.3k
                while __lzo_unlikely(m_len > 255)
294
9.84k
                {
295
9.84k
                    m_len -= 255;
296
9.84k
                    UA_SET1(op, 0);
297
9.84k
                    op++;
298
9.84k
                }
299
10.5k
                *op++ = LZO_BYTE(m_len);
300
10.5k
            }
301
40.7k
            *op++ = LZO_BYTE(m_off << 2);
302
40.7k
            *op++ = LZO_BYTE(m_off >> 6);
303
40.7k
        }
304
4.50k
        else
305
4.50k
        {
306
4.50k
            m_off -= 0x4000;
307
4.50k
            if (m_len <= M4_MAX_LEN)
308
2.39k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8) | (m_len - 2));
309
2.11k
            else
310
2.11k
            {
311
2.11k
                m_len -= M4_MAX_LEN;
312
2.11k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8));
313
4.97k
                while __lzo_unlikely(m_len > 255)
314
2.86k
                {
315
2.86k
                    m_len -= 255;
316
2.86k
                    UA_SET1(op, 0);
317
2.86k
                    op++;
318
2.86k
                }
319
2.11k
                *op++ = LZO_BYTE(m_len);
320
2.11k
            }
321
4.50k
            *op++ = LZO_BYTE(m_off << 2);
322
4.50k
            *op++ = LZO_BYTE(m_off >> 6);
323
4.50k
        }
324
108k
        goto next;
325
107k
    }
326
327
987
    *out_len = pd(op, out);
328
987
    return pd(in_end,ii-ti);
329
987
}
lzo1x_1o.c:lzo1x_1_15_compress_core
Line
Count
Source
44
1.03k
{
45
1.03k
    const lzo_bytep ip;
46
1.03k
    lzo_bytep op;
47
1.03k
    const lzo_bytep const in_end = in + in_len;
48
1.03k
    const lzo_bytep const ip_end = in + in_len - 20;
49
1.03k
    const lzo_bytep ii;
50
1.03k
    lzo_dict_p const dict = (lzo_dict_p) wrkmem;
51
52
1.03k
    op = out;
53
1.03k
    ip = in;
54
1.03k
    ii = ip;
55
56
1.03k
    ip += ti < 4 ? 4 - ti : 0;
57
1.03k
    for (;;)
58
1.03k
    {
59
1.03k
        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
1.03k
        lzo_uint m_off;
100
1.03k
        lzo_uint m_len;
101
1.03k
        {
102
1.03k
        lzo_uint32_t dv;
103
1.03k
        lzo_uint dindex;
104
644k
literal:
105
644k
        ip += 1 + ((ip - ii) >> 5);
106
775k
next:
107
775k
        if __lzo_unlikely(ip >= ip_end)
108
1.03k
            break;
109
774k
        dv = UA_GET_LE32(ip);
110
774k
        dindex = DINDEX(dv,ip);
111
774k
        GINDEX(m_off,m_pos,in+dict,dindex,in);
112
774k
        UPDATE_I(dict,0,dindex,ip,in);
113
774k
        if __lzo_unlikely(dv != UA_GET_LE32(m_pos))
114
643k
            goto literal;
115
774k
        }
116
130k
#endif
117
118
    /* a match */
119
120
130k
        ii -= ti; ti = 0;
121
130k
        {
122
130k
        lzo_uint t = pd(ip,ii);
123
130k
        if (t != 0)
124
56.7k
        {
125
56.7k
            if (t <= 3)
126
32.3k
            {
127
32.3k
                op[-2] = LZO_BYTE(op[-2] | t);
128
32.3k
#if (LZO_OPT_UNALIGNED32)
129
32.3k
                UA_COPY4(op, ii);
130
32.3k
                op += t;
131
#else
132
                { do *op++ = *ii++; while (--t > 0); }
133
#endif
134
32.3k
            }
135
24.4k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
136
24.4k
            else if (t <= 16)
137
17.3k
            {
138
17.3k
                *op++ = LZO_BYTE(t - 3);
139
17.3k
                UA_COPY8(op, ii);
140
17.3k
                UA_COPY8(op+8, ii+8);
141
17.3k
                op += t;
142
17.3k
            }
143
7.07k
#endif
144
7.07k
            else
145
7.07k
            {
146
7.07k
                if (t <= 18)
147
685
                    *op++ = LZO_BYTE(t - 3);
148
6.38k
                else
149
6.38k
                {
150
6.38k
                    lzo_uint tt = t - 18;
151
6.38k
                    *op++ = 0;
152
43.0k
                    while __lzo_unlikely(tt > 255)
153
36.6k
                    {
154
36.6k
                        tt -= 255;
155
36.6k
                        UA_SET1(op, 0);
156
36.6k
                        op++;
157
36.6k
                    }
158
6.38k
                    assert(tt > 0);
159
6.38k
                    *op++ = LZO_BYTE(tt);
160
6.38k
                }
161
7.07k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
162
610k
                do {
163
610k
                    UA_COPY8(op, ii);
164
610k
                    UA_COPY8(op+8, ii+8);
165
610k
                    op += 16; ii += 16; t -= 16;
166
610k
                } while (t >= 16); if (t > 0)
167
6.51k
#endif
168
45.1k
                { do *op++ = *ii++; while (--t > 0); }
169
7.07k
            }
170
56.7k
        }
171
130k
        }
172
130k
        m_len = 4;
173
130k
        {
174
130k
#if (LZO_OPT_UNALIGNED64)
175
130k
        lzo_uint64_t v;
176
130k
        v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
177
130k
        if __lzo_unlikely(v == 0) {
178
906k
            do {
179
906k
                m_len += 8;
180
906k
                v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
181
906k
                if __lzo_unlikely(ip + m_len >= ip_end)
182
211
                    goto m_len_done;
183
906k
            } while (v == 0);
184
19.2k
        }
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
129k
        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
129k
        }
269
130k
m_len_done:
270
130k
        m_off = pd(ip,m_pos);
271
130k
        ip += m_len;
272
130k
        ii = ip;
273
130k
        if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
274
82.0k
        {
275
82.0k
            m_off -= 1;
276
82.0k
#if defined(LZO1X)
277
82.0k
            *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2));
278
82.0k
            *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
82.0k
        }
284
48.0k
        else if (m_off <= M3_MAX_OFFSET)
285
42.1k
        {
286
42.1k
            m_off -= 1;
287
42.1k
            if (m_len <= M3_MAX_LEN)
288
33.6k
                *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
289
8.56k
            else
290
8.56k
            {
291
8.56k
                m_len -= M3_MAX_LEN;
292
8.56k
                *op++ = M3_MARKER | 0;
293
30.1k
                while __lzo_unlikely(m_len > 255)
294
21.6k
                {
295
21.6k
                    m_len -= 255;
296
21.6k
                    UA_SET1(op, 0);
297
21.6k
                    op++;
298
21.6k
                }
299
8.56k
                *op++ = LZO_BYTE(m_len);
300
8.56k
            }
301
42.1k
            *op++ = LZO_BYTE(m_off << 2);
302
42.1k
            *op++ = LZO_BYTE(m_off >> 6);
303
42.1k
        }
304
5.86k
        else
305
5.86k
        {
306
5.86k
            m_off -= 0x4000;
307
5.86k
            if (m_len <= M4_MAX_LEN)
308
3.97k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8) | (m_len - 2));
309
1.88k
            else
310
1.88k
            {
311
1.88k
                m_len -= M4_MAX_LEN;
312
1.88k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8));
313
4.99k
                while __lzo_unlikely(m_len > 255)
314
3.10k
                {
315
3.10k
                    m_len -= 255;
316
3.10k
                    UA_SET1(op, 0);
317
3.10k
                    op++;
318
3.10k
                }
319
1.88k
                *op++ = LZO_BYTE(m_len);
320
1.88k
            }
321
5.86k
            *op++ = LZO_BYTE(m_off << 2);
322
5.86k
            *op++ = LZO_BYTE(m_off >> 6);
323
5.86k
        }
324
130k
        goto next;
325
129k
    }
326
327
1.03k
    *out_len = pd(op, out);
328
1.03k
    return pd(in_end,ii-ti);
329
1.03k
}
lzo1y_1.c:lzo1y_1_compress_core
Line
Count
Source
44
896
{
45
896
    const lzo_bytep ip;
46
896
    lzo_bytep op;
47
896
    const lzo_bytep const in_end = in + in_len;
48
896
    const lzo_bytep const ip_end = in + in_len - 20;
49
896
    const lzo_bytep ii;
50
896
    lzo_dict_p const dict = (lzo_dict_p) wrkmem;
51
52
896
    op = out;
53
896
    ip = in;
54
896
    ii = ip;
55
56
896
    ip += ti < 4 ? 4 - ti : 0;
57
896
    for (;;)
58
896
    {
59
896
        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
896
        lzo_uint m_off;
100
896
        lzo_uint m_len;
101
896
        {
102
896
        lzo_uint32_t dv;
103
896
        lzo_uint dindex;
104
669k
literal:
105
669k
        ip += 1 + ((ip - ii) >> 5);
106
785k
next:
107
785k
        if __lzo_unlikely(ip >= ip_end)
108
896
            break;
109
784k
        dv = UA_GET_LE32(ip);
110
784k
        dindex = DINDEX(dv,ip);
111
784k
        GINDEX(m_off,m_pos,in+dict,dindex,in);
112
784k
        UPDATE_I(dict,0,dindex,ip,in);
113
784k
        if __lzo_unlikely(dv != UA_GET_LE32(m_pos))
114
668k
            goto literal;
115
784k
        }
116
115k
#endif
117
118
    /* a match */
119
120
115k
        ii -= ti; ti = 0;
121
115k
        {
122
115k
        lzo_uint t = pd(ip,ii);
123
115k
        if (t != 0)
124
55.4k
        {
125
55.4k
            if (t <= 3)
126
29.1k
            {
127
29.1k
                op[-2] = LZO_BYTE(op[-2] | t);
128
29.1k
#if (LZO_OPT_UNALIGNED32)
129
29.1k
                UA_COPY4(op, ii);
130
29.1k
                op += t;
131
#else
132
                { do *op++ = *ii++; while (--t > 0); }
133
#endif
134
29.1k
            }
135
26.2k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
136
26.2k
            else if (t <= 16)
137
17.4k
            {
138
17.4k
                *op++ = LZO_BYTE(t - 3);
139
17.4k
                UA_COPY8(op, ii);
140
17.4k
                UA_COPY8(op+8, ii+8);
141
17.4k
                op += t;
142
17.4k
            }
143
8.88k
#endif
144
8.88k
            else
145
8.88k
            {
146
8.88k
                if (t <= 18)
147
807
                    *op++ = LZO_BYTE(t - 3);
148
8.08k
                else
149
8.08k
                {
150
8.08k
                    lzo_uint tt = t - 18;
151
8.08k
                    *op++ = 0;
152
33.3k
                    while __lzo_unlikely(tt > 255)
153
25.2k
                    {
154
25.2k
                        tt -= 255;
155
25.2k
                        UA_SET1(op, 0);
156
25.2k
                        op++;
157
25.2k
                    }
158
8.08k
                    assert(tt > 0);
159
8.08k
                    *op++ = LZO_BYTE(tt);
160
8.08k
                }
161
8.88k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
162
432k
                do {
163
432k
                    UA_COPY8(op, ii);
164
432k
                    UA_COPY8(op+8, ii+8);
165
432k
                    op += 16; ii += 16; t -= 16;
166
432k
                } while (t >= 16); if (t > 0)
167
8.10k
#endif
168
55.8k
                { do *op++ = *ii++; while (--t > 0); }
169
8.88k
            }
170
55.4k
        }
171
115k
        }
172
115k
        m_len = 4;
173
115k
        {
174
115k
#if (LZO_OPT_UNALIGNED64)
175
115k
        lzo_uint64_t v;
176
115k
        v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
177
115k
        if __lzo_unlikely(v == 0) {
178
1.19M
            do {
179
1.19M
                m_len += 8;
180
1.19M
                v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
181
1.19M
                if __lzo_unlikely(ip + m_len >= ip_end)
182
250
                    goto m_len_done;
183
1.19M
            } while (v == 0);
184
28.2k
        }
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
115k
        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
115k
        }
269
115k
m_len_done:
270
115k
        m_off = pd(ip,m_pos);
271
115k
        ip += m_len;
272
115k
        ii = ip;
273
115k
        if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
274
61.5k
        {
275
61.5k
            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
61.5k
            *op++ = LZO_BYTE(((m_len + 1) << 4) | ((m_off & 3) << 2));
281
61.5k
            *op++ = LZO_BYTE(m_off >> 2);
282
61.5k
#endif
283
61.5k
        }
284
53.9k
        else if (m_off <= M3_MAX_OFFSET)
285
46.9k
        {
286
46.9k
            m_off -= 1;
287
46.9k
            if (m_len <= M3_MAX_LEN)
288
34.6k
                *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
289
12.2k
            else
290
12.2k
            {
291
12.2k
                m_len -= M3_MAX_LEN;
292
12.2k
                *op++ = M3_MARKER | 0;
293
39.8k
                while __lzo_unlikely(m_len > 255)
294
27.6k
                {
295
27.6k
                    m_len -= 255;
296
27.6k
                    UA_SET1(op, 0);
297
27.6k
                    op++;
298
27.6k
                }
299
12.2k
                *op++ = LZO_BYTE(m_len);
300
12.2k
            }
301
46.9k
            *op++ = LZO_BYTE(m_off << 2);
302
46.9k
            *op++ = LZO_BYTE(m_off >> 6);
303
46.9k
        }
304
7.02k
        else
305
7.02k
        {
306
7.02k
            m_off -= 0x4000;
307
7.02k
            if (m_len <= M4_MAX_LEN)
308
4.00k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8) | (m_len - 2));
309
3.01k
            else
310
3.01k
            {
311
3.01k
                m_len -= M4_MAX_LEN;
312
3.01k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8));
313
7.82k
                while __lzo_unlikely(m_len > 255)
314
4.81k
                {
315
4.81k
                    m_len -= 255;
316
4.81k
                    UA_SET1(op, 0);
317
4.81k
                    op++;
318
4.81k
                }
319
3.01k
                *op++ = LZO_BYTE(m_len);
320
3.01k
            }
321
7.02k
            *op++ = LZO_BYTE(m_off << 2);
322
7.02k
            *op++ = LZO_BYTE(m_off >> 6);
323
7.02k
        }
324
115k
        goto next;
325
115k
    }
326
327
896
    *out_len = pd(op, out);
328
896
    return pd(in_end,ii-ti);
329
896
}
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
3.23k
{
341
3.23k
    const lzo_bytep ip = in;
342
3.23k
    lzo_bytep op = out;
343
3.23k
    lzo_uint l = in_len;
344
3.23k
    lzo_uint t = 0;
345
346
10.3k
    while (l > 20)
347
7.10k
    {
348
7.10k
        lzo_uint ll = l;
349
7.10k
        lzo_uintptr_t ll_end;
350
7.10k
#if 0 || (LZO_DETERMINISTIC)
351
7.10k
        ll = LZO_MIN(ll, 49152);
352
7.10k
#endif
353
7.10k
        ll_end = (lzo_uintptr_t)ip + ll;
354
7.10k
        if ((ll_end + ((t + ll) >> 5)) <= ll_end || (const lzo_bytep)(ll_end + ((t + ll) >> 5)) <= ip + ll)
355
24
            break;
356
7.08k
#if (LZO_DETERMINISTIC)
357
7.08k
        lzo_memset(wrkmem, 0, ((lzo_uint)1 << D_BITS) * sizeof(lzo_dict_t));
358
7.08k
#endif
359
7.08k
        t = do_compress(ip,ll,op,out_len,t,wrkmem);
360
7.08k
        ip += ll;
361
7.08k
        op += *out_len;
362
7.08k
        l  -= ll;
363
7.08k
    }
364
3.23k
    t += l;
365
366
3.23k
    if (t > 0)
367
3.22k
    {
368
3.22k
        const lzo_bytep ii = in + in_len - t;
369
370
3.22k
        if (op == out && t <= 238)
371
218
            *op++ = LZO_BYTE(17 + t);
372
3.00k
        else if (t <= 3)
373
0
            op[-2] = LZO_BYTE(op[-2] | t);
374
3.00k
        else if (t <= 18)
375
1.63k
            *op++ = LZO_BYTE(t - 3);
376
1.37k
        else
377
1.37k
        {
378
1.37k
            lzo_uint tt = t - 18;
379
380
1.37k
            *op++ = 0;
381
379k
            while (tt > 255)
382
377k
            {
383
377k
                tt -= 255;
384
377k
                UA_SET1(op, 0);
385
377k
                op++;
386
377k
            }
387
1.37k
            assert(tt > 0);
388
1.37k
            *op++ = LZO_BYTE(tt);
389
1.37k
        }
390
3.22k
        UA_COPYN(op, ii, t);
391
3.22k
        op += t;
392
3.22k
    }
393
394
3.23k
    *op++ = M4_MARKER | 1;
395
3.23k
    *op++ = 0;
396
3.23k
    *op++ = 0;
397
398
3.23k
    *out_len = pd(op, out);
399
3.23k
    return LZO_E_OK;
400
3.23k
}
lzo1x_1_compress
Line
Count
Source
340
1.43k
{
341
1.43k
    const lzo_bytep ip = in;
342
1.43k
    lzo_bytep op = out;
343
1.43k
    lzo_uint l = in_len;
344
1.43k
    lzo_uint t = 0;
345
346
4.72k
    while (l > 20)
347
3.29k
    {
348
3.29k
        lzo_uint ll = l;
349
3.29k
        lzo_uintptr_t ll_end;
350
3.29k
#if 0 || (LZO_DETERMINISTIC)
351
3.29k
        ll = LZO_MIN(ll, 49152);
352
3.29k
#endif
353
3.29k
        ll_end = (lzo_uintptr_t)ip + ll;
354
3.29k
        if ((ll_end + ((t + ll) >> 5)) <= ll_end || (const lzo_bytep)(ll_end + ((t + ll) >> 5)) <= ip + ll)
355
9
            break;
356
3.28k
#if (LZO_DETERMINISTIC)
357
3.28k
        lzo_memset(wrkmem, 0, ((lzo_uint)1 << D_BITS) * sizeof(lzo_dict_t));
358
3.28k
#endif
359
3.28k
        t = do_compress(ip,ll,op,out_len,t,wrkmem);
360
3.28k
        ip += ll;
361
3.28k
        op += *out_len;
362
3.28k
        l  -= ll;
363
3.28k
    }
364
1.43k
    t += l;
365
366
1.43k
    if (t > 0)
367
1.43k
    {
368
1.43k
        const lzo_bytep ii = in + in_len - t;
369
370
1.43k
        if (op == out && t <= 238)
371
87
            *op++ = LZO_BYTE(17 + t);
372
1.34k
        else if (t <= 3)
373
0
            op[-2] = LZO_BYTE(op[-2] | t);
374
1.34k
        else if (t <= 18)
375
783
            *op++ = LZO_BYTE(t - 3);
376
566
        else
377
566
        {
378
566
            lzo_uint tt = t - 18;
379
380
566
            *op++ = 0;
381
190k
            while (tt > 255)
382
189k
            {
383
189k
                tt -= 255;
384
189k
                UA_SET1(op, 0);
385
189k
                op++;
386
189k
            }
387
566
            assert(tt > 0);
388
566
            *op++ = LZO_BYTE(tt);
389
566
        }
390
1.43k
        UA_COPYN(op, ii, t);
391
1.43k
        op += t;
392
1.43k
    }
393
394
1.43k
    *op++ = M4_MARKER | 1;
395
1.43k
    *op++ = 0;
396
1.43k
    *op++ = 0;
397
398
1.43k
    *out_len = pd(op, out);
399
1.43k
    return LZO_E_OK;
400
1.43k
}
lzo1x_1_11_compress
Line
Count
Source
340
429
{
341
429
    const lzo_bytep ip = in;
342
429
    lzo_bytep op = out;
343
429
    lzo_uint l = in_len;
344
429
    lzo_uint t = 0;
345
346
1.30k
    while (l > 20)
347
874
    {
348
874
        lzo_uint ll = l;
349
874
        lzo_uintptr_t ll_end;
350
874
#if 0 || (LZO_DETERMINISTIC)
351
874
        ll = LZO_MIN(ll, 49152);
352
874
#endif
353
874
        ll_end = (lzo_uintptr_t)ip + ll;
354
874
        if ((ll_end + ((t + ll) >> 5)) <= ll_end || (const lzo_bytep)(ll_end + ((t + ll) >> 5)) <= ip + ll)
355
2
            break;
356
872
#if (LZO_DETERMINISTIC)
357
872
        lzo_memset(wrkmem, 0, ((lzo_uint)1 << D_BITS) * sizeof(lzo_dict_t));
358
872
#endif
359
872
        t = do_compress(ip,ll,op,out_len,t,wrkmem);
360
872
        ip += ll;
361
872
        op += *out_len;
362
872
        l  -= ll;
363
872
    }
364
429
    t += l;
365
366
429
    if (t > 0)
367
428
    {
368
428
        const lzo_bytep ii = in + in_len - t;
369
370
428
        if (op == out && t <= 238)
371
34
            *op++ = LZO_BYTE(17 + t);
372
394
        else if (t <= 3)
373
0
            op[-2] = LZO_BYTE(op[-2] | t);
374
394
        else if (t <= 18)
375
193
            *op++ = LZO_BYTE(t - 3);
376
201
        else
377
201
        {
378
201
            lzo_uint tt = t - 18;
379
380
201
            *op++ = 0;
381
32.4k
            while (tt > 255)
382
32.2k
            {
383
32.2k
                tt -= 255;
384
32.2k
                UA_SET1(op, 0);
385
32.2k
                op++;
386
32.2k
            }
387
201
            assert(tt > 0);
388
201
            *op++ = LZO_BYTE(tt);
389
201
        }
390
428
        UA_COPYN(op, ii, t);
391
428
        op += t;
392
428
    }
393
394
429
    *op++ = M4_MARKER | 1;
395
429
    *op++ = 0;
396
429
    *op++ = 0;
397
398
429
    *out_len = pd(op, out);
399
429
    return LZO_E_OK;
400
429
}
lzo1x_1_12_compress
Line
Count
Source
340
477
{
341
477
    const lzo_bytep ip = in;
342
477
    lzo_bytep op = out;
343
477
    lzo_uint l = in_len;
344
477
    lzo_uint t = 0;
345
346
1.46k
    while (l > 20)
347
992
    {
348
992
        lzo_uint ll = l;
349
992
        lzo_uintptr_t ll_end;
350
992
#if 0 || (LZO_DETERMINISTIC)
351
992
        ll = LZO_MIN(ll, 49152);
352
992
#endif
353
992
        ll_end = (lzo_uintptr_t)ip + ll;
354
992
        if ((ll_end + ((t + ll) >> 5)) <= ll_end || (const lzo_bytep)(ll_end + ((t + ll) >> 5)) <= ip + ll)
355
5
            break;
356
987
#if (LZO_DETERMINISTIC)
357
987
        lzo_memset(wrkmem, 0, ((lzo_uint)1 << D_BITS) * sizeof(lzo_dict_t));
358
987
#endif
359
987
        t = do_compress(ip,ll,op,out_len,t,wrkmem);
360
987
        ip += ll;
361
987
        op += *out_len;
362
987
        l  -= ll;
363
987
    }
364
477
    t += l;
365
366
477
    if (t > 0)
367
476
    {
368
476
        const lzo_bytep ii = in + in_len - t;
369
370
476
        if (op == out && t <= 238)
371
33
            *op++ = LZO_BYTE(17 + t);
372
443
        else if (t <= 3)
373
0
            op[-2] = LZO_BYTE(op[-2] | t);
374
443
        else if (t <= 18)
375
213
            *op++ = LZO_BYTE(t - 3);
376
230
        else
377
230
        {
378
230
            lzo_uint tt = t - 18;
379
380
230
            *op++ = 0;
381
63.5k
            while (tt > 255)
382
63.3k
            {
383
63.3k
                tt -= 255;
384
63.3k
                UA_SET1(op, 0);
385
63.3k
                op++;
386
63.3k
            }
387
230
            assert(tt > 0);
388
230
            *op++ = LZO_BYTE(tt);
389
230
        }
390
476
        UA_COPYN(op, ii, t);
391
476
        op += t;
392
476
    }
393
394
477
    *op++ = M4_MARKER | 1;
395
477
    *op++ = 0;
396
477
    *op++ = 0;
397
398
477
    *out_len = pd(op, out);
399
477
    return LZO_E_OK;
400
477
}
lzo1x_1_15_compress
Line
Count
Source
340
451
{
341
451
    const lzo_bytep ip = in;
342
451
    lzo_bytep op = out;
343
451
    lzo_uint l = in_len;
344
451
    lzo_uint t = 0;
345
346
1.49k
    while (l > 20)
347
1.04k
    {
348
1.04k
        lzo_uint ll = l;
349
1.04k
        lzo_uintptr_t ll_end;
350
1.04k
#if 0 || (LZO_DETERMINISTIC)
351
1.04k
        ll = LZO_MIN(ll, 49152);
352
1.04k
#endif
353
1.04k
        ll_end = (lzo_uintptr_t)ip + ll;
354
1.04k
        if ((ll_end + ((t + ll) >> 5)) <= ll_end || (const lzo_bytep)(ll_end + ((t + ll) >> 5)) <= ip + ll)
355
6
            break;
356
1.03k
#if (LZO_DETERMINISTIC)
357
1.03k
        lzo_memset(wrkmem, 0, ((lzo_uint)1 << D_BITS) * sizeof(lzo_dict_t));
358
1.03k
#endif
359
1.03k
        t = do_compress(ip,ll,op,out_len,t,wrkmem);
360
1.03k
        ip += ll;
361
1.03k
        op += *out_len;
362
1.03k
        l  -= ll;
363
1.03k
    }
364
451
    t += l;
365
366
451
    if (t > 0)
367
450
    {
368
450
        const lzo_bytep ii = in + in_len - t;
369
370
450
        if (op == out && t <= 238)
371
40
            *op++ = LZO_BYTE(17 + t);
372
410
        else if (t <= 3)
373
0
            op[-2] = LZO_BYTE(op[-2] | t);
374
410
        else if (t <= 18)
375
220
            *op++ = LZO_BYTE(t - 3);
376
190
        else
377
190
        {
378
190
            lzo_uint tt = t - 18;
379
380
190
            *op++ = 0;
381
57.9k
            while (tt > 255)
382
57.8k
            {
383
57.8k
                tt -= 255;
384
57.8k
                UA_SET1(op, 0);
385
57.8k
                op++;
386
57.8k
            }
387
190
            assert(tt > 0);
388
190
            *op++ = LZO_BYTE(tt);
389
190
        }
390
450
        UA_COPYN(op, ii, t);
391
450
        op += t;
392
450
    }
393
394
451
    *op++ = M4_MARKER | 1;
395
451
    *op++ = 0;
396
451
    *op++ = 0;
397
398
451
    *out_len = pd(op, out);
399
451
    return LZO_E_OK;
400
451
}
lzo1y_1_compress
Line
Count
Source
340
436
{
341
436
    const lzo_bytep ip = in;
342
436
    lzo_bytep op = out;
343
436
    lzo_uint l = in_len;
344
436
    lzo_uint t = 0;
345
346
1.33k
    while (l > 20)
347
898
    {
348
898
        lzo_uint ll = l;
349
898
        lzo_uintptr_t ll_end;
350
898
#if 0 || (LZO_DETERMINISTIC)
351
898
        ll = LZO_MIN(ll, 49152);
352
898
#endif
353
898
        ll_end = (lzo_uintptr_t)ip + ll;
354
898
        if ((ll_end + ((t + ll) >> 5)) <= ll_end || (const lzo_bytep)(ll_end + ((t + ll) >> 5)) <= ip + ll)
355
2
            break;
356
896
#if (LZO_DETERMINISTIC)
357
896
        lzo_memset(wrkmem, 0, ((lzo_uint)1 << D_BITS) * sizeof(lzo_dict_t));
358
896
#endif
359
896
        t = do_compress(ip,ll,op,out_len,t,wrkmem);
360
896
        ip += ll;
361
896
        op += *out_len;
362
896
        l  -= ll;
363
896
    }
364
436
    t += l;
365
366
436
    if (t > 0)
367
435
    {
368
435
        const lzo_bytep ii = in + in_len - t;
369
370
435
        if (op == out && t <= 238)
371
24
            *op++ = LZO_BYTE(17 + t);
372
411
        else if (t <= 3)
373
0
            op[-2] = LZO_BYTE(op[-2] | t);
374
411
        else if (t <= 18)
375
228
            *op++ = LZO_BYTE(t - 3);
376
183
        else
377
183
        {
378
183
            lzo_uint tt = t - 18;
379
380
183
            *op++ = 0;
381
34.6k
            while (tt > 255)
382
34.4k
            {
383
34.4k
                tt -= 255;
384
34.4k
                UA_SET1(op, 0);
385
34.4k
                op++;
386
34.4k
            }
387
183
            assert(tt > 0);
388
183
            *op++ = LZO_BYTE(tt);
389
183
        }
390
435
        UA_COPYN(op, ii, t);
391
435
        op += t;
392
435
    }
393
394
436
    *op++ = M4_MARKER | 1;
395
436
    *op++ = 0;
396
436
    *op++ = 0;
397
398
436
    *out_len = pd(op, out);
399
436
    return LZO_E_OK;
400
436
}
401
402
403
/* vim:set ts=4 sw=4 et: */