^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * LZ4 - Fast LZ compression algorithm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2011 - 2016, Yann Collet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * BSD 2 - Clause License (http://www.opensource.org/licenses/bsd - license.php)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Redistribution and use in source and binary forms, with or without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * modification, are permitted provided that the following conditions are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * met:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * * Redistributions of source code must retain the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * notice, this list of conditions and the following disclaimer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * * Redistributions in binary form must reproduce the above
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * copyright notice, this list of conditions and the following disclaimer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * in the documentation and/or other materials provided with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * distribution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * You can contact the author at :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * - LZ4 homepage : http://www.lz4.org
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * - LZ4 source repository : https://github.com/lz4/lz4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * Changed for kernel usage by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * Sven Schmidt <4sschmid@informatik.uni-hamburg.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /*-************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * Dependencies
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) **************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/lz4.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include "lz4defs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static const int LZ4_minLength = (MFLIMIT + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static const int LZ4_64Klimit = ((64 * KB) + (MFLIMIT - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) /*-******************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * Compression functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) ********************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static FORCE_INLINE U32 LZ4_hash4(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) U32 sequence,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) tableType_t const tableType)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) if (tableType == byU16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) return ((sequence * 2654435761U)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) >> ((MINMATCH * 8) - (LZ4_HASHLOG + 1)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) return ((sequence * 2654435761U)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) >> ((MINMATCH * 8) - LZ4_HASHLOG));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static FORCE_INLINE U32 LZ4_hash5(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) U64 sequence,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) tableType_t const tableType)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) const U32 hashLog = (tableType == byU16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) ? LZ4_HASHLOG + 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) : LZ4_HASHLOG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #if LZ4_LITTLE_ENDIAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) static const U64 prime5bytes = 889523592379ULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) return (U32)(((sequence << 24) * prime5bytes) >> (64 - hashLog));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static const U64 prime8bytes = 11400714785074694791ULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) return (U32)(((sequence >> 24) * prime8bytes) >> (64 - hashLog));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) static FORCE_INLINE U32 LZ4_hashPosition(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) const void *p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) tableType_t const tableType)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) #if LZ4_ARCH64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) if (tableType == byU32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return LZ4_hash5(LZ4_read_ARCH(p), tableType);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) return LZ4_hash4(LZ4_read32(p), tableType);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) static void LZ4_putPositionOnHash(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) const BYTE *p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) U32 h,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) void *tableBase,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) tableType_t const tableType,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) const BYTE *srcBase)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) switch (tableType) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) case byPtr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) const BYTE **hashTable = (const BYTE **)tableBase;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) hashTable[h] = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) case byU32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) U32 *hashTable = (U32 *) tableBase;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) hashTable[h] = (U32)(p - srcBase);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) case byU16:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) U16 *hashTable = (U16 *) tableBase;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) hashTable[h] = (U16)(p - srcBase);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static FORCE_INLINE void LZ4_putPosition(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) const BYTE *p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) void *tableBase,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) tableType_t tableType,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) const BYTE *srcBase)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) U32 const h = LZ4_hashPosition(p, tableType);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) LZ4_putPositionOnHash(p, h, tableBase, tableType, srcBase);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static const BYTE *LZ4_getPositionOnHash(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) U32 h,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) void *tableBase,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) tableType_t tableType,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) const BYTE *srcBase)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) if (tableType == byPtr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) const BYTE **hashTable = (const BYTE **) tableBase;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) return hashTable[h];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) if (tableType == byU32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) const U32 * const hashTable = (U32 *) tableBase;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) return hashTable[h] + srcBase;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) /* default, to ensure a return */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) const U16 * const hashTable = (U16 *) tableBase;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) return hashTable[h] + srcBase;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) static FORCE_INLINE const BYTE *LZ4_getPosition(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) const BYTE *p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) void *tableBase,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) tableType_t tableType,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) const BYTE *srcBase)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) U32 const h = LZ4_hashPosition(p, tableType);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) return LZ4_getPositionOnHash(h, tableBase, tableType, srcBase);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * LZ4_compress_generic() :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * inlined, to ensure branches are decided at compilation time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) static FORCE_INLINE int LZ4_compress_generic(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) LZ4_stream_t_internal * const dictPtr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) const char * const source,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) char * const dest,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) const int inputSize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) const int maxOutputSize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) const limitedOutput_directive outputLimited,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) const tableType_t tableType,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) const dict_directive dict,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) const dictIssue_directive dictIssue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) const U32 acceleration)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) const BYTE *ip = (const BYTE *) source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) const BYTE *base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) const BYTE *lowLimit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) const BYTE * const lowRefLimit = ip - dictPtr->dictSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) const BYTE * const dictionary = dictPtr->dictionary;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) const BYTE * const dictEnd = dictionary + dictPtr->dictSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) const size_t dictDelta = dictEnd - (const BYTE *)source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) const BYTE *anchor = (const BYTE *) source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) const BYTE * const iend = ip + inputSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) const BYTE * const mflimit = iend - MFLIMIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) const BYTE * const matchlimit = iend - LASTLITERALS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) BYTE *op = (BYTE *) dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) BYTE * const olimit = op + maxOutputSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) U32 forwardH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) size_t refDelta = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) /* Init conditions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) if ((U32)inputSize > (U32)LZ4_MAX_INPUT_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) /* Unsupported inputSize, too large (or negative) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) switch (dict) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) case noDict:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) base = (const BYTE *)source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) lowLimit = (const BYTE *)source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) case withPrefix64k:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) base = (const BYTE *)source - dictPtr->currentOffset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) lowLimit = (const BYTE *)source - dictPtr->dictSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) case usingExtDict:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) base = (const BYTE *)source - dictPtr->currentOffset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) lowLimit = (const BYTE *)source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) if ((tableType == byU16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) && (inputSize >= LZ4_64Klimit)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) /* Size too large (not within 64K limit) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) if (inputSize < LZ4_minLength) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) /* Input too small, no compression (all literals) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) goto _last_literals;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) /* First Byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) LZ4_putPosition(ip, dictPtr->hashTable, tableType, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) ip++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) forwardH = LZ4_hashPosition(ip, tableType);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) /* Main Loop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) for ( ; ; ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) const BYTE *match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) BYTE *token;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) /* Find a match */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) const BYTE *forwardIp = ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) unsigned int step = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) unsigned int searchMatchNb = acceleration << LZ4_SKIPTRIGGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) U32 const h = forwardH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) ip = forwardIp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) forwardIp += step;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) step = (searchMatchNb++ >> LZ4_SKIPTRIGGER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) if (unlikely(forwardIp > mflimit))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) goto _last_literals;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) match = LZ4_getPositionOnHash(h,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) dictPtr->hashTable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) tableType, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) if (dict == usingExtDict) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) if (match < (const BYTE *)source) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) refDelta = dictDelta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) lowLimit = dictionary;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) refDelta = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) lowLimit = (const BYTE *)source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) } }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) forwardH = LZ4_hashPosition(forwardIp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) tableType);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) LZ4_putPositionOnHash(ip, h, dictPtr->hashTable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) tableType, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) } while (((dictIssue == dictSmall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) ? (match < lowRefLimit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) : 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) || ((tableType == byU16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) ? 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) : (match + MAX_DISTANCE < ip))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) || (LZ4_read32(match + refDelta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) != LZ4_read32(ip)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) /* Catch up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) while (((ip > anchor) & (match + refDelta > lowLimit))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) && (unlikely(ip[-1] == match[refDelta - 1]))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) ip--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) match--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) /* Encode Literals */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) unsigned const int litLength = (unsigned int)(ip - anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) token = op++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) if ((outputLimited) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) /* Check output buffer overflow */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) (unlikely(op + litLength +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) (2 + 1 + LASTLITERALS) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) (litLength / 255) > olimit)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) if (litLength >= RUN_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) int len = (int)litLength - RUN_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) *token = (RUN_MASK << ML_BITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) for (; len >= 255; len -= 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) *op++ = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) *op++ = (BYTE)len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) *token = (BYTE)(litLength << ML_BITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) /* Copy Literals */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) LZ4_wildCopy(op, anchor, op + litLength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) op += litLength;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) _next_match:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) /* Encode Offset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) LZ4_writeLE16(op, (U16)(ip - match));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) op += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) /* Encode MatchLength */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) unsigned int matchCode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) if ((dict == usingExtDict)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) && (lowLimit == dictionary)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) const BYTE *limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) match += refDelta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) limit = ip + (dictEnd - match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) if (limit > matchlimit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) limit = matchlimit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) matchCode = LZ4_count(ip + MINMATCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) match + MINMATCH, limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) ip += MINMATCH + matchCode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) if (ip == limit) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) unsigned const int more = LZ4_count(ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) (const BYTE *)source,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) matchlimit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) matchCode += more;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) ip += more;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) matchCode = LZ4_count(ip + MINMATCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) match + MINMATCH, matchlimit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) ip += MINMATCH + matchCode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) if (outputLimited &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) /* Check output buffer overflow */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) (unlikely(op +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) (1 + LASTLITERALS) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) (matchCode >> 8) > olimit)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) if (matchCode >= ML_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) *token += ML_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) matchCode -= ML_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) LZ4_write32(op, 0xFFFFFFFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) while (matchCode >= 4 * 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) op += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) LZ4_write32(op, 0xFFFFFFFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) matchCode -= 4 * 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) op += matchCode / 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) *op++ = (BYTE)(matchCode % 255);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) *token += (BYTE)(matchCode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) anchor = ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) /* Test end of chunk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) if (ip > mflimit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) /* Fill table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) LZ4_putPosition(ip - 2, dictPtr->hashTable, tableType, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) /* Test next position */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) match = LZ4_getPosition(ip, dictPtr->hashTable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) tableType, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) if (dict == usingExtDict) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) if (match < (const BYTE *)source) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) refDelta = dictDelta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) lowLimit = dictionary;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) refDelta = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) lowLimit = (const BYTE *)source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) LZ4_putPosition(ip, dictPtr->hashTable, tableType, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) if (((dictIssue == dictSmall) ? (match >= lowRefLimit) : 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) && (match + MAX_DISTANCE >= ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) && (LZ4_read32(match + refDelta) == LZ4_read32(ip))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) token = op++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) *token = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) goto _next_match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) /* Prepare next loop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) forwardH = LZ4_hashPosition(++ip, tableType);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) _last_literals:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) /* Encode Last Literals */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) size_t const lastRun = (size_t)(iend - anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) if ((outputLimited) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) /* Check output buffer overflow */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) ((op - (BYTE *)dest) + lastRun + 1 +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) ((lastRun + 255 - RUN_MASK) / 255) > (U32)maxOutputSize))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) if (lastRun >= RUN_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) size_t accumulator = lastRun - RUN_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) *op++ = RUN_MASK << ML_BITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) for (; accumulator >= 255; accumulator -= 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) *op++ = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) *op++ = (BYTE) accumulator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) *op++ = (BYTE)(lastRun << ML_BITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) LZ4_memcpy(op, anchor, lastRun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) op += lastRun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) /* End */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) return (int) (((char *)op) - dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) static int LZ4_compress_fast_extState(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) void *state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) const char *source,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) char *dest,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) int inputSize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) int maxOutputSize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) int acceleration)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) LZ4_stream_t_internal *ctx = &((LZ4_stream_t *)state)->internal_donotuse;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) #if LZ4_ARCH64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) const tableType_t tableType = byU32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) const tableType_t tableType = byPtr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) LZ4_resetStream((LZ4_stream_t *)state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) if (acceleration < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) acceleration = LZ4_ACCELERATION_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) if (maxOutputSize >= LZ4_COMPRESSBOUND(inputSize)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) if (inputSize < LZ4_64Klimit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) return LZ4_compress_generic(ctx, source,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) dest, inputSize, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) noLimit, byU16, noDict,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) noDictIssue, acceleration);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) return LZ4_compress_generic(ctx, source,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) dest, inputSize, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) noLimit, tableType, noDict,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) noDictIssue, acceleration);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) if (inputSize < LZ4_64Klimit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) return LZ4_compress_generic(ctx, source,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) dest, inputSize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) maxOutputSize, limitedOutput, byU16, noDict,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) noDictIssue, acceleration);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) return LZ4_compress_generic(ctx, source,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) dest, inputSize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) maxOutputSize, limitedOutput, tableType, noDict,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) noDictIssue, acceleration);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) int LZ4_compress_fast(const char *source, char *dest, int inputSize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) int maxOutputSize, int acceleration, void *wrkmem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) return LZ4_compress_fast_extState(wrkmem, source, dest, inputSize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) maxOutputSize, acceleration);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) EXPORT_SYMBOL(LZ4_compress_fast);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) int LZ4_compress_default(const char *source, char *dest, int inputSize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) int maxOutputSize, void *wrkmem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) return LZ4_compress_fast(source, dest, inputSize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) maxOutputSize, LZ4_ACCELERATION_DEFAULT, wrkmem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) EXPORT_SYMBOL(LZ4_compress_default);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) /*-******************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) * *_destSize() variant
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) ********************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) static int LZ4_compress_destSize_generic(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) LZ4_stream_t_internal * const ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) const char * const src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) char * const dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) int * const srcSizePtr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) const int targetDstSize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) const tableType_t tableType)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) const BYTE *ip = (const BYTE *) src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) const BYTE *base = (const BYTE *) src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) const BYTE *lowLimit = (const BYTE *) src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) const BYTE *anchor = ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) const BYTE * const iend = ip + *srcSizePtr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) const BYTE * const mflimit = iend - MFLIMIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) const BYTE * const matchlimit = iend - LASTLITERALS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) BYTE *op = (BYTE *) dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) BYTE * const oend = op + targetDstSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) BYTE * const oMaxLit = op + targetDstSize - 2 /* offset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) - 8 /* because 8 + MINMATCH == MFLIMIT */ - 1 /* token */;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) BYTE * const oMaxMatch = op + targetDstSize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) - (LASTLITERALS + 1 /* token */);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) BYTE * const oMaxSeq = oMaxLit - 1 /* token */;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) U32 forwardH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) /* Init conditions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) /* Impossible to store anything */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) if (targetDstSize < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) /* Unsupported input size, too large (or negative) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) if ((U32)*srcSizePtr > (U32)LZ4_MAX_INPUT_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) /* Size too large (not within 64K limit) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) if ((tableType == byU16) && (*srcSizePtr >= LZ4_64Klimit))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) /* Input too small, no compression (all literals) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) if (*srcSizePtr < LZ4_minLength)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) goto _last_literals;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) /* First Byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) *srcSizePtr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) LZ4_putPosition(ip, ctx->hashTable, tableType, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) ip++; forwardH = LZ4_hashPosition(ip, tableType);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) /* Main Loop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) for ( ; ; ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) const BYTE *match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) BYTE *token;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) /* Find a match */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) const BYTE *forwardIp = ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) unsigned int step = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) unsigned int searchMatchNb = 1 << LZ4_SKIPTRIGGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) U32 h = forwardH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) ip = forwardIp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) forwardIp += step;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) step = (searchMatchNb++ >> LZ4_SKIPTRIGGER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) if (unlikely(forwardIp > mflimit))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) goto _last_literals;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) match = LZ4_getPositionOnHash(h, ctx->hashTable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) tableType, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) forwardH = LZ4_hashPosition(forwardIp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) tableType);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) LZ4_putPositionOnHash(ip, h,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) ctx->hashTable, tableType,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) } while (((tableType == byU16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) ? 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) : (match + MAX_DISTANCE < ip))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) || (LZ4_read32(match) != LZ4_read32(ip)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) /* Catch up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) while ((ip > anchor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) && (match > lowLimit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) && (unlikely(ip[-1] == match[-1]))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) ip--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) match--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) /* Encode Literal length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) unsigned int litLength = (unsigned int)(ip - anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) token = op++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) if (op + ((litLength + 240) / 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) + litLength > oMaxLit) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) /* Not enough space for a last match */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) op--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) goto _last_literals;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) if (litLength >= RUN_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) unsigned int len = litLength - RUN_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) *token = (RUN_MASK<<ML_BITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) for (; len >= 255; len -= 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) *op++ = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) *op++ = (BYTE)len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) *token = (BYTE)(litLength << ML_BITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) /* Copy Literals */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) LZ4_wildCopy(op, anchor, op + litLength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) op += litLength;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) _next_match:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) /* Encode Offset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) LZ4_writeLE16(op, (U16)(ip - match)); op += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) /* Encode MatchLength */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) size_t matchLength = LZ4_count(ip + MINMATCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) match + MINMATCH, matchlimit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) if (op + ((matchLength + 240)/255) > oMaxMatch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) /* Match description too long : reduce it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) matchLength = (15 - 1) + (oMaxMatch - op) * 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) ip += MINMATCH + matchLength;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) if (matchLength >= ML_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) *token += ML_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) matchLength -= ML_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) while (matchLength >= 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) matchLength -= 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) *op++ = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) *op++ = (BYTE)matchLength;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) *token += (BYTE)(matchLength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) anchor = ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) /* Test end of block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) if (ip > mflimit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) if (op > oMaxSeq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) /* Fill table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) LZ4_putPosition(ip - 2, ctx->hashTable, tableType, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) /* Test next position */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) match = LZ4_getPosition(ip, ctx->hashTable, tableType, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) LZ4_putPosition(ip, ctx->hashTable, tableType, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) if ((match + MAX_DISTANCE >= ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) && (LZ4_read32(match) == LZ4_read32(ip))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) token = op++; *token = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) goto _next_match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) /* Prepare next loop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) forwardH = LZ4_hashPosition(++ip, tableType);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) _last_literals:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) /* Encode Last Literals */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) size_t lastRunSize = (size_t)(iend - anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) if (op + 1 /* token */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) + ((lastRunSize + 240) / 255) /* litLength */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) + lastRunSize /* literals */ > oend) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) /* adapt lastRunSize to fill 'dst' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) lastRunSize = (oend - op) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) lastRunSize -= (lastRunSize + 240) / 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) ip = anchor + lastRunSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) if (lastRunSize >= RUN_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) size_t accumulator = lastRunSize - RUN_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) *op++ = RUN_MASK << ML_BITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) for (; accumulator >= 255; accumulator -= 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) *op++ = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) *op++ = (BYTE) accumulator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) *op++ = (BYTE)(lastRunSize<<ML_BITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) LZ4_memcpy(op, anchor, lastRunSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) op += lastRunSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) /* End */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) *srcSizePtr = (int) (((const char *)ip) - src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) return (int) (((char *)op) - dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) static int LZ4_compress_destSize_extState(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) LZ4_stream_t *state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) const char *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) char *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) int *srcSizePtr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) int targetDstSize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) #if LZ4_ARCH64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) const tableType_t tableType = byU32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) const tableType_t tableType = byPtr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) LZ4_resetStream(state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) if (targetDstSize >= LZ4_COMPRESSBOUND(*srcSizePtr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) /* compression success is guaranteed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) return LZ4_compress_fast_extState(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) state, src, dst, *srcSizePtr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) targetDstSize, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) if (*srcSizePtr < LZ4_64Klimit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) return LZ4_compress_destSize_generic(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) &state->internal_donotuse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) src, dst, srcSizePtr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) targetDstSize, byU16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) return LZ4_compress_destSize_generic(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) &state->internal_donotuse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) src, dst, srcSizePtr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) targetDstSize, tableType);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) int LZ4_compress_destSize(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) const char *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) char *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) int *srcSizePtr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) int targetDstSize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) void *wrkmem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) return LZ4_compress_destSize_extState(wrkmem, src, dst, srcSizePtr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) targetDstSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) EXPORT_SYMBOL(LZ4_compress_destSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) /*-******************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) * Streaming functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) ********************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) void LZ4_resetStream(LZ4_stream_t *LZ4_stream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) memset(LZ4_stream, 0, sizeof(LZ4_stream_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) int LZ4_loadDict(LZ4_stream_t *LZ4_dict,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) const char *dictionary, int dictSize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) LZ4_stream_t_internal *dict = &LZ4_dict->internal_donotuse;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) const BYTE *p = (const BYTE *)dictionary;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) const BYTE * const dictEnd = p + dictSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) const BYTE *base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) if ((dict->initCheck)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) || (dict->currentOffset > 1 * GB)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) /* Uninitialized structure, or reuse overflow */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) LZ4_resetStream(LZ4_dict);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) if (dictSize < (int)HASH_UNIT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) dict->dictionary = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) dict->dictSize = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) if ((dictEnd - p) > 64 * KB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) p = dictEnd - 64 * KB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) dict->currentOffset += 64 * KB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) base = p - dict->currentOffset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) dict->dictionary = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) dict->dictSize = (U32)(dictEnd - p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) dict->currentOffset += dict->dictSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) while (p <= dictEnd - HASH_UNIT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) LZ4_putPosition(p, dict->hashTable, byU32, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) p += 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) return dict->dictSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) EXPORT_SYMBOL(LZ4_loadDict);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) static void LZ4_renormDictT(LZ4_stream_t_internal *LZ4_dict,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) const BYTE *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) if ((LZ4_dict->currentOffset > 0x80000000) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) ((uptrval)LZ4_dict->currentOffset > (uptrval)src)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) /* address space overflow */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) /* rescale hash table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) U32 const delta = LZ4_dict->currentOffset - 64 * KB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) const BYTE *dictEnd = LZ4_dict->dictionary + LZ4_dict->dictSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) for (i = 0; i < LZ4_HASH_SIZE_U32; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) if (LZ4_dict->hashTable[i] < delta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) LZ4_dict->hashTable[i] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) LZ4_dict->hashTable[i] -= delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) LZ4_dict->currentOffset = 64 * KB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) if (LZ4_dict->dictSize > 64 * KB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) LZ4_dict->dictSize = 64 * KB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) LZ4_dict->dictionary = dictEnd - LZ4_dict->dictSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) int LZ4_saveDict(LZ4_stream_t *LZ4_dict, char *safeBuffer, int dictSize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) LZ4_stream_t_internal * const dict = &LZ4_dict->internal_donotuse;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) const BYTE * const previousDictEnd = dict->dictionary + dict->dictSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) if ((U32)dictSize > 64 * KB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) /* useless to define a dictionary > 64 * KB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) dictSize = 64 * KB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) if ((U32)dictSize > dict->dictSize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) dictSize = dict->dictSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) memmove(safeBuffer, previousDictEnd - dictSize, dictSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) dict->dictionary = (const BYTE *)safeBuffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) dict->dictSize = (U32)dictSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) return dictSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) EXPORT_SYMBOL(LZ4_saveDict);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) int LZ4_compress_fast_continue(LZ4_stream_t *LZ4_stream, const char *source,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) char *dest, int inputSize, int maxOutputSize, int acceleration)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) LZ4_stream_t_internal *streamPtr = &LZ4_stream->internal_donotuse;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) const BYTE * const dictEnd = streamPtr->dictionary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) + streamPtr->dictSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) const BYTE *smallest = (const BYTE *) source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) if (streamPtr->initCheck) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) /* Uninitialized structure detected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) if ((streamPtr->dictSize > 0) && (smallest > dictEnd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) smallest = dictEnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) LZ4_renormDictT(streamPtr, smallest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) if (acceleration < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) acceleration = LZ4_ACCELERATION_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) /* Check overlapping input/dictionary space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) const BYTE *sourceEnd = (const BYTE *) source + inputSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) if ((sourceEnd > streamPtr->dictionary)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) && (sourceEnd < dictEnd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) streamPtr->dictSize = (U32)(dictEnd - sourceEnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) if (streamPtr->dictSize > 64 * KB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) streamPtr->dictSize = 64 * KB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) if (streamPtr->dictSize < 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) streamPtr->dictSize = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) streamPtr->dictionary = dictEnd - streamPtr->dictSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) /* prefix mode : source data follows dictionary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) if (dictEnd == (const BYTE *)source) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) if ((streamPtr->dictSize < 64 * KB) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) (streamPtr->dictSize < streamPtr->currentOffset)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) result = LZ4_compress_generic(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) streamPtr, source, dest, inputSize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) maxOutputSize, limitedOutput, byU32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) withPrefix64k, dictSmall, acceleration);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) result = LZ4_compress_generic(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) streamPtr, source, dest, inputSize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) maxOutputSize, limitedOutput, byU32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) withPrefix64k, noDictIssue, acceleration);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) streamPtr->dictSize += (U32)inputSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) streamPtr->currentOffset += (U32)inputSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) /* external dictionary mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) if ((streamPtr->dictSize < 64 * KB) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) (streamPtr->dictSize < streamPtr->currentOffset)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) result = LZ4_compress_generic(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) streamPtr, source, dest, inputSize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) maxOutputSize, limitedOutput, byU32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) usingExtDict, dictSmall, acceleration);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) result = LZ4_compress_generic(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) streamPtr, source, dest, inputSize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) maxOutputSize, limitedOutput, byU32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) usingExtDict, noDictIssue, acceleration);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) streamPtr->dictionary = (const BYTE *)source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) streamPtr->dictSize = (U32)inputSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) streamPtr->currentOffset += (U32)inputSize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) EXPORT_SYMBOL(LZ4_compress_fast_continue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) MODULE_LICENSE("Dual BSD/GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) MODULE_DESCRIPTION("LZ4 compressor");