/src/lzo-2.10/src/lzo1a_cr.ch
Line | Count | Source |
1 | | /* lzo1a_cr.ch -- literal run handling for the the LZO1A 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 | | /* 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 | | */ |
33 | | |
34 | | |
35 | | #ifndef __LZO1A_CR_H |
36 | | #define __LZO1A_CR_H 1 |
37 | | |
38 | | |
39 | | /*********************************************************************** |
40 | | // code a literal run |
41 | | ************************************************************************/ |
42 | | |
43 | | static lzo_bytep |
44 | | store_run(lzo_bytep const oo, const lzo_bytep const ii, lzo_uint r_len) |
45 | 6.75k | { |
46 | 6.75k | lzo_bytep op; |
47 | 6.75k | const lzo_bytep ip; |
48 | 6.75k | lzo_uint t; |
49 | | |
50 | 6.75k | op = oo; |
51 | 6.75k | ip = ii; |
52 | 6.75k | assert(r_len > 0); |
53 | | |
54 | | /* code a long R0 run */ |
55 | 6.75k | if (r_len >= 512) |
56 | 3.28k | { |
57 | 3.28k | unsigned r_bits = 6; /* 256 << 6 == 16384 */ |
58 | 3.28k | lzo_uint tt = 32768u; |
59 | | |
60 | 3.36k | while (r_len >= (t = tt)) |
61 | 75 | { |
62 | 75 | r_len -= t; |
63 | 75 | *op++ = 0; *op++ = (R0MAX - R0MIN); |
64 | 75 | MEMCPY8_DS(op, ip, t); |
65 | 75 | LZO_STATS(lzo_stats->r0long_runs++); |
66 | 75 | } |
67 | 3.28k | tt >>= 1; |
68 | 19.7k | do { |
69 | 19.7k | if (r_len >= (t = tt)) |
70 | 4.10k | { |
71 | 4.10k | r_len -= t; |
72 | 4.10k | *op++ = 0; *op++ = LZO_BYTE((R0FAST - R0MIN) + r_bits); |
73 | 4.10k | MEMCPY8_DS(op, ip, t); |
74 | 4.10k | LZO_STATS(lzo_stats->r0long_runs++); |
75 | 4.10k | } |
76 | 19.7k | tt >>= 1; |
77 | 19.7k | } while (--r_bits > 0); |
78 | 3.28k | } |
79 | 6.75k | assert(r_len < 512); |
80 | | |
81 | 10.9k | while (r_len >= (t = R0FAST)) |
82 | 4.15k | { |
83 | 4.15k | r_len -= t; |
84 | 4.15k | *op++ = 0; *op++ = (R0FAST - R0MIN); |
85 | 4.15k | MEMCPY8_DS(op, ip, t); |
86 | 4.15k | LZO_STATS(lzo_stats->r0fast_runs++); |
87 | 4.15k | } |
88 | | |
89 | 6.75k | t = r_len; |
90 | 6.75k | if (t >= R0MIN) |
91 | 4.96k | { |
92 | | /* code a short R0 run */ |
93 | 4.96k | *op++ = 0; *op++ = LZO_BYTE(t - R0MIN); |
94 | 4.96k | MEMCPY_DS(op, ip, t); |
95 | 4.96k | LZO_STATS(lzo_stats->r0short_runs++); |
96 | 4.96k | } |
97 | 1.79k | else if (t > 0) |
98 | 1.55k | { |
99 | | /* code a short literal run */ |
100 | 1.55k | LZO_STATS(lzo_stats->lit_runs++); |
101 | 1.55k | LZO_STATS(lzo_stats->lit_run[t]++); |
102 | 1.55k | *op++ = LZO_BYTE(t); |
103 | 1.55k | MEMCPY_DS(op, ip, t); |
104 | 1.55k | } |
105 | | |
106 | 6.75k | return op; |
107 | 6.75k | } |
108 | | |
109 | | |
110 | | |
111 | | #endif /* already included */ |
112 | | |
113 | | |
114 | | /* vim:set ts=4 sw=4 et: */ |