2013-07-08 16:01:49 -07:00
|
|
|
/*
|
|
|
|
* LZ4 - Fast LZ compression algorithm
|
2017-02-24 15:01:12 -08:00
|
|
|
* Copyright (C) 2011 - 2016, Yann Collet.
|
|
|
|
* BSD 2 - Clause License (http://www.opensource.org/licenses/bsd - license.php)
|
2013-07-08 16:01:49 -07:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met:
|
2017-02-24 15:01:12 -08:00
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above
|
2013-07-08 16:01:49 -07:00
|
|
|
* copyright notice, this list of conditions and the following disclaimer
|
|
|
|
* in the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
* You can contact the author at :
|
2017-02-24 15:01:12 -08:00
|
|
|
* - LZ4 homepage : http://www.lz4.org
|
|
|
|
* - LZ4 source repository : https://github.com/lz4/lz4
|
2013-07-08 16:01:49 -07:00
|
|
|
*
|
2017-02-24 15:01:12 -08:00
|
|
|
* Changed for kernel usage by:
|
|
|
|
* Sven Schmidt <4sschmid@informatik.uni-hamburg.de>
|
2013-07-08 16:01:49 -07:00
|
|
|
*/
|
|
|
|
|
2017-02-24 15:01:12 -08:00
|
|
|
/*-************************************
|
|
|
|
* Dependencies
|
|
|
|
**************************************/
|
|
|
|
#include <linux/lz4.h>
|
|
|
|
#include "lz4defs.h"
|
2013-07-08 16:01:49 -07:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <asm/unaligned.h>
|
|
|
|
|
2017-02-24 15:01:12 -08:00
|
|
|
static const int LZ4_minLength = (MFLIMIT + 1);
|
|
|
|
static const int LZ4_64Klimit = ((64 * KB) + (MFLIMIT - 1));
|
2022-06-29 19:16:02 +02:00
|
|
|
/* Increase this value ==> compression run slower on incompressible data */
|
|
|
|
static const U32 LZ4_skipTrigger = 6;
|
|
|
|
|
|
|
|
LZ4_stream_t *LZ4_initStream(void *buffer, size_t size);
|
2017-02-24 15:01:12 -08:00
|
|
|
|
|
|
|
/*-******************************
|
|
|
|
* Compression functions
|
|
|
|
********************************/
|
2022-06-29 19:16:02 +02:00
|
|
|
static FORCE_INLINE U32 LZ4_hash4(U32 sequence, tableType_t const tableType)
|
2013-07-08 16:01:49 -07:00
|
|
|
{
|
2017-02-24 15:01:12 -08:00
|
|
|
if (tableType == byU16)
|
2022-06-29 19:16:02 +02:00
|
|
|
return ((sequence * 2654435761U) >>
|
|
|
|
((MINMATCH * 8) - (LZ4_HASHLOG + 1)));
|
2017-02-24 15:01:12 -08:00
|
|
|
else
|
2022-06-29 19:16:02 +02:00
|
|
|
return ((sequence * 2654435761U) >>
|
|
|
|
((MINMATCH * 8) - LZ4_HASHLOG));
|
2017-02-24 15:01:12 -08:00
|
|
|
}
|
|
|
|
|
2022-06-29 19:16:02 +02:00
|
|
|
static FORCE_INLINE U32 LZ4_hash5(U64 sequence, tableType_t const tableType)
|
2017-02-24 15:01:12 -08:00
|
|
|
{
|
2022-06-29 19:16:02 +02:00
|
|
|
const U32 hashLog = (tableType == byU16) ? LZ4_HASHLOG + 1 :
|
|
|
|
LZ4_HASHLOG;
|
2017-02-24 15:01:12 -08:00
|
|
|
|
|
|
|
#if LZ4_LITTLE_ENDIAN
|
|
|
|
static const U64 prime5bytes = 889523592379ULL;
|
|
|
|
|
|
|
|
return (U32)(((sequence << 24) * prime5bytes) >> (64 - hashLog));
|
2013-07-08 16:01:49 -07:00
|
|
|
#else
|
2017-02-24 15:01:12 -08:00
|
|
|
static const U64 prime8bytes = 11400714785074694791ULL;
|
|
|
|
|
|
|
|
return (U32)(((sequence >> 24) * prime8bytes) >> (64 - hashLog));
|
2013-07-08 16:01:49 -07:00
|
|
|
#endif
|
2017-02-24 15:01:12 -08:00
|
|
|
}
|
|
|
|
|
2022-06-29 19:16:02 +02:00
|
|
|
static FORCE_INLINE U32 LZ4_hashPosition(const void *p,
|
|
|
|
tableType_t const tableType)
|
2017-02-24 15:01:12 -08:00
|
|
|
{
|
|
|
|
#if LZ4_ARCH64
|
2022-06-29 19:16:02 +02:00
|
|
|
if (tableType != byU16)
|
2017-02-24 15:01:12 -08:00
|
|
|
return LZ4_hash5(LZ4_read_ARCH(p), tableType);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return LZ4_hash4(LZ4_read32(p), tableType);
|
|
|
|
}
|
|
|
|
|
2022-06-29 19:16:02 +02:00
|
|
|
static FORCE_INLINE void LZ4_clearHash(U32 h, void *tableBase,
|
|
|
|
tableType_t const tableType)
|
2017-02-24 15:01:12 -08:00
|
|
|
{
|
|
|
|
switch (tableType) {
|
2022-06-29 19:16:02 +02:00
|
|
|
default: /* fallthrough */
|
|
|
|
case clearedTable: { /* illegal! */
|
|
|
|
assert(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case byPtr: {
|
|
|
|
const BYTE **hashTable = (const BYTE **)tableBase;
|
|
|
|
hashTable[h] = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case byU32: {
|
|
|
|
U32 *hashTable = (U32 *)tableBase;
|
|
|
|
hashTable[h] = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case byU16: {
|
|
|
|
U16 *hashTable = (U16 *)tableBase;
|
|
|
|
hashTable[h] = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static FORCE_INLINE void LZ4_putIndexOnHash(U32 idx, U32 h, void *tableBase,
|
|
|
|
tableType_t const tableType)
|
|
|
|
{
|
|
|
|
switch (tableType) {
|
|
|
|
default: /* fallthrough */
|
|
|
|
case clearedTable: /* fallthrough */
|
|
|
|
case byPtr: { /* illegal! */
|
|
|
|
assert(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case byU32: {
|
|
|
|
U32 *hashTable = (U32 *)tableBase;
|
|
|
|
hashTable[h] = idx;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case byU16: {
|
|
|
|
U16 *hashTable = (U16 *)tableBase;
|
|
|
|
assert(idx < 65536);
|
|
|
|
hashTable[h] = (U16)idx;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void LZ4_putPositionOnHash(const BYTE *p, U32 h, void *tableBase,
|
|
|
|
tableType_t const tableType,
|
|
|
|
const BYTE *srcBase)
|
|
|
|
{
|
|
|
|
switch (tableType) {
|
|
|
|
case byPtr: {
|
2017-02-24 15:01:12 -08:00
|
|
|
const BYTE **hashTable = (const BYTE **)tableBase;
|
|
|
|
|
|
|
|
hashTable[h] = p;
|
|
|
|
return;
|
|
|
|
}
|
2022-06-29 19:16:02 +02:00
|
|
|
case byU32: {
|
|
|
|
U32 *hashTable = (U32 *)tableBase;
|
2017-02-24 15:01:12 -08:00
|
|
|
|
|
|
|
hashTable[h] = (U32)(p - srcBase);
|
|
|
|
return;
|
|
|
|
}
|
2022-06-29 19:16:02 +02:00
|
|
|
case byU16: {
|
|
|
|
U16 *hashTable = (U16 *)tableBase;
|
2017-02-24 15:01:12 -08:00
|
|
|
|
|
|
|
hashTable[h] = (U16)(p - srcBase);
|
|
|
|
return;
|
|
|
|
}
|
2022-06-29 19:16:02 +02:00
|
|
|
case clearedTable: { /* fallthrough */
|
|
|
|
}
|
2017-02-24 15:01:12 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-29 19:16:02 +02:00
|
|
|
static FORCE_INLINE void LZ4_putPosition(const BYTE *p, void *tableBase,
|
|
|
|
tableType_t tableType,
|
|
|
|
const BYTE *srcBase)
|
2017-02-24 15:01:12 -08:00
|
|
|
{
|
|
|
|
U32 const h = LZ4_hashPosition(p, tableType);
|
|
|
|
|
|
|
|
LZ4_putPositionOnHash(p, h, tableBase, tableType, srcBase);
|
|
|
|
}
|
|
|
|
|
2022-06-29 19:16:02 +02:00
|
|
|
/* LZ4_getIndexOnHash() :
|
|
|
|
* Index of match position registered in hash table.
|
|
|
|
* hash position must be calculated by using base+index, or dictBase+index.
|
|
|
|
* Assumption 1 : only valid if tableType == byU32 or byU16.
|
|
|
|
* Assumption 2 : h is presumed valid (within limits of hash table)
|
|
|
|
*/
|
|
|
|
static FORCE_INLINE U32 LZ4_getIndexOnHash(U32 h, const void *tableBase,
|
|
|
|
tableType_t tableType)
|
|
|
|
{
|
|
|
|
LZ4_STATIC_ASSERT(LZ4_MEMORY_USAGE > 2);
|
|
|
|
if (tableType == byU32) {
|
|
|
|
const U32 *const hashTable = (const U32 *)tableBase;
|
|
|
|
assert(h < (1U << (LZ4_MEMORY_USAGE - 2)));
|
|
|
|
return hashTable[h];
|
|
|
|
}
|
|
|
|
if (tableType == byU16) {
|
|
|
|
const U16 *const hashTable = (const U16 *)tableBase;
|
|
|
|
assert(h < (1U << (LZ4_MEMORY_USAGE - 1)));
|
|
|
|
return hashTable[h];
|
|
|
|
}
|
|
|
|
assert(0);
|
|
|
|
return 0; /* forbidden case */
|
|
|
|
}
|
|
|
|
|
|
|
|
static const BYTE *LZ4_getPositionOnHash(U32 h, void *tableBase,
|
|
|
|
tableType_t tableType,
|
|
|
|
const BYTE *srcBase)
|
2017-02-24 15:01:12 -08:00
|
|
|
{
|
|
|
|
if (tableType == byPtr) {
|
2022-06-29 19:16:02 +02:00
|
|
|
const BYTE **hashTable = (const BYTE **)tableBase;
|
2017-02-24 15:01:12 -08:00
|
|
|
|
|
|
|
return hashTable[h];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tableType == byU32) {
|
2022-06-29 19:16:02 +02:00
|
|
|
const U32 *const hashTable = (U32 *)tableBase;
|
2017-02-24 15:01:12 -08:00
|
|
|
|
|
|
|
return hashTable[h] + srcBase;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
/* default, to ensure a return */
|
2022-06-29 19:16:02 +02:00
|
|
|
const U16 *const hashTable = (U16 *)tableBase;
|
2017-02-24 15:01:12 -08:00
|
|
|
|
|
|
|
return hashTable[h] + srcBase;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-29 19:16:02 +02:00
|
|
|
static FORCE_INLINE const BYTE *LZ4_getPosition(const BYTE *p, void *tableBase,
|
|
|
|
tableType_t tableType,
|
|
|
|
const BYTE *srcBase)
|
2017-02-24 15:01:12 -08:00
|
|
|
{
|
|
|
|
U32 const h = LZ4_hashPosition(p, tableType);
|
|
|
|
|
|
|
|
return LZ4_getPositionOnHash(h, tableBase, tableType, srcBase);
|
|
|
|
}
|
|
|
|
|
2022-06-29 19:16:02 +02:00
|
|
|
static FORCE_INLINE void LZ4_prepareTable(LZ4_stream_t_internal *const cctx,
|
|
|
|
const int inputSize,
|
|
|
|
const tableType_t tableType)
|
|
|
|
{
|
|
|
|
/* If the table hasn't been used, it's guaranteed to be zeroed out, and is
|
|
|
|
* therefore safe to use no matter what mode we're in. Otherwise, we figure
|
|
|
|
* out if it's safe to leave as is or whether it needs to be reset.
|
|
|
|
*/
|
|
|
|
if ((tableType_t)cctx->tableType != clearedTable) {
|
|
|
|
assert(inputSize >= 0);
|
|
|
|
if ((tableType_t)cctx->tableType != tableType ||
|
|
|
|
((tableType == byU16) &&
|
|
|
|
cctx->currentOffset + (unsigned)inputSize >= 0xFFFFU) ||
|
|
|
|
((tableType == byU32) && cctx->currentOffset > 1 * GB) ||
|
|
|
|
tableType == byPtr || inputSize >= 4 * KB) {
|
|
|
|
DEBUGLOG(4, "LZ4_prepareTable: Resetting table in %p",
|
|
|
|
cctx);
|
|
|
|
memset(cctx->hashTable, 0, LZ4_HASHTABLESIZE);
|
|
|
|
cctx->currentOffset = 0;
|
|
|
|
cctx->tableType = (U32)clearedTable;
|
|
|
|
} else {
|
|
|
|
DEBUGLOG(
|
|
|
|
4,
|
|
|
|
"LZ4_prepareTable: Re-use hash table (no reset)");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Adding a gap, so all previous entries are > LZ4_DISTANCE_MAX back,
|
|
|
|
* is faster than compressing without a gap.
|
|
|
|
* However, compressing with currentOffset == 0 is faster still,
|
|
|
|
* so we preserve that case.
|
|
|
|
*/
|
|
|
|
if (cctx->currentOffset != 0 && tableType == byU32) {
|
|
|
|
DEBUGLOG(5, "LZ4_prepareTable: adding 64KB to currentOffset");
|
|
|
|
cctx->currentOffset += 64 * KB;
|
|
|
|
}
|
2013-07-08 16:01:49 -07:00
|
|
|
|
2022-06-29 19:16:02 +02:00
|
|
|
/* Finally, clear history */
|
|
|
|
cctx->dictCtx = NULL;
|
|
|
|
cctx->dictionary = NULL;
|
|
|
|
cctx->dictSize = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** LZ4_compress_generic() :
|
|
|
|
* inlined, to ensure branches are decided at compilation time.
|
|
|
|
* Presumed already validated at this stage:
|
|
|
|
* - source != NULL
|
|
|
|
* - inputSize > 0
|
2017-02-24 15:01:12 -08:00
|
|
|
*/
|
2022-06-29 19:16:02 +02:00
|
|
|
static FORCE_INLINE int LZ4_compress_generic_validated(
|
|
|
|
LZ4_stream_t_internal *const cctx, const char *const source,
|
|
|
|
char *const dest, const int inputSize,
|
|
|
|
int *inputConsumed, /* only written when outputDirective == fillOutput */
|
|
|
|
const int maxOutputSize, const limitedOutput_directive outputDirective,
|
|
|
|
const tableType_t tableType, const dict_directive dictDirective,
|
|
|
|
const dictIssue_directive dictIssue, const int acceleration)
|
2017-02-24 15:01:12 -08:00
|
|
|
{
|
2022-06-29 19:16:02 +02:00
|
|
|
int result;
|
|
|
|
const BYTE *ip = (const BYTE *)source;
|
|
|
|
|
|
|
|
U32 const startIndex = cctx->currentOffset;
|
|
|
|
const BYTE *base = (const BYTE *)source - startIndex;
|
2017-02-24 15:01:12 -08:00
|
|
|
const BYTE *lowLimit;
|
|
|
|
|
2022-06-29 19:16:02 +02:00
|
|
|
const LZ4_stream_t_internal *dictCtx =
|
|
|
|
(const LZ4_stream_t_internal *)cctx->dictCtx;
|
|
|
|
const BYTE *const dictionary = dictDirective == usingDictCtx ?
|
|
|
|
dictCtx->dictionary :
|
|
|
|
cctx->dictionary;
|
|
|
|
const U32 dictSize = dictDirective == usingDictCtx ? dictCtx->dictSize :
|
|
|
|
cctx->dictSize;
|
|
|
|
const U32 dictDelta =
|
|
|
|
(dictDirective == usingDictCtx) ?
|
|
|
|
startIndex - dictCtx->currentOffset :
|
|
|
|
0; /* make indexes in dictCtx comparable with index in current context */
|
|
|
|
|
|
|
|
int const maybe_extMem = (dictDirective == usingExtDict) ||
|
|
|
|
(dictDirective == usingDictCtx);
|
|
|
|
U32 const prefixIdxLimit =
|
|
|
|
startIndex -
|
|
|
|
dictSize; /* used when dictDirective == dictSmall */
|
|
|
|
const BYTE *const dictEnd = dictionary ? dictionary + dictSize :
|
|
|
|
dictionary;
|
|
|
|
const BYTE *anchor = (const BYTE *)source;
|
|
|
|
const BYTE *const iend = ip + inputSize;
|
|
|
|
const BYTE *const mflimitPlusOne = iend - MFLIMIT + 1;
|
|
|
|
const BYTE *const matchlimit = iend - LASTLITERALS;
|
|
|
|
|
|
|
|
/* the dictCtx currentOffset is indexed on the start of the dictionary,
|
|
|
|
* while a dictionary in the current context precedes the currentOffset */
|
|
|
|
const BYTE *dictBase =
|
|
|
|
(dictionary == NULL) ?
|
|
|
|
NULL :
|
|
|
|
(dictDirective == usingDictCtx) ?
|
|
|
|
dictionary + dictSize - dictCtx->currentOffset :
|
|
|
|
dictionary + dictSize - startIndex;
|
|
|
|
|
|
|
|
BYTE *op = (BYTE *)dest;
|
|
|
|
BYTE *const olimit = op + maxOutputSize;
|
|
|
|
|
|
|
|
U32 offset = 0;
|
2017-02-24 15:01:12 -08:00
|
|
|
U32 forwardH;
|
|
|
|
|
2022-06-29 19:16:02 +02:00
|
|
|
DEBUGLOG(5, "LZ4_compress_generic_validated: srcSize=%i, tableType=%u",
|
|
|
|
inputSize, tableType);
|
|
|
|
assert(ip != NULL);
|
|
|
|
/* If init conditions are not met, we don't have to mark stream
|
|
|
|
* as having dirty context, since no action was taken yet */
|
|
|
|
if (outputDirective == fillOutput && maxOutputSize < 1) {
|
2017-02-24 15:01:12 -08:00
|
|
|
return 0;
|
2022-06-29 19:16:02 +02:00
|
|
|
} /* Impossible to store anything */
|
|
|
|
if ((tableType == byU16) && (inputSize >= LZ4_64Klimit)) {
|
2017-02-24 15:01:12 -08:00
|
|
|
return 0;
|
2022-06-29 19:16:02 +02:00
|
|
|
} /* Size too large (not within 64K limit) */
|
|
|
|
if (tableType == byPtr)
|
|
|
|
assert(dictDirective ==
|
|
|
|
noDict); /* only supported use case with byPtr */
|
|
|
|
assert(acceleration >= 1);
|
|
|
|
|
|
|
|
lowLimit = (const BYTE *)source -
|
|
|
|
(dictDirective == withPrefix64k ? dictSize : 0);
|
|
|
|
|
|
|
|
/* Update context state */
|
|
|
|
if (dictDirective == usingDictCtx) {
|
|
|
|
/* Subsequent linked blocks can't use the dictionary. */
|
|
|
|
/* Instead, they use the block we just compressed. */
|
|
|
|
cctx->dictCtx = NULL;
|
|
|
|
cctx->dictSize = (U32)inputSize;
|
|
|
|
} else {
|
|
|
|
cctx->dictSize += (U32)inputSize;
|
2017-02-24 15:01:12 -08:00
|
|
|
}
|
2022-06-29 19:16:02 +02:00
|
|
|
cctx->currentOffset += (U32)inputSize;
|
|
|
|
cctx->tableType = (U32)tableType;
|
2017-02-24 15:01:12 -08:00
|
|
|
|
2022-06-29 19:16:02 +02:00
|
|
|
if (inputSize < LZ4_minLength)
|
|
|
|
goto _last_literals; /* Input too small, no compression (all literals) */
|
2013-07-08 16:01:49 -07:00
|
|
|
|
|
|
|
/* First Byte */
|
2022-06-29 19:16:02 +02:00
|
|
|
LZ4_putPosition(ip, cctx->hashTable, tableType, base);
|
2013-07-08 16:01:49 -07:00
|
|
|
ip++;
|
2017-02-24 15:01:12 -08:00
|
|
|
forwardH = LZ4_hashPosition(ip, tableType);
|
2013-07-08 16:01:49 -07:00
|
|
|
|
|
|
|
/* Main Loop */
|
2022-06-29 19:16:02 +02:00
|
|
|
for (;;) {
|
2017-02-24 15:01:12 -08:00
|
|
|
const BYTE *match;
|
|
|
|
BYTE *token;
|
2022-06-29 19:16:02 +02:00
|
|
|
const BYTE *filledIp;
|
2013-07-08 16:01:49 -07:00
|
|
|
|
|
|
|
/* Find a match */
|
2022-06-29 19:16:02 +02:00
|
|
|
if (tableType == byPtr) {
|
2017-02-24 15:01:12 -08:00
|
|
|
const BYTE *forwardIp = ip;
|
2022-06-29 19:16:02 +02:00
|
|
|
int step = 1;
|
|
|
|
int searchMatchNb = acceleration << LZ4_skipTrigger;
|
2017-02-24 15:01:12 -08:00
|
|
|
do {
|
|
|
|
U32 const h = forwardH;
|
|
|
|
ip = forwardIp;
|
|
|
|
forwardIp += step;
|
2022-06-29 19:16:02 +02:00
|
|
|
step = (searchMatchNb++ >> LZ4_skipTrigger);
|
2017-02-24 15:01:12 -08:00
|
|
|
|
2022-06-29 19:16:02 +02:00
|
|
|
if (unlikely(forwardIp > mflimitPlusOne))
|
2017-02-24 15:01:12 -08:00
|
|
|
goto _last_literals;
|
2022-06-29 19:16:02 +02:00
|
|
|
assert(ip < mflimitPlusOne);
|
|
|
|
|
|
|
|
match = LZ4_getPositionOnHash(
|
|
|
|
h, cctx->hashTable, tableType, base);
|
|
|
|
forwardH =
|
|
|
|
LZ4_hashPosition(forwardIp, tableType);
|
|
|
|
LZ4_putPositionOnHash(ip, h, cctx->hashTable,
|
|
|
|
tableType, base);
|
2017-02-24 15:01:12 -08:00
|
|
|
|
2022-06-29 19:16:02 +02:00
|
|
|
} while ((match + LZ4_DISTANCE_MAX < ip) ||
|
|
|
|
(LZ4_read32(match) != LZ4_read32(ip)));
|
2017-02-24 15:01:12 -08:00
|
|
|
|
2022-06-29 19:16:02 +02:00
|
|
|
} else { /* byU32, byU16 */
|
|
|
|
|
|
|
|
const BYTE *forwardIp = ip;
|
|
|
|
int step = 1;
|
|
|
|
int searchMatchNb = acceleration << LZ4_skipTrigger;
|
|
|
|
do {
|
|
|
|
U32 const h = forwardH;
|
|
|
|
U32 const cur = (U32)(forwardIp - base);
|
|
|
|
U32 matchIndex = LZ4_getIndexOnHash(
|
|
|
|
h, cctx->hashTable, tableType);
|
|
|
|
assert(matchIndex <= cur);
|
|
|
|
assert(forwardIp - base <
|
|
|
|
(ptrdiff_t)(2 * GB - 1));
|
|
|
|
ip = forwardIp;
|
|
|
|
forwardIp += step;
|
|
|
|
step = (searchMatchNb++ >> LZ4_skipTrigger);
|
|
|
|
|
|
|
|
if (unlikely(forwardIp > mflimitPlusOne))
|
|
|
|
goto _last_literals;
|
|
|
|
assert(ip < mflimitPlusOne);
|
|
|
|
|
|
|
|
if (dictDirective == usingDictCtx) {
|
|
|
|
if (matchIndex < startIndex) {
|
|
|
|
/* there was no match, try the dictionary */
|
|
|
|
assert(tableType == byU32);
|
|
|
|
matchIndex = LZ4_getIndexOnHash(
|
|
|
|
h, dictCtx->hashTable,
|
|
|
|
byU32);
|
|
|
|
match = dictBase + matchIndex;
|
|
|
|
matchIndex +=
|
|
|
|
dictDelta; /* make dictCtx index comparable with current context */
|
|
|
|
lowLimit = dictionary;
|
|
|
|
} else {
|
|
|
|
match = base + matchIndex;
|
|
|
|
lowLimit = (const BYTE *)source;
|
|
|
|
}
|
|
|
|
} else if (dictDirective == usingExtDict) {
|
|
|
|
if (matchIndex < startIndex) {
|
|
|
|
DEBUGLOG(
|
|
|
|
7,
|
|
|
|
"extDict candidate: matchIndex=%5u < startIndex=%5u",
|
|
|
|
matchIndex, startIndex);
|
|
|
|
assert(startIndex -
|
|
|
|
matchIndex >=
|
|
|
|
MINMATCH);
|
|
|
|
assert(dictBase);
|
|
|
|
match = dictBase + matchIndex;
|
2017-02-24 15:01:12 -08:00
|
|
|
lowLimit = dictionary;
|
|
|
|
} else {
|
2022-06-29 19:16:02 +02:00
|
|
|
match = base + matchIndex;
|
2017-02-24 15:01:12 -08:00
|
|
|
lowLimit = (const BYTE *)source;
|
2022-06-29 19:16:02 +02:00
|
|
|
}
|
|
|
|
} else { /* single continuous memory segment */
|
|
|
|
match = base + matchIndex;
|
|
|
|
}
|
|
|
|
forwardH =
|
|
|
|
LZ4_hashPosition(forwardIp, tableType);
|
|
|
|
LZ4_putIndexOnHash(cur, h, cctx->hashTable,
|
|
|
|
tableType);
|
|
|
|
|
|
|
|
DEBUGLOG(7,
|
|
|
|
"candidate at pos=%u (offset=%u \n",
|
|
|
|
matchIndex, cur - matchIndex);
|
|
|
|
if ((dictIssue == dictSmall) &&
|
|
|
|
(matchIndex < prefixIdxLimit)) {
|
|
|
|
continue;
|
|
|
|
} /* match outside of valid area */
|
|
|
|
assert(matchIndex < cur);
|
|
|
|
if (((tableType != byU16) ||
|
|
|
|
(LZ4_DISTANCE_MAX <
|
|
|
|
LZ4_DISTANCE_ABSOLUTE_MAX)) &&
|
|
|
|
(matchIndex + LZ4_DISTANCE_MAX < cur)) {
|
|
|
|
continue;
|
|
|
|
} /* too far */
|
|
|
|
assert((cur - matchIndex) <=
|
|
|
|
LZ4_DISTANCE_MAX); /* match now expected within distance */
|
|
|
|
|
|
|
|
if (LZ4_read32(match) == LZ4_read32(ip)) {
|
|
|
|
if (maybe_extMem)
|
|
|
|
offset = cur - matchIndex;
|
|
|
|
break; /* match found */
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (1);
|
2017-02-24 15:01:12 -08:00
|
|
|
}
|
2013-07-08 16:01:49 -07:00
|
|
|
|
|
|
|
/* Catch up */
|
2022-06-29 19:16:02 +02:00
|
|
|
filledIp = ip;
|
|
|
|
while (((ip > anchor) & (match > lowLimit)) &&
|
|
|
|
(unlikely(ip[-1] == match[-1]))) {
|
2013-07-08 16:01:49 -07:00
|
|
|
ip--;
|
2017-02-24 15:01:12 -08:00
|
|
|
match--;
|
2013-07-08 16:01:49 -07:00
|
|
|
}
|
|
|
|
|
2017-02-24 15:01:12 -08:00
|
|
|
/* Encode Literals */
|
|
|
|
{
|
2022-06-29 19:16:02 +02:00
|
|
|
unsigned const litLength = (unsigned)(ip - anchor);
|
2017-02-24 15:01:12 -08:00
|
|
|
token = op++;
|
2022-06-29 19:16:02 +02:00
|
|
|
if ((outputDirective ==
|
|
|
|
limitedOutput) && /* Check output buffer overflow */
|
|
|
|
(unlikely(op + litLength + (2 + 1 + LASTLITERALS) +
|
|
|
|
(litLength / 255) >
|
|
|
|
olimit))) {
|
|
|
|
return 0; /* cannot compress within `dst` budget. Stored indexes in hash table are nonetheless fine */
|
|
|
|
}
|
|
|
|
if ((outputDirective == fillOutput) &&
|
|
|
|
(unlikely(
|
|
|
|
op + (litLength + 240) / 255 /* litlen */ +
|
|
|
|
litLength /* literals */ +
|
|
|
|
2 /* offset */ + 1 /* token */ +
|
|
|
|
MFLIMIT -
|
|
|
|
MINMATCH /* min last literals so last match is <= end - MFLIMIT */
|
|
|
|
> olimit))) {
|
|
|
|
op--;
|
|
|
|
goto _last_literals;
|
|
|
|
}
|
2017-02-24 15:01:12 -08:00
|
|
|
if (litLength >= RUN_MASK) {
|
2022-06-29 19:16:02 +02:00
|
|
|
int len = (int)(litLength - RUN_MASK);
|
2017-02-24 15:01:12 -08:00
|
|
|
*token = (RUN_MASK << ML_BITS);
|
|
|
|
for (; len >= 255; len -= 255)
|
|
|
|
*op++ = 255;
|
|
|
|
*op++ = (BYTE)len;
|
|
|
|
} else
|
|
|
|
*token = (BYTE)(litLength << ML_BITS);
|
|
|
|
|
|
|
|
/* Copy Literals */
|
2022-06-29 19:16:02 +02:00
|
|
|
LZ4_wildCopy8(op, anchor, op + litLength);
|
2017-02-24 15:01:12 -08:00
|
|
|
op += litLength;
|
2022-06-29 19:16:02 +02:00
|
|
|
DEBUGLOG(6, "seq.start:%i, literals=%u, match.start:%i",
|
|
|
|
(int)(anchor - (const BYTE *)source),
|
|
|
|
litLength, (int)(ip - (const BYTE *)source));
|
2017-02-24 15:01:12 -08:00
|
|
|
}
|
2013-07-08 16:01:49 -07:00
|
|
|
|
|
|
|
_next_match:
|
2022-06-29 19:16:02 +02:00
|
|
|
/* at this stage, the following variables must be correctly set :
|
|
|
|
* - ip : at start of LZ operation
|
|
|
|
* - match : at start of previous pattern occurrence; can be within current prefix, or within extDict
|
|
|
|
* - offset : if maybe_ext_memSegment==1 (constant)
|
|
|
|
* - lowLimit : must be == dictionary to mean "match is within extDict"; must be == source otherwise
|
|
|
|
* - token and *token : position to write 4-bits for match length; higher 4-bits for literal length supposed already written
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((outputDirective == fillOutput) &&
|
|
|
|
(op + 2 /* offset */ + 1 /* token */ + MFLIMIT -
|
|
|
|
MINMATCH /* min last literals so last match is <= end - MFLIMIT */
|
|
|
|
> olimit)) {
|
|
|
|
/* the match was too close to the end, rewind and go to last literals */
|
|
|
|
op = token;
|
|
|
|
goto _last_literals;
|
|
|
|
}
|
|
|
|
|
2013-07-08 16:01:49 -07:00
|
|
|
/* Encode Offset */
|
2022-06-29 19:16:02 +02:00
|
|
|
if (maybe_extMem) { /* static test */
|
|
|
|
DEBUGLOG(6,
|
|
|
|
" with offset=%u (ext if > %i)",
|
|
|
|
offset, (int)(ip - (const BYTE *)source));
|
|
|
|
assert(offset <= LZ4_DISTANCE_MAX && offset > 0);
|
|
|
|
LZ4_writeLE16(op, (U16)offset);
|
|
|
|
op += 2;
|
|
|
|
} else {
|
|
|
|
DEBUGLOG(6,
|
|
|
|
" with offset=%u (same segment)",
|
|
|
|
(U32)(ip - match));
|
|
|
|
assert(ip - match <= LZ4_DISTANCE_MAX);
|
|
|
|
LZ4_writeLE16(op, (U16)(ip - match));
|
|
|
|
op += 2;
|
|
|
|
}
|
2013-07-08 16:01:49 -07:00
|
|
|
|
|
|
|
/* Encode MatchLength */
|
2017-02-24 15:01:12 -08:00
|
|
|
{
|
2022-06-29 19:16:02 +02:00
|
|
|
unsigned matchCode;
|
|
|
|
|
|
|
|
if ((dictDirective == usingExtDict ||
|
|
|
|
dictDirective == usingDictCtx) &&
|
|
|
|
(lowLimit ==
|
|
|
|
dictionary) /* match within extDict */) {
|
|
|
|
const BYTE *limit = ip + (dictEnd - match);
|
|
|
|
assert(dictEnd > match);
|
2017-02-24 15:01:12 -08:00
|
|
|
if (limit > matchlimit)
|
|
|
|
limit = matchlimit;
|
|
|
|
matchCode = LZ4_count(ip + MINMATCH,
|
2022-06-29 19:16:02 +02:00
|
|
|
match + MINMATCH, limit);
|
|
|
|
ip += (size_t)matchCode + MINMATCH;
|
2017-02-24 15:01:12 -08:00
|
|
|
if (ip == limit) {
|
2022-06-29 19:16:02 +02:00
|
|
|
unsigned const more = LZ4_count(
|
|
|
|
limit, (const BYTE *)source,
|
2017-02-24 15:01:12 -08:00
|
|
|
matchlimit);
|
|
|
|
matchCode += more;
|
|
|
|
ip += more;
|
|
|
|
}
|
2022-06-29 19:16:02 +02:00
|
|
|
DEBUGLOG(
|
|
|
|
6,
|
|
|
|
" with matchLength=%u starting in extDict",
|
|
|
|
matchCode + MINMATCH);
|
2017-02-24 15:01:12 -08:00
|
|
|
} else {
|
|
|
|
matchCode = LZ4_count(ip + MINMATCH,
|
2022-06-29 19:16:02 +02:00
|
|
|
match + MINMATCH,
|
|
|
|
matchlimit);
|
|
|
|
ip += (size_t)matchCode + MINMATCH;
|
|
|
|
DEBUGLOG(6, " with matchLength=%u",
|
|
|
|
matchCode + MINMATCH);
|
2013-07-08 16:01:49 -07:00
|
|
|
}
|
2017-02-24 15:01:12 -08:00
|
|
|
|
2022-06-29 19:16:02 +02:00
|
|
|
if ((outputDirective) && /* Check output buffer overflow */
|
|
|
|
(unlikely(op + (1 + LASTLITERALS) +
|
|
|
|
(matchCode + 240) / 255 >
|
|
|
|
olimit))) {
|
|
|
|
if (outputDirective == fillOutput) {
|
|
|
|
/* Match description too long : reduce it */
|
|
|
|
U32 newMatchCode =
|
|
|
|
15 /* in token */ -
|
|
|
|
1 /* to avoid needing a zero byte */ +
|
|
|
|
((U32)(olimit - op) - 1 -
|
|
|
|
LASTLITERALS) *
|
|
|
|
255;
|
|
|
|
ip -= matchCode - newMatchCode;
|
|
|
|
assert(newMatchCode < matchCode);
|
|
|
|
matchCode = newMatchCode;
|
|
|
|
if (unlikely(ip <= filledIp)) {
|
|
|
|
/* We have already filled up to filledIp so if ip ends up less than filledIp
|
|
|
|
* we have positions in the hash table beyond the current position. This is
|
|
|
|
* a problem if we reuse the hash table. So we have to remove these positions
|
|
|
|
* from the hash table.
|
|
|
|
*/
|
|
|
|
const BYTE *ptr;
|
|
|
|
DEBUGLOG(
|
|
|
|
5,
|
|
|
|
"Clearing %u positions",
|
|
|
|
(U32)(filledIp - ip));
|
|
|
|
for (ptr = ip; ptr <= filledIp;
|
|
|
|
++ptr) {
|
|
|
|
U32 const h =
|
|
|
|
LZ4_hashPosition(
|
|
|
|
ptr,
|
|
|
|
tableType);
|
|
|
|
LZ4_clearHash(
|
|
|
|
h,
|
|
|
|
cctx->hashTable,
|
|
|
|
tableType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
assert(outputDirective ==
|
|
|
|
limitedOutput);
|
|
|
|
return 0; /* cannot compress within `dst` budget. Stored indexes in hash table are nonetheless fine */
|
|
|
|
}
|
|
|
|
}
|
2017-02-24 15:01:12 -08:00
|
|
|
if (matchCode >= ML_MASK) {
|
|
|
|
*token += ML_MASK;
|
|
|
|
matchCode -= ML_MASK;
|
|
|
|
LZ4_write32(op, 0xFFFFFFFF);
|
|
|
|
while (matchCode >= 4 * 255) {
|
|
|
|
op += 4;
|
|
|
|
LZ4_write32(op, 0xFFFFFFFF);
|
|
|
|
matchCode -= 4 * 255;
|
|
|
|
}
|
|
|
|
op += matchCode / 255;
|
|
|
|
*op++ = (BYTE)(matchCode % 255);
|
|
|
|
} else
|
|
|
|
*token += (BYTE)(matchCode);
|
|
|
|
}
|
2022-06-29 19:16:02 +02:00
|
|
|
/* Ensure we have enough space for the last literals. */
|
|
|
|
assert(!(outputDirective == fillOutput &&
|
|
|
|
op + 1 + LASTLITERALS > olimit));
|
2017-02-24 15:01:12 -08:00
|
|
|
|
|
|
|
anchor = ip;
|
2013-07-08 16:01:49 -07:00
|
|
|
|
|
|
|
/* Test end of chunk */
|
2022-06-29 19:16:02 +02:00
|
|
|
if (ip >= mflimitPlusOne)
|
2013-07-08 16:01:49 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* Fill table */
|
2022-06-29 19:16:02 +02:00
|
|
|
LZ4_putPosition(ip - 2, cctx->hashTable, tableType, base);
|
2013-07-08 16:01:49 -07:00
|
|
|
|
|
|
|
/* Test next position */
|
2022-06-29 19:16:02 +02:00
|
|
|
if (tableType == byPtr) {
|
|
|
|
match = LZ4_getPosition(ip, cctx->hashTable, tableType,
|
|
|
|
base);
|
|
|
|
LZ4_putPosition(ip, cctx->hashTable, tableType, base);
|
|
|
|
if ((match + LZ4_DISTANCE_MAX >= ip) &&
|
|
|
|
(LZ4_read32(match) == LZ4_read32(ip))) {
|
|
|
|
token = op++;
|
|
|
|
*token = 0;
|
|
|
|
goto _next_match;
|
2017-02-24 15:01:12 -08:00
|
|
|
}
|
|
|
|
|
2022-06-29 19:16:02 +02:00
|
|
|
} else { /* byU32, byU16 */
|
|
|
|
|
|
|
|
U32 const h = LZ4_hashPosition(ip, tableType);
|
|
|
|
U32 const cur = (U32)(ip - base);
|
|
|
|
U32 matchIndex = LZ4_getIndexOnHash(h, cctx->hashTable,
|
|
|
|
tableType);
|
|
|
|
assert(matchIndex < cur);
|
|
|
|
if (dictDirective == usingDictCtx) {
|
|
|
|
if (matchIndex < startIndex) {
|
|
|
|
/* there was no match, try the dictionary */
|
|
|
|
matchIndex = LZ4_getIndexOnHash(
|
|
|
|
h, dictCtx->hashTable, byU32);
|
|
|
|
match = dictBase + matchIndex;
|
|
|
|
lowLimit =
|
|
|
|
dictionary; /* required for match length counter */
|
|
|
|
matchIndex += dictDelta;
|
|
|
|
} else {
|
|
|
|
match = base + matchIndex;
|
|
|
|
lowLimit = (const BYTE *)
|
|
|
|
source; /* required for match length counter */
|
|
|
|
}
|
|
|
|
} else if (dictDirective == usingExtDict) {
|
|
|
|
if (matchIndex < startIndex) {
|
|
|
|
assert(dictBase);
|
|
|
|
match = dictBase + matchIndex;
|
|
|
|
lowLimit =
|
|
|
|
dictionary; /* required for match length counter */
|
|
|
|
} else {
|
|
|
|
match = base + matchIndex;
|
|
|
|
lowLimit = (const BYTE *)
|
|
|
|
source; /* required for match length counter */
|
|
|
|
}
|
|
|
|
} else { /* single memory segment */
|
|
|
|
match = base + matchIndex;
|
|
|
|
}
|
|
|
|
LZ4_putIndexOnHash(cur, h, cctx->hashTable, tableType);
|
|
|
|
assert(matchIndex < cur);
|
|
|
|
if (((dictIssue == dictSmall) ?
|
|
|
|
(matchIndex >= prefixIdxLimit) :
|
|
|
|
1) &&
|
|
|
|
(((tableType == byU16) &&
|
|
|
|
(LZ4_DISTANCE_MAX == LZ4_DISTANCE_ABSOLUTE_MAX)) ?
|
|
|
|
1 :
|
|
|
|
(matchIndex + LZ4_DISTANCE_MAX >= cur)) &&
|
|
|
|
(LZ4_read32(match) == LZ4_read32(ip))) {
|
|
|
|
token = op++;
|
|
|
|
*token = 0;
|
|
|
|
if (maybe_extMem)
|
|
|
|
offset = cur - matchIndex;
|
|
|
|
DEBUGLOG(
|
|
|
|
6,
|
|
|
|
"seq.start:%i, literals=%u, match.start:%i",
|
|
|
|
(int)(anchor - (const BYTE *)source), 0,
|
|
|
|
(int)(ip - (const BYTE *)source));
|
|
|
|
goto _next_match;
|
|
|
|
}
|
2013-07-08 16:01:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Prepare next loop */
|
2017-02-24 15:01:12 -08:00
|
|
|
forwardH = LZ4_hashPosition(++ip, tableType);
|
2013-07-08 16:01:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
_last_literals:
|
|
|
|
/* Encode Last Literals */
|
2017-02-24 15:01:12 -08:00
|
|
|
{
|
2022-06-29 19:16:02 +02:00
|
|
|
size_t lastRun = (size_t)(iend - anchor);
|
|
|
|
if ((outputDirective) && /* Check output buffer overflow */
|
|
|
|
(op + lastRun + 1 + ((lastRun + 255 - RUN_MASK) / 255) >
|
|
|
|
olimit)) {
|
|
|
|
if (outputDirective == fillOutput) {
|
|
|
|
/* adapt lastRun to fill 'dst' */
|
|
|
|
assert(olimit >= op);
|
|
|
|
lastRun = (size_t)(olimit - op) - 1 /*token*/;
|
|
|
|
lastRun -= (lastRun + 256 - RUN_MASK) /
|
|
|
|
256; /*additional length tokens*/
|
|
|
|
} else {
|
|
|
|
assert(outputDirective == limitedOutput);
|
|
|
|
return 0; /* cannot compress within `dst` budget. Stored indexes in hash table are nonetheless fine */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DEBUGLOG(6, "Final literal run : %i literals", (int)lastRun);
|
2017-02-24 15:01:12 -08:00
|
|
|
if (lastRun >= RUN_MASK) {
|
|
|
|
size_t accumulator = lastRun - RUN_MASK;
|
|
|
|
*op++ = RUN_MASK << ML_BITS;
|
|
|
|
for (; accumulator >= 255; accumulator -= 255)
|
|
|
|
*op++ = 255;
|
2022-06-29 19:16:02 +02:00
|
|
|
*op++ = (BYTE)accumulator;
|
2017-02-24 15:01:12 -08:00
|
|
|
} else {
|
|
|
|
*op++ = (BYTE)(lastRun << ML_BITS);
|
|
|
|
}
|
2020-08-14 17:30:10 -07:00
|
|
|
LZ4_memcpy(op, anchor, lastRun);
|
2022-06-29 19:16:02 +02:00
|
|
|
ip = anchor + lastRun;
|
2017-02-24 15:01:12 -08:00
|
|
|
op += lastRun;
|
|
|
|
}
|
2013-07-08 16:01:49 -07:00
|
|
|
|
2022-06-29 19:16:02 +02:00
|
|
|
if (outputDirective == fillOutput) {
|
|
|
|
*inputConsumed = (int)(((const char *)ip) - source);
|
|
|
|
}
|
|
|
|
result = (int)(((char *)op) - dest);
|
|
|
|
assert(result > 0);
|
|
|
|
DEBUGLOG(5, "LZ4_compress_generic: compressed %i bytes into %i bytes",
|
|
|
|
inputSize, result);
|
|
|
|
return result;
|
2013-07-08 16:01:49 -07:00
|
|
|
}
|
|
|
|
|
2022-06-29 19:16:02 +02:00
|
|
|
/** LZ4_compress_generic() :
|
|
|
|
* inlined, to ensure branches are decided at compilation time;
|
|
|
|
* takes care of src == (NULL, 0)
|
|
|
|
* and forward the rest to LZ4_compress_generic_validated */
|
|
|
|
static FORCE_INLINE int LZ4_compress_generic(
|
|
|
|
LZ4_stream_t_internal *const cctx, const char *const src,
|
|
|
|
char *const dst, const int srcSize,
|
|
|
|
int *inputConsumed, /* only written when outputDirective == fillOutput */
|
|
|
|
const int dstCapacity, const limitedOutput_directive outputDirective,
|
|
|
|
const tableType_t tableType, const dict_directive dictDirective,
|
|
|
|
const dictIssue_directive dictIssue, const int acceleration)
|
2013-07-08 16:01:49 -07:00
|
|
|
{
|
2022-06-29 19:16:02 +02:00
|
|
|
DEBUGLOG(5, "LZ4_compress_generic: srcSize=%i, dstCapacity=%i", srcSize,
|
|
|
|
dstCapacity);
|
2013-07-08 16:01:49 -07:00
|
|
|
|
2022-06-29 19:16:02 +02:00
|
|
|
if ((U32)srcSize > (U32)LZ4_MAX_INPUT_SIZE) {
|
|
|
|
return 0;
|
|
|
|
} /* Unsupported srcSize, too large (or negative) */
|
|
|
|
if (srcSize == 0) { /* src == NULL supported if srcSize == 0 */
|
|
|
|
if (outputDirective != notLimited && dstCapacity <= 0)
|
|
|
|
return 0; /* no output, can't write anything */
|
|
|
|
DEBUGLOG(5, "Generating an empty block");
|
|
|
|
assert(outputDirective == notLimited || dstCapacity >= 1);
|
|
|
|
assert(dst != NULL);
|
|
|
|
dst[0] = 0;
|
|
|
|
if (outputDirective == fillOutput) {
|
|
|
|
assert(inputConsumed != NULL);
|
|
|
|
*inputConsumed = 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
assert(src != NULL);
|
|
|
|
|
|
|
|
return LZ4_compress_generic_validated(
|
|
|
|
cctx, src, dst, srcSize,
|
|
|
|
inputConsumed, /* only written into if outputDirective == fillOutput */
|
|
|
|
dstCapacity, outputDirective, tableType, dictDirective,
|
|
|
|
dictIssue, acceleration);
|
|
|
|
}
|
2017-02-24 15:01:12 -08:00
|
|
|
|
2022-06-29 19:16:02 +02:00
|
|
|
int LZ4_compress_fast_extState(void *state, const char *source, char *dest,
|
|
|
|
int inputSize, int maxOutputSize,
|
|
|
|
int acceleration)
|
|
|
|
{
|
|
|
|
LZ4_stream_t_internal *const ctx =
|
|
|
|
&LZ4_initStream(state, sizeof(LZ4_stream_t))->internal_donotuse;
|
|
|
|
assert(ctx != NULL);
|
2017-02-24 15:01:12 -08:00
|
|
|
if (acceleration < 1)
|
|
|
|
acceleration = LZ4_ACCELERATION_DEFAULT;
|
2022-06-29 19:16:02 +02:00
|
|
|
if (acceleration > LZ4_ACCELERATION_MAX)
|
|
|
|
acceleration = LZ4_ACCELERATION_MAX;
|
|
|
|
if (maxOutputSize >= LZ4_compressBound(inputSize)) {
|
|
|
|
if (inputSize < LZ4_64Klimit) {
|
|
|
|
return LZ4_compress_generic(ctx, source, dest,
|
|
|
|
inputSize, NULL, 0,
|
|
|
|
notLimited, byU16, noDict,
|
|
|
|
noDictIssue, acceleration);
|
|
|
|
} else {
|
|
|
|
const tableType_t tableType =
|
|
|
|
((sizeof(void *) == 4) &&
|
|
|
|
((uptrval)source > LZ4_DISTANCE_MAX)) ?
|
|
|
|
byPtr :
|
|
|
|
byU32;
|
|
|
|
return LZ4_compress_generic(ctx, source, dest,
|
|
|
|
inputSize, NULL, 0,
|
|
|
|
notLimited, tableType,
|
|
|
|
noDict, noDictIssue,
|
|
|
|
acceleration);
|
|
|
|
}
|
2017-02-24 15:01:12 -08:00
|
|
|
} else {
|
2022-06-29 19:16:02 +02:00
|
|
|
if (inputSize < LZ4_64Klimit) {
|
|
|
|
return LZ4_compress_generic(
|
|
|
|
ctx, source, dest, inputSize, NULL,
|
2017-02-24 15:01:12 -08:00
|
|
|
maxOutputSize, limitedOutput, byU16, noDict,
|
|
|
|
noDictIssue, acceleration);
|
2022-06-29 19:16:02 +02:00
|
|
|
} else {
|
|
|
|
const tableType_t tableType =
|
|
|
|
((sizeof(void *) == 4) &&
|
|
|
|
((uptrval)source > LZ4_DISTANCE_MAX)) ?
|
|
|
|
byPtr :
|
|
|
|
byU32;
|
|
|
|
return LZ4_compress_generic(
|
|
|
|
ctx, source, dest, inputSize, NULL,
|
2017-02-24 15:01:12 -08:00
|
|
|
maxOutputSize, limitedOutput, tableType, noDict,
|
|
|
|
noDictIssue, acceleration);
|
2022-06-29 19:16:02 +02:00
|
|
|
}
|
2017-02-24 15:01:12 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int LZ4_compress_fast(const char *source, char *dest, int inputSize,
|
2022-06-29 19:16:02 +02:00
|
|
|
int maxOutputSize, int acceleration, void *wrkmem)
|
2017-02-24 15:01:12 -08:00
|
|
|
{
|
|
|
|
return LZ4_compress_fast_extState(wrkmem, source, dest, inputSize,
|
2022-06-29 19:16:02 +02:00
|
|
|
maxOutputSize, acceleration);
|
2017-02-24 15:01:12 -08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(LZ4_compress_fast);
|
|
|
|
|
|
|
|
int LZ4_compress_default(const char *source, char *dest, int inputSize,
|
2022-06-29 19:16:02 +02:00
|
|
|
int maxOutputSize, void *wrkmem)
|
2017-02-24 15:01:12 -08:00
|
|
|
{
|
2022-06-29 19:16:02 +02:00
|
|
|
return LZ4_compress_fast(source, dest, inputSize, maxOutputSize,
|
|
|
|
LZ4_ACCELERATION_DEFAULT, wrkmem);
|
2017-02-24 15:01:12 -08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(LZ4_compress_default);
|
|
|
|
|
2022-06-29 19:16:02 +02:00
|
|
|
static int LZ4_compress_destSize_extState(LZ4_stream_t *state, const char *src,
|
|
|
|
char *dst, int *srcSizePtr,
|
|
|
|
int targetDstSize)
|
2017-02-24 15:01:12 -08:00
|
|
|
{
|
2022-06-29 19:16:02 +02:00
|
|
|
void *const s = LZ4_initStream(state, sizeof(*state));
|
|
|
|
assert(s != NULL);
|
|
|
|
(void)s;
|
|
|
|
|
|
|
|
if (targetDstSize >=
|
|
|
|
LZ4_compressBound(
|
|
|
|
*srcSizePtr)) { /* compression success is guaranteed */
|
|
|
|
return LZ4_compress_fast_extState(state, src, dst, *srcSizePtr,
|
|
|
|
targetDstSize, 1);
|
|
|
|
} else {
|
|
|
|
if (*srcSizePtr < LZ4_64Klimit) {
|
|
|
|
return LZ4_compress_generic(&state->internal_donotuse,
|
|
|
|
src, dst, *srcSizePtr,
|
|
|
|
srcSizePtr, targetDstSize,
|
|
|
|
fillOutput, byU16, noDict,
|
|
|
|
noDictIssue, 1);
|
2017-02-24 15:01:12 -08:00
|
|
|
} else {
|
2022-06-29 19:16:02 +02:00
|
|
|
tableType_t const addrMode =
|
|
|
|
((sizeof(void *) == 4) &&
|
|
|
|
((uptrval)src > LZ4_DISTANCE_MAX)) ?
|
|
|
|
byPtr :
|
|
|
|
byU32;
|
|
|
|
return LZ4_compress_generic(&state->internal_donotuse,
|
|
|
|
src, dst, *srcSizePtr,
|
|
|
|
srcSizePtr, targetDstSize,
|
|
|
|
fillOutput, addrMode,
|
|
|
|
noDict, noDictIssue, 1);
|
2017-02-24 15:01:12 -08:00
|
|
|
}
|
|
|
|
}
|
2013-07-08 16:01:49 -07:00
|
|
|
}
|
|
|
|
|
2022-06-29 19:16:02 +02:00
|
|
|
int LZ4_compress_destSize(const char *src, char *dst, int *srcSizePtr,
|
|
|
|
int targetDstSize, void *wrkmem)
|
2017-02-24 15:01:12 -08:00
|
|
|
{
|
|
|
|
return LZ4_compress_destSize_extState(wrkmem, src, dst, srcSizePtr,
|
2022-06-29 19:16:02 +02:00
|
|
|
targetDstSize);
|
2017-02-24 15:01:12 -08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(LZ4_compress_destSize);
|
|
|
|
|
|
|
|
/*-******************************
|
|
|
|
* Streaming functions
|
|
|
|
********************************/
|
2022-06-29 19:16:02 +02:00
|
|
|
static size_t LZ4_stream_t_alignment(void)
|
|
|
|
{
|
|
|
|
typedef struct {
|
|
|
|
char c;
|
|
|
|
LZ4_stream_t t;
|
|
|
|
} t_a;
|
|
|
|
return sizeof(t_a) - sizeof(LZ4_stream_t);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int LZ4_isAligned(const void *ptr, size_t alignment)
|
|
|
|
{
|
|
|
|
return ((size_t)ptr & (alignment - 1)) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LZ4_stream_t *LZ4_initStream(void *buffer, size_t size)
|
|
|
|
{
|
|
|
|
DEBUGLOG(5, "LZ4_initStream");
|
|
|
|
if (buffer == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (size < sizeof(LZ4_stream_t)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (!LZ4_isAligned(buffer, LZ4_stream_t_alignment()))
|
|
|
|
return NULL;
|
|
|
|
memset(buffer, 0, sizeof(LZ4_stream_t_internal));
|
|
|
|
return (LZ4_stream_t *)buffer;
|
|
|
|
}
|
|
|
|
|
2017-02-24 15:01:12 -08:00
|
|
|
void LZ4_resetStream(LZ4_stream_t *LZ4_stream)
|
|
|
|
{
|
2022-06-29 19:16:02 +02:00
|
|
|
memset(LZ4_stream, 0, sizeof(LZ4_stream_t_internal));
|
2017-02-24 15:01:12 -08:00
|
|
|
}
|
|
|
|
|
2022-06-29 19:16:02 +02:00
|
|
|
int LZ4_loadDict(LZ4_stream_t *LZ4_dict, const char *dictionary, int dictSize)
|
2017-02-24 15:01:12 -08:00
|
|
|
{
|
|
|
|
LZ4_stream_t_internal *dict = &LZ4_dict->internal_donotuse;
|
2022-06-29 19:16:02 +02:00
|
|
|
const tableType_t tableType = byU32;
|
2017-02-24 15:01:12 -08:00
|
|
|
const BYTE *p = (const BYTE *)dictionary;
|
2022-06-29 19:16:02 +02:00
|
|
|
const BYTE *const dictEnd = p + dictSize;
|
2017-02-24 15:01:12 -08:00
|
|
|
const BYTE *base;
|
|
|
|
|
2022-06-29 19:16:02 +02:00
|
|
|
DEBUGLOG(4, "LZ4_loadDict (%i bytes from %p into %p)", dictSize,
|
|
|
|
dictionary, LZ4_dict);
|
|
|
|
|
|
|
|
/* It's necessary to reset the context,
|
|
|
|
* and not just continue it with prepareTable()
|
|
|
|
* to avoid any risk of generating overflowing matchIndex
|
|
|
|
* when compressing using this dictionary */
|
|
|
|
LZ4_resetStream(LZ4_dict);
|
|
|
|
|
|
|
|
/* We always increment the offset by 64 KB, since, if the dict is longer,
|
|
|
|
* we truncate it to the last 64k, and if it's shorter, we still want to
|
|
|
|
* advance by a whole window length so we can provide the guarantee that
|
|
|
|
* there are only valid offsets in the window, which allows an optimization
|
|
|
|
* in LZ4_compress_fast_continue() where it uses noDictIssue even when the
|
|
|
|
* dictionary isn't a full 64k. */
|
|
|
|
dict->currentOffset += 64 * KB;
|
2017-02-24 15:01:12 -08:00
|
|
|
|
|
|
|
if (dictSize < (int)HASH_UNIT) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((dictEnd - p) > 64 * KB)
|
|
|
|
p = dictEnd - 64 * KB;
|
2022-06-29 19:16:02 +02:00
|
|
|
base = dictEnd - dict->currentOffset;
|
2017-02-24 15:01:12 -08:00
|
|
|
dict->dictionary = p;
|
|
|
|
dict->dictSize = (U32)(dictEnd - p);
|
2022-06-29 19:16:02 +02:00
|
|
|
dict->tableType = (U32)tableType;
|
2017-02-24 15:01:12 -08:00
|
|
|
|
|
|
|
while (p <= dictEnd - HASH_UNIT) {
|
2022-06-29 19:16:02 +02:00
|
|
|
LZ4_putPosition(p, dict->hashTable, tableType, base);
|
2017-02-24 15:01:12 -08:00
|
|
|
p += 3;
|
|
|
|
}
|
|
|
|
|
2022-06-29 19:16:02 +02:00
|
|
|
return (int)dict->dictSize;
|
2017-02-24 15:01:12 -08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(LZ4_loadDict);
|
|
|
|
|
2022-06-29 19:16:02 +02:00
|
|
|
static void LZ4_renormDictT(LZ4_stream_t_internal *LZ4_dict, int nextSize)
|
2017-02-24 15:01:12 -08:00
|
|
|
{
|
2022-06-29 19:16:02 +02:00
|
|
|
assert(nextSize >= 0);
|
|
|
|
if (LZ4_dict->currentOffset + (unsigned)nextSize >
|
|
|
|
0x80000000) { /* potential ptrdiff_t overflow (32-bits mode) */
|
2017-02-24 15:01:12 -08:00
|
|
|
/* rescale hash table */
|
|
|
|
U32 const delta = LZ4_dict->currentOffset - 64 * KB;
|
|
|
|
const BYTE *dictEnd = LZ4_dict->dictionary + LZ4_dict->dictSize;
|
|
|
|
int i;
|
2022-06-29 19:16:02 +02:00
|
|
|
DEBUGLOG(4, "LZ4_renormDictT");
|
2017-02-24 15:01:12 -08:00
|
|
|
for (i = 0; i < LZ4_HASH_SIZE_U32; i++) {
|
|
|
|
if (LZ4_dict->hashTable[i] < delta)
|
|
|
|
LZ4_dict->hashTable[i] = 0;
|
|
|
|
else
|
|
|
|
LZ4_dict->hashTable[i] -= delta;
|
|
|
|
}
|
|
|
|
LZ4_dict->currentOffset = 64 * KB;
|
|
|
|
if (LZ4_dict->dictSize > 64 * KB)
|
|
|
|
LZ4_dict->dictSize = 64 * KB;
|
|
|
|
LZ4_dict->dictionary = dictEnd - LZ4_dict->dictSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int LZ4_saveDict(LZ4_stream_t *LZ4_dict, char *safeBuffer, int dictSize)
|
|
|
|
{
|
2022-06-29 19:16:02 +02:00
|
|
|
LZ4_stream_t_internal *const dict = &LZ4_dict->internal_donotuse;
|
|
|
|
|
|
|
|
DEBUGLOG(5, "LZ4_saveDict : dictSize=%i, safeBuffer=%p", dictSize,
|
|
|
|
safeBuffer);
|
2017-02-24 15:01:12 -08:00
|
|
|
|
|
|
|
if ((U32)dictSize > 64 * KB) {
|
|
|
|
dictSize = 64 * KB;
|
2022-06-29 19:16:02 +02:00
|
|
|
} /* useless to define a dictionary > 64 KB */
|
|
|
|
if ((U32)dictSize > dict->dictSize) {
|
|
|
|
dictSize = (int)dict->dictSize;
|
2017-02-24 15:01:12 -08:00
|
|
|
}
|
|
|
|
|
2022-06-29 19:16:02 +02:00
|
|
|
if (safeBuffer == NULL)
|
|
|
|
assert(dictSize == 0);
|
|
|
|
if (dictSize > 0) {
|
|
|
|
const BYTE *const previousDictEnd =
|
|
|
|
dict->dictionary + dict->dictSize;
|
|
|
|
assert(dict->dictionary);
|
|
|
|
LZ4_memmove(safeBuffer, previousDictEnd - dictSize, dictSize);
|
|
|
|
}
|
2017-02-24 15:01:12 -08:00
|
|
|
|
|
|
|
dict->dictionary = (const BYTE *)safeBuffer;
|
|
|
|
dict->dictSize = (U32)dictSize;
|
|
|
|
|
|
|
|
return dictSize;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(LZ4_saveDict);
|
|
|
|
|
|
|
|
int LZ4_compress_fast_continue(LZ4_stream_t *LZ4_stream, const char *source,
|
2022-06-29 19:16:02 +02:00
|
|
|
char *dest, int inputSize, int maxOutputSize,
|
|
|
|
int acceleration)
|
2017-02-24 15:01:12 -08:00
|
|
|
{
|
2022-06-29 19:16:02 +02:00
|
|
|
const tableType_t tableType = byU32;
|
|
|
|
LZ4_stream_t_internal *const streamPtr = &LZ4_stream->internal_donotuse;
|
|
|
|
const char *dictEnd = streamPtr->dictSize ?
|
|
|
|
(const char *)streamPtr->dictionary +
|
|
|
|
streamPtr->dictSize :
|
|
|
|
NULL;
|
2017-02-24 15:01:12 -08:00
|
|
|
|
2022-06-29 19:16:02 +02:00
|
|
|
DEBUGLOG(5, "LZ4_compress_fast_continue (inputSize=%i, dictSize=%u)",
|
|
|
|
inputSize, streamPtr->dictSize);
|
2017-02-24 15:01:12 -08:00
|
|
|
|
2022-06-29 19:16:02 +02:00
|
|
|
LZ4_renormDictT(streamPtr, inputSize); /* fix index overflow */
|
2017-02-24 15:01:12 -08:00
|
|
|
if (acceleration < 1)
|
|
|
|
acceleration = LZ4_ACCELERATION_DEFAULT;
|
2022-06-29 19:16:02 +02:00
|
|
|
if (acceleration > LZ4_ACCELERATION_MAX)
|
|
|
|
acceleration = LZ4_ACCELERATION_MAX;
|
|
|
|
|
|
|
|
/* invalidate tiny dictionaries */
|
|
|
|
if ((streamPtr->dictSize <
|
|
|
|
4) /* tiny dictionary : not enough for a hash */
|
|
|
|
&& (dictEnd != source) /* prefix mode */
|
|
|
|
&&
|
|
|
|
(inputSize >
|
|
|
|
0) /* tolerance : don't lose history, in case next invocation would use prefix mode */
|
|
|
|
&& (streamPtr->dictCtx == NULL) /* usingDictCtx */
|
|
|
|
) {
|
|
|
|
DEBUGLOG(
|
|
|
|
5,
|
|
|
|
"LZ4_compress_fast_continue: dictSize(%u) at addr:%p is too small",
|
|
|
|
streamPtr->dictSize, streamPtr->dictionary);
|
|
|
|
/* remove dictionary existence from history, to employ faster prefix mode */
|
|
|
|
streamPtr->dictSize = 0;
|
|
|
|
streamPtr->dictionary = (const BYTE *)source;
|
|
|
|
dictEnd = source;
|
|
|
|
}
|
2013-07-08 16:01:49 -07:00
|
|
|
|
2017-02-24 15:01:12 -08:00
|
|
|
/* Check overlapping input/dictionary space */
|
|
|
|
{
|
2022-06-29 19:16:02 +02:00
|
|
|
const char *const sourceEnd = source + inputSize;
|
|
|
|
if ((sourceEnd > (const char *)streamPtr->dictionary) &&
|
|
|
|
(sourceEnd < dictEnd)) {
|
2017-02-24 15:01:12 -08:00
|
|
|
streamPtr->dictSize = (U32)(dictEnd - sourceEnd);
|
|
|
|
if (streamPtr->dictSize > 64 * KB)
|
|
|
|
streamPtr->dictSize = 64 * KB;
|
|
|
|
if (streamPtr->dictSize < 4)
|
|
|
|
streamPtr->dictSize = 0;
|
2022-06-29 19:16:02 +02:00
|
|
|
streamPtr->dictionary =
|
|
|
|
(const BYTE *)dictEnd - streamPtr->dictSize;
|
2017-02-24 15:01:12 -08:00
|
|
|
}
|
|
|
|
}
|
2013-07-08 16:01:49 -07:00
|
|
|
|
2017-02-24 15:01:12 -08:00
|
|
|
/* prefix mode : source data follows dictionary */
|
2022-06-29 19:16:02 +02:00
|
|
|
if (dictEnd == source) {
|
2017-02-24 15:01:12 -08:00
|
|
|
if ((streamPtr->dictSize < 64 * KB) &&
|
2022-06-29 19:16:02 +02:00
|
|
|
(streamPtr->dictSize < streamPtr->currentOffset))
|
|
|
|
return LZ4_compress_generic(
|
|
|
|
streamPtr, source, dest, inputSize, NULL,
|
|
|
|
maxOutputSize, limitedOutput, tableType,
|
2017-02-24 15:01:12 -08:00
|
|
|
withPrefix64k, dictSmall, acceleration);
|
2022-06-29 19:16:02 +02:00
|
|
|
else
|
|
|
|
return LZ4_compress_generic(
|
|
|
|
streamPtr, source, dest, inputSize, NULL,
|
|
|
|
maxOutputSize, limitedOutput, tableType,
|
2017-02-24 15:01:12 -08:00
|
|
|
withPrefix64k, noDictIssue, acceleration);
|
|
|
|
}
|
2013-07-08 16:01:49 -07:00
|
|
|
|
2017-02-24 15:01:12 -08:00
|
|
|
/* external dictionary mode */
|
|
|
|
{
|
|
|
|
int result;
|
2022-06-29 19:16:02 +02:00
|
|
|
if (streamPtr->dictCtx) {
|
|
|
|
/* We depend here on the fact that dictCtx'es (produced by
|
|
|
|
* LZ4_loadDict) guarantee that their tables contain no references
|
|
|
|
* to offsets between dictCtx->currentOffset - 64 KB and
|
|
|
|
* dictCtx->currentOffset - dictCtx->dictSize. This makes it safe
|
|
|
|
* to use noDictIssue even when the dict isn't a full 64 KB.
|
|
|
|
*/
|
|
|
|
if (inputSize > 4 * KB) {
|
|
|
|
/* For compressing large blobs, it is faster to pay the setup
|
|
|
|
* cost to copy the dictionary's tables into the active context,
|
|
|
|
* so that the compression loop is only looking into one table.
|
|
|
|
*/
|
|
|
|
LZ4_memcpy(streamPtr, streamPtr->dictCtx,
|
|
|
|
sizeof(*streamPtr));
|
|
|
|
result = LZ4_compress_generic(
|
|
|
|
streamPtr, source, dest, inputSize,
|
|
|
|
NULL, maxOutputSize, limitedOutput,
|
|
|
|
tableType, usingExtDict, noDictIssue,
|
|
|
|
acceleration);
|
|
|
|
} else {
|
|
|
|
result = LZ4_compress_generic(
|
|
|
|
streamPtr, source, dest, inputSize,
|
|
|
|
NULL, maxOutputSize, limitedOutput,
|
|
|
|
tableType, usingDictCtx, noDictIssue,
|
|
|
|
acceleration);
|
|
|
|
}
|
|
|
|
} else { /* small data <= 4 KB */
|
|
|
|
if ((streamPtr->dictSize < 64 * KB) &&
|
|
|
|
(streamPtr->dictSize < streamPtr->currentOffset)) {
|
|
|
|
result = LZ4_compress_generic(
|
|
|
|
streamPtr, source, dest, inputSize,
|
|
|
|
NULL, maxOutputSize, limitedOutput,
|
|
|
|
tableType, usingExtDict, dictSmall,
|
|
|
|
acceleration);
|
|
|
|
} else {
|
|
|
|
result = LZ4_compress_generic(
|
|
|
|
streamPtr, source, dest, inputSize,
|
|
|
|
NULL, maxOutputSize, limitedOutput,
|
|
|
|
tableType, usingExtDict, noDictIssue,
|
|
|
|
acceleration);
|
|
|
|
}
|
2017-02-24 15:01:12 -08:00
|
|
|
}
|
|
|
|
streamPtr->dictionary = (const BYTE *)source;
|
|
|
|
streamPtr->dictSize = (U32)inputSize;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(LZ4_compress_fast_continue);
|
|
|
|
|
|
|
|
/*-******************************
|
|
|
|
* For backwards compatibility
|
|
|
|
********************************/
|
|
|
|
int lz4_compress(const unsigned char *src, size_t src_len, unsigned char *dst,
|
|
|
|
size_t *dst_len, void *wrkmem) {
|
|
|
|
*dst_len = LZ4_compress_default(src, dst, src_len,
|
2017-08-14 21:31:19 -07:00
|
|
|
LZ4_COMPRESSBOUND(src_len), wrkmem);
|
2017-02-24 15:01:12 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Prior lz4_compress will return -1 in case of error
|
|
|
|
* and 0 on success
|
|
|
|
* while new LZ4_compress_fast/default
|
|
|
|
* returns 0 in case of error
|
|
|
|
* and the output length on success
|
|
|
|
*/
|
|
|
|
if (!*dst_len)
|
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return 0;
|
2013-07-08 16:01:49 -07:00
|
|
|
}
|
2013-08-22 16:35:47 -07:00
|
|
|
EXPORT_SYMBOL(lz4_compress);
|
2013-07-08 16:01:49 -07:00
|
|
|
|
2013-08-22 16:35:47 -07:00
|
|
|
MODULE_LICENSE("Dual BSD/GPL");
|
2013-07-08 16:01:49 -07:00
|
|
|
MODULE_DESCRIPTION("LZ4 compressor");
|