Lines Matching +full:charge +full:- +full:integration
5 * This source code is licensed under both the BSD-style license (found in the
8 * You may select, at your option, one of the above-listed licenses.
12 /*- Dependencies -*/
39 /*--- Constants ---*/
51 #define ZSTDv07_SEARCHLOG_MAX (ZSTDv07_WINDOWLOG_MAX-1)
70 /*--- Advanced Decompression functions ---*/
86 * Buffer-less streaming functions (synchronous mode)
97 Buffer-less streaming decompression (synchronous mode)
101 A ZSTDv07_DCtx object can be re-used multiple times.
129 or that previous contiguous segment is large enough to properly handle maximum back-reference.
137 Skippable frames allow the integration of user-defined data into a flow of concatenated frames.
139 a) Skippable frame ID - 4 Bytes, Little endian format, any value from 0x184D2A50 to 0x184D2A5F
140 b) Frame Size - 4 Bytes, Little endian format, unsigned 32-bits
141 c) Frame Content - any content (User Data) of length equal to Frame Size
143 …For skippable frames ZSTDv07_getFrameParams() returns fparamsPtr->windowLog==0 what means that a f…
144 It also returns Frame Size as fparamsPtr->frameContentSize.
152 …Frame metadata cost is typically ~18 bytes, which can be non-negligible for very small blocks (< 1…
153 …User will have to take in charge required information to regenerate data, such as compressed and c…
156 - Compressing and decompressing require a context structure
158 - It is necessary to init context before starting
163 - Block size is limited, it must be <= ZSTDv07_getBlockSizeMax()
166 … - When a block is considered not compressible enough, ZSTDv07_compressBlock() result will be zero.
184 low-level memory access routines
185 Copyright (C) 2013-2015, Yann Collet.
187 BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
213 - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy
214 - Public forum : https://groups.google.com/forum/#!forum/lz4c
223 /*-****************************************
241 /*-**************************************************************
268 /*-**************************************************************
273 * Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal.
281 * See http://fastcompression.blogspot.fr/2015/08/accessing-unaligned-memory.html for details.
315 MEM_STATIC U16 MEM_read16(const void* ptr) { return ((const unalign*)ptr)->u16; } in MEM_read16()
316 MEM_STATIC U32 MEM_read32(const void* ptr) { return ((const unalign*)ptr)->u32; } in MEM_read32()
317 MEM_STATIC U64 MEM_read64(const void* ptr) { return ((const unalign*)ptr)->u64; } in MEM_read64()
319 MEM_STATIC void MEM_write16(void* memPtr, U16 value) { ((unalign*)memPtr)->u16 = value; } in MEM_write16()
440 Copyright (C) 2013-2016, Yann Collet.
442 BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
468 - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
480 * Since link-time-optimization is not available for all compilers,
492 /*-********************************************
516 /*-****************************************
524 /*-**************************************************************
548 /*-********************************************************
561 if (srcSize >= sizeof(bitD->bitContainer)) { /* normal case */ in BITv07_initDStream()
562 bitD->start = (const char*)srcBuffer; in BITv07_initDStream()
563 bitD->ptr = (const char*)srcBuffer + srcSize - sizeof(bitD->bitContainer); in BITv07_initDStream()
564 bitD->bitContainer = MEM_readLEST(bitD->ptr); in BITv07_initDStream()
565 { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1]; in BITv07_initDStream()
566 bitD->bitsConsumed = lastByte ? 8 - BITv07_highbit32(lastByte) : 0; in BITv07_initDStream()
569 bitD->start = (const char*)srcBuffer; in BITv07_initDStream()
570 bitD->ptr = bitD->start; in BITv07_initDStream()
571 bitD->bitContainer = *(const BYTE*)(bitD->start); in BITv07_initDStream()
574 …case 7: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[6]) << (sizeof(bitD->bitContaine… in BITv07_initDStream()
575 …case 6: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[5]) << (sizeof(bitD->bitContaine… in BITv07_initDStream()
576 …case 5: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[4]) << (sizeof(bitD->bitContaine… in BITv07_initDStream()
577 … case 4: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[3]) << 24; /* fall-through */ in BITv07_initDStream()
578 … case 3: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[2]) << 16; /* fall-through */ in BITv07_initDStream()
579 … case 2: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[1]) << 8; /* fall-through */ in BITv07_initDStream()
582 { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1]; in BITv07_initDStream()
583 bitD->bitsConsumed = lastByte ? 8 - BITv07_highbit32(lastByte) : 0; in BITv07_initDStream()
585 bitD->bitsConsumed += (U32)(sizeof(bitD->bitContainer) - srcSize)*8; in BITv07_initDStream()
594 U32 const bitMask = sizeof(bitD->bitContainer)*8 - 1; in BITv07_lookBits()
595 …return ((bitD->bitContainer << (bitD->bitsConsumed & bitMask)) >> 1) >> ((bitMask-nbBits) & bitMas… in BITv07_lookBits()
602 U32 const bitMask = sizeof(bitD->bitContainer)*8 - 1; in BITv07_lookBitsFast()
603 … return (bitD->bitContainer << (bitD->bitsConsumed & bitMask)) >> (((bitMask+1)-nbBits) & bitMask); in BITv07_lookBitsFast()
608 bitD->bitsConsumed += nbBits; in BITv07_skipBits()
629 …if (bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8)) /* should not happen => corruption detec… in BITv07_reloadDStream()
632 if (bitD->ptr >= bitD->start + sizeof(bitD->bitContainer)) { in BITv07_reloadDStream()
633 bitD->ptr -= bitD->bitsConsumed >> 3; in BITv07_reloadDStream()
634 bitD->bitsConsumed &= 7; in BITv07_reloadDStream()
635 bitD->bitContainer = MEM_readLEST(bitD->ptr); in BITv07_reloadDStream()
638 if (bitD->ptr == bitD->start) { in BITv07_reloadDStream()
639 if (bitD->bitsConsumed < sizeof(bitD->bitContainer)*8) return BITv07_DStream_endOfBuffer; in BITv07_reloadDStream()
642 { U32 nbBytes = bitD->bitsConsumed >> 3; in BITv07_reloadDStream()
644 if (bitD->ptr - nbBytes < bitD->start) { in BITv07_reloadDStream()
645 nbBytes = (U32)(bitD->ptr - bitD->start); /* ptr > start */ in BITv07_reloadDStream()
648 bitD->ptr -= nbBytes; in BITv07_reloadDStream()
649 bitD->bitsConsumed -= nbBytes*8; in BITv07_reloadDStream()
650 bitD->bitContainer = MEM_readLEST(bitD->ptr); /* reminder : srcSize > sizeof(bitD) */ in BITv07_reloadDStream()
660 …return ((DStream->ptr == DStream->start) && (DStream->bitsConsumed == sizeof(DStream->bitContainer… in BITv07_endOfDStream()
671 Copyright (C) 2013-2016, Yann Collet.
673 BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
699 - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
710 /*-****************************************
720 ** Important ** : FSEv07_decompress() does not decompress non-compressible nor RLE data !!!
733 /*-*****************************************
742 The following API allows targeting specific sub-functions for advanced tasks.
777 ----------
778 (Note : these functions only decompress FSE-compressed blocks.
876 DStatePtr->state = BITv07_readBits(bitD, DTableH->tableLog); in FSEv07_initDState()
878 DStatePtr->table = dt + 1; in FSEv07_initDState()
883 FSEv07_decode_t const DInfo = ((const FSEv07_decode_t*)(DStatePtr->table))[DStatePtr->state]; in FSEv07_peekSymbol()
889 FSEv07_decode_t const DInfo = ((const FSEv07_decode_t*)(DStatePtr->table))[DStatePtr->state]; in FSEv07_updateState()
892 DStatePtr->state = DInfo.newState + lowBits; in FSEv07_updateState()
897 FSEv07_decode_t const DInfo = ((const FSEv07_decode_t*)(DStatePtr->table))[DStatePtr->state]; in FSEv07_decodeSymbol()
902 DStatePtr->state = DInfo.newState + lowBits; in FSEv07_decodeSymbol()
910 FSEv07_decode_t const DInfo = ((const FSEv07_decode_t*)(DStatePtr->table))[DStatePtr->state]; in FSEv07_decodeSymbolFast()
915 DStatePtr->state = DInfo.newState + lowBits; in FSEv07_decodeSymbolFast()
927 * Memory usage formula : N->2^N Bytes (examples : 10 -> 1KB; 12 -> 4KB ; 16 -> 64KB; 20 -> 1MB; et…
954 #define FSEv07_MAX_TABLELOG (FSEv07_MAX_MEMORY_USAGE-2)
956 #define FSEv07_MAXTABLESIZE_MASK (FSEv07_MAX_TABLESIZE-1)
957 #define FSEv07_DEFAULT_TABLELOG (FSEv07_DEFAULT_MEMORY_USAGE-2)
979 Copyright (C) 2013-2016, Yann Collet.
981 BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1007 - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
1064 #define HUFv07_BLOCKBOUND(size) (size + (size>>8) + 8) /* only true if incompressible pre-filtere…
1070 … HUFv07_DTable DTable[HUFv07_DTABLE_SIZE((maxTableLog)-1)] = { ((U32)((maxTableLog)-1)*0x1000001) }
1078 …4X2 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< single-symbol decoder */
1079 …X4 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< double-symbols decoder */
1083 …ctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< single-symbol decoder */
1084 …tx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< double-symbols decoder */
1087 …ctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< single-symbol decoder */
1088 …tx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< double-symbols decoder */
1095 The following API allows targeting specific sub-functions for advanced tasks.
1113 1. select the decompression algorithm (X2, X4) based on pre-computed heuristics
1120 * based on a set of pre-determined metrics.
1134 …ss1X2 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /* single-symbol decoder */
1135 …ss1X4 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /* double-symbol decoder */
1154 BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1180 - FSE+HUF source repository : https://github.com/Cyan4973/FiniteStateEntropy
1181 - Public forum : https://groups.google.com/forum/#!forum/lz4c
1186 /*-****************************************
1202 /*-**************************************************************
1203 * FSE NCount encoding-decoding
1205 static short FSEv07_abs(short a) { return (short)(a<0 ? -a : a); } in FSEv07_abs()
1237 if (ip < iend-5) { in FSEv07_readNCount()
1253 if ((ip <= iend-7) || (ip + (bitCount>>3) <= iend-4)) { in FSEv07_readNCount()
1261 { short const max = (short)((2*threshold-1)-remaining); in FSEv07_readNCount()
1264 if ((bitStream & (threshold-1)) < (U32)max) { in FSEv07_readNCount()
1265 count = (short)(bitStream & (threshold-1)); in FSEv07_readNCount()
1266 bitCount += nbBits-1; in FSEv07_readNCount()
1268 count = (short)(bitStream & (2*threshold-1)); in FSEv07_readNCount()
1269 if (count >= threshold) count -= max; in FSEv07_readNCount()
1273 count--; /* extra accuracy */ in FSEv07_readNCount()
1274 remaining -= FSEv07_abs(count); in FSEv07_readNCount()
1278 nbBits--; in FSEv07_readNCount()
1282 if ((ip <= iend-7) || (ip + (bitCount>>3) <= iend-4)) { in FSEv07_readNCount()
1286 bitCount -= (int)(8 * (iend - 4 - ip)); in FSEv07_readNCount()
1287 ip = iend - 4; in FSEv07_readNCount()
1292 *maxSVPtr = charnum-1; in FSEv07_readNCount()
1295 if ((size_t)(ip-istart) > hbSize) return ERROR(srcSize_wrong); in FSEv07_readNCount()
1296 return ip-istart; in FSEv07_readNCount()
1322 oSize = l[iSize-242]; in HUFv07_readStats()
1327 oSize = iSize - 127; in HUFv07_readStats()
1339 …oSize = FSEv07_decompress(huffWeight, hwSize-1, ip+1, iSize); /* max (hwSize-1) values decoded, … in HUFv07_readStats()
1353 /* get last non-null symbol weight (implied, total must be 2^n) */ in HUFv07_readStats()
1359 U32 const rest = total - weightTotal; in HUFv07_readStats()
1376 Copyright (C) 2013-2015, Yann Collet.
1378 BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1404 - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy
1405 - Public forum : https://groups.google.com/forum/#!forum/lz4c
1416 # pragma warning(disable : 4214) /* disable: C4214: non-int bitfields */
1448 for type-specific functions (template emulation in C)
1480 void* const tdPtr = dt+1; /* because *dt is unsigned, 32-bits aligned on 32-bits */ in FSEv07_buildDTable()
1486 U32 highThreshold = tableSize-1; in FSEv07_buildDTable()
1496 { S16 const largeLimit= (S16)(1 << (tableLog-1)); in FSEv07_buildDTable()
1499 if (normalizedCounter[s]==-1) { in FSEv07_buildDTable()
1500 tableDecode[highThreshold--].symbol = (FSEv07_FUNCTION_TYPE)s; in FSEv07_buildDTable()
1510 { U32 const tableMask = tableSize-1; in FSEv07_buildDTable()
1529 tableDecode[u].nbBits = (BYTE) (tableLog - BITv07_highbit32 ((U32)nextState) ); in FSEv07_buildDTable()
1530 tableDecode[u].newState = (U16) ( (nextState << tableDecode[u].nbBits) - tableSize); in FSEv07_buildDTable()
1540 /*-*******************************************************
1550 DTableH->tableLog = 0; in FSEv07_buildDTable_rle()
1551 DTableH->fastMode = 0; in FSEv07_buildDTable_rle()
1553 cell->newState = 0; in FSEv07_buildDTable_rle()
1554 cell->symbol = symbolValue; in FSEv07_buildDTable_rle()
1555 cell->nbBits = 0; in FSEv07_buildDTable_rle()
1568 const unsigned tableMask = tableSize - 1; in FSEv07_buildDTable_raw()
1576 DTableH->tableLog = (U16)nbBits; in FSEv07_buildDTable_raw()
1577 DTableH->fastMode = 1; in FSEv07_buildDTable_raw()
1595 BYTE* const olimit = omax-3; in FSEv07_decompress_usingDTable_generic()
1633 if (op>(omax-2)) return ERROR(dstSize_tooSmall); in FSEv07_decompress_usingDTable_generic()
1642 if (op>(omax-2)) return ERROR(dstSize_tooSmall); in FSEv07_decompress_usingDTable_generic()
1651 return op-ostart; in FSEv07_decompress_usingDTable_generic()
1661 const U32 fastMode = DTableH->fastMode; in FSEv07_decompress_usingDTable()
1685 cSrcSize -= NCountLength; in FSEv07_decompress()
1700 Copyright (C) 2013-2016, Yann Collet.
1702 BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1728 - FSE+HUF source repository : https://github.com/Cyan4973/FiniteStateEntropy
1729 - Public forum : https://groups.google.com/forum/#!forum/lz4c
1756 /*-***************************/
1758 /*-***************************/
1770 /*-***************************/
1771 /* single-symbol decoding */
1772 /*-***************************/
1774 typedef struct { BYTE byte; BYTE nbBits; } HUFv07_DEltX2; /* single-symbol decoding */
1804 nextRankStart += (rankVal[n] << (n-1)); in HUFv07_readDTableX2()
1815 D.byte = (BYTE)n; D.nbBits = (BYTE)(tableLog + 1 - w); in HUFv07_readDTableX2()
1849 while ((BITv07_reloadDStream(bitDPtr) == BITv07_DStream_unfinished) && (p <= pEnd-4)) { in HUFv07_decodeStreamX2()
1864 return pEnd-pStart; in HUFv07_decodeStreamX2()
1908 ip += hSize; cSrcSize -= hSize; in HUFv07_decompress1X2_DCtx()
1942 size_t const length4 = cSrcSize - (length1 + length2 + length3 + 6); in HUFv07_decompress4X2_usingDTable_internal()
1969 /* 16-32 symbols per loop (4-8 symbols per stream) */ in HUFv07_decompress4X2_usingDTable_internal()
1971 for ( ; (endSignal==BITv07_DStream_unfinished) && (op4<(oend-7)) ; ) { in HUFv07_decompress4X2_usingDTable_internal()
2031 ip += hSize; cSrcSize -= hSize; in HUFv07_decompress4X2_DCtx()
2044 /* double-symbols decoding */
2046 typedef struct { U16 sequence; BYTE nbBits; BYTE length; } HUFv07_DEltX4; /* double-symbols decodi…
2058 /* get pre-calculated rankVal */ in HUFv07_fillDTableX4Level2()
2075 const U32 nbBits = nbBitsBaseline - weight; in HUFv07_fillDTableX4Level2()
2076 const U32 length = 1 << (sizeLog-nbBits); in HUFv07_fillDTableX4Level2()
2098 …const int scaleLog = nbBitsBaseline - targetLog; /* note : targetLog >= srcLog, hence scaleLog <… in HUFv07_fillDTableX4()
2099 const U32 minBits = nbBitsBaseline - maxWeight; in HUFv07_fillDTableX4()
2108 const U32 nbBits = nbBitsBaseline - weight; in HUFv07_fillDTableX4()
2110 const U32 length = 1 << (targetLog-nbBits); in HUFv07_fillDTableX4()
2112 if (targetLog-nbBits >= minBits) { /* enough room for a second symbol */ in HUFv07_fillDTableX4()
2117 HUFv07_fillDTableX4Level2(DTable+start, targetLog-nbBits, nbBits, in HUFv07_fillDTableX4()
2119 sortedList+sortedRank, sortedListSize-sortedRank, in HUFv07_fillDTableX4()
2146 void* dtPtr = DTable+1; /* force compiler to avoid strict-aliasing */ in HUFv07_readDTableX4()
2160 … for (maxW = tableLog; rankStats[maxW]==0; maxW--) {} /* necessarily finds a solution before 0 */ in HUFv07_readDTableX4()
2186 { int const rescale = (maxTableLog-tableLog) - 1; /* tableLog <= maxTableLog */ in HUFv07_readDTableX4()
2194 { U32 const minBits = tableLog+1 - maxW; in HUFv07_readDTableX4()
2196 for (consumed = minBits; consumed < maxTableLog - minBits + 1; consumed++) { in HUFv07_readDTableX4()
2229 if (DStream->bitsConsumed < (sizeof(DStream->bitContainer)*8)) { in HUFv07_decodeLastSymbolX4()
2231 if (DStream->bitsConsumed > (sizeof(DStream->bitContainer)*8)) in HUFv07_decodeLastSymbolX4()
2232 …DStream->bitsConsumed = (sizeof(DStream->bitContainer)*8); /* ugly hack; works only because it's… in HUFv07_decodeLastSymbolX4()
2254 while ((BITv07_reloadDStream(bitDPtr) == BITv07_DStream_unfinished) && (p < pEnd-7)) { in HUFv07_decodeStreamX4()
2262 while ((BITv07_reloadDStream(bitDPtr) == BITv07_DStream_unfinished) && (p <= pEnd-2)) in HUFv07_decodeStreamX4()
2265 while (p <= pEnd-2) in HUFv07_decodeStreamX4()
2271 return p-pStart; in HUFv07_decodeStreamX4()
2290 const void* const dtPtr = DTable+1; /* force compiler to not use strict-aliasing */ in HUFv07_decompress1X4_usingDTable_internal()
2320 ip += hSize; cSrcSize -= hSize; in HUFv07_decompress1X4_DCtx()
2352 size_t const length4 = cSrcSize - (length1 + length2 + length3 + 6); in HUFv07_decompress4X4_usingDTable_internal()
2379 /* 16-32 symbols per loop (4-8 symbols per stream) */ in HUFv07_decompress4X4_usingDTable_internal()
2381 for ( ; (endSignal==BITv07_DStream_unfinished) && (op4<(oend-7)) ; ) { in HUFv07_decompress4X4_usingDTable_internal()
2442 ip += hSize; cSrcSize -= hSize; in HUFv07_decompress4X4_DCtx()
2483 {{ 38,130}, {1313, 74}, {2151, 38}}, /* Q == 2 : 12-18% */
2484 {{ 448,128}, {1353, 74}, {2238, 41}}, /* Q == 3 : 18-25% */
2485 {{ 556,128}, {1353, 74}, {2238, 47}}, /* Q == 4 : 25-32% */
2486 {{ 714,128}, {1418, 74}, {2436, 53}}, /* Q == 5 : 32-38% */
2487 {{ 883,128}, {1437, 74}, {2464, 61}}, /* Q == 6 : 38-44% */
2488 {{ 897,128}, {1515, 75}, {2622, 68}}, /* Q == 7 : 44-50% */
2489 {{ 926,128}, {1613, 75}, {2730, 75}}, /* Q == 8 : 50-56% */
2490 {{ 947,128}, {1729, 77}, {3359, 77}}, /* Q == 9 : 56-62% */
2491 {{1107,128}, {2083, 81}, {4006, 84}}, /* Q ==10 : 62-69% */
2492 {{1177,128}, {2379, 87}, {4785, 88}}, /* Q ==11 : 69-75% */
2493 {{1242,128}, {2415, 93}, {5155, 84}}, /* Q ==12 : 75-81% */
2494 {{1349,128}, {2644,106}, {5260,106}}, /* Q ==13 : 81-87% */
2495 {{1455,128}, {2422,124}, {4174,124}}, /* Q ==14 : 87-93% */
2496 {{ 722,128}, {1891,145}, {1936,146}}, /* Q ==15 : 93-99% */
2501 * based on a set of pre-determined metrics.
2533 …/* return HUFv07_decompress4X2(dst, dstSize, cSrc, cSrcSize); */ /* multi-streams single-symbol … in HUFv07_decompress()
2534 …/* return HUFv07_decompress4X4(dst, dstSize, cSrc, cSrcSize); */ /* multi-streams double-symbols… in HUFv07_decompress()
2578 Copyright (C) 2015-2016, Yann Collet.
2580 BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
2604 - zstd homepage : http://www.zstd.net/
2609 /*-****************************************
2646 zstd_internal - common functions to include
2648 Copyright (C) 2014-2016, Yann Collet.
2650 BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
2674 - zstd homepage : https://www.zstd.net
2680 /*-*************************************
2687 /*-*************************************
2695 #define ZSTDv07_REP_MOVE (ZSTDv07_REP_NUM-1)
2718 …/*litCSize*/ + 1 /* RLE or RAW */ + MIN_SEQUENCES_SIZE /* nbSeq==0 */) /* for a non-null block */
2729 #define MaxLit ((1<<Litbits) - 1)
2743 #define ZSTD_CONTENTSIZE_ERROR (0ULL - 2)
2750 -1,-1,-1,-1 };
2759 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,-1,-1,
2760 -1,-1,-1,-1,-1 };
2764 1, 1, 1, 1, 1, 1, 1, 1,-1,-1,-1,-1,-1 };
2768 /*-*******************************************
2788 /*-*******************************************
2854 zstd - standard compression library
2855 Copyright (C) 2014-2016, Yann Collet.
2857 BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
2881 - zstd homepage : http://www.zstd.net
2897 /*-*******************************************************
2908 /*-*************************************
2922 /*-*************************************************************
2964 dctx->expected = ZSTDv07_frameHeaderSize_min; in ZSTDv07_decompressBegin()
2965 dctx->stage = ZSTDds_getFrameHeaderSize; in ZSTDv07_decompressBegin()
2966 dctx->previousDstEnd = NULL; in ZSTDv07_decompressBegin()
2967 dctx->base = NULL; in ZSTDv07_decompressBegin()
2968 dctx->vBase = NULL; in ZSTDv07_decompressBegin()
2969 dctx->dictEnd = NULL; in ZSTDv07_decompressBegin()
2970 dctx->hufTable[0] = (HUFv07_DTable)((HufLog)*0x1000001); in ZSTDv07_decompressBegin()
2971 dctx->litEntropy = dctx->fseEntropy = 0; in ZSTDv07_decompressBegin()
2972 dctx->dictID = 0; in ZSTDv07_decompressBegin()
2973 { int i; for (i=0; i<ZSTDv07_REP_NUM; i++) dctx->rep[i] = repStartValue[i]; } in ZSTDv07_decompressBegin()
2989 memcpy(&dctx->customMem, &customMem, sizeof(ZSTDv07_customMem)); in ZSTDv07_createDCtx_advanced()
3002 dctx->customMem.customFree(dctx->customMem.opaque, dctx); in ZSTDv07_freeDCtx()
3009 …sizeof(ZSTDv07_DCtx) - (ZSTDv07_BLOCKSIZE_ABSOLUTEMAX+WILDCOPY_OVERLENGTH + ZSTDv07_frameHeaderSiz… in ZSTDv07_copyDCtx()
3013 /*-*************************************************************
3018 Frame Header - [ Block Header - Block ] - Frame End
3020 - 4 bytes - Magic Number : ZSTDv07_MAGICNUMBER (defined within zstd.h)
3021 - 1 byte - Frame Descriptor
3023 - 3 bytes, starting with a 2-bits descriptor
3028 - 3 bytes, compatible with Block Header
3034 1 byte - FrameHeaderDescription :
3035 bit 0-1 : dictID (0, 1, 2 or 4 bytes)
3040 bit 6-7 : FrameContentFieldSize (0, 2, 4, or 8)
3044 bit 0-2 : octal Fractional (1/8th)
3045 bit 3-7 : Power of 2, with 0 = 1 KB (up to 2 TB)
3050 1 : 1 - 255
3051 2 : 256 - 65535
3056 1 : 0-255 bytes (fcfs==0 and swl==1)
3057 2 : 256 - 65535+256 (fcfs==1)
3058 4 : 0 - 4GB-1 (fcfs==2)
3059 8 : 0 - 16EB-1 (fcfs==3)
3065 Block = Literal Section - Sequences Section
3070 1.1) Header : 1-5 bytes
3079 1.1.1) Huff0-compressed literal block : 3-5 bytes
3080 srcSize < 1 KB => 3 bytes (2-2-10-10) => single stream
3081 srcSize < 1 KB => 3 bytes (2-2-10-10)
3082 srcSize < 16KB => 4 bytes (2-2-14-14)
3083 else => 5 bytes (2-2-18-18)
3086 1.1.2) Raw (uncompressed) literal block header : 1-3 bytes
3094 1.1.3) Rle (repeated single byte) literal block header : 1-3 bytes
3102 1.1.4) Huff0-compressed literal block, using precomputed CTables : 3-5 bytes
3103 srcSize < 1 KB => 3 bytes (2-2-10-10) => single stream
3104 srcSize < 1 KB => 3 bytes (2-2-10-10)
3105 srcSize < 16KB => 4 bytes (2-2-14-14)
3106 else => 5 bytes (2-2-18-18)
3109 1- CTable available (stored into workspace ?)
3110 2- Small input (fast heuristic ? Full comparison ? depend on clevel ?)
3159 fparamsPtr->frameContentSize = MEM_readLE32((const char *)src + 4); in ZSTDv07_getFrameParams()
3160 fparamsPtr->windowSize = 0; /* windowSize==0 means a frame is skippable */ in ZSTDv07_getFrameParams()
3210 fparamsPtr->frameContentSize = frameContentSize; in ZSTDv07_getFrameParams()
3211 fparamsPtr->windowSize = windowSize; in ZSTDv07_getFrameParams()
3212 fparamsPtr->dictID = dictID; in ZSTDv07_getFrameParams()
3213 fparamsPtr->checksumFlag = checksumFlag; in ZSTDv07_getFrameParams()
3223 - decompressed size is not provided within frame header
3224 - frame header unknown / not supported
3225 - frame header not completely provided (`srcSize` too small) */
3240 size_t const result = ZSTDv07_getFrameParams(&(dctx->fParams), src, srcSize); in ZSTDv07_decodeFrameHeader()
3241 …if (dctx->fParams.dictID && (dctx->dictID != dctx->fParams.dictID)) return ERROR(dictionary_wrong); in ZSTDv07_decodeFrameHeader()
3242 if (dctx->fParams.checksumFlag) XXH64_reset(&dctx->xxhState, 0); in ZSTDv07_decodeFrameHeader()
3262 bpPtr->blockType = (blockType_t)((*in) >> 6); in ZSTDv07_getcBlockSize()
3264 bpPtr->origSize = (bpPtr->blockType == bt_rle) ? cSize : 0; in ZSTDv07_getcBlockSize()
3266 if (bpPtr->blockType == bt_end) return 0; in ZSTDv07_getcBlockSize()
3267 if (bpPtr->blockType == bt_rle) return 1; in ZSTDv07_getcBlockSize()
3300 /* 2 - 2 - 10 - 10 */ in ZSTDv07_decodeLiteralsBlock()
3307 /* 2 - 2 - 14 - 14 */ in ZSTDv07_decodeLiteralsBlock()
3313 /* 2 - 2 - 18 - 18 */ in ZSTDv07_decodeLiteralsBlock()
3323 … HUFv07_decompress1X2_DCtx(dctx->hufTable, dctx->litBuffer, litSize, istart+lhSize, litCSize) : in ZSTDv07_decodeLiteralsBlock()
3324 … HUFv07_decompress4X_hufOnly (dctx->hufTable, dctx->litBuffer, litSize, istart+lhSize, litCSize) )) in ZSTDv07_decodeLiteralsBlock()
3327 dctx->litPtr = dctx->litBuffer; in ZSTDv07_decodeLiteralsBlock()
3328 dctx->litSize = litSize; in ZSTDv07_decodeLiteralsBlock()
3329 dctx->litEntropy = 1; in ZSTDv07_decodeLiteralsBlock()
3330 memset(dctx->litBuffer + dctx->litSize, 0, WILDCOPY_OVERLENGTH); in ZSTDv07_decodeLiteralsBlock()
3338 if (dctx->litEntropy==0) in ZSTDv07_decodeLiteralsBlock()
3341 /* 2 - 2 - 10 - 10 */ in ZSTDv07_decodeLiteralsBlock()
3347 … errorCode = HUFv07_decompress1X4_usingDTable(dctx->litBuffer, litSize, istart+lhSize, litCSize, d… in ZSTDv07_decodeLiteralsBlock()
3350 dctx->litPtr = dctx->litBuffer; in ZSTDv07_decodeLiteralsBlock()
3351 dctx->litSize = litSize; in ZSTDv07_decodeLiteralsBlock()
3352 memset(dctx->litBuffer + dctx->litSize, 0, WILDCOPY_OVERLENGTH); in ZSTDv07_decodeLiteralsBlock()
3374 memcpy(dctx->litBuffer, istart+lhSize, litSize); in ZSTDv07_decodeLiteralsBlock()
3375 dctx->litPtr = dctx->litBuffer; in ZSTDv07_decodeLiteralsBlock()
3376 dctx->litSize = litSize; in ZSTDv07_decodeLiteralsBlock()
3377 memset(dctx->litBuffer + dctx->litSize, 0, WILDCOPY_OVERLENGTH); in ZSTDv07_decodeLiteralsBlock()
3381 dctx->litPtr = istart+lhSize; in ZSTDv07_decodeLiteralsBlock()
3382 dctx->litSize = litSize; in ZSTDv07_decodeLiteralsBlock()
3403 memset(dctx->litBuffer, istart[lhSize], litSize + WILDCOPY_OVERLENGTH); in ZSTDv07_decodeLiteralsBlock()
3404 dctx->litPtr = dctx->litBuffer; in ZSTDv07_decodeLiteralsBlock()
3405 dctx->litSize = litSize; in ZSTDv07_decodeLiteralsBlock()
3468 nbSeq = ((nbSeq-0x80)<<8) + *ip++; in ZSTDv07_decodeSeqHeaders()
3482 … llhSize = ZSTDv07_buildSeqTable(DTableLL, LLtype, MaxLL, LLFSELog, ip, iend-ip, LL_defaultNorm, L… in ZSTDv07_decodeSeqHeaders()
3486 …Size = ZSTDv07_buildSeqTable(DTableOffb, OFtype, MaxOff, OffFSELog, ip, iend-ip, OF_defaultNorm, O… in ZSTDv07_decodeSeqHeaders()
3490 … mlhSize = ZSTDv07_buildSeqTable(DTableML, MLtype, MaxML, MLFSELog, ip, iend-ip, ML_defaultNorm, M… in ZSTDv07_decodeSeqHeaders()
3495 return ip-istart; in ZSTDv07_decodeSeqHeaders()
3518 U32 const llCode = FSEv07_peekSymbol(&(seqState->stateLL)); in ZSTDv07_decodeSequence()
3519 U32 const mlCode = FSEv07_peekSymbol(&(seqState->stateML)); in ZSTDv07_decodeSequence()
3520 …U32 const ofCode = FSEv07_peekSymbol(&(seqState->stateOffb)); /* <= maxOff, by table constructio… in ZSTDv07_decodeSequence()
3549 …set = OF_base[ofCode] + BITv07_readBits(&(seqState->DStream), ofBits); /* <= (ZSTDv07_WINDOWLOG… in ZSTDv07_decodeSequence()
3550 if (MEM_32bits()) BITv07_reloadDStream(&(seqState->DStream)); in ZSTDv07_decodeSequence()
3554 if ((llCode == 0) & (offset <= 1)) offset = 1-offset; in ZSTDv07_decodeSequence()
3556 size_t const temp = seqState->prevOffset[offset]; in ZSTDv07_decodeSequence()
3557 if (offset != 1) seqState->prevOffset[2] = seqState->prevOffset[1]; in ZSTDv07_decodeSequence()
3558 seqState->prevOffset[1] = seqState->prevOffset[0]; in ZSTDv07_decodeSequence()
3559 seqState->prevOffset[0] = offset = temp; in ZSTDv07_decodeSequence()
3561 offset = seqState->prevOffset[0]; in ZSTDv07_decodeSequence()
3564 seqState->prevOffset[2] = seqState->prevOffset[1]; in ZSTDv07_decodeSequence()
3565 seqState->prevOffset[1] = seqState->prevOffset[0]; in ZSTDv07_decodeSequence()
3566 seqState->prevOffset[0] = offset; in ZSTDv07_decodeSequence()
3571 …seq.matchLength = ML_base[mlCode] + ((mlCode>31) ? BITv07_readBits(&(seqState->DStream), mlBits) :… in ZSTDv07_decodeSequence()
3572 if (MEM_32bits() && (mlBits+llBits>24)) BITv07_reloadDStream(&(seqState->DStream)); in ZSTDv07_decodeSequence()
3574 …seq.litLength = LL_base[llCode] + ((llCode>15) ? BITv07_readBits(&(seqState->DStream), llBits) : 0… in ZSTDv07_decodeSequence()
3576 … (totalBits > 64 - 7 - (LLFSELog+MLFSELog+OffFSELog)) ) BITv07_reloadDStream(&(seqState->DStream)); in ZSTDv07_decodeSequence()
3579 FSEv07_updateState(&(seqState->stateLL), &(seqState->DStream)); /* <= 9 bits */ in ZSTDv07_decodeSequence()
3580 FSEv07_updateState(&(seqState->stateML), &(seqState->DStream)); /* <= 9 bits */ in ZSTDv07_decodeSequence()
3581 if (MEM_32bits()) BITv07_reloadDStream(&(seqState->DStream)); /* <= 18 bits */ in ZSTDv07_decodeSequence()
3582 FSEv07_updateState(&(seqState->stateOffb), &(seqState->DStream)); /* <= 8 bits */ in ZSTDv07_decodeSequence()
3596 BYTE* const oMatchEnd = op + sequenceLength; /* risk : address space overflow (32-bits) */ in ZSTDv07_execSequence()
3597 BYTE* const oend_w = oend-WILDCOPY_OVERLENGTH; in ZSTDv07_execSequence()
3599 const BYTE* match = oLitEnd - sequence.offset; in ZSTDv07_execSequence()
3603 if (iLitEnd > litLimit) return ERROR(corruption_detected); /* over-read beyond lit buffer */ in ZSTDv07_execSequence()
3606 …ZSTDv07_wildcopy(op, *litPtr, sequence.litLength); /* note : since oLitEnd <= oend-WILDCOPY_OVER… in ZSTDv07_execSequence()
3611 if (sequence.offset > (size_t)(oLitEnd - base)) { in ZSTDv07_execSequence()
3613 if (sequence.offset > (size_t)(oLitEnd - vBase)) return ERROR(corruption_detected); in ZSTDv07_execSequence()
3614 match = dictEnd - (base-match); in ZSTDv07_execSequence()
3620 { size_t const length1 = dictEnd - match; in ZSTDv07_execSequence()
3623 sequence.matchLength -= length1; in ZSTDv07_execSequence()
3644 match -= sub2; in ZSTDv07_execSequence()
3650 if (oMatchEnd > oend-(16-MINMATCH)) { in ZSTDv07_execSequence()
3652 ZSTDv07_wildcopy(op, match, oend_w - op); in ZSTDv07_execSequence()
3653 match += oend_w - op; in ZSTDv07_execSequence()
3658 …ZSTDv07_wildcopy(op, match, (ptrdiff_t)sequence.matchLength-8); /* works even if matchLength < 8… in ZSTDv07_execSequence()
3674 const BYTE* litPtr = dctx->litPtr; in ZSTDv07_decompressSequences()
3675 const BYTE* const litEnd = litPtr + dctx->litSize; in ZSTDv07_decompressSequences()
3676 FSEv07_DTable* DTableLL = dctx->LLTable; in ZSTDv07_decompressSequences()
3677 FSEv07_DTable* DTableML = dctx->MLTable; in ZSTDv07_decompressSequences()
3678 FSEv07_DTable* DTableOffb = dctx->OffTable; in ZSTDv07_decompressSequences()
3679 const BYTE* const base = (const BYTE*) (dctx->base); in ZSTDv07_decompressSequences()
3680 const BYTE* const vBase = (const BYTE*) (dctx->vBase); in ZSTDv07_decompressSequences()
3681 const BYTE* const dictEnd = (const BYTE*) (dctx->dictEnd); in ZSTDv07_decompressSequences()
3685 …Size = ZSTDv07_decodeSeqHeaders(&nbSeq, DTableLL, DTableML, DTableOffb, dctx->fseEntropy, ip, seqS… in ZSTDv07_decompressSequences()
3693 dctx->fseEntropy = 1; in ZSTDv07_decompressSequences()
3694 { U32 i; for (i=0; i<ZSTDv07_REP_INIT; i++) seqState.prevOffset[i] = dctx->rep[i]; } in ZSTDv07_decompressSequences()
3695 { size_t const errorCode = BITv07_initDStream(&(seqState.DStream), ip, iend-ip); in ZSTDv07_decompressSequences()
3702 nbSeq--; in ZSTDv07_decompressSequences()
3712 { U32 i; for (i=0; i<ZSTDv07_REP_INIT; i++) dctx->rep[i] = (U32)(seqState.prevOffset[i]); } in ZSTDv07_decompressSequences()
3716 { size_t const lastLLSize = litEnd - litPtr; in ZSTDv07_decompressSequences()
3718 if (lastLLSize > (size_t)(oend-op)) return ERROR(dstSize_tooSmall); in ZSTDv07_decompressSequences()
3725 return op-ostart; in ZSTDv07_decompressSequences()
3731 if (dst != dctx->previousDstEnd) { /* not contiguous */ in ZSTDv07_checkContinuity()
3732 dctx->dictEnd = dctx->previousDstEnd; in ZSTDv07_checkContinuity()
3733 …dctx->vBase = (const char*)dst - ((const char*)(dctx->previousDstEnd) - (const char*)(dctx->base)); in ZSTDv07_checkContinuity()
3734 dctx->base = dst; in ZSTDv07_checkContinuity()
3735 dctx->previousDstEnd = dst; in ZSTDv07_checkContinuity()
3748 /* Decode literals sub-block */ in ZSTDv07_decompressBlock_internal()
3752 srcSize -= litCSize; in ZSTDv07_decompressBlock_internal()
3765 dctx->previousDstEnd = (char*)dst + dSize; in ZSTDv07_decompressBlock()
3775 dctx->previousDstEnd = (const char*)blockStart + blockSize; in ZSTDv07_insertBlock()
3811 ip += frameHeaderSize; remainingSize -= frameHeaderSize; in ZSTDv07_decompressFrame()
3818 size_t const cBlockSize = ZSTDv07_getcBlockSize(ip, iend-ip, &blockProperties); in ZSTDv07_decompressFrame()
3822 remainingSize -= ZSTDv07_blockHeaderSize; in ZSTDv07_decompressFrame()
3828 decodedSize = ZSTDv07_decompressBlock_internal(dctx, op, oend-op, ip, cBlockSize); in ZSTDv07_decompressFrame()
3831 decodedSize = ZSTDv07_copyRawBlock(op, oend-op, ip, cBlockSize); in ZSTDv07_decompressFrame()
3834 decodedSize = ZSTDv07_generateNxBytes(op, oend-op, *ip, blockProperties.origSize); in ZSTDv07_decompressFrame()
3847 if (dctx->fParams.checksumFlag) XXH64_update(&dctx->xxhState, op, decodedSize); in ZSTDv07_decompressFrame()
3850 remainingSize -= cBlockSize; in ZSTDv07_decompressFrame()
3853 return op-ostart; in ZSTDv07_decompressFrame()
3938 ip += frameHeaderSize; remainingSize -= frameHeaderSize; in ZSTDv07_findFrameSizeInfoLegacy()
3951 remainingSize -= ZSTDv07_blockHeaderSize; in ZSTDv07_findFrameSizeInfoLegacy()
3961 remainingSize -= cBlockSize; in ZSTDv07_findFrameSizeInfoLegacy()
3965 *cSize = ip - (const BYTE*)src; in ZSTDv07_findFrameSizeInfoLegacy()
3974 return dctx->expected; in ZSTDv07_nextSrcSizeToDecompress()
3979 return dctx->stage == ZSTDds_skipFrame; in ZSTDv07_isSkipFrame()
3988 if (srcSize != dctx->expected) return ERROR(srcSize_wrong); in ZSTDv07_decompressContinue()
3991 switch (dctx->stage) in ZSTDv07_decompressContinue()
3996 memcpy(dctx->headerBuffer, src, ZSTDv07_frameHeaderSize_min); in ZSTDv07_decompressContinue()
3997 …dctx->expected = ZSTDv07_skippableHeaderSize - ZSTDv07_frameHeaderSize_min; /* magic number + skip… in ZSTDv07_decompressContinue()
3998 dctx->stage = ZSTDds_decodeSkippableHeader; in ZSTDv07_decompressContinue()
4001 dctx->headerSize = ZSTDv07_frameHeaderSize(src, ZSTDv07_frameHeaderSize_min); in ZSTDv07_decompressContinue()
4002 if (ZSTDv07_isError(dctx->headerSize)) return dctx->headerSize; in ZSTDv07_decompressContinue()
4003 memcpy(dctx->headerBuffer, src, ZSTDv07_frameHeaderSize_min); in ZSTDv07_decompressContinue()
4004 if (dctx->headerSize > ZSTDv07_frameHeaderSize_min) { in ZSTDv07_decompressContinue()
4005 dctx->expected = dctx->headerSize - ZSTDv07_frameHeaderSize_min; in ZSTDv07_decompressContinue()
4006 dctx->stage = ZSTDds_decodeFrameHeader; in ZSTDv07_decompressContinue()
4009 dctx->expected = 0; /* not necessary to copy more */ in ZSTDv07_decompressContinue()
4010 /* fall-through */ in ZSTDv07_decompressContinue()
4013 memcpy(dctx->headerBuffer + ZSTDv07_frameHeaderSize_min, src, dctx->expected); in ZSTDv07_decompressContinue()
4014 result = ZSTDv07_decodeFrameHeader(dctx, dctx->headerBuffer, dctx->headerSize); in ZSTDv07_decompressContinue()
4016 dctx->expected = ZSTDv07_blockHeaderSize; in ZSTDv07_decompressContinue()
4017 dctx->stage = ZSTDds_decodeBlockHeader; in ZSTDv07_decompressContinue()
4025 if (dctx->fParams.checksumFlag) { in ZSTDv07_decompressContinue()
4026 U64 const h64 = XXH64_digest(&dctx->xxhState); in ZSTDv07_decompressContinue()
4027 U32 const h32 = (U32)(h64>>11) & ((1<<22)-1); in ZSTDv07_decompressContinue()
4032 dctx->expected = 0; in ZSTDv07_decompressContinue()
4033 dctx->stage = ZSTDds_getFrameHeaderSize; in ZSTDv07_decompressContinue()
4035 dctx->expected = cBlockSize; in ZSTDv07_decompressContinue()
4036 dctx->bType = bp.blockType; in ZSTDv07_decompressContinue()
4037 dctx->stage = ZSTDds_decompressBlock; in ZSTDv07_decompressContinue()
4043 switch(dctx->bType) in ZSTDv07_decompressContinue()
4060 dctx->stage = ZSTDds_decodeBlockHeader; in ZSTDv07_decompressContinue()
4061 dctx->expected = ZSTDv07_blockHeaderSize; in ZSTDv07_decompressContinue()
4062 dctx->previousDstEnd = (char*)dst + rSize; in ZSTDv07_decompressContinue()
4064 if (dctx->fParams.checksumFlag) XXH64_update(&dctx->xxhState, dst, rSize); in ZSTDv07_decompressContinue()
4068 { memcpy(dctx->headerBuffer + ZSTDv07_frameHeaderSize_min, src, dctx->expected); in ZSTDv07_decompressContinue()
4069 dctx->expected = MEM_readLE32(dctx->headerBuffer + 4); in ZSTDv07_decompressContinue()
4070 dctx->stage = ZSTDds_skipFrame; in ZSTDv07_decompressContinue()
4074 { dctx->expected = 0; in ZSTDv07_decompressContinue()
4075 dctx->stage = ZSTDds_getFrameHeaderSize; in ZSTDv07_decompressContinue()
4086 dctx->dictEnd = dctx->previousDstEnd; in ZSTDv07_refDictContent()
4087 …dctx->vBase = (const char*)dict - ((const char*)(dctx->previousDstEnd) - (const char*)(dctx->base)… in ZSTDv07_refDictContent()
4088 dctx->base = dict; in ZSTDv07_refDictContent()
4089 dctx->previousDstEnd = (const char*)dict + dictSize; in ZSTDv07_refDictContent()
4098 { size_t const hSize = HUFv07_readDTableX4(dctx->hufTable, dict, dictSize); in ZSTDv07_loadEntropy()
4105 …erSize = FSEv07_readNCount(offcodeNCount, &offcodeMaxValue, &offcodeLog, dictPtr, dictEnd-dictPtr); in ZSTDv07_loadEntropy()
4108 …{ size_t const errorCode = FSEv07_buildDTable(dctx->OffTable, offcodeNCount, offcodeMaxValue, offc… in ZSTDv07_loadEntropy()
4115 …v07_readNCount(matchlengthNCount, &matchlengthMaxValue, &matchlengthLog, dictPtr, dictEnd-dictPtr); in ZSTDv07_loadEntropy()
4118 …{ size_t const errorCode = FSEv07_buildDTable(dctx->MLTable, matchlengthNCount, matchlengthMaxValu… in ZSTDv07_loadEntropy()
4125 … = FSEv07_readNCount(litlengthNCount, &litlengthMaxValue, &litlengthLog, dictPtr, dictEnd-dictPtr); in ZSTDv07_loadEntropy()
4128 …{ size_t const errorCode = FSEv07_buildDTable(dctx->LLTable, litlengthNCount, litlengthMaxValue, l… in ZSTDv07_loadEntropy()
4134 …dctx->rep[0] = MEM_readLE32(dictPtr+0); if (dctx->rep[0] == 0 || dctx->rep[0] >= dictSize) return … in ZSTDv07_loadEntropy()
4135 …dctx->rep[1] = MEM_readLE32(dictPtr+4); if (dctx->rep[1] == 0 || dctx->rep[1] >= dictSize) return … in ZSTDv07_loadEntropy()
4136 …dctx->rep[2] = MEM_readLE32(dictPtr+8); if (dctx->rep[2] == 0 || dctx->rep[2] >= dictSize) return … in ZSTDv07_loadEntropy()
4139 dctx->litEntropy = dctx->fseEntropy = 1; in ZSTDv07_loadEntropy()
4140 return dictPtr - (const BYTE*)dict; in ZSTDv07_loadEntropy()
4150 dctx->dictID = MEM_readLE32((const char*)dict + 4); in ZSTDv07_decompress_insertDictionary()
4154 dictSize -= 8; in ZSTDv07_decompress_insertDictionary()
4158 dictSize -= eSize; in ZSTDv07_decompress_insertDictionary()
4214 ddict->dict = dictContent; in ZSTDv07_createDDict_advanced()
4215 ddict->dictSize = dictSize; in ZSTDv07_createDDict_advanced()
4216 ddict->refContext = dctx; in ZSTDv07_createDDict_advanced()
4232 ZSTDv07_freeFunction const cFree = ddict->refContext->customMem.customFree; in ZSTDv07_freeDDict()
4233 void* const opaque = ddict->refContext->customMem.opaque; in ZSTDv07_freeDDict()
4234 ZSTDv07_freeDCtx(ddict->refContext); in ZSTDv07_freeDDict()
4235 cFree(opaque, ddict->dict); in ZSTDv07_freeDDict()
4241 * Decompression using a pre-digested Dictionary
4248 return ZSTDv07_decompress_usingPreparedDCtx(dctx, ddict->refContext, in ZSTDv07_decompress_usingDDict()
4254 Copyright (C) 2015-2016, Yann Collet.
4256 BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
4280 - zstd homepage : http://www.zstd.net/
4285 /*-***************************************************************************
4292 * Note that ZBUFFv07_DCtx objects can be re-init multiple times.
4350 memcpy(&zbd->customMem, &customMem, sizeof(ZSTDv07_customMem)); in ZBUFFv07_createDCtx_advanced()
4351 zbd->zd = ZSTDv07_createDCtx_advanced(customMem); in ZBUFFv07_createDCtx_advanced()
4352 if (zbd->zd == NULL) { ZBUFFv07_freeDCtx(zbd); return NULL; } in ZBUFFv07_createDCtx_advanced()
4353 zbd->stage = ZBUFFds_init; in ZBUFFv07_createDCtx_advanced()
4360 ZSTDv07_freeDCtx(zbd->zd); in ZBUFFv07_freeDCtx()
4361 if (zbd->inBuff) zbd->customMem.customFree(zbd->customMem.opaque, zbd->inBuff); in ZBUFFv07_freeDCtx()
4362 if (zbd->outBuff) zbd->customMem.customFree(zbd->customMem.opaque, zbd->outBuff); in ZBUFFv07_freeDCtx()
4363 zbd->customMem.customFree(zbd->customMem.opaque, zbd); in ZBUFFv07_freeDCtx()
4372 zbd->stage = ZBUFFds_loadHeader; in ZBUFFv07_decompressInitDictionary()
4373 zbd->lhSize = zbd->inPos = zbd->outStart = zbd->outEnd = 0; in ZBUFFv07_decompressInitDictionary()
4374 return ZSTDv07_decompressBegin_usingDict(zbd->zd, dict, dictSize); in ZBUFFv07_decompressInitDictionary()
4409 switch(zbd->stage) in ZBUFFv07_decompressContinue()
4415 … { size_t const hSize = ZSTDv07_getFrameParams(&(zbd->fParams), zbd->headerBuffer, zbd->lhSize); in ZBUFFv07_decompressContinue()
4418 … size_t const toLoad = hSize - zbd->lhSize; /* if hSize!=0, hSize > zbd->lhSize */ in ZBUFFv07_decompressContinue()
4419 if (toLoad > (size_t)(iend-ip)) { /* not enough input to load full header */ in ZBUFFv07_decompressContinue()
4420 memcpy(zbd->headerBuffer + zbd->lhSize, ip, iend-ip); in ZBUFFv07_decompressContinue()
4421 zbd->lhSize += iend-ip; in ZBUFFv07_decompressContinue()
4423 …return (hSize - zbd->lhSize) + ZSTDv07_blockHeaderSize; /* remaining header bytes + next block h… in ZBUFFv07_decompressContinue()
4425 … memcpy(zbd->headerBuffer + zbd->lhSize, ip, toLoad); zbd->lhSize = hSize; ip += toLoad; in ZBUFFv07_decompressContinue()
4430 …{ size_t const h1Size = ZSTDv07_nextSrcSizeToDecompress(zbd->zd); /* == ZSTDv07_frameHeaderSize… in ZBUFFv07_decompressContinue()
4431 … size_t const h1Result = ZSTDv07_decompressContinue(zbd->zd, NULL, 0, zbd->headerBuffer, h1Size); in ZBUFFv07_decompressContinue()
4433 if (h1Size < zbd->lhSize) { /* long header */ in ZBUFFv07_decompressContinue()
4434 size_t const h2Size = ZSTDv07_nextSrcSizeToDecompress(zbd->zd); in ZBUFFv07_decompressContinue()
4435 …size_t const h2Result = ZSTDv07_decompressContinue(zbd->zd, NULL, 0, zbd->headerBuffer+h1Size, h2S… in ZBUFFv07_decompressContinue()
4439 … zbd->fParams.windowSize = MAX(zbd->fParams.windowSize, 1U << ZSTDv07_WINDOWLOG_ABSOLUTEMIN); in ZBUFFv07_decompressContinue()
4442 … { size_t const blockSize = MIN(zbd->fParams.windowSize, ZSTDv07_BLOCKSIZE_ABSOLUTEMAX); in ZBUFFv07_decompressContinue()
4443 zbd->blockSize = blockSize; in ZBUFFv07_decompressContinue()
4444 if (zbd->inBuffSize < blockSize) { in ZBUFFv07_decompressContinue()
4445 zbd->customMem.customFree(zbd->customMem.opaque, zbd->inBuff); in ZBUFFv07_decompressContinue()
4446 zbd->inBuffSize = blockSize; in ZBUFFv07_decompressContinue()
4447 … zbd->inBuff = (char*)zbd->customMem.customAlloc(zbd->customMem.opaque, blockSize); in ZBUFFv07_decompressContinue()
4448 if (zbd->inBuff == NULL) return ERROR(memory_allocation); in ZBUFFv07_decompressContinue()
4450 … { size_t const neededOutSize = zbd->fParams.windowSize + blockSize + WILDCOPY_OVERLENGTH * 2; in ZBUFFv07_decompressContinue()
4451 if (zbd->outBuffSize < neededOutSize) { in ZBUFFv07_decompressContinue()
4452 zbd->customMem.customFree(zbd->customMem.opaque, zbd->outBuff); in ZBUFFv07_decompressContinue()
4453 zbd->outBuffSize = neededOutSize; in ZBUFFv07_decompressContinue()
4454 … zbd->outBuff = (char*)zbd->customMem.customAlloc(zbd->customMem.opaque, neededOutSize); in ZBUFFv07_decompressContinue()
4455 if (zbd->outBuff == NULL) return ERROR(memory_allocation); in ZBUFFv07_decompressContinue()
4457 zbd->stage = ZBUFFds_read; in ZBUFFv07_decompressContinue()
4458 /* pass-through */ in ZBUFFv07_decompressContinue()
4459 /* fall-through */ in ZBUFFv07_decompressContinue()
4461 { size_t const neededInSize = ZSTDv07_nextSrcSizeToDecompress(zbd->zd); in ZBUFFv07_decompressContinue()
4463 zbd->stage = ZBUFFds_init; in ZBUFFv07_decompressContinue()
4467 if ((size_t)(iend-ip) >= neededInSize) { /* decode directly from src */ in ZBUFFv07_decompressContinue()
4468 const int isSkipFrame = ZSTDv07_isSkipFrame(zbd->zd); in ZBUFFv07_decompressContinue()
4469 size_t const decodedSize = ZSTDv07_decompressContinue(zbd->zd, in ZBUFFv07_decompressContinue()
4470 … zbd->outBuff + zbd->outStart, (isSkipFrame ? 0 : zbd->outBuffSize - zbd->outStart), in ZBUFFv07_decompressContinue()
4475 zbd->outEnd = zbd->outStart + decodedSize; in ZBUFFv07_decompressContinue()
4476 zbd->stage = ZBUFFds_flush; in ZBUFFv07_decompressContinue()
4480 zbd->stage = ZBUFFds_load; in ZBUFFv07_decompressContinue()
4482 /* fall-through */ in ZBUFFv07_decompressContinue()
4484 { size_t const neededInSize = ZSTDv07_nextSrcSizeToDecompress(zbd->zd); in ZBUFFv07_decompressContinue()
4485 …size_t const toLoad = neededInSize - zbd->inPos; /* should always be <= remaining space within i… in ZBUFFv07_decompressContinue()
4487 …if (toLoad > zbd->inBuffSize - zbd->inPos) return ERROR(corruption_detected); /* should never ha… in ZBUFFv07_decompressContinue()
4488 loadedSize = ZBUFFv07_limitCopy(zbd->inBuff + zbd->inPos, toLoad, ip, iend-ip); in ZBUFFv07_decompressContinue()
4490 zbd->inPos += loadedSize; in ZBUFFv07_decompressContinue()
4494 { const int isSkipFrame = ZSTDv07_isSkipFrame(zbd->zd); in ZBUFFv07_decompressContinue()
4495 size_t const decodedSize = ZSTDv07_decompressContinue(zbd->zd, in ZBUFFv07_decompressContinue()
4496 zbd->outBuff + zbd->outStart, zbd->outBuffSize - zbd->outStart, in ZBUFFv07_decompressContinue()
4497 zbd->inBuff, neededInSize); in ZBUFFv07_decompressContinue()
4499 zbd->inPos = 0; /* input is consumed */ in ZBUFFv07_decompressContinue()
4500 …if (!decodedSize && !isSkipFrame) { zbd->stage = ZBUFFds_read; break; } /* this was just a heade… in ZBUFFv07_decompressContinue()
4501 zbd->outEnd = zbd->outStart + decodedSize; in ZBUFFv07_decompressContinue()
4502 zbd->stage = ZBUFFds_flush; in ZBUFFv07_decompressContinue()
4504 /* pass-through */ in ZBUFFv07_decompressContinue()
4507 /* fall-through */ in ZBUFFv07_decompressContinue()
4509 { size_t const toFlushSize = zbd->outEnd - zbd->outStart; in ZBUFFv07_decompressContinue()
4510 …size_t const flushedSize = ZBUFFv07_limitCopy(op, oend-op, zbd->outBuff + zbd->outStart, toFlushSi… in ZBUFFv07_decompressContinue()
4512 zbd->outStart += flushedSize; in ZBUFFv07_decompressContinue()
4514 zbd->stage = ZBUFFds_read; in ZBUFFv07_decompressContinue()
4515 if (zbd->outStart + zbd->blockSize > zbd->outBuffSize) in ZBUFFv07_decompressContinue()
4516 zbd->outStart = zbd->outEnd = 0; in ZBUFFv07_decompressContinue()
4527 *srcSizePtr = ip-istart; in ZBUFFv07_decompressContinue()
4528 *dstCapacityPtr = op-ostart; in ZBUFFv07_decompressContinue()
4529 { size_t nextSrcSizeHint = ZSTDv07_nextSrcSizeToDecompress(zbd->zd); in ZBUFFv07_decompressContinue()
4530 nextSrcSizeHint -= zbd->inPos; /* already loaded*/ in ZBUFFv07_decompressContinue()