53#define LZ4_ACCELERATION_DEFAULT 1
59#define LZ4_ACCELERATION_MAX 65537
79#ifndef LZ4_FORCE_MEMORY_ACCESS
80#if defined(__GNUC__) && \
81 (defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || \
82 defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || \
83 defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__))
84#define LZ4_FORCE_MEMORY_ACCESS 2
85#elif (defined(__INTEL_COMPILER) && !defined(_WIN32)) || defined(__GNUC__) || \
87#define LZ4_FORCE_MEMORY_ACCESS 1
96#if defined(_MSC_VER) && \
99#undef LZ4_FORCE_SW_BITCOUNT
100#define LZ4_FORCE_SW_BITCOUNT
110#ifndef LZ4_SRC_INCLUDED
111#define LZ4_SRC_INCLUDED 1
114#ifndef LZ4_DISABLE_DEPRECATE_WARNINGS
115#define LZ4_DISABLE_DEPRECATE_WARNINGS
119#ifndef LZ4_STATIC_LINKING_ONLY
120#define LZ4_STATIC_LINKING_ONLY
128#if defined(_MSC_VER) && (_MSC_VER >= 1400)
140#pragma warning(disable : 6326)
144#ifndef LZ4_FORCE_INLINE
145#if defined(_MSC_VER) && !defined(__clang__)
146#define LZ4_FORCE_INLINE static __forceinline
148#if defined(__cplusplus) || \
149 defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
150#if defined(__GNUC__) || defined(__clang__)
151#define LZ4_FORCE_INLINE static inline __attribute__((always_inline))
153#define LZ4_FORCE_INLINE static inline
156#define LZ4_FORCE_INLINE static
175#if defined(__PPC64__) && defined(__LITTLE_ENDIAN__) && defined(__GNUC__) && \
177#define LZ4_FORCE_O2 __attribute__((optimize("O2")))
178#undef LZ4_FORCE_INLINE
179#define LZ4_FORCE_INLINE \
180 static __inline __attribute__((optimize("O2"), always_inline))
185#if (defined(__GNUC__) && (__GNUC__ >= 3)) || \
186 (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 800)) || \
188#define expect(expr, value) (__builtin_expect((expr), (value)))
190#define expect(expr, value) (expr)
194#define likely(expr) expect((expr) != 0, 1)
197#define unlikely(expr) expect((expr) != 0, 0)
202#ifndef LZ4_ALIGN_TEST
203#define LZ4_ALIGN_TEST 1
226#if defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
227#define ALLOC(s) lz4_error_memory_allocation_is_disabled
228#define ALLOC_AND_ZERO(s) lz4_error_memory_allocation_is_disabled
229#define FREEMEM(p) lz4_error_memory_allocation_is_disabled
230#elif defined(LZ4_USER_MEMORY_FUNCTIONS)
237#define ALLOC(s) LZ4_malloc(s)
238#define ALLOC_AND_ZERO(s) LZ4_calloc(1, s)
239#define FREEMEM(p) LZ4_free(p)
242#define ALLOC(s) malloc(s)
243#define ALLOC_AND_ZERO(s) calloc(1, s)
244#define FREEMEM(p) free(p)
250#if !defined(LZ4_memset)
251#define LZ4_memset(p, v, s) memset((p), (v), (s))
253#define MEM_INIT(p, v, s) LZ4_memset((p), (v), (s))
260#define WILDCOPYLENGTH 8
261#define LASTLITERALS \
265#define MATCH_SAFEGUARD_DISTANCE \
266 ((2 * WILDCOPYLENGTH) - \
269#define FASTLOOP_SAFE_DISTANCE 64
270static const int LZ4_minLength = (
MFLIMIT + 1);
274#define GB *(1U << 30)
276#define LZ4_DISTANCE_ABSOLUTE_MAX 65535
277#if (LZ4_DISTANCE_MAX > \
278 LZ4_DISTANCE_ABSOLUTE_MAX)
279#error "LZ4_DISTANCE_MAX is too big : must be <= 65535"
283#define ML_MASK ((1U << ML_BITS) - 1)
284#define RUN_BITS (8 - ML_BITS)
285#define RUN_MASK ((1U << RUN_BITS) - 1)
290#if defined(LZ4_DEBUG) && (LZ4_DEBUG >= 1)
294#define assert(condition) ((void)0)
298#define LZ4_STATIC_ASSERT(c) \
300 enum { LZ4_static_assert = 1 / (int)(!!(c)) }; \
303#if defined(LZ4_DEBUG) && (LZ4_DEBUG >= 2)
306#define DEBUGLOG(l, ...) \
308 if ((g_debuglog_enable) && (l <= LZ4_DEBUG)) { \
309 fprintf(stderr, __FILE__ " %i: ", __LINE__); \
310 fprintf(stderr, __VA_ARGS__); \
311 fprintf(stderr, " \n"); \
315#define DEBUGLOG(l, ...) \
320static int LZ4_isAligned(
const void *ptr,
size_t alignment)
322 return ((
size_t)ptr & (
alignment - 1)) == 0;
329#if defined(__cplusplus) || \
330 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) )
339#if UINT_MAX != 4294967295UL
340#error "LZ4 code (when not C++ or C99) assumes that sizeof(int) == 4"
343typedef unsigned short U16;
345typedef signed int S32;
346typedef unsigned long long U64;
350#if defined(__x86_64__)
375#if !defined(LZ4_memcpy)
376#if defined(__GNUC__) && (__GNUC__ >= 4)
377#define LZ4_memcpy(dst, src, size) __builtin_memcpy(dst, src, size)
379#define LZ4_memcpy(dst, src, size) memcpy(dst, src, size)
383#if !defined(LZ4_memmove)
384#if defined(__GNUC__) && (__GNUC__ >= 4)
385#define LZ4_memmove __builtin_memmove
387#define LZ4_memmove memmove
391static unsigned LZ4_isLittleEndian(
void)
400#if defined(__GNUC__) || defined(__INTEL_COMPILER)
401#define LZ4_PACK(__Declaration__) __Declaration__ __attribute__((__packed__))
402#elif defined(_MSC_VER)
403#define LZ4_PACK(__Declaration__) \
404 __pragma(pack(push, 1)) __Declaration__ __pragma(pack(pop))
407#if defined(LZ4_FORCE_MEMORY_ACCESS) && (LZ4_FORCE_MEMORY_ACCESS == 2)
423static void LZ4_write16(
void *
memPtr,
U16 value)
427static void LZ4_write32(
void *
memPtr,
U32 value)
432#elif defined(LZ4_FORCE_MEMORY_ACCESS) && (LZ4_FORCE_MEMORY_ACCESS == 1)
441static U16 LZ4_read16(
const void *ptr)
445static U32 LZ4_read32(
const void *ptr)
449static reg_t LZ4_read_ARCH(
const void *ptr)
454static void LZ4_write16(
void *
memPtr,
U16 value)
458static void LZ4_write32(
void *
memPtr,
U32 value)
486static void LZ4_write16(
void *
memPtr,
U16 value)
491static void LZ4_write32(
void *
memPtr,
U32 value)
498static U16 LZ4_readLE16(
const void *
memPtr)
500 if (LZ4_isLittleEndian()) {
501 return LZ4_read16(
memPtr);
505 return (
U16)((
U16)p[0] | (p[1] << 8));
509#ifdef LZ4_STATIC_LINKING_ONLY_ENDIANNESS_INDEPENDENT_OUTPUT
512 if (LZ4_isLittleEndian()) {
513 return LZ4_read32(
memPtr);
517 return (
U32)p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
522static void LZ4_writeLE16(
void *
memPtr,
U16 value)
524 if (LZ4_isLittleEndian()) {
525 LZ4_write16(
memPtr, value);
530 p[1] = (
BYTE)(value >> 8);
550static const unsigned inc32table[8] = {0, 1, 2, 1, 0, 4, 4, 4};
551static const int dec64table[8] = {0, 0, 0, -1, -4, 1, 2, 3};
553#ifndef LZ4_FAST_DEC_LOOP
554#if defined __i386__ || defined _M_IX86 || defined __x86_64__ || defined _M_X64
555#define LZ4_FAST_DEC_LOOP 1
556#elif defined(__aarch64__) && defined(__APPLE__)
557#define LZ4_FAST_DEC_LOOP 1
558#elif defined(__aarch64__) && !defined(__clang__)
562#define LZ4_FAST_DEC_LOOP 1
564#define LZ4_FAST_DEC_LOOP 0
582 srcPtr += inc32table[offset];
584 srcPtr -= dec64table[offset];
631#if defined(_MSC_VER) && (_MSC_VER <= 1937)
634#pragma warning(disable \
638#if defined(_MSC_VER) && (_MSC_VER <= 1937)
664static unsigned LZ4_NbCommonBytes(
reg_t val)
667 if (LZ4_isLittleEndian()) {
668 if (
sizeof(val) == 8) {
669#if defined(_MSC_VER) && (_MSC_VER >= 1800) && \
670 (defined(_M_AMD64) && !defined(_M_ARM64EC)) && \
671 !defined(LZ4_FORCE_SW_BITCOUNT)
678#if defined(__clang__) && (__clang_major__ < 10)
686#elif defined(_MSC_VER) && defined(_WIN64) && !defined(LZ4_FORCE_SW_BITCOUNT)
689 return (
unsigned)
r >> 3;
690#elif (defined(__clang__) || \
691 (defined(__GNUC__) && \
692 ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 4))))) && \
693 !defined(LZ4_FORCE_SW_BITCOUNT)
696 const U64 m = 0x0101010101010101ULL;
698 return (
unsigned)(((
U64)((val & (
m - 1)) *
m)) >> 56);
702#if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(LZ4_FORCE_SW_BITCOUNT)
705 return (
unsigned)
r >> 3;
706#elif (defined(__clang__) || \
707 (defined(__GNUC__) && \
708 ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 4))))) && \
709 !defined(__TINYC__) && !defined(LZ4_FORCE_SW_BITCOUNT)
712 const U32 m = 0x01010101;
713 return (
unsigned)((((val - 1) ^ val) & (
m - 1)) *
m) >> 24;
718 if (
sizeof(val) == 8) {
719#if (defined(__clang__) || \
720 (defined(__GNUC__) && \
721 ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 4))))) && \
722 !defined(__TINYC__) && !defined(LZ4_FORCE_SW_BITCOUNT)
728 static const unsigned char ctz7_tab[128] = {
729 7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1,
730 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 5, 0, 1, 0, 2, 0,
731 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3,
732 0, 1, 0, 2, 0, 1, 0, 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0,
733 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1,
734 0, 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0,
735 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
737 U64 const mask = 0x0101010101010101ULL;
739 return ctz7_tab[(
t * 0x0080402010080402ULL) >> 57];
749 if (!(val >>
by32)) {
769#if (defined(__clang__) || \
770 (defined(__GNUC__) && \
771 ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 4))))) && \
772 !defined(LZ4_FORCE_SW_BITCOUNT)
776 val = ((((val + 0x00FFFF00) | 0x00FFFFFF) + val) |
777 (val + 0x00FF0000)) >>
779 return (
unsigned)val ^ 3;
785#define STEPSIZE sizeof(reg_t)
798 return LZ4_NbCommonBytes(
diff);
809 pIn += LZ4_NbCommonBytes(
diff);
814 (LZ4_read32(
pMatch) == LZ4_read32(
pIn))) {
827#ifndef LZ4_COMMONDEFS_ONLY
831static const int LZ4_64Klimit = ((64
KB) + (
MFLIMIT - 1));
832static const U32 LZ4_skipTrigger = 6;
894#if defined(__cplusplus)
907#if defined(__cplusplus)
916 if (tableType ==
byU16)
926 if (LZ4_isLittleEndian()) {
939 if ((
sizeof(
reg_t) == 8) && (tableType !=
byU16))
940 return LZ4_hash5(LZ4_read_ARCH(p), tableType);
942#ifdef LZ4_STATIC_LINKING_ONLY_ENDIANNESS_INDEPENDENT_OUTPUT
945 return LZ4_hash4(LZ4_read32(p), tableType);
994 hashTable[h] = (
U16)idx;
1014 U32 const h = LZ4_hashPosition(p, tableType);
1015 LZ4_putPositionOnHash(p, h,
tableBase, tableType);
1028 if (tableType ==
byU32) {
1031 return hashTable[h];
1033 if (tableType ==
byU16) {
1036 return hashTable[h];
1049 return hashTable[h];
1056 U32 const h = LZ4_hashPosition(p, tableType);
1057 return LZ4_getPositionOnHash(h,
tableBase, tableType);
1071 ((tableType ==
byU16) &&
1073 ((tableType ==
byU32) &&
cctx->currentOffset > 1
GB) ||
1075 DEBUGLOG(4,
"LZ4_prepareTable: Resetting table in %p",
cctx);
1077 cctx->currentOffset = 0;
1081 DEBUGLOG(4,
"LZ4_prepareTable: Re-use hash table (no reset)");
1090 if (
cctx->currentOffset != 0 && tableType ==
byU32) {
1091 DEBUGLOG(5,
"LZ4_prepareTable: adding 64KB to currentOffset");
1092 cctx->currentOffset += 64
KB;
1124 const BYTE *
const dictionary =
1126 const U32 dictSize =
1137 const BYTE *
const dictEnd = dictionary ? dictionary + dictSize : dictionary;
1147 ? dictionary + dictSize - dictCtx->currentOffset
1156 DEBUGLOG(5,
"LZ4_compress_generic_validated: srcSize=%i, tableType=%u",
1159 if (tableType ==
byU16)
1162 if (tableType ==
byPtr)
1186 cctx->tableType = (
U32)tableType;
1194 U32 const h = LZ4_hashPosition(ip, tableType);
1195 if (tableType ==
byPtr) {
1196 LZ4_putPositionOnHash(ip, h,
cctx->hashTable,
byPtr);
1203 forwardH = LZ4_hashPosition(ip, tableType);
1212 if (tableType ==
byPtr) {
1226 match = LZ4_getPositionOnHash(h,
cctx->hashTable, tableType);
1228 LZ4_putPositionOnHash(ip, h,
cctx->hashTable, tableType);
1231 (LZ4_read32(
match) != LZ4_read32(ip)));
1242 LZ4_getIndexOnHash(h,
cctx->hashTable, tableType);
1258 LZ4_getIndexOnHash(h, dictCtx->hashTable,
byU32);
1273 "extDict candidate: matchIndex=%5u < "
1290 LZ4_putIndexOnHash(current, h,
cctx->hashTable, tableType);
1298 if (((tableType !=
byU16) ||
1307 if (LZ4_read32(
match) == LZ4_read32(ip)) {
1353 for (; len >= 255; len -= 255)
1363 DEBUGLOG(6,
"seq.start:%i, literals=%u, match.start:%i",
1393 DEBUGLOG(6,
" with offset=%u (ext if > %i)", offset,
1396 LZ4_writeLE16(
op, (
U16)offset);
1400 DEBUGLOG(6,
" with offset=%u (same segment)",
1421 unsigned const more =
1427 " with matchLength=%u starting in extDict",
1434 DEBUGLOG(6,
" with matchLength=%u",
1458 DEBUGLOG(5,
"Clearing %u positions",
1460 for (ptr = ip; ptr <=
filledIp; ++ptr) {
1461 U32 const h = LZ4_hashPosition(ptr, tableType);
1462 LZ4_clearHash(h,
cctx->hashTable, tableType);
1475 LZ4_write32(
op, 0xFFFFFFFF);
1478 LZ4_write32(
op, 0xFFFFFFFF);
1499 U32 const h = LZ4_hashPosition(ip - 2, tableType);
1500 if (tableType ==
byPtr) {
1501 LZ4_putPositionOnHash(ip - 2, h,
cctx->hashTable,
byPtr);
1504 U32 const idx = (
U32)((ip - 2) - base);
1505 LZ4_putIndexOnHash(idx, h,
cctx->hashTable, tableType);
1510 if (tableType ==
byPtr) {
1512 match = LZ4_getPosition(ip,
cctx->hashTable, tableType);
1513 LZ4_putPosition(ip,
cctx->hashTable, tableType);
1515 (LZ4_read32(
match) == LZ4_read32(ip))) {
1523 U32 const h = LZ4_hashPosition(ip, tableType);
1524 U32 const current = (
U32)(ip - base);
1532 LZ4_getIndexOnHash(h, dictCtx->hashTable,
byU32);
1560 LZ4_putIndexOnHash(current, h,
cctx->hashTable, tableType);
1564 (((tableType ==
byU16) &&
1568 (LZ4_read32(
match) == LZ4_read32(ip))) {
1573 DEBUGLOG(6,
"seq.start:%i, literals=%u, match.start:%i",
1581 forwardH = LZ4_hashPosition(++ip, tableType);
1624 DEBUGLOG(5,
"LZ4_compress_generic: compressed %i bytes into %i bytes",
1641 DEBUGLOG(5,
"LZ4_compress_generic: srcSize=%i, dstCapacity=%i",
srcSize,
1650 DEBUGLOG(5,
"Generating an empty block");
1662 return LZ4_compress_generic_validated(
1739 if (
ctx->currentOffset) {
1765 if (
ctx->currentOffset) {
1766 return LZ4_compress_generic(
1771 return LZ4_compress_generic(
1820static int LZ4_compress_destSize_extState_internal(
LZ4_stream_t *state,
1821 const char *src,
char *dst,
1838 return LZ4_compress_generic(&
state->internal_donotuse, src, dst,
1848 return LZ4_compress_generic(&
state->internal_donotuse, src, dst,
1860 int const r = LZ4_compress_destSize_extState_internal(
1881 int result = LZ4_compress_destSize_extState_internal(
1894#if !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
1907static size_t LZ4_stream_t_alignment(
void)
1923 if (buffer ==
NULL) {
1929 if (!LZ4_isAligned(buffer, LZ4_stream_t_alignment()))
1945 LZ4_prepareTable(&(
ctx->internal_donotuse), 0,
byU32);
1948#if !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
1960#define HASH_UNIT sizeof(reg_t)
1966 const BYTE *p = (
const BYTE *)dictionary;
1970 DEBUGLOG(4,
"LZ4_loadDict (%i bytes from %p into %p)", dictSize, dictionary,
1985 dict->currentOffset += 64
KB;
1993 dict->dictionary = p;
1995 dict->tableType = (
U32)tableType;
1999 U32 const h = LZ4_hashPosition(p, tableType);
2001 LZ4_putIndexOnHash(
idx32, h,
dict->hashTable, tableType);
2009 p =
dict->dictionary;
2012 U32 const h = LZ4_hashPosition(p, tableType);
2013 U32 const limit =
dict->currentOffset - 64
KB;
2014 if (LZ4_getIndexOnHash(h,
dict->hashTable, tableType) <= limit) {
2017 LZ4_putIndexOnHash(
idx32, h,
dict->hashTable, tableType);
2048 if (dictCtx !=
NULL) {
2101 DEBUGLOG(5,
"LZ4_compress_fast_continue (inputSize=%i, dictSize=%u)",
2119 "LZ4_compress_fast_continue: dictSize(%u) at addr:%p is too small",
2173 result = LZ4_compress_generic(
2179 result = LZ4_compress_generic(
2188 result = LZ4_compress_generic(
2194 result = LZ4_compress_generic(
2245 DEBUGLOG(5,
"LZ4_saveDict : dictSize=%i, safeBuffer=%p", dictSize,
2248 if ((
U32)dictSize > 64
KB) {
2251 if ((
U32)dictSize >
dict->dictSize) {
2252 dictSize = (
int)
dict->dictSize;
2264 dict->dictSize = (
U32)dictSize;
2276#define MIN(a, b) ((a) < (b) ? (a) : (b))
2282static size_t read_long_length_no_check(
const BYTE **
pp)
2290 DEBUGLOG(6,
"read_long_length_no_check: +length=%zu using %zu input bytes",
2309 const size_t dictSize
2317 DEBUGLOG(5,
"LZ4_decompress_unsafe_generic");
2323 unsigned token = *ip++;
2330 ll += read_long_length_no_check(&ip);
2342 "invalid: literals end at distance %zi from end of block",
2353 size_t ml = token & 15;
2354 size_t const offset = LZ4_readLE16(ip);
2359 ml += read_long_length_no_check(&ip);
2371 DEBUGLOG(6,
"offset out of range");
2400 for (u = 0; u <
ml; u++) {
2408 5,
"invalid: match ends at distance %zi from end of block",
2417 return (
int)(ip -
istart);
2429typedef size_t Rvl_t;
2434 Rvl_t s, length = 0;
2448 if ((
sizeof(length) < 8) &&
unlikely(length > ((
Rvl_t)(-1) / 2))) {
2461 if ((
sizeof(length) < 8) &&
unlikely(length > ((
Rvl_t)(-1) / 2))) {
2476 const char *
const src,
char *
const dst,
int srcSize,
2484 const size_t dictSize
2492 const BYTE *ip = (
const BYTE *)src;
2513 DEBUGLOG(5,
"LZ4_decompress_generic (srcSize:%i, dstSize:%i)",
srcSize,
2522 return ((
srcSize == 1) && (*ip == 0)) ? 0 : -1;
2533#if LZ4_FAST_DEC_LOOP
2535 DEBUGLOG(6,
"move to safe decode loop");
2541 DEBUGLOG(6,
"using fast decode loop");
2549 DEBUGLOG(7,
"blockPos%6u: litLength token = %u",
2550 (
unsigned)(
op - (
BYTE *)dst), (
unsigned)length);
2556 if (
addl == rvl_error) {
2557 DEBUGLOG(6,
"error reading long literal length");
2570 if ((
op + length >
oend - 32) || (ip + length >
iend - 32)) {
2577 else if (ip <=
iend - (16 + 1 )) {
2580 DEBUGLOG(7,
"copy %u bytes in a 16-bytes stripe",
2593 offset = LZ4_readLE16(ip);
2595 DEBUGLOG(6,
"blockPos%6u: offset = %u",
2596 (
unsigned)(
op - (
BYTE *)dst), (
unsigned)offset);
2602 DEBUGLOG(7,
" match length token = %u (len==%u)", (
unsigned)length,
2608 if (
addl == rvl_error) {
2609 DEBUGLOG(5,
"error reading long match length");
2614 DEBUGLOG(7,
" long match length == %u", (
unsigned)length);
2625 DEBUGLOG(7,
"moving to safe_match_copy (ml==%u)",
2647 DEBUGLOG(5,
"Error : pos=%zi, offset=%zi => outside buffers",
2656 DEBUGLOG(7,
"partialDecoding: dictionary match, close "
2658 length =
MIN(length, (
size_t)(
oend -
op));
2661 DEBUGLOG(6,
"end-of-block condition violated")
2713 DEBUGLOG(6,
"using safe decode loop");
2718 DEBUGLOG(7,
"blockPos%6u: litLength token = %u",
2719 (
unsigned)(
op - (
BYTE *)dst), (
unsigned)length);
2742 DEBUGLOG(7,
"blockPos%6u: matchLength token = %u (len=%u)",
2743 (
unsigned)(
op - (
BYTE *)dst), (
unsigned)length,
2744 (
unsigned)length + 4);
2745 offset = LZ4_readLE16(ip);
2751 if ((length !=
ML_MASK) && (offset >= 8) &&
2771 if (
addl == rvl_error) {
2783#if LZ4_FAST_DEC_LOOP
2804 DEBUGLOG(7,
"partialDecoding: copying literals, close to "
2805 "input or output end")
2817 if (ip + length >
iend) {
2836 DEBUGLOG(5,
"should have been last run of literals")
2837 DEBUGLOG(5, "ip(%p) + length(%i) = %p !=
iend (%p)", ip,
2838 (
int)length, ip + length,
iend);
2862 LZ4_wildCopy8(
op, ip,
2869 offset = LZ4_readLE16(ip);
2875 DEBUGLOG(7,
"blockPos%6u: matchLength token = %u",
2876 (
unsigned)(
op - (
BYTE *)dst), (
unsigned)length);
2882 if (
addl == rvl_error) {
2891#if LZ4_FAST_DEC_LOOP
2901 length =
MIN(length, (
size_t)(
oend -
op));
2966 match += inc32table[offset];
2968 match -= dec64table[offset];
3001 DEBUGLOG(5,
"decoded %i bytes", (
int)(((
char *)
op) - dst));
3002 return (
int)(((
char *)
op) - dst);
3006 return (
int)(-(((
const char *)ip) - src)) - 1;
3033 DEBUGLOG(5,
"LZ4_decompress_fast");
3098 DEBUGLOG(5,
"LZ4_decompress_safe_forceExtDict");
3132 size_t prefixSize,
const void *
dictStart,
3143#if !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
3168 const char *dictionary,
int dictSize)
3174 lz4sd->prefixEnd = (
const BYTE *)dictionary + dictSize;
3177 lz4sd->prefixEnd = (
const BYTE *)dictionary;
3180 lz4sd->extDictSize = 0;
3222 if (
lz4sd->prefixSize == 0) {
3234 if (
lz4sd->prefixSize >= 64
KB - 1)
3237 else if (
lz4sd->extDictSize == 0)
3247 lz4sd->prefixEnd += result;
3255 lz4sd->extDictSize);
3277 if (
lz4sd->prefixSize == 0) {
3278 DEBUGLOG(5,
"first invocation : no prefix nor extDict");
3287 DEBUGLOG(5,
"continue using existing prefix");
3288 result = LZ4_decompress_unsafe_generic(
3297 DEBUGLOG(5,
"prefix becomes extDict");
3301 lz4sd->externalDict,
3302 lz4sd->extDictSize);
3326 if (dictSize >= 64
KB - 1) {
3349 if (dictSize >= 64
KB - 1) {
3401 const char *src,
char *dst,
int srcSize,
3444#if !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
3456 ->internal_donotuse.dictionary;
int LZ4_decompress_safe_forceExtDict(const char *source, char *dest, int compressedSize, int maxOutputSize, const void *dictStart, size_t dictSize)
int LZ4_compress_fast_extState(void *state, const char *source, char *dest, int inputSize, int maxOutputSize, int acceleration)
#define LZ4_STATIC_ASSERT(c)
int LZ4_compressBound(int isize)
int LZ4_loadDict(LZ4_stream_t *LZ4_dict, const char *dictionary, int dictSize)
int LZ4_decompress_safe_partial_forceExtDict(const char *source, char *dest, int compressedSize, int targetOutputSize, int dstCapacity, const void *dictStart, size_t dictSize)
int LZ4_loadDict_internal(LZ4_stream_t *LZ4_dict, const char *dictionary, int dictSize, LoadDict_mode_e _ld)
int LZ4_compress_destSize(const char *src, char *dst, int *srcSizePtr, int targetDstSize)
int LZ4_sizeofState(void)
#define LZ4_memcpy(dst, src, size)
void LZ4_resetStream(LZ4_stream_t *LZ4_stream)
#define LZ4_DISTANCE_ABSOLUTE_MAX
void LZ4_resetStream_fast(LZ4_stream_t *ctx)
int LZ4_freeStream(LZ4_stream_t *LZ4_stream)
const char * LZ4_versionString(void)
LZ4_stream_t * LZ4_initStream(void *buffer, size_t size)
int LZ4_loadDictSlow(LZ4_stream_t *LZ4_dict, const char *dictionary, int dictSize)
int LZ4_versionNumber(void)
LZ4_stream_t * LZ4_createStream(void)
int LZ4_compress_forceExtDict(LZ4_stream_t *LZ4_dict, const char *source, char *dest, int srcSize)
#define FASTLOOP_SAFE_DISTANCE
#define ALLOC_AND_ZERO(s)
#define MEM_INIT(p, v, s)
int LZ4_compress_default(const char *src, char *dst, int srcSize, int dstCapacity)
int LZ4_saveDict(LZ4_stream_t *LZ4_dict, char *safeBuffer, int dictSize)
int LZ4_compress_fast_continue(LZ4_stream_t *LZ4_stream, const char *source, char *dest, int inputSize, int maxOutputSize, int acceleration)
#define LZ4_ACCELERATION_MAX
#define MATCH_SAFEGUARD_DISTANCE
#define assert(condition)
int LZ4_compress_fast_extState_fastReset(void *state, const char *src, char *dst, int srcSize, int dstCapacity, int acceleration)
#define LZ4_ACCELERATION_DEFAULT
void LZ4_attach_dictionary(LZ4_stream_t *workingStream, const LZ4_stream_t *dictionaryStream)
int LZ4_compress_fast(const char *src, char *dest, int srcSize, int dstCapacity, int acceleration)
int LZ4_compress_destSize_extState(void *state, const char *src, char *dst, int *srcSizePtr, int targetDstSize, int acceleration)
int LZ4_decompress_fast_withPrefix64k(const char *src, char *dst, int originalSize)
int LZ4_decompress_fast_usingDict(const char *src, char *dst, int originalSize, const char *dictStart, int dictSize)
#define LZ4_HASHTABLESIZE
int LZ4_compress_limitedOutput_continue(LZ4_stream_t *LZ4_streamPtr, const char *source, char *dest, int inputSize, int maxOutputSize)
#define LZ4_COMPRESSBOUND(isize)
#define LZ4_VERSION_STRING
int LZ4_decompress_safe_partial(const char *src, char *dst, int srcSize, int targetOutputSize, int dstCapacity)
int LZ4_compress_withState(void *state, const char *source, char *dest, int inputSize)
int LZ4_decoderRingBufferSize(int maxBlockSize)
union LZ4_stream_u LZ4_stream_t
int LZ4_compress(const char *src, char *dest, int srcSize)
int LZ4_decompress_safe_partial_usingDict(const char *src, char *dst, int compressedSize, int targetOutputSize, int maxOutputSize, const char *dictStart, int dictSize)
#define LZ4_HASH_SIZE_U32
int LZ4_uncompress(const char *source, char *dest, int outputSize)
char * LZ4_slideInputBuffer(void *state)
int LZ4_decompress_safe_withPrefix64k(const char *src, char *dst, int compressedSize, int maxDstSize)
int LZ4_decompress_fast(const char *src, char *dst, int originalSize)
#define LZ4_DECODER_RING_BUFFER_SIZE(maxBlockSize)
int LZ4_uncompress_unknownOutputSize(const char *source, char *dest, int isize, int maxOutputSize)
int LZ4_compress_limitedOutput(const char *src, char *dest, int srcSize, int maxOutputSize)
#define LZ4_MAX_INPUT_SIZE
int LZ4_sizeofStreamState(void)
int LZ4_setStreamDecode(LZ4_streamDecode_t *LZ4_streamDecode, const char *dictionary, int dictSize)
#define LZ4_VERSION_NUMBER
int LZ4_compress_limitedOutput_withState(void *state, const char *source, char *dest, int inputSize, int maxOutputSize)
int LZ4_decompress_safe_continue(LZ4_streamDecode_t *LZ4_streamDecode, const char *src, char *dst, int srcSize, int dstCapacity)
int LZ4_resetStreamState(void *state, char *inputBuffer)
int LZ4_decompress_safe(const char *src, char *dst, int compressedSize, int dstCapacity)
int LZ4_compress_continue(LZ4_stream_t *LZ4_streamPtr, const char *source, char *dest, int inputSize)
int LZ4_decompress_safe_usingDict(const char *src, char *dst, int srcSize, int dstCapacity, const char *dictStart, int dictSize)
int LZ4_decompress_fast_continue(LZ4_streamDecode_t *LZ4_streamDecode, const char *src, char *dst, int originalSize)
int LZ4_freeStreamDecode(LZ4_streamDecode_t *LZ4_stream)
LZ4_streamDecode_t * LZ4_createStreamDecode(void)
void * LZ4_create(char *inputBuffer)
LZ4_stream_t_internal internal_donotuse