Coverage Report

Created: 2026-01-10 07:02

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.95k
#  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.95k
{
45
5.95k
    const lzo_bytep ip;
46
5.95k
    lzo_bytep op;
47
5.95k
    const lzo_bytep const in_end = in + in_len;
48
5.95k
    const lzo_bytep const ip_end = in + in_len - 20;
49
5.95k
    const lzo_bytep ii;
50
5.95k
    lzo_dict_p const dict = (lzo_dict_p) wrkmem;
51
52
5.95k
    op = out;
53
5.95k
    ip = in;
54
5.95k
    ii = ip;
55
56
5.95k
    ip += ti < 4 ? 4 - ti : 0;
57
5.95k
    for (;;)
58
5.95k
    {
59
5.95k
        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.95k
        lzo_uint m_off;
100
5.95k
        lzo_uint m_len;
101
5.95k
        {
102
5.95k
        lzo_uint32_t dv;
103
5.95k
        lzo_uint dindex;
104
5.54M
literal:
105
5.54M
        ip += 1 + ((ip - ii) >> 5);
106
6.76M
next:
107
6.76M
        if __lzo_unlikely(ip >= ip_end)
108
5.95k
            break;
109
6.76M
        dv = UA_GET_LE32(ip);
110
6.76M
        dindex = DINDEX(dv,ip);
111
6.76M
        GINDEX(m_off,m_pos,in+dict,dindex,in);
112
6.76M
        UPDATE_I(dict,0,dindex,ip,in);
113
6.76M
        if __lzo_unlikely(dv != UA_GET_LE32(m_pos))
114
5.53M
            goto literal;
115
6.76M
        }
116
1.22M
#endif
117
118
    /* a match */
119
120
1.22M
        ii -= ti; ti = 0;
121
1.22M
        {
122
1.22M
        lzo_uint t = pd(ip,ii);
123
1.22M
        if (t != 0)
124
563k
        {
125
563k
            if (t <= 3)
126
307k
            {
127
307k
                op[-2] = LZO_BYTE(op[-2] | t);
128
307k
#if (LZO_OPT_UNALIGNED32)
129
307k
                UA_COPY4(op, ii);
130
307k
                op += t;
131
#else
132
                { do *op++ = *ii++; while (--t > 0); }
133
#endif
134
307k
            }
135
256k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
136
256k
            else if (t <= 16)
137
191k
            {
138
191k
                *op++ = LZO_BYTE(t - 3);
139
191k
                UA_COPY8(op, ii);
140
191k
                UA_COPY8(op+8, ii+8);
141
191k
                op += t;
142
191k
            }
143
64.3k
#endif
144
64.3k
            else
145
64.3k
            {
146
64.3k
                if (t <= 18)
147
7.75k
                    *op++ = LZO_BYTE(t - 3);
148
56.5k
                else
149
56.5k
                {
150
56.5k
                    lzo_uint tt = t - 18;
151
56.5k
                    *op++ = 0;
152
281k
                    while __lzo_unlikely(tt > 255)
153
225k
                    {
154
225k
                        tt -= 255;
155
225k
                        UA_SET1(op, 0);
156
225k
                        op++;
157
225k
                    }
158
56.5k
                    assert(tt > 0);
159
56.5k
                    *op++ = LZO_BYTE(tt);
160
56.5k
                }
161
64.3k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
162
3.82M
                do {
163
3.82M
                    UA_COPY8(op, ii);
164
3.82M
                    UA_COPY8(op+8, ii+8);
165
3.82M
                    op += 16; ii += 16; t -= 16;
166
3.82M
                } while (t >= 16); if (t > 0)
167
59.6k
#endif
168
396k
                { do *op++ = *ii++; while (--t > 0); }
169
64.3k
            }
170
563k
        }
171
1.22M
        }
172
1.22M
        m_len = 4;
173
1.22M
        {
174
1.22M
#if (LZO_OPT_UNALIGNED64)
175
1.22M
        lzo_uint64_t v;
176
1.22M
        v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
177
1.22M
        if __lzo_unlikely(v == 0) {
178
6.48M
            do {
179
6.48M
                m_len += 8;
180
6.48M
                v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
181
6.48M
                if __lzo_unlikely(ip + m_len >= ip_end)
182
1.47k
                    goto m_len_done;
183
6.48M
            } while (v == 0);
184
328k
        }
185
#if (LZO_ABI_BIG_ENDIAN) && defined(lzo_bitops_ctlz64)
186
        m_len += lzo_bitops_ctlz64(v) / CHAR_BIT;
187
#elif (LZO_ABI_BIG_ENDIAN)
188
        if ((v >> (64 - CHAR_BIT)) == 0) do {
189
            v <<= CHAR_BIT;
190
            m_len += 1;
191
        } while ((v >> (64 - CHAR_BIT)) == 0);
192
#elif (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_cttz64)
193
1.22M
        m_len += lzo_bitops_cttz64(v) / CHAR_BIT;
194
#elif (LZO_ABI_LITTLE_ENDIAN)
195
        if ((v & UCHAR_MAX) == 0) do {
196
            v >>= CHAR_BIT;
197
            m_len += 1;
198
        } while ((v & UCHAR_MAX) == 0);
199
#else
200
        if (ip[m_len] == m_pos[m_len]) do {
201
            m_len += 1;
202
        } while (ip[m_len] == m_pos[m_len]);
203
#endif
204
#elif (LZO_OPT_UNALIGNED32)
205
        lzo_uint32_t v;
206
        v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len);
207
        if __lzo_unlikely(v == 0) {
208
            do {
209
                m_len += 4;
210
                v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len);
211
                if (v != 0)
212
                    break;
213
                m_len += 4;
214
                v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len);
215
                if __lzo_unlikely(ip + m_len >= ip_end)
216
                    goto m_len_done;
217
            } while (v == 0);
218
        }
219
#if (LZO_ABI_BIG_ENDIAN) && defined(lzo_bitops_ctlz32)
220
        m_len += lzo_bitops_ctlz32(v) / CHAR_BIT;
221
#elif (LZO_ABI_BIG_ENDIAN)
222
        if ((v >> (32 - CHAR_BIT)) == 0) do {
223
            v <<= CHAR_BIT;
224
            m_len += 1;
225
        } while ((v >> (32 - CHAR_BIT)) == 0);
226
#elif (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_cttz32)
227
        m_len += lzo_bitops_cttz32(v) / CHAR_BIT;
228
#elif (LZO_ABI_LITTLE_ENDIAN)
229
        if ((v & UCHAR_MAX) == 0) do {
230
            v >>= CHAR_BIT;
231
            m_len += 1;
232
        } while ((v & UCHAR_MAX) == 0);
233
#else
234
        if (ip[m_len] == m_pos[m_len]) do {
235
            m_len += 1;
236
        } while (ip[m_len] == m_pos[m_len]);
237
#endif
238
#else
239
        if __lzo_unlikely(ip[m_len] == m_pos[m_len]) {
240
            do {
241
                m_len += 1;
242
                if (ip[m_len] != m_pos[m_len])
243
                    break;
244
                m_len += 1;
245
                if (ip[m_len] != m_pos[m_len])
246
                    break;
247
                m_len += 1;
248
                if (ip[m_len] != m_pos[m_len])
249
                    break;
250
                m_len += 1;
251
                if (ip[m_len] != m_pos[m_len])
252
                    break;
253
                m_len += 1;
254
                if (ip[m_len] != m_pos[m_len])
255
                    break;
256
                m_len += 1;
257
                if (ip[m_len] != m_pos[m_len])
258
                    break;
259
                m_len += 1;
260
                if (ip[m_len] != m_pos[m_len])
261
                    break;
262
                m_len += 1;
263
                if __lzo_unlikely(ip + m_len >= ip_end)
264
                    goto m_len_done;
265
            } while (ip[m_len] == m_pos[m_len]);
266
        }
267
#endif
268
1.22M
        }
269
1.22M
m_len_done:
270
1.22M
        m_off = pd(ip,m_pos);
271
1.22M
        ip += m_len;
272
1.22M
        ii = ip;
273
1.22M
        if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
274
633k
        {
275
633k
            m_off -= 1;
276
#if defined(LZO1X)
277
507k
            *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2));
278
507k
            *op++ = LZO_BYTE(m_off >> 3);
279
#elif defined(LZO1Y)
280
125k
            *op++ = LZO_BYTE(((m_len + 1) << 4) | ((m_off & 3) << 2));
281
125k
            *op++ = LZO_BYTE(m_off >> 2);
282
#endif
283
633k
        }
284
592k
        else if (m_off <= M3_MAX_OFFSET)
285
523k
        {
286
523k
            m_off -= 1;
287
523k
            if (m_len <= M3_MAX_LEN)
288
381k
                *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
289
142k
            else
290
142k
            {
291
142k
                m_len -= M3_MAX_LEN;
292
142k
                *op++ = M3_MARKER | 0;
293
259k
                while __lzo_unlikely(m_len > 255)
294
117k
                {
295
117k
                    m_len -= 255;
296
117k
                    UA_SET1(op, 0);
297
117k
                    op++;
298
117k
                }
299
142k
                *op++ = LZO_BYTE(m_len);
300
142k
            }
301
523k
            *op++ = LZO_BYTE(m_off << 2);
302
523k
            *op++ = LZO_BYTE(m_off >> 6);
303
523k
        }
304
68.7k
        else
305
68.7k
        {
306
68.7k
            m_off -= 0x4000;
307
68.7k
            if (m_len <= M4_MAX_LEN)
308
38.8k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8) | (m_len - 2));
309
29.8k
            else
310
29.8k
            {
311
29.8k
                m_len -= M4_MAX_LEN;
312
29.8k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8));
313
56.0k
                while __lzo_unlikely(m_len > 255)
314
26.1k
                {
315
26.1k
                    m_len -= 255;
316
26.1k
                    UA_SET1(op, 0);
317
26.1k
                    op++;
318
26.1k
                }
319
29.8k
                *op++ = LZO_BYTE(m_len);
320
29.8k
            }
321
68.7k
            *op++ = LZO_BYTE(m_off << 2);
322
68.7k
            *op++ = LZO_BYTE(m_off >> 6);
323
68.7k
        }
324
1.22M
        goto next;
325
1.22M
    }
326
327
5.95k
    *out_len = pd(op, out);
328
5.95k
    return pd(in_end,ii-ti);
329
5.95k
}
lzo1x_1.c:lzo1x_1_compress_core
Line
Count
Source
44
2.87k
{
45
2.87k
    const lzo_bytep ip;
46
2.87k
    lzo_bytep op;
47
2.87k
    const lzo_bytep const in_end = in + in_len;
48
2.87k
    const lzo_bytep const ip_end = in + in_len - 20;
49
2.87k
    const lzo_bytep ii;
50
2.87k
    lzo_dict_p const dict = (lzo_dict_p) wrkmem;
51
52
2.87k
    op = out;
53
2.87k
    ip = in;
54
2.87k
    ii = ip;
55
56
2.87k
    ip += ti < 4 ? 4 - ti : 0;
57
2.87k
    for (;;)
58
2.87k
    {
59
2.87k
        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
2.87k
        lzo_uint m_off;
100
2.87k
        lzo_uint m_len;
101
2.87k
        {
102
2.87k
        lzo_uint32_t dv;
103
2.87k
        lzo_uint dindex;
104
2.08M
literal:
105
2.08M
        ip += 1 + ((ip - ii) >> 5);
106
2.40M
next:
107
2.40M
        if __lzo_unlikely(ip >= ip_end)
108
2.87k
            break;
109
2.40M
        dv = UA_GET_LE32(ip);
110
2.40M
        dindex = DINDEX(dv,ip);
111
2.40M
        GINDEX(m_off,m_pos,in+dict,dindex,in);
112
2.40M
        UPDATE_I(dict,0,dindex,ip,in);
113
2.40M
        if __lzo_unlikely(dv != UA_GET_LE32(m_pos))
114
2.07M
            goto literal;
115
2.40M
        }
116
328k
#endif
117
118
    /* a match */
119
120
328k
        ii -= ti; ti = 0;
121
328k
        {
122
328k
        lzo_uint t = pd(ip,ii);
123
328k
        if (t != 0)
124
168k
        {
125
168k
            if (t <= 3)
126
91.7k
            {
127
91.7k
                op[-2] = LZO_BYTE(op[-2] | t);
128
91.7k
#if (LZO_OPT_UNALIGNED32)
129
91.7k
                UA_COPY4(op, ii);
130
91.7k
                op += t;
131
#else
132
                { do *op++ = *ii++; while (--t > 0); }
133
#endif
134
91.7k
            }
135
76.3k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
136
76.3k
            else if (t <= 16)
137
52.8k
            {
138
52.8k
                *op++ = LZO_BYTE(t - 3);
139
52.8k
                UA_COPY8(op, ii);
140
52.8k
                UA_COPY8(op+8, ii+8);
141
52.8k
                op += t;
142
52.8k
            }
143
23.4k
#endif
144
23.4k
            else
145
23.4k
            {
146
23.4k
                if (t <= 18)
147
3.12k
                    *op++ = LZO_BYTE(t - 3);
148
20.3k
                else
149
20.3k
                {
150
20.3k
                    lzo_uint tt = t - 18;
151
20.3k
                    *op++ = 0;
152
163k
                    while __lzo_unlikely(tt > 255)
153
143k
                    {
154
143k
                        tt -= 255;
155
143k
                        UA_SET1(op, 0);
156
143k
                        op++;
157
143k
                    }
158
20.3k
                    assert(tt > 0);
159
20.3k
                    *op++ = LZO_BYTE(tt);
160
20.3k
                }
161
23.4k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
162
2.37M
                do {
163
2.37M
                    UA_COPY8(op, ii);
164
2.37M
                    UA_COPY8(op+8, ii+8);
165
2.37M
                    op += 16; ii += 16; t -= 16;
166
2.37M
                } while (t >= 16); if (t > 0)
167
21.5k
#endif
168
142k
                { do *op++ = *ii++; while (--t > 0); }
169
23.4k
            }
170
168k
        }
171
328k
        }
172
328k
        m_len = 4;
173
328k
        {
174
328k
#if (LZO_OPT_UNALIGNED64)
175
328k
        lzo_uint64_t v;
176
328k
        v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
177
328k
        if __lzo_unlikely(v == 0) {
178
2.00M
            do {
179
2.00M
                m_len += 8;
180
2.00M
                v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
181
2.00M
                if __lzo_unlikely(ip + m_len >= ip_end)
182
481
                    goto m_len_done;
183
2.00M
            } while (v == 0);
184
126k
        }
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
328k
        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
328k
        }
269
328k
m_len_done:
270
328k
        m_off = pd(ip,m_pos);
271
328k
        ip += m_len;
272
328k
        ii = ip;
273
328k
        if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
274
134k
        {
275
134k
            m_off -= 1;
276
134k
#if defined(LZO1X)
277
134k
            *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2));
278
134k
            *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
134k
        }
284
194k
        else if (m_off <= M3_MAX_OFFSET)
285
171k
        {
286
171k
            m_off -= 1;
287
171k
            if (m_len <= M3_MAX_LEN)
288
113k
                *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
289
58.4k
            else
290
58.4k
            {
291
58.4k
                m_len -= M3_MAX_LEN;
292
58.4k
                *op++ = M3_MARKER | 0;
293
89.3k
                while __lzo_unlikely(m_len > 255)
294
30.8k
                {
295
30.8k
                    m_len -= 255;
296
30.8k
                    UA_SET1(op, 0);
297
30.8k
                    op++;
298
30.8k
                }
299
58.4k
                *op++ = LZO_BYTE(m_len);
300
58.4k
            }
301
171k
            *op++ = LZO_BYTE(m_off << 2);
302
171k
            *op++ = LZO_BYTE(m_off >> 6);
303
171k
        }
304
22.2k
        else
305
22.2k
        {
306
22.2k
            m_off -= 0x4000;
307
22.2k
            if (m_len <= M4_MAX_LEN)
308
9.75k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8) | (m_len - 2));
309
12.4k
            else
310
12.4k
            {
311
12.4k
                m_len -= M4_MAX_LEN;
312
12.4k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8));
313
22.9k
                while __lzo_unlikely(m_len > 255)
314
10.4k
                {
315
10.4k
                    m_len -= 255;
316
10.4k
                    UA_SET1(op, 0);
317
10.4k
                    op++;
318
10.4k
                }
319
12.4k
                *op++ = LZO_BYTE(m_len);
320
12.4k
            }
321
22.2k
            *op++ = LZO_BYTE(m_off << 2);
322
22.2k
            *op++ = LZO_BYTE(m_off >> 6);
323
22.2k
        }
324
328k
        goto next;
325
328k
    }
326
327
2.87k
    *out_len = pd(op, out);
328
2.87k
    return pd(in_end,ii-ti);
329
2.87k
}
lzo1x_1k.c:lzo1x_1_11_compress_core
Line
Count
Source
44
815
{
45
815
    const lzo_bytep ip;
46
815
    lzo_bytep op;
47
815
    const lzo_bytep const in_end = in + in_len;
48
815
    const lzo_bytep const ip_end = in + in_len - 20;
49
815
    const lzo_bytep ii;
50
815
    lzo_dict_p const dict = (lzo_dict_p) wrkmem;
51
52
815
    op = out;
53
815
    ip = in;
54
815
    ii = ip;
55
56
815
    ip += ti < 4 ? 4 - ti : 0;
57
815
    for (;;)
58
815
    {
59
815
        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
815
        lzo_uint m_off;
100
815
        lzo_uint m_len;
101
815
        {
102
815
        lzo_uint32_t dv;
103
815
        lzo_uint dindex;
104
906k
literal:
105
906k
        ip += 1 + ((ip - ii) >> 5);
106
1.11M
next:
107
1.11M
        if __lzo_unlikely(ip >= ip_end)
108
815
            break;
109
1.11M
        dv = UA_GET_LE32(ip);
110
1.11M
        dindex = DINDEX(dv,ip);
111
1.11M
        GINDEX(m_off,m_pos,in+dict,dindex,in);
112
1.11M
        UPDATE_I(dict,0,dindex,ip,in);
113
1.11M
        if __lzo_unlikely(dv != UA_GET_LE32(m_pos))
114
905k
            goto literal;
115
1.11M
        }
116
212k
#endif
117
118
    /* a match */
119
120
212k
        ii -= ti; ti = 0;
121
212k
        {
122
212k
        lzo_uint t = pd(ip,ii);
123
212k
        if (t != 0)
124
97.0k
        {
125
97.0k
            if (t <= 3)
126
52.9k
            {
127
52.9k
                op[-2] = LZO_BYTE(op[-2] | t);
128
52.9k
#if (LZO_OPT_UNALIGNED32)
129
52.9k
                UA_COPY4(op, ii);
130
52.9k
                op += t;
131
#else
132
                { do *op++ = *ii++; while (--t > 0); }
133
#endif
134
52.9k
            }
135
44.1k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
136
44.1k
            else if (t <= 16)
137
33.0k
            {
138
33.0k
                *op++ = LZO_BYTE(t - 3);
139
33.0k
                UA_COPY8(op, ii);
140
33.0k
                UA_COPY8(op+8, ii+8);
141
33.0k
                op += t;
142
33.0k
            }
143
11.0k
#endif
144
11.0k
            else
145
11.0k
            {
146
11.0k
                if (t <= 18)
147
1.20k
                    *op++ = LZO_BYTE(t - 3);
148
9.87k
                else
149
9.87k
                {
150
9.87k
                    lzo_uint tt = t - 18;
151
9.87k
                    *op++ = 0;
152
30.8k
                    while __lzo_unlikely(tt > 255)
153
20.9k
                    {
154
20.9k
                        tt -= 255;
155
20.9k
                        UA_SET1(op, 0);
156
20.9k
                        op++;
157
20.9k
                    }
158
9.87k
                    assert(tt > 0);
159
9.87k
                    *op++ = LZO_BYTE(tt);
160
9.87k
                }
161
11.0k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
162
373k
                do {
163
373k
                    UA_COPY8(op, ii);
164
373k
                    UA_COPY8(op+8, ii+8);
165
373k
                    op += 16; ii += 16; t -= 16;
166
373k
                } while (t >= 16); if (t > 0)
167
10.4k
#endif
168
70.2k
                { do *op++ = *ii++; while (--t > 0); }
169
11.0k
            }
170
97.0k
        }
171
212k
        }
172
212k
        m_len = 4;
173
212k
        {
174
212k
#if (LZO_OPT_UNALIGNED64)
175
212k
        lzo_uint64_t v;
176
212k
        v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
177
212k
        if __lzo_unlikely(v == 0) {
178
1.02M
            do {
179
1.02M
                m_len += 8;
180
1.02M
                v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
181
1.02M
                if __lzo_unlikely(ip + m_len >= ip_end)
182
218
                    goto m_len_done;
183
1.02M
            } while (v == 0);
184
44.8k
        }
185
#if (LZO_ABI_BIG_ENDIAN) && defined(lzo_bitops_ctlz64)
186
        m_len += lzo_bitops_ctlz64(v) / CHAR_BIT;
187
#elif (LZO_ABI_BIG_ENDIAN)
188
        if ((v >> (64 - CHAR_BIT)) == 0) do {
189
            v <<= CHAR_BIT;
190
            m_len += 1;
191
        } while ((v >> (64 - CHAR_BIT)) == 0);
192
#elif (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_cttz64)
193
212k
        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
212k
        }
269
212k
m_len_done:
270
212k
        m_off = pd(ip,m_pos);
271
212k
        ip += m_len;
272
212k
        ii = ip;
273
212k
        if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
274
126k
        {
275
126k
            m_off -= 1;
276
126k
#if defined(LZO1X)
277
126k
            *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2));
278
126k
            *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
126k
        }
284
85.3k
        else if (m_off <= M3_MAX_OFFSET)
285
78.3k
        {
286
78.3k
            m_off -= 1;
287
78.3k
            if (m_len <= M3_MAX_LEN)
288
59.2k
                *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
289
19.1k
            else
290
19.1k
            {
291
19.1k
                m_len -= M3_MAX_LEN;
292
19.1k
                *op++ = M3_MARKER | 0;
293
39.6k
                while __lzo_unlikely(m_len > 255)
294
20.5k
                {
295
20.5k
                    m_len -= 255;
296
20.5k
                    UA_SET1(op, 0);
297
20.5k
                    op++;
298
20.5k
                }
299
19.1k
                *op++ = LZO_BYTE(m_len);
300
19.1k
            }
301
78.3k
            *op++ = LZO_BYTE(m_off << 2);
302
78.3k
            *op++ = LZO_BYTE(m_off >> 6);
303
78.3k
        }
304
6.97k
        else
305
6.97k
        {
306
6.97k
            m_off -= 0x4000;
307
6.97k
            if (m_len <= M4_MAX_LEN)
308
4.19k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8) | (m_len - 2));
309
2.78k
            else
310
2.78k
            {
311
2.78k
                m_len -= M4_MAX_LEN;
312
2.78k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8));
313
5.76k
                while __lzo_unlikely(m_len > 255)
314
2.98k
                {
315
2.98k
                    m_len -= 255;
316
2.98k
                    UA_SET1(op, 0);
317
2.98k
                    op++;
318
2.98k
                }
319
2.78k
                *op++ = LZO_BYTE(m_len);
320
2.78k
            }
321
6.97k
            *op++ = LZO_BYTE(m_off << 2);
322
6.97k
            *op++ = LZO_BYTE(m_off >> 6);
323
6.97k
        }
324
212k
        goto next;
325
212k
    }
326
327
815
    *out_len = pd(op, out);
328
815
    return pd(in_end,ii-ti);
329
815
}
lzo1x_1l.c:lzo1x_1_12_compress_core
Line
Count
Source
44
724
{
45
724
    const lzo_bytep ip;
46
724
    lzo_bytep op;
47
724
    const lzo_bytep const in_end = in + in_len;
48
724
    const lzo_bytep const ip_end = in + in_len - 20;
49
724
    const lzo_bytep ii;
50
724
    lzo_dict_p const dict = (lzo_dict_p) wrkmem;
51
52
724
    op = out;
53
724
    ip = in;
54
724
    ii = ip;
55
56
724
    ip += ti < 4 ? 4 - ti : 0;
57
724
    for (;;)
58
724
    {
59
724
        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
724
        lzo_uint m_off;
100
724
        lzo_uint m_len;
101
724
        {
102
724
        lzo_uint32_t dv;
103
724
        lzo_uint dindex;
104
904k
literal:
105
904k
        ip += 1 + ((ip - ii) >> 5);
106
1.12M
next:
107
1.12M
        if __lzo_unlikely(ip >= ip_end)
108
724
            break;
109
1.12M
        dv = UA_GET_LE32(ip);
110
1.12M
        dindex = DINDEX(dv,ip);
111
1.12M
        GINDEX(m_off,m_pos,in+dict,dindex,in);
112
1.12M
        UPDATE_I(dict,0,dindex,ip,in);
113
1.12M
        if __lzo_unlikely(dv != UA_GET_LE32(m_pos))
114
903k
            goto literal;
115
1.12M
        }
116
224k
#endif
117
118
    /* a match */
119
120
224k
        ii -= ti; ti = 0;
121
224k
        {
122
224k
        lzo_uint t = pd(ip,ii);
123
224k
        if (t != 0)
124
110k
        {
125
110k
            if (t <= 3)
126
61.5k
            {
127
61.5k
                op[-2] = LZO_BYTE(op[-2] | t);
128
61.5k
#if (LZO_OPT_UNALIGNED32)
129
61.5k
                UA_COPY4(op, ii);
130
61.5k
                op += t;
131
#else
132
                { do *op++ = *ii++; while (--t > 0); }
133
#endif
134
61.5k
            }
135
48.5k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
136
48.5k
            else if (t <= 16)
137
38.0k
            {
138
38.0k
                *op++ = LZO_BYTE(t - 3);
139
38.0k
                UA_COPY8(op, ii);
140
38.0k
                UA_COPY8(op+8, ii+8);
141
38.0k
                op += t;
142
38.0k
            }
143
10.5k
#endif
144
10.5k
            else
145
10.5k
            {
146
10.5k
                if (t <= 18)
147
1.29k
                    *op++ = LZO_BYTE(t - 3);
148
9.21k
                else
149
9.21k
                {
150
9.21k
                    lzo_uint tt = t - 18;
151
9.21k
                    *op++ = 0;
152
26.4k
                    while __lzo_unlikely(tt > 255)
153
17.2k
                    {
154
17.2k
                        tt -= 255;
155
17.2k
                        UA_SET1(op, 0);
156
17.2k
                        op++;
157
17.2k
                    }
158
9.21k
                    assert(tt > 0);
159
9.21k
                    *op++ = LZO_BYTE(tt);
160
9.21k
                }
161
10.5k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
162
312k
                do {
163
312k
                    UA_COPY8(op, ii);
164
312k
                    UA_COPY8(op+8, ii+8);
165
312k
                    op += 16; ii += 16; t -= 16;
166
312k
                } while (t >= 16); if (t > 0)
167
9.87k
#endif
168
66.2k
                { do *op++ = *ii++; while (--t > 0); }
169
10.5k
            }
170
110k
        }
171
224k
        }
172
224k
        m_len = 4;
173
224k
        {
174
224k
#if (LZO_OPT_UNALIGNED64)
175
224k
        lzo_uint64_t v;
176
224k
        v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
177
224k
        if __lzo_unlikely(v == 0) {
178
1.01M
            do {
179
1.01M
                m_len += 8;
180
1.01M
                v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
181
1.01M
                if __lzo_unlikely(ip + m_len >= ip_end)
182
241
                    goto m_len_done;
183
1.01M
            } while (v == 0);
184
59.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
224k
        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
224k
        }
269
224k
m_len_done:
270
224k
        m_off = pd(ip,m_pos);
271
224k
        ip += m_len;
272
224k
        ii = ip;
273
224k
        if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
274
110k
        {
275
110k
            m_off -= 1;
276
110k
#if defined(LZO1X)
277
110k
            *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2));
278
110k
            *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
110k
        }
284
113k
        else if (m_off <= M3_MAX_OFFSET)
285
99.6k
        {
286
99.6k
            m_off -= 1;
287
99.6k
            if (m_len <= M3_MAX_LEN)
288
75.3k
                *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
289
24.2k
            else
290
24.2k
            {
291
24.2k
                m_len -= M3_MAX_LEN;
292
24.2k
                *op++ = M3_MARKER | 0;
293
41.0k
                while __lzo_unlikely(m_len > 255)
294
16.8k
                {
295
16.8k
                    m_len -= 255;
296
16.8k
                    UA_SET1(op, 0);
297
16.8k
                    op++;
298
16.8k
                }
299
24.2k
                *op++ = LZO_BYTE(m_len);
300
24.2k
            }
301
99.6k
            *op++ = LZO_BYTE(m_off << 2);
302
99.6k
            *op++ = LZO_BYTE(m_off >> 6);
303
99.6k
        }
304
14.0k
        else
305
14.0k
        {
306
14.0k
            m_off -= 0x4000;
307
14.0k
            if (m_len <= M4_MAX_LEN)
308
8.01k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8) | (m_len - 2));
309
6.01k
            else
310
6.01k
            {
311
6.01k
                m_len -= M4_MAX_LEN;
312
6.01k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8));
313
10.1k
                while __lzo_unlikely(m_len > 255)
314
4.14k
                {
315
4.14k
                    m_len -= 255;
316
4.14k
                    UA_SET1(op, 0);
317
4.14k
                    op++;
318
4.14k
                }
319
6.01k
                *op++ = LZO_BYTE(m_len);
320
6.01k
            }
321
14.0k
            *op++ = LZO_BYTE(m_off << 2);
322
14.0k
            *op++ = LZO_BYTE(m_off >> 6);
323
14.0k
        }
324
224k
        goto next;
325
224k
    }
326
327
724
    *out_len = pd(op, out);
328
724
    return pd(in_end,ii-ti);
329
724
}
lzo1x_1o.c:lzo1x_1_15_compress_core
Line
Count
Source
44
648
{
45
648
    const lzo_bytep ip;
46
648
    lzo_bytep op;
47
648
    const lzo_bytep const in_end = in + in_len;
48
648
    const lzo_bytep const ip_end = in + in_len - 20;
49
648
    const lzo_bytep ii;
50
648
    lzo_dict_p const dict = (lzo_dict_p) wrkmem;
51
52
648
    op = out;
53
648
    ip = in;
54
648
    ii = ip;
55
56
648
    ip += ti < 4 ? 4 - ti : 0;
57
648
    for (;;)
58
648
    {
59
648
        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
648
        lzo_uint m_off;
100
648
        lzo_uint m_len;
101
648
        {
102
648
        lzo_uint32_t dv;
103
648
        lzo_uint dindex;
104
767k
literal:
105
767k
        ip += 1 + ((ip - ii) >> 5);
106
999k
next:
107
999k
        if __lzo_unlikely(ip >= ip_end)
108
648
            break;
109
998k
        dv = UA_GET_LE32(ip);
110
998k
        dindex = DINDEX(dv,ip);
111
998k
        GINDEX(m_off,m_pos,in+dict,dindex,in);
112
998k
        UPDATE_I(dict,0,dindex,ip,in);
113
998k
        if __lzo_unlikely(dv != UA_GET_LE32(m_pos))
114
767k
            goto literal;
115
998k
        }
116
231k
#endif
117
118
    /* a match */
119
120
231k
        ii -= ti; ti = 0;
121
231k
        {
122
231k
        lzo_uint t = pd(ip,ii);
123
231k
        if (t != 0)
124
86.7k
        {
125
86.7k
            if (t <= 3)
126
46.5k
            {
127
46.5k
                op[-2] = LZO_BYTE(op[-2] | t);
128
46.5k
#if (LZO_OPT_UNALIGNED32)
129
46.5k
                UA_COPY4(op, ii);
130
46.5k
                op += t;
131
#else
132
                { do *op++ = *ii++; while (--t > 0); }
133
#endif
134
46.5k
            }
135
40.2k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
136
40.2k
            else if (t <= 16)
137
30.7k
            {
138
30.7k
                *op++ = LZO_BYTE(t - 3);
139
30.7k
                UA_COPY8(op, ii);
140
30.7k
                UA_COPY8(op+8, ii+8);
141
30.7k
                op += t;
142
30.7k
            }
143
9.44k
#endif
144
9.44k
            else
145
9.44k
            {
146
9.44k
                if (t <= 18)
147
943
                    *op++ = LZO_BYTE(t - 3);
148
8.50k
                else
149
8.50k
                {
150
8.50k
                    lzo_uint tt = t - 18;
151
8.50k
                    *op++ = 0;
152
23.9k
                    while __lzo_unlikely(tt > 255)
153
15.4k
                    {
154
15.4k
                        tt -= 255;
155
15.4k
                        UA_SET1(op, 0);
156
15.4k
                        op++;
157
15.4k
                    }
158
8.50k
                    assert(tt > 0);
159
8.50k
                    *op++ = LZO_BYTE(tt);
160
8.50k
                }
161
9.44k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
162
279k
                do {
163
279k
                    UA_COPY8(op, ii);
164
279k
                    UA_COPY8(op+8, ii+8);
165
279k
                    op += 16; ii += 16; t -= 16;
166
279k
                } while (t >= 16); if (t > 0)
167
8.66k
#endif
168
58.5k
                { do *op++ = *ii++; while (--t > 0); }
169
9.44k
            }
170
86.7k
        }
171
231k
        }
172
231k
        m_len = 4;
173
231k
        {
174
231k
#if (LZO_OPT_UNALIGNED64)
175
231k
        lzo_uint64_t v;
176
231k
        v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
177
231k
        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
237
                    goto m_len_done;
183
1.11M
            } while (v == 0);
184
40.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
231k
        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
231k
        }
269
231k
m_len_done:
270
231k
        m_off = pd(ip,m_pos);
271
231k
        ip += m_len;
272
231k
        ii = ip;
273
231k
        if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
274
135k
        {
275
135k
            m_off -= 1;
276
135k
#if defined(LZO1X)
277
135k
            *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2));
278
135k
            *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
135k
        }
284
96.0k
        else if (m_off <= M3_MAX_OFFSET)
285
83.0k
        {
286
83.0k
            m_off -= 1;
287
83.0k
            if (m_len <= M3_MAX_LEN)
288
67.0k
                *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
289
15.9k
            else
290
15.9k
            {
291
15.9k
                m_len -= M3_MAX_LEN;
292
15.9k
                *op++ = M3_MARKER | 0;
293
39.0k
                while __lzo_unlikely(m_len > 255)
294
23.1k
                {
295
23.1k
                    m_len -= 255;
296
23.1k
                    UA_SET1(op, 0);
297
23.1k
                    op++;
298
23.1k
                }
299
15.9k
                *op++ = LZO_BYTE(m_len);
300
15.9k
            }
301
83.0k
            *op++ = LZO_BYTE(m_off << 2);
302
83.0k
            *op++ = LZO_BYTE(m_off >> 6);
303
83.0k
        }
304
13.0k
        else
305
13.0k
        {
306
13.0k
            m_off -= 0x4000;
307
13.0k
            if (m_len <= M4_MAX_LEN)
308
9.05k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8) | (m_len - 2));
309
3.97k
            else
310
3.97k
            {
311
3.97k
                m_len -= M4_MAX_LEN;
312
3.97k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8));
313
7.97k
                while __lzo_unlikely(m_len > 255)
314
4.00k
                {
315
4.00k
                    m_len -= 255;
316
4.00k
                    UA_SET1(op, 0);
317
4.00k
                    op++;
318
4.00k
                }
319
3.97k
                *op++ = LZO_BYTE(m_len);
320
3.97k
            }
321
13.0k
            *op++ = LZO_BYTE(m_off << 2);
322
13.0k
            *op++ = LZO_BYTE(m_off >> 6);
323
13.0k
        }
324
231k
        goto next;
325
231k
    }
326
327
648
    *out_len = pd(op, out);
328
648
    return pd(in_end,ii-ti);
329
648
}
lzo1y_1.c:lzo1y_1_compress_core
Line
Count
Source
44
888
{
45
888
    const lzo_bytep ip;
46
888
    lzo_bytep op;
47
888
    const lzo_bytep const in_end = in + in_len;
48
888
    const lzo_bytep const ip_end = in + in_len - 20;
49
888
    const lzo_bytep ii;
50
888
    lzo_dict_p const dict = (lzo_dict_p) wrkmem;
51
52
888
    op = out;
53
888
    ip = in;
54
888
    ii = ip;
55
56
888
    ip += ti < 4 ? 4 - ti : 0;
57
888
    for (;;)
58
888
    {
59
888
        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
888
        lzo_uint m_off;
100
888
        lzo_uint m_len;
101
888
        {
102
888
        lzo_uint32_t dv;
103
888
        lzo_uint dindex;
104
880k
literal:
105
880k
        ip += 1 + ((ip - ii) >> 5);
106
1.10M
next:
107
1.10M
        if __lzo_unlikely(ip >= ip_end)
108
888
            break;
109
1.10M
        dv = UA_GET_LE32(ip);
110
1.10M
        dindex = DINDEX(dv,ip);
111
1.10M
        GINDEX(m_off,m_pos,in+dict,dindex,in);
112
1.10M
        UPDATE_I(dict,0,dindex,ip,in);
113
1.10M
        if __lzo_unlikely(dv != UA_GET_LE32(m_pos))
114
879k
            goto literal;
115
1.10M
        }
116
229k
#endif
117
118
    /* a match */
119
120
229k
        ii -= ti; ti = 0;
121
229k
        {
122
229k
        lzo_uint t = pd(ip,ii);
123
229k
        if (t != 0)
124
101k
        {
125
101k
            if (t <= 3)
126
54.7k
            {
127
54.7k
                op[-2] = LZO_BYTE(op[-2] | t);
128
54.7k
#if (LZO_OPT_UNALIGNED32)
129
54.7k
                UA_COPY4(op, ii);
130
54.7k
                op += t;
131
#else
132
                { do *op++ = *ii++; while (--t > 0); }
133
#endif
134
54.7k
            }
135
46.8k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
136
46.8k
            else if (t <= 16)
137
36.9k
            {
138
36.9k
                *op++ = LZO_BYTE(t - 3);
139
36.9k
                UA_COPY8(op, ii);
140
36.9k
                UA_COPY8(op+8, ii+8);
141
36.9k
                op += t;
142
36.9k
            }
143
9.88k
#endif
144
9.88k
            else
145
9.88k
            {
146
9.88k
                if (t <= 18)
147
1.18k
                    *op++ = LZO_BYTE(t - 3);
148
8.69k
                else
149
8.69k
                {
150
8.69k
                    lzo_uint tt = t - 18;
151
8.69k
                    *op++ = 0;
152
37.0k
                    while __lzo_unlikely(tt > 255)
153
28.3k
                    {
154
28.3k
                        tt -= 255;
155
28.3k
                        UA_SET1(op, 0);
156
28.3k
                        op++;
157
28.3k
                    }
158
8.69k
                    assert(tt > 0);
159
8.69k
                    *op++ = LZO_BYTE(tt);
160
8.69k
                }
161
9.88k
#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64)
162
486k
                do {
163
486k
                    UA_COPY8(op, ii);
164
486k
                    UA_COPY8(op+8, ii+8);
165
486k
                    op += 16; ii += 16; t -= 16;
166
486k
                } while (t >= 16); if (t > 0)
167
9.04k
#endif
168
59.4k
                { do *op++ = *ii++; while (--t > 0); }
169
9.88k
            }
170
101k
        }
171
229k
        }
172
229k
        m_len = 4;
173
229k
        {
174
229k
#if (LZO_OPT_UNALIGNED64)
175
229k
        lzo_uint64_t v;
176
229k
        v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
177
229k
        if __lzo_unlikely(v == 0) {
178
1.32M
            do {
179
1.32M
                m_len += 8;
180
1.32M
                v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len);
181
1.32M
                if __lzo_unlikely(ip + m_len >= ip_end)
182
294
                    goto m_len_done;
183
1.32M
            } while (v == 0);
184
57.8k
        }
185
#if (LZO_ABI_BIG_ENDIAN) && defined(lzo_bitops_ctlz64)
186
        m_len += lzo_bitops_ctlz64(v) / CHAR_BIT;
187
#elif (LZO_ABI_BIG_ENDIAN)
188
        if ((v >> (64 - CHAR_BIT)) == 0) do {
189
            v <<= CHAR_BIT;
190
            m_len += 1;
191
        } while ((v >> (64 - CHAR_BIT)) == 0);
192
#elif (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_cttz64)
193
228k
        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
228k
        }
269
229k
m_len_done:
270
229k
        m_off = pd(ip,m_pos);
271
229k
        ip += m_len;
272
229k
        ii = ip;
273
229k
        if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
274
125k
        {
275
125k
            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
125k
            *op++ = LZO_BYTE(((m_len + 1) << 4) | ((m_off & 3) << 2));
281
125k
            *op++ = LZO_BYTE(m_off >> 2);
282
125k
#endif
283
125k
        }
284
103k
        else if (m_off <= M3_MAX_OFFSET)
285
91.0k
        {
286
91.0k
            m_off -= 1;
287
91.0k
            if (m_len <= M3_MAX_LEN)
288
66.6k
                *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
289
24.4k
            else
290
24.4k
            {
291
24.4k
                m_len -= M3_MAX_LEN;
292
24.4k
                *op++ = M3_MARKER | 0;
293
50.1k
                while __lzo_unlikely(m_len > 255)
294
25.7k
                {
295
25.7k
                    m_len -= 255;
296
25.7k
                    UA_SET1(op, 0);
297
25.7k
                    op++;
298
25.7k
                }
299
24.4k
                *op++ = LZO_BYTE(m_len);
300
24.4k
            }
301
91.0k
            *op++ = LZO_BYTE(m_off << 2);
302
91.0k
            *op++ = LZO_BYTE(m_off >> 6);
303
91.0k
        }
304
12.4k
        else
305
12.4k
        {
306
12.4k
            m_off -= 0x4000;
307
12.4k
            if (m_len <= M4_MAX_LEN)
308
7.85k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8) | (m_len - 2));
309
4.61k
            else
310
4.61k
            {
311
4.61k
                m_len -= M4_MAX_LEN;
312
4.61k
                *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8));
313
9.21k
                while __lzo_unlikely(m_len > 255)
314
4.60k
                {
315
4.60k
                    m_len -= 255;
316
4.60k
                    UA_SET1(op, 0);
317
4.60k
                    op++;
318
4.60k
                }
319
4.61k
                *op++ = LZO_BYTE(m_len);
320
4.61k
            }
321
12.4k
            *op++ = LZO_BYTE(m_off << 2);
322
12.4k
            *op++ = LZO_BYTE(m_off >> 6);
323
12.4k
        }
324
229k
        goto next;
325
228k
    }
326
327
888
    *out_len = pd(op, out);
328
888
    return pd(in_end,ii-ti);
329
888
}
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.83k
{
341
2.83k
    const lzo_bytep ip = in;
342
2.83k
    lzo_bytep op = out;
343
2.83k
    lzo_uint l = in_len;
344
2.83k
    lzo_uint t = 0;
345
346
8.78k
    while (l > 20)
347
5.97k
    {
348
5.97k
        lzo_uint ll = l;
349
5.97k
        lzo_uintptr_t ll_end;
350
5.97k
#if 0 || (LZO_DETERMINISTIC)
351
5.97k
        ll = LZO_MIN(ll, 49152);
352
5.97k
#endif
353
5.97k
        ll_end = (lzo_uintptr_t)ip + ll;
354
5.97k
        if ((ll_end + ((t + ll) >> 5)) <= ll_end || (const lzo_bytep)(ll_end + ((t + ll) >> 5)) <= ip + ll)
355
25
            break;
356
5.95k
#if (LZO_DETERMINISTIC)
357
5.95k
        lzo_memset(wrkmem, 0, ((lzo_uint)1 << D_BITS) * sizeof(lzo_dict_t));
358
5.95k
#endif
359
5.95k
        t = do_compress(ip,ll,op,out_len,t,wrkmem);
360
5.95k
        ip += ll;
361
5.95k
        op += *out_len;
362
5.95k
        l  -= ll;
363
5.95k
    }
364
2.83k
    t += l;
365
366
2.83k
    if (t > 0)
367
2.82k
    {
368
2.82k
        const lzo_bytep ii = in + in_len - t;
369
370
2.82k
        if (op == out && t <= 238)
371
159
            *op++ = LZO_BYTE(17 + t);
372
2.66k
        else if (t <= 3)
373
0
            op[-2] = LZO_BYTE(op[-2] | t);
374
2.66k
        else if (t <= 18)
375
1.49k
            *op++ = LZO_BYTE(t - 3);
376
1.17k
        else
377
1.17k
        {
378
1.17k
            lzo_uint tt = t - 18;
379
380
1.17k
            *op++ = 0;
381
216k
            while (tt > 255)
382
214k
            {
383
214k
                tt -= 255;
384
214k
                UA_SET1(op, 0);
385
214k
                op++;
386
214k
            }
387
1.17k
            assert(tt > 0);
388
1.17k
            *op++ = LZO_BYTE(tt);
389
1.17k
        }
390
2.82k
        UA_COPYN(op, ii, t);
391
2.82k
        op += t;
392
2.82k
    }
393
394
2.83k
    *op++ = M4_MARKER | 1;
395
2.83k
    *op++ = 0;
396
2.83k
    *op++ = 0;
397
398
2.83k
    *out_len = pd(op, out);
399
2.83k
    return LZO_E_OK;
400
2.83k
}
lzo1x_1_compress
Line
Count
Source
340
1.33k
{
341
1.33k
    const lzo_bytep ip = in;
342
1.33k
    lzo_bytep op = out;
343
1.33k
    lzo_uint l = in_len;
344
1.33k
    lzo_uint t = 0;
345
346
4.21k
    while (l > 20)
347
2.88k
    {
348
2.88k
        lzo_uint ll = l;
349
2.88k
        lzo_uintptr_t ll_end;
350
2.88k
#if 0 || (LZO_DETERMINISTIC)
351
2.88k
        ll = LZO_MIN(ll, 49152);
352
2.88k
#endif
353
2.88k
        ll_end = (lzo_uintptr_t)ip + ll;
354
2.88k
        if ((ll_end + ((t + ll) >> 5)) <= ll_end || (const lzo_bytep)(ll_end + ((t + ll) >> 5)) <= ip + ll)
355
10
            break;
356
2.87k
#if (LZO_DETERMINISTIC)
357
2.87k
        lzo_memset(wrkmem, 0, ((lzo_uint)1 << D_BITS) * sizeof(lzo_dict_t));
358
2.87k
#endif
359
2.87k
        t = do_compress(ip,ll,op,out_len,t,wrkmem);
360
2.87k
        ip += ll;
361
2.87k
        op += *out_len;
362
2.87k
        l  -= ll;
363
2.87k
    }
364
1.33k
    t += l;
365
366
1.33k
    if (t > 0)
367
1.33k
    {
368
1.33k
        const lzo_bytep ii = in + in_len - t;
369
370
1.33k
        if (op == out && t <= 238)
371
68
            *op++ = LZO_BYTE(17 + t);
372
1.26k
        else if (t <= 3)
373
0
            op[-2] = LZO_BYTE(op[-2] | t);
374
1.26k
        else if (t <= 18)
375
769
            *op++ = LZO_BYTE(t - 3);
376
498
        else
377
498
        {
378
498
            lzo_uint tt = t - 18;
379
380
498
            *op++ = 0;
381
118k
            while (tt > 255)
382
117k
            {
383
117k
                tt -= 255;
384
117k
                UA_SET1(op, 0);
385
117k
                op++;
386
117k
            }
387
498
            assert(tt > 0);
388
498
            *op++ = LZO_BYTE(tt);
389
498
        }
390
1.33k
        UA_COPYN(op, ii, t);
391
1.33k
        op += t;
392
1.33k
    }
393
394
1.33k
    *op++ = M4_MARKER | 1;
395
1.33k
    *op++ = 0;
396
1.33k
    *op++ = 0;
397
398
1.33k
    *out_len = pd(op, out);
399
1.33k
    return LZO_E_OK;
400
1.33k
}
lzo1x_1_11_compress
Line
Count
Source
340
353
{
341
353
    const lzo_bytep ip = in;
342
353
    lzo_bytep op = out;
343
353
    lzo_uint l = in_len;
344
353
    lzo_uint t = 0;
345
346
1.16k
    while (l > 20)
347
817
    {
348
817
        lzo_uint ll = l;
349
817
        lzo_uintptr_t ll_end;
350
817
#if 0 || (LZO_DETERMINISTIC)
351
817
        ll = LZO_MIN(ll, 49152);
352
817
#endif
353
817
        ll_end = (lzo_uintptr_t)ip + ll;
354
817
        if ((ll_end + ((t + ll) >> 5)) <= ll_end || (const lzo_bytep)(ll_end + ((t + ll) >> 5)) <= ip + ll)
355
2
            break;
356
815
#if (LZO_DETERMINISTIC)
357
815
        lzo_memset(wrkmem, 0, ((lzo_uint)1 << D_BITS) * sizeof(lzo_dict_t));
358
815
#endif
359
815
        t = do_compress(ip,ll,op,out_len,t,wrkmem);
360
815
        ip += ll;
361
815
        op += *out_len;
362
815
        l  -= ll;
363
815
    }
364
353
    t += l;
365
366
353
    if (t > 0)
367
352
    {
368
352
        const lzo_bytep ii = in + in_len - t;
369
370
352
        if (op == out && t <= 238)
371
22
            *op++ = LZO_BYTE(17 + t);
372
330
        else if (t <= 3)
373
0
            op[-2] = LZO_BYTE(op[-2] | t);
374
330
        else if (t <= 18)
375
173
            *op++ = LZO_BYTE(t - 3);
376
157
        else
377
157
        {
378
157
            lzo_uint tt = t - 18;
379
380
157
            *op++ = 0;
381
39.4k
            while (tt > 255)
382
39.3k
            {
383
39.3k
                tt -= 255;
384
39.3k
                UA_SET1(op, 0);
385
39.3k
                op++;
386
39.3k
            }
387
157
            assert(tt > 0);
388
157
            *op++ = LZO_BYTE(tt);
389
157
        }
390
352
        UA_COPYN(op, ii, t);
391
352
        op += t;
392
352
    }
393
394
353
    *op++ = M4_MARKER | 1;
395
353
    *op++ = 0;
396
353
    *op++ = 0;
397
398
353
    *out_len = pd(op, out);
399
353
    return LZO_E_OK;
400
353
}
lzo1x_1_12_compress
Line
Count
Source
340
385
{
341
385
    const lzo_bytep ip = in;
342
385
    lzo_bytep op = out;
343
385
    lzo_uint l = in_len;
344
385
    lzo_uint t = 0;
345
346
1.10k
    while (l > 20)
347
730
    {
348
730
        lzo_uint ll = l;
349
730
        lzo_uintptr_t ll_end;
350
730
#if 0 || (LZO_DETERMINISTIC)
351
730
        ll = LZO_MIN(ll, 49152);
352
730
#endif
353
730
        ll_end = (lzo_uintptr_t)ip + ll;
354
730
        if ((ll_end + ((t + ll) >> 5)) <= ll_end || (const lzo_bytep)(ll_end + ((t + ll) >> 5)) <= ip + ll)
355
6
            break;
356
724
#if (LZO_DETERMINISTIC)
357
724
        lzo_memset(wrkmem, 0, ((lzo_uint)1 << D_BITS) * sizeof(lzo_dict_t));
358
724
#endif
359
724
        t = do_compress(ip,ll,op,out_len,t,wrkmem);
360
724
        ip += ll;
361
724
        op += *out_len;
362
724
        l  -= ll;
363
724
    }
364
385
    t += l;
365
366
385
    if (t > 0)
367
384
    {
368
384
        const lzo_bytep ii = in + in_len - t;
369
370
384
        if (op == out && t <= 238)
371
22
            *op++ = LZO_BYTE(17 + t);
372
362
        else if (t <= 3)
373
0
            op[-2] = LZO_BYTE(op[-2] | t);
374
362
        else if (t <= 18)
375
190
            *op++ = LZO_BYTE(t - 3);
376
172
        else
377
172
        {
378
172
            lzo_uint tt = t - 18;
379
380
172
            *op++ = 0;
381
21.1k
            while (tt > 255)
382
21.0k
            {
383
21.0k
                tt -= 255;
384
21.0k
                UA_SET1(op, 0);
385
21.0k
                op++;
386
21.0k
            }
387
172
            assert(tt > 0);
388
172
            *op++ = LZO_BYTE(tt);
389
172
        }
390
384
        UA_COPYN(op, ii, t);
391
384
        op += t;
392
384
    }
393
394
385
    *op++ = M4_MARKER | 1;
395
385
    *op++ = 0;
396
385
    *op++ = 0;
397
398
385
    *out_len = pd(op, out);
399
385
    return LZO_E_OK;
400
385
}
lzo1x_1_15_compress
Line
Count
Source
340
353
{
341
353
    const lzo_bytep ip = in;
342
353
    lzo_bytep op = out;
343
353
    lzo_uint l = in_len;
344
353
    lzo_uint t = 0;
345
346
1.00k
    while (l > 20)
347
653
    {
348
653
        lzo_uint ll = l;
349
653
        lzo_uintptr_t ll_end;
350
653
#if 0 || (LZO_DETERMINISTIC)
351
653
        ll = LZO_MIN(ll, 49152);
352
653
#endif
353
653
        ll_end = (lzo_uintptr_t)ip + ll;
354
653
        if ((ll_end + ((t + ll) >> 5)) <= ll_end || (const lzo_bytep)(ll_end + ((t + ll) >> 5)) <= ip + ll)
355
5
            break;
356
648
#if (LZO_DETERMINISTIC)
357
648
        lzo_memset(wrkmem, 0, ((lzo_uint)1 << D_BITS) * sizeof(lzo_dict_t));
358
648
#endif
359
648
        t = do_compress(ip,ll,op,out_len,t,wrkmem);
360
648
        ip += ll;
361
648
        op += *out_len;
362
648
        l  -= ll;
363
648
    }
364
353
    t += l;
365
366
353
    if (t > 0)
367
352
    {
368
352
        const lzo_bytep ii = in + in_len - t;
369
370
352
        if (op == out && t <= 238)
371
29
            *op++ = LZO_BYTE(17 + t);
372
323
        else if (t <= 3)
373
0
            op[-2] = LZO_BYTE(op[-2] | t);
374
323
        else if (t <= 18)
375
160
            *op++ = LZO_BYTE(t - 3);
376
163
        else
377
163
        {
378
163
            lzo_uint tt = t - 18;
379
380
163
            *op++ = 0;
381
9.75k
            while (tt > 255)
382
9.59k
            {
383
9.59k
                tt -= 255;
384
9.59k
                UA_SET1(op, 0);
385
9.59k
                op++;
386
9.59k
            }
387
163
            assert(tt > 0);
388
163
            *op++ = LZO_BYTE(tt);
389
163
        }
390
352
        UA_COPYN(op, ii, t);
391
352
        op += t;
392
352
    }
393
394
353
    *op++ = M4_MARKER | 1;
395
353
    *op++ = 0;
396
353
    *op++ = 0;
397
398
353
    *out_len = pd(op, out);
399
353
    return LZO_E_OK;
400
353
}
lzo1y_1_compress
Line
Count
Source
340
406
{
341
406
    const lzo_bytep ip = in;
342
406
    lzo_bytep op = out;
343
406
    lzo_uint l = in_len;
344
406
    lzo_uint t = 0;
345
346
1.29k
    while (l > 20)
347
890
    {
348
890
        lzo_uint ll = l;
349
890
        lzo_uintptr_t ll_end;
350
890
#if 0 || (LZO_DETERMINISTIC)
351
890
        ll = LZO_MIN(ll, 49152);
352
890
#endif
353
890
        ll_end = (lzo_uintptr_t)ip + ll;
354
890
        if ((ll_end + ((t + ll) >> 5)) <= ll_end || (const lzo_bytep)(ll_end + ((t + ll) >> 5)) <= ip + ll)
355
2
            break;
356
888
#if (LZO_DETERMINISTIC)
357
888
        lzo_memset(wrkmem, 0, ((lzo_uint)1 << D_BITS) * sizeof(lzo_dict_t));
358
888
#endif
359
888
        t = do_compress(ip,ll,op,out_len,t,wrkmem);
360
888
        ip += ll;
361
888
        op += *out_len;
362
888
        l  -= ll;
363
888
    }
364
406
    t += l;
365
366
406
    if (t > 0)
367
405
    {
368
405
        const lzo_bytep ii = in + in_len - t;
369
370
405
        if (op == out && t <= 238)
371
18
            *op++ = LZO_BYTE(17 + t);
372
387
        else if (t <= 3)
373
0
            op[-2] = LZO_BYTE(op[-2] | t);
374
387
        else if (t <= 18)
375
198
            *op++ = LZO_BYTE(t - 3);
376
189
        else
377
189
        {
378
189
            lzo_uint tt = t - 18;
379
380
189
            *op++ = 0;
381
27.1k
            while (tt > 255)
382
26.9k
            {
383
26.9k
                tt -= 255;
384
26.9k
                UA_SET1(op, 0);
385
26.9k
                op++;
386
26.9k
            }
387
189
            assert(tt > 0);
388
189
            *op++ = LZO_BYTE(tt);
389
189
        }
390
405
        UA_COPYN(op, ii, t);
391
405
        op += t;
392
405
    }
393
394
406
    *op++ = M4_MARKER | 1;
395
406
    *op++ = 0;
396
406
    *op++ = 0;
397
398
406
    *out_len = pd(op, out);
399
406
    return LZO_E_OK;
400
406
}
401
402
403
/* vim:set ts=4 sw=4 et: */