line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
/* |
2
|
|
|
|
|
|
|
LZ4 - Fast LZ compression algorithm |
3
|
|
|
|
|
|
|
Copyright (C) 2011-2017, Yann Collet. |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without |
8
|
|
|
|
|
|
|
modification, are permitted provided that the following conditions are |
9
|
|
|
|
|
|
|
met: |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright |
12
|
|
|
|
|
|
|
notice, this list of conditions and the following disclaimer. |
13
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above |
14
|
|
|
|
|
|
|
copyright notice, this list of conditions and the following disclaimer |
15
|
|
|
|
|
|
|
in the documentation and/or other materials provided with the |
16
|
|
|
|
|
|
|
distribution. |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19
|
|
|
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20
|
|
|
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21
|
|
|
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22
|
|
|
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23
|
|
|
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24
|
|
|
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25
|
|
|
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26
|
|
|
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27
|
|
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28
|
|
|
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
You can contact the author at : |
31
|
|
|
|
|
|
|
- LZ4 homepage : http://www.lz4.org |
32
|
|
|
|
|
|
|
- LZ4 source repository : https://github.com/lz4/lz4 |
33
|
|
|
|
|
|
|
*/ |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
/*-************************************ |
37
|
|
|
|
|
|
|
* Tuning parameters |
38
|
|
|
|
|
|
|
**************************************/ |
39
|
|
|
|
|
|
|
/* |
40
|
|
|
|
|
|
|
* LZ4_HEAPMODE : |
41
|
|
|
|
|
|
|
* Select how default compression functions will allocate memory for their hash table, |
42
|
|
|
|
|
|
|
* in memory stack (0:default, fastest), or in memory heap (1:requires malloc()). |
43
|
|
|
|
|
|
|
*/ |
44
|
|
|
|
|
|
|
#ifndef LZ4_HEAPMODE |
45
|
|
|
|
|
|
|
# define LZ4_HEAPMODE 0 |
46
|
|
|
|
|
|
|
#endif |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
/* |
49
|
|
|
|
|
|
|
* ACCELERATION_DEFAULT : |
50
|
|
|
|
|
|
|
* Select "acceleration" for LZ4_compress_fast() when parameter value <= 0 |
51
|
|
|
|
|
|
|
*/ |
52
|
|
|
|
|
|
|
#define ACCELERATION_DEFAULT 1 |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
/*-************************************ |
56
|
|
|
|
|
|
|
* CPU Feature Detection |
57
|
|
|
|
|
|
|
**************************************/ |
58
|
|
|
|
|
|
|
/* LZ4_FORCE_MEMORY_ACCESS |
59
|
|
|
|
|
|
|
* By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable. |
60
|
|
|
|
|
|
|
* Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal. |
61
|
|
|
|
|
|
|
* The below switch allow to select different access method for improved performance. |
62
|
|
|
|
|
|
|
* Method 0 (default) : use `memcpy()`. Safe and portable. |
63
|
|
|
|
|
|
|
* Method 1 : `__packed` statement. It depends on compiler extension (ie, not portable). |
64
|
|
|
|
|
|
|
* This method is safe if your compiler supports it, and *generally* as fast or faster than `memcpy`. |
65
|
|
|
|
|
|
|
* Method 2 : direct access. This method is portable but violate C standard. |
66
|
|
|
|
|
|
|
* It can generate buggy code on targets which assembly generation depends on alignment. |
67
|
|
|
|
|
|
|
* But in some circumstances, it's the only known way to get the most performance (ie GCC + ARMv6) |
68
|
|
|
|
|
|
|
* See https://fastcompression.blogspot.fr/2015/08/accessing-unaligned-memory.html for details. |
69
|
|
|
|
|
|
|
* Prefer these methods in priority order (0 > 1 > 2) |
70
|
|
|
|
|
|
|
*/ |
71
|
|
|
|
|
|
|
#ifndef LZ4_FORCE_MEMORY_ACCESS /* can be defined externally */ |
72
|
|
|
|
|
|
|
# if defined(__GNUC__) && ( defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) ) |
73
|
|
|
|
|
|
|
# define LZ4_FORCE_MEMORY_ACCESS 2 |
74
|
|
|
|
|
|
|
# elif defined(__INTEL_COMPILER) || defined(__GNUC__) |
75
|
|
|
|
|
|
|
# define LZ4_FORCE_MEMORY_ACCESS 1 |
76
|
|
|
|
|
|
|
# endif |
77
|
|
|
|
|
|
|
#endif |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
/* |
80
|
|
|
|
|
|
|
* LZ4_FORCE_SW_BITCOUNT |
81
|
|
|
|
|
|
|
* Define this parameter if your target system or compiler does not support hardware bit count |
82
|
|
|
|
|
|
|
*/ |
83
|
|
|
|
|
|
|
#if defined(_MSC_VER) && defined(_WIN32_WCE) /* Visual Studio for Windows CE does not support Hardware bit count */ |
84
|
|
|
|
|
|
|
# define LZ4_FORCE_SW_BITCOUNT |
85
|
|
|
|
|
|
|
#endif |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
/*-************************************ |
90
|
|
|
|
|
|
|
* Dependency |
91
|
|
|
|
|
|
|
**************************************/ |
92
|
|
|
|
|
|
|
#include "lz4.h" |
93
|
|
|
|
|
|
|
/* see also "memory routines" below */ |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
/*-************************************ |
97
|
|
|
|
|
|
|
* Compiler Options |
98
|
|
|
|
|
|
|
**************************************/ |
99
|
|
|
|
|
|
|
#ifdef _MSC_VER /* Visual Studio */ |
100
|
|
|
|
|
|
|
# include |
101
|
|
|
|
|
|
|
# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */ |
102
|
|
|
|
|
|
|
# pragma warning(disable : 4293) /* disable: C4293: too large shift (32-bits) */ |
103
|
|
|
|
|
|
|
#endif /* _MSC_VER */ |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
#ifndef LZ4_FORCE_INLINE |
106
|
|
|
|
|
|
|
# ifdef _MSC_VER /* Visual Studio */ |
107
|
|
|
|
|
|
|
# define LZ4_FORCE_INLINE static __forceinline |
108
|
|
|
|
|
|
|
# else |
109
|
|
|
|
|
|
|
# if defined (__cplusplus) || defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */ |
110
|
|
|
|
|
|
|
# ifdef __GNUC__ |
111
|
|
|
|
|
|
|
# define LZ4_FORCE_INLINE static inline __attribute__((always_inline)) |
112
|
|
|
|
|
|
|
# else |
113
|
|
|
|
|
|
|
# define LZ4_FORCE_INLINE static inline |
114
|
|
|
|
|
|
|
# endif |
115
|
|
|
|
|
|
|
# else |
116
|
|
|
|
|
|
|
# define LZ4_FORCE_INLINE static |
117
|
|
|
|
|
|
|
# endif /* __STDC_VERSION__ */ |
118
|
|
|
|
|
|
|
# endif /* _MSC_VER */ |
119
|
|
|
|
|
|
|
#endif /* LZ4_FORCE_INLINE */ |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
/* LZ4_FORCE_O2_GCC_PPC64LE and LZ4_FORCE_O2_INLINE_GCC_PPC64LE |
122
|
|
|
|
|
|
|
* Gcc on ppc64le generates an unrolled SIMDized loop for LZ4_wildCopy, |
123
|
|
|
|
|
|
|
* together with a simple 8-byte copy loop as a fall-back path. |
124
|
|
|
|
|
|
|
* However, this optimization hurts the decompression speed by >30%, |
125
|
|
|
|
|
|
|
* because the execution does not go to the optimized loop |
126
|
|
|
|
|
|
|
* for typical compressible data, and all of the preamble checks |
127
|
|
|
|
|
|
|
* before going to the fall-back path become useless overhead. |
128
|
|
|
|
|
|
|
* This optimization happens only with the -O3 flag, and -O2 generates |
129
|
|
|
|
|
|
|
* a simple 8-byte copy loop. |
130
|
|
|
|
|
|
|
* With gcc on ppc64le, all of the LZ4_decompress_* and LZ4_wildCopy |
131
|
|
|
|
|
|
|
* functions are annotated with __attribute__((optimize("O2"))), |
132
|
|
|
|
|
|
|
* and also LZ4_wildCopy is forcibly inlined, so that the O2 attribute |
133
|
|
|
|
|
|
|
* of LZ4_wildCopy does not affect the compression speed. |
134
|
|
|
|
|
|
|
*/ |
135
|
|
|
|
|
|
|
#if defined(__PPC64__) && defined(__LITTLE_ENDIAN__) && defined(__GNUC__) |
136
|
|
|
|
|
|
|
# define LZ4_FORCE_O2_GCC_PPC64LE __attribute__((optimize("O2"))) |
137
|
|
|
|
|
|
|
# define LZ4_FORCE_O2_INLINE_GCC_PPC64LE __attribute__((optimize("O2"))) LZ4_FORCE_INLINE |
138
|
|
|
|
|
|
|
#else |
139
|
|
|
|
|
|
|
# define LZ4_FORCE_O2_GCC_PPC64LE |
140
|
|
|
|
|
|
|
# define LZ4_FORCE_O2_INLINE_GCC_PPC64LE static |
141
|
|
|
|
|
|
|
#endif |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
#if (defined(__GNUC__) && (__GNUC__ >= 3)) || (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 800)) || defined(__clang__) |
144
|
|
|
|
|
|
|
# define expect(expr,value) (__builtin_expect ((expr),(value)) ) |
145
|
|
|
|
|
|
|
#else |
146
|
|
|
|
|
|
|
# define expect(expr,value) (expr) |
147
|
|
|
|
|
|
|
#endif |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
#define likely(expr) expect((expr) != 0, 1) |
150
|
|
|
|
|
|
|
#define unlikely(expr) expect((expr) != 0, 0) |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
/*-************************************ |
154
|
|
|
|
|
|
|
* Memory routines |
155
|
|
|
|
|
|
|
**************************************/ |
156
|
|
|
|
|
|
|
#include /* malloc, calloc, free */ |
157
|
|
|
|
|
|
|
#define ALLOCATOR(n,s) calloc(n,s) |
158
|
|
|
|
|
|
|
#define FREEMEM free |
159
|
|
|
|
|
|
|
#include /* memset, memcpy */ |
160
|
|
|
|
|
|
|
#define MEM_INIT memset |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
/*-************************************ |
164
|
|
|
|
|
|
|
* Basic Types |
165
|
|
|
|
|
|
|
**************************************/ |
166
|
|
|
|
|
|
|
#if defined(__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) |
167
|
|
|
|
|
|
|
# include |
168
|
|
|
|
|
|
|
typedef uint8_t BYTE; |
169
|
|
|
|
|
|
|
typedef uint16_t U16; |
170
|
|
|
|
|
|
|
typedef uint32_t U32; |
171
|
|
|
|
|
|
|
typedef int32_t S32; |
172
|
|
|
|
|
|
|
typedef uint64_t U64; |
173
|
|
|
|
|
|
|
typedef uintptr_t uptrval; |
174
|
|
|
|
|
|
|
#else |
175
|
|
|
|
|
|
|
typedef unsigned char BYTE; |
176
|
|
|
|
|
|
|
typedef unsigned short U16; |
177
|
|
|
|
|
|
|
typedef unsigned int U32; |
178
|
|
|
|
|
|
|
typedef signed int S32; |
179
|
|
|
|
|
|
|
typedef unsigned long long U64; |
180
|
|
|
|
|
|
|
typedef size_t uptrval; /* generally true, except OpenVMS-64 */ |
181
|
|
|
|
|
|
|
#endif |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
#if defined(__x86_64__) |
184
|
|
|
|
|
|
|
typedef U64 reg_t; /* 64-bits in x32 mode */ |
185
|
|
|
|
|
|
|
#else |
186
|
|
|
|
|
|
|
typedef size_t reg_t; /* 32-bits in x32 mode */ |
187
|
|
|
|
|
|
|
#endif |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
/*-************************************ |
190
|
|
|
|
|
|
|
* Reading and writing into memory |
191
|
|
|
|
|
|
|
**************************************/ |
192
|
950825
|
|
|
|
|
|
static unsigned LZ4_isLittleEndian(void) |
193
|
|
|
|
|
|
|
{ |
194
|
950825
|
|
|
|
|
|
const union { U32 u; BYTE c[4]; } one = { 1 }; /* don't use static : performance detrimental */ |
195
|
950825
|
|
|
|
|
|
return one.c[0]; |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
#if defined(LZ4_FORCE_MEMORY_ACCESS) && (LZ4_FORCE_MEMORY_ACCESS==2) |
200
|
|
|
|
|
|
|
/* lie to the compiler about data alignment; use with caution */ |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
static U16 LZ4_read16(const void* memPtr) { return *(const U16*) memPtr; } |
203
|
|
|
|
|
|
|
static U32 LZ4_read32(const void* memPtr) { return *(const U32*) memPtr; } |
204
|
|
|
|
|
|
|
static reg_t LZ4_read_ARCH(const void* memPtr) { return *(const reg_t*) memPtr; } |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
static void LZ4_write16(void* memPtr, U16 value) { *(U16*)memPtr = value; } |
207
|
|
|
|
|
|
|
static void LZ4_write32(void* memPtr, U32 value) { *(U32*)memPtr = value; } |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
#elif defined(LZ4_FORCE_MEMORY_ACCESS) && (LZ4_FORCE_MEMORY_ACCESS==1) |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
/* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */ |
212
|
|
|
|
|
|
|
/* currently only defined for gcc and icc */ |
213
|
|
|
|
|
|
|
typedef union { U16 u16; U32 u32; reg_t uArch; } __attribute__((packed)) unalign; |
214
|
|
|
|
|
|
|
|
215
|
323000
|
|
|
|
|
|
static U16 LZ4_read16(const void* ptr) { return ((const unalign*)ptr)->u16; } |
216
|
2157796
|
|
|
|
|
|
static U32 LZ4_read32(const void* ptr) { return ((const unalign*)ptr)->u32; } |
217
|
1578650
|
|
|
|
|
|
static reg_t LZ4_read_ARCH(const void* ptr) { return ((const unalign*)ptr)->uArch; } |
218
|
|
|
|
|
|
|
|
219
|
49973
|
|
|
|
|
|
static void LZ4_write16(void* memPtr, U16 value) { ((unalign*)memPtr)->u16 = value; } |
220
|
8189
|
|
|
|
|
|
static void LZ4_write32(void* memPtr, U32 value) { ((unalign*)memPtr)->u32 = value; } |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
#else /* safe and portable access through memcpy() */ |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
static U16 LZ4_read16(const void* memPtr) |
225
|
|
|
|
|
|
|
{ |
226
|
|
|
|
|
|
|
U16 val; memcpy(&val, memPtr, sizeof(val)); return val; |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
static U32 LZ4_read32(const void* memPtr) |
230
|
|
|
|
|
|
|
{ |
231
|
|
|
|
|
|
|
U32 val; memcpy(&val, memPtr, sizeof(val)); return val; |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
static reg_t LZ4_read_ARCH(const void* memPtr) |
235
|
|
|
|
|
|
|
{ |
236
|
|
|
|
|
|
|
reg_t val; memcpy(&val, memPtr, sizeof(val)); return val; |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
static void LZ4_write16(void* memPtr, U16 value) |
240
|
|
|
|
|
|
|
{ |
241
|
|
|
|
|
|
|
memcpy(memPtr, &value, sizeof(value)); |
242
|
|
|
|
|
|
|
} |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
static void LZ4_write32(void* memPtr, U32 value) |
245
|
|
|
|
|
|
|
{ |
246
|
|
|
|
|
|
|
memcpy(memPtr, &value, sizeof(value)); |
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
#endif /* LZ4_FORCE_MEMORY_ACCESS */ |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
|
252
|
161500
|
|
|
|
|
|
static U16 LZ4_readLE16(const void* memPtr) |
253
|
|
|
|
|
|
|
{ |
254
|
161500
|
50
|
|
|
|
|
if (LZ4_isLittleEndian()) { |
255
|
161500
|
|
|
|
|
|
return LZ4_read16(memPtr); |
256
|
|
|
|
|
|
|
} else { |
257
|
0
|
|
|
|
|
|
const BYTE* p = (const BYTE*)memPtr; |
258
|
0
|
|
|
|
|
|
return (U16)((U16)p[0] + (p[1]<<8)); |
259
|
|
|
|
|
|
|
} |
260
|
|
|
|
|
|
|
} |
261
|
|
|
|
|
|
|
|
262
|
49973
|
|
|
|
|
|
static void LZ4_writeLE16(void* memPtr, U16 value) |
263
|
|
|
|
|
|
|
{ |
264
|
49973
|
50
|
|
|
|
|
if (LZ4_isLittleEndian()) { |
265
|
49973
|
|
|
|
|
|
LZ4_write16(memPtr, value); |
266
|
|
|
|
|
|
|
} else { |
267
|
0
|
|
|
|
|
|
BYTE* p = (BYTE*)memPtr; |
268
|
0
|
|
|
|
|
|
p[0] = (BYTE) value; |
269
|
0
|
|
|
|
|
|
p[1] = (BYTE)(value>>8); |
270
|
|
|
|
|
|
|
} |
271
|
49973
|
|
|
|
|
|
} |
272
|
|
|
|
|
|
|
|
273
|
140721
|
|
|
|
|
|
static void LZ4_copy8(void* dst, const void* src) |
274
|
|
|
|
|
|
|
{ |
275
|
140721
|
|
|
|
|
|
memcpy(dst,src,8); |
276
|
140721
|
|
|
|
|
|
} |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
/* customized variant of memcpy, which can overwrite up to 8 bytes beyond dstEnd */ |
279
|
|
|
|
|
|
|
LZ4_FORCE_O2_INLINE_GCC_PPC64LE |
280
|
58174
|
|
|
|
|
|
void LZ4_wildCopy(void* dstPtr, const void* srcPtr, void* dstEnd) |
281
|
|
|
|
|
|
|
{ |
282
|
58174
|
|
|
|
|
|
BYTE* d = (BYTE*)dstPtr; |
283
|
58174
|
|
|
|
|
|
const BYTE* s = (const BYTE*)srcPtr; |
284
|
58174
|
|
|
|
|
|
BYTE* const e = (BYTE*)dstEnd; |
285
|
|
|
|
|
|
|
|
286
|
124664
|
100
|
|
|
|
|
do { LZ4_copy8(d,s); d+=8; s+=8; } while (d
|
287
|
58174
|
|
|
|
|
|
} |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
/*-************************************ |
291
|
|
|
|
|
|
|
* Common Constants |
292
|
|
|
|
|
|
|
**************************************/ |
293
|
|
|
|
|
|
|
#define MINMATCH 4 |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
#define WILDCOPYLENGTH 8 |
296
|
|
|
|
|
|
|
#define LASTLITERALS 5 |
297
|
|
|
|
|
|
|
#define MFLIMIT (WILDCOPYLENGTH+MINMATCH) |
298
|
|
|
|
|
|
|
static const int LZ4_minLength = (MFLIMIT+1); |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
#define KB *(1 <<10) |
301
|
|
|
|
|
|
|
#define MB *(1 <<20) |
302
|
|
|
|
|
|
|
#define GB *(1U<<30) |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
#define MAXD_LOG 16 |
305
|
|
|
|
|
|
|
#define MAX_DISTANCE ((1 << MAXD_LOG) - 1) |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
#define ML_BITS 4 |
308
|
|
|
|
|
|
|
#define ML_MASK ((1U<
|
309
|
|
|
|
|
|
|
#define RUN_BITS (8-ML_BITS) |
310
|
|
|
|
|
|
|
#define RUN_MASK ((1U<
|
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
/*-************************************ |
314
|
|
|
|
|
|
|
* Error detection |
315
|
|
|
|
|
|
|
**************************************/ |
316
|
|
|
|
|
|
|
#if defined(LZ4_DEBUG) && (LZ4_DEBUG>=1) |
317
|
|
|
|
|
|
|
# include |
318
|
|
|
|
|
|
|
#else |
319
|
|
|
|
|
|
|
# ifndef assert |
320
|
|
|
|
|
|
|
# define assert(condition) ((void)0) |
321
|
|
|
|
|
|
|
# endif |
322
|
|
|
|
|
|
|
#endif |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
#define LZ4_STATIC_ASSERT(c) { enum { LZ4_static_assert = 1/(int)(!!(c)) }; } /* use only *after* variable declarations */ |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
#if defined(LZ4_DEBUG) && (LZ4_DEBUG>=2) |
327
|
|
|
|
|
|
|
# include |
328
|
|
|
|
|
|
|
static int g_debuglog_enable = 1; |
329
|
|
|
|
|
|
|
# define DEBUGLOG(l, ...) { \ |
330
|
|
|
|
|
|
|
if ((g_debuglog_enable) && (l<=LZ4_DEBUG)) { \ |
331
|
|
|
|
|
|
|
fprintf(stderr, __FILE__ ": "); \ |
332
|
|
|
|
|
|
|
fprintf(stderr, __VA_ARGS__); \ |
333
|
|
|
|
|
|
|
fprintf(stderr, " \n"); \ |
334
|
|
|
|
|
|
|
} } |
335
|
|
|
|
|
|
|
#else |
336
|
|
|
|
|
|
|
# define DEBUGLOG(l, ...) {} /* disabled */ |
337
|
|
|
|
|
|
|
#endif |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
/*-************************************ |
341
|
|
|
|
|
|
|
* Common functions |
342
|
|
|
|
|
|
|
**************************************/ |
343
|
49973
|
|
|
|
|
|
static unsigned LZ4_NbCommonBytes (reg_t val) |
344
|
|
|
|
|
|
|
{ |
345
|
49973
|
50
|
|
|
|
|
if (LZ4_isLittleEndian()) { |
346
|
|
|
|
|
|
|
if (sizeof(val)==8) { |
347
|
|
|
|
|
|
|
# if defined(_MSC_VER) && defined(_WIN64) && !defined(LZ4_FORCE_SW_BITCOUNT) |
348
|
|
|
|
|
|
|
unsigned long r = 0; |
349
|
|
|
|
|
|
|
_BitScanForward64( &r, (U64)val ); |
350
|
|
|
|
|
|
|
return (int)(r>>3); |
351
|
|
|
|
|
|
|
# elif (defined(__clang__) || (defined(__GNUC__) && (__GNUC__>=3))) && !defined(LZ4_FORCE_SW_BITCOUNT) |
352
|
49973
|
|
|
|
|
|
return (__builtin_ctzll((U64)val) >> 3); |
353
|
|
|
|
|
|
|
# else |
354
|
|
|
|
|
|
|
static const int DeBruijnBytePos[64] = { 0, 0, 0, 0, 0, 1, 1, 2, |
355
|
|
|
|
|
|
|
0, 3, 1, 3, 1, 4, 2, 7, |
356
|
|
|
|
|
|
|
0, 2, 3, 6, 1, 5, 3, 5, |
357
|
|
|
|
|
|
|
1, 3, 4, 4, 2, 5, 6, 7, |
358
|
|
|
|
|
|
|
7, 0, 1, 2, 3, 3, 4, 6, |
359
|
|
|
|
|
|
|
2, 6, 5, 5, 3, 4, 5, 6, |
360
|
|
|
|
|
|
|
7, 1, 2, 4, 6, 4, 4, 5, |
361
|
|
|
|
|
|
|
7, 2, 6, 5, 7, 6, 7, 7 }; |
362
|
|
|
|
|
|
|
return DeBruijnBytePos[((U64)((val & -(long long)val) * 0x0218A392CDABBD3FULL)) >> 58]; |
363
|
|
|
|
|
|
|
# endif |
364
|
|
|
|
|
|
|
} else /* 32 bits */ { |
365
|
|
|
|
|
|
|
# if defined(_MSC_VER) && !defined(LZ4_FORCE_SW_BITCOUNT) |
366
|
|
|
|
|
|
|
unsigned long r; |
367
|
|
|
|
|
|
|
_BitScanForward( &r, (U32)val ); |
368
|
|
|
|
|
|
|
return (int)(r>>3); |
369
|
|
|
|
|
|
|
# elif (defined(__clang__) || (defined(__GNUC__) && (__GNUC__>=3))) && !defined(LZ4_FORCE_SW_BITCOUNT) |
370
|
|
|
|
|
|
|
return (__builtin_ctz((U32)val) >> 3); |
371
|
|
|
|
|
|
|
# else |
372
|
|
|
|
|
|
|
static const int DeBruijnBytePos[32] = { 0, 0, 3, 0, 3, 1, 3, 0, |
373
|
|
|
|
|
|
|
3, 2, 2, 1, 3, 2, 0, 1, |
374
|
|
|
|
|
|
|
3, 3, 1, 2, 2, 2, 2, 0, |
375
|
|
|
|
|
|
|
3, 1, 2, 0, 1, 0, 1, 1 }; |
376
|
|
|
|
|
|
|
return DeBruijnBytePos[((U32)((val & -(S32)val) * 0x077CB531U)) >> 27]; |
377
|
|
|
|
|
|
|
# endif |
378
|
|
|
|
|
|
|
} |
379
|
|
|
|
|
|
|
} else /* Big Endian CPU */ { |
380
|
|
|
|
|
|
|
if (sizeof(val)==8) { /* 64-bits */ |
381
|
|
|
|
|
|
|
# if defined(_MSC_VER) && defined(_WIN64) && !defined(LZ4_FORCE_SW_BITCOUNT) |
382
|
|
|
|
|
|
|
unsigned long r = 0; |
383
|
|
|
|
|
|
|
_BitScanReverse64( &r, val ); |
384
|
|
|
|
|
|
|
return (unsigned)(r>>3); |
385
|
|
|
|
|
|
|
# elif (defined(__clang__) || (defined(__GNUC__) && (__GNUC__>=3))) && !defined(LZ4_FORCE_SW_BITCOUNT) |
386
|
0
|
|
|
|
|
|
return (__builtin_clzll((U64)val) >> 3); |
387
|
|
|
|
|
|
|
# else |
388
|
|
|
|
|
|
|
static const U32 by32 = sizeof(val)*4; /* 32 on 64 bits (goal), 16 on 32 bits. |
389
|
|
|
|
|
|
|
Just to avoid some static analyzer complaining about shift by 32 on 32-bits target. |
390
|
|
|
|
|
|
|
Note that this code path is never triggered in 32-bits mode. */ |
391
|
|
|
|
|
|
|
unsigned r; |
392
|
|
|
|
|
|
|
if (!(val>>by32)) { r=4; } else { r=0; val>>=by32; } |
393
|
|
|
|
|
|
|
if (!(val>>16)) { r+=2; val>>=8; } else { val>>=24; } |
394
|
|
|
|
|
|
|
r += (!val); |
395
|
|
|
|
|
|
|
return r; |
396
|
|
|
|
|
|
|
# endif |
397
|
|
|
|
|
|
|
} else /* 32 bits */ { |
398
|
|
|
|
|
|
|
# if defined(_MSC_VER) && !defined(LZ4_FORCE_SW_BITCOUNT) |
399
|
|
|
|
|
|
|
unsigned long r = 0; |
400
|
|
|
|
|
|
|
_BitScanReverse( &r, (unsigned long)val ); |
401
|
|
|
|
|
|
|
return (unsigned)(r>>3); |
402
|
|
|
|
|
|
|
# elif (defined(__clang__) || (defined(__GNUC__) && (__GNUC__>=3))) && !defined(LZ4_FORCE_SW_BITCOUNT) |
403
|
|
|
|
|
|
|
return (__builtin_clz((U32)val) >> 3); |
404
|
|
|
|
|
|
|
# else |
405
|
|
|
|
|
|
|
unsigned r; |
406
|
|
|
|
|
|
|
if (!(val>>16)) { r=2; val>>=8; } else { r=0; val>>=24; } |
407
|
|
|
|
|
|
|
r += (!val); |
408
|
|
|
|
|
|
|
return r; |
409
|
|
|
|
|
|
|
# endif |
410
|
|
|
|
|
|
|
} |
411
|
|
|
|
|
|
|
} |
412
|
|
|
|
|
|
|
} |
413
|
|
|
|
|
|
|
|
414
|
|
|
|
|
|
|
#define STEPSIZE sizeof(reg_t) |
415
|
|
|
|
|
|
|
LZ4_FORCE_INLINE |
416
|
|
|
|
|
|
|
unsigned LZ4_count(const BYTE* pIn, const BYTE* pMatch, const BYTE* pInLimit) |
417
|
|
|
|
|
|
|
{ |
418
|
49973
|
|
|
|
|
|
const BYTE* const pStart = pIn; |
419
|
|
|
|
|
|
|
|
420
|
49973
|
0
|
|
|
|
|
if (likely(pIn < pInLimit-(STEPSIZE-1))) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
421
|
49973
|
|
|
|
|
|
reg_t const diff = LZ4_read_ARCH(pMatch) ^ LZ4_read_ARCH(pIn); |
422
|
49973
|
|
|
|
|
|
if (!diff) { |
423
|
0
|
|
|
|
|
|
pIn+=STEPSIZE; pMatch+=STEPSIZE; |
424
|
|
|
|
|
|
|
} else { |
425
|
49973
|
|
|
|
|
|
return LZ4_NbCommonBytes(diff); |
426
|
|
|
|
|
|
|
} } |
427
|
|
|
|
|
|
|
|
428
|
0
|
0
|
|
|
|
|
while (likely(pIn < pInLimit-(STEPSIZE-1))) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
429
|
0
|
|
|
|
|
|
reg_t const diff = LZ4_read_ARCH(pMatch) ^ LZ4_read_ARCH(pIn); |
430
|
0
|
0
|
|
|
|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|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
438
|
0
|
|
|
|
|
|
return (unsigned)(pIn - pStart); |
439
|
|
|
|
|
|
|
} |
440
|
|
|
|
|
|
|
|
441
|
|
|
|
|
|
|
|
442
|
|
|
|
|
|
|
#ifndef LZ4_COMMONDEFS_ONLY |
443
|
|
|
|
|
|
|
/*-************************************ |
444
|
|
|
|
|
|
|
* Local Constants |
445
|
|
|
|
|
|
|
**************************************/ |
446
|
|
|
|
|
|
|
static const int LZ4_64Klimit = ((64 KB) + (MFLIMIT-1)); |
447
|
|
|
|
|
|
|
static const U32 LZ4_skipTrigger = 6; /* Increase this value ==> compression run slower on incompressible data */ |
448
|
|
|
|
|
|
|
|
449
|
|
|
|
|
|
|
|
450
|
|
|
|
|
|
|
/*-************************************ |
451
|
|
|
|
|
|
|
* Local Structures and types |
452
|
|
|
|
|
|
|
**************************************/ |
453
|
|
|
|
|
|
|
typedef enum { notLimited = 0, limitedOutput = 1 } limitedOutput_directive; |
454
|
|
|
|
|
|
|
typedef enum { byPtr, byU32, byU16 } tableType_t; |
455
|
|
|
|
|
|
|
|
456
|
|
|
|
|
|
|
typedef enum { noDict = 0, withPrefix64k, usingExtDict } dict_directive; |
457
|
|
|
|
|
|
|
typedef enum { noDictIssue = 0, dictSmall } dictIssue_directive; |
458
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
typedef enum { endOnOutputSize = 0, endOnInputSize = 1 } endCondition_directive; |
460
|
|
|
|
|
|
|
typedef enum { full = 0, partial = 1 } earlyEnd_directive; |
461
|
|
|
|
|
|
|
|
462
|
|
|
|
|
|
|
|
463
|
|
|
|
|
|
|
/*-************************************ |
464
|
|
|
|
|
|
|
* Local Utils |
465
|
|
|
|
|
|
|
**************************************/ |
466
|
0
|
|
|
|
|
|
int LZ4_versionNumber (void) { return LZ4_VERSION_NUMBER; } |
467
|
0
|
|
|
|
|
|
const char* LZ4_versionString(void) { return LZ4_VERSION_STRING; } |
468
|
0
|
0
|
|
|
|
|
int LZ4_compressBound(int isize) { return LZ4_COMPRESSBOUND(isize); } |
469
|
0
|
|
|
|
|
|
int LZ4_sizeofState() { return LZ4_STREAMSIZE; } |
470
|
|
|
|
|
|
|
|
471
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
/*-****************************** |
473
|
|
|
|
|
|
|
* Compression functions |
474
|
|
|
|
|
|
|
********************************/ |
475
|
0
|
|
|
|
|
|
static U32 LZ4_hash4(U32 sequence, tableType_t const tableType) |
476
|
|
|
|
|
|
|
{ |
477
|
0
|
0
|
|
|
|
|
if (tableType == byU16) |
478
|
0
|
|
|
|
|
|
return ((sequence * 2654435761U) >> ((MINMATCH*8)-(LZ4_HASHLOG+1))); |
479
|
|
|
|
|
|
|
else |
480
|
0
|
|
|
|
|
|
return ((sequence * 2654435761U) >> ((MINMATCH*8)-LZ4_HASHLOG)); |
481
|
|
|
|
|
|
|
} |
482
|
|
|
|
|
|
|
|
483
|
689379
|
|
|
|
|
|
static U32 LZ4_hash5(U64 sequence, tableType_t const tableType) |
484
|
|
|
|
|
|
|
{ |
485
|
|
|
|
|
|
|
static const U64 prime5bytes = 889523592379ULL; |
486
|
|
|
|
|
|
|
static const U64 prime8bytes = 11400714785074694791ULL; |
487
|
689379
|
50
|
|
|
|
|
const U32 hashLog = (tableType == byU16) ? LZ4_HASHLOG+1 : LZ4_HASHLOG; |
488
|
689379
|
50
|
|
|
|
|
if (LZ4_isLittleEndian()) |
489
|
689379
|
|
|
|
|
|
return (U32)(((sequence << 24) * prime5bytes) >> (64 - hashLog)); |
490
|
|
|
|
|
|
|
else |
491
|
0
|
|
|
|
|
|
return (U32)(((sequence >> 24) * prime8bytes) >> (64 - hashLog)); |
492
|
|
|
|
|
|
|
} |
493
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
LZ4_FORCE_INLINE U32 LZ4_hashPosition(const void* const p, tableType_t const tableType) |
495
|
|
|
|
|
|
|
{ |
496
|
689379
|
0
|
|
|
|
|
if ((sizeof(reg_t)==8) && (tableType != byU16)) return LZ4_hash5(LZ4_read_ARCH(p), tableType); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
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0
|
|
|
|
|
|
return LZ4_hash4(LZ4_read32(p), tableType); |
498
|
|
|
|
|
|
|
} |
499
|
|
|
|
|
|
|
|
500
|
589438
|
|
|
|
|
|
static void LZ4_putPositionOnHash(const BYTE* p, U32 h, void* tableBase, tableType_t const tableType, const BYTE* srcBase) |
501
|
|
|
|
|
|
|
{ |
502
|
589438
|
|
|
|
|
|
switch (tableType) |
503
|
|
|
|
|
|
|
{ |
504
|
0
|
|
|
|
|
|
case byPtr: { const BYTE** hashTable = (const BYTE**)tableBase; hashTable[h] = p; return; } |
505
|
589438
|
|
|
|
|
|
case byU32: { U32* hashTable = (U32*) tableBase; hashTable[h] = (U32)(p-srcBase); return; } |
506
|
0
|
|
|
|
|
|
case byU16: { U16* hashTable = (U16*) tableBase; hashTable[h] = (U16)(p-srcBase); return; } |
507
|
|
|
|
|
|
|
} |
508
|
|
|
|
|
|
|
} |
509
|
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
LZ4_FORCE_INLINE void LZ4_putPosition(const BYTE* p, void* tableBase, tableType_t tableType, const BYTE* srcBase) |
511
|
|
|
|
|
|
|
{ |
512
|
99949
|
|
|
|
|
|
U32 const h = LZ4_hashPosition(p, tableType); |
513
|
99949
|
|
|
|
|
|
LZ4_putPositionOnHash(p, h, tableBase, tableType, srcBase); |
514
|
|
|
|
|
|
|
} |
515
|
|
|
|
|
|
|
|
516
|
539457
|
|
|
|
|
|
static const BYTE* LZ4_getPositionOnHash(U32 h, void* tableBase, tableType_t tableType, const BYTE* srcBase) |
517
|
|
|
|
|
|
|
{ |
518
|
539457
|
50
|
|
|
|
|
if (tableType == byPtr) { const BYTE** hashTable = (const BYTE**) tableBase; return hashTable[h]; } |
519
|
539457
|
50
|
|
|
|
|
if (tableType == byU32) { const U32* const hashTable = (U32*) tableBase; return hashTable[h] + srcBase; } |
520
|
0
|
|
|
|
|
|
{ const U16* const hashTable = (U16*) tableBase; return hashTable[h] + srcBase; } /* default, to ensure a return */ |
521
|
|
|
|
|
|
|
} |
522
|
|
|
|
|
|
|
|
523
|
|
|
|
|
|
|
LZ4_FORCE_INLINE const BYTE* LZ4_getPosition(const BYTE* p, void* tableBase, tableType_t tableType, const BYTE* srcBase) |
524
|
|
|
|
|
|
|
{ |
525
|
49968
|
|
|
|
|
|
U32 const h = LZ4_hashPosition(p, tableType); |
526
|
49968
|
|
|
|
|
|
return LZ4_getPositionOnHash(h, tableBase, tableType, srcBase); |
527
|
|
|
|
|
|
|
} |
528
|
|
|
|
|
|
|
|
529
|
|
|
|
|
|
|
|
530
|
|
|
|
|
|
|
/** LZ4_compress_generic() : |
531
|
|
|
|
|
|
|
inlined, to ensure branches are decided at compilation time */ |
532
|
|
|
|
|
|
|
LZ4_FORCE_INLINE int LZ4_compress_generic( |
533
|
|
|
|
|
|
|
LZ4_stream_t_internal* const cctx, |
534
|
|
|
|
|
|
|
const char* const source, |
535
|
|
|
|
|
|
|
char* const dest, |
536
|
|
|
|
|
|
|
const int inputSize, |
537
|
|
|
|
|
|
|
const int maxOutputSize, |
538
|
|
|
|
|
|
|
const limitedOutput_directive outputLimited, |
539
|
|
|
|
|
|
|
const tableType_t tableType, |
540
|
|
|
|
|
|
|
const dict_directive dict, |
541
|
|
|
|
|
|
|
const dictIssue_directive dictIssue, |
542
|
|
|
|
|
|
|
const U32 acceleration) |
543
|
|
|
|
|
|
|
{ |
544
|
13
|
|
|
|
|
|
const BYTE* ip = (const BYTE*) source; |
545
|
|
|
|
|
|
|
const BYTE* base; |
546
|
|
|
|
|
|
|
const BYTE* lowLimit; |
547
|
13
|
|
|
|
|
|
const BYTE* const lowRefLimit = ip - cctx->dictSize; |
548
|
13
|
|
|
|
|
|
const BYTE* const dictionary = cctx->dictionary; |
549
|
13
|
|
|
|
|
|
const BYTE* const dictEnd = dictionary + cctx->dictSize; |
550
|
13
|
|
|
|
|
|
const ptrdiff_t dictDelta = dictEnd - (const BYTE*)source; |
551
|
13
|
|
|
|
|
|
const BYTE* anchor = (const BYTE*) source; |
552
|
13
|
|
|
|
|
|
const BYTE* const iend = ip + inputSize; |
553
|
13
|
|
|
|
|
|
const BYTE* const mflimit = iend - MFLIMIT; |
554
|
13
|
|
|
|
|
|
const BYTE* const matchlimit = iend - LASTLITERALS; |
555
|
|
|
|
|
|
|
|
556
|
13
|
|
|
|
|
|
BYTE* op = (BYTE*) dest; |
557
|
13
|
|
|
|
|
|
BYTE* const olimit = op + maxOutputSize; |
558
|
|
|
|
|
|
|
|
559
|
|
|
|
|
|
|
U32 forwardH; |
560
|
|
|
|
|
|
|
|
561
|
|
|
|
|
|
|
/* Init conditions */ |
562
|
13
|
0
|
|
|
|
|
if ((U32)inputSize > (U32)LZ4_MAX_INPUT_SIZE) return 0; /* Unsupported inputSize, too large (or negative) */ |
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
563
|
|
|
|
|
|
|
switch(dict) |
564
|
|
|
|
|
|
|
{ |
565
|
|
|
|
|
|
|
case noDict: |
566
|
|
|
|
|
|
|
default: |
567
|
0
|
|
|
|
|
|
base = (const BYTE*)source; |
568
|
0
|
|
|
|
|
|
lowLimit = (const BYTE*)source; |
569
|
|
|
|
|
|
|
break; |
570
|
|
|
|
|
|
|
case withPrefix64k: |
571
|
12
|
|
|
|
|
|
base = (const BYTE*)source - cctx->currentOffset; |
572
|
12
|
|
|
|
|
|
lowLimit = (const BYTE*)source - cctx->dictSize; |
573
|
|
|
|
|
|
|
break; |
574
|
|
|
|
|
|
|
case usingExtDict: |
575
|
1
|
|
|
|
|
|
base = (const BYTE*)source - cctx->currentOffset; |
576
|
1
|
|
|
|
|
|
lowLimit = (const BYTE*)source; |
577
|
|
|
|
|
|
|
break; |
578
|
|
|
|
|
|
|
} |
579
|
0
|
0
|
|
|
|
|
if ((tableType == byU16) && (inputSize>=LZ4_64Klimit)) return 0; /* Size too large (not within 64K limit) */ |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
580
|
13
|
0
|
|
|
|
|
if (inputSize
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
581
|
|
|
|
|
|
|
|
582
|
|
|
|
|
|
|
/* First Byte */ |
583
|
13
|
|
|
|
|
|
LZ4_putPosition(ip, cctx->hashTable, tableType, base); |
584
|
13
|
|
|
|
|
|
ip++; forwardH = LZ4_hashPosition(ip, tableType); |
585
|
|
|
|
|
|
|
|
586
|
|
|
|
|
|
|
/* Main Loop */ |
587
|
|
|
|
|
|
|
for ( ; ; ) { |
588
|
49973
|
|
|
|
|
|
ptrdiff_t refDelta = 0; |
589
|
|
|
|
|
|
|
const BYTE* match; |
590
|
|
|
|
|
|
|
BYTE* token; |
591
|
|
|
|
|
|
|
|
592
|
|
|
|
|
|
|
/* Find a match */ |
593
|
49973
|
|
|
|
|
|
{ const BYTE* forwardIp = ip; |
594
|
49973
|
|
|
|
|
|
unsigned step = 1; |
595
|
49973
|
|
|
|
|
|
unsigned searchMatchNb = acceleration << LZ4_skipTrigger; |
596
|
|
|
|
|
|
|
do { |
597
|
489497
|
|
|
|
|
|
U32 const h = forwardH; |
598
|
489497
|
|
|
|
|
|
ip = forwardIp; |
599
|
489497
|
|
|
|
|
|
forwardIp += step; |
600
|
489497
|
|
|
|
|
|
step = (searchMatchNb++ >> LZ4_skipTrigger); |
601
|
|
|
|
|
|
|
|
602
|
489497
|
0
|
|
|
|
|
if (unlikely(forwardIp > mflimit)) goto _last_literals; |
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
603
|
|
|
|
|
|
|
|
604
|
489489
|
|
|
|
|
|
match = LZ4_getPositionOnHash(h, cctx->hashTable, tableType, base); |
605
|
|
|
|
|
|
|
if (dict==usingExtDict) { |
606
|
37382
|
|
|
|
|
|
if (match < (const BYTE*)source) { |
607
|
0
|
|
|
|
|
|
refDelta = dictDelta; |
608
|
0
|
|
|
|
|
|
lowLimit = dictionary; |
609
|
|
|
|
|
|
|
} else { |
610
|
37382
|
|
|
|
|
|
refDelta = 0; |
611
|
37382
|
|
|
|
|
|
lowLimit = (const BYTE*)source; |
612
|
|
|
|
|
|
|
} } |
613
|
489489
|
|
|
|
|
|
forwardH = LZ4_hashPosition(forwardIp, tableType); |
614
|
489489
|
|
|
|
|
|
LZ4_putPositionOnHash(ip, h, cctx->hashTable, tableType, base); |
615
|
|
|
|
|
|
|
|
616
|
|
|
|
|
|
|
} while ( ((dictIssue==dictSmall) ? (match < lowRefLimit) : 0) |
617
|
489489
|
|
|
|
|
|
|| ((tableType==byU16) ? 0 : (match + MAX_DISTANCE < ip)) |
618
|
489482
|
0
|
|
|
|
|
|| (LZ4_read32(match+refDelta) != LZ4_read32(ip)) ); |
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
619
|
|
|
|
|
|
|
} |
620
|
|
|
|
|
|
|
|
621
|
|
|
|
|
|
|
/* Catch up */ |
622
|
50016
|
0
|
|
|
|
|
while (((ip>anchor) & (match+refDelta > lowLimit)) && (unlikely(ip[-1]==match[refDelta-1]))) { ip--; match--; } |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
623
|
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
/* Encode Literals */ |
625
|
49965
|
|
|
|
|
|
{ unsigned const litLength = (unsigned)(ip - anchor); |
626
|
49965
|
|
|
|
|
|
token = op++; |
627
|
49965
|
0
|
|
|
|
|
if ((outputLimited) && /* Check output buffer overflow */ |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
628
|
49965
|
|
|
|
|
|
(unlikely(op + litLength + (2 + 1 + LASTLITERALS) + (litLength/255) > olimit))) |
629
|
0
|
|
|
|
|
|
return 0; |
630
|
49965
|
0
|
|
|
|
|
if (litLength >= RUN_MASK) { |
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
631
|
98
|
|
|
|
|
|
int len = (int)litLength-RUN_MASK; |
632
|
98
|
|
|
|
|
|
*token = (RUN_MASK<
|
633
|
98
|
0
|
|
|
|
|
for(; len >= 255 ; len-=255) *op++ = 255; |
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
634
|
98
|
|
|
|
|
|
*op++ = (BYTE)len; |
635
|
|
|
|
|
|
|
} |
636
|
49867
|
|
|
|
|
|
else *token = (BYTE)(litLength<
|
637
|
|
|
|
|
|
|
|
638
|
|
|
|
|
|
|
/* Copy Literals */ |
639
|
49965
|
|
|
|
|
|
LZ4_wildCopy(op, anchor, op+litLength); |
640
|
49965
|
|
|
|
|
|
op+=litLength; |
641
|
|
|
|
|
|
|
} |
642
|
|
|
|
|
|
|
|
643
|
|
|
|
|
|
|
_next_match: |
644
|
|
|
|
|
|
|
/* Encode Offset */ |
645
|
49973
|
|
|
|
|
|
LZ4_writeLE16(op, (U16)(ip-match)); op+=2; |
646
|
|
|
|
|
|
|
|
647
|
|
|
|
|
|
|
/* Encode MatchLength */ |
648
|
|
|
|
|
|
|
{ unsigned matchCode; |
649
|
|
|
|
|
|
|
|
650
|
4091
|
|
|
|
|
|
if ((dict==usingExtDict) && (lowLimit==dictionary)) { |
651
|
|
|
|
|
|
|
const BYTE* limit; |
652
|
0
|
|
|
|
|
|
match += refDelta; |
653
|
0
|
|
|
|
|
|
limit = ip + (dictEnd-match); |
654
|
0
|
0
|
|
|
|
|
if (limit > matchlimit) limit = matchlimit; |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
655
|
0
|
|
|
|
|
|
matchCode = LZ4_count(ip+MINMATCH, match+MINMATCH, limit); |
656
|
0
|
|
|
|
|
|
ip += MINMATCH + matchCode; |
657
|
0
|
0
|
|
|
|
|
if (ip==limit) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
658
|
0
|
|
|
|
|
|
unsigned const more = LZ4_count(ip, (const BYTE*)source, matchlimit); |
659
|
0
|
|
|
|
|
|
matchCode += more; |
660
|
0
|
|
|
|
|
|
ip += more; |
661
|
|
|
|
|
|
|
} |
662
|
|
|
|
|
|
|
} else { |
663
|
99946
|
|
|
|
|
|
matchCode = LZ4_count(ip+MINMATCH, match+MINMATCH, matchlimit); |
664
|
4091
|
|
|
|
|
|
ip += MINMATCH + matchCode; |
665
|
|
|
|
|
|
|
} |
666
|
|
|
|
|
|
|
|
667
|
49973
|
0
|
|
|
|
|
if ( outputLimited && /* Check output buffer overflow */ |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
668
|
49973
|
|
|
|
|
|
(unlikely(op + (1 + LASTLITERALS) + (matchCode>>8) > olimit)) ) |
669
|
0
|
|
|
|
|
|
return 0; |
670
|
49973
|
0
|
|
|
|
|
if (matchCode >= ML_MASK) { |
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
671
|
0
|
|
|
|
|
|
*token += ML_MASK; |
672
|
0
|
|
|
|
|
|
matchCode -= ML_MASK; |
673
|
0
|
|
|
|
|
|
LZ4_write32(op, 0xFFFFFFFF); |
674
|
0
|
0
|
|
|
|
|
while (matchCode >= 4*255) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
675
|
0
|
|
|
|
|
|
op+=4; |
676
|
0
|
|
|
|
|
|
LZ4_write32(op, 0xFFFFFFFF); |
677
|
0
|
|
|
|
|
|
matchCode -= 4*255; |
678
|
|
|
|
|
|
|
} |
679
|
0
|
|
|
|
|
|
op += matchCode / 255; |
680
|
0
|
|
|
|
|
|
*op++ = (BYTE)(matchCode % 255); |
681
|
|
|
|
|
|
|
} else |
682
|
49973
|
|
|
|
|
|
*token += (BYTE)(matchCode); |
683
|
|
|
|
|
|
|
} |
684
|
|
|
|
|
|
|
|
685
|
49973
|
|
|
|
|
|
anchor = ip; |
686
|
|
|
|
|
|
|
|
687
|
|
|
|
|
|
|
/* Test end of chunk */ |
688
|
49973
|
0
|
|
|
|
|
if (ip > mflimit) break; |
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
689
|
|
|
|
|
|
|
|
690
|
|
|
|
|
|
|
/* Fill table */ |
691
|
49968
|
|
|
|
|
|
LZ4_putPosition(ip-2, cctx->hashTable, tableType, base); |
692
|
|
|
|
|
|
|
|
693
|
|
|
|
|
|
|
/* Test next position */ |
694
|
99936
|
|
|
|
|
|
match = LZ4_getPosition(ip, cctx->hashTable, tableType, base); |
695
|
|
|
|
|
|
|
if (dict==usingExtDict) { |
696
|
4090
|
|
|
|
|
|
if (match < (const BYTE*)source) { |
697
|
0
|
|
|
|
|
|
refDelta = dictDelta; |
698
|
0
|
|
|
|
|
|
lowLimit = dictionary; |
699
|
|
|
|
|
|
|
} else { |
700
|
4090
|
|
|
|
|
|
refDelta = 0; |
701
|
4090
|
|
|
|
|
|
lowLimit = (const BYTE*)source; |
702
|
|
|
|
|
|
|
} } |
703
|
49968
|
|
|
|
|
|
LZ4_putPosition(ip, cctx->hashTable, tableType, base); |
704
|
|
|
|
|
|
|
if ( ((dictIssue==dictSmall) ? (match>=lowRefLimit) : 1) |
705
|
49968
|
|
|
|
|
|
&& (match+MAX_DISTANCE>=ip) |
706
|
49967
|
0
|
|
|
|
|
&& (LZ4_read32(match+refDelta)==LZ4_read32(ip)) ) |
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
707
|
8
|
|
|
|
|
|
{ token=op++; *token=0; goto _next_match; } |
708
|
|
|
|
|
|
|
|
709
|
|
|
|
|
|
|
/* Prepare next loop */ |
710
|
49960
|
|
|
|
|
|
forwardH = LZ4_hashPosition(++ip, tableType); |
711
|
|
|
|
|
|
|
} |
712
|
|
|
|
|
|
|
|
713
|
|
|
|
|
|
|
_last_literals: |
714
|
|
|
|
|
|
|
/* Encode Last Literals */ |
715
|
13
|
|
|
|
|
|
{ size_t const lastRun = (size_t)(iend - anchor); |
716
|
13
|
0
|
|
|
|
|
if ( (outputLimited) && /* Check output buffer overflow */ |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
717
|
13
|
|
|
|
|
|
((op - (BYTE*)dest) + lastRun + 1 + ((lastRun+255-RUN_MASK)/255) > (U32)maxOutputSize) ) |
718
|
0
|
|
|
|
|
|
return 0; |
719
|
13
|
0
|
|
|
|
|
if (lastRun >= RUN_MASK) { |
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
720
|
0
|
|
|
|
|
|
size_t accumulator = lastRun - RUN_MASK; |
721
|
0
|
|
|
|
|
|
*op++ = RUN_MASK << ML_BITS; |
722
|
0
|
0
|
|
|
|
|
for(; accumulator >= 255 ; accumulator-=255) *op++ = 255; |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
723
|
0
|
|
|
|
|
|
*op++ = (BYTE) accumulator; |
724
|
|
|
|
|
|
|
} else { |
725
|
13
|
|
|
|
|
|
*op++ = (BYTE)(lastRun<
|
726
|
|
|
|
|
|
|
} |
727
|
13
|
|
|
|
|
|
memcpy(op, anchor, lastRun); |
728
|
13
|
|
|
|
|
|
op += lastRun; |
729
|
|
|
|
|
|
|
} |
730
|
|
|
|
|
|
|
|
731
|
|
|
|
|
|
|
/* End */ |
732
|
13
|
|
|
|
|
|
return (int) (((char*)op)-dest); |
733
|
|
|
|
|
|
|
} |
734
|
|
|
|
|
|
|
|
735
|
|
|
|
|
|
|
|
736
|
0
|
|
|
|
|
|
int LZ4_compress_fast_extState(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int acceleration) |
737
|
|
|
|
|
|
|
{ |
738
|
0
|
|
|
|
|
|
LZ4_stream_t_internal* ctx = &((LZ4_stream_t*)state)->internal_donotuse; |
739
|
0
|
|
|
|
|
|
LZ4_resetStream((LZ4_stream_t*)state); |
740
|
0
|
0
|
|
|
|
|
if (acceleration < 1) acceleration = ACCELERATION_DEFAULT; |
741
|
|
|
|
|
|
|
|
742
|
0
|
0
|
|
|
|
|
if (maxOutputSize >= LZ4_compressBound(inputSize)) { |
743
|
0
|
0
|
|
|
|
|
if (inputSize < LZ4_64Klimit) |
744
|
0
|
|
|
|
|
|
return LZ4_compress_generic(ctx, source, dest, inputSize, 0, notLimited, byU16, noDict, noDictIssue, acceleration); |
745
|
|
|
|
|
|
|
else |
746
|
0
|
|
|
|
|
|
return LZ4_compress_generic(ctx, source, dest, inputSize, 0, notLimited, (sizeof(void*)==8) ? byU32 : byPtr, noDict, noDictIssue, acceleration); |
747
|
|
|
|
|
|
|
} else { |
748
|
0
|
0
|
|
|
|
|
if (inputSize < LZ4_64Klimit) |
749
|
0
|
|
|
|
|
|
return LZ4_compress_generic(ctx, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, acceleration); |
750
|
|
|
|
|
|
|
else |
751
|
0
|
|
|
|
|
|
return LZ4_compress_generic(ctx, source, dest, inputSize, maxOutputSize, limitedOutput, (sizeof(void*)==8) ? byU32 : byPtr, noDict, noDictIssue, acceleration); |
752
|
|
|
|
|
|
|
} |
753
|
|
|
|
|
|
|
} |
754
|
|
|
|
|
|
|
|
755
|
|
|
|
|
|
|
|
756
|
0
|
|
|
|
|
|
int LZ4_compress_fast(const char* source, char* dest, int inputSize, int maxOutputSize, int acceleration) |
757
|
|
|
|
|
|
|
{ |
758
|
|
|
|
|
|
|
#if (LZ4_HEAPMODE) |
759
|
|
|
|
|
|
|
void* ctxPtr = ALLOCATOR(1, sizeof(LZ4_stream_t)); /* malloc-calloc always properly aligned */ |
760
|
|
|
|
|
|
|
#else |
761
|
|
|
|
|
|
|
LZ4_stream_t ctx; |
762
|
0
|
|
|
|
|
|
void* const ctxPtr = &ctx; |
763
|
|
|
|
|
|
|
#endif |
764
|
|
|
|
|
|
|
|
765
|
0
|
|
|
|
|
|
int const result = LZ4_compress_fast_extState(ctxPtr, source, dest, inputSize, maxOutputSize, acceleration); |
766
|
|
|
|
|
|
|
|
767
|
|
|
|
|
|
|
#if (LZ4_HEAPMODE) |
768
|
|
|
|
|
|
|
FREEMEM(ctxPtr); |
769
|
|
|
|
|
|
|
#endif |
770
|
0
|
|
|
|
|
|
return result; |
771
|
|
|
|
|
|
|
} |
772
|
|
|
|
|
|
|
|
773
|
|
|
|
|
|
|
|
774
|
0
|
|
|
|
|
|
int LZ4_compress_default(const char* source, char* dest, int inputSize, int maxOutputSize) |
775
|
|
|
|
|
|
|
{ |
776
|
0
|
|
|
|
|
|
return LZ4_compress_fast(source, dest, inputSize, maxOutputSize, 1); |
777
|
|
|
|
|
|
|
} |
778
|
|
|
|
|
|
|
|
779
|
|
|
|
|
|
|
|
780
|
|
|
|
|
|
|
/* hidden debug function */ |
781
|
|
|
|
|
|
|
/* strangely enough, gcc generates faster code when this function is uncommented, even if unused */ |
782
|
0
|
|
|
|
|
|
int LZ4_compress_fast_force(const char* source, char* dest, int inputSize, int maxOutputSize, int acceleration) |
783
|
|
|
|
|
|
|
{ |
784
|
|
|
|
|
|
|
LZ4_stream_t ctx; |
785
|
0
|
|
|
|
|
|
LZ4_resetStream(&ctx); |
786
|
|
|
|
|
|
|
|
787
|
0
|
0
|
|
|
|
|
if (inputSize < LZ4_64Klimit) |
788
|
0
|
|
|
|
|
|
return LZ4_compress_generic(&ctx.internal_donotuse, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, acceleration); |
789
|
|
|
|
|
|
|
else |
790
|
0
|
|
|
|
|
|
return LZ4_compress_generic(&ctx.internal_donotuse, source, dest, inputSize, maxOutputSize, limitedOutput, sizeof(void*)==8 ? byU32 : byPtr, noDict, noDictIssue, acceleration); |
791
|
|
|
|
|
|
|
} |
792
|
|
|
|
|
|
|
|
793
|
|
|
|
|
|
|
|
794
|
|
|
|
|
|
|
/*-****************************** |
795
|
|
|
|
|
|
|
* *_destSize() variant |
796
|
|
|
|
|
|
|
********************************/ |
797
|
|
|
|
|
|
|
|
798
|
0
|
|
|
|
|
|
static int LZ4_compress_destSize_generic( |
799
|
|
|
|
|
|
|
LZ4_stream_t_internal* const ctx, |
800
|
|
|
|
|
|
|
const char* const src, |
801
|
|
|
|
|
|
|
char* const dst, |
802
|
|
|
|
|
|
|
int* const srcSizePtr, |
803
|
|
|
|
|
|
|
const int targetDstSize, |
804
|
|
|
|
|
|
|
const tableType_t tableType) |
805
|
|
|
|
|
|
|
{ |
806
|
0
|
|
|
|
|
|
const BYTE* ip = (const BYTE*) src; |
807
|
0
|
|
|
|
|
|
const BYTE* base = (const BYTE*) src; |
808
|
0
|
|
|
|
|
|
const BYTE* lowLimit = (const BYTE*) src; |
809
|
0
|
|
|
|
|
|
const BYTE* anchor = ip; |
810
|
0
|
|
|
|
|
|
const BYTE* const iend = ip + *srcSizePtr; |
811
|
0
|
|
|
|
|
|
const BYTE* const mflimit = iend - MFLIMIT; |
812
|
0
|
|
|
|
|
|
const BYTE* const matchlimit = iend - LASTLITERALS; |
813
|
|
|
|
|
|
|
|
814
|
0
|
|
|
|
|
|
BYTE* op = (BYTE*) dst; |
815
|
0
|
|
|
|
|
|
BYTE* const oend = op + targetDstSize; |
816
|
0
|
|
|
|
|
|
BYTE* const oMaxLit = op + targetDstSize - 2 /* offset */ - 8 /* because 8+MINMATCH==MFLIMIT */ - 1 /* token */; |
817
|
0
|
|
|
|
|
|
BYTE* const oMaxMatch = op + targetDstSize - (LASTLITERALS + 1 /* token */); |
818
|
0
|
|
|
|
|
|
BYTE* const oMaxSeq = oMaxLit - 1 /* token */; |
819
|
|
|
|
|
|
|
|
820
|
|
|
|
|
|
|
U32 forwardH; |
821
|
|
|
|
|
|
|
|
822
|
|
|
|
|
|
|
|
823
|
|
|
|
|
|
|
/* Init conditions */ |
824
|
0
|
0
|
|
|
|
|
if (targetDstSize < 1) return 0; /* Impossible to store anything */ |
825
|
0
|
0
|
|
|
|
|
if ((U32)*srcSizePtr > (U32)LZ4_MAX_INPUT_SIZE) return 0; /* Unsupported input size, too large (or negative) */ |
826
|
0
|
0
|
|
|
|
|
if ((tableType == byU16) && (*srcSizePtr>=LZ4_64Klimit)) return 0; /* Size too large (not within 64K limit) */ |
|
|
0
|
|
|
|
|
|
827
|
0
|
0
|
|
|
|
|
if (*srcSizePtr
|
828
|
|
|
|
|
|
|
|
829
|
|
|
|
|
|
|
/* First Byte */ |
830
|
0
|
|
|
|
|
|
*srcSizePtr = 0; |
831
|
0
|
|
|
|
|
|
LZ4_putPosition(ip, ctx->hashTable, tableType, base); |
832
|
0
|
|
|
|
|
|
ip++; forwardH = LZ4_hashPosition(ip, tableType); |
833
|
|
|
|
|
|
|
|
834
|
|
|
|
|
|
|
/* Main Loop */ |
835
|
|
|
|
|
|
|
for ( ; ; ) { |
836
|
|
|
|
|
|
|
const BYTE* match; |
837
|
|
|
|
|
|
|
BYTE* token; |
838
|
|
|
|
|
|
|
|
839
|
|
|
|
|
|
|
/* Find a match */ |
840
|
0
|
|
|
|
|
|
{ const BYTE* forwardIp = ip; |
841
|
0
|
|
|
|
|
|
unsigned step = 1; |
842
|
0
|
|
|
|
|
|
unsigned searchMatchNb = 1 << LZ4_skipTrigger; |
843
|
|
|
|
|
|
|
|
844
|
|
|
|
|
|
|
do { |
845
|
0
|
|
|
|
|
|
U32 h = forwardH; |
846
|
0
|
|
|
|
|
|
ip = forwardIp; |
847
|
0
|
|
|
|
|
|
forwardIp += step; |
848
|
0
|
|
|
|
|
|
step = (searchMatchNb++ >> LZ4_skipTrigger); |
849
|
|
|
|
|
|
|
|
850
|
0
|
0
|
|
|
|
|
if (unlikely(forwardIp > mflimit)) goto _last_literals; |
851
|
|
|
|
|
|
|
|
852
|
0
|
|
|
|
|
|
match = LZ4_getPositionOnHash(h, ctx->hashTable, tableType, base); |
853
|
0
|
|
|
|
|
|
forwardH = LZ4_hashPosition(forwardIp, tableType); |
854
|
0
|
|
|
|
|
|
LZ4_putPositionOnHash(ip, h, ctx->hashTable, tableType, base); |
855
|
|
|
|
|
|
|
|
856
|
0
|
|
|
|
|
|
} while ( ((tableType==byU16) ? 0 : (match + MAX_DISTANCE < ip)) |
857
|
0
|
0
|
|
|
|
|
|| (LZ4_read32(match) != LZ4_read32(ip)) ); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
858
|
|
|
|
|
|
|
} |
859
|
|
|
|
|
|
|
|
860
|
|
|
|
|
|
|
/* Catch up */ |
861
|
0
|
0
|
|
|
|
|
while ((ip>anchor) && (match > lowLimit) && (unlikely(ip[-1]==match[-1]))) { ip--; match--; } |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
862
|
|
|
|
|
|
|
|
863
|
|
|
|
|
|
|
/* Encode Literal length */ |
864
|
0
|
|
|
|
|
|
{ unsigned litLength = (unsigned)(ip - anchor); |
865
|
0
|
|
|
|
|
|
token = op++; |
866
|
0
|
0
|
|
|
|
|
if (op + ((litLength+240)/255) + litLength > oMaxLit) { |
867
|
|
|
|
|
|
|
/* Not enough space for a last match */ |
868
|
0
|
|
|
|
|
|
op--; |
869
|
0
|
|
|
|
|
|
goto _last_literals; |
870
|
|
|
|
|
|
|
} |
871
|
0
|
0
|
|
|
|
|
if (litLength>=RUN_MASK) { |
872
|
0
|
|
|
|
|
|
unsigned len = litLength - RUN_MASK; |
873
|
0
|
|
|
|
|
|
*token=(RUN_MASK<
|
874
|
0
|
0
|
|
|
|
|
for(; len >= 255 ; len-=255) *op++ = 255; |
875
|
0
|
|
|
|
|
|
*op++ = (BYTE)len; |
876
|
|
|
|
|
|
|
} |
877
|
0
|
|
|
|
|
|
else *token = (BYTE)(litLength<
|
878
|
|
|
|
|
|
|
|
879
|
|
|
|
|
|
|
/* Copy Literals */ |
880
|
0
|
|
|
|
|
|
LZ4_wildCopy(op, anchor, op+litLength); |
881
|
0
|
|
|
|
|
|
op += litLength; |
882
|
|
|
|
|
|
|
} |
883
|
|
|
|
|
|
|
|
884
|
|
|
|
|
|
|
_next_match: |
885
|
|
|
|
|
|
|
/* Encode Offset */ |
886
|
0
|
|
|
|
|
|
LZ4_writeLE16(op, (U16)(ip-match)); op+=2; |
887
|
|
|
|
|
|
|
|
888
|
|
|
|
|
|
|
/* Encode MatchLength */ |
889
|
0
|
|
|
|
|
|
{ size_t matchLength = LZ4_count(ip+MINMATCH, match+MINMATCH, matchlimit); |
890
|
|
|
|
|
|
|
|
891
|
0
|
0
|
|
|
|
|
if (op + ((matchLength+240)/255) > oMaxMatch) { |
892
|
|
|
|
|
|
|
/* Match description too long : reduce it */ |
893
|
0
|
|
|
|
|
|
matchLength = (15-1) + (oMaxMatch-op) * 255; |
894
|
|
|
|
|
|
|
} |
895
|
0
|
|
|
|
|
|
ip += MINMATCH + matchLength; |
896
|
|
|
|
|
|
|
|
897
|
0
|
0
|
|
|
|
|
if (matchLength>=ML_MASK) { |
898
|
0
|
|
|
|
|
|
*token += ML_MASK; |
899
|
0
|
|
|
|
|
|
matchLength -= ML_MASK; |
900
|
0
|
0
|
|
|
|
|
while (matchLength >= 255) { matchLength-=255; *op++ = 255; } |
901
|
0
|
|
|
|
|
|
*op++ = (BYTE)matchLength; |
902
|
|
|
|
|
|
|
} |
903
|
0
|
|
|
|
|
|
else *token += (BYTE)(matchLength); |
904
|
|
|
|
|
|
|
} |
905
|
|
|
|
|
|
|
|
906
|
0
|
|
|
|
|
|
anchor = ip; |
907
|
|
|
|
|
|
|
|
908
|
|
|
|
|
|
|
/* Test end of block */ |
909
|
0
|
0
|
|
|
|
|
if (ip > mflimit) break; |
910
|
0
|
0
|
|
|
|
|
if (op > oMaxSeq) break; |
911
|
|
|
|
|
|
|
|
912
|
|
|
|
|
|
|
/* Fill table */ |
913
|
0
|
|
|
|
|
|
LZ4_putPosition(ip-2, ctx->hashTable, tableType, base); |
914
|
|
|
|
|
|
|
|
915
|
|
|
|
|
|
|
/* Test next position */ |
916
|
0
|
|
|
|
|
|
match = LZ4_getPosition(ip, ctx->hashTable, tableType, base); |
917
|
0
|
|
|
|
|
|
LZ4_putPosition(ip, ctx->hashTable, tableType, base); |
918
|
0
|
0
|
|
|
|
|
if ( (match+MAX_DISTANCE>=ip) |
919
|
0
|
0
|
|
|
|
|
&& (LZ4_read32(match)==LZ4_read32(ip)) ) |
920
|
0
|
|
|
|
|
|
{ token=op++; *token=0; goto _next_match; } |
921
|
|
|
|
|
|
|
|
922
|
|
|
|
|
|
|
/* Prepare next loop */ |
923
|
0
|
|
|
|
|
|
forwardH = LZ4_hashPosition(++ip, tableType); |
924
|
0
|
|
|
|
|
|
} |
925
|
|
|
|
|
|
|
|
926
|
|
|
|
|
|
|
_last_literals: |
927
|
|
|
|
|
|
|
/* Encode Last Literals */ |
928
|
0
|
|
|
|
|
|
{ size_t lastRunSize = (size_t)(iend - anchor); |
929
|
0
|
0
|
|
|
|
|
if (op + 1 /* token */ + ((lastRunSize+240)/255) /* litLength */ + lastRunSize /* literals */ > oend) { |
930
|
|
|
|
|
|
|
/* adapt lastRunSize to fill 'dst' */ |
931
|
0
|
|
|
|
|
|
lastRunSize = (oend-op) - 1; |
932
|
0
|
|
|
|
|
|
lastRunSize -= (lastRunSize+240)/255; |
933
|
|
|
|
|
|
|
} |
934
|
0
|
|
|
|
|
|
ip = anchor + lastRunSize; |
935
|
|
|
|
|
|
|
|
936
|
0
|
0
|
|
|
|
|
if (lastRunSize >= RUN_MASK) { |
937
|
0
|
|
|
|
|
|
size_t accumulator = lastRunSize - RUN_MASK; |
938
|
0
|
|
|
|
|
|
*op++ = RUN_MASK << ML_BITS; |
939
|
0
|
0
|
|
|
|
|
for(; accumulator >= 255 ; accumulator-=255) *op++ = 255; |
940
|
0
|
|
|
|
|
|
*op++ = (BYTE) accumulator; |
941
|
|
|
|
|
|
|
} else { |
942
|
0
|
|
|
|
|
|
*op++ = (BYTE)(lastRunSize<
|
943
|
|
|
|
|
|
|
} |
944
|
0
|
|
|
|
|
|
memcpy(op, anchor, lastRunSize); |
945
|
0
|
|
|
|
|
|
op += lastRunSize; |
946
|
|
|
|
|
|
|
} |
947
|
|
|
|
|
|
|
|
948
|
|
|
|
|
|
|
/* End */ |
949
|
0
|
|
|
|
|
|
*srcSizePtr = (int) (((const char*)ip)-src); |
950
|
0
|
|
|
|
|
|
return (int) (((char*)op)-dst); |
951
|
|
|
|
|
|
|
} |
952
|
|
|
|
|
|
|
|
953
|
|
|
|
|
|
|
|
954
|
0
|
|
|
|
|
|
static int LZ4_compress_destSize_extState (LZ4_stream_t* state, const char* src, char* dst, int* srcSizePtr, int targetDstSize) |
955
|
|
|
|
|
|
|
{ |
956
|
0
|
|
|
|
|
|
LZ4_resetStream(state); |
957
|
|
|
|
|
|
|
|
958
|
0
|
0
|
|
|
|
|
if (targetDstSize >= LZ4_compressBound(*srcSizePtr)) { /* compression success is guaranteed */ |
959
|
0
|
|
|
|
|
|
return LZ4_compress_fast_extState(state, src, dst, *srcSizePtr, targetDstSize, 1); |
960
|
|
|
|
|
|
|
} else { |
961
|
0
|
0
|
|
|
|
|
if (*srcSizePtr < LZ4_64Klimit) |
962
|
0
|
|
|
|
|
|
return LZ4_compress_destSize_generic(&state->internal_donotuse, src, dst, srcSizePtr, targetDstSize, byU16); |
963
|
|
|
|
|
|
|
else |
964
|
0
|
|
|
|
|
|
return LZ4_compress_destSize_generic(&state->internal_donotuse, src, dst, srcSizePtr, targetDstSize, sizeof(void*)==8 ? byU32 : byPtr); |
965
|
|
|
|
|
|
|
} |
966
|
|
|
|
|
|
|
} |
967
|
|
|
|
|
|
|
|
968
|
|
|
|
|
|
|
|
969
|
0
|
|
|
|
|
|
int LZ4_compress_destSize(const char* src, char* dst, int* srcSizePtr, int targetDstSize) |
970
|
|
|
|
|
|
|
{ |
971
|
|
|
|
|
|
|
#if (LZ4_HEAPMODE) |
972
|
|
|
|
|
|
|
LZ4_stream_t* ctx = (LZ4_stream_t*)ALLOCATOR(1, sizeof(LZ4_stream_t)); /* malloc-calloc always properly aligned */ |
973
|
|
|
|
|
|
|
#else |
974
|
|
|
|
|
|
|
LZ4_stream_t ctxBody; |
975
|
0
|
|
|
|
|
|
LZ4_stream_t* ctx = &ctxBody; |
976
|
|
|
|
|
|
|
#endif |
977
|
|
|
|
|
|
|
|
978
|
0
|
|
|
|
|
|
int result = LZ4_compress_destSize_extState(ctx, src, dst, srcSizePtr, targetDstSize); |
979
|
|
|
|
|
|
|
|
980
|
|
|
|
|
|
|
#if (LZ4_HEAPMODE) |
981
|
|
|
|
|
|
|
FREEMEM(ctx); |
982
|
|
|
|
|
|
|
#endif |
983
|
0
|
|
|
|
|
|
return result; |
984
|
|
|
|
|
|
|
} |
985
|
|
|
|
|
|
|
|
986
|
|
|
|
|
|
|
|
987
|
|
|
|
|
|
|
|
988
|
|
|
|
|
|
|
/*-****************************** |
989
|
|
|
|
|
|
|
* Streaming functions |
990
|
|
|
|
|
|
|
********************************/ |
991
|
|
|
|
|
|
|
|
992
|
0
|
|
|
|
|
|
LZ4_stream_t* LZ4_createStream(void) |
993
|
|
|
|
|
|
|
{ |
994
|
0
|
|
|
|
|
|
LZ4_stream_t* lz4s = (LZ4_stream_t*)ALLOCATOR(8, LZ4_STREAMSIZE_U64); |
995
|
|
|
|
|
|
|
LZ4_STATIC_ASSERT(LZ4_STREAMSIZE >= sizeof(LZ4_stream_t_internal)); /* A compilation error here means LZ4_STREAMSIZE is not large enough */ |
996
|
0
|
|
|
|
|
|
LZ4_resetStream(lz4s); |
997
|
0
|
|
|
|
|
|
return lz4s; |
998
|
|
|
|
|
|
|
} |
999
|
|
|
|
|
|
|
|
1000
|
1
|
|
|
|
|
|
void LZ4_resetStream (LZ4_stream_t* LZ4_stream) |
1001
|
|
|
|
|
|
|
{ |
1002
|
|
|
|
|
|
|
DEBUGLOG(4, "LZ4_resetStream"); |
1003
|
1
|
|
|
|
|
|
MEM_INIT(LZ4_stream, 0, sizeof(LZ4_stream_t)); |
1004
|
1
|
|
|
|
|
|
} |
1005
|
|
|
|
|
|
|
|
1006
|
0
|
|
|
|
|
|
int LZ4_freeStream (LZ4_stream_t* LZ4_stream) |
1007
|
|
|
|
|
|
|
{ |
1008
|
0
|
0
|
|
|
|
|
if (!LZ4_stream) return 0; /* support free on NULL */ |
1009
|
0
|
|
|
|
|
|
FREEMEM(LZ4_stream); |
1010
|
0
|
|
|
|
|
|
return (0); |
1011
|
|
|
|
|
|
|
} |
1012
|
|
|
|
|
|
|
|
1013
|
|
|
|
|
|
|
|
1014
|
|
|
|
|
|
|
#define HASH_UNIT sizeof(reg_t) |
1015
|
0
|
|
|
|
|
|
int LZ4_loadDict (LZ4_stream_t* LZ4_dict, const char* dictionary, int dictSize) |
1016
|
|
|
|
|
|
|
{ |
1017
|
0
|
|
|
|
|
|
LZ4_stream_t_internal* dict = &LZ4_dict->internal_donotuse; |
1018
|
0
|
|
|
|
|
|
const BYTE* p = (const BYTE*)dictionary; |
1019
|
0
|
|
|
|
|
|
const BYTE* const dictEnd = p + dictSize; |
1020
|
|
|
|
|
|
|
const BYTE* base; |
1021
|
|
|
|
|
|
|
|
1022
|
0
|
0
|
|
|
|
|
if ((dict->initCheck) || (dict->currentOffset > 1 GB)) /* Uninitialized structure, or reuse overflow */ |
|
|
0
|
|
|
|
|
|
1023
|
0
|
|
|
|
|
|
LZ4_resetStream(LZ4_dict); |
1024
|
|
|
|
|
|
|
|
1025
|
0
|
0
|
|
|
|
|
if (dictSize < (int)HASH_UNIT) { |
1026
|
0
|
|
|
|
|
|
dict->dictionary = NULL; |
1027
|
0
|
|
|
|
|
|
dict->dictSize = 0; |
1028
|
0
|
|
|
|
|
|
return 0; |
1029
|
|
|
|
|
|
|
} |
1030
|
|
|
|
|
|
|
|
1031
|
0
|
0
|
|
|
|
|
if ((dictEnd - p) > 64 KB) p = dictEnd - 64 KB; |
1032
|
0
|
|
|
|
|
|
dict->currentOffset += 64 KB; |
1033
|
0
|
|
|
|
|
|
base = p - dict->currentOffset; |
1034
|
0
|
|
|
|
|
|
dict->dictionary = p; |
1035
|
0
|
|
|
|
|
|
dict->dictSize = (U32)(dictEnd - p); |
1036
|
0
|
|
|
|
|
|
dict->currentOffset += dict->dictSize; |
1037
|
|
|
|
|
|
|
|
1038
|
0
|
0
|
|
|
|
|
while (p <= dictEnd-HASH_UNIT) { |
1039
|
0
|
|
|
|
|
|
LZ4_putPosition(p, dict->hashTable, byU32, base); |
1040
|
0
|
|
|
|
|
|
p+=3; |
1041
|
|
|
|
|
|
|
} |
1042
|
|
|
|
|
|
|
|
1043
|
0
|
|
|
|
|
|
return dict->dictSize; |
1044
|
|
|
|
|
|
|
} |
1045
|
|
|
|
|
|
|
|
1046
|
|
|
|
|
|
|
|
1047
|
13
|
|
|
|
|
|
static void LZ4_renormDictT(LZ4_stream_t_internal* LZ4_dict, const BYTE* src) |
1048
|
|
|
|
|
|
|
{ |
1049
|
13
|
50
|
|
|
|
|
if ((LZ4_dict->currentOffset > 0x80000000) || |
|
|
50
|
|
|
|
|
|
1050
|
13
|
|
|
|
|
|
((uptrval)LZ4_dict->currentOffset > (uptrval)src)) { /* address space overflow */ |
1051
|
|
|
|
|
|
|
/* rescale hash table */ |
1052
|
0
|
|
|
|
|
|
U32 const delta = LZ4_dict->currentOffset - 64 KB; |
1053
|
0
|
|
|
|
|
|
const BYTE* dictEnd = LZ4_dict->dictionary + LZ4_dict->dictSize; |
1054
|
|
|
|
|
|
|
int i; |
1055
|
0
|
0
|
|
|
|
|
for (i=0; i
|
1056
|
0
|
0
|
|
|
|
|
if (LZ4_dict->hashTable[i] < delta) LZ4_dict->hashTable[i]=0; |
1057
|
0
|
|
|
|
|
|
else LZ4_dict->hashTable[i] -= delta; |
1058
|
|
|
|
|
|
|
} |
1059
|
0
|
|
|
|
|
|
LZ4_dict->currentOffset = 64 KB; |
1060
|
0
|
0
|
|
|
|
|
if (LZ4_dict->dictSize > 64 KB) LZ4_dict->dictSize = 64 KB; |
1061
|
0
|
|
|
|
|
|
LZ4_dict->dictionary = dictEnd - LZ4_dict->dictSize; |
1062
|
|
|
|
|
|
|
} |
1063
|
13
|
|
|
|
|
|
} |
1064
|
|
|
|
|
|
|
|
1065
|
|
|
|
|
|
|
|
1066
|
13
|
|
|
|
|
|
int LZ4_compress_fast_continue (LZ4_stream_t* LZ4_stream, const char* source, char* dest, int inputSize, int maxOutputSize, int acceleration) |
1067
|
|
|
|
|
|
|
{ |
1068
|
13
|
|
|
|
|
|
LZ4_stream_t_internal* streamPtr = &LZ4_stream->internal_donotuse; |
1069
|
13
|
|
|
|
|
|
const BYTE* const dictEnd = streamPtr->dictionary + streamPtr->dictSize; |
1070
|
|
|
|
|
|
|
|
1071
|
13
|
|
|
|
|
|
const BYTE* smallest = (const BYTE*) source; |
1072
|
13
|
50
|
|
|
|
|
if (streamPtr->initCheck) return 0; /* Uninitialized structure detected */ |
1073
|
13
|
100
|
|
|
|
|
if ((streamPtr->dictSize>0) && (smallest>dictEnd)) smallest = dictEnd; |
|
|
50
|
|
|
|
|
|
1074
|
13
|
|
|
|
|
|
LZ4_renormDictT(streamPtr, smallest); |
1075
|
13
|
50
|
|
|
|
|
if (acceleration < 1) acceleration = ACCELERATION_DEFAULT; |
1076
|
|
|
|
|
|
|
|
1077
|
|
|
|
|
|
|
/* Check overlapping input/dictionary space */ |
1078
|
13
|
|
|
|
|
|
{ const BYTE* sourceEnd = (const BYTE*) source + inputSize; |
1079
|
13
|
50
|
|
|
|
|
if ((sourceEnd > streamPtr->dictionary) && (sourceEnd < dictEnd)) { |
|
|
50
|
|
|
|
|
|
1080
|
0
|
|
|
|
|
|
streamPtr->dictSize = (U32)(dictEnd - sourceEnd); |
1081
|
0
|
0
|
|
|
|
|
if (streamPtr->dictSize > 64 KB) streamPtr->dictSize = 64 KB; |
1082
|
0
|
0
|
|
|
|
|
if (streamPtr->dictSize < 4) streamPtr->dictSize = 0; |
1083
|
0
|
|
|
|
|
|
streamPtr->dictionary = dictEnd - streamPtr->dictSize; |
1084
|
|
|
|
|
|
|
} |
1085
|
|
|
|
|
|
|
} |
1086
|
|
|
|
|
|
|
|
1087
|
|
|
|
|
|
|
/* prefix mode : source data follows dictionary */ |
1088
|
13
|
100
|
|
|
|
|
if (dictEnd == (const BYTE*)source) { |
1089
|
|
|
|
|
|
|
int result; |
1090
|
12
|
50
|
|
|
|
|
if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset)) |
|
|
0
|
|
|
|
|
|
1091
|
0
|
|
|
|
|
|
result = LZ4_compress_generic(streamPtr, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, withPrefix64k, dictSmall, acceleration); |
1092
|
|
|
|
|
|
|
else |
1093
|
12
|
|
|
|
|
|
result = LZ4_compress_generic(streamPtr, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, withPrefix64k, noDictIssue, acceleration); |
1094
|
12
|
|
|
|
|
|
streamPtr->dictSize += (U32)inputSize; |
1095
|
12
|
|
|
|
|
|
streamPtr->currentOffset += (U32)inputSize; |
1096
|
12
|
|
|
|
|
|
return result; |
1097
|
|
|
|
|
|
|
} |
1098
|
|
|
|
|
|
|
|
1099
|
|
|
|
|
|
|
/* external dictionary mode */ |
1100
|
|
|
|
|
|
|
{ int result; |
1101
|
1
|
50
|
|
|
|
|
if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset)) |
|
|
50
|
|
|
|
|
|
1102
|
0
|
|
|
|
|
|
result = LZ4_compress_generic(streamPtr, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, usingExtDict, dictSmall, acceleration); |
1103
|
|
|
|
|
|
|
else |
1104
|
1
|
|
|
|
|
|
result = LZ4_compress_generic(streamPtr, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, usingExtDict, noDictIssue, acceleration); |
1105
|
1
|
|
|
|
|
|
streamPtr->dictionary = (const BYTE*)source; |
1106
|
1
|
|
|
|
|
|
streamPtr->dictSize = (U32)inputSize; |
1107
|
1
|
|
|
|
|
|
streamPtr->currentOffset += (U32)inputSize; |
1108
|
1
|
|
|
|
|
|
return result; |
1109
|
|
|
|
|
|
|
} |
1110
|
|
|
|
|
|
|
} |
1111
|
|
|
|
|
|
|
|
1112
|
|
|
|
|
|
|
|
1113
|
|
|
|
|
|
|
/* Hidden debug function, to force external dictionary mode */ |
1114
|
0
|
|
|
|
|
|
int LZ4_compress_forceExtDict (LZ4_stream_t* LZ4_dict, const char* source, char* dest, int inputSize) |
1115
|
|
|
|
|
|
|
{ |
1116
|
0
|
|
|
|
|
|
LZ4_stream_t_internal* streamPtr = &LZ4_dict->internal_donotuse; |
1117
|
|
|
|
|
|
|
int result; |
1118
|
0
|
|
|
|
|
|
const BYTE* const dictEnd = streamPtr->dictionary + streamPtr->dictSize; |
1119
|
|
|
|
|
|
|
|
1120
|
0
|
|
|
|
|
|
const BYTE* smallest = dictEnd; |
1121
|
0
|
0
|
|
|
|
|
if (smallest > (const BYTE*) source) smallest = (const BYTE*) source; |
1122
|
0
|
|
|
|
|
|
LZ4_renormDictT(streamPtr, smallest); |
1123
|
|
|
|
|
|
|
|
1124
|
0
|
|
|
|
|
|
result = LZ4_compress_generic(streamPtr, source, dest, inputSize, 0, notLimited, byU32, usingExtDict, noDictIssue, 1); |
1125
|
|
|
|
|
|
|
|
1126
|
0
|
|
|
|
|
|
streamPtr->dictionary = (const BYTE*)source; |
1127
|
0
|
|
|
|
|
|
streamPtr->dictSize = (U32)inputSize; |
1128
|
0
|
|
|
|
|
|
streamPtr->currentOffset += (U32)inputSize; |
1129
|
|
|
|
|
|
|
|
1130
|
0
|
|
|
|
|
|
return result; |
1131
|
|
|
|
|
|
|
} |
1132
|
|
|
|
|
|
|
|
1133
|
|
|
|
|
|
|
|
1134
|
|
|
|
|
|
|
/*! LZ4_saveDict() : |
1135
|
|
|
|
|
|
|
* If previously compressed data block is not guaranteed to remain available at its memory location, |
1136
|
|
|
|
|
|
|
* save it into a safer place (char* safeBuffer). |
1137
|
|
|
|
|
|
|
* Note : you don't need to call LZ4_loadDict() afterwards, |
1138
|
|
|
|
|
|
|
* dictionary is immediately usable, you can therefore call LZ4_compress_fast_continue(). |
1139
|
|
|
|
|
|
|
* Return : saved dictionary size in bytes (necessarily <= dictSize), or 0 if error. |
1140
|
|
|
|
|
|
|
*/ |
1141
|
0
|
|
|
|
|
|
int LZ4_saveDict (LZ4_stream_t* LZ4_dict, char* safeBuffer, int dictSize) |
1142
|
|
|
|
|
|
|
{ |
1143
|
0
|
|
|
|
|
|
LZ4_stream_t_internal* const dict = &LZ4_dict->internal_donotuse; |
1144
|
0
|
|
|
|
|
|
const BYTE* const previousDictEnd = dict->dictionary + dict->dictSize; |
1145
|
|
|
|
|
|
|
|
1146
|
0
|
0
|
|
|
|
|
if ((U32)dictSize > 64 KB) dictSize = 64 KB; /* useless to define a dictionary > 64 KB */ |
1147
|
0
|
0
|
|
|
|
|
if ((U32)dictSize > dict->dictSize) dictSize = dict->dictSize; |
1148
|
|
|
|
|
|
|
|
1149
|
0
|
|
|
|
|
|
memmove(safeBuffer, previousDictEnd - dictSize, dictSize); |
1150
|
|
|
|
|
|
|
|
1151
|
0
|
|
|
|
|
|
dict->dictionary = (const BYTE*)safeBuffer; |
1152
|
0
|
|
|
|
|
|
dict->dictSize = (U32)dictSize; |
1153
|
|
|
|
|
|
|
|
1154
|
0
|
|
|
|
|
|
return dictSize; |
1155
|
|
|
|
|
|
|
} |
1156
|
|
|
|
|
|
|
|
1157
|
|
|
|
|
|
|
|
1158
|
|
|
|
|
|
|
|
1159
|
|
|
|
|
|
|
/*-***************************** |
1160
|
|
|
|
|
|
|
* Decompression functions |
1161
|
|
|
|
|
|
|
*******************************/ |
1162
|
|
|
|
|
|
|
/*! LZ4_decompress_generic() : |
1163
|
|
|
|
|
|
|
* This generic decompression function covers all use cases. |
1164
|
|
|
|
|
|
|
* It shall be instantiated several times, using different sets of directives. |
1165
|
|
|
|
|
|
|
* Note that it is important for performance that this function really get inlined, |
1166
|
|
|
|
|
|
|
* in order to remove useless branches during compilation optimization. |
1167
|
|
|
|
|
|
|
*/ |
1168
|
|
|
|
|
|
|
LZ4_FORCE_O2_GCC_PPC64LE |
1169
|
|
|
|
|
|
|
LZ4_FORCE_INLINE int LZ4_decompress_generic( |
1170
|
|
|
|
|
|
|
const char* const src, |
1171
|
|
|
|
|
|
|
char* const dst, |
1172
|
|
|
|
|
|
|
int srcSize, |
1173
|
|
|
|
|
|
|
int outputSize, /* If endOnInput==endOnInputSize, this value is `dstCapacity` */ |
1174
|
|
|
|
|
|
|
|
1175
|
|
|
|
|
|
|
int endOnInput, /* endOnOutputSize, endOnInputSize */ |
1176
|
|
|
|
|
|
|
int partialDecoding, /* full, partial */ |
1177
|
|
|
|
|
|
|
int targetOutputSize, /* only used if partialDecoding==partial */ |
1178
|
|
|
|
|
|
|
int dict, /* noDict, withPrefix64k, usingExtDict */ |
1179
|
|
|
|
|
|
|
const BYTE* const lowPrefix, /* always <= dst, == dst when no prefix */ |
1180
|
|
|
|
|
|
|
const BYTE* const dictStart, /* only if dict==usingExtDict */ |
1181
|
|
|
|
|
|
|
const size_t dictSize /* note : = 0 if noDict */ |
1182
|
|
|
|
|
|
|
) |
1183
|
|
|
|
|
|
|
{ |
1184
|
42
|
|
|
|
|
|
const BYTE* ip = (const BYTE*) src; |
1185
|
42
|
|
|
|
|
|
const BYTE* const iend = ip + srcSize; |
1186
|
|
|
|
|
|
|
|
1187
|
42
|
|
|
|
|
|
BYTE* op = (BYTE*) dst; |
1188
|
42
|
|
|
|
|
|
BYTE* const oend = op + outputSize; |
1189
|
|
|
|
|
|
|
BYTE* cpy; |
1190
|
42
|
|
|
|
|
|
BYTE* oexit = op + targetOutputSize; |
1191
|
|
|
|
|
|
|
|
1192
|
42
|
|
|
|
|
|
const BYTE* const dictEnd = (const BYTE*)dictStart + dictSize; |
1193
|
42
|
|
|
|
|
|
const unsigned inc32table[8] = {0, 1, 2, 1, 0, 4, 4, 4}; |
1194
|
42
|
|
|
|
|
|
const int dec64table[8] = {0, 0, 0, -1, -4, 1, 2, 3}; |
1195
|
|
|
|
|
|
|
|
1196
|
42
|
|
|
|
|
|
const int safeDecode = (endOnInput==endOnInputSize); |
1197
|
42
|
0
|
|
|
|
|
const int checkOffset = ((safeDecode) && (dictSize < (int)(64 KB))); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1198
|
|
|
|
|
|
|
|
1199
|
|
|
|
|
|
|
|
1200
|
|
|
|
|
|
|
/* Special cases */ |
1201
|
42
|
0
|
|
|
|
|
if ((partialDecoding) && (oexit > oend-MFLIMIT)) oexit = oend-MFLIMIT; /* targetOutputSize too high => just decode everything */ |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
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
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1204
|
|
|
|
|
|
|
|
1205
|
|
|
|
|
|
|
/* Main Loop : decode sequences */ |
1206
|
|
|
|
|
|
|
while (1) { |
1207
|
|
|
|
|
|
|
size_t length; |
1208
|
|
|
|
|
|
|
const BYTE* match; |
1209
|
|
|
|
|
|
|
size_t offset; |
1210
|
|
|
|
|
|
|
|
1211
|
153697
|
|
|
|
|
|
unsigned const token = *ip++; |
1212
|
|
|
|
|
|
|
|
1213
|
|
|
|
|
|
|
/* shortcut for common case : |
1214
|
|
|
|
|
|
|
* in most circumstances, we expect to decode small matches (<= 18 bytes) separated by few literals (<= 14 bytes). |
1215
|
|
|
|
|
|
|
* this shortcut was tested on x86 and x64, where it improves decoding speed. |
1216
|
|
|
|
|
|
|
* it has not yet been benchmarked on ARM, Power, mips, etc. */ |
1217
|
153697
|
0
|
|
|
|
|
if (((ip + 14 /*maxLL*/ + 2 /*offset*/ <= iend) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1218
|
153697
|
|
|
|
|
|
& (op + 14 /*maxLL*/ + 18 /*maxML*/ <= oend)) |
1219
|
153697
|
|
|
|
|
|
& ((token < (15<
|
1220
|
153311
|
|
|
|
|
|
size_t const ll = token >> ML_BITS; |
1221
|
153311
|
|
|
|
|
|
size_t const off = LZ4_readLE16(ip+ll); |
1222
|
153311
|
|
|
|
|
|
const BYTE* const matchPtr = op + ll - off; /* pointer underflow risk ? */ |
1223
|
153311
|
|
|
|
|
|
if ((off >= 18) /* do not deal with overlapping matches */ & (matchPtr >= lowPrefix)) { |
1224
|
145466
|
|
|
|
|
|
size_t const ml = (token & ML_MASK) + MINMATCH; |
1225
|
145466
|
|
|
|
|
|
memcpy(op, ip, 16); op += ll; ip += ll + 2 /*offset*/; |
1226
|
145466
|
|
|
|
|
|
memcpy(op, matchPtr, 18); op += ml; |
1227
|
145466
|
|
|
|
|
|
continue; |
1228
|
|
|
|
|
|
|
} |
1229
|
|
|
|
|
|
|
} |
1230
|
|
|
|
|
|
|
|
1231
|
|
|
|
|
|
|
/* decode literal length */ |
1232
|
8231
|
0
|
|
|
|
|
if ((length=(token>>ML_BITS)) == RUN_MASK) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|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<(uptrval)(ip))) goto _output_error; /* overflow detection */ |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1240
|
|
|
|
|
|
|
} |
1241
|
|
|
|
|
|
|
|
1242
|
|
|
|
|
|
|
/* copy literals */ |
1243
|
8231
|
|
|
|
|
|
cpy = op+length; |
1244
|
8231
|
0
|
|
|
|
|
if ( ((endOnInput) && ((cpy>(partialDecoding?oexit:oend-MFLIMIT)) || (ip+length>iend-(2+1+LASTLITERALS))) ) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|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
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1248
|
0
|
0
|
|
|
|
|
if (cpy > oend) goto _output_error; /* Error : write attempt beyond end of output buffer */ |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1249
|
0
|
0
|
|
|
|
|
if ((endOnInput) && (ip+length > iend)) goto _output_error; /* Error : read attempt beyond end of input buffer */ |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1250
|
|
|
|
|
|
|
} else { |
1251
|
42
|
0
|
|
|
|
|
if ((!endOnInput) && (cpy != oend)) goto _output_error; /* Error : block decoding must stop exactly there */ |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1252
|
42
|
0
|
|
|
|
|
if ((endOnInput) && ((ip+length != iend) || (cpy > oend))) goto _output_error; /* Error : input must be consumed */ |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|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
|
|
|
|
} |
1259
|
8189
|
|
|
|
|
|
LZ4_wildCopy(op, ip, cpy); |
1260
|
8189
|
|
|
|
|
|
ip += length; op = cpy; |
1261
|
|
|
|
|
|
|
|
1262
|
|
|
|
|
|
|
/* get offset */ |
1263
|
8189
|
|
|
|
|
|
offset = LZ4_readLE16(ip); ip+=2; |
1264
|
8189
|
|
|
|
|
|
match = op - offset; |
1265
|
8189
|
0
|
|
|
|
|
if ((checkOffset) && (unlikely(match + dictSize < lowPrefix))) goto _output_error; /* Error : offset outside buffers */ |
|
|
0
|
|
|
|
|
|
1266
|
8189
|
|
|
|
|
|
LZ4_write32(op, (U32)offset); /* costs ~1%; silence an msan warning when offset==0 */ |
1267
|
|
|
|
|
|
|
|
1268
|
|
|
|
|
|
|
/* get matchlength */ |
1269
|
8189
|
|
|
|
|
|
length = token & ML_MASK; |
1270
|
8189
|
|
|
|
|
|
if (length == ML_MASK) { |
1271
|
|
|
|
|
|
|
unsigned s; |
1272
|
|
|
|
|
|
|
do { |
1273
|
269
|
|
|
|
|
|
s = *ip++; |
1274
|
269
|
0
|
|
|
|
|
if ((endOnInput) && (ip > iend-LASTLITERALS)) goto _output_error; |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|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
|
|
|
|
1283
|
141
|
0
|
|
|
|
|
if (unlikely(op+length > oend-LASTLITERALS)) goto _output_error; /* doesn't respect parsing restriction */ |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1284
|
|
|
|
|
|
|
|
1285
|
141
|
0
|
|
|
|
|
if (length <= (size_t)(lowPrefix-match)) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1286
|
|
|
|
|
|
|
/* match can be copied as a single segment from external dictionary */ |
1287
|
141
|
|
|
|
|
|
memmove(op, dictEnd - (lowPrefix-match), length); |
1288
|
141
|
|
|
|
|
|
op += length; |
1289
|
|
|
|
|
|
|
} else { |
1290
|
|
|
|
|
|
|
/* match encompass external dictionary and current block */ |
1291
|
0
|
|
|
|
|
|
size_t const copySize = (size_t)(lowPrefix-match); |
1292
|
0
|
|
|
|
|
|
size_t const restSize = length - copySize; |
1293
|
0
|
|
|
|
|
|
memcpy(op, dictEnd - copySize, copySize); |
1294
|
0
|
|
|
|
|
|
op += copySize; |
1295
|
0
|
0
|
|
|
|
|
if (restSize > (size_t)(op-lowPrefix)) { /* overlap copy */ |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1296
|
0
|
|
|
|
|
|
BYTE* const endOfMatch = op + restSize; |
1297
|
0
|
|
|
|
|
|
const BYTE* copyFrom = lowPrefix; |
1298
|
0
|
0
|
|
|
|
|
while (op < endOfMatch) *op++ = *copyFrom++; |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1299
|
|
|
|
|
|
|
} else { |
1300
|
0
|
|
|
|
|
|
memcpy(op, lowPrefix, restSize); |
1301
|
0
|
|
|
|
|
|
op += restSize; |
1302
|
|
|
|
|
|
|
} } |
1303
|
141
|
|
|
|
|
|
continue; |
1304
|
|
|
|
|
|
|
} |
1305
|
|
|
|
|
|
|
|
1306
|
|
|
|
|
|
|
/* copy match within block */ |
1307
|
8048
|
|
|
|
|
|
cpy = op + length; |
1308
|
8048
|
0
|
|
|
|
|
if (unlikely(offset<8)) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1309
|
23
|
|
|
|
|
|
op[0] = match[0]; |
1310
|
23
|
|
|
|
|
|
op[1] = match[1]; |
1311
|
23
|
|
|
|
|
|
op[2] = match[2]; |
1312
|
23
|
|
|
|
|
|
op[3] = match[3]; |
1313
|
23
|
|
|
|
|
|
match += inc32table[offset]; |
1314
|
23
|
|
|
|
|
|
memcpy(op+4, match, 4); |
1315
|
23
|
|
|
|
|
|
match -= dec64table[offset]; |
1316
|
8025
|
|
|
|
|
|
} else { LZ4_copy8(op, match); match+=8; } |
1317
|
8048
|
|
|
|
|
|
op += 8; |
1318
|
|
|
|
|
|
|
|
1319
|
8048
|
0
|
|
|
|
|
if (unlikely(cpy>oend-12)) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1320
|
16
|
|
|
|
|
|
BYTE* const oCopyLimit = oend-(WILDCOPYLENGTH-1); |
1321
|
16
|
0
|
|
|
|
|
if (cpy > oend-LASTLITERALS) goto _output_error; /* Error : last LASTLITERALS bytes must be literals (uncompressed) */ |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1322
|
16
|
0
|
|
|
|
|
if (op < oCopyLimit) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1323
|
16
|
|
|
|
|
|
LZ4_wildCopy(op, match, oCopyLimit); |
1324
|
16
|
|
|
|
|
|
match += oCopyLimit - op; |
1325
|
16
|
|
|
|
|
|
op = oCopyLimit; |
1326
|
|
|
|
|
|
|
} |
1327
|
18
|
0
|
|
|
|
|
while (op
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1328
|
|
|
|
|
|
|
} else { |
1329
|
8032
|
|
|
|
|
|
LZ4_copy8(op, match); |
1330
|
8032
|
0
|
|
|
|
|
if (length>16) LZ4_wildCopy(op+8, match+8, cpy); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1331
|
|
|
|
|
|
|
} |
1332
|
153655
|
|
|
|
|
|
op = cpy; /* correction */ |
1333
|
|
|
|
|
|
|
} |
1334
|
|
|
|
|
|
|
|
1335
|
|
|
|
|
|
|
/* end of decoding */ |
1336
|
42
|
0
|
|
|
|
|
if (endOnInput) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1337
|
42
|
|
|
|
|
|
return (int) (((char*)op)-dst); /* Nb of output bytes decoded */ |
1338
|
|
|
|
|
|
|
else |
1339
|
0
|
|
|
|
|
|
return (int) (((const char*)ip)-src); /* Nb of input bytes read */ |
1340
|
|
|
|
|
|
|
|
1341
|
|
|
|
|
|
|
/* Overflow error detected */ |
1342
|
|
|
|
|
|
|
_output_error: |
1343
|
42
|
|
|
|
|
|
return (int) (-(((const char*)ip)-src))-1; |
1344
|
|
|
|
|
|
|
} |
1345
|
|
|
|
|
|
|
|
1346
|
|
|
|
|
|
|
|
1347
|
|
|
|
|
|
|
LZ4_FORCE_O2_GCC_PPC64LE |
1348
|
0
|
|
|
|
|
|
int LZ4_decompress_safe(const char* source, char* dest, int compressedSize, int maxDecompressedSize) |
1349
|
|
|
|
|
|
|
{ |
1350
|
0
|
|
|
|
|
|
return LZ4_decompress_generic(source, dest, compressedSize, maxDecompressedSize, endOnInputSize, full, 0, noDict, (BYTE*)dest, NULL, 0); |
1351
|
|
|
|
|
|
|
} |
1352
|
|
|
|
|
|
|
|
1353
|
|
|
|
|
|
|
LZ4_FORCE_O2_GCC_PPC64LE |
1354
|
0
|
|
|
|
|
|
int LZ4_decompress_safe_partial(const char* source, char* dest, int compressedSize, int targetOutputSize, int maxDecompressedSize) |
1355
|
|
|
|
|
|
|
{ |
1356
|
0
|
|
|
|
|
|
return LZ4_decompress_generic(source, dest, compressedSize, maxDecompressedSize, endOnInputSize, partial, targetOutputSize, noDict, (BYTE*)dest, NULL, 0); |
1357
|
|
|
|
|
|
|
} |
1358
|
|
|
|
|
|
|
|
1359
|
|
|
|
|
|
|
LZ4_FORCE_O2_GCC_PPC64LE |
1360
|
0
|
|
|
|
|
|
int LZ4_decompress_fast(const char* source, char* dest, int originalSize) |
1361
|
|
|
|
|
|
|
{ |
1362
|
0
|
|
|
|
|
|
return LZ4_decompress_generic(source, dest, 0, originalSize, endOnOutputSize, full, 0, withPrefix64k, (BYTE*)(dest - 64 KB), NULL, 64 KB); |
1363
|
|
|
|
|
|
|
} |
1364
|
|
|
|
|
|
|
|
1365
|
|
|
|
|
|
|
|
1366
|
|
|
|
|
|
|
/*===== streaming decompression functions =====*/ |
1367
|
|
|
|
|
|
|
|
1368
|
0
|
|
|
|
|
|
LZ4_streamDecode_t* LZ4_createStreamDecode(void) |
1369
|
|
|
|
|
|
|
{ |
1370
|
0
|
|
|
|
|
|
LZ4_streamDecode_t* lz4s = (LZ4_streamDecode_t*) ALLOCATOR(1, sizeof(LZ4_streamDecode_t)); |
1371
|
0
|
|
|
|
|
|
return lz4s; |
1372
|
|
|
|
|
|
|
} |
1373
|
|
|
|
|
|
|
|
1374
|
0
|
|
|
|
|
|
int LZ4_freeStreamDecode (LZ4_streamDecode_t* LZ4_stream) |
1375
|
|
|
|
|
|
|
{ |
1376
|
0
|
0
|
|
|
|
|
if (!LZ4_stream) return 0; /* support free on NULL */ |
1377
|
0
|
|
|
|
|
|
FREEMEM(LZ4_stream); |
1378
|
0
|
|
|
|
|
|
return 0; |
1379
|
|
|
|
|
|
|
} |
1380
|
|
|
|
|
|
|
|
1381
|
|
|
|
|
|
|
/*! |
1382
|
|
|
|
|
|
|
* LZ4_setStreamDecode() : |
1383
|
|
|
|
|
|
|
* Use this function to instruct where to find the dictionary. |
1384
|
|
|
|
|
|
|
* This function is not necessary if previous data is still available where it was decoded. |
1385
|
|
|
|
|
|
|
* Loading a size of 0 is allowed (same effect as no dictionary). |
1386
|
|
|
|
|
|
|
* Return : 1 if OK, 0 if error |
1387
|
|
|
|
|
|
|
*/ |
1388
|
0
|
|
|
|
|
|
int LZ4_setStreamDecode (LZ4_streamDecode_t* LZ4_streamDecode, const char* dictionary, int dictSize) |
1389
|
|
|
|
|
|
|
{ |
1390
|
0
|
|
|
|
|
|
LZ4_streamDecode_t_internal* lz4sd = &LZ4_streamDecode->internal_donotuse; |
1391
|
0
|
|
|
|
|
|
lz4sd->prefixSize = (size_t) dictSize; |
1392
|
0
|
|
|
|
|
|
lz4sd->prefixEnd = (const BYTE*) dictionary + dictSize; |
1393
|
0
|
|
|
|
|
|
lz4sd->externalDict = NULL; |
1394
|
0
|
|
|
|
|
|
lz4sd->extDictSize = 0; |
1395
|
0
|
|
|
|
|
|
return 1; |
1396
|
|
|
|
|
|
|
} |
1397
|
|
|
|
|
|
|
|
1398
|
|
|
|
|
|
|
/* |
1399
|
|
|
|
|
|
|
*_continue() : |
1400
|
|
|
|
|
|
|
These decoding functions allow decompression of multiple blocks in "streaming" mode. |
1401
|
|
|
|
|
|
|
Previously decoded blocks must still be available at the memory position where they were decoded. |
1402
|
|
|
|
|
|
|
If it's not possible, save the relevant part of decoded data into a safe buffer, |
1403
|
|
|
|
|
|
|
and indicate where it stands using LZ4_setStreamDecode() |
1404
|
|
|
|
|
|
|
*/ |
1405
|
|
|
|
|
|
|
LZ4_FORCE_O2_GCC_PPC64LE |
1406
|
0
|
|
|
|
|
|
int LZ4_decompress_safe_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* source, char* dest, int compressedSize, int maxOutputSize) |
1407
|
|
|
|
|
|
|
{ |
1408
|
0
|
|
|
|
|
|
LZ4_streamDecode_t_internal* lz4sd = &LZ4_streamDecode->internal_donotuse; |
1409
|
|
|
|
|
|
|
int result; |
1410
|
|
|
|
|
|
|
|
1411
|
0
|
0
|
|
|
|
|
if (lz4sd->prefixEnd == (BYTE*)dest) { |
1412
|
0
|
|
|
|
|
|
result = LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, |
1413
|
|
|
|
|
|
|
endOnInputSize, full, 0, |
1414
|
0
|
|
|
|
|
|
usingExtDict, lz4sd->prefixEnd - lz4sd->prefixSize, lz4sd->externalDict, lz4sd->extDictSize); |
1415
|
0
|
0
|
|
|
|
|
if (result <= 0) return result; |
1416
|
0
|
|
|
|
|
|
lz4sd->prefixSize += result; |
1417
|
0
|
|
|
|
|
|
lz4sd->prefixEnd += result; |
1418
|
|
|
|
|
|
|
} else { |
1419
|
0
|
|
|
|
|
|
lz4sd->extDictSize = lz4sd->prefixSize; |
1420
|
0
|
|
|
|
|
|
lz4sd->externalDict = lz4sd->prefixEnd - lz4sd->extDictSize; |
1421
|
0
|
|
|
|
|
|
result = LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, |
1422
|
|
|
|
|
|
|
endOnInputSize, full, 0, |
1423
|
0
|
|
|
|
|
|
usingExtDict, (BYTE*)dest, lz4sd->externalDict, lz4sd->extDictSize); |
1424
|
0
|
0
|
|
|
|
|
if (result <= 0) return result; |
1425
|
0
|
|
|
|
|
|
lz4sd->prefixSize = result; |
1426
|
0
|
|
|
|
|
|
lz4sd->prefixEnd = (BYTE*)dest + result; |
1427
|
|
|
|
|
|
|
} |
1428
|
|
|
|
|
|
|
|
1429
|
0
|
|
|
|
|
|
return result; |
1430
|
|
|
|
|
|
|
} |
1431
|
|
|
|
|
|
|
|
1432
|
|
|
|
|
|
|
LZ4_FORCE_O2_GCC_PPC64LE |
1433
|
0
|
|
|
|
|
|
int LZ4_decompress_fast_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* source, char* dest, int originalSize) |
1434
|
|
|
|
|
|
|
{ |
1435
|
0
|
|
|
|
|
|
LZ4_streamDecode_t_internal* lz4sd = &LZ4_streamDecode->internal_donotuse; |
1436
|
|
|
|
|
|
|
int result; |
1437
|
|
|
|
|
|
|
|
1438
|
0
|
0
|
|
|
|
|
if (lz4sd->prefixEnd == (BYTE*)dest) { |
1439
|
0
|
|
|
|
|
|
result = LZ4_decompress_generic(source, dest, 0, originalSize, |
1440
|
|
|
|
|
|
|
endOnOutputSize, full, 0, |
1441
|
0
|
|
|
|
|
|
usingExtDict, lz4sd->prefixEnd - lz4sd->prefixSize, lz4sd->externalDict, lz4sd->extDictSize); |
1442
|
0
|
0
|
|
|
|
|
if (result <= 0) return result; |
1443
|
0
|
|
|
|
|
|
lz4sd->prefixSize += originalSize; |
1444
|
0
|
|
|
|
|
|
lz4sd->prefixEnd += originalSize; |
1445
|
|
|
|
|
|
|
} else { |
1446
|
0
|
|
|
|
|
|
lz4sd->extDictSize = lz4sd->prefixSize; |
1447
|
0
|
|
|
|
|
|
lz4sd->externalDict = lz4sd->prefixEnd - lz4sd->extDictSize; |
1448
|
0
|
|
|
|
|
|
result = LZ4_decompress_generic(source, dest, 0, originalSize, |
1449
|
|
|
|
|
|
|
endOnOutputSize, full, 0, |
1450
|
0
|
|
|
|
|
|
usingExtDict, (BYTE*)dest, lz4sd->externalDict, lz4sd->extDictSize); |
1451
|
0
|
0
|
|
|
|
|
if (result <= 0) return result; |
1452
|
0
|
|
|
|
|
|
lz4sd->prefixSize = originalSize; |
1453
|
0
|
|
|
|
|
|
lz4sd->prefixEnd = (BYTE*)dest + originalSize; |
1454
|
|
|
|
|
|
|
} |
1455
|
|
|
|
|
|
|
|
1456
|
0
|
|
|
|
|
|
return result; |
1457
|
|
|
|
|
|
|
} |
1458
|
|
|
|
|
|
|
|
1459
|
|
|
|
|
|
|
|
1460
|
|
|
|
|
|
|
/* |
1461
|
|
|
|
|
|
|
Advanced decoding functions : |
1462
|
|
|
|
|
|
|
*_usingDict() : |
1463
|
|
|
|
|
|
|
These decoding functions work the same as "_continue" ones, |
1464
|
|
|
|
|
|
|
the dictionary must be explicitly provided within parameters |
1465
|
|
|
|
|
|
|
*/ |
1466
|
|
|
|
|
|
|
|
1467
|
|
|
|
|
|
|
LZ4_FORCE_O2_GCC_PPC64LE |
1468
|
|
|
|
|
|
|
LZ4_FORCE_INLINE int LZ4_decompress_usingDict_generic(const char* source, char* dest, int compressedSize, int maxOutputSize, int safe, const char* dictStart, int dictSize) |
1469
|
|
|
|
|
|
|
{ |
1470
|
42
|
0
|
|
|
|
|
if (dictSize==0) |
|
|
100
|
|
|
|
|
|
1471
|
6
|
|
|
|
|
|
return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, safe, full, 0, noDict, (BYTE*)dest, NULL, 0); |
1472
|
36
|
0
|
|
|
|
|
if (dictStart+dictSize == dest) { |
|
|
100
|
|
|
|
|
|
1473
|
33
|
0
|
|
|
|
|
if (dictSize >= (int)(64 KB - 1)) |
|
|
50
|
|
|
|
|
|
1474
|
33
|
|
|
|
|
|
return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, safe, full, 0, withPrefix64k, (BYTE*)dest-64 KB, NULL, 0); |
1475
|
0
|
|
|
|
|
|
return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, safe, full, 0, noDict, (BYTE*)dest-dictSize, NULL, 0); |
1476
|
|
|
|
|
|
|
} |
1477
|
3
|
|
|
|
|
|
return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, safe, full, 0, usingExtDict, (BYTE*)dest, (const BYTE*)dictStart, dictSize); |
1478
|
|
|
|
|
|
|
} |
1479
|
|
|
|
|
|
|
|
1480
|
|
|
|
|
|
|
LZ4_FORCE_O2_GCC_PPC64LE |
1481
|
42
|
|
|
|
|
|
int LZ4_decompress_safe_usingDict(const char* source, char* dest, int compressedSize, int maxOutputSize, const char* dictStart, int dictSize) |
1482
|
|
|
|
|
|
|
{ |
1483
|
42
|
|
|
|
|
|
return LZ4_decompress_usingDict_generic(source, dest, compressedSize, maxOutputSize, 1, dictStart, dictSize); |
1484
|
|
|
|
|
|
|
} |
1485
|
|
|
|
|
|
|
|
1486
|
|
|
|
|
|
|
LZ4_FORCE_O2_GCC_PPC64LE |
1487
|
0
|
|
|
|
|
|
int LZ4_decompress_fast_usingDict(const char* source, char* dest, int originalSize, const char* dictStart, int dictSize) |
1488
|
|
|
|
|
|
|
{ |
1489
|
0
|
|
|
|
|
|
return LZ4_decompress_usingDict_generic(source, dest, 0, originalSize, 0, dictStart, dictSize); |
1490
|
|
|
|
|
|
|
} |
1491
|
|
|
|
|
|
|
|
1492
|
|
|
|
|
|
|
/* debug function */ |
1493
|
|
|
|
|
|
|
LZ4_FORCE_O2_GCC_PPC64LE |
1494
|
0
|
|
|
|
|
|
int LZ4_decompress_safe_forceExtDict(const char* source, char* dest, int compressedSize, int maxOutputSize, const char* dictStart, int dictSize) |
1495
|
|
|
|
|
|
|
{ |
1496
|
0
|
|
|
|
|
|
return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, endOnInputSize, full, 0, usingExtDict, (BYTE*)dest, (const BYTE*)dictStart, dictSize); |
1497
|
|
|
|
|
|
|
} |
1498
|
|
|
|
|
|
|
|
1499
|
|
|
|
|
|
|
|
1500
|
|
|
|
|
|
|
/*=************************************************* |
1501
|
|
|
|
|
|
|
* Obsolete Functions |
1502
|
|
|
|
|
|
|
***************************************************/ |
1503
|
|
|
|
|
|
|
/* obsolete compression functions */ |
1504
|
0
|
|
|
|
|
|
int LZ4_compress_limitedOutput(const char* source, char* dest, int inputSize, int maxOutputSize) { return LZ4_compress_default(source, dest, inputSize, maxOutputSize); } |
1505
|
0
|
|
|
|
|
|
int LZ4_compress(const char* source, char* dest, int inputSize) { return LZ4_compress_default(source, dest, inputSize, LZ4_compressBound(inputSize)); } |
1506
|
0
|
|
|
|
|
|
int LZ4_compress_limitedOutput_withState (void* state, const char* src, char* dst, int srcSize, int dstSize) { return LZ4_compress_fast_extState(state, src, dst, srcSize, dstSize, 1); } |
1507
|
0
|
|
|
|
|
|
int LZ4_compress_withState (void* state, const char* src, char* dst, int srcSize) { return LZ4_compress_fast_extState(state, src, dst, srcSize, LZ4_compressBound(srcSize), 1); } |
1508
|
0
|
|
|
|
|
|
int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_stream, const char* src, char* dst, int srcSize, int maxDstSize) { return LZ4_compress_fast_continue(LZ4_stream, src, dst, srcSize, maxDstSize, 1); } |
1509
|
0
|
|
|
|
|
|
int LZ4_compress_continue (LZ4_stream_t* LZ4_stream, const char* source, char* dest, int inputSize) { return LZ4_compress_fast_continue(LZ4_stream, source, dest, inputSize, LZ4_compressBound(inputSize), 1); } |
1510
|
|
|
|
|
|
|
|
1511
|
|
|
|
|
|
|
/* |
1512
|
|
|
|
|
|
|
These function names are deprecated and should no longer be used. |
1513
|
|
|
|
|
|
|
They are only provided here for compatibility with older user programs. |
1514
|
|
|
|
|
|
|
- LZ4_uncompress is totally equivalent to LZ4_decompress_fast |
1515
|
|
|
|
|
|
|
- LZ4_uncompress_unknownOutputSize is totally equivalent to LZ4_decompress_safe |
1516
|
|
|
|
|
|
|
*/ |
1517
|
0
|
|
|
|
|
|
int LZ4_uncompress (const char* source, char* dest, int outputSize) { return LZ4_decompress_fast(source, dest, outputSize); } |
1518
|
0
|
|
|
|
|
|
int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize) { return LZ4_decompress_safe(source, dest, isize, maxOutputSize); } |
1519
|
|
|
|
|
|
|
|
1520
|
|
|
|
|
|
|
|
1521
|
|
|
|
|
|
|
/* Obsolete Streaming functions */ |
1522
|
|
|
|
|
|
|
|
1523
|
0
|
|
|
|
|
|
int LZ4_sizeofStreamState() { return LZ4_STREAMSIZE; } |
1524
|
|
|
|
|
|
|
|
1525
|
0
|
|
|
|
|
|
static void LZ4_init(LZ4_stream_t* lz4ds, BYTE* base) |
1526
|
|
|
|
|
|
|
{ |
1527
|
0
|
|
|
|
|
|
MEM_INIT(lz4ds, 0, sizeof(LZ4_stream_t)); |
1528
|
0
|
|
|
|
|
|
lz4ds->internal_donotuse.bufferStart = base; |
1529
|
0
|
|
|
|
|
|
} |
1530
|
|
|
|
|
|
|
|
1531
|
0
|
|
|
|
|
|
int LZ4_resetStreamState(void* state, char* inputBuffer) |
1532
|
|
|
|
|
|
|
{ |
1533
|
0
|
0
|
|
|
|
|
if ((((uptrval)state) & 3) != 0) return 1; /* Error : pointer is not aligned on 4-bytes boundary */ |
1534
|
0
|
|
|
|
|
|
LZ4_init((LZ4_stream_t*)state, (BYTE*)inputBuffer); |
1535
|
0
|
|
|
|
|
|
return 0; |
1536
|
|
|
|
|
|
|
} |
1537
|
|
|
|
|
|
|
|
1538
|
0
|
|
|
|
|
|
void* LZ4_create (char* inputBuffer) |
1539
|
|
|
|
|
|
|
{ |
1540
|
0
|
|
|
|
|
|
LZ4_stream_t* lz4ds = (LZ4_stream_t*)ALLOCATOR(8, sizeof(LZ4_stream_t)); |
1541
|
0
|
|
|
|
|
|
LZ4_init (lz4ds, (BYTE*)inputBuffer); |
1542
|
0
|
|
|
|
|
|
return lz4ds; |
1543
|
|
|
|
|
|
|
} |
1544
|
|
|
|
|
|
|
|
1545
|
0
|
|
|
|
|
|
char* LZ4_slideInputBuffer (void* LZ4_Data) |
1546
|
|
|
|
|
|
|
{ |
1547
|
0
|
|
|
|
|
|
LZ4_stream_t_internal* ctx = &((LZ4_stream_t*)LZ4_Data)->internal_donotuse; |
1548
|
0
|
|
|
|
|
|
int dictSize = LZ4_saveDict((LZ4_stream_t*)LZ4_Data, (char*)ctx->bufferStart, 64 KB); |
1549
|
0
|
|
|
|
|
|
return (char*)(ctx->bufferStart + dictSize); |
1550
|
|
|
|
|
|
|
} |
1551
|
|
|
|
|
|
|
|
1552
|
|
|
|
|
|
|
/* Obsolete streaming decompression functions */ |
1553
|
|
|
|
|
|
|
|
1554
|
0
|
|
|
|
|
|
int LZ4_decompress_safe_withPrefix64k(const char* source, char* dest, int compressedSize, int maxOutputSize) |
1555
|
|
|
|
|
|
|
{ |
1556
|
0
|
|
|
|
|
|
return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, endOnInputSize, full, 0, withPrefix64k, (BYTE*)dest - 64 KB, NULL, 64 KB); |
1557
|
|
|
|
|
|
|
} |
1558
|
|
|
|
|
|
|
|
1559
|
0
|
|
|
|
|
|
int LZ4_decompress_fast_withPrefix64k(const char* source, char* dest, int originalSize) |
1560
|
|
|
|
|
|
|
{ |
1561
|
0
|
|
|
|
|
|
return LZ4_decompress_generic(source, dest, 0, originalSize, endOnOutputSize, full, 0, withPrefix64k, (BYTE*)dest - 64 KB, NULL, 64 KB); |
1562
|
|
|
|
|
|
|
} |
1563
|
|
|
|
|
|
|
|
1564
|
|
|
|
|
|
|
#endif /* LZ4_COMMONDEFS_ONLY */ |