lzo: update to 2.09
[tomato.git] / release / src / router / lzo / src / lzo1a_cr.ch
blobeef584b8320624bed079f85c4a80c5e6422beb21
1 /* lzo1a_cr.ch -- literal run handling for the the LZO1A 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 /* WARNING: this file should *not* be used by applications. It is
30    part of the implementation of the LZO package and is subject
31    to change.
32  */
35 #ifndef __LZO1A_CR_H
36 #define __LZO1A_CR_H 1
39 /***********************************************************************
40 // code a literal run
41 ************************************************************************/
43 static lzo_bytep
44 store_run(lzo_bytep const oo, const lzo_bytep const ii, lzo_uint r_len)
46     lzo_bytep op;
47     const lzo_bytep ip;
48     lzo_uint t;
50     op = oo;
51     ip = ii;
52     assert(r_len > 0);
54     /* code a long R0 run */
55     if (r_len >= 512)
56     {
57         unsigned r_bits = 6;        /* 256 << 6 == 16384 */
58         lzo_uint tt = 32768u;
60         while (r_len >= (t = tt))
61         {
62             r_len -= t;
63             *op++ = 0; *op++ = (R0MAX - R0MIN);
64             MEMCPY8_DS(op, ip, t);
65             LZO_STATS(lzo_stats->r0long_runs++);
66         }
67         tt >>= 1;
68         do {
69             if (r_len >= (t = tt))
70             {
71                 r_len -= t;
72                 *op++ = 0; *op++ = LZO_BYTE((R0FAST - R0MIN) + r_bits);
73                 MEMCPY8_DS(op, ip, t);
74                 LZO_STATS(lzo_stats->r0long_runs++);
75             }
76             tt >>= 1;
77         } while (--r_bits > 0);
78     }
79     assert(r_len < 512);
81     while (r_len >= (t = R0FAST))
82     {
83         r_len -= t;
84         *op++ = 0; *op++ = (R0FAST - R0MIN);
85         MEMCPY8_DS(op, ip, t);
86         LZO_STATS(lzo_stats->r0fast_runs++);
87     }
89     t = r_len;
90     if (t >= R0MIN)
91     {
92         /* code a short R0 run */
93         *op++ = 0; *op++ = LZO_BYTE(t - R0MIN);
94         MEMCPY_DS(op, ip, t);
95         LZO_STATS(lzo_stats->r0short_runs++);
96     }
97     else if (t > 0)
98     {
99         /* code a short literal run */
100         LZO_STATS(lzo_stats->lit_runs++);
101         LZO_STATS(lzo_stats->lit_run[t]++);
102         *op++ = LZO_BYTE(t);
103         MEMCPY_DS(op, ip, t);
104     }
106     return op;
111 #endif /* already included */
114 /* vim:set ts=4 sw=4 et: */