|
|
f143d5 |
diff -Naur kvdo-127a993f34010e4d8b05e46c4af2a9295c4477d0.orig/vdo/lz4_compress.c kvdo-127a993f34010e4d8b05e46c4af2a9295c4477d0/vdo/lz4_compress.c
|
|
|
f143d5 |
--- kvdo-127a993f34010e4d8b05e46c4af2a9295c4477d0.orig/vdo/lz4_compress.c 1969-12-31 19:00:00.000000000 -0500
|
|
|
f143d5 |
+++ kvdo-127a993f34010e4d8b05e46c4af2a9295c4477d0/vdo/lz4_compress.c 2022-07-27 21:39:51.288835411 -0400
|
|
|
f143d5 |
@@ -0,0 +1,940 @@
|
|
|
f143d5 |
+/*
|
|
|
f143d5 |
+ * LZ4 - Fast LZ compression algorithm
|
|
|
f143d5 |
+ * Copyright (C) 2011 - 2016, Yann Collet.
|
|
|
f143d5 |
+ * BSD 2 - Clause License (http://www.opensource.org/licenses/bsd - license.php)
|
|
|
f143d5 |
+ * Redistribution and use in source and binary forms, with or without
|
|
|
f143d5 |
+ * modification, are permitted provided that the following conditions are
|
|
|
f143d5 |
+ * met:
|
|
|
f143d5 |
+ * * Redistributions of source code must retain the above copyright
|
|
|
f143d5 |
+ * notice, this list of conditions and the following disclaimer.
|
|
|
f143d5 |
+ * * Redistributions in binary form must reproduce the above
|
|
|
f143d5 |
+ * copyright notice, this list of conditions and the following disclaimer
|
|
|
f143d5 |
+ * in the documentation and/or other materials provided with the
|
|
|
f143d5 |
+ * distribution.
|
|
|
f143d5 |
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
f143d5 |
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
f143d5 |
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
f143d5 |
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
f143d5 |
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
f143d5 |
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
f143d5 |
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
f143d5 |
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
f143d5 |
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
f143d5 |
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
f143d5 |
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
f143d5 |
+ * You can contact the author at :
|
|
|
f143d5 |
+ * - LZ4 homepage : http://www.lz4.org
|
|
|
f143d5 |
+ * - LZ4 source repository : https://github.com/lz4/lz4
|
|
|
f143d5 |
+ *
|
|
|
f143d5 |
+ * Changed for kernel usage by:
|
|
|
f143d5 |
+ * Sven Schmidt <4sschmid@informatik.uni-hamburg.de>
|
|
|
f143d5 |
+ */
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+/*-************************************
|
|
|
f143d5 |
+ * Dependencies
|
|
|
f143d5 |
+ **************************************/
|
|
|
f143d5 |
+#include <linux/lz4.h>
|
|
|
f143d5 |
+#include "lz4defs.h"
|
|
|
f143d5 |
+#include <linux/module.h>
|
|
|
f143d5 |
+#include <linux/kernel.h>
|
|
|
f143d5 |
+#include <asm/unaligned.h>
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+static const int LZ4_minLength = (MFLIMIT + 1);
|
|
|
f143d5 |
+static const int LZ4_64Klimit = ((64 * KB) + (MFLIMIT - 1));
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+/*-******************************
|
|
|
f143d5 |
+ * Compression functions
|
|
|
f143d5 |
+ ********************************/
|
|
|
f143d5 |
+static FORCE_INLINE U32 LZ4_hash4(
|
|
|
f143d5 |
+ U32 sequence,
|
|
|
f143d5 |
+ tableType_t const tableType)
|
|
|
f143d5 |
+{
|
|
|
f143d5 |
+ if (tableType == byU16)
|
|
|
f143d5 |
+ return ((sequence * 2654435761U)
|
|
|
f143d5 |
+ >> ((MINMATCH * 8) - (LZ4_HASHLOG + 1)));
|
|
|
f143d5 |
+ else
|
|
|
f143d5 |
+ return ((sequence * 2654435761U)
|
|
|
f143d5 |
+ >> ((MINMATCH * 8) - LZ4_HASHLOG));
|
|
|
f143d5 |
+}
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+static FORCE_INLINE U32 LZ4_hash5(
|
|
|
f143d5 |
+ U64 sequence,
|
|
|
f143d5 |
+ tableType_t const tableType)
|
|
|
f143d5 |
+{
|
|
|
f143d5 |
+ const U32 hashLog = (tableType == byU16)
|
|
|
f143d5 |
+ ? LZ4_HASHLOG + 1
|
|
|
f143d5 |
+ : LZ4_HASHLOG;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+#if LZ4_LITTLE_ENDIAN
|
|
|
f143d5 |
+ static const U64 prime5bytes = 889523592379ULL;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ return (U32)(((sequence << 24) * prime5bytes) >> (64 - hashLog));
|
|
|
f143d5 |
+#else
|
|
|
f143d5 |
+ static const U64 prime8bytes = 11400714785074694791ULL;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ return (U32)(((sequence >> 24) * prime8bytes) >> (64 - hashLog));
|
|
|
f143d5 |
+#endif
|
|
|
f143d5 |
+}
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+static FORCE_INLINE U32 LZ4_hashPosition(
|
|
|
f143d5 |
+ const void *p,
|
|
|
f143d5 |
+ tableType_t const tableType)
|
|
|
f143d5 |
+{
|
|
|
f143d5 |
+#if LZ4_ARCH64
|
|
|
f143d5 |
+ if (tableType == byU32)
|
|
|
f143d5 |
+ return LZ4_hash5(LZ4_read_ARCH(p), tableType);
|
|
|
f143d5 |
+#endif
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ return LZ4_hash4(LZ4_read32(p), tableType);
|
|
|
f143d5 |
+}
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+static void LZ4_putPositionOnHash(
|
|
|
f143d5 |
+ const BYTE *p,
|
|
|
f143d5 |
+ U32 h,
|
|
|
f143d5 |
+ void *tableBase,
|
|
|
f143d5 |
+ tableType_t const tableType,
|
|
|
f143d5 |
+ const BYTE *srcBase)
|
|
|
f143d5 |
+{
|
|
|
f143d5 |
+ switch (tableType) {
|
|
|
f143d5 |
+ case byPtr:
|
|
|
f143d5 |
+ {
|
|
|
f143d5 |
+ const BYTE **hashTable = (const BYTE **)tableBase;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ hashTable[h] = p;
|
|
|
f143d5 |
+ return;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+ case byU32:
|
|
|
f143d5 |
+ {
|
|
|
f143d5 |
+ U32 *hashTable = (U32 *) tableBase;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ hashTable[h] = (U32)(p - srcBase);
|
|
|
f143d5 |
+ return;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+ case byU16:
|
|
|
f143d5 |
+ {
|
|
|
f143d5 |
+ U16 *hashTable = (U16 *) tableBase;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ hashTable[h] = (U16)(p - srcBase);
|
|
|
f143d5 |
+ return;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+}
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+static FORCE_INLINE void LZ4_putPosition(
|
|
|
f143d5 |
+ const BYTE *p,
|
|
|
f143d5 |
+ void *tableBase,
|
|
|
f143d5 |
+ tableType_t tableType,
|
|
|
f143d5 |
+ const BYTE *srcBase)
|
|
|
f143d5 |
+{
|
|
|
f143d5 |
+ U32 const h = LZ4_hashPosition(p, tableType);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ LZ4_putPositionOnHash(p, h, tableBase, tableType, srcBase);
|
|
|
f143d5 |
+}
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+static const BYTE *LZ4_getPositionOnHash(
|
|
|
f143d5 |
+ U32 h,
|
|
|
f143d5 |
+ void *tableBase,
|
|
|
f143d5 |
+ tableType_t tableType,
|
|
|
f143d5 |
+ const BYTE *srcBase)
|
|
|
f143d5 |
+{
|
|
|
f143d5 |
+ if (tableType == byPtr) {
|
|
|
f143d5 |
+ const BYTE **hashTable = (const BYTE **) tableBase;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ return hashTable[h];
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if (tableType == byU32) {
|
|
|
f143d5 |
+ const U32 * const hashTable = (U32 *) tableBase;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ return hashTable[h] + srcBase;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ {
|
|
|
f143d5 |
+ /* default, to ensure a return */
|
|
|
f143d5 |
+ const U16 * const hashTable = (U16 *) tableBase;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ return hashTable[h] + srcBase;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+}
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+static FORCE_INLINE const BYTE *LZ4_getPosition(
|
|
|
f143d5 |
+ const BYTE *p,
|
|
|
f143d5 |
+ void *tableBase,
|
|
|
f143d5 |
+ tableType_t tableType,
|
|
|
f143d5 |
+ const BYTE *srcBase)
|
|
|
f143d5 |
+{
|
|
|
f143d5 |
+ U32 const h = LZ4_hashPosition(p, tableType);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ return LZ4_getPositionOnHash(h, tableBase, tableType, srcBase);
|
|
|
f143d5 |
+}
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+/*
|
|
|
f143d5 |
+ * LZ4_compress_generic() :
|
|
|
f143d5 |
+ * inlined, to ensure branches are decided at compilation time
|
|
|
f143d5 |
+ */
|
|
|
f143d5 |
+static FORCE_INLINE int LZ4_compress_generic(
|
|
|
f143d5 |
+ LZ4_stream_t_internal * const dictPtr,
|
|
|
f143d5 |
+ const char * const source,
|
|
|
f143d5 |
+ char * const dest,
|
|
|
f143d5 |
+ const int inputSize,
|
|
|
f143d5 |
+ const int maxOutputSize,
|
|
|
f143d5 |
+ const limitedOutput_directive outputLimited,
|
|
|
f143d5 |
+ const tableType_t tableType,
|
|
|
f143d5 |
+ const dict_directive dict,
|
|
|
f143d5 |
+ const dictIssue_directive dictIssue,
|
|
|
f143d5 |
+ const U32 acceleration)
|
|
|
f143d5 |
+{
|
|
|
f143d5 |
+ const BYTE *ip = (const BYTE *) source;
|
|
|
f143d5 |
+ const BYTE *base;
|
|
|
f143d5 |
+ const BYTE *lowLimit;
|
|
|
f143d5 |
+ const BYTE * const lowRefLimit = ip - dictPtr->dictSize;
|
|
|
f143d5 |
+ const BYTE * const dictionary = dictPtr->dictionary;
|
|
|
f143d5 |
+ const BYTE * const dictEnd = dictionary + dictPtr->dictSize;
|
|
|
f143d5 |
+ const size_t dictDelta = dictEnd - (const BYTE *)source;
|
|
|
f143d5 |
+ const BYTE *anchor = (const BYTE *) source;
|
|
|
f143d5 |
+ const BYTE * const iend = ip + inputSize;
|
|
|
f143d5 |
+ const BYTE * const mflimit = iend - MFLIMIT;
|
|
|
f143d5 |
+ const BYTE * const matchlimit = iend - LASTLITERALS;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ BYTE *op = (BYTE *) dest;
|
|
|
f143d5 |
+ BYTE * const olimit = op + maxOutputSize;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ U32 forwardH;
|
|
|
f143d5 |
+ size_t refDelta = 0;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ /* Init conditions */
|
|
|
f143d5 |
+ if ((U32)inputSize > (U32)LZ4_MAX_INPUT_SIZE) {
|
|
|
f143d5 |
+ /* Unsupported inputSize, too large (or negative) */
|
|
|
f143d5 |
+ return 0;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ switch (dict) {
|
|
|
f143d5 |
+ case noDict:
|
|
|
f143d5 |
+ default:
|
|
|
f143d5 |
+ base = (const BYTE *)source;
|
|
|
f143d5 |
+ lowLimit = (const BYTE *)source;
|
|
|
f143d5 |
+ break;
|
|
|
f143d5 |
+ case withPrefix64k:
|
|
|
f143d5 |
+ base = (const BYTE *)source - dictPtr->currentOffset;
|
|
|
f143d5 |
+ lowLimit = (const BYTE *)source - dictPtr->dictSize;
|
|
|
f143d5 |
+ break;
|
|
|
f143d5 |
+ case usingExtDict:
|
|
|
f143d5 |
+ base = (const BYTE *)source - dictPtr->currentOffset;
|
|
|
f143d5 |
+ lowLimit = (const BYTE *)source;
|
|
|
f143d5 |
+ break;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if ((tableType == byU16)
|
|
|
f143d5 |
+ && (inputSize >= LZ4_64Klimit)) {
|
|
|
f143d5 |
+ /* Size too large (not within 64K limit) */
|
|
|
f143d5 |
+ return 0;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if (inputSize < LZ4_minLength) {
|
|
|
f143d5 |
+ /* Input too small, no compression (all literals) */
|
|
|
f143d5 |
+ goto _last_literals;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ /* First Byte */
|
|
|
f143d5 |
+ LZ4_putPosition(ip, dictPtr->hashTable, tableType, base);
|
|
|
f143d5 |
+ ip++;
|
|
|
f143d5 |
+ forwardH = LZ4_hashPosition(ip, tableType);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ /* Main Loop */
|
|
|
f143d5 |
+ for ( ; ; ) {
|
|
|
f143d5 |
+ const BYTE *match;
|
|
|
f143d5 |
+ BYTE *token;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ /* Find a match */
|
|
|
f143d5 |
+ {
|
|
|
f143d5 |
+ const BYTE *forwardIp = ip;
|
|
|
f143d5 |
+ unsigned int step = 1;
|
|
|
f143d5 |
+ unsigned int searchMatchNb = acceleration << LZ4_SKIPTRIGGER;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ do {
|
|
|
f143d5 |
+ U32 const h = forwardH;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ ip = forwardIp;
|
|
|
f143d5 |
+ forwardIp += step;
|
|
|
f143d5 |
+ step = (searchMatchNb++ >> LZ4_SKIPTRIGGER);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if (unlikely(forwardIp > mflimit))
|
|
|
f143d5 |
+ goto _last_literals;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ match = LZ4_getPositionOnHash(h,
|
|
|
f143d5 |
+ dictPtr->hashTable,
|
|
|
f143d5 |
+ tableType, base);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if (dict == usingExtDict) {
|
|
|
f143d5 |
+ if (match < (const BYTE *)source) {
|
|
|
f143d5 |
+ refDelta = dictDelta;
|
|
|
f143d5 |
+ lowLimit = dictionary;
|
|
|
f143d5 |
+ } else {
|
|
|
f143d5 |
+ refDelta = 0;
|
|
|
f143d5 |
+ lowLimit = (const BYTE *)source;
|
|
|
f143d5 |
+ } }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ forwardH = LZ4_hashPosition(forwardIp,
|
|
|
f143d5 |
+ tableType);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ LZ4_putPositionOnHash(ip, h, dictPtr->hashTable,
|
|
|
f143d5 |
+ tableType, base);
|
|
|
f143d5 |
+ } while (((dictIssue == dictSmall)
|
|
|
f143d5 |
+ ? (match < lowRefLimit)
|
|
|
f143d5 |
+ : 0)
|
|
|
f143d5 |
+ || ((tableType == byU16)
|
|
|
f143d5 |
+ ? 0
|
|
|
f143d5 |
+ : (match + MAX_DISTANCE < ip))
|
|
|
f143d5 |
+ || (LZ4_read32(match + refDelta)
|
|
|
f143d5 |
+ != LZ4_read32(ip)));
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ /* Catch up */
|
|
|
f143d5 |
+ while (((ip > anchor) & (match + refDelta > lowLimit))
|
|
|
f143d5 |
+ && (unlikely(ip[-1] == match[refDelta - 1]))) {
|
|
|
f143d5 |
+ ip--;
|
|
|
f143d5 |
+ match--;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ /* Encode Literals */
|
|
|
f143d5 |
+ {
|
|
|
f143d5 |
+ unsigned const int litLength = (unsigned int)(ip - anchor);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ token = op++;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if ((outputLimited) &&
|
|
|
f143d5 |
+ /* Check output buffer overflow */
|
|
|
f143d5 |
+ (unlikely(op + litLength +
|
|
|
f143d5 |
+ (2 + 1 + LASTLITERALS) +
|
|
|
f143d5 |
+ (litLength / 255) > olimit)))
|
|
|
f143d5 |
+ return 0;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if (litLength >= RUN_MASK) {
|
|
|
f143d5 |
+ int len = (int)litLength - RUN_MASK;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ *token = (RUN_MASK << ML_BITS);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ for (; len >= 255; len -= 255)
|
|
|
f143d5 |
+ *op++ = 255;
|
|
|
f143d5 |
+ *op++ = (BYTE)len;
|
|
|
f143d5 |
+ } else
|
|
|
f143d5 |
+ *token = (BYTE)(litLength << ML_BITS);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ /* Copy Literals */
|
|
|
f143d5 |
+ LZ4_wildCopy(op, anchor, op + litLength);
|
|
|
f143d5 |
+ op += litLength;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+_next_match:
|
|
|
f143d5 |
+ /* Encode Offset */
|
|
|
f143d5 |
+ LZ4_writeLE16(op, (U16)(ip - match));
|
|
|
f143d5 |
+ op += 2;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ /* Encode MatchLength */
|
|
|
f143d5 |
+ {
|
|
|
f143d5 |
+ unsigned int matchCode;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if ((dict == usingExtDict)
|
|
|
f143d5 |
+ && (lowLimit == dictionary)) {
|
|
|
f143d5 |
+ const BYTE *limit;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ match += refDelta;
|
|
|
f143d5 |
+ limit = ip + (dictEnd - match);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if (limit > matchlimit)
|
|
|
f143d5 |
+ limit = matchlimit;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ matchCode = LZ4_count(ip + MINMATCH,
|
|
|
f143d5 |
+ match + MINMATCH, limit);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ ip += MINMATCH + matchCode;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if (ip == limit) {
|
|
|
f143d5 |
+ unsigned const int more = LZ4_count(ip,
|
|
|
f143d5 |
+ (const BYTE *)source,
|
|
|
f143d5 |
+ matchlimit);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ matchCode += more;
|
|
|
f143d5 |
+ ip += more;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+ } else {
|
|
|
f143d5 |
+ matchCode = LZ4_count(ip + MINMATCH,
|
|
|
f143d5 |
+ match + MINMATCH, matchlimit);
|
|
|
f143d5 |
+ ip += MINMATCH + matchCode;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if (outputLimited &&
|
|
|
f143d5 |
+ /* Check output buffer overflow */
|
|
|
f143d5 |
+ (unlikely(op +
|
|
|
f143d5 |
+ (1 + LASTLITERALS) +
|
|
|
f143d5 |
+ (matchCode >> 8) > olimit)))
|
|
|
f143d5 |
+ return 0;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if (matchCode >= ML_MASK) {
|
|
|
f143d5 |
+ *token += ML_MASK;
|
|
|
f143d5 |
+ matchCode -= ML_MASK;
|
|
|
f143d5 |
+ LZ4_write32(op, 0xFFFFFFFF);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ while (matchCode >= 4 * 255) {
|
|
|
f143d5 |
+ op += 4;
|
|
|
f143d5 |
+ LZ4_write32(op, 0xFFFFFFFF);
|
|
|
f143d5 |
+ matchCode -= 4 * 255;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ op += matchCode / 255;
|
|
|
f143d5 |
+ *op++ = (BYTE)(matchCode % 255);
|
|
|
f143d5 |
+ } else
|
|
|
f143d5 |
+ *token += (BYTE)(matchCode);
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ anchor = ip;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ /* Test end of chunk */
|
|
|
f143d5 |
+ if (ip > mflimit)
|
|
|
f143d5 |
+ break;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ /* Fill table */
|
|
|
f143d5 |
+ LZ4_putPosition(ip - 2, dictPtr->hashTable, tableType, base);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ /* Test next position */
|
|
|
f143d5 |
+ match = LZ4_getPosition(ip, dictPtr->hashTable,
|
|
|
f143d5 |
+ tableType, base);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if (dict == usingExtDict) {
|
|
|
f143d5 |
+ if (match < (const BYTE *)source) {
|
|
|
f143d5 |
+ refDelta = dictDelta;
|
|
|
f143d5 |
+ lowLimit = dictionary;
|
|
|
f143d5 |
+ } else {
|
|
|
f143d5 |
+ refDelta = 0;
|
|
|
f143d5 |
+ lowLimit = (const BYTE *)source;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ LZ4_putPosition(ip, dictPtr->hashTable, tableType, base);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if (((dictIssue == dictSmall) ? (match >= lowRefLimit) : 1)
|
|
|
f143d5 |
+ && (match + MAX_DISTANCE >= ip)
|
|
|
f143d5 |
+ && (LZ4_read32(match + refDelta) == LZ4_read32(ip))) {
|
|
|
f143d5 |
+ token = op++;
|
|
|
f143d5 |
+ *token = 0;
|
|
|
f143d5 |
+ goto _next_match;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ /* Prepare next loop */
|
|
|
f143d5 |
+ forwardH = LZ4_hashPosition(++ip, tableType);
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+_last_literals:
|
|
|
f143d5 |
+ /* Encode Last Literals */
|
|
|
f143d5 |
+ {
|
|
|
f143d5 |
+ size_t const lastRun = (size_t)(iend - anchor);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if ((outputLimited) &&
|
|
|
f143d5 |
+ /* Check output buffer overflow */
|
|
|
f143d5 |
+ ((op - (BYTE *)dest) + lastRun + 1 +
|
|
|
f143d5 |
+ ((lastRun + 255 - RUN_MASK) / 255) > (U32)maxOutputSize))
|
|
|
f143d5 |
+ return 0;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if (lastRun >= RUN_MASK) {
|
|
|
f143d5 |
+ size_t accumulator = lastRun - RUN_MASK;
|
|
|
f143d5 |
+ *op++ = RUN_MASK << ML_BITS;
|
|
|
f143d5 |
+ for (; accumulator >= 255; accumulator -= 255)
|
|
|
f143d5 |
+ *op++ = 255;
|
|
|
f143d5 |
+ *op++ = (BYTE) accumulator;
|
|
|
f143d5 |
+ } else {
|
|
|
f143d5 |
+ *op++ = (BYTE)(lastRun << ML_BITS);
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ LZ4_memcpy(op, anchor, lastRun);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ op += lastRun;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ /* End */
|
|
|
f143d5 |
+ return (int) (((char *)op) - dest);
|
|
|
f143d5 |
+}
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+static int LZ4_compress_fast_extState(
|
|
|
f143d5 |
+ void *state,
|
|
|
f143d5 |
+ const char *source,
|
|
|
f143d5 |
+ char *dest,
|
|
|
f143d5 |
+ int inputSize,
|
|
|
f143d5 |
+ int maxOutputSize,
|
|
|
f143d5 |
+ int acceleration)
|
|
|
f143d5 |
+{
|
|
|
f143d5 |
+ LZ4_stream_t_internal *ctx = &((LZ4_stream_t *)state)->internal_donotuse;
|
|
|
f143d5 |
+#if LZ4_ARCH64
|
|
|
f143d5 |
+ const tableType_t tableType = byU32;
|
|
|
f143d5 |
+#else
|
|
|
f143d5 |
+ const tableType_t tableType = byPtr;
|
|
|
f143d5 |
+#endif
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ LZ4_resetStream((LZ4_stream_t *)state);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if (acceleration < 1)
|
|
|
f143d5 |
+ acceleration = LZ4_ACCELERATION_DEFAULT;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if (maxOutputSize >= LZ4_COMPRESSBOUND(inputSize)) {
|
|
|
f143d5 |
+ if (inputSize < LZ4_64Klimit)
|
|
|
f143d5 |
+ return LZ4_compress_generic(ctx, source,
|
|
|
f143d5 |
+ dest, inputSize, 0,
|
|
|
f143d5 |
+ noLimit, byU16, noDict,
|
|
|
f143d5 |
+ noDictIssue, acceleration);
|
|
|
f143d5 |
+ else
|
|
|
f143d5 |
+ return LZ4_compress_generic(ctx, source,
|
|
|
f143d5 |
+ dest, inputSize, 0,
|
|
|
f143d5 |
+ noLimit, tableType, noDict,
|
|
|
f143d5 |
+ noDictIssue, acceleration);
|
|
|
f143d5 |
+ } else {
|
|
|
f143d5 |
+ if (inputSize < LZ4_64Klimit)
|
|
|
f143d5 |
+ return LZ4_compress_generic(ctx, source,
|
|
|
f143d5 |
+ dest, inputSize,
|
|
|
f143d5 |
+ maxOutputSize, limitedOutput, byU16, noDict,
|
|
|
f143d5 |
+ noDictIssue, acceleration);
|
|
|
f143d5 |
+ else
|
|
|
f143d5 |
+ return LZ4_compress_generic(ctx, source,
|
|
|
f143d5 |
+ dest, inputSize,
|
|
|
f143d5 |
+ maxOutputSize, limitedOutput, tableType, noDict,
|
|
|
f143d5 |
+ noDictIssue, acceleration);
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+}
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+int LZ4_compress_fast(const char *source, char *dest, int inputSize,
|
|
|
f143d5 |
+ int maxOutputSize, int acceleration, void *wrkmem)
|
|
|
f143d5 |
+{
|
|
|
f143d5 |
+ return LZ4_compress_fast_extState(wrkmem, source, dest, inputSize,
|
|
|
f143d5 |
+ maxOutputSize, acceleration);
|
|
|
f143d5 |
+}
|
|
|
f143d5 |
+EXPORT_SYMBOL(LZ4_compress_fast);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+int LZ4_compress_default(const char *source, char *dest, int inputSize,
|
|
|
f143d5 |
+ int maxOutputSize, void *wrkmem)
|
|
|
f143d5 |
+{
|
|
|
f143d5 |
+ return LZ4_compress_fast(source, dest, inputSize,
|
|
|
f143d5 |
+ maxOutputSize, LZ4_ACCELERATION_DEFAULT, wrkmem);
|
|
|
f143d5 |
+}
|
|
|
f143d5 |
+EXPORT_SYMBOL(LZ4_compress_default);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+/*-******************************
|
|
|
f143d5 |
+ * *_destSize() variant
|
|
|
f143d5 |
+ ********************************/
|
|
|
f143d5 |
+static int LZ4_compress_destSize_generic(
|
|
|
f143d5 |
+ LZ4_stream_t_internal * const ctx,
|
|
|
f143d5 |
+ const char * const src,
|
|
|
f143d5 |
+ char * const dst,
|
|
|
f143d5 |
+ int * const srcSizePtr,
|
|
|
f143d5 |
+ const int targetDstSize,
|
|
|
f143d5 |
+ const tableType_t tableType)
|
|
|
f143d5 |
+{
|
|
|
f143d5 |
+ const BYTE *ip = (const BYTE *) src;
|
|
|
f143d5 |
+ const BYTE *base = (const BYTE *) src;
|
|
|
f143d5 |
+ const BYTE *lowLimit = (const BYTE *) src;
|
|
|
f143d5 |
+ const BYTE *anchor = ip;
|
|
|
f143d5 |
+ const BYTE * const iend = ip + *srcSizePtr;
|
|
|
f143d5 |
+ const BYTE * const mflimit = iend - MFLIMIT;
|
|
|
f143d5 |
+ const BYTE * const matchlimit = iend - LASTLITERALS;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ BYTE *op = (BYTE *) dst;
|
|
|
f143d5 |
+ BYTE * const oend = op + targetDstSize;
|
|
|
f143d5 |
+ BYTE * const oMaxLit = op + targetDstSize - 2 /* offset */
|
|
|
f143d5 |
+ - 8 /* because 8 + MINMATCH == MFLIMIT */ - 1 /* token */;
|
|
|
f143d5 |
+ BYTE * const oMaxMatch = op + targetDstSize
|
|
|
f143d5 |
+ - (LASTLITERALS + 1 /* token */);
|
|
|
f143d5 |
+ BYTE * const oMaxSeq = oMaxLit - 1 /* token */;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ U32 forwardH;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ /* Init conditions */
|
|
|
f143d5 |
+ /* Impossible to store anything */
|
|
|
f143d5 |
+ if (targetDstSize < 1)
|
|
|
f143d5 |
+ return 0;
|
|
|
f143d5 |
+ /* Unsupported input size, too large (or negative) */
|
|
|
f143d5 |
+ if ((U32)*srcSizePtr > (U32)LZ4_MAX_INPUT_SIZE)
|
|
|
f143d5 |
+ return 0;
|
|
|
f143d5 |
+ /* Size too large (not within 64K limit) */
|
|
|
f143d5 |
+ if ((tableType == byU16) && (*srcSizePtr >= LZ4_64Klimit))
|
|
|
f143d5 |
+ return 0;
|
|
|
f143d5 |
+ /* Input too small, no compression (all literals) */
|
|
|
f143d5 |
+ if (*srcSizePtr < LZ4_minLength)
|
|
|
f143d5 |
+ goto _last_literals;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ /* First Byte */
|
|
|
f143d5 |
+ *srcSizePtr = 0;
|
|
|
f143d5 |
+ LZ4_putPosition(ip, ctx->hashTable, tableType, base);
|
|
|
f143d5 |
+ ip++; forwardH = LZ4_hashPosition(ip, tableType);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ /* Main Loop */
|
|
|
f143d5 |
+ for ( ; ; ) {
|
|
|
f143d5 |
+ const BYTE *match;
|
|
|
f143d5 |
+ BYTE *token;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ /* Find a match */
|
|
|
f143d5 |
+ {
|
|
|
f143d5 |
+ const BYTE *forwardIp = ip;
|
|
|
f143d5 |
+ unsigned int step = 1;
|
|
|
f143d5 |
+ unsigned int searchMatchNb = 1 << LZ4_SKIPTRIGGER;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ do {
|
|
|
f143d5 |
+ U32 h = forwardH;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ ip = forwardIp;
|
|
|
f143d5 |
+ forwardIp += step;
|
|
|
f143d5 |
+ step = (searchMatchNb++ >> LZ4_SKIPTRIGGER);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if (unlikely(forwardIp > mflimit))
|
|
|
f143d5 |
+ goto _last_literals;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ match = LZ4_getPositionOnHash(h, ctx->hashTable,
|
|
|
f143d5 |
+ tableType, base);
|
|
|
f143d5 |
+ forwardH = LZ4_hashPosition(forwardIp,
|
|
|
f143d5 |
+ tableType);
|
|
|
f143d5 |
+ LZ4_putPositionOnHash(ip, h,
|
|
|
f143d5 |
+ ctx->hashTable, tableType,
|
|
|
f143d5 |
+ base);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ } while (((tableType == byU16)
|
|
|
f143d5 |
+ ? 0
|
|
|
f143d5 |
+ : (match + MAX_DISTANCE < ip))
|
|
|
f143d5 |
+ || (LZ4_read32(match) != LZ4_read32(ip)));
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ /* Catch up */
|
|
|
f143d5 |
+ while ((ip > anchor)
|
|
|
f143d5 |
+ && (match > lowLimit)
|
|
|
f143d5 |
+ && (unlikely(ip[-1] == match[-1]))) {
|
|
|
f143d5 |
+ ip--;
|
|
|
f143d5 |
+ match--;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ /* Encode Literal length */
|
|
|
f143d5 |
+ {
|
|
|
f143d5 |
+ unsigned int litLength = (unsigned int)(ip - anchor);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ token = op++;
|
|
|
f143d5 |
+ if (op + ((litLength + 240) / 255)
|
|
|
f143d5 |
+ + litLength > oMaxLit) {
|
|
|
f143d5 |
+ /* Not enough space for a last match */
|
|
|
f143d5 |
+ op--;
|
|
|
f143d5 |
+ goto _last_literals;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+ if (litLength >= RUN_MASK) {
|
|
|
f143d5 |
+ unsigned int len = litLength - RUN_MASK;
|
|
|
f143d5 |
+ *token = (RUN_MASK<
|
|
|
f143d5 |
+ for (; len >= 255; len -= 255)
|
|
|
f143d5 |
+ *op++ = 255;
|
|
|
f143d5 |
+ *op++ = (BYTE)len;
|
|
|
f143d5 |
+ } else
|
|
|
f143d5 |
+ *token = (BYTE)(litLength << ML_BITS);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ /* Copy Literals */
|
|
|
f143d5 |
+ LZ4_wildCopy(op, anchor, op + litLength);
|
|
|
f143d5 |
+ op += litLength;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+_next_match:
|
|
|
f143d5 |
+ /* Encode Offset */
|
|
|
f143d5 |
+ LZ4_writeLE16(op, (U16)(ip - match)); op += 2;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ /* Encode MatchLength */
|
|
|
f143d5 |
+ {
|
|
|
f143d5 |
+ size_t matchLength = LZ4_count(ip + MINMATCH,
|
|
|
f143d5 |
+ match + MINMATCH, matchlimit);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if (op + ((matchLength + 240)/255) > oMaxMatch) {
|
|
|
f143d5 |
+ /* Match description too long : reduce it */
|
|
|
f143d5 |
+ matchLength = (15 - 1) + (oMaxMatch - op) * 255;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+ ip += MINMATCH + matchLength;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if (matchLength >= ML_MASK) {
|
|
|
f143d5 |
+ *token += ML_MASK;
|
|
|
f143d5 |
+ matchLength -= ML_MASK;
|
|
|
f143d5 |
+ while (matchLength >= 255) {
|
|
|
f143d5 |
+ matchLength -= 255;
|
|
|
f143d5 |
+ *op++ = 255;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+ *op++ = (BYTE)matchLength;
|
|
|
f143d5 |
+ } else
|
|
|
f143d5 |
+ *token += (BYTE)(matchLength);
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ anchor = ip;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ /* Test end of block */
|
|
|
f143d5 |
+ if (ip > mflimit)
|
|
|
f143d5 |
+ break;
|
|
|
f143d5 |
+ if (op > oMaxSeq)
|
|
|
f143d5 |
+ break;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ /* Fill table */
|
|
|
f143d5 |
+ LZ4_putPosition(ip - 2, ctx->hashTable, tableType, base);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ /* Test next position */
|
|
|
f143d5 |
+ match = LZ4_getPosition(ip, ctx->hashTable, tableType, base);
|
|
|
f143d5 |
+ LZ4_putPosition(ip, ctx->hashTable, tableType, base);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if ((match + MAX_DISTANCE >= ip)
|
|
|
f143d5 |
+ && (LZ4_read32(match) == LZ4_read32(ip))) {
|
|
|
f143d5 |
+ token = op++; *token = 0;
|
|
|
f143d5 |
+ goto _next_match;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ /* Prepare next loop */
|
|
|
f143d5 |
+ forwardH = LZ4_hashPosition(++ip, tableType);
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+_last_literals:
|
|
|
f143d5 |
+ /* Encode Last Literals */
|
|
|
f143d5 |
+ {
|
|
|
f143d5 |
+ size_t lastRunSize = (size_t)(iend - anchor);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if (op + 1 /* token */
|
|
|
f143d5 |
+ + ((lastRunSize + 240) / 255) /* litLength */
|
|
|
f143d5 |
+ + lastRunSize /* literals */ > oend) {
|
|
|
f143d5 |
+ /* adapt lastRunSize to fill 'dst' */
|
|
|
f143d5 |
+ lastRunSize = (oend - op) - 1;
|
|
|
f143d5 |
+ lastRunSize -= (lastRunSize + 240) / 255;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+ ip = anchor + lastRunSize;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if (lastRunSize >= RUN_MASK) {
|
|
|
f143d5 |
+ size_t accumulator = lastRunSize - RUN_MASK;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ *op++ = RUN_MASK << ML_BITS;
|
|
|
f143d5 |
+ for (; accumulator >= 255; accumulator -= 255)
|
|
|
f143d5 |
+ *op++ = 255;
|
|
|
f143d5 |
+ *op++ = (BYTE) accumulator;
|
|
|
f143d5 |
+ } else {
|
|
|
f143d5 |
+ *op++ = (BYTE)(lastRunSize<
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+ LZ4_memcpy(op, anchor, lastRunSize);
|
|
|
f143d5 |
+ op += lastRunSize;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ /* End */
|
|
|
f143d5 |
+ *srcSizePtr = (int) (((const char *)ip) - src);
|
|
|
f143d5 |
+ return (int) (((char *)op) - dst);
|
|
|
f143d5 |
+}
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+static int LZ4_compress_destSize_extState(
|
|
|
f143d5 |
+ LZ4_stream_t *state,
|
|
|
f143d5 |
+ const char *src,
|
|
|
f143d5 |
+ char *dst,
|
|
|
f143d5 |
+ int *srcSizePtr,
|
|
|
f143d5 |
+ int targetDstSize)
|
|
|
f143d5 |
+{
|
|
|
f143d5 |
+#if LZ4_ARCH64
|
|
|
f143d5 |
+ const tableType_t tableType = byU32;
|
|
|
f143d5 |
+#else
|
|
|
f143d5 |
+ const tableType_t tableType = byPtr;
|
|
|
f143d5 |
+#endif
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ LZ4_resetStream(state);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if (targetDstSize >= LZ4_COMPRESSBOUND(*srcSizePtr)) {
|
|
|
f143d5 |
+ /* compression success is guaranteed */
|
|
|
f143d5 |
+ return LZ4_compress_fast_extState(
|
|
|
f143d5 |
+ state, src, dst, *srcSizePtr,
|
|
|
f143d5 |
+ targetDstSize, 1);
|
|
|
f143d5 |
+ } else {
|
|
|
f143d5 |
+ if (*srcSizePtr < LZ4_64Klimit)
|
|
|
f143d5 |
+ return LZ4_compress_destSize_generic(
|
|
|
f143d5 |
+ &state->internal_donotuse,
|
|
|
f143d5 |
+ src, dst, srcSizePtr,
|
|
|
f143d5 |
+ targetDstSize, byU16);
|
|
|
f143d5 |
+ else
|
|
|
f143d5 |
+ return LZ4_compress_destSize_generic(
|
|
|
f143d5 |
+ &state->internal_donotuse,
|
|
|
f143d5 |
+ src, dst, srcSizePtr,
|
|
|
f143d5 |
+ targetDstSize, tableType);
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+}
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+int LZ4_compress_destSize(
|
|
|
f143d5 |
+ const char *src,
|
|
|
f143d5 |
+ char *dst,
|
|
|
f143d5 |
+ int *srcSizePtr,
|
|
|
f143d5 |
+ int targetDstSize,
|
|
|
f143d5 |
+ void *wrkmem)
|
|
|
f143d5 |
+{
|
|
|
f143d5 |
+ return LZ4_compress_destSize_extState(wrkmem, src, dst, srcSizePtr,
|
|
|
f143d5 |
+ targetDstSize);
|
|
|
f143d5 |
+}
|
|
|
f143d5 |
+EXPORT_SYMBOL(LZ4_compress_destSize);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+/*-******************************
|
|
|
f143d5 |
+ * Streaming functions
|
|
|
f143d5 |
+ ********************************/
|
|
|
f143d5 |
+void LZ4_resetStream(LZ4_stream_t *LZ4_stream)
|
|
|
f143d5 |
+{
|
|
|
f143d5 |
+ memset(LZ4_stream, 0, sizeof(LZ4_stream_t));
|
|
|
f143d5 |
+}
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+int LZ4_loadDict(LZ4_stream_t *LZ4_dict,
|
|
|
f143d5 |
+ const char *dictionary, int dictSize)
|
|
|
f143d5 |
+{
|
|
|
f143d5 |
+ LZ4_stream_t_internal *dict = &LZ4_dict->internal_donotuse;
|
|
|
f143d5 |
+ const BYTE *p = (const BYTE *)dictionary;
|
|
|
f143d5 |
+ const BYTE * const dictEnd = p + dictSize;
|
|
|
f143d5 |
+ const BYTE *base;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if ((dict->initCheck)
|
|
|
f143d5 |
+ || (dict->currentOffset > 1 * GB)) {
|
|
|
f143d5 |
+ /* Uninitialized structure, or reuse overflow */
|
|
|
f143d5 |
+ LZ4_resetStream(LZ4_dict);
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if (dictSize < (int)HASH_UNIT) {
|
|
|
f143d5 |
+ dict->dictionary = NULL;
|
|
|
f143d5 |
+ dict->dictSize = 0;
|
|
|
f143d5 |
+ return 0;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if ((dictEnd - p) > 64 * KB)
|
|
|
f143d5 |
+ p = dictEnd - 64 * KB;
|
|
|
f143d5 |
+ dict->currentOffset += 64 * KB;
|
|
|
f143d5 |
+ base = p - dict->currentOffset;
|
|
|
f143d5 |
+ dict->dictionary = p;
|
|
|
f143d5 |
+ dict->dictSize = (U32)(dictEnd - p);
|
|
|
f143d5 |
+ dict->currentOffset += dict->dictSize;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ while (p <= dictEnd - HASH_UNIT) {
|
|
|
f143d5 |
+ LZ4_putPosition(p, dict->hashTable, byU32, base);
|
|
|
f143d5 |
+ p += 3;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ return dict->dictSize;
|
|
|
f143d5 |
+}
|
|
|
f143d5 |
+EXPORT_SYMBOL(LZ4_loadDict);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+static void LZ4_renormDictT(LZ4_stream_t_internal *LZ4_dict,
|
|
|
f143d5 |
+ const BYTE *src)
|
|
|
f143d5 |
+{
|
|
|
f143d5 |
+ if ((LZ4_dict->currentOffset > 0x80000000) ||
|
|
|
f143d5 |
+ ((uptrval)LZ4_dict->currentOffset > (uptrval)src)) {
|
|
|
f143d5 |
+ /* address space overflow */
|
|
|
f143d5 |
+ /* rescale hash table */
|
|
|
f143d5 |
+ U32 const delta = LZ4_dict->currentOffset - 64 * KB;
|
|
|
f143d5 |
+ const BYTE *dictEnd = LZ4_dict->dictionary + LZ4_dict->dictSize;
|
|
|
f143d5 |
+ int i;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ for (i = 0; i < LZ4_HASH_SIZE_U32; i++) {
|
|
|
f143d5 |
+ if (LZ4_dict->hashTable[i] < delta)
|
|
|
f143d5 |
+ LZ4_dict->hashTable[i] = 0;
|
|
|
f143d5 |
+ else
|
|
|
f143d5 |
+ LZ4_dict->hashTable[i] -= delta;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+ LZ4_dict->currentOffset = 64 * KB;
|
|
|
f143d5 |
+ if (LZ4_dict->dictSize > 64 * KB)
|
|
|
f143d5 |
+ LZ4_dict->dictSize = 64 * KB;
|
|
|
f143d5 |
+ LZ4_dict->dictionary = dictEnd - LZ4_dict->dictSize;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+}
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+int LZ4_saveDict(LZ4_stream_t *LZ4_dict, char *safeBuffer, int dictSize)
|
|
|
f143d5 |
+{
|
|
|
f143d5 |
+ LZ4_stream_t_internal * const dict = &LZ4_dict->internal_donotuse;
|
|
|
f143d5 |
+ const BYTE * const previousDictEnd = dict->dictionary + dict->dictSize;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if ((U32)dictSize > 64 * KB) {
|
|
|
f143d5 |
+ /* useless to define a dictionary > 64 * KB */
|
|
|
f143d5 |
+ dictSize = 64 * KB;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+ if ((U32)dictSize > dict->dictSize)
|
|
|
f143d5 |
+ dictSize = dict->dictSize;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ memmove(safeBuffer, previousDictEnd - dictSize, dictSize);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ dict->dictionary = (const BYTE *)safeBuffer;
|
|
|
f143d5 |
+ dict->dictSize = (U32)dictSize;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ return dictSize;
|
|
|
f143d5 |
+}
|
|
|
f143d5 |
+EXPORT_SYMBOL(LZ4_saveDict);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+int LZ4_compress_fast_continue(LZ4_stream_t *LZ4_stream, const char *source,
|
|
|
f143d5 |
+ char *dest, int inputSize, int maxOutputSize, int acceleration)
|
|
|
f143d5 |
+{
|
|
|
f143d5 |
+ LZ4_stream_t_internal *streamPtr = &LZ4_stream->internal_donotuse;
|
|
|
f143d5 |
+ const BYTE * const dictEnd = streamPtr->dictionary
|
|
|
f143d5 |
+ + streamPtr->dictSize;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ const BYTE *smallest = (const BYTE *) source;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if (streamPtr->initCheck) {
|
|
|
f143d5 |
+ /* Uninitialized structure detected */
|
|
|
f143d5 |
+ return 0;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if ((streamPtr->dictSize > 0) && (smallest > dictEnd))
|
|
|
f143d5 |
+ smallest = dictEnd;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ LZ4_renormDictT(streamPtr, smallest);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if (acceleration < 1)
|
|
|
f143d5 |
+ acceleration = LZ4_ACCELERATION_DEFAULT;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ /* Check overlapping input/dictionary space */
|
|
|
f143d5 |
+ {
|
|
|
f143d5 |
+ const BYTE *sourceEnd = (const BYTE *) source + inputSize;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if ((sourceEnd > streamPtr->dictionary)
|
|
|
f143d5 |
+ && (sourceEnd < dictEnd)) {
|
|
|
f143d5 |
+ streamPtr->dictSize = (U32)(dictEnd - sourceEnd);
|
|
|
f143d5 |
+ if (streamPtr->dictSize > 64 * KB)
|
|
|
f143d5 |
+ streamPtr->dictSize = 64 * KB;
|
|
|
f143d5 |
+ if (streamPtr->dictSize < 4)
|
|
|
f143d5 |
+ streamPtr->dictSize = 0;
|
|
|
f143d5 |
+ streamPtr->dictionary = dictEnd - streamPtr->dictSize;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ /* prefix mode : source data follows dictionary */
|
|
|
f143d5 |
+ if (dictEnd == (const BYTE *)source) {
|
|
|
f143d5 |
+ int result;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if ((streamPtr->dictSize < 64 * KB) &&
|
|
|
f143d5 |
+ (streamPtr->dictSize < streamPtr->currentOffset)) {
|
|
|
f143d5 |
+ result = LZ4_compress_generic(
|
|
|
f143d5 |
+ streamPtr, source, dest, inputSize,
|
|
|
f143d5 |
+ maxOutputSize, limitedOutput, byU32,
|
|
|
f143d5 |
+ withPrefix64k, dictSmall, acceleration);
|
|
|
f143d5 |
+ } else {
|
|
|
f143d5 |
+ result = LZ4_compress_generic(
|
|
|
f143d5 |
+ streamPtr, source, dest, inputSize,
|
|
|
f143d5 |
+ maxOutputSize, limitedOutput, byU32,
|
|
|
f143d5 |
+ withPrefix64k, noDictIssue, acceleration);
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+ streamPtr->dictSize += (U32)inputSize;
|
|
|
f143d5 |
+ streamPtr->currentOffset += (U32)inputSize;
|
|
|
f143d5 |
+ return result;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ /* external dictionary mode */
|
|
|
f143d5 |
+ {
|
|
|
f143d5 |
+ int result;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if ((streamPtr->dictSize < 64 * KB) &&
|
|
|
f143d5 |
+ (streamPtr->dictSize < streamPtr->currentOffset)) {
|
|
|
f143d5 |
+ result = LZ4_compress_generic(
|
|
|
f143d5 |
+ streamPtr, source, dest, inputSize,
|
|
|
f143d5 |
+ maxOutputSize, limitedOutput, byU32,
|
|
|
f143d5 |
+ usingExtDict, dictSmall, acceleration);
|
|
|
f143d5 |
+ } else {
|
|
|
f143d5 |
+ result = LZ4_compress_generic(
|
|
|
f143d5 |
+ streamPtr, source, dest, inputSize,
|
|
|
f143d5 |
+ maxOutputSize, limitedOutput, byU32,
|
|
|
f143d5 |
+ usingExtDict, noDictIssue, acceleration);
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+ streamPtr->dictionary = (const BYTE *)source;
|
|
|
f143d5 |
+ streamPtr->dictSize = (U32)inputSize;
|
|
|
f143d5 |
+ streamPtr->currentOffset += (U32)inputSize;
|
|
|
f143d5 |
+ return result;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+}
|
|
|
f143d5 |
+EXPORT_SYMBOL(LZ4_compress_fast_continue);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+MODULE_LICENSE("Dual BSD/GPL");
|
|
|
f143d5 |
+MODULE_DESCRIPTION("LZ4 compressor");
|
|
|
f143d5 |
diff -Naur kvdo-127a993f34010e4d8b05e46c4af2a9295c4477d0.orig/vdo/lz4defs.h kvdo-127a993f34010e4d8b05e46c4af2a9295c4477d0/vdo/lz4defs.h
|
|
|
f143d5 |
--- kvdo-127a993f34010e4d8b05e46c4af2a9295c4477d0.orig/vdo/lz4defs.h 1969-12-31 19:00:00.000000000 -0500
|
|
|
f143d5 |
+++ kvdo-127a993f34010e4d8b05e46c4af2a9295c4477d0/vdo/lz4defs.h 2022-07-27 21:39:43.896830772 -0400
|
|
|
f143d5 |
@@ -0,0 +1,245 @@
|
|
|
f143d5 |
+#ifndef __LZ4DEFS_H__
|
|
|
f143d5 |
+#define __LZ4DEFS_H__
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+/*
|
|
|
f143d5 |
+ * lz4defs.h -- common and architecture specific defines for the kernel usage
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ * LZ4 - Fast LZ compression algorithm
|
|
|
f143d5 |
+ * Copyright (C) 2011-2016, Yann Collet.
|
|
|
f143d5 |
+ * BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
|
|
f143d5 |
+ * Redistribution and use in source and binary forms, with or without
|
|
|
f143d5 |
+ * modification, are permitted provided that the following conditions are
|
|
|
f143d5 |
+ * met:
|
|
|
f143d5 |
+ * * Redistributions of source code must retain the above copyright
|
|
|
f143d5 |
+ * notice, this list of conditions and the following disclaimer.
|
|
|
f143d5 |
+ * * Redistributions in binary form must reproduce the above
|
|
|
f143d5 |
+ * copyright notice, this list of conditions and the following disclaimer
|
|
|
f143d5 |
+ * in the documentation and/or other materials provided with the
|
|
|
f143d5 |
+ * distribution.
|
|
|
f143d5 |
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
f143d5 |
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
f143d5 |
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
f143d5 |
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
f143d5 |
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
f143d5 |
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
f143d5 |
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
f143d5 |
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
f143d5 |
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
f143d5 |
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
f143d5 |
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
f143d5 |
+ * You can contact the author at :
|
|
|
f143d5 |
+ * - LZ4 homepage : http://www.lz4.org
|
|
|
f143d5 |
+ * - LZ4 source repository : https://github.com/lz4/lz4
|
|
|
f143d5 |
+ *
|
|
|
f143d5 |
+ * Changed for kernel usage by:
|
|
|
f143d5 |
+ * Sven Schmidt <4sschmid@informatik.uni-hamburg.de>
|
|
|
f143d5 |
+ */
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+#include <asm/unaligned.h>
|
|
|
f143d5 |
+#include <linux/string.h> /* memset, memcpy */
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+#define FORCE_INLINE __always_inline
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+/*-************************************
|
|
|
f143d5 |
+ * Basic Types
|
|
|
f143d5 |
+ **************************************/
|
|
|
f143d5 |
+#include <linux/types.h>
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+typedef uint8_t BYTE;
|
|
|
f143d5 |
+typedef uint16_t U16;
|
|
|
f143d5 |
+typedef uint32_t U32;
|
|
|
f143d5 |
+typedef int32_t S32;
|
|
|
f143d5 |
+typedef uint64_t U64;
|
|
|
f143d5 |
+typedef uintptr_t uptrval;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+/*-************************************
|
|
|
f143d5 |
+ * Architecture specifics
|
|
|
f143d5 |
+ **************************************/
|
|
|
f143d5 |
+#if defined(CONFIG_64BIT)
|
|
|
f143d5 |
+#define LZ4_ARCH64 1
|
|
|
f143d5 |
+#else
|
|
|
f143d5 |
+#define LZ4_ARCH64 0
|
|
|
f143d5 |
+#endif
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+#if defined(__LITTLE_ENDIAN)
|
|
|
f143d5 |
+#define LZ4_LITTLE_ENDIAN 1
|
|
|
f143d5 |
+#else
|
|
|
f143d5 |
+#define LZ4_LITTLE_ENDIAN 0
|
|
|
f143d5 |
+#endif
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+/*-************************************
|
|
|
f143d5 |
+ * Constants
|
|
|
f143d5 |
+ **************************************/
|
|
|
f143d5 |
+#define MINMATCH 4
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+#define WILDCOPYLENGTH 8
|
|
|
f143d5 |
+#define LASTLITERALS 5
|
|
|
f143d5 |
+#define MFLIMIT (WILDCOPYLENGTH + MINMATCH)
|
|
|
f143d5 |
+/*
|
|
|
f143d5 |
+ * ensure it's possible to write 2 x wildcopyLength
|
|
|
f143d5 |
+ * without overflowing output buffer
|
|
|
f143d5 |
+ */
|
|
|
f143d5 |
+#define MATCH_SAFEGUARD_DISTANCE ((2 * WILDCOPYLENGTH) - MINMATCH)
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+/* Increase this value ==> compression run slower on incompressible data */
|
|
|
f143d5 |
+#define LZ4_SKIPTRIGGER 6
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+#define HASH_UNIT sizeof(size_t)
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+#define KB (1 << 10)
|
|
|
f143d5 |
+#define MB (1 << 20)
|
|
|
f143d5 |
+#define GB (1U << 30)
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+#define MAXD_LOG 16
|
|
|
f143d5 |
+#define MAX_DISTANCE ((1 << MAXD_LOG) - 1)
|
|
|
f143d5 |
+#define STEPSIZE sizeof(size_t)
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+#define ML_BITS 4
|
|
|
f143d5 |
+#define ML_MASK ((1U << ML_BITS) - 1)
|
|
|
f143d5 |
+#define RUN_BITS (8 - ML_BITS)
|
|
|
f143d5 |
+#define RUN_MASK ((1U << RUN_BITS) - 1)
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+/*-************************************
|
|
|
f143d5 |
+ * Reading and writing into memory
|
|
|
f143d5 |
+ **************************************/
|
|
|
f143d5 |
+static FORCE_INLINE U16 LZ4_read16(const void *ptr)
|
|
|
f143d5 |
+{
|
|
|
f143d5 |
+ return get_unaligned((const U16 *)ptr);
|
|
|
f143d5 |
+}
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+static FORCE_INLINE U32 LZ4_read32(const void *ptr)
|
|
|
f143d5 |
+{
|
|
|
f143d5 |
+ return get_unaligned((const U32 *)ptr);
|
|
|
f143d5 |
+}
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+static FORCE_INLINE size_t LZ4_read_ARCH(const void *ptr)
|
|
|
f143d5 |
+{
|
|
|
f143d5 |
+ return get_unaligned((const size_t *)ptr);
|
|
|
f143d5 |
+}
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+static FORCE_INLINE void LZ4_write16(void *memPtr, U16 value)
|
|
|
f143d5 |
+{
|
|
|
f143d5 |
+ put_unaligned(value, (U16 *)memPtr);
|
|
|
f143d5 |
+}
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+static FORCE_INLINE void LZ4_write32(void *memPtr, U32 value)
|
|
|
f143d5 |
+{
|
|
|
f143d5 |
+ put_unaligned(value, (U32 *)memPtr);
|
|
|
f143d5 |
+}
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+static FORCE_INLINE U16 LZ4_readLE16(const void *memPtr)
|
|
|
f143d5 |
+{
|
|
|
f143d5 |
+ return get_unaligned_le16(memPtr);
|
|
|
f143d5 |
+}
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+static FORCE_INLINE void LZ4_writeLE16(void *memPtr, U16 value)
|
|
|
f143d5 |
+{
|
|
|
f143d5 |
+ return put_unaligned_le16(value, memPtr);
|
|
|
f143d5 |
+}
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+/*
|
|
|
f143d5 |
+ * LZ4 relies on memcpy with a constant size being inlined. In freestanding
|
|
|
f143d5 |
+ * environments, the compiler can't assume the implementation of memcpy() is
|
|
|
f143d5 |
+ * standard compliant, so apply its specialized memcpy() inlining logic. When
|
|
|
f143d5 |
+ * possible, use __builtin_memcpy() to tell the compiler to analyze memcpy()
|
|
|
f143d5 |
+ * as-if it were standard compliant, so it can inline it in freestanding
|
|
|
f143d5 |
+ * environments. This is needed when decompressing the Linux Kernel, for example.
|
|
|
f143d5 |
+ */
|
|
|
f143d5 |
+#define LZ4_memcpy(dst, src, size) __builtin_memcpy(dst, src, size)
|
|
|
f143d5 |
+#define LZ4_memmove(dst, src, size) __builtin_memmove(dst, src, size)
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+static FORCE_INLINE void LZ4_copy8(void *dst, const void *src)
|
|
|
f143d5 |
+{
|
|
|
f143d5 |
+#if LZ4_ARCH64
|
|
|
f143d5 |
+ U64 a = get_unaligned((const U64 *)src);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ put_unaligned(a, (U64 *)dst);
|
|
|
f143d5 |
+#else
|
|
|
f143d5 |
+ U32 a = get_unaligned((const U32 *)src);
|
|
|
f143d5 |
+ U32 b = get_unaligned((const U32 *)src + 1);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ put_unaligned(a, (U32 *)dst);
|
|
|
f143d5 |
+ put_unaligned(b, (U32 *)dst + 1);
|
|
|
f143d5 |
+#endif
|
|
|
f143d5 |
+}
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+/*
|
|
|
f143d5 |
+ * customized variant of memcpy,
|
|
|
f143d5 |
+ * which can overwrite up to 7 bytes beyond dstEnd
|
|
|
f143d5 |
+ */
|
|
|
f143d5 |
+static FORCE_INLINE void LZ4_wildCopy(void *dstPtr,
|
|
|
f143d5 |
+ const void *srcPtr, void *dstEnd)
|
|
|
f143d5 |
+{
|
|
|
f143d5 |
+ BYTE *d = (BYTE *)dstPtr;
|
|
|
f143d5 |
+ const BYTE *s = (const BYTE *)srcPtr;
|
|
|
f143d5 |
+ BYTE *const e = (BYTE *)dstEnd;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ do {
|
|
|
f143d5 |
+ LZ4_copy8(d, s);
|
|
|
f143d5 |
+ d += 8;
|
|
|
f143d5 |
+ s += 8;
|
|
|
f143d5 |
+ } while (d < e);
|
|
|
f143d5 |
+}
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+static FORCE_INLINE unsigned int LZ4_NbCommonBytes(register size_t val)
|
|
|
f143d5 |
+{
|
|
|
f143d5 |
+#if LZ4_LITTLE_ENDIAN
|
|
|
f143d5 |
+ return __ffs(val) >> 3;
|
|
|
f143d5 |
+#else
|
|
|
f143d5 |
+ return (BITS_PER_LONG - 1 - __fls(val)) >> 3;
|
|
|
f143d5 |
+#endif
|
|
|
f143d5 |
+}
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+static FORCE_INLINE unsigned int LZ4_count(
|
|
|
f143d5 |
+ const BYTE *pIn,
|
|
|
f143d5 |
+ const BYTE *pMatch,
|
|
|
f143d5 |
+ const BYTE *pInLimit)
|
|
|
f143d5 |
+{
|
|
|
f143d5 |
+ const BYTE *const pStart = pIn;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ while (likely(pIn < pInLimit - (STEPSIZE - 1))) {
|
|
|
f143d5 |
+ size_t const diff = LZ4_read_ARCH(pMatch) ^ LZ4_read_ARCH(pIn);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if (!diff) {
|
|
|
f143d5 |
+ pIn += STEPSIZE;
|
|
|
f143d5 |
+ pMatch += STEPSIZE;
|
|
|
f143d5 |
+ continue;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ pIn += LZ4_NbCommonBytes(diff);
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ return (unsigned int)(pIn - pStart);
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+#if LZ4_ARCH64
|
|
|
f143d5 |
+ if ((pIn < (pInLimit - 3))
|
|
|
f143d5 |
+ && (LZ4_read32(pMatch) == LZ4_read32(pIn))) {
|
|
|
f143d5 |
+ pIn += 4;
|
|
|
f143d5 |
+ pMatch += 4;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+#endif
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if ((pIn < (pInLimit - 1))
|
|
|
f143d5 |
+ && (LZ4_read16(pMatch) == LZ4_read16(pIn))) {
|
|
|
f143d5 |
+ pIn += 2;
|
|
|
f143d5 |
+ pMatch += 2;
|
|
|
f143d5 |
+ }
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ if ((pIn < pInLimit) && (*pMatch == *pIn))
|
|
|
f143d5 |
+ pIn++;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+ return (unsigned int)(pIn - pStart);
|
|
|
f143d5 |
+}
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+typedef enum { noLimit = 0, limitedOutput = 1 } limitedOutput_directive;
|
|
|
f143d5 |
+typedef enum { byPtr, byU32, byU16 } tableType_t;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+typedef enum { noDict = 0, withPrefix64k, usingExtDict } dict_directive;
|
|
|
f143d5 |
+typedef enum { noDictIssue = 0, dictSmall } dictIssue_directive;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+typedef enum { endOnOutputSize = 0, endOnInputSize = 1 } endCondition_directive;
|
|
|
f143d5 |
+typedef enum { decode_full_block = 0, partial_decode = 1 } earlyEnd_directive;
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+#define LZ4_STATIC_ASSERT(c) BUILD_BUG_ON(!(c))
|
|
|
f143d5 |
+
|
|
|
f143d5 |
+#endif
|