lzo: update to 2.09
[tomato.git] / release / src / router / lzo / src / lzo1b_r.ch
blob827a67de3cd6d7dc905b4779df949ea07a3b6578
1 /* lzo1b_r.ch -- literal run handling for the the LZO1B/LZO1C algorithm
3    This file is part of the LZO real-time data compression library.
5    Copyright (C) 1996-2015 Markus Franz Xaver Johannes Oberhumer
6    All Rights Reserved.
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.
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.
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.
23    Markus F.X.J. Oberhumer
24    <markus@oberhumer.com>
25    http://www.oberhumer.com/opensource/lzo/
26  */
29 /***********************************************************************
30 // store a literal run (internal)
31 ************************************************************************/
33 LZO_LOCAL_IMPL(lzo_bytep )
34 STORE_RUN ( lzo_bytep const oo, const lzo_bytep const ii, lzo_uint r_len)
36     lzo_bytep op;
37     const lzo_bytep ip;
38     lzo_uint t;
40     LZO_STATS(lzo_stats->literals += r_len);
42     op = oo;
43     ip = ii;
44     assert(r_len > 0);
46     /* code a long R0 run */
47     if (r_len >= 512)
48     {
49         unsigned r_bits = 6;        /* 256 << 6 == 16384 */
50         lzo_uint tt = 32768u;
52         while (r_len >= (t = tt))
53         {
54             r_len -= t;
55             *op++ = 0; *op++ = (R0FAST - R0MIN) + 7;
56             MEMCPY8_DS(op, ip, t);
57             LZO_STATS(lzo_stats->r0long_runs++);
58         }
59         tt >>= 1;
60         do {
61             if (r_len >= (t = tt))
62             {
63                 r_len -= t;
64                 *op++ = 0; *op++ = LZO_BYTE((R0FAST - R0MIN) + r_bits);
65                 MEMCPY8_DS(op, ip, t);
66                 LZO_STATS(lzo_stats->r0long_runs++);
67             }
68             tt >>= 1;
69         } while (--r_bits > 0);
70     }
71     assert(r_len < 512);
73     while (r_len >= (t = R0FAST))
74     {
75         r_len -= t;
76         *op++ = 0; *op++ = (R0FAST - R0MIN);
77         MEMCPY8_DS(op, ip, t);
78         LZO_STATS(lzo_stats->r0fast_runs++);
79     }
81     t = r_len;
82     if (t >= R0MIN)
83     {
84         /* code a short R0 run */
85         *op++ = 0; *op++ = LZO_BYTE(t - R0MIN);
86         MEMCPY_DS(op, ip, t);
87         LZO_STATS(lzo_stats->r0short_runs++);
88     }
89     else if (t > 0)
90     {
91         /* code a short literal run */
92         LZO_STATS(lzo_stats->lit_runs++);
93         LZO_STATS(lzo_stats->lit_run[t]++);
94         *op++ = LZO_BYTE(t);
95         MEMCPY_DS(op, ip, t);
96     }
98     return op;
102 /* vim:set ts=4 sw=4 et: */