Coverage Report

Created: 2026-08-13 06:43

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
5.49k
#  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
5.49k
{
45
5.49k
    const lzo_bytep ip;
46
5.49k
    lzo_bytep op;
47
5.49k
    const lzo_bytep const in_end = in + in_len;
48
5.49k
    const lzo_bytep const ip_end = in + in_len - 20;
49
5.49k
    const lzo_bytep ii;
50
5.49k
    lzo_dict_p const dict = (lzo_dict_p) wrkmem;
51
52
5.49k
    op = out;
53
5.49k
    ip = in;
54
5.49k
    ii = ip;
55
56
5.49k
    ip += ti < 4 ? 4 - ti : 0;
57
5.49k
    for (;;)
58
5.49k
    {
59
5.49k
        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
5.49k
        lzo_uint m_off;
100
5.49k
        lzo_uint m_len;
101
5.49k
        {
102
5.49k
        lzo_uint32_t dv;
103
5.49k
        lzo_uint dindex;
104
3.30M
literal:
105
3.30M
        ip += 1 + ((ip - ii) >> 5);
106
4.08M
next:
107
4.08M
        if __lzo_unlikely(ip >= ip_end)
108
5.49k
            break;
109
4.08M
        dv = UA_GET_LE32(ip);
110
4.08M
        dindex = DINDEX(dv,ip);
111
4.08M
        GINDEX(m_off,m_pos,in+dict,dindex,in);
112
4.08M
        UPDATE_I(dict,0,dindex,ip,in);
113
4.08M
        if __lzo_unlikely(dv != UA_GET_LE32(m_pos))
114
3.30M
            goto literal;
115
4.08M
        }
116
779k
#endif
117
118
    /* a match */
119
120
779k
        ii -= ti; ti = 0;
121
779k
        {
122
779k
        lzo_uint t = pd(ip,ii);
123
779k
        if (t != 0)
124
304k
        {
125
304k
            if (t <= 3)
126
176k
            {
127
176k
                op[-2] = LZO_BYTE(op[-2] | t);
128
176k
#if (LZO_OPT_UNALIGNED32)
129
176k
                UA_COPY4(op, ii);
130
176k
                op += t;
131
#else
132
                { do *op++ = *ii++; while (--t > 0); }
133
#endif
134
176k
            }
135
127k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
136
127k
            else if (t <= 16)
137
91.9k
            {
138
91.9k
                *op++ = LZO_BYTE(t - 3);
139
91.9k
                UA_COPY8(op, ii);
140
91.9k
                UA_COPY8(op+8, ii+8);
141
91.9k
                op += t;
142
91.9k
            }
143
35.9k
#endif
144
35.9k
            else
145
35.9k
            {
146
35.9k
                if (t <= 18)
147
3.71k
                    *op++ = LZO_BYTE(t - 3);
148
32.1k
                else
149
32.1k
                {
150
32.1k
                    lzo_uint tt = t - 18;
151
32.1k
                    *op++ = 0;
152
243k
                    while __lzo_unlikely(tt > 255)
153
210k
                    {
154
210k
                        tt -= 255;
155
210k
                        UA_SET1(op, 0);
156
210k
                        op++;
157
210k
                    }
158
32.1k
                    assert(tt > 0);
159
32.1k
                    *op++ = LZO_BYTE(tt);
160
32.1k
                }
161
35.9k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
162
3.48M
                do {
163
3.48M
                    UA_COPY8(op, ii);
164
3.48M
                    UA_COPY8(op+8, ii+8);
165
3.48M
                    op += 16; ii += 16; t -= 16;
166
3.48M
                } while (t >= 16); if (t > 0)
167
32.9k
#endif
168
225k
                { do *op++ = *ii++; while (--t > 0); }
169
35.9k
            }
170
304k
        }
171
779k
        }
172
779k
        m_len = 4;
173
779k
        {
174
779k
#if (LZO_OPT_UNALIGNED64)
175
779k
        lzo_uint64_t v;
176
779k
        v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
177
779k
        if __lzo_unlikely(v == 0) {
178
4.66M
            do {
179
4.66M
                m_len += 8;
180
4.66M
                v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
181
4.66M
                if __lzo_unlikely(ip + m_len >= ip_end)
182
1.06k
                    goto m_len_done;
183
4.66M
            } while (v == 0);
184
135k
        }
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
778k
        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
778k
        }
269
779k
m_len_done:
270
779k
        m_off = pd(ip,m_pos);
271
779k
        ip += m_len;
272
779k
        ii = ip;
273
779k
        if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
274
506k
        {
275
506k
            m_off -= 1;
276
#if defined(LZO1X)
277
454k
            *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2));
278
454k
            *op++ = LZO_BYTE(m_off >> 3);
279
#elif defined(LZO1Y)
280
51.8k
            *op++ = LZO_BYTE(((m_len + 1) << 4) | ((m_off & 3) << 2));
281
51.8k
            *op++ = LZO_BYTE(m_off >> 2);
282
#endif
283
506k
        }
284
272k
        else if (m_off <= M3_MAX_OFFSET)
285
242k
        {
286
242k
            m_off -= 1;
287
242k
            if (m_len <= M3_MAX_LEN)
288
185k
                *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
289
57.5k
            else
290
57.5k
            {
291
57.5k
                m_len -= M3_MAX_LEN;
292
57.5k
                *op++ = M3_MARKER | 0;
293
163k
                while __lzo_unlikely(m_len > 255)
294
105k
                {
295
105k
                    m_len -= 255;
296
105k
                    UA_SET1(op, 0);
297
105k
                    op++;
298
105k
                }
299
57.5k
                *op++ = LZO_BYTE(m_len);
300
57.5k
            }
301
242k
            *op++ = LZO_BYTE(m_off << 2);
302
242k
            *op++ = LZO_BYTE(m_off >> 6);
303
242k
        }
304
30.1k
        else
305
30.1k
        {
306
30.1k
            m_off -= 0x4000;
307
30.1k
            if (m_len <= M4_MAX_LEN)
308
19.3k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8) | (m_len - 2));
309
10.8k
            else
310
10.8k
            {
311
10.8k
                m_len -= M4_MAX_LEN;
312
10.8k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8));
313
27.2k
                while __lzo_unlikely(m_len > 255)
314
16.4k
                {
315
16.4k
                    m_len -= 255;
316
16.4k
                    UA_SET1(op, 0);
317
16.4k
                    op++;
318
16.4k
                }
319
10.8k
                *op++ = LZO_BYTE(m_len);
320
10.8k
            }
321
30.1k
            *op++ = LZO_BYTE(m_off << 2);
322
30.1k
            *op++ = LZO_BYTE(m_off >> 6);
323
30.1k
        }
324
779k
        goto next;
325
778k
    }
326
327
5.49k
    *out_len = pd(op, out);
328
5.49k
    return pd(in_end,ii-ti);
329
5.49k
}
lzo1x_1.c:lzo1x_1_compress_core
Line
Count
Source
44
1.18k
{
45
1.18k
    const lzo_bytep ip;
46
1.18k
    lzo_bytep op;
47
1.18k
    const lzo_bytep const in_end = in + in_len;
48
1.18k
    const lzo_bytep const ip_end = in + in_len - 20;
49
1.18k
    const lzo_bytep ii;
50
1.18k
    lzo_dict_p const dict = (lzo_dict_p) wrkmem;
51
52
1.18k
    op = out;
53
1.18k
    ip = in;
54
1.18k
    ii = ip;
55
56
1.18k
    ip += ti < 4 ? 4 - ti : 0;
57
1.18k
    for (;;)
58
1.18k
    {
59
1.18k
        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.18k
        lzo_uint m_off;
100
1.18k
        lzo_uint m_len;
101
1.18k
        {
102
1.18k
        lzo_uint32_t dv;
103
1.18k
        lzo_uint dindex;
104
680k
literal:
105
680k
        ip += 1 + ((ip - ii) >> 5);
106
972k
next:
107
972k
        if __lzo_unlikely(ip >= ip_end)
108
1.18k
            break;
109
970k
        dv = UA_GET_LE32(ip);
110
970k
        dindex = DINDEX(dv,ip);
111
970k
        GINDEX(m_off,m_pos,in+dict,dindex,in);
112
970k
        UPDATE_I(dict,0,dindex,ip,in);
113
970k
        if __lzo_unlikely(dv != UA_GET_LE32(m_pos))
114
679k
            goto literal;
115
970k
        }
116
291k
#endif
117
118
    /* a match */
119
120
291k
        ii -= ti; ti = 0;
121
291k
        {
122
291k
        lzo_uint t = pd(ip,ii);
123
291k
        if (t != 0)
124
78.1k
        {
125
78.1k
            if (t <= 3)
126
51.6k
            {
127
51.6k
                op[-2] = LZO_BYTE(op[-2] | t);
128
51.6k
#if (LZO_OPT_UNALIGNED32)
129
51.6k
                UA_COPY4(op, ii);
130
51.6k
                op += t;
131
#else
132
                { do *op++ = *ii++; while (--t > 0); }
133
#endif
134
51.6k
            }
135
26.5k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
136
26.5k
            else if (t <= 16)
137
20.1k
            {
138
20.1k
                *op++ = LZO_BYTE(t - 3);
139
20.1k
                UA_COPY8(op, ii);
140
20.1k
                UA_COPY8(op+8, ii+8);
141
20.1k
                op += t;
142
20.1k
            }
143
6.39k
#endif
144
6.39k
            else
145
6.39k
            {
146
6.39k
                if (t <= 18)
147
669
                    *op++ = LZO_BYTE(t - 3);
148
5.72k
                else
149
5.72k
                {
150
5.72k
                    lzo_uint tt = t - 18;
151
5.72k
                    *op++ = 0;
152
53.7k
                    while __lzo_unlikely(tt > 255)
153
48.0k
                    {
154
48.0k
                        tt -= 255;
155
48.0k
                        UA_SET1(op, 0);
156
48.0k
                        op++;
157
48.0k
                    }
158
5.72k
                    assert(tt > 0);
159
5.72k
                    *op++ = LZO_BYTE(tt);
160
5.72k
                }
161
6.39k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
162
787k
                do {
163
787k
                    UA_COPY8(op, ii);
164
787k
                    UA_COPY8(op+8, ii+8);
165
787k
                    op += 16; ii += 16; t -= 16;
166
787k
                } while (t >= 16); if (t > 0)
167
5.89k
#endif
168
40.3k
                { do *op++ = *ii++; while (--t > 0); }
169
6.39k
            }
170
78.1k
        }
171
291k
        }
172
291k
        m_len = 4;
173
291k
        {
174
291k
#if (LZO_OPT_UNALIGNED64)
175
291k
        lzo_uint64_t v;
176
291k
        v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
177
291k
        if __lzo_unlikely(v == 0) {
178
846k
            do {
179
846k
                m_len += 8;
180
846k
                v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
181
846k
                if __lzo_unlikely(ip + m_len >= ip_end)
182
204
                    goto m_len_done;
183
846k
            } while (v == 0);
184
30.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
291k
        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
291k
        }
269
291k
m_len_done:
270
291k
        m_off = pd(ip,m_pos);
271
291k
        ip += m_len;
272
291k
        ii = ip;
273
291k
        if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
274
215k
        {
275
215k
            m_off -= 1;
276
215k
#if defined(LZO1X)
277
215k
            *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2));
278
215k
            *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
215k
        }
284
75.8k
        else if (m_off <= M3_MAX_OFFSET)
285
65.1k
        {
286
65.1k
            m_off -= 1;
287
65.1k
            if (m_len <= M3_MAX_LEN)
288
54.3k
                *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
289
10.8k
            else
290
10.8k
            {
291
10.8k
                m_len -= M3_MAX_LEN;
292
10.8k
                *op++ = M3_MARKER | 0;
293
29.8k
                while __lzo_unlikely(m_len > 255)
294
19.0k
                {
295
19.0k
                    m_len -= 255;
296
19.0k
                    UA_SET1(op, 0);
297
19.0k
                    op++;
298
19.0k
                }
299
10.8k
                *op++ = LZO_BYTE(m_len);
300
10.8k
            }
301
65.1k
            *op++ = LZO_BYTE(m_off << 2);
302
65.1k
            *op++ = LZO_BYTE(m_off >> 6);
303
65.1k
        }
304
10.6k
        else
305
10.6k
        {
306
10.6k
            m_off -= 0x4000;
307
10.6k
            if (m_len <= M4_MAX_LEN)
308
8.59k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8) | (m_len - 2));
309
2.10k
            else
310
2.10k
            {
311
2.10k
                m_len -= M4_MAX_LEN;
312
2.10k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8));
313
4.75k
                while __lzo_unlikely(m_len > 255)
314
2.64k
                {
315
2.64k
                    m_len -= 255;
316
2.64k
                    UA_SET1(op, 0);
317
2.64k
                    op++;
318
2.64k
                }
319
2.10k
                *op++ = LZO_BYTE(m_len);
320
2.10k
            }
321
10.6k
            *op++ = LZO_BYTE(m_off << 2);
322
10.6k
            *op++ = LZO_BYTE(m_off >> 6);
323
10.6k
        }
324
291k
        goto next;
325
291k
    }
326
327
1.18k
    *out_len = pd(op, out);
328
1.18k
    return pd(in_end,ii-ti);
329
1.18k
}
lzo1x_1k.c:lzo1x_1_11_compress_core
Line
Count
Source
44
958
{
45
958
    const lzo_bytep ip;
46
958
    lzo_bytep op;
47
958
    const lzo_bytep const in_end = in + in_len;
48
958
    const lzo_bytep const ip_end = in + in_len - 20;
49
958
    const lzo_bytep ii;
50
958
    lzo_dict_p const dict = (lzo_dict_p) wrkmem;
51
52
958
    op = out;
53
958
    ip = in;
54
958
    ii = ip;
55
56
958
    ip += ti < 4 ? 4 - ti : 0;
57
958
    for (;;)
58
958
    {
59
958
        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
958
        lzo_uint m_off;
100
958
        lzo_uint m_len;
101
958
        {
102
958
        lzo_uint32_t dv;
103
958
        lzo_uint dindex;
104
624k
literal:
105
624k
        ip += 1 + ((ip - ii) >> 5);
106
745k
next:
107
745k
        if __lzo_unlikely(ip >= ip_end)
108
958
            break;
109
744k
        dv = UA_GET_LE32(ip);
110
744k
        dindex = DINDEX(dv,ip);
111
744k
        GINDEX(m_off,m_pos,in+dict,dindex,in);
112
744k
        UPDATE_I(dict,0,dindex,ip,in);
113
744k
        if __lzo_unlikely(dv != UA_GET_LE32(m_pos))
114
623k
            goto literal;
115
744k
        }
116
121k
#endif
117
118
    /* a match */
119
120
121k
        ii -= ti; ti = 0;
121
121k
        {
122
121k
        lzo_uint t = pd(ip,ii);
123
121k
        if (t != 0)
124
57.1k
        {
125
57.1k
            if (t <= 3)
126
31.2k
            {
127
31.2k
                op[-2] = LZO_BYTE(op[-2] | t);
128
31.2k
#if (LZO_OPT_UNALIGNED32)
129
31.2k
                UA_COPY4(op, ii);
130
31.2k
                op += t;
131
#else
132
                { do *op++ = *ii++; while (--t > 0); }
133
#endif
134
31.2k
            }
135
25.9k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
136
25.9k
            else if (t <= 16)
137
18.9k
            {
138
18.9k
                *op++ = LZO_BYTE(t - 3);
139
18.9k
                UA_COPY8(op, ii);
140
18.9k
                UA_COPY8(op+8, ii+8);
141
18.9k
                op += t;
142
18.9k
            }
143
6.97k
#endif
144
6.97k
            else
145
6.97k
            {
146
6.97k
                if (t <= 18)
147
688
                    *op++ = LZO_BYTE(t - 3);
148
6.28k
                else
149
6.28k
                {
150
6.28k
                    lzo_uint tt = t - 18;
151
6.28k
                    *op++ = 0;
152
44.5k
                    while __lzo_unlikely(tt > 255)
153
38.2k
                    {
154
38.2k
                        tt -= 255;
155
38.2k
                        UA_SET1(op, 0);
156
38.2k
                        op++;
157
38.2k
                    }
158
6.28k
                    assert(tt > 0);
159
6.28k
                    *op++ = LZO_BYTE(tt);
160
6.28k
                }
161
6.97k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
162
635k
                do {
163
635k
                    UA_COPY8(op, ii);
164
635k
                    UA_COPY8(op+8, ii+8);
165
635k
                    op += 16; ii += 16; t -= 16;
166
635k
                } while (t >= 16); if (t > 0)
167
6.34k
#endif
168
43.7k
                { do *op++ = *ii++; while (--t > 0); }
169
6.97k
            }
170
57.1k
        }
171
121k
        }
172
121k
        m_len = 4;
173
121k
        {
174
121k
#if (LZO_OPT_UNALIGNED64)
175
121k
        lzo_uint64_t v;
176
121k
        v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
177
121k
        if __lzo_unlikely(v == 0) {
178
1.12M
            do {
179
1.12M
                m_len += 8;
180
1.12M
                v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
181
1.12M
                if __lzo_unlikely(ip + m_len >= ip_end)
182
238
                    goto m_len_done;
183
1.12M
            } while (v == 0);
184
27.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
121k
        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
121k
        }
269
121k
m_len_done:
270
121k
        m_off = pd(ip,m_pos);
271
121k
        ip += m_len;
272
121k
        ii = ip;
273
121k
        if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
274
70.2k
        {
275
70.2k
            m_off -= 1;
276
70.2k
#if defined(LZO1X)
277
70.2k
            *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2));
278
70.2k
            *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
70.2k
        }
284
51.2k
        else if (m_off <= M3_MAX_OFFSET)
285
47.2k
        {
286
47.2k
            m_off -= 1;
287
47.2k
            if (m_len <= M3_MAX_LEN)
288
36.4k
                *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
289
10.7k
            else
290
10.7k
            {
291
10.7k
                m_len -= M3_MAX_LEN;
292
10.7k
                *op++ = M3_MARKER | 0;
293
37.4k
                while __lzo_unlikely(m_len > 255)
294
26.6k
                {
295
26.6k
                    m_len -= 255;
296
26.6k
                    UA_SET1(op, 0);
297
26.6k
                    op++;
298
26.6k
                }
299
10.7k
                *op++ = LZO_BYTE(m_len);
300
10.7k
            }
301
47.2k
            *op++ = LZO_BYTE(m_off << 2);
302
47.2k
            *op++ = LZO_BYTE(m_off >> 6);
303
47.2k
        }
304
3.93k
        else
305
3.93k
        {
306
3.93k
            m_off -= 0x4000;
307
3.93k
            if (m_len <= M4_MAX_LEN)
308
1.86k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8) | (m_len - 2));
309
2.07k
            else
310
2.07k
            {
311
2.07k
                m_len -= M4_MAX_LEN;
312
2.07k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8));
313
5.79k
                while __lzo_unlikely(m_len > 255)
314
3.71k
                {
315
3.71k
                    m_len -= 255;
316
3.71k
                    UA_SET1(op, 0);
317
3.71k
                    op++;
318
3.71k
                }
319
2.07k
                *op++ = LZO_BYTE(m_len);
320
2.07k
            }
321
3.93k
            *op++ = LZO_BYTE(m_off << 2);
322
3.93k
            *op++ = LZO_BYTE(m_off >> 6);
323
3.93k
        }
324
121k
        goto next;
325
121k
    }
326
327
958
    *out_len = pd(op, out);
328
958
    return pd(in_end,ii-ti);
329
958
}
lzo1x_1l.c:lzo1x_1_12_compress_core
Line
Count
Source
44
1.12k
{
45
1.12k
    const lzo_bytep ip;
46
1.12k
    lzo_bytep op;
47
1.12k
    const lzo_bytep const in_end = in + in_len;
48
1.12k
    const lzo_bytep const ip_end = in + in_len - 20;
49
1.12k
    const lzo_bytep ii;
50
1.12k
    lzo_dict_p const dict = (lzo_dict_p) wrkmem;
51
52
1.12k
    op = out;
53
1.12k
    ip = in;
54
1.12k
    ii = ip;
55
56
1.12k
    ip += ti < 4 ? 4 - ti : 0;
57
1.12k
    for (;;)
58
1.12k
    {
59
1.12k
        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.12k
        lzo_uint m_off;
100
1.12k
        lzo_uint m_len;
101
1.12k
        {
102
1.12k
        lzo_uint32_t dv;
103
1.12k
        lzo_uint dindex;
104
849k
literal:
105
849k
        ip += 1 + ((ip - ii) >> 5);
106
1.02M
next:
107
1.02M
        if __lzo_unlikely(ip >= ip_end)
108
1.12k
            break;
109
1.01M
        dv = UA_GET_LE32(ip);
110
1.01M
        dindex = DINDEX(dv,ip);
111
1.01M
        GINDEX(m_off,m_pos,in+dict,dindex,in);
112
1.01M
        UPDATE_I(dict,0,dindex,ip,in);
113
1.01M
        if __lzo_unlikely(dv != UA_GET_LE32(m_pos))
114
848k
            goto literal;
115
1.01M
        }
116
171k
#endif
117
118
    /* a match */
119
120
171k
        ii -= ti; ti = 0;
121
171k
        {
122
171k
        lzo_uint t = pd(ip,ii);
123
171k
        if (t != 0)
124
80.8k
        {
125
80.8k
            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.9k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
136
35.9k
            else if (t <= 16)
137
25.7k
            {
138
25.7k
                *op++ = LZO_BYTE(t - 3);
139
25.7k
                UA_COPY8(op, ii);
140
25.7k
                UA_COPY8(op+8, ii+8);
141
25.7k
                op += t;
142
25.7k
            }
143
10.2k
#endif
144
10.2k
            else
145
10.2k
            {
146
10.2k
                if (t <= 18)
147
1.04k
                    *op++ = LZO_BYTE(t - 3);
148
9.18k
                else
149
9.18k
                {
150
9.18k
                    lzo_uint tt = t - 18;
151
9.18k
                    *op++ = 0;
152
57.7k
                    while __lzo_unlikely(tt > 255)
153
48.5k
                    {
154
48.5k
                        tt -= 255;
155
48.5k
                        UA_SET1(op, 0);
156
48.5k
                        op++;
157
48.5k
                    }
158
9.18k
                    assert(tt > 0);
159
9.18k
                    *op++ = LZO_BYTE(tt);
160
9.18k
                }
161
10.2k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
162
806k
                do {
163
806k
                    UA_COPY8(op, ii);
164
806k
                    UA_COPY8(op+8, ii+8);
165
806k
                    op += 16; ii += 16; t -= 16;
166
806k
                } while (t >= 16); if (t > 0)
167
9.54k
#endif
168
66.0k
                { do *op++ = *ii++; while (--t > 0); }
169
10.2k
            }
170
80.8k
        }
171
171k
        }
172
171k
        m_len = 4;
173
171k
        {
174
171k
#if (LZO_OPT_UNALIGNED64)
175
171k
        lzo_uint64_t v;
176
171k
        v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
177
171k
        if __lzo_unlikely(v == 0) {
178
648k
            do {
179
648k
                m_len += 8;
180
648k
                v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
181
648k
                if __lzo_unlikely(ip + m_len >= ip_end)
182
155
                    goto m_len_done;
183
648k
            } while (v == 0);
184
36.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
171k
        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
171k
        }
269
171k
m_len_done:
270
171k
        m_off = pd(ip,m_pos);
271
171k
        ip += m_len;
272
171k
        ii = ip;
273
171k
        if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
274
105k
        {
275
105k
            m_off -= 1;
276
105k
#if defined(LZO1X)
277
105k
            *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2));
278
105k
            *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
105k
        }
284
66.0k
        else if (m_off <= M3_MAX_OFFSET)
285
60.0k
        {
286
60.0k
            m_off -= 1;
287
60.0k
            if (m_len <= M3_MAX_LEN)
288
42.7k
                *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
289
17.3k
            else
290
17.3k
            {
291
17.3k
                m_len -= M3_MAX_LEN;
292
17.3k
                *op++ = M3_MARKER | 0;
293
28.2k
                while __lzo_unlikely(m_len > 255)
294
10.8k
                {
295
10.8k
                    m_len -= 255;
296
10.8k
                    UA_SET1(op, 0);
297
10.8k
                    op++;
298
10.8k
                }
299
17.3k
                *op++ = LZO_BYTE(m_len);
300
17.3k
            }
301
60.0k
            *op++ = LZO_BYTE(m_off << 2);
302
60.0k
            *op++ = LZO_BYTE(m_off >> 6);
303
60.0k
        }
304
5.99k
        else
305
5.99k
        {
306
5.99k
            m_off -= 0x4000;
307
5.99k
            if (m_len <= M4_MAX_LEN)
308
3.68k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8) | (m_len - 2));
309
2.30k
            else
310
2.30k
            {
311
2.30k
                m_len -= M4_MAX_LEN;
312
2.30k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8));
313
5.75k
                while __lzo_unlikely(m_len > 255)
314
3.44k
                {
315
3.44k
                    m_len -= 255;
316
3.44k
                    UA_SET1(op, 0);
317
3.44k
                    op++;
318
3.44k
                }
319
2.30k
                *op++ = LZO_BYTE(m_len);
320
2.30k
            }
321
5.99k
            *op++ = LZO_BYTE(m_off << 2);
322
5.99k
            *op++ = LZO_BYTE(m_off >> 6);
323
5.99k
        }
324
171k
        goto next;
325
171k
    }
326
327
1.12k
    *out_len = pd(op, out);
328
1.12k
    return pd(in_end,ii-ti);
329
1.12k
}
lzo1x_1o.c:lzo1x_1_15_compress_core
Line
Count
Source
44
1.22k
{
45
1.22k
    const lzo_bytep ip;
46
1.22k
    lzo_bytep op;
47
1.22k
    const lzo_bytep const in_end = in + in_len;
48
1.22k
    const lzo_bytep const ip_end = in + in_len - 20;
49
1.22k
    const lzo_bytep ii;
50
1.22k
    lzo_dict_p const dict = (lzo_dict_p) wrkmem;
51
52
1.22k
    op = out;
53
1.22k
    ip = in;
54
1.22k
    ii = ip;
55
56
1.22k
    ip += ti < 4 ? 4 - ti : 0;
57
1.22k
    for (;;)
58
1.22k
    {
59
1.22k
        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.22k
        lzo_uint m_off;
100
1.22k
        lzo_uint m_len;
101
1.22k
        {
102
1.22k
        lzo_uint32_t dv;
103
1.22k
        lzo_uint dindex;
104
576k
literal:
105
576k
        ip += 1 + ((ip - ii) >> 5);
106
677k
next:
107
677k
        if __lzo_unlikely(ip >= ip_end)
108
1.22k
            break;
109
676k
        dv = UA_GET_LE32(ip);
110
676k
        dindex = DINDEX(dv,ip);
111
676k
        GINDEX(m_off,m_pos,in+dict,dindex,in);
112
676k
        UPDATE_I(dict,0,dindex,ip,in);
113
676k
        if __lzo_unlikely(dv != UA_GET_LE32(m_pos))
114
575k
            goto literal;
115
676k
        }
116
100k
#endif
117
118
    /* a match */
119
120
100k
        ii -= ti; ti = 0;
121
100k
        {
122
100k
        lzo_uint t = pd(ip,ii);
123
100k
        if (t != 0)
124
46.1k
        {
125
46.1k
            if (t <= 3)
126
25.9k
            {
127
25.9k
                op[-2] = LZO_BYTE(op[-2] | t);
128
25.9k
#if (LZO_OPT_UNALIGNED32)
129
25.9k
                UA_COPY4(op, ii);
130
25.9k
                op += t;
131
#else
132
                { do *op++ = *ii++; while (--t > 0); }
133
#endif
134
25.9k
            }
135
20.1k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
136
20.1k
            else if (t <= 16)
137
14.4k
            {
138
14.4k
                *op++ = LZO_BYTE(t - 3);
139
14.4k
                UA_COPY8(op, ii);
140
14.4k
                UA_COPY8(op+8, ii+8);
141
14.4k
                op += t;
142
14.4k
            }
143
5.66k
#endif
144
5.66k
            else
145
5.66k
            {
146
5.66k
                if (t <= 18)
147
655
                    *op++ = LZO_BYTE(t - 3);
148
5.01k
                else
149
5.01k
                {
150
5.01k
                    lzo_uint tt = t - 18;
151
5.01k
                    *op++ = 0;
152
49.1k
                    while __lzo_unlikely(tt > 255)
153
44.1k
                    {
154
44.1k
                        tt -= 255;
155
44.1k
                        UA_SET1(op, 0);
156
44.1k
                        op++;
157
44.1k
                    }
158
5.01k
                    assert(tt > 0);
159
5.01k
                    *op++ = LZO_BYTE(tt);
160
5.01k
                }
161
5.66k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
162
723k
                do {
163
723k
                    UA_COPY8(op, ii);
164
723k
                    UA_COPY8(op+8, ii+8);
165
723k
                    op += 16; ii += 16; t -= 16;
166
723k
                } while (t >= 16); if (t > 0)
167
5.12k
#endif
168
34.2k
                { do *op++ = *ii++; while (--t > 0); }
169
5.66k
            }
170
46.1k
        }
171
100k
        }
172
100k
        m_len = 4;
173
100k
        {
174
100k
#if (LZO_OPT_UNALIGNED64)
175
100k
        lzo_uint64_t v;
176
100k
        v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
177
100k
        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
252
                    goto m_len_done;
183
1.14M
            } while (v == 0);
184
17.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
100k
        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
100k
        }
269
100k
m_len_done:
270
100k
        m_off = pd(ip,m_pos);
271
100k
        ip += m_len;
272
100k
        ii = ip;
273
100k
        if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
274
63.6k
        {
275
63.6k
            m_off -= 1;
276
63.6k
#if defined(LZO1X)
277
63.6k
            *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2));
278
63.6k
            *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
63.6k
        }
284
36.8k
        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
25.5k
                *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
289
7.08k
            else
290
7.08k
            {
291
7.08k
                m_len -= M3_MAX_LEN;
292
7.08k
                *op++ = M3_MARKER | 0;
293
35.9k
                while __lzo_unlikely(m_len > 255)
294
28.8k
                {
295
28.8k
                    m_len -= 255;
296
28.8k
                    UA_SET1(op, 0);
297
28.8k
                    op++;
298
28.8k
                }
299
7.08k
                *op++ = LZO_BYTE(m_len);
300
7.08k
            }
301
32.5k
            *op++ = LZO_BYTE(m_off << 2);
302
32.5k
            *op++ = LZO_BYTE(m_off >> 6);
303
32.5k
        }
304
4.25k
        else
305
4.25k
        {
306
4.25k
            m_off -= 0x4000;
307
4.25k
            if (m_len <= M4_MAX_LEN)
308
2.69k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8) | (m_len - 2));
309
1.56k
            else
310
1.56k
            {
311
1.56k
                m_len -= M4_MAX_LEN;
312
1.56k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8));
313
5.11k
                while __lzo_unlikely(m_len > 255)
314
3.55k
                {
315
3.55k
                    m_len -= 255;
316
3.55k
                    UA_SET1(op, 0);
317
3.55k
                    op++;
318
3.55k
                }
319
1.56k
                *op++ = LZO_BYTE(m_len);
320
1.56k
            }
321
4.25k
            *op++ = LZO_BYTE(m_off << 2);
322
4.25k
            *op++ = LZO_BYTE(m_off >> 6);
323
4.25k
        }
324
100k
        goto next;
325
100k
    }
326
327
1.22k
    *out_len = pd(op, out);
328
1.22k
    return pd(in_end,ii-ti);
329
1.22k
}
lzo1y_1.c:lzo1y_1_compress_core
Line
Count
Source
44
1.00k
{
45
1.00k
    const lzo_bytep ip;
46
1.00k
    lzo_bytep op;
47
1.00k
    const lzo_bytep const in_end = in + in_len;
48
1.00k
    const lzo_bytep const ip_end = in + in_len - 20;
49
1.00k
    const lzo_bytep ii;
50
1.00k
    lzo_dict_p const dict = (lzo_dict_p) wrkmem;
51
52
1.00k
    op = out;
53
1.00k
    ip = in;
54
1.00k
    ii = ip;
55
56
1.00k
    ip += ti < 4 ? 4 - ti : 0;
57
1.00k
    for (;;)
58
1.00k
    {
59
1.00k
        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.00k
        lzo_uint m_off;
100
1.00k
        lzo_uint m_len;
101
1.00k
        {
102
1.00k
        lzo_uint32_t dv;
103
1.00k
        lzo_uint dindex;
104
578k
literal:
105
578k
        ip += 1 + ((ip - ii) >> 5);
106
673k
next:
107
673k
        if __lzo_unlikely(ip >= ip_end)
108
1.00k
            break;
109
672k
        dv = UA_GET_LE32(ip);
110
672k
        dindex = DINDEX(dv,ip);
111
672k
        GINDEX(m_off,m_pos,in+dict,dindex,in);
112
672k
        UPDATE_I(dict,0,dindex,ip,in);
113
672k
        if __lzo_unlikely(dv != UA_GET_LE32(m_pos))
114
577k
            goto literal;
115
672k
        }
116
94.6k
#endif
117
118
    /* a match */
119
120
94.6k
        ii -= ti; ti = 0;
121
94.6k
        {
122
94.6k
        lzo_uint t = pd(ip,ii);
123
94.6k
        if (t != 0)
124
41.9k
        {
125
41.9k
            if (t <= 3)
126
22.6k
            {
127
22.6k
                op[-2] = LZO_BYTE(op[-2] | t);
128
22.6k
#if (LZO_OPT_UNALIGNED32)
129
22.6k
                UA_COPY4(op, ii);
130
22.6k
                op += t;
131
#else
132
                { do *op++ = *ii++; while (--t > 0); }
133
#endif
134
22.6k
            }
135
19.3k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
136
19.3k
            else if (t <= 16)
137
12.6k
            {
138
12.6k
                *op++ = LZO_BYTE(t - 3);
139
12.6k
                UA_COPY8(op, ii);
140
12.6k
                UA_COPY8(op+8, ii+8);
141
12.6k
                op += t;
142
12.6k
            }
143
6.64k
#endif
144
6.64k
            else
145
6.64k
            {
146
6.64k
                if (t <= 18)
147
666
                    *op++ = LZO_BYTE(t - 3);
148
5.97k
                else
149
5.97k
                {
150
5.97k
                    lzo_uint tt = t - 18;
151
5.97k
                    *op++ = 0;
152
37.9k
                    while __lzo_unlikely(tt > 255)
153
32.0k
                    {
154
32.0k
                        tt -= 255;
155
32.0k
                        UA_SET1(op, 0);
156
32.0k
                        op++;
157
32.0k
                    }
158
5.97k
                    assert(tt > 0);
159
5.97k
                    *op++ = LZO_BYTE(tt);
160
5.97k
                }
161
6.64k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
162
535k
                do {
163
535k
                    UA_COPY8(op, ii);
164
535k
                    UA_COPY8(op+8, ii+8);
165
535k
                    op += 16; ii += 16; t -= 16;
166
535k
                } while (t >= 16); if (t > 0)
167
6.02k
#endif
168
41.0k
                { do *op++ = *ii++; while (--t > 0); }
169
6.64k
            }
170
41.9k
        }
171
94.6k
        }
172
94.6k
        m_len = 4;
173
94.6k
        {
174
94.6k
#if (LZO_OPT_UNALIGNED64)
175
94.6k
        lzo_uint64_t v;
176
94.6k
        v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
177
94.6k
        if __lzo_unlikely(v == 0) {
178
901k
            do {
179
901k
                m_len += 8;
180
901k
                v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
181
901k
                if __lzo_unlikely(ip + m_len >= ip_end)
182
213
                    goto m_len_done;
183
901k
            } while (v == 0);
184
24.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
94.4k
        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
94.4k
        }
269
94.6k
m_len_done:
270
94.6k
        m_off = pd(ip,m_pos);
271
94.6k
        ip += m_len;
272
94.6k
        ii = ip;
273
94.6k
        if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
274
51.8k
        {
275
51.8k
            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
51.8k
            *op++ = LZO_BYTE(((m_len + 1) << 4) | ((m_off & 3) << 2));
281
51.8k
            *op++ = LZO_BYTE(m_off >> 2);
282
51.8k
#endif
283
51.8k
        }
284
42.7k
        else if (m_off <= M3_MAX_OFFSET)
285
37.5k
        {
286
37.5k
            m_off -= 1;
287
37.5k
            if (m_len <= M3_MAX_LEN)
288
25.9k
                *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
289
11.5k
            else
290
11.5k
            {
291
11.5k
                m_len -= M3_MAX_LEN;
292
11.5k
                *op++ = M3_MARKER | 0;
293
31.8k
                while __lzo_unlikely(m_len > 255)
294
20.3k
                {
295
20.3k
                    m_len -= 255;
296
20.3k
                    UA_SET1(op, 0);
297
20.3k
                    op++;
298
20.3k
                }
299
11.5k
                *op++ = LZO_BYTE(m_len);
300
11.5k
            }
301
37.5k
            *op++ = LZO_BYTE(m_off << 2);
302
37.5k
            *op++ = LZO_BYTE(m_off >> 6);
303
37.5k
        }
304
5.27k
        else
305
5.27k
        {
306
5.27k
            m_off -= 0x4000;
307
5.27k
            if (m_len <= M4_MAX_LEN)
308
2.50k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8) | (m_len - 2));
309
2.76k
            else
310
2.76k
            {
311
2.76k
                m_len -= M4_MAX_LEN;
312
2.76k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8));
313
5.85k
                while __lzo_unlikely(m_len > 255)
314
3.09k
                {
315
3.09k
                    m_len -= 255;
316
3.09k
                    UA_SET1(op, 0);
317
3.09k
                    op++;
318
3.09k
                }
319
2.76k
                *op++ = LZO_BYTE(m_len);
320
2.76k
            }
321
5.27k
            *op++ = LZO_BYTE(m_off << 2);
322
5.27k
            *op++ = LZO_BYTE(m_off >> 6);
323
5.27k
        }
324
94.6k
        goto next;
325
94.4k
    }
326
327
1.00k
    *out_len = pd(op, out);
328
1.00k
    return pd(in_end,ii-ti);
329
1.00k
}
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
2.35k
{
341
2.35k
    const lzo_bytep ip = in;
342
2.35k
    lzo_bytep op = out;
343
2.35k
    lzo_uint l = in_len;
344
2.35k
    lzo_uint t = 0;
345
346
7.85k
    while (l > 20)
347
5.51k
    {
348
5.51k
        lzo_uint ll = l;
349
5.51k
        lzo_uintptr_t ll_end;
350
5.51k
#if 0 || (LZO_DETERMINISTIC)
351
5.51k
        ll = LZO_MIN(ll, 49152);
352
5.51k
#endif
353
5.51k
        ll_end = (lzo_uintptr_t)ip + ll;
354
5.51k
        if ((ll_end + ((t + ll) >> 5)) <= ll_end || (const lzo_bytep)(ll_end + ((t + ll) >> 5)) <= ip + ll)
355
18
            break;
356
5.49k
#if (LZO_DETERMINISTIC)
357
5.49k
        lzo_memset(wrkmem, 0, ((lzo_uint)1 << D_BITS) * sizeof(lzo_dict_t));
358
5.49k
#endif
359
5.49k
        t = do_compress(ip,ll,op,out_len,t,wrkmem);
360
5.49k
        ip += ll;
361
5.49k
        op += *out_len;
362
5.49k
        l  -= ll;
363
5.49k
    }
364
2.35k
    t += l;
365
366
2.35k
    if (t > 0)
367
2.35k
    {
368
2.35k
        const lzo_bytep ii = in + in_len - t;
369
370
2.35k
        if (op == out && t <= 238)
371
150
            *op++ = LZO_BYTE(17 + t);
372
2.20k
        else if (t <= 3)
373
0
            op[-2] = LZO_BYTE(op[-2] | t);
374
2.20k
        else if (t <= 18)
375
1.09k
            *op++ = LZO_BYTE(t - 3);
376
1.10k
        else
377
1.10k
        {
378
1.10k
            lzo_uint tt = t - 18;
379
380
1.10k
            *op++ = 0;
381
293k
            while (tt > 255)
382
292k
            {
383
292k
                tt -= 255;
384
292k
                UA_SET1(op, 0);
385
292k
                op++;
386
292k
            }
387
1.10k
            assert(tt > 0);
388
1.10k
            *op++ = LZO_BYTE(tt);
389
1.10k
        }
390
2.35k
        UA_COPYN(op, ii, t);
391
2.35k
        op += t;
392
2.35k
    }
393
394
2.35k
    *op++ = M4_MARKER | 1;
395
2.35k
    *op++ = 0;
396
2.35k
    *op++ = 0;
397
398
2.35k
    *out_len = pd(op, out);
399
2.35k
    return LZO_E_OK;
400
2.35k
}
lzo1x_1_compress
Line
Count
Source
340
464
{
341
464
    const lzo_bytep ip = in;
342
464
    lzo_bytep op = out;
343
464
    lzo_uint l = in_len;
344
464
    lzo_uint t = 0;
345
346
1.64k
    while (l > 20)
347
1.18k
    {
348
1.18k
        lzo_uint ll = l;
349
1.18k
        lzo_uintptr_t ll_end;
350
1.18k
#if 0 || (LZO_DETERMINISTIC)
351
1.18k
        ll = LZO_MIN(ll, 49152);
352
1.18k
#endif
353
1.18k
        ll_end = (lzo_uintptr_t)ip + ll;
354
1.18k
        if ((ll_end + ((t + ll) >> 5)) <= ll_end || (const lzo_bytep)(ll_end + ((t + ll) >> 5)) <= ip + ll)
355
2
            break;
356
1.18k
#if (LZO_DETERMINISTIC)
357
1.18k
        lzo_memset(wrkmem, 0, ((lzo_uint)1 << D_BITS) * sizeof(lzo_dict_t));
358
1.18k
#endif
359
1.18k
        t = do_compress(ip,ll,op,out_len,t,wrkmem);
360
1.18k
        ip += ll;
361
1.18k
        op += *out_len;
362
1.18k
        l  -= ll;
363
1.18k
    }
364
464
    t += l;
365
366
464
    if (t > 0)
367
463
    {
368
463
        const lzo_bytep ii = in + in_len - t;
369
370
463
        if (op == out && t <= 238)
371
27
            *op++ = LZO_BYTE(17 + t);
372
436
        else if (t <= 3)
373
0
            op[-2] = LZO_BYTE(op[-2] | t);
374
436
        else if (t <= 18)
375
218
            *op++ = LZO_BYTE(t - 3);
376
218
        else
377
218
        {
378
218
            lzo_uint tt = t - 18;
379
380
218
            *op++ = 0;
381
69.8k
            while (tt > 255)
382
69.6k
            {
383
69.6k
                tt -= 255;
384
69.6k
                UA_SET1(op, 0);
385
69.6k
                op++;
386
69.6k
            }
387
218
            assert(tt > 0);
388
218
            *op++ = LZO_BYTE(tt);
389
218
        }
390
463
        UA_COPYN(op, ii, t);
391
463
        op += t;
392
463
    }
393
394
464
    *op++ = M4_MARKER | 1;
395
464
    *op++ = 0;
396
464
    *op++ = 0;
397
398
464
    *out_len = pd(op, out);
399
464
    return LZO_E_OK;
400
464
}
lzo1x_1_11_compress
Line
Count
Source
340
450
{
341
450
    const lzo_bytep ip = in;
342
450
    lzo_bytep op = out;
343
450
    lzo_uint l = in_len;
344
450
    lzo_uint t = 0;
345
346
1.40k
    while (l > 20)
347
960
    {
348
960
        lzo_uint ll = l;
349
960
        lzo_uintptr_t ll_end;
350
960
#if 0 || (LZO_DETERMINISTIC)
351
960
        ll = LZO_MIN(ll, 49152);
352
960
#endif
353
960
        ll_end = (lzo_uintptr_t)ip + ll;
354
960
        if ((ll_end + ((t + ll) >> 5)) <= ll_end || (const lzo_bytep)(ll_end + ((t + ll) >> 5)) <= ip + ll)
355
2
            break;
356
958
#if (LZO_DETERMINISTIC)
357
958
        lzo_memset(wrkmem, 0, ((lzo_uint)1 << D_BITS) * sizeof(lzo_dict_t));
358
958
#endif
359
958
        t = do_compress(ip,ll,op,out_len,t,wrkmem);
360
958
        ip += ll;
361
958
        op += *out_len;
362
958
        l  -= ll;
363
958
    }
364
450
    t += l;
365
366
450
    if (t > 0)
367
449
    {
368
449
        const lzo_bytep ii = in + in_len - t;
369
370
449
        if (op == out && t <= 238)
371
34
            *op++ = LZO_BYTE(17 + t);
372
415
        else if (t <= 3)
373
0
            op[-2] = LZO_BYTE(op[-2] | t);
374
415
        else if (t <= 18)
375
209
            *op++ = LZO_BYTE(t - 3);
376
206
        else
377
206
        {
378
206
            lzo_uint tt = t - 18;
379
380
206
            *op++ = 0;
381
33.4k
            while (tt > 255)
382
33.1k
            {
383
33.1k
                tt -= 255;
384
33.1k
                UA_SET1(op, 0);
385
33.1k
                op++;
386
33.1k
            }
387
206
            assert(tt > 0);
388
206
            *op++ = LZO_BYTE(tt);
389
206
        }
390
449
        UA_COPYN(op, ii, t);
391
449
        op += t;
392
449
    }
393
394
450
    *op++ = M4_MARKER | 1;
395
450
    *op++ = 0;
396
450
    *op++ = 0;
397
398
450
    *out_len = pd(op, out);
399
450
    return LZO_E_OK;
400
450
}
lzo1x_1_12_compress
Line
Count
Source
340
509
{
341
509
    const lzo_bytep ip = in;
342
509
    lzo_bytep op = out;
343
509
    lzo_uint l = in_len;
344
509
    lzo_uint t = 0;
345
346
1.63k
    while (l > 20)
347
1.13k
    {
348
1.13k
        lzo_uint ll = l;
349
1.13k
        lzo_uintptr_t ll_end;
350
1.13k
#if 0 || (LZO_DETERMINISTIC)
351
1.13k
        ll = LZO_MIN(ll, 49152);
352
1.13k
#endif
353
1.13k
        ll_end = (lzo_uintptr_t)ip + ll;
354
1.13k
        if ((ll_end + ((t + ll) >> 5)) <= ll_end || (const lzo_bytep)(ll_end + ((t + ll) >> 5)) <= ip + ll)
355
6
            break;
356
1.12k
#if (LZO_DETERMINISTIC)
357
1.12k
        lzo_memset(wrkmem, 0, ((lzo_uint)1 << D_BITS) * sizeof(lzo_dict_t));
358
1.12k
#endif
359
1.12k
        t = do_compress(ip,ll,op,out_len,t,wrkmem);
360
1.12k
        ip += ll;
361
1.12k
        op += *out_len;
362
1.12k
        l  -= ll;
363
1.12k
    }
364
509
    t += l;
365
366
509
    if (t > 0)
367
508
    {
368
508
        const lzo_bytep ii = in + in_len - t;
369
370
508
        if (op == out && t <= 238)
371
28
            *op++ = LZO_BYTE(17 + t);
372
480
        else if (t <= 3)
373
0
            op[-2] = LZO_BYTE(op[-2] | t);
374
480
        else if (t <= 18)
375
231
            *op++ = LZO_BYTE(t - 3);
376
249
        else
377
249
        {
378
249
            lzo_uint tt = t - 18;
379
380
249
            *op++ = 0;
381
60.1k
            while (tt > 255)
382
59.9k
            {
383
59.9k
                tt -= 255;
384
59.9k
                UA_SET1(op, 0);
385
59.9k
                op++;
386
59.9k
            }
387
249
            assert(tt > 0);
388
249
            *op++ = LZO_BYTE(tt);
389
249
        }
390
508
        UA_COPYN(op, ii, t);
391
508
        op += t;
392
508
    }
393
394
509
    *op++ = M4_MARKER | 1;
395
509
    *op++ = 0;
396
509
    *op++ = 0;
397
398
509
    *out_len = pd(op, out);
399
509
    return LZO_E_OK;
400
509
}
lzo1x_1_15_compress
Line
Count
Source
340
483
{
341
483
    const lzo_bytep ip = in;
342
483
    lzo_bytep op = out;
343
483
    lzo_uint l = in_len;
344
483
    lzo_uint t = 0;
345
346
1.70k
    while (l > 20)
347
1.23k
    {
348
1.23k
        lzo_uint ll = l;
349
1.23k
        lzo_uintptr_t ll_end;
350
1.23k
#if 0 || (LZO_DETERMINISTIC)
351
1.23k
        ll = LZO_MIN(ll, 49152);
352
1.23k
#endif
353
1.23k
        ll_end = (lzo_uintptr_t)ip + ll;
354
1.23k
        if ((ll_end + ((t + ll) >> 5)) <= ll_end || (const lzo_bytep)(ll_end + ((t + ll) >> 5)) <= ip + ll)
355
6
            break;
356
1.22k
#if (LZO_DETERMINISTIC)
357
1.22k
        lzo_memset(wrkmem, 0, ((lzo_uint)1 << D_BITS) * sizeof(lzo_dict_t));
358
1.22k
#endif
359
1.22k
        t = do_compress(ip,ll,op,out_len,t,wrkmem);
360
1.22k
        ip += ll;
361
1.22k
        op += *out_len;
362
1.22k
        l  -= ll;
363
1.22k
    }
364
483
    t += l;
365
366
483
    if (t > 0)
367
482
    {
368
482
        const lzo_bytep ii = in + in_len - t;
369
370
482
        if (op == out && t <= 238)
371
40
            *op++ = LZO_BYTE(17 + t);
372
442
        else if (t <= 3)
373
0
            op[-2] = LZO_BYTE(op[-2] | t);
374
442
        else if (t <= 18)
375
222
            *op++ = LZO_BYTE(t - 3);
376
220
        else
377
220
        {
378
220
            lzo_uint tt = t - 18;
379
380
220
            *op++ = 0;
381
74.3k
            while (tt > 255)
382
74.0k
            {
383
74.0k
                tt -= 255;
384
74.0k
                UA_SET1(op, 0);
385
74.0k
                op++;
386
74.0k
            }
387
220
            assert(tt > 0);
388
220
            *op++ = LZO_BYTE(tt);
389
220
        }
390
482
        UA_COPYN(op, ii, t);
391
482
        op += t;
392
482
    }
393
394
483
    *op++ = M4_MARKER | 1;
395
483
    *op++ = 0;
396
483
    *op++ = 0;
397
398
483
    *out_len = pd(op, out);
399
483
    return LZO_E_OK;
400
483
}
lzo1y_1_compress
Line
Count
Source
340
453
{
341
453
    const lzo_bytep ip = in;
342
453
    lzo_bytep op = out;
343
453
    lzo_uint l = in_len;
344
453
    lzo_uint t = 0;
345
346
1.45k
    while (l > 20)
347
1.00k
    {
348
1.00k
        lzo_uint ll = l;
349
1.00k
        lzo_uintptr_t ll_end;
350
1.00k
#if 0 || (LZO_DETERMINISTIC)
351
1.00k
        ll = LZO_MIN(ll, 49152);
352
1.00k
#endif
353
1.00k
        ll_end = (lzo_uintptr_t)ip + ll;
354
1.00k
        if ((ll_end + ((t + ll) >> 5)) <= ll_end || (const lzo_bytep)(ll_end + ((t + ll) >> 5)) <= ip + ll)
355
2
            break;
356
1.00k
#if (LZO_DETERMINISTIC)
357
1.00k
        lzo_memset(wrkmem, 0, ((lzo_uint)1 << D_BITS) * sizeof(lzo_dict_t));
358
1.00k
#endif
359
1.00k
        t = do_compress(ip,ll,op,out_len,t,wrkmem);
360
1.00k
        ip += ll;
361
1.00k
        op += *out_len;
362
1.00k
        l  -= ll;
363
1.00k
    }
364
453
    t += l;
365
366
453
    if (t > 0)
367
452
    {
368
452
        const lzo_bytep ii = in + in_len - t;
369
370
452
        if (op == out && t <= 238)
371
21
            *op++ = LZO_BYTE(17 + t);
372
431
        else if (t <= 3)
373
0
            op[-2] = LZO_BYTE(op[-2] | t);
374
431
        else if (t <= 18)
375
218
            *op++ = LZO_BYTE(t - 3);
376
213
        else
377
213
        {
378
213
            lzo_uint tt = t - 18;
379
380
213
            *op++ = 0;
381
56.0k
            while (tt > 255)
382
55.8k
            {
383
55.8k
                tt -= 255;
384
55.8k
                UA_SET1(op, 0);
385
55.8k
                op++;
386
55.8k
            }
387
213
            assert(tt > 0);
388
213
            *op++ = LZO_BYTE(tt);
389
213
        }
390
452
        UA_COPYN(op, ii, t);
391
452
        op += t;
392
452
    }
393
394
453
    *op++ = M4_MARKER | 1;
395
453
    *op++ = 0;
396
453
    *op++ = 0;
397
398
453
    *out_len = pd(op, out);
399
453
    return LZO_E_OK;
400
453
}
401
402
403
/* vim:set ts=4 sw=4 et: */