Mercurial > hg
annotate contrib/python-zstandard/zstd/compress/zstd_compress.c @ 35654:59c842a3d1e1
hgweb: remove unused second argument of nextPageVarGet()
nextPageVarGet is a function that's used in ajaxScrollInit() to produce URL of
the next page. Before f84b01257e06, its second argument previousVal was a
number on /graph pages, and the code was simply adding 60 to it and returning
the resulting value. Now previousVal can only be a string containing changeset
hash, which can't be used the same way (and in fact isn't used in any way).
author | Anton Shestakov <av6@dwimlabs.net> |
---|---|
date | Mon, 15 Jan 2018 19:44:18 +0800 |
parents | c32454d69b85 |
children | b1fb341d8a61 |
rev | line source |
---|---|
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1 /** |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3 * All rights reserved. |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
4 * |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
5 * This source code is licensed under the BSD-style license found in the |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
6 * LICENSE file in the root directory of this source tree. An additional grant |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
7 * of patent rights can be found in the PATENTS file in the same directory. |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
8 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
9 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
10 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
11 /*-************************************* |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
12 * Dependencies |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
13 ***************************************/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
14 #include <string.h> /* memset */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
15 #include "mem.h" |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
16 #define XXH_STATIC_LINKING_ONLY /* XXH64_state_t */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
17 #include "xxhash.h" /* XXH_reset, update, digest */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
18 #define FSE_STATIC_LINKING_ONLY /* FSE_encodeSymbol */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
19 #include "fse.h" |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
20 #define HUF_STATIC_LINKING_ONLY |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
21 #include "huf.h" |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
22 #include "zstd_internal.h" /* includes zstd.h */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
23 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
24 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
25 /*-************************************* |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
26 * Constants |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
27 ***************************************/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
28 static const U32 g_searchStrength = 8; /* control skip over incompressible data */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
29 #define HASH_READ_SIZE 8 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
30 typedef enum { ZSTDcs_created=0, ZSTDcs_init, ZSTDcs_ongoing, ZSTDcs_ending } ZSTD_compressionStage_e; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
31 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
32 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
33 /*-************************************* |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
34 * Helper functions |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
35 ***************************************/ |
30822
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
36 #define ZSTD_STATIC_ASSERT(c) { enum { ZSTD_static_assert = 1/(int)(!!(c)) }; } |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
37 size_t ZSTD_compressBound(size_t srcSize) { return FSE_compressBound(srcSize) + 12; } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
38 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
39 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
40 /*-************************************* |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
41 * Sequence storage |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
42 ***************************************/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
43 static void ZSTD_resetSeqStore(seqStore_t* ssPtr) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
44 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
45 ssPtr->lit = ssPtr->litStart; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
46 ssPtr->sequences = ssPtr->sequencesStart; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
47 ssPtr->longLengthID = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
48 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
49 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
50 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
51 /*-************************************* |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
52 * Context memory management |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
53 ***************************************/ |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
54 struct ZSTD_CCtx_s { |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
55 const BYTE* nextSrc; /* next block here to continue on current prefix */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
56 const BYTE* base; /* All regular indexes relative to this position */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
57 const BYTE* dictBase; /* extDict indexes relative to this position */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
58 U32 dictLimit; /* below that point, need extDict */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
59 U32 lowLimit; /* below that point, no more data */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
60 U32 nextToUpdate; /* index from which to continue dictionary update */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
61 U32 nextToUpdate3; /* index from which to continue dictionary update */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
62 U32 hashLog3; /* dispatch table : larger == faster, more memory */ |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
63 U32 loadedDictEnd; /* index of end of dictionary */ |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
64 U32 forceWindow; /* force back-references to respect limit of 1<<wLog, even for dictionary */ |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
65 ZSTD_compressionStage_e stage; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
66 U32 rep[ZSTD_REP_NUM]; |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
67 U32 repToConfirm[ZSTD_REP_NUM]; |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
68 U32 dictID; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
69 ZSTD_parameters params; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
70 void* workSpace; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
71 size_t workSpaceSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
72 size_t blockSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
73 U64 frameContentSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
74 XXH64_state_t xxhState; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
75 ZSTD_customMem customMem; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
76 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
77 seqStore_t seqStore; /* sequences storage ptrs */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
78 U32* hashTable; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
79 U32* hashTable3; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
80 U32* chainTable; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
81 HUF_CElt* hufTable; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
82 U32 flagStaticTables; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
83 FSE_CTable offcodeCTable [FSE_CTABLE_SIZE_U32(OffFSELog, MaxOff)]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
84 FSE_CTable matchlengthCTable[FSE_CTABLE_SIZE_U32(MLFSELog, MaxML)]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
85 FSE_CTable litlengthCTable [FSE_CTABLE_SIZE_U32(LLFSELog, MaxLL)]; |
30822
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
86 unsigned tmpCounters[1024]; |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
87 }; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
88 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
89 ZSTD_CCtx* ZSTD_createCCtx(void) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
90 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
91 return ZSTD_createCCtx_advanced(defaultCustomMem); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
92 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
93 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
94 ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
95 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
96 ZSTD_CCtx* cctx; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
97 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
98 if (!customMem.customAlloc && !customMem.customFree) customMem = defaultCustomMem; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
99 if (!customMem.customAlloc || !customMem.customFree) return NULL; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
100 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
101 cctx = (ZSTD_CCtx*) ZSTD_malloc(sizeof(ZSTD_CCtx), customMem); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
102 if (!cctx) return NULL; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
103 memset(cctx, 0, sizeof(ZSTD_CCtx)); |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
104 cctx->customMem = customMem; |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
105 return cctx; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
106 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
107 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
108 size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
109 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
110 if (cctx==NULL) return 0; /* support free on NULL */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
111 ZSTD_free(cctx->workSpace, cctx->customMem); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
112 ZSTD_free(cctx, cctx->customMem); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
113 return 0; /* reserved as a potential error code in the future */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
114 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
115 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
116 size_t ZSTD_sizeof_CCtx(const ZSTD_CCtx* cctx) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
117 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
118 if (cctx==NULL) return 0; /* support sizeof on NULL */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
119 return sizeof(*cctx) + cctx->workSpaceSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
120 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
121 |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
122 size_t ZSTD_setCCtxParameter(ZSTD_CCtx* cctx, ZSTD_CCtxParameter param, unsigned value) |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
123 { |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
124 switch(param) |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
125 { |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
126 case ZSTD_p_forceWindow : cctx->forceWindow = value>0; cctx->loadedDictEnd = 0; return 0; |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
127 default: return ERROR(parameter_unknown); |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
128 } |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
129 } |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
130 |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
131 const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx) /* hidden interface */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
132 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
133 return &(ctx->seqStore); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
134 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
135 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
136 static ZSTD_parameters ZSTD_getParamsFromCCtx(const ZSTD_CCtx* cctx) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
137 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
138 return cctx->params; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
139 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
140 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
141 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
142 /** ZSTD_checkParams() : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
143 ensure param values remain within authorized range. |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
144 @return : 0, or an error code if one value is beyond authorized range */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
145 size_t ZSTD_checkCParams(ZSTD_compressionParameters cParams) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
146 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
147 # define CLAMPCHECK(val,min,max) { if ((val<min) | (val>max)) return ERROR(compressionParameter_unsupported); } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
148 CLAMPCHECK(cParams.windowLog, ZSTD_WINDOWLOG_MIN, ZSTD_WINDOWLOG_MAX); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
149 CLAMPCHECK(cParams.chainLog, ZSTD_CHAINLOG_MIN, ZSTD_CHAINLOG_MAX); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
150 CLAMPCHECK(cParams.hashLog, ZSTD_HASHLOG_MIN, ZSTD_HASHLOG_MAX); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
151 CLAMPCHECK(cParams.searchLog, ZSTD_SEARCHLOG_MIN, ZSTD_SEARCHLOG_MAX); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
152 { U32 const searchLengthMin = ((cParams.strategy == ZSTD_fast) | (cParams.strategy == ZSTD_greedy)) ? ZSTD_SEARCHLENGTH_MIN+1 : ZSTD_SEARCHLENGTH_MIN; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
153 U32 const searchLengthMax = (cParams.strategy == ZSTD_fast) ? ZSTD_SEARCHLENGTH_MAX : ZSTD_SEARCHLENGTH_MAX-1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
154 CLAMPCHECK(cParams.searchLength, searchLengthMin, searchLengthMax); } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
155 CLAMPCHECK(cParams.targetLength, ZSTD_TARGETLENGTH_MIN, ZSTD_TARGETLENGTH_MAX); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
156 if ((U32)(cParams.strategy) > (U32)ZSTD_btopt2) return ERROR(compressionParameter_unsupported); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
157 return 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
158 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
159 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
160 |
30822
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
161 /** ZSTD_cycleLog() : |
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
162 * condition for correct operation : hashLog > 1 */ |
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
163 static U32 ZSTD_cycleLog(U32 hashLog, ZSTD_strategy strat) |
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
164 { |
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
165 U32 const btScale = ((U32)strat >= (U32)ZSTD_btlazy2); |
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
166 return hashLog - btScale; |
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
167 } |
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
168 |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
169 /** ZSTD_adjustCParams() : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
170 optimize `cPar` for a given input (`srcSize` and `dictSize`). |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
171 mostly downsizing to reduce memory consumption and initialization. |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
172 Both `srcSize` and `dictSize` are optional (use 0 if unknown), |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
173 but if both are 0, no optimization can be done. |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
174 Note : cPar is considered validated at this stage. Use ZSTD_checkParams() to ensure that. */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
175 ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, unsigned long long srcSize, size_t dictSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
176 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
177 if (srcSize+dictSize == 0) return cPar; /* no size information available : no adjustment */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
178 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
179 /* resize params, to use less memory when necessary */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
180 { U32 const minSrcSize = (srcSize==0) ? 500 : 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
181 U64 const rSize = srcSize + dictSize + minSrcSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
182 if (rSize < ((U64)1<<ZSTD_WINDOWLOG_MAX)) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
183 U32 const srcLog = MAX(ZSTD_HASHLOG_MIN, ZSTD_highbit32((U32)(rSize)-1) + 1); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
184 if (cPar.windowLog > srcLog) cPar.windowLog = srcLog; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
185 } } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
186 if (cPar.hashLog > cPar.windowLog) cPar.hashLog = cPar.windowLog; |
30822
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
187 { U32 const cycleLog = ZSTD_cycleLog(cPar.chainLog, cPar.strategy); |
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
188 if (cycleLog > cPar.windowLog) cPar.chainLog -= (cycleLog - cPar.windowLog); |
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
189 } |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
190 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
191 if (cPar.windowLog < ZSTD_WINDOWLOG_ABSOLUTEMIN) cPar.windowLog = ZSTD_WINDOWLOG_ABSOLUTEMIN; /* required for frame header */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
192 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
193 return cPar; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
194 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
195 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
196 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
197 size_t ZSTD_estimateCCtxSize(ZSTD_compressionParameters cParams) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
198 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
199 size_t const blockSize = MIN(ZSTD_BLOCKSIZE_ABSOLUTEMAX, (size_t)1 << cParams.windowLog); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
200 U32 const divider = (cParams.searchLength==3) ? 3 : 4; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
201 size_t const maxNbSeq = blockSize / divider; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
202 size_t const tokenSpace = blockSize + 11*maxNbSeq; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
203 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
204 size_t const chainSize = (cParams.strategy == ZSTD_fast) ? 0 : (1 << cParams.chainLog); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
205 size_t const hSize = ((size_t)1) << cParams.hashLog; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
206 U32 const hashLog3 = (cParams.searchLength>3) ? 0 : MIN(ZSTD_HASHLOG3_MAX, cParams.windowLog); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
207 size_t const h3Size = ((size_t)1) << hashLog3; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
208 size_t const tableSpace = (chainSize + hSize + h3Size) * sizeof(U32); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
209 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
210 size_t const optSpace = ((MaxML+1) + (MaxLL+1) + (MaxOff+1) + (1<<Litbits))*sizeof(U32) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
211 + (ZSTD_OPT_NUM+1)*(sizeof(ZSTD_match_t) + sizeof(ZSTD_optimal_t)); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
212 size_t const neededSpace = tableSpace + (256*sizeof(U32)) /* huffTable */ + tokenSpace |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
213 + (((cParams.strategy == ZSTD_btopt) || (cParams.strategy == ZSTD_btopt2)) ? optSpace : 0); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
214 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
215 return sizeof(ZSTD_CCtx) + neededSpace; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
216 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
217 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
218 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
219 static U32 ZSTD_equivalentParams(ZSTD_parameters param1, ZSTD_parameters param2) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
220 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
221 return (param1.cParams.hashLog == param2.cParams.hashLog) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
222 & (param1.cParams.chainLog == param2.cParams.chainLog) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
223 & (param1.cParams.strategy == param2.cParams.strategy) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
224 & ((param1.cParams.searchLength==3) == (param2.cParams.searchLength==3)); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
225 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
226 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
227 /*! ZSTD_continueCCtx() : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
228 reuse CCtx without reset (note : requires no dictionary) */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
229 static size_t ZSTD_continueCCtx(ZSTD_CCtx* cctx, ZSTD_parameters params, U64 frameContentSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
230 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
231 U32 const end = (U32)(cctx->nextSrc - cctx->base); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
232 cctx->params = params; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
233 cctx->frameContentSize = frameContentSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
234 cctx->lowLimit = end; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
235 cctx->dictLimit = end; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
236 cctx->nextToUpdate = end+1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
237 cctx->stage = ZSTDcs_init; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
238 cctx->dictID = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
239 cctx->loadedDictEnd = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
240 { int i; for (i=0; i<ZSTD_REP_NUM; i++) cctx->rep[i] = repStartValue[i]; } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
241 cctx->seqStore.litLengthSum = 0; /* force reset of btopt stats */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
242 XXH64_reset(&cctx->xxhState, 0); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
243 return 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
244 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
245 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
246 typedef enum { ZSTDcrp_continue, ZSTDcrp_noMemset, ZSTDcrp_fullReset } ZSTD_compResetPolicy_e; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
247 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
248 /*! ZSTD_resetCCtx_advanced() : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
249 note : 'params' must be validated */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
250 static size_t ZSTD_resetCCtx_advanced (ZSTD_CCtx* zc, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
251 ZSTD_parameters params, U64 frameContentSize, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
252 ZSTD_compResetPolicy_e const crp) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
253 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
254 if (crp == ZSTDcrp_continue) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
255 if (ZSTD_equivalentParams(params, zc->params)) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
256 return ZSTD_continueCCtx(zc, params, frameContentSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
257 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
258 { size_t const blockSize = MIN(ZSTD_BLOCKSIZE_ABSOLUTEMAX, (size_t)1 << params.cParams.windowLog); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
259 U32 const divider = (params.cParams.searchLength==3) ? 3 : 4; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
260 size_t const maxNbSeq = blockSize / divider; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
261 size_t const tokenSpace = blockSize + 11*maxNbSeq; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
262 size_t const chainSize = (params.cParams.strategy == ZSTD_fast) ? 0 : (1 << params.cParams.chainLog); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
263 size_t const hSize = ((size_t)1) << params.cParams.hashLog; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
264 U32 const hashLog3 = (params.cParams.searchLength>3) ? 0 : MIN(ZSTD_HASHLOG3_MAX, params.cParams.windowLog); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
265 size_t const h3Size = ((size_t)1) << hashLog3; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
266 size_t const tableSpace = (chainSize + hSize + h3Size) * sizeof(U32); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
267 void* ptr; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
268 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
269 /* Check if workSpace is large enough, alloc a new one if needed */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
270 { size_t const optSpace = ((MaxML+1) + (MaxLL+1) + (MaxOff+1) + (1<<Litbits))*sizeof(U32) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
271 + (ZSTD_OPT_NUM+1)*(sizeof(ZSTD_match_t) + sizeof(ZSTD_optimal_t)); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
272 size_t const neededSpace = tableSpace + (256*sizeof(U32)) /* huffTable */ + tokenSpace |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
273 + (((params.cParams.strategy == ZSTD_btopt) || (params.cParams.strategy == ZSTD_btopt2)) ? optSpace : 0); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
274 if (zc->workSpaceSize < neededSpace) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
275 ZSTD_free(zc->workSpace, zc->customMem); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
276 zc->workSpace = ZSTD_malloc(neededSpace, zc->customMem); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
277 if (zc->workSpace == NULL) return ERROR(memory_allocation); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
278 zc->workSpaceSize = neededSpace; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
279 } } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
280 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
281 if (crp!=ZSTDcrp_noMemset) memset(zc->workSpace, 0, tableSpace); /* reset tables only */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
282 XXH64_reset(&zc->xxhState, 0); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
283 zc->hashLog3 = hashLog3; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
284 zc->hashTable = (U32*)(zc->workSpace); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
285 zc->chainTable = zc->hashTable + hSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
286 zc->hashTable3 = zc->chainTable + chainSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
287 ptr = zc->hashTable3 + h3Size; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
288 zc->hufTable = (HUF_CElt*)ptr; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
289 zc->flagStaticTables = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
290 ptr = ((U32*)ptr) + 256; /* note : HUF_CElt* is incomplete type, size is simulated using U32 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
291 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
292 zc->nextToUpdate = 1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
293 zc->nextSrc = NULL; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
294 zc->base = NULL; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
295 zc->dictBase = NULL; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
296 zc->dictLimit = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
297 zc->lowLimit = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
298 zc->params = params; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
299 zc->blockSize = blockSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
300 zc->frameContentSize = frameContentSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
301 { int i; for (i=0; i<ZSTD_REP_NUM; i++) zc->rep[i] = repStartValue[i]; } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
302 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
303 if ((params.cParams.strategy == ZSTD_btopt) || (params.cParams.strategy == ZSTD_btopt2)) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
304 zc->seqStore.litFreq = (U32*)ptr; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
305 zc->seqStore.litLengthFreq = zc->seqStore.litFreq + (1<<Litbits); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
306 zc->seqStore.matchLengthFreq = zc->seqStore.litLengthFreq + (MaxLL+1); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
307 zc->seqStore.offCodeFreq = zc->seqStore.matchLengthFreq + (MaxML+1); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
308 ptr = zc->seqStore.offCodeFreq + (MaxOff+1); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
309 zc->seqStore.matchTable = (ZSTD_match_t*)ptr; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
310 ptr = zc->seqStore.matchTable + ZSTD_OPT_NUM+1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
311 zc->seqStore.priceTable = (ZSTD_optimal_t*)ptr; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
312 ptr = zc->seqStore.priceTable + ZSTD_OPT_NUM+1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
313 zc->seqStore.litLengthSum = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
314 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
315 zc->seqStore.sequencesStart = (seqDef*)ptr; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
316 ptr = zc->seqStore.sequencesStart + maxNbSeq; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
317 zc->seqStore.llCode = (BYTE*) ptr; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
318 zc->seqStore.mlCode = zc->seqStore.llCode + maxNbSeq; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
319 zc->seqStore.ofCode = zc->seqStore.mlCode + maxNbSeq; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
320 zc->seqStore.litStart = zc->seqStore.ofCode + maxNbSeq; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
321 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
322 zc->stage = ZSTDcs_init; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
323 zc->dictID = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
324 zc->loadedDictEnd = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
325 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
326 return 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
327 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
328 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
329 |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
330 /* ZSTD_invalidateRepCodes() : |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
331 * ensures next compression will not use repcodes from previous block. |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
332 * Note : only works with regular variant; |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
333 * do not use with extDict variant ! */ |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
334 void ZSTD_invalidateRepCodes(ZSTD_CCtx* cctx) { |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
335 int i; |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
336 for (i=0; i<ZSTD_REP_NUM; i++) cctx->rep[i] = 0; |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
337 } |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
338 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
339 /*! ZSTD_copyCCtx() : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
340 * Duplicate an existing context `srcCCtx` into another one `dstCCtx`. |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
341 * Only works during stage ZSTDcs_init (i.e. after creation, but before first call to ZSTD_compressContinue()). |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
342 * @return : 0, or an error code */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
343 size_t ZSTD_copyCCtx(ZSTD_CCtx* dstCCtx, const ZSTD_CCtx* srcCCtx, unsigned long long pledgedSrcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
344 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
345 if (srcCCtx->stage!=ZSTDcs_init) return ERROR(stage_wrong); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
346 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
347 memcpy(&dstCCtx->customMem, &srcCCtx->customMem, sizeof(ZSTD_customMem)); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
348 ZSTD_resetCCtx_advanced(dstCCtx, srcCCtx->params, pledgedSrcSize, ZSTDcrp_noMemset); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
349 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
350 /* copy tables */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
351 { size_t const chainSize = (srcCCtx->params.cParams.strategy == ZSTD_fast) ? 0 : (1 << srcCCtx->params.cParams.chainLog); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
352 size_t const hSize = ((size_t)1) << srcCCtx->params.cParams.hashLog; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
353 size_t const h3Size = (size_t)1 << srcCCtx->hashLog3; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
354 size_t const tableSpace = (chainSize + hSize + h3Size) * sizeof(U32); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
355 memcpy(dstCCtx->workSpace, srcCCtx->workSpace, tableSpace); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
356 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
357 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
358 /* copy dictionary offsets */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
359 dstCCtx->nextToUpdate = srcCCtx->nextToUpdate; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
360 dstCCtx->nextToUpdate3= srcCCtx->nextToUpdate3; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
361 dstCCtx->nextSrc = srcCCtx->nextSrc; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
362 dstCCtx->base = srcCCtx->base; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
363 dstCCtx->dictBase = srcCCtx->dictBase; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
364 dstCCtx->dictLimit = srcCCtx->dictLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
365 dstCCtx->lowLimit = srcCCtx->lowLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
366 dstCCtx->loadedDictEnd= srcCCtx->loadedDictEnd; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
367 dstCCtx->dictID = srcCCtx->dictID; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
368 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
369 /* copy entropy tables */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
370 dstCCtx->flagStaticTables = srcCCtx->flagStaticTables; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
371 if (srcCCtx->flagStaticTables) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
372 memcpy(dstCCtx->hufTable, srcCCtx->hufTable, 256*4); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
373 memcpy(dstCCtx->litlengthCTable, srcCCtx->litlengthCTable, sizeof(dstCCtx->litlengthCTable)); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
374 memcpy(dstCCtx->matchlengthCTable, srcCCtx->matchlengthCTable, sizeof(dstCCtx->matchlengthCTable)); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
375 memcpy(dstCCtx->offcodeCTable, srcCCtx->offcodeCTable, sizeof(dstCCtx->offcodeCTable)); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
376 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
377 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
378 return 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
379 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
380 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
381 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
382 /*! ZSTD_reduceTable() : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
383 * reduce table indexes by `reducerValue` */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
384 static void ZSTD_reduceTable (U32* const table, U32 const size, U32 const reducerValue) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
385 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
386 U32 u; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
387 for (u=0 ; u < size ; u++) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
388 if (table[u] < reducerValue) table[u] = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
389 else table[u] -= reducerValue; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
390 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
391 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
392 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
393 /*! ZSTD_reduceIndex() : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
394 * rescale all indexes to avoid future overflow (indexes are U32) */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
395 static void ZSTD_reduceIndex (ZSTD_CCtx* zc, const U32 reducerValue) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
396 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
397 { U32 const hSize = 1 << zc->params.cParams.hashLog; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
398 ZSTD_reduceTable(zc->hashTable, hSize, reducerValue); } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
399 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
400 { U32 const chainSize = (zc->params.cParams.strategy == ZSTD_fast) ? 0 : (1 << zc->params.cParams.chainLog); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
401 ZSTD_reduceTable(zc->chainTable, chainSize, reducerValue); } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
402 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
403 { U32 const h3Size = (zc->hashLog3) ? 1 << zc->hashLog3 : 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
404 ZSTD_reduceTable(zc->hashTable3, h3Size, reducerValue); } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
405 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
406 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
407 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
408 /*-******************************************************* |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
409 * Block entropic compression |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
410 *********************************************************/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
411 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
412 /* See doc/zstd_compression_format.md for detailed format description */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
413 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
414 size_t ZSTD_noCompressBlock (void* dst, size_t dstCapacity, const void* src, size_t srcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
415 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
416 if (srcSize + ZSTD_blockHeaderSize > dstCapacity) return ERROR(dstSize_tooSmall); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
417 memcpy((BYTE*)dst + ZSTD_blockHeaderSize, src, srcSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
418 MEM_writeLE24(dst, (U32)(srcSize << 2) + (U32)bt_raw); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
419 return ZSTD_blockHeaderSize+srcSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
420 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
421 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
422 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
423 static size_t ZSTD_noCompressLiterals (void* dst, size_t dstCapacity, const void* src, size_t srcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
424 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
425 BYTE* const ostart = (BYTE* const)dst; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
426 U32 const flSize = 1 + (srcSize>31) + (srcSize>4095); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
427 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
428 if (srcSize + flSize > dstCapacity) return ERROR(dstSize_tooSmall); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
429 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
430 switch(flSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
431 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
432 case 1: /* 2 - 1 - 5 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
433 ostart[0] = (BYTE)((U32)set_basic + (srcSize<<3)); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
434 break; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
435 case 2: /* 2 - 2 - 12 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
436 MEM_writeLE16(ostart, (U16)((U32)set_basic + (1<<2) + (srcSize<<4))); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
437 break; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
438 default: /*note : should not be necessary : flSize is within {1,2,3} */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
439 case 3: /* 2 - 2 - 20 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
440 MEM_writeLE32(ostart, (U32)((U32)set_basic + (3<<2) + (srcSize<<4))); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
441 break; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
442 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
443 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
444 memcpy(ostart + flSize, src, srcSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
445 return srcSize + flSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
446 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
447 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
448 static size_t ZSTD_compressRleLiteralsBlock (void* dst, size_t dstCapacity, const void* src, size_t srcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
449 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
450 BYTE* const ostart = (BYTE* const)dst; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
451 U32 const flSize = 1 + (srcSize>31) + (srcSize>4095); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
452 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
453 (void)dstCapacity; /* dstCapacity already guaranteed to be >=4, hence large enough */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
454 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
455 switch(flSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
456 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
457 case 1: /* 2 - 1 - 5 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
458 ostart[0] = (BYTE)((U32)set_rle + (srcSize<<3)); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
459 break; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
460 case 2: /* 2 - 2 - 12 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
461 MEM_writeLE16(ostart, (U16)((U32)set_rle + (1<<2) + (srcSize<<4))); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
462 break; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
463 default: /*note : should not be necessary : flSize is necessarily within {1,2,3} */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
464 case 3: /* 2 - 2 - 20 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
465 MEM_writeLE32(ostart, (U32)((U32)set_rle + (3<<2) + (srcSize<<4))); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
466 break; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
467 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
468 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
469 ostart[flSize] = *(const BYTE*)src; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
470 return flSize+1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
471 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
472 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
473 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
474 static size_t ZSTD_minGain(size_t srcSize) { return (srcSize >> 6) + 2; } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
475 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
476 static size_t ZSTD_compressLiterals (ZSTD_CCtx* zc, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
477 void* dst, size_t dstCapacity, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
478 const void* src, size_t srcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
479 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
480 size_t const minGain = ZSTD_minGain(srcSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
481 size_t const lhSize = 3 + (srcSize >= 1 KB) + (srcSize >= 16 KB); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
482 BYTE* const ostart = (BYTE*)dst; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
483 U32 singleStream = srcSize < 256; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
484 symbolEncodingType_e hType = set_compressed; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
485 size_t cLitSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
486 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
487 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
488 /* small ? don't even attempt compression (speed opt) */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
489 # define LITERAL_NOENTROPY 63 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
490 { size_t const minLitSize = zc->flagStaticTables ? 6 : LITERAL_NOENTROPY; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
491 if (srcSize <= minLitSize) return ZSTD_noCompressLiterals(dst, dstCapacity, src, srcSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
492 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
493 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
494 if (dstCapacity < lhSize+1) return ERROR(dstSize_tooSmall); /* not enough space for compression */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
495 if (zc->flagStaticTables && (lhSize==3)) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
496 hType = set_repeat; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
497 singleStream = 1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
498 cLitSize = HUF_compress1X_usingCTable(ostart+lhSize, dstCapacity-lhSize, src, srcSize, zc->hufTable); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
499 } else { |
30822
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
500 cLitSize = singleStream ? HUF_compress1X_wksp(ostart+lhSize, dstCapacity-lhSize, src, srcSize, 255, 11, zc->tmpCounters, sizeof(zc->tmpCounters)) |
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
501 : HUF_compress4X_wksp(ostart+lhSize, dstCapacity-lhSize, src, srcSize, 255, 11, zc->tmpCounters, sizeof(zc->tmpCounters)); |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
502 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
503 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
504 if ((cLitSize==0) | (cLitSize >= srcSize - minGain)) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
505 return ZSTD_noCompressLiterals(dst, dstCapacity, src, srcSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
506 if (cLitSize==1) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
507 return ZSTD_compressRleLiteralsBlock(dst, dstCapacity, src, srcSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
508 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
509 /* Build header */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
510 switch(lhSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
511 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
512 case 3: /* 2 - 2 - 10 - 10 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
513 { U32 const lhc = hType + ((!singleStream) << 2) + ((U32)srcSize<<4) + ((U32)cLitSize<<14); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
514 MEM_writeLE24(ostart, lhc); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
515 break; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
516 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
517 case 4: /* 2 - 2 - 14 - 14 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
518 { U32 const lhc = hType + (2 << 2) + ((U32)srcSize<<4) + ((U32)cLitSize<<18); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
519 MEM_writeLE32(ostart, lhc); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
520 break; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
521 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
522 default: /* should not be necessary, lhSize is only {3,4,5} */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
523 case 5: /* 2 - 2 - 18 - 18 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
524 { U32 const lhc = hType + (3 << 2) + ((U32)srcSize<<4) + ((U32)cLitSize<<22); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
525 MEM_writeLE32(ostart, lhc); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
526 ostart[4] = (BYTE)(cLitSize >> 10); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
527 break; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
528 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
529 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
530 return lhSize+cLitSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
531 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
532 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
533 static const BYTE LL_Code[64] = { 0, 1, 2, 3, 4, 5, 6, 7, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
534 8, 9, 10, 11, 12, 13, 14, 15, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
535 16, 16, 17, 17, 18, 18, 19, 19, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
536 20, 20, 20, 20, 21, 21, 21, 21, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
537 22, 22, 22, 22, 22, 22, 22, 22, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
538 23, 23, 23, 23, 23, 23, 23, 23, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
539 24, 24, 24, 24, 24, 24, 24, 24, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
540 24, 24, 24, 24, 24, 24, 24, 24 }; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
541 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
542 static const BYTE ML_Code[128] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
543 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
544 32, 32, 33, 33, 34, 34, 35, 35, 36, 36, 36, 36, 37, 37, 37, 37, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
545 38, 38, 38, 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, 39, 39, 39, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
546 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
547 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
548 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
549 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42 }; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
550 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
551 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
552 void ZSTD_seqToCodes(const seqStore_t* seqStorePtr) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
553 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
554 BYTE const LL_deltaCode = 19; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
555 BYTE const ML_deltaCode = 36; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
556 const seqDef* const sequences = seqStorePtr->sequencesStart; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
557 BYTE* const llCodeTable = seqStorePtr->llCode; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
558 BYTE* const ofCodeTable = seqStorePtr->ofCode; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
559 BYTE* const mlCodeTable = seqStorePtr->mlCode; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
560 U32 const nbSeq = (U32)(seqStorePtr->sequences - seqStorePtr->sequencesStart); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
561 U32 u; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
562 for (u=0; u<nbSeq; u++) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
563 U32 const llv = sequences[u].litLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
564 U32 const mlv = sequences[u].matchLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
565 llCodeTable[u] = (llv> 63) ? (BYTE)ZSTD_highbit32(llv) + LL_deltaCode : LL_Code[llv]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
566 ofCodeTable[u] = (BYTE)ZSTD_highbit32(sequences[u].offset); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
567 mlCodeTable[u] = (mlv>127) ? (BYTE)ZSTD_highbit32(mlv) + ML_deltaCode : ML_Code[mlv]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
568 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
569 if (seqStorePtr->longLengthID==1) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
570 llCodeTable[seqStorePtr->longLengthPos] = MaxLL; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
571 if (seqStorePtr->longLengthID==2) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
572 mlCodeTable[seqStorePtr->longLengthPos] = MaxML; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
573 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
574 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
575 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
576 size_t ZSTD_compressSequences(ZSTD_CCtx* zc, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
577 void* dst, size_t dstCapacity, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
578 size_t srcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
579 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
580 const seqStore_t* seqStorePtr = &(zc->seqStore); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
581 U32 count[MaxSeq+1]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
582 S16 norm[MaxSeq+1]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
583 FSE_CTable* CTable_LitLength = zc->litlengthCTable; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
584 FSE_CTable* CTable_OffsetBits = zc->offcodeCTable; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
585 FSE_CTable* CTable_MatchLength = zc->matchlengthCTable; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
586 U32 LLtype, Offtype, MLtype; /* compressed, raw or rle */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
587 const seqDef* const sequences = seqStorePtr->sequencesStart; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
588 const BYTE* const ofCodeTable = seqStorePtr->ofCode; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
589 const BYTE* const llCodeTable = seqStorePtr->llCode; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
590 const BYTE* const mlCodeTable = seqStorePtr->mlCode; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
591 BYTE* const ostart = (BYTE*)dst; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
592 BYTE* const oend = ostart + dstCapacity; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
593 BYTE* op = ostart; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
594 size_t const nbSeq = seqStorePtr->sequences - seqStorePtr->sequencesStart; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
595 BYTE* seqHead; |
30822
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
596 BYTE scratchBuffer[1<<MAX(MLFSELog,LLFSELog)]; |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
597 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
598 /* Compress literals */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
599 { const BYTE* const literals = seqStorePtr->litStart; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
600 size_t const litSize = seqStorePtr->lit - literals; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
601 size_t const cSize = ZSTD_compressLiterals(zc, op, dstCapacity, literals, litSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
602 if (ZSTD_isError(cSize)) return cSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
603 op += cSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
604 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
605 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
606 /* Sequences Header */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
607 if ((oend-op) < 3 /*max nbSeq Size*/ + 1 /*seqHead */) return ERROR(dstSize_tooSmall); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
608 if (nbSeq < 0x7F) *op++ = (BYTE)nbSeq; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
609 else if (nbSeq < LONGNBSEQ) op[0] = (BYTE)((nbSeq>>8) + 0x80), op[1] = (BYTE)nbSeq, op+=2; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
610 else op[0]=0xFF, MEM_writeLE16(op+1, (U16)(nbSeq - LONGNBSEQ)), op+=3; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
611 if (nbSeq==0) goto _check_compressibility; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
612 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
613 /* seqHead : flags for FSE encoding type */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
614 seqHead = op++; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
615 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
616 #define MIN_SEQ_FOR_DYNAMIC_FSE 64 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
617 #define MAX_SEQ_FOR_STATIC_FSE 1000 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
618 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
619 /* convert length/distances into codes */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
620 ZSTD_seqToCodes(seqStorePtr); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
621 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
622 /* CTable for Literal Lengths */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
623 { U32 max = MaxLL; |
30822
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
624 size_t const mostFrequent = FSE_countFast_wksp(count, &max, llCodeTable, nbSeq, zc->tmpCounters); |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
625 if ((mostFrequent == nbSeq) && (nbSeq > 2)) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
626 *op++ = llCodeTable[0]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
627 FSE_buildCTable_rle(CTable_LitLength, (BYTE)max); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
628 LLtype = set_rle; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
629 } else if ((zc->flagStaticTables) && (nbSeq < MAX_SEQ_FOR_STATIC_FSE)) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
630 LLtype = set_repeat; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
631 } else if ((nbSeq < MIN_SEQ_FOR_DYNAMIC_FSE) || (mostFrequent < (nbSeq >> (LL_defaultNormLog-1)))) { |
30822
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
632 FSE_buildCTable_wksp(CTable_LitLength, LL_defaultNorm, MaxLL, LL_defaultNormLog, scratchBuffer, sizeof(scratchBuffer)); |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
633 LLtype = set_basic; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
634 } else { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
635 size_t nbSeq_1 = nbSeq; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
636 const U32 tableLog = FSE_optimalTableLog(LLFSELog, nbSeq, max); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
637 if (count[llCodeTable[nbSeq-1]]>1) { count[llCodeTable[nbSeq-1]]--; nbSeq_1--; } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
638 FSE_normalizeCount(norm, tableLog, count, nbSeq_1, max); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
639 { size_t const NCountSize = FSE_writeNCount(op, oend-op, norm, max, tableLog); /* overflow protected */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
640 if (FSE_isError(NCountSize)) return ERROR(GENERIC); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
641 op += NCountSize; } |
30822
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
642 FSE_buildCTable_wksp(CTable_LitLength, norm, max, tableLog, scratchBuffer, sizeof(scratchBuffer)); |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
643 LLtype = set_compressed; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
644 } } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
645 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
646 /* CTable for Offsets */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
647 { U32 max = MaxOff; |
30822
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
648 size_t const mostFrequent = FSE_countFast_wksp(count, &max, ofCodeTable, nbSeq, zc->tmpCounters); |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
649 if ((mostFrequent == nbSeq) && (nbSeq > 2)) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
650 *op++ = ofCodeTable[0]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
651 FSE_buildCTable_rle(CTable_OffsetBits, (BYTE)max); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
652 Offtype = set_rle; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
653 } else if ((zc->flagStaticTables) && (nbSeq < MAX_SEQ_FOR_STATIC_FSE)) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
654 Offtype = set_repeat; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
655 } else if ((nbSeq < MIN_SEQ_FOR_DYNAMIC_FSE) || (mostFrequent < (nbSeq >> (OF_defaultNormLog-1)))) { |
30822
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
656 FSE_buildCTable_wksp(CTable_OffsetBits, OF_defaultNorm, MaxOff, OF_defaultNormLog, scratchBuffer, sizeof(scratchBuffer)); |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
657 Offtype = set_basic; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
658 } else { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
659 size_t nbSeq_1 = nbSeq; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
660 const U32 tableLog = FSE_optimalTableLog(OffFSELog, nbSeq, max); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
661 if (count[ofCodeTable[nbSeq-1]]>1) { count[ofCodeTable[nbSeq-1]]--; nbSeq_1--; } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
662 FSE_normalizeCount(norm, tableLog, count, nbSeq_1, max); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
663 { size_t const NCountSize = FSE_writeNCount(op, oend-op, norm, max, tableLog); /* overflow protected */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
664 if (FSE_isError(NCountSize)) return ERROR(GENERIC); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
665 op += NCountSize; } |
30822
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
666 FSE_buildCTable_wksp(CTable_OffsetBits, norm, max, tableLog, scratchBuffer, sizeof(scratchBuffer)); |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
667 Offtype = set_compressed; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
668 } } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
669 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
670 /* CTable for MatchLengths */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
671 { U32 max = MaxML; |
30822
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
672 size_t const mostFrequent = FSE_countFast_wksp(count, &max, mlCodeTable, nbSeq, zc->tmpCounters); |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
673 if ((mostFrequent == nbSeq) && (nbSeq > 2)) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
674 *op++ = *mlCodeTable; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
675 FSE_buildCTable_rle(CTable_MatchLength, (BYTE)max); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
676 MLtype = set_rle; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
677 } else if ((zc->flagStaticTables) && (nbSeq < MAX_SEQ_FOR_STATIC_FSE)) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
678 MLtype = set_repeat; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
679 } else if ((nbSeq < MIN_SEQ_FOR_DYNAMIC_FSE) || (mostFrequent < (nbSeq >> (ML_defaultNormLog-1)))) { |
30822
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
680 FSE_buildCTable_wksp(CTable_MatchLength, ML_defaultNorm, MaxML, ML_defaultNormLog, scratchBuffer, sizeof(scratchBuffer)); |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
681 MLtype = set_basic; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
682 } else { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
683 size_t nbSeq_1 = nbSeq; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
684 const U32 tableLog = FSE_optimalTableLog(MLFSELog, nbSeq, max); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
685 if (count[mlCodeTable[nbSeq-1]]>1) { count[mlCodeTable[nbSeq-1]]--; nbSeq_1--; } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
686 FSE_normalizeCount(norm, tableLog, count, nbSeq_1, max); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
687 { size_t const NCountSize = FSE_writeNCount(op, oend-op, norm, max, tableLog); /* overflow protected */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
688 if (FSE_isError(NCountSize)) return ERROR(GENERIC); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
689 op += NCountSize; } |
30822
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
690 FSE_buildCTable_wksp(CTable_MatchLength, norm, max, tableLog, scratchBuffer, sizeof(scratchBuffer)); |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
691 MLtype = set_compressed; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
692 } } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
693 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
694 *seqHead = (BYTE)((LLtype<<6) + (Offtype<<4) + (MLtype<<2)); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
695 zc->flagStaticTables = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
696 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
697 /* Encoding Sequences */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
698 { BIT_CStream_t blockStream; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
699 FSE_CState_t stateMatchLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
700 FSE_CState_t stateOffsetBits; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
701 FSE_CState_t stateLitLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
702 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
703 CHECK_E(BIT_initCStream(&blockStream, op, oend-op), dstSize_tooSmall); /* not enough space remaining */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
704 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
705 /* first symbols */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
706 FSE_initCState2(&stateMatchLength, CTable_MatchLength, mlCodeTable[nbSeq-1]); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
707 FSE_initCState2(&stateOffsetBits, CTable_OffsetBits, ofCodeTable[nbSeq-1]); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
708 FSE_initCState2(&stateLitLength, CTable_LitLength, llCodeTable[nbSeq-1]); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
709 BIT_addBits(&blockStream, sequences[nbSeq-1].litLength, LL_bits[llCodeTable[nbSeq-1]]); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
710 if (MEM_32bits()) BIT_flushBits(&blockStream); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
711 BIT_addBits(&blockStream, sequences[nbSeq-1].matchLength, ML_bits[mlCodeTable[nbSeq-1]]); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
712 if (MEM_32bits()) BIT_flushBits(&blockStream); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
713 BIT_addBits(&blockStream, sequences[nbSeq-1].offset, ofCodeTable[nbSeq-1]); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
714 BIT_flushBits(&blockStream); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
715 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
716 { size_t n; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
717 for (n=nbSeq-2 ; n<nbSeq ; n--) { /* intentional underflow */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
718 BYTE const llCode = llCodeTable[n]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
719 BYTE const ofCode = ofCodeTable[n]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
720 BYTE const mlCode = mlCodeTable[n]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
721 U32 const llBits = LL_bits[llCode]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
722 U32 const ofBits = ofCode; /* 32b*/ /* 64b*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
723 U32 const mlBits = ML_bits[mlCode]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
724 /* (7)*/ /* (7)*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
725 FSE_encodeSymbol(&blockStream, &stateOffsetBits, ofCode); /* 15 */ /* 15 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
726 FSE_encodeSymbol(&blockStream, &stateMatchLength, mlCode); /* 24 */ /* 24 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
727 if (MEM_32bits()) BIT_flushBits(&blockStream); /* (7)*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
728 FSE_encodeSymbol(&blockStream, &stateLitLength, llCode); /* 16 */ /* 33 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
729 if (MEM_32bits() || (ofBits+mlBits+llBits >= 64-7-(LLFSELog+MLFSELog+OffFSELog))) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
730 BIT_flushBits(&blockStream); /* (7)*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
731 BIT_addBits(&blockStream, sequences[n].litLength, llBits); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
732 if (MEM_32bits() && ((llBits+mlBits)>24)) BIT_flushBits(&blockStream); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
733 BIT_addBits(&blockStream, sequences[n].matchLength, mlBits); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
734 if (MEM_32bits()) BIT_flushBits(&blockStream); /* (7)*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
735 BIT_addBits(&blockStream, sequences[n].offset, ofBits); /* 31 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
736 BIT_flushBits(&blockStream); /* (7)*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
737 } } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
738 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
739 FSE_flushCState(&blockStream, &stateMatchLength); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
740 FSE_flushCState(&blockStream, &stateOffsetBits); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
741 FSE_flushCState(&blockStream, &stateLitLength); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
742 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
743 { size_t const streamSize = BIT_closeCStream(&blockStream); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
744 if (streamSize==0) return ERROR(dstSize_tooSmall); /* not enough space */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
745 op += streamSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
746 } } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
747 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
748 /* check compressibility */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
749 _check_compressibility: |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
750 { size_t const minGain = ZSTD_minGain(srcSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
751 size_t const maxCSize = srcSize - minGain; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
752 if ((size_t)(op-ostart) >= maxCSize) return 0; } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
753 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
754 /* confirm repcodes */ |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
755 { int i; for (i=0; i<ZSTD_REP_NUM; i++) zc->rep[i] = zc->repToConfirm[i]; } |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
756 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
757 return op - ostart; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
758 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
759 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
760 |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
761 #if 0 /* for debug */ |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
762 # define STORESEQ_DEBUG |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
763 #include <stdio.h> /* fprintf */ |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
764 U32 g_startDebug = 0; |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
765 const BYTE* g_start = NULL; |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
766 #endif |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
767 |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
768 /*! ZSTD_storeSeq() : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
769 Store a sequence (literal length, literals, offset code and match length code) into seqStore_t. |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
770 `offsetCode` : distance to match, or 0 == repCode. |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
771 `matchCode` : matchLength - MINMATCH |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
772 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
773 MEM_STATIC void ZSTD_storeSeq(seqStore_t* seqStorePtr, size_t litLength, const void* literals, U32 offsetCode, size_t matchCode) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
774 { |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
775 #ifdef STORESEQ_DEBUG |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
776 if (g_startDebug) { |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
777 const U32 pos = (U32)((const BYTE*)literals - g_start); |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
778 if (g_start==NULL) g_start = (const BYTE*)literals; |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
779 if ((pos > 1895000) && (pos < 1895300)) |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
780 fprintf(stderr, "Cpos %6u :%5u literals & match %3u bytes at distance %6u \n", |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
781 pos, (U32)litLength, (U32)matchCode+MINMATCH, (U32)offsetCode); |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
782 } |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
783 #endif |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
784 /* copy Literals */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
785 ZSTD_wildcopy(seqStorePtr->lit, literals, litLength); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
786 seqStorePtr->lit += litLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
787 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
788 /* literal Length */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
789 if (litLength>0xFFFF) { seqStorePtr->longLengthID = 1; seqStorePtr->longLengthPos = (U32)(seqStorePtr->sequences - seqStorePtr->sequencesStart); } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
790 seqStorePtr->sequences[0].litLength = (U16)litLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
791 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
792 /* match offset */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
793 seqStorePtr->sequences[0].offset = offsetCode + 1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
794 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
795 /* match Length */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
796 if (matchCode>0xFFFF) { seqStorePtr->longLengthID = 2; seqStorePtr->longLengthPos = (U32)(seqStorePtr->sequences - seqStorePtr->sequencesStart); } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
797 seqStorePtr->sequences[0].matchLength = (U16)matchCode; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
798 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
799 seqStorePtr->sequences++; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
800 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
801 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
802 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
803 /*-************************************* |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
804 * Match length counter |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
805 ***************************************/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
806 static unsigned ZSTD_NbCommonBytes (register size_t val) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
807 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
808 if (MEM_isLittleEndian()) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
809 if (MEM_64bits()) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
810 # if defined(_MSC_VER) && defined(_WIN64) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
811 unsigned long r = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
812 _BitScanForward64( &r, (U64)val ); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
813 return (unsigned)(r>>3); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
814 # elif defined(__GNUC__) && (__GNUC__ >= 3) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
815 return (__builtin_ctzll((U64)val) >> 3); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
816 # else |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
817 static const int DeBruijnBytePos[64] = { 0, 0, 0, 0, 0, 1, 1, 2, 0, 3, 1, 3, 1, 4, 2, 7, 0, 2, 3, 6, 1, 5, 3, 5, 1, 3, 4, 4, 2, 5, 6, 7, 7, 0, 1, 2, 3, 3, 4, 6, 2, 6, 5, 5, 3, 4, 5, 6, 7, 1, 2, 4, 6, 4, 4, 5, 7, 2, 6, 5, 7, 6, 7, 7 }; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
818 return DeBruijnBytePos[((U64)((val & -(long long)val) * 0x0218A392CDABBD3FULL)) >> 58]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
819 # endif |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
820 } else { /* 32 bits */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
821 # if defined(_MSC_VER) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
822 unsigned long r=0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
823 _BitScanForward( &r, (U32)val ); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
824 return (unsigned)(r>>3); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
825 # elif defined(__GNUC__) && (__GNUC__ >= 3) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
826 return (__builtin_ctz((U32)val) >> 3); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
827 # else |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
828 static const int DeBruijnBytePos[32] = { 0, 0, 3, 0, 3, 1, 3, 0, 3, 2, 2, 1, 3, 2, 0, 1, 3, 3, 1, 2, 2, 2, 2, 0, 3, 1, 2, 0, 1, 0, 1, 1 }; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
829 return DeBruijnBytePos[((U32)((val & -(S32)val) * 0x077CB531U)) >> 27]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
830 # endif |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
831 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
832 } else { /* Big Endian CPU */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
833 if (MEM_64bits()) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
834 # if defined(_MSC_VER) && defined(_WIN64) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
835 unsigned long r = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
836 _BitScanReverse64( &r, val ); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
837 return (unsigned)(r>>3); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
838 # elif defined(__GNUC__) && (__GNUC__ >= 3) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
839 return (__builtin_clzll(val) >> 3); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
840 # else |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
841 unsigned r; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
842 const unsigned n32 = sizeof(size_t)*4; /* calculate this way due to compiler complaining in 32-bits mode */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
843 if (!(val>>n32)) { r=4; } else { r=0; val>>=n32; } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
844 if (!(val>>16)) { r+=2; val>>=8; } else { val>>=24; } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
845 r += (!val); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
846 return r; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
847 # endif |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
848 } else { /* 32 bits */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
849 # if defined(_MSC_VER) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
850 unsigned long r = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
851 _BitScanReverse( &r, (unsigned long)val ); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
852 return (unsigned)(r>>3); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
853 # elif defined(__GNUC__) && (__GNUC__ >= 3) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
854 return (__builtin_clz((U32)val) >> 3); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
855 # else |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
856 unsigned r; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
857 if (!(val>>16)) { r=2; val>>=8; } else { r=0; val>>=24; } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
858 r += (!val); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
859 return r; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
860 # endif |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
861 } } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
862 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
863 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
864 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
865 static size_t ZSTD_count(const BYTE* pIn, const BYTE* pMatch, const BYTE* const pInLimit) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
866 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
867 const BYTE* const pStart = pIn; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
868 const BYTE* const pInLoopLimit = pInLimit - (sizeof(size_t)-1); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
869 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
870 while (pIn < pInLoopLimit) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
871 size_t const diff = MEM_readST(pMatch) ^ MEM_readST(pIn); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
872 if (!diff) { pIn+=sizeof(size_t); pMatch+=sizeof(size_t); continue; } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
873 pIn += ZSTD_NbCommonBytes(diff); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
874 return (size_t)(pIn - pStart); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
875 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
876 if (MEM_64bits()) if ((pIn<(pInLimit-3)) && (MEM_read32(pMatch) == MEM_read32(pIn))) { pIn+=4; pMatch+=4; } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
877 if ((pIn<(pInLimit-1)) && (MEM_read16(pMatch) == MEM_read16(pIn))) { pIn+=2; pMatch+=2; } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
878 if ((pIn<pInLimit) && (*pMatch == *pIn)) pIn++; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
879 return (size_t)(pIn - pStart); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
880 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
881 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
882 /** ZSTD_count_2segments() : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
883 * can count match length with `ip` & `match` in 2 different segments. |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
884 * convention : on reaching mEnd, match count continue starting from iStart |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
885 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
886 static size_t ZSTD_count_2segments(const BYTE* ip, const BYTE* match, const BYTE* iEnd, const BYTE* mEnd, const BYTE* iStart) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
887 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
888 const BYTE* const vEnd = MIN( ip + (mEnd - match), iEnd); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
889 size_t const matchLength = ZSTD_count(ip, match, vEnd); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
890 if (match + matchLength != mEnd) return matchLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
891 return matchLength + ZSTD_count(ip+matchLength, iStart, iEnd); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
892 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
893 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
894 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
895 /*-************************************* |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
896 * Hashes |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
897 ***************************************/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
898 static const U32 prime3bytes = 506832829U; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
899 static U32 ZSTD_hash3(U32 u, U32 h) { return ((u << (32-24)) * prime3bytes) >> (32-h) ; } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
900 MEM_STATIC size_t ZSTD_hash3Ptr(const void* ptr, U32 h) { return ZSTD_hash3(MEM_readLE32(ptr), h); } /* only in zstd_opt.h */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
901 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
902 static const U32 prime4bytes = 2654435761U; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
903 static U32 ZSTD_hash4(U32 u, U32 h) { return (u * prime4bytes) >> (32-h) ; } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
904 static size_t ZSTD_hash4Ptr(const void* ptr, U32 h) { return ZSTD_hash4(MEM_read32(ptr), h); } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
905 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
906 static const U64 prime5bytes = 889523592379ULL; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
907 static size_t ZSTD_hash5(U64 u, U32 h) { return (size_t)(((u << (64-40)) * prime5bytes) >> (64-h)) ; } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
908 static size_t ZSTD_hash5Ptr(const void* p, U32 h) { return ZSTD_hash5(MEM_readLE64(p), h); } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
909 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
910 static const U64 prime6bytes = 227718039650203ULL; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
911 static size_t ZSTD_hash6(U64 u, U32 h) { return (size_t)(((u << (64-48)) * prime6bytes) >> (64-h)) ; } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
912 static size_t ZSTD_hash6Ptr(const void* p, U32 h) { return ZSTD_hash6(MEM_readLE64(p), h); } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
913 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
914 static const U64 prime7bytes = 58295818150454627ULL; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
915 static size_t ZSTD_hash7(U64 u, U32 h) { return (size_t)(((u << (64-56)) * prime7bytes) >> (64-h)) ; } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
916 static size_t ZSTD_hash7Ptr(const void* p, U32 h) { return ZSTD_hash7(MEM_readLE64(p), h); } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
917 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
918 static const U64 prime8bytes = 0xCF1BBCDCB7A56463ULL; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
919 static size_t ZSTD_hash8(U64 u, U32 h) { return (size_t)(((u) * prime8bytes) >> (64-h)) ; } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
920 static size_t ZSTD_hash8Ptr(const void* p, U32 h) { return ZSTD_hash8(MEM_readLE64(p), h); } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
921 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
922 static size_t ZSTD_hashPtr(const void* p, U32 hBits, U32 mls) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
923 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
924 switch(mls) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
925 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
926 default: |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
927 case 4: return ZSTD_hash4Ptr(p, hBits); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
928 case 5: return ZSTD_hash5Ptr(p, hBits); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
929 case 6: return ZSTD_hash6Ptr(p, hBits); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
930 case 7: return ZSTD_hash7Ptr(p, hBits); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
931 case 8: return ZSTD_hash8Ptr(p, hBits); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
932 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
933 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
934 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
935 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
936 /*-************************************* |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
937 * Fast Scan |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
938 ***************************************/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
939 static void ZSTD_fillHashTable (ZSTD_CCtx* zc, const void* end, const U32 mls) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
940 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
941 U32* const hashTable = zc->hashTable; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
942 U32 const hBits = zc->params.cParams.hashLog; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
943 const BYTE* const base = zc->base; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
944 const BYTE* ip = base + zc->nextToUpdate; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
945 const BYTE* const iend = ((const BYTE*)end) - HASH_READ_SIZE; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
946 const size_t fastHashFillStep = 3; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
947 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
948 while(ip <= iend) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
949 hashTable[ZSTD_hashPtr(ip, hBits, mls)] = (U32)(ip - base); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
950 ip += fastHashFillStep; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
951 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
952 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
953 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
954 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
955 FORCE_INLINE |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
956 void ZSTD_compressBlock_fast_generic(ZSTD_CCtx* cctx, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
957 const void* src, size_t srcSize, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
958 const U32 mls) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
959 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
960 U32* const hashTable = cctx->hashTable; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
961 U32 const hBits = cctx->params.cParams.hashLog; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
962 seqStore_t* seqStorePtr = &(cctx->seqStore); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
963 const BYTE* const base = cctx->base; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
964 const BYTE* const istart = (const BYTE*)src; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
965 const BYTE* ip = istart; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
966 const BYTE* anchor = istart; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
967 const U32 lowestIndex = cctx->dictLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
968 const BYTE* const lowest = base + lowestIndex; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
969 const BYTE* const iend = istart + srcSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
970 const BYTE* const ilimit = iend - HASH_READ_SIZE; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
971 U32 offset_1=cctx->rep[0], offset_2=cctx->rep[1]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
972 U32 offsetSaved = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
973 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
974 /* init */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
975 ip += (ip==lowest); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
976 { U32 const maxRep = (U32)(ip-lowest); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
977 if (offset_2 > maxRep) offsetSaved = offset_2, offset_2 = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
978 if (offset_1 > maxRep) offsetSaved = offset_1, offset_1 = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
979 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
980 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
981 /* Main Search Loop */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
982 while (ip < ilimit) { /* < instead of <=, because repcode check at (ip+1) */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
983 size_t mLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
984 size_t const h = ZSTD_hashPtr(ip, hBits, mls); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
985 U32 const current = (U32)(ip-base); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
986 U32 const matchIndex = hashTable[h]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
987 const BYTE* match = base + matchIndex; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
988 hashTable[h] = current; /* update hash table */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
989 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
990 if ((offset_1 > 0) & (MEM_read32(ip+1-offset_1) == MEM_read32(ip+1))) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
991 mLength = ZSTD_count(ip+1+4, ip+1+4-offset_1, iend) + 4; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
992 ip++; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
993 ZSTD_storeSeq(seqStorePtr, ip-anchor, anchor, 0, mLength-MINMATCH); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
994 } else { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
995 U32 offset; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
996 if ( (matchIndex <= lowestIndex) || (MEM_read32(match) != MEM_read32(ip)) ) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
997 ip += ((ip-anchor) >> g_searchStrength) + 1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
998 continue; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
999 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1000 mLength = ZSTD_count(ip+4, match+4, iend) + 4; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1001 offset = (U32)(ip-match); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1002 while (((ip>anchor) & (match>lowest)) && (ip[-1] == match[-1])) { ip--; match--; mLength++; } /* catch up */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1003 offset_2 = offset_1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1004 offset_1 = offset; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1005 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1006 ZSTD_storeSeq(seqStorePtr, ip-anchor, anchor, offset + ZSTD_REP_MOVE, mLength-MINMATCH); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1007 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1008 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1009 /* match found */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1010 ip += mLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1011 anchor = ip; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1012 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1013 if (ip <= ilimit) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1014 /* Fill Table */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1015 hashTable[ZSTD_hashPtr(base+current+2, hBits, mls)] = current+2; /* here because current+2 could be > iend-8 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1016 hashTable[ZSTD_hashPtr(ip-2, hBits, mls)] = (U32)(ip-2-base); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1017 /* check immediate repcode */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1018 while ( (ip <= ilimit) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1019 && ( (offset_2>0) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1020 & (MEM_read32(ip) == MEM_read32(ip - offset_2)) )) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1021 /* store sequence */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1022 size_t const rLength = ZSTD_count(ip+4, ip+4-offset_2, iend) + 4; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1023 { U32 const tmpOff = offset_2; offset_2 = offset_1; offset_1 = tmpOff; } /* swap offset_2 <=> offset_1 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1024 hashTable[ZSTD_hashPtr(ip, hBits, mls)] = (U32)(ip-base); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1025 ZSTD_storeSeq(seqStorePtr, 0, anchor, 0, rLength-MINMATCH); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1026 ip += rLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1027 anchor = ip; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1028 continue; /* faster when present ... (?) */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1029 } } } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1030 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1031 /* save reps for next block */ |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
1032 cctx->repToConfirm[0] = offset_1 ? offset_1 : offsetSaved; |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
1033 cctx->repToConfirm[1] = offset_2 ? offset_2 : offsetSaved; |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1034 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1035 /* Last Literals */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1036 { size_t const lastLLSize = iend - anchor; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1037 memcpy(seqStorePtr->lit, anchor, lastLLSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1038 seqStorePtr->lit += lastLLSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1039 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1040 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1041 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1042 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1043 static void ZSTD_compressBlock_fast(ZSTD_CCtx* ctx, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1044 const void* src, size_t srcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1045 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1046 const U32 mls = ctx->params.cParams.searchLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1047 switch(mls) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1048 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1049 default: |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1050 case 4 : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1051 ZSTD_compressBlock_fast_generic(ctx, src, srcSize, 4); return; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1052 case 5 : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1053 ZSTD_compressBlock_fast_generic(ctx, src, srcSize, 5); return; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1054 case 6 : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1055 ZSTD_compressBlock_fast_generic(ctx, src, srcSize, 6); return; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1056 case 7 : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1057 ZSTD_compressBlock_fast_generic(ctx, src, srcSize, 7); return; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1058 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1059 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1060 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1061 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1062 static void ZSTD_compressBlock_fast_extDict_generic(ZSTD_CCtx* ctx, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1063 const void* src, size_t srcSize, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1064 const U32 mls) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1065 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1066 U32* hashTable = ctx->hashTable; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1067 const U32 hBits = ctx->params.cParams.hashLog; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1068 seqStore_t* seqStorePtr = &(ctx->seqStore); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1069 const BYTE* const base = ctx->base; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1070 const BYTE* const dictBase = ctx->dictBase; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1071 const BYTE* const istart = (const BYTE*)src; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1072 const BYTE* ip = istart; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1073 const BYTE* anchor = istart; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1074 const U32 lowestIndex = ctx->lowLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1075 const BYTE* const dictStart = dictBase + lowestIndex; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1076 const U32 dictLimit = ctx->dictLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1077 const BYTE* const lowPrefixPtr = base + dictLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1078 const BYTE* const dictEnd = dictBase + dictLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1079 const BYTE* const iend = istart + srcSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1080 const BYTE* const ilimit = iend - 8; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1081 U32 offset_1=ctx->rep[0], offset_2=ctx->rep[1]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1082 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1083 /* Search Loop */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1084 while (ip < ilimit) { /* < instead of <=, because (ip+1) */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1085 const size_t h = ZSTD_hashPtr(ip, hBits, mls); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1086 const U32 matchIndex = hashTable[h]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1087 const BYTE* matchBase = matchIndex < dictLimit ? dictBase : base; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1088 const BYTE* match = matchBase + matchIndex; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1089 const U32 current = (U32)(ip-base); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1090 const U32 repIndex = current + 1 - offset_1; /* offset_1 expected <= current +1 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1091 const BYTE* repBase = repIndex < dictLimit ? dictBase : base; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1092 const BYTE* repMatch = repBase + repIndex; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1093 size_t mLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1094 hashTable[h] = current; /* update hash table */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1095 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1096 if ( (((U32)((dictLimit-1) - repIndex) >= 3) /* intentional underflow */ & (repIndex > lowestIndex)) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1097 && (MEM_read32(repMatch) == MEM_read32(ip+1)) ) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1098 const BYTE* repMatchEnd = repIndex < dictLimit ? dictEnd : iend; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1099 mLength = ZSTD_count_2segments(ip+1+EQUAL_READ32, repMatch+EQUAL_READ32, iend, repMatchEnd, lowPrefixPtr) + EQUAL_READ32; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1100 ip++; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1101 ZSTD_storeSeq(seqStorePtr, ip-anchor, anchor, 0, mLength-MINMATCH); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1102 } else { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1103 if ( (matchIndex < lowestIndex) || |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1104 (MEM_read32(match) != MEM_read32(ip)) ) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1105 ip += ((ip-anchor) >> g_searchStrength) + 1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1106 continue; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1107 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1108 { const BYTE* matchEnd = matchIndex < dictLimit ? dictEnd : iend; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1109 const BYTE* lowMatchPtr = matchIndex < dictLimit ? dictStart : lowPrefixPtr; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1110 U32 offset; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1111 mLength = ZSTD_count_2segments(ip+EQUAL_READ32, match+EQUAL_READ32, iend, matchEnd, lowPrefixPtr) + EQUAL_READ32; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1112 while (((ip>anchor) & (match>lowMatchPtr)) && (ip[-1] == match[-1])) { ip--; match--; mLength++; } /* catch up */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1113 offset = current - matchIndex; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1114 offset_2 = offset_1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1115 offset_1 = offset; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1116 ZSTD_storeSeq(seqStorePtr, ip-anchor, anchor, offset + ZSTD_REP_MOVE, mLength-MINMATCH); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1117 } } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1118 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1119 /* found a match : store it */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1120 ip += mLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1121 anchor = ip; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1122 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1123 if (ip <= ilimit) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1124 /* Fill Table */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1125 hashTable[ZSTD_hashPtr(base+current+2, hBits, mls)] = current+2; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1126 hashTable[ZSTD_hashPtr(ip-2, hBits, mls)] = (U32)(ip-2-base); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1127 /* check immediate repcode */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1128 while (ip <= ilimit) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1129 U32 const current2 = (U32)(ip-base); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1130 U32 const repIndex2 = current2 - offset_2; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1131 const BYTE* repMatch2 = repIndex2 < dictLimit ? dictBase + repIndex2 : base + repIndex2; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1132 if ( (((U32)((dictLimit-1) - repIndex2) >= 3) & (repIndex2 > lowestIndex)) /* intentional overflow */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1133 && (MEM_read32(repMatch2) == MEM_read32(ip)) ) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1134 const BYTE* const repEnd2 = repIndex2 < dictLimit ? dictEnd : iend; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1135 size_t repLength2 = ZSTD_count_2segments(ip+EQUAL_READ32, repMatch2+EQUAL_READ32, iend, repEnd2, lowPrefixPtr) + EQUAL_READ32; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1136 U32 tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset; /* swap offset_2 <=> offset_1 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1137 ZSTD_storeSeq(seqStorePtr, 0, anchor, 0, repLength2-MINMATCH); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1138 hashTable[ZSTD_hashPtr(ip, hBits, mls)] = current2; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1139 ip += repLength2; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1140 anchor = ip; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1141 continue; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1142 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1143 break; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1144 } } } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1145 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1146 /* save reps for next block */ |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
1147 ctx->repToConfirm[0] = offset_1; ctx->repToConfirm[1] = offset_2; |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1148 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1149 /* Last Literals */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1150 { size_t const lastLLSize = iend - anchor; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1151 memcpy(seqStorePtr->lit, anchor, lastLLSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1152 seqStorePtr->lit += lastLLSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1153 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1154 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1155 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1156 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1157 static void ZSTD_compressBlock_fast_extDict(ZSTD_CCtx* ctx, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1158 const void* src, size_t srcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1159 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1160 U32 const mls = ctx->params.cParams.searchLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1161 switch(mls) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1162 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1163 default: |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1164 case 4 : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1165 ZSTD_compressBlock_fast_extDict_generic(ctx, src, srcSize, 4); return; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1166 case 5 : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1167 ZSTD_compressBlock_fast_extDict_generic(ctx, src, srcSize, 5); return; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1168 case 6 : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1169 ZSTD_compressBlock_fast_extDict_generic(ctx, src, srcSize, 6); return; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1170 case 7 : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1171 ZSTD_compressBlock_fast_extDict_generic(ctx, src, srcSize, 7); return; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1172 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1173 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1174 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1175 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1176 /*-************************************* |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1177 * Double Fast |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1178 ***************************************/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1179 static void ZSTD_fillDoubleHashTable (ZSTD_CCtx* cctx, const void* end, const U32 mls) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1180 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1181 U32* const hashLarge = cctx->hashTable; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1182 U32 const hBitsL = cctx->params.cParams.hashLog; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1183 U32* const hashSmall = cctx->chainTable; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1184 U32 const hBitsS = cctx->params.cParams.chainLog; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1185 const BYTE* const base = cctx->base; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1186 const BYTE* ip = base + cctx->nextToUpdate; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1187 const BYTE* const iend = ((const BYTE*)end) - HASH_READ_SIZE; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1188 const size_t fastHashFillStep = 3; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1189 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1190 while(ip <= iend) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1191 hashSmall[ZSTD_hashPtr(ip, hBitsS, mls)] = (U32)(ip - base); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1192 hashLarge[ZSTD_hashPtr(ip, hBitsL, 8)] = (U32)(ip - base); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1193 ip += fastHashFillStep; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1194 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1195 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1196 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1197 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1198 FORCE_INLINE |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1199 void ZSTD_compressBlock_doubleFast_generic(ZSTD_CCtx* cctx, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1200 const void* src, size_t srcSize, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1201 const U32 mls) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1202 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1203 U32* const hashLong = cctx->hashTable; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1204 const U32 hBitsL = cctx->params.cParams.hashLog; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1205 U32* const hashSmall = cctx->chainTable; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1206 const U32 hBitsS = cctx->params.cParams.chainLog; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1207 seqStore_t* seqStorePtr = &(cctx->seqStore); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1208 const BYTE* const base = cctx->base; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1209 const BYTE* const istart = (const BYTE*)src; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1210 const BYTE* ip = istart; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1211 const BYTE* anchor = istart; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1212 const U32 lowestIndex = cctx->dictLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1213 const BYTE* const lowest = base + lowestIndex; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1214 const BYTE* const iend = istart + srcSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1215 const BYTE* const ilimit = iend - HASH_READ_SIZE; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1216 U32 offset_1=cctx->rep[0], offset_2=cctx->rep[1]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1217 U32 offsetSaved = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1218 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1219 /* init */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1220 ip += (ip==lowest); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1221 { U32 const maxRep = (U32)(ip-lowest); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1222 if (offset_2 > maxRep) offsetSaved = offset_2, offset_2 = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1223 if (offset_1 > maxRep) offsetSaved = offset_1, offset_1 = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1224 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1225 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1226 /* Main Search Loop */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1227 while (ip < ilimit) { /* < instead of <=, because repcode check at (ip+1) */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1228 size_t mLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1229 size_t const h2 = ZSTD_hashPtr(ip, hBitsL, 8); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1230 size_t const h = ZSTD_hashPtr(ip, hBitsS, mls); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1231 U32 const current = (U32)(ip-base); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1232 U32 const matchIndexL = hashLong[h2]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1233 U32 const matchIndexS = hashSmall[h]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1234 const BYTE* matchLong = base + matchIndexL; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1235 const BYTE* match = base + matchIndexS; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1236 hashLong[h2] = hashSmall[h] = current; /* update hash tables */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1237 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1238 if ((offset_1 > 0) & (MEM_read32(ip+1-offset_1) == MEM_read32(ip+1))) { /* note : by construction, offset_1 <= current */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1239 mLength = ZSTD_count(ip+1+4, ip+1+4-offset_1, iend) + 4; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1240 ip++; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1241 ZSTD_storeSeq(seqStorePtr, ip-anchor, anchor, 0, mLength-MINMATCH); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1242 } else { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1243 U32 offset; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1244 if ( (matchIndexL > lowestIndex) && (MEM_read64(matchLong) == MEM_read64(ip)) ) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1245 mLength = ZSTD_count(ip+8, matchLong+8, iend) + 8; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1246 offset = (U32)(ip-matchLong); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1247 while (((ip>anchor) & (matchLong>lowest)) && (ip[-1] == matchLong[-1])) { ip--; matchLong--; mLength++; } /* catch up */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1248 } else if ( (matchIndexS > lowestIndex) && (MEM_read32(match) == MEM_read32(ip)) ) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1249 size_t const h3 = ZSTD_hashPtr(ip+1, hBitsL, 8); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1250 U32 const matchIndex3 = hashLong[h3]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1251 const BYTE* match3 = base + matchIndex3; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1252 hashLong[h3] = current + 1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1253 if ( (matchIndex3 > lowestIndex) && (MEM_read64(match3) == MEM_read64(ip+1)) ) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1254 mLength = ZSTD_count(ip+9, match3+8, iend) + 8; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1255 ip++; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1256 offset = (U32)(ip-match3); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1257 while (((ip>anchor) & (match3>lowest)) && (ip[-1] == match3[-1])) { ip--; match3--; mLength++; } /* catch up */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1258 } else { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1259 mLength = ZSTD_count(ip+4, match+4, iend) + 4; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1260 offset = (U32)(ip-match); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1261 while (((ip>anchor) & (match>lowest)) && (ip[-1] == match[-1])) { ip--; match--; mLength++; } /* catch up */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1262 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1263 } else { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1264 ip += ((ip-anchor) >> g_searchStrength) + 1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1265 continue; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1266 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1267 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1268 offset_2 = offset_1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1269 offset_1 = offset; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1270 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1271 ZSTD_storeSeq(seqStorePtr, ip-anchor, anchor, offset + ZSTD_REP_MOVE, mLength-MINMATCH); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1272 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1273 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1274 /* match found */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1275 ip += mLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1276 anchor = ip; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1277 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1278 if (ip <= ilimit) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1279 /* Fill Table */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1280 hashLong[ZSTD_hashPtr(base+current+2, hBitsL, 8)] = |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1281 hashSmall[ZSTD_hashPtr(base+current+2, hBitsS, mls)] = current+2; /* here because current+2 could be > iend-8 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1282 hashLong[ZSTD_hashPtr(ip-2, hBitsL, 8)] = |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1283 hashSmall[ZSTD_hashPtr(ip-2, hBitsS, mls)] = (U32)(ip-2-base); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1284 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1285 /* check immediate repcode */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1286 while ( (ip <= ilimit) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1287 && ( (offset_2>0) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1288 & (MEM_read32(ip) == MEM_read32(ip - offset_2)) )) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1289 /* store sequence */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1290 size_t const rLength = ZSTD_count(ip+4, ip+4-offset_2, iend) + 4; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1291 { U32 const tmpOff = offset_2; offset_2 = offset_1; offset_1 = tmpOff; } /* swap offset_2 <=> offset_1 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1292 hashSmall[ZSTD_hashPtr(ip, hBitsS, mls)] = (U32)(ip-base); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1293 hashLong[ZSTD_hashPtr(ip, hBitsL, 8)] = (U32)(ip-base); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1294 ZSTD_storeSeq(seqStorePtr, 0, anchor, 0, rLength-MINMATCH); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1295 ip += rLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1296 anchor = ip; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1297 continue; /* faster when present ... (?) */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1298 } } } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1299 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1300 /* save reps for next block */ |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
1301 cctx->repToConfirm[0] = offset_1 ? offset_1 : offsetSaved; |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
1302 cctx->repToConfirm[1] = offset_2 ? offset_2 : offsetSaved; |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1303 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1304 /* Last Literals */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1305 { size_t const lastLLSize = iend - anchor; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1306 memcpy(seqStorePtr->lit, anchor, lastLLSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1307 seqStorePtr->lit += lastLLSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1308 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1309 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1310 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1311 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1312 static void ZSTD_compressBlock_doubleFast(ZSTD_CCtx* ctx, const void* src, size_t srcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1313 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1314 const U32 mls = ctx->params.cParams.searchLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1315 switch(mls) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1316 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1317 default: |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1318 case 4 : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1319 ZSTD_compressBlock_doubleFast_generic(ctx, src, srcSize, 4); return; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1320 case 5 : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1321 ZSTD_compressBlock_doubleFast_generic(ctx, src, srcSize, 5); return; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1322 case 6 : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1323 ZSTD_compressBlock_doubleFast_generic(ctx, src, srcSize, 6); return; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1324 case 7 : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1325 ZSTD_compressBlock_doubleFast_generic(ctx, src, srcSize, 7); return; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1326 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1327 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1328 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1329 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1330 static void ZSTD_compressBlock_doubleFast_extDict_generic(ZSTD_CCtx* ctx, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1331 const void* src, size_t srcSize, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1332 const U32 mls) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1333 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1334 U32* const hashLong = ctx->hashTable; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1335 U32 const hBitsL = ctx->params.cParams.hashLog; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1336 U32* const hashSmall = ctx->chainTable; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1337 U32 const hBitsS = ctx->params.cParams.chainLog; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1338 seqStore_t* seqStorePtr = &(ctx->seqStore); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1339 const BYTE* const base = ctx->base; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1340 const BYTE* const dictBase = ctx->dictBase; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1341 const BYTE* const istart = (const BYTE*)src; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1342 const BYTE* ip = istart; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1343 const BYTE* anchor = istart; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1344 const U32 lowestIndex = ctx->lowLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1345 const BYTE* const dictStart = dictBase + lowestIndex; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1346 const U32 dictLimit = ctx->dictLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1347 const BYTE* const lowPrefixPtr = base + dictLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1348 const BYTE* const dictEnd = dictBase + dictLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1349 const BYTE* const iend = istart + srcSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1350 const BYTE* const ilimit = iend - 8; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1351 U32 offset_1=ctx->rep[0], offset_2=ctx->rep[1]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1352 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1353 /* Search Loop */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1354 while (ip < ilimit) { /* < instead of <=, because (ip+1) */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1355 const size_t hSmall = ZSTD_hashPtr(ip, hBitsS, mls); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1356 const U32 matchIndex = hashSmall[hSmall]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1357 const BYTE* matchBase = matchIndex < dictLimit ? dictBase : base; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1358 const BYTE* match = matchBase + matchIndex; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1359 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1360 const size_t hLong = ZSTD_hashPtr(ip, hBitsL, 8); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1361 const U32 matchLongIndex = hashLong[hLong]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1362 const BYTE* matchLongBase = matchLongIndex < dictLimit ? dictBase : base; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1363 const BYTE* matchLong = matchLongBase + matchLongIndex; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1364 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1365 const U32 current = (U32)(ip-base); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1366 const U32 repIndex = current + 1 - offset_1; /* offset_1 expected <= current +1 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1367 const BYTE* repBase = repIndex < dictLimit ? dictBase : base; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1368 const BYTE* repMatch = repBase + repIndex; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1369 size_t mLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1370 hashSmall[hSmall] = hashLong[hLong] = current; /* update hash table */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1371 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1372 if ( (((U32)((dictLimit-1) - repIndex) >= 3) /* intentional underflow */ & (repIndex > lowestIndex)) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1373 && (MEM_read32(repMatch) == MEM_read32(ip+1)) ) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1374 const BYTE* repMatchEnd = repIndex < dictLimit ? dictEnd : iend; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1375 mLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, lowPrefixPtr) + 4; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1376 ip++; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1377 ZSTD_storeSeq(seqStorePtr, ip-anchor, anchor, 0, mLength-MINMATCH); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1378 } else { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1379 if ((matchLongIndex > lowestIndex) && (MEM_read64(matchLong) == MEM_read64(ip))) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1380 const BYTE* matchEnd = matchLongIndex < dictLimit ? dictEnd : iend; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1381 const BYTE* lowMatchPtr = matchLongIndex < dictLimit ? dictStart : lowPrefixPtr; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1382 U32 offset; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1383 mLength = ZSTD_count_2segments(ip+8, matchLong+8, iend, matchEnd, lowPrefixPtr) + 8; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1384 offset = current - matchLongIndex; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1385 while (((ip>anchor) & (matchLong>lowMatchPtr)) && (ip[-1] == matchLong[-1])) { ip--; matchLong--; mLength++; } /* catch up */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1386 offset_2 = offset_1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1387 offset_1 = offset; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1388 ZSTD_storeSeq(seqStorePtr, ip-anchor, anchor, offset + ZSTD_REP_MOVE, mLength-MINMATCH); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1389 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1390 } else if ((matchIndex > lowestIndex) && (MEM_read32(match) == MEM_read32(ip))) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1391 size_t const h3 = ZSTD_hashPtr(ip+1, hBitsL, 8); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1392 U32 const matchIndex3 = hashLong[h3]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1393 const BYTE* const match3Base = matchIndex3 < dictLimit ? dictBase : base; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1394 const BYTE* match3 = match3Base + matchIndex3; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1395 U32 offset; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1396 hashLong[h3] = current + 1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1397 if ( (matchIndex3 > lowestIndex) && (MEM_read64(match3) == MEM_read64(ip+1)) ) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1398 const BYTE* matchEnd = matchIndex3 < dictLimit ? dictEnd : iend; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1399 const BYTE* lowMatchPtr = matchIndex3 < dictLimit ? dictStart : lowPrefixPtr; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1400 mLength = ZSTD_count_2segments(ip+9, match3+8, iend, matchEnd, lowPrefixPtr) + 8; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1401 ip++; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1402 offset = current+1 - matchIndex3; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1403 while (((ip>anchor) & (match3>lowMatchPtr)) && (ip[-1] == match3[-1])) { ip--; match3--; mLength++; } /* catch up */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1404 } else { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1405 const BYTE* matchEnd = matchIndex < dictLimit ? dictEnd : iend; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1406 const BYTE* lowMatchPtr = matchIndex < dictLimit ? dictStart : lowPrefixPtr; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1407 mLength = ZSTD_count_2segments(ip+4, match+4, iend, matchEnd, lowPrefixPtr) + 4; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1408 offset = current - matchIndex; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1409 while (((ip>anchor) & (match>lowMatchPtr)) && (ip[-1] == match[-1])) { ip--; match--; mLength++; } /* catch up */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1410 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1411 offset_2 = offset_1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1412 offset_1 = offset; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1413 ZSTD_storeSeq(seqStorePtr, ip-anchor, anchor, offset + ZSTD_REP_MOVE, mLength-MINMATCH); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1414 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1415 } else { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1416 ip += ((ip-anchor) >> g_searchStrength) + 1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1417 continue; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1418 } } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1419 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1420 /* found a match : store it */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1421 ip += mLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1422 anchor = ip; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1423 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1424 if (ip <= ilimit) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1425 /* Fill Table */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1426 hashSmall[ZSTD_hashPtr(base+current+2, hBitsS, mls)] = current+2; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1427 hashLong[ZSTD_hashPtr(base+current+2, hBitsL, 8)] = current+2; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1428 hashSmall[ZSTD_hashPtr(ip-2, hBitsS, mls)] = (U32)(ip-2-base); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1429 hashLong[ZSTD_hashPtr(ip-2, hBitsL, 8)] = (U32)(ip-2-base); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1430 /* check immediate repcode */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1431 while (ip <= ilimit) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1432 U32 const current2 = (U32)(ip-base); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1433 U32 const repIndex2 = current2 - offset_2; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1434 const BYTE* repMatch2 = repIndex2 < dictLimit ? dictBase + repIndex2 : base + repIndex2; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1435 if ( (((U32)((dictLimit-1) - repIndex2) >= 3) & (repIndex2 > lowestIndex)) /* intentional overflow */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1436 && (MEM_read32(repMatch2) == MEM_read32(ip)) ) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1437 const BYTE* const repEnd2 = repIndex2 < dictLimit ? dictEnd : iend; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1438 size_t const repLength2 = ZSTD_count_2segments(ip+EQUAL_READ32, repMatch2+EQUAL_READ32, iend, repEnd2, lowPrefixPtr) + EQUAL_READ32; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1439 U32 tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset; /* swap offset_2 <=> offset_1 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1440 ZSTD_storeSeq(seqStorePtr, 0, anchor, 0, repLength2-MINMATCH); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1441 hashSmall[ZSTD_hashPtr(ip, hBitsS, mls)] = current2; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1442 hashLong[ZSTD_hashPtr(ip, hBitsL, 8)] = current2; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1443 ip += repLength2; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1444 anchor = ip; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1445 continue; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1446 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1447 break; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1448 } } } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1449 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1450 /* save reps for next block */ |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
1451 ctx->repToConfirm[0] = offset_1; ctx->repToConfirm[1] = offset_2; |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1452 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1453 /* Last Literals */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1454 { size_t const lastLLSize = iend - anchor; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1455 memcpy(seqStorePtr->lit, anchor, lastLLSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1456 seqStorePtr->lit += lastLLSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1457 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1458 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1459 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1460 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1461 static void ZSTD_compressBlock_doubleFast_extDict(ZSTD_CCtx* ctx, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1462 const void* src, size_t srcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1463 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1464 U32 const mls = ctx->params.cParams.searchLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1465 switch(mls) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1466 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1467 default: |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1468 case 4 : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1469 ZSTD_compressBlock_doubleFast_extDict_generic(ctx, src, srcSize, 4); return; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1470 case 5 : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1471 ZSTD_compressBlock_doubleFast_extDict_generic(ctx, src, srcSize, 5); return; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1472 case 6 : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1473 ZSTD_compressBlock_doubleFast_extDict_generic(ctx, src, srcSize, 6); return; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1474 case 7 : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1475 ZSTD_compressBlock_doubleFast_extDict_generic(ctx, src, srcSize, 7); return; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1476 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1477 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1478 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1479 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1480 /*-************************************* |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1481 * Binary Tree search |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1482 ***************************************/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1483 /** ZSTD_insertBt1() : add one or multiple positions to tree. |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1484 * ip : assumed <= iend-8 . |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1485 * @return : nb of positions added */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1486 static U32 ZSTD_insertBt1(ZSTD_CCtx* zc, const BYTE* const ip, const U32 mls, const BYTE* const iend, U32 nbCompares, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1487 U32 extDict) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1488 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1489 U32* const hashTable = zc->hashTable; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1490 U32 const hashLog = zc->params.cParams.hashLog; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1491 size_t const h = ZSTD_hashPtr(ip, hashLog, mls); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1492 U32* const bt = zc->chainTable; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1493 U32 const btLog = zc->params.cParams.chainLog - 1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1494 U32 const btMask = (1 << btLog) - 1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1495 U32 matchIndex = hashTable[h]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1496 size_t commonLengthSmaller=0, commonLengthLarger=0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1497 const BYTE* const base = zc->base; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1498 const BYTE* const dictBase = zc->dictBase; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1499 const U32 dictLimit = zc->dictLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1500 const BYTE* const dictEnd = dictBase + dictLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1501 const BYTE* const prefixStart = base + dictLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1502 const BYTE* match; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1503 const U32 current = (U32)(ip-base); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1504 const U32 btLow = btMask >= current ? 0 : current - btMask; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1505 U32* smallerPtr = bt + 2*(current&btMask); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1506 U32* largerPtr = smallerPtr + 1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1507 U32 dummy32; /* to be nullified at the end */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1508 U32 const windowLow = zc->lowLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1509 U32 matchEndIdx = current+8; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1510 size_t bestLength = 8; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1511 #ifdef ZSTD_C_PREDICT |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1512 U32 predictedSmall = *(bt + 2*((current-1)&btMask) + 0); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1513 U32 predictedLarge = *(bt + 2*((current-1)&btMask) + 1); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1514 predictedSmall += (predictedSmall>0); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1515 predictedLarge += (predictedLarge>0); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1516 #endif /* ZSTD_C_PREDICT */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1517 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1518 hashTable[h] = current; /* Update Hash Table */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1519 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1520 while (nbCompares-- && (matchIndex > windowLow)) { |
30822
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
1521 U32* const nextPtr = bt + 2*(matchIndex & btMask); |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1522 size_t matchLength = MIN(commonLengthSmaller, commonLengthLarger); /* guaranteed minimum nb of common bytes */ |
30822
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
1523 |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1524 #ifdef ZSTD_C_PREDICT /* note : can create issues when hlog small <= 11 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1525 const U32* predictPtr = bt + 2*((matchIndex-1) & btMask); /* written this way, as bt is a roll buffer */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1526 if (matchIndex == predictedSmall) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1527 /* no need to check length, result known */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1528 *smallerPtr = matchIndex; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1529 if (matchIndex <= btLow) { smallerPtr=&dummy32; break; } /* beyond tree size, stop the search */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1530 smallerPtr = nextPtr+1; /* new "smaller" => larger of match */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1531 matchIndex = nextPtr[1]; /* new matchIndex larger than previous (closer to current) */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1532 predictedSmall = predictPtr[1] + (predictPtr[1]>0); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1533 continue; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1534 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1535 if (matchIndex == predictedLarge) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1536 *largerPtr = matchIndex; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1537 if (matchIndex <= btLow) { largerPtr=&dummy32; break; } /* beyond tree size, stop the search */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1538 largerPtr = nextPtr; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1539 matchIndex = nextPtr[0]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1540 predictedLarge = predictPtr[0] + (predictPtr[0]>0); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1541 continue; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1542 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1543 #endif |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1544 if ((!extDict) || (matchIndex+matchLength >= dictLimit)) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1545 match = base + matchIndex; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1546 if (match[matchLength] == ip[matchLength]) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1547 matchLength += ZSTD_count(ip+matchLength+1, match+matchLength+1, iend) +1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1548 } else { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1549 match = dictBase + matchIndex; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1550 matchLength += ZSTD_count_2segments(ip+matchLength, match+matchLength, iend, dictEnd, prefixStart); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1551 if (matchIndex+matchLength >= dictLimit) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1552 match = base + matchIndex; /* to prepare for next usage of match[matchLength] */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1553 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1554 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1555 if (matchLength > bestLength) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1556 bestLength = matchLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1557 if (matchLength > matchEndIdx - matchIndex) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1558 matchEndIdx = matchIndex + (U32)matchLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1559 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1560 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1561 if (ip+matchLength == iend) /* equal : no way to know if inf or sup */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1562 break; /* drop , to guarantee consistency ; miss a bit of compression, but other solutions can corrupt the tree */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1563 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1564 if (match[matchLength] < ip[matchLength]) { /* necessarily within correct buffer */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1565 /* match is smaller than current */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1566 *smallerPtr = matchIndex; /* update smaller idx */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1567 commonLengthSmaller = matchLength; /* all smaller will now have at least this guaranteed common length */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1568 if (matchIndex <= btLow) { smallerPtr=&dummy32; break; } /* beyond tree size, stop the search */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1569 smallerPtr = nextPtr+1; /* new "smaller" => larger of match */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1570 matchIndex = nextPtr[1]; /* new matchIndex larger than previous (closer to current) */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1571 } else { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1572 /* match is larger than current */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1573 *largerPtr = matchIndex; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1574 commonLengthLarger = matchLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1575 if (matchIndex <= btLow) { largerPtr=&dummy32; break; } /* beyond tree size, stop the search */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1576 largerPtr = nextPtr; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1577 matchIndex = nextPtr[0]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1578 } } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1579 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1580 *smallerPtr = *largerPtr = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1581 if (bestLength > 384) return MIN(192, (U32)(bestLength - 384)); /* speed optimization */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1582 if (matchEndIdx > current + 8) return matchEndIdx - current - 8; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1583 return 1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1584 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1585 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1586 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1587 static size_t ZSTD_insertBtAndFindBestMatch ( |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1588 ZSTD_CCtx* zc, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1589 const BYTE* const ip, const BYTE* const iend, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1590 size_t* offsetPtr, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1591 U32 nbCompares, const U32 mls, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1592 U32 extDict) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1593 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1594 U32* const hashTable = zc->hashTable; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1595 U32 const hashLog = zc->params.cParams.hashLog; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1596 size_t const h = ZSTD_hashPtr(ip, hashLog, mls); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1597 U32* const bt = zc->chainTable; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1598 U32 const btLog = zc->params.cParams.chainLog - 1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1599 U32 const btMask = (1 << btLog) - 1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1600 U32 matchIndex = hashTable[h]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1601 size_t commonLengthSmaller=0, commonLengthLarger=0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1602 const BYTE* const base = zc->base; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1603 const BYTE* const dictBase = zc->dictBase; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1604 const U32 dictLimit = zc->dictLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1605 const BYTE* const dictEnd = dictBase + dictLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1606 const BYTE* const prefixStart = base + dictLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1607 const U32 current = (U32)(ip-base); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1608 const U32 btLow = btMask >= current ? 0 : current - btMask; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1609 const U32 windowLow = zc->lowLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1610 U32* smallerPtr = bt + 2*(current&btMask); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1611 U32* largerPtr = bt + 2*(current&btMask) + 1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1612 U32 matchEndIdx = current+8; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1613 U32 dummy32; /* to be nullified at the end */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1614 size_t bestLength = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1615 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1616 hashTable[h] = current; /* Update Hash Table */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1617 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1618 while (nbCompares-- && (matchIndex > windowLow)) { |
30822
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
1619 U32* const nextPtr = bt + 2*(matchIndex & btMask); |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1620 size_t matchLength = MIN(commonLengthSmaller, commonLengthLarger); /* guaranteed minimum nb of common bytes */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1621 const BYTE* match; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1622 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1623 if ((!extDict) || (matchIndex+matchLength >= dictLimit)) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1624 match = base + matchIndex; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1625 if (match[matchLength] == ip[matchLength]) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1626 matchLength += ZSTD_count(ip+matchLength+1, match+matchLength+1, iend) +1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1627 } else { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1628 match = dictBase + matchIndex; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1629 matchLength += ZSTD_count_2segments(ip+matchLength, match+matchLength, iend, dictEnd, prefixStart); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1630 if (matchIndex+matchLength >= dictLimit) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1631 match = base + matchIndex; /* to prepare for next usage of match[matchLength] */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1632 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1633 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1634 if (matchLength > bestLength) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1635 if (matchLength > matchEndIdx - matchIndex) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1636 matchEndIdx = matchIndex + (U32)matchLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1637 if ( (4*(int)(matchLength-bestLength)) > (int)(ZSTD_highbit32(current-matchIndex+1) - ZSTD_highbit32((U32)offsetPtr[0]+1)) ) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1638 bestLength = matchLength, *offsetPtr = ZSTD_REP_MOVE + current - matchIndex; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1639 if (ip+matchLength == iend) /* equal : no way to know if inf or sup */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1640 break; /* drop, to guarantee consistency (miss a little bit of compression) */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1641 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1642 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1643 if (match[matchLength] < ip[matchLength]) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1644 /* match is smaller than current */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1645 *smallerPtr = matchIndex; /* update smaller idx */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1646 commonLengthSmaller = matchLength; /* all smaller will now have at least this guaranteed common length */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1647 if (matchIndex <= btLow) { smallerPtr=&dummy32; break; } /* beyond tree size, stop the search */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1648 smallerPtr = nextPtr+1; /* new "smaller" => larger of match */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1649 matchIndex = nextPtr[1]; /* new matchIndex larger than previous (closer to current) */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1650 } else { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1651 /* match is larger than current */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1652 *largerPtr = matchIndex; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1653 commonLengthLarger = matchLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1654 if (matchIndex <= btLow) { largerPtr=&dummy32; break; } /* beyond tree size, stop the search */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1655 largerPtr = nextPtr; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1656 matchIndex = nextPtr[0]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1657 } } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1658 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1659 *smallerPtr = *largerPtr = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1660 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1661 zc->nextToUpdate = (matchEndIdx > current + 8) ? matchEndIdx - 8 : current+1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1662 return bestLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1663 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1664 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1665 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1666 static void ZSTD_updateTree(ZSTD_CCtx* zc, const BYTE* const ip, const BYTE* const iend, const U32 nbCompares, const U32 mls) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1667 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1668 const BYTE* const base = zc->base; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1669 const U32 target = (U32)(ip - base); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1670 U32 idx = zc->nextToUpdate; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1671 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1672 while(idx < target) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1673 idx += ZSTD_insertBt1(zc, base+idx, mls, iend, nbCompares, 0); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1674 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1675 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1676 /** ZSTD_BtFindBestMatch() : Tree updater, providing best match */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1677 static size_t ZSTD_BtFindBestMatch ( |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1678 ZSTD_CCtx* zc, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1679 const BYTE* const ip, const BYTE* const iLimit, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1680 size_t* offsetPtr, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1681 const U32 maxNbAttempts, const U32 mls) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1682 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1683 if (ip < zc->base + zc->nextToUpdate) return 0; /* skipped area */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1684 ZSTD_updateTree(zc, ip, iLimit, maxNbAttempts, mls); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1685 return ZSTD_insertBtAndFindBestMatch(zc, ip, iLimit, offsetPtr, maxNbAttempts, mls, 0); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1686 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1687 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1688 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1689 static size_t ZSTD_BtFindBestMatch_selectMLS ( |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1690 ZSTD_CCtx* zc, /* Index table will be updated */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1691 const BYTE* ip, const BYTE* const iLimit, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1692 size_t* offsetPtr, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1693 const U32 maxNbAttempts, const U32 matchLengthSearch) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1694 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1695 switch(matchLengthSearch) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1696 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1697 default : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1698 case 4 : return ZSTD_BtFindBestMatch(zc, ip, iLimit, offsetPtr, maxNbAttempts, 4); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1699 case 5 : return ZSTD_BtFindBestMatch(zc, ip, iLimit, offsetPtr, maxNbAttempts, 5); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1700 case 6 : return ZSTD_BtFindBestMatch(zc, ip, iLimit, offsetPtr, maxNbAttempts, 6); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1701 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1702 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1703 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1704 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1705 static void ZSTD_updateTree_extDict(ZSTD_CCtx* zc, const BYTE* const ip, const BYTE* const iend, const U32 nbCompares, const U32 mls) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1706 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1707 const BYTE* const base = zc->base; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1708 const U32 target = (U32)(ip - base); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1709 U32 idx = zc->nextToUpdate; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1710 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1711 while (idx < target) idx += ZSTD_insertBt1(zc, base+idx, mls, iend, nbCompares, 1); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1712 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1713 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1714 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1715 /** Tree updater, providing best match */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1716 static size_t ZSTD_BtFindBestMatch_extDict ( |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1717 ZSTD_CCtx* zc, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1718 const BYTE* const ip, const BYTE* const iLimit, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1719 size_t* offsetPtr, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1720 const U32 maxNbAttempts, const U32 mls) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1721 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1722 if (ip < zc->base + zc->nextToUpdate) return 0; /* skipped area */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1723 ZSTD_updateTree_extDict(zc, ip, iLimit, maxNbAttempts, mls); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1724 return ZSTD_insertBtAndFindBestMatch(zc, ip, iLimit, offsetPtr, maxNbAttempts, mls, 1); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1725 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1726 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1727 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1728 static size_t ZSTD_BtFindBestMatch_selectMLS_extDict ( |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1729 ZSTD_CCtx* zc, /* Index table will be updated */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1730 const BYTE* ip, const BYTE* const iLimit, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1731 size_t* offsetPtr, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1732 const U32 maxNbAttempts, const U32 matchLengthSearch) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1733 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1734 switch(matchLengthSearch) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1735 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1736 default : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1737 case 4 : return ZSTD_BtFindBestMatch_extDict(zc, ip, iLimit, offsetPtr, maxNbAttempts, 4); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1738 case 5 : return ZSTD_BtFindBestMatch_extDict(zc, ip, iLimit, offsetPtr, maxNbAttempts, 5); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1739 case 6 : return ZSTD_BtFindBestMatch_extDict(zc, ip, iLimit, offsetPtr, maxNbAttempts, 6); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1740 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1741 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1742 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1743 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1744 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1745 /* ********************************* |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1746 * Hash Chain |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1747 ***********************************/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1748 #define NEXT_IN_CHAIN(d, mask) chainTable[(d) & mask] |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1749 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1750 /* Update chains up to ip (excluded) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1751 Assumption : always within prefix (ie. not within extDict) */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1752 FORCE_INLINE |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1753 U32 ZSTD_insertAndFindFirstIndex (ZSTD_CCtx* zc, const BYTE* ip, U32 mls) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1754 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1755 U32* const hashTable = zc->hashTable; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1756 const U32 hashLog = zc->params.cParams.hashLog; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1757 U32* const chainTable = zc->chainTable; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1758 const U32 chainMask = (1 << zc->params.cParams.chainLog) - 1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1759 const BYTE* const base = zc->base; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1760 const U32 target = (U32)(ip - base); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1761 U32 idx = zc->nextToUpdate; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1762 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1763 while(idx < target) { /* catch up */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1764 size_t const h = ZSTD_hashPtr(base+idx, hashLog, mls); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1765 NEXT_IN_CHAIN(idx, chainMask) = hashTable[h]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1766 hashTable[h] = idx; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1767 idx++; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1768 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1769 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1770 zc->nextToUpdate = target; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1771 return hashTable[ZSTD_hashPtr(ip, hashLog, mls)]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1772 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1773 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1774 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1775 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1776 FORCE_INLINE /* inlining is important to hardwire a hot branch (template emulation) */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1777 size_t ZSTD_HcFindBestMatch_generic ( |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1778 ZSTD_CCtx* zc, /* Index table will be updated */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1779 const BYTE* const ip, const BYTE* const iLimit, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1780 size_t* offsetPtr, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1781 const U32 maxNbAttempts, const U32 mls, const U32 extDict) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1782 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1783 U32* const chainTable = zc->chainTable; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1784 const U32 chainSize = (1 << zc->params.cParams.chainLog); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1785 const U32 chainMask = chainSize-1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1786 const BYTE* const base = zc->base; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1787 const BYTE* const dictBase = zc->dictBase; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1788 const U32 dictLimit = zc->dictLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1789 const BYTE* const prefixStart = base + dictLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1790 const BYTE* const dictEnd = dictBase + dictLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1791 const U32 lowLimit = zc->lowLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1792 const U32 current = (U32)(ip-base); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1793 const U32 minChain = current > chainSize ? current - chainSize : 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1794 int nbAttempts=maxNbAttempts; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1795 size_t ml=EQUAL_READ32-1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1796 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1797 /* HC4 match finder */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1798 U32 matchIndex = ZSTD_insertAndFindFirstIndex (zc, ip, mls); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1799 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1800 for ( ; (matchIndex>lowLimit) & (nbAttempts>0) ; nbAttempts--) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1801 const BYTE* match; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1802 size_t currentMl=0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1803 if ((!extDict) || matchIndex >= dictLimit) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1804 match = base + matchIndex; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1805 if (match[ml] == ip[ml]) /* potentially better */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1806 currentMl = ZSTD_count(ip, match, iLimit); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1807 } else { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1808 match = dictBase + matchIndex; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1809 if (MEM_read32(match) == MEM_read32(ip)) /* assumption : matchIndex <= dictLimit-4 (by table construction) */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1810 currentMl = ZSTD_count_2segments(ip+EQUAL_READ32, match+EQUAL_READ32, iLimit, dictEnd, prefixStart) + EQUAL_READ32; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1811 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1812 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1813 /* save best solution */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1814 if (currentMl > ml) { ml = currentMl; *offsetPtr = current - matchIndex + ZSTD_REP_MOVE; if (ip+currentMl == iLimit) break; /* best possible, and avoid read overflow*/ } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1815 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1816 if (matchIndex <= minChain) break; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1817 matchIndex = NEXT_IN_CHAIN(matchIndex, chainMask); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1818 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1819 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1820 return ml; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1821 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1822 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1823 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1824 FORCE_INLINE size_t ZSTD_HcFindBestMatch_selectMLS ( |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1825 ZSTD_CCtx* zc, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1826 const BYTE* ip, const BYTE* const iLimit, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1827 size_t* offsetPtr, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1828 const U32 maxNbAttempts, const U32 matchLengthSearch) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1829 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1830 switch(matchLengthSearch) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1831 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1832 default : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1833 case 4 : return ZSTD_HcFindBestMatch_generic(zc, ip, iLimit, offsetPtr, maxNbAttempts, 4, 0); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1834 case 5 : return ZSTD_HcFindBestMatch_generic(zc, ip, iLimit, offsetPtr, maxNbAttempts, 5, 0); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1835 case 6 : return ZSTD_HcFindBestMatch_generic(zc, ip, iLimit, offsetPtr, maxNbAttempts, 6, 0); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1836 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1837 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1838 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1839 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1840 FORCE_INLINE size_t ZSTD_HcFindBestMatch_extDict_selectMLS ( |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1841 ZSTD_CCtx* zc, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1842 const BYTE* ip, const BYTE* const iLimit, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1843 size_t* offsetPtr, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1844 const U32 maxNbAttempts, const U32 matchLengthSearch) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1845 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1846 switch(matchLengthSearch) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1847 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1848 default : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1849 case 4 : return ZSTD_HcFindBestMatch_generic(zc, ip, iLimit, offsetPtr, maxNbAttempts, 4, 1); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1850 case 5 : return ZSTD_HcFindBestMatch_generic(zc, ip, iLimit, offsetPtr, maxNbAttempts, 5, 1); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1851 case 6 : return ZSTD_HcFindBestMatch_generic(zc, ip, iLimit, offsetPtr, maxNbAttempts, 6, 1); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1852 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1853 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1854 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1855 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1856 /* ******************************* |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1857 * Common parser - lazy strategy |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1858 *********************************/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1859 FORCE_INLINE |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1860 void ZSTD_compressBlock_lazy_generic(ZSTD_CCtx* ctx, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1861 const void* src, size_t srcSize, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1862 const U32 searchMethod, const U32 depth) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1863 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1864 seqStore_t* seqStorePtr = &(ctx->seqStore); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1865 const BYTE* const istart = (const BYTE*)src; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1866 const BYTE* ip = istart; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1867 const BYTE* anchor = istart; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1868 const BYTE* const iend = istart + srcSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1869 const BYTE* const ilimit = iend - 8; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1870 const BYTE* const base = ctx->base + ctx->dictLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1871 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1872 U32 const maxSearches = 1 << ctx->params.cParams.searchLog; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1873 U32 const mls = ctx->params.cParams.searchLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1874 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1875 typedef size_t (*searchMax_f)(ZSTD_CCtx* zc, const BYTE* ip, const BYTE* iLimit, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1876 size_t* offsetPtr, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1877 U32 maxNbAttempts, U32 matchLengthSearch); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1878 searchMax_f const searchMax = searchMethod ? ZSTD_BtFindBestMatch_selectMLS : ZSTD_HcFindBestMatch_selectMLS; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1879 U32 offset_1 = ctx->rep[0], offset_2 = ctx->rep[1], savedOffset=0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1880 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1881 /* init */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1882 ip += (ip==base); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1883 ctx->nextToUpdate3 = ctx->nextToUpdate; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1884 { U32 const maxRep = (U32)(ip-base); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1885 if (offset_2 > maxRep) savedOffset = offset_2, offset_2 = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1886 if (offset_1 > maxRep) savedOffset = offset_1, offset_1 = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1887 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1888 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1889 /* Match Loop */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1890 while (ip < ilimit) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1891 size_t matchLength=0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1892 size_t offset=0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1893 const BYTE* start=ip+1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1894 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1895 /* check repCode */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1896 if ((offset_1>0) & (MEM_read32(ip+1) == MEM_read32(ip+1 - offset_1))) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1897 /* repcode : we take it */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1898 matchLength = ZSTD_count(ip+1+EQUAL_READ32, ip+1+EQUAL_READ32-offset_1, iend) + EQUAL_READ32; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1899 if (depth==0) goto _storeSequence; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1900 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1901 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1902 /* first search (depth 0) */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1903 { size_t offsetFound = 99999999; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1904 size_t const ml2 = searchMax(ctx, ip, iend, &offsetFound, maxSearches, mls); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1905 if (ml2 > matchLength) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1906 matchLength = ml2, start = ip, offset=offsetFound; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1907 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1908 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1909 if (matchLength < EQUAL_READ32) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1910 ip += ((ip-anchor) >> g_searchStrength) + 1; /* jump faster over incompressible sections */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1911 continue; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1912 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1913 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1914 /* let's try to find a better solution */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1915 if (depth>=1) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1916 while (ip<ilimit) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1917 ip ++; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1918 if ((offset) && ((offset_1>0) & (MEM_read32(ip) == MEM_read32(ip - offset_1)))) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1919 size_t const mlRep = ZSTD_count(ip+EQUAL_READ32, ip+EQUAL_READ32-offset_1, iend) + EQUAL_READ32; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1920 int const gain2 = (int)(mlRep * 3); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1921 int const gain1 = (int)(matchLength*3 - ZSTD_highbit32((U32)offset+1) + 1); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1922 if ((mlRep >= EQUAL_READ32) && (gain2 > gain1)) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1923 matchLength = mlRep, offset = 0, start = ip; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1924 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1925 { size_t offset2=99999999; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1926 size_t const ml2 = searchMax(ctx, ip, iend, &offset2, maxSearches, mls); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1927 int const gain2 = (int)(ml2*4 - ZSTD_highbit32((U32)offset2+1)); /* raw approx */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1928 int const gain1 = (int)(matchLength*4 - ZSTD_highbit32((U32)offset+1) + 4); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1929 if ((ml2 >= EQUAL_READ32) && (gain2 > gain1)) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1930 matchLength = ml2, offset = offset2, start = ip; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1931 continue; /* search a better one */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1932 } } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1933 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1934 /* let's find an even better one */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1935 if ((depth==2) && (ip<ilimit)) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1936 ip ++; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1937 if ((offset) && ((offset_1>0) & (MEM_read32(ip) == MEM_read32(ip - offset_1)))) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1938 size_t const ml2 = ZSTD_count(ip+EQUAL_READ32, ip+EQUAL_READ32-offset_1, iend) + EQUAL_READ32; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1939 int const gain2 = (int)(ml2 * 4); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1940 int const gain1 = (int)(matchLength*4 - ZSTD_highbit32((U32)offset+1) + 1); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1941 if ((ml2 >= EQUAL_READ32) && (gain2 > gain1)) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1942 matchLength = ml2, offset = 0, start = ip; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1943 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1944 { size_t offset2=99999999; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1945 size_t const ml2 = searchMax(ctx, ip, iend, &offset2, maxSearches, mls); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1946 int const gain2 = (int)(ml2*4 - ZSTD_highbit32((U32)offset2+1)); /* raw approx */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1947 int const gain1 = (int)(matchLength*4 - ZSTD_highbit32((U32)offset+1) + 7); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1948 if ((ml2 >= EQUAL_READ32) && (gain2 > gain1)) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1949 matchLength = ml2, offset = offset2, start = ip; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1950 continue; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1951 } } } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1952 break; /* nothing found : store previous solution */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1953 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1954 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1955 /* catch up */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1956 if (offset) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1957 while ((start>anchor) && (start>base+offset-ZSTD_REP_MOVE) && (start[-1] == start[-1-offset+ZSTD_REP_MOVE])) /* only search for offset within prefix */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1958 { start--; matchLength++; } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1959 offset_2 = offset_1; offset_1 = (U32)(offset - ZSTD_REP_MOVE); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1960 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1961 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1962 /* store sequence */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1963 _storeSequence: |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1964 { size_t const litLength = start - anchor; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1965 ZSTD_storeSeq(seqStorePtr, litLength, anchor, (U32)offset, matchLength-MINMATCH); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1966 anchor = ip = start + matchLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1967 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1968 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1969 /* check immediate repcode */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1970 while ( (ip <= ilimit) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1971 && ((offset_2>0) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1972 & (MEM_read32(ip) == MEM_read32(ip - offset_2)) )) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1973 /* store sequence */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1974 matchLength = ZSTD_count(ip+EQUAL_READ32, ip+EQUAL_READ32-offset_2, iend) + EQUAL_READ32; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1975 offset = offset_2; offset_2 = offset_1; offset_1 = (U32)offset; /* swap repcodes */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1976 ZSTD_storeSeq(seqStorePtr, 0, anchor, 0, matchLength-MINMATCH); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1977 ip += matchLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1978 anchor = ip; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1979 continue; /* faster when present ... (?) */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1980 } } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1981 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1982 /* Save reps for next block */ |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
1983 ctx->repToConfirm[0] = offset_1 ? offset_1 : savedOffset; |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
1984 ctx->repToConfirm[1] = offset_2 ? offset_2 : savedOffset; |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1985 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1986 /* Last Literals */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1987 { size_t const lastLLSize = iend - anchor; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1988 memcpy(seqStorePtr->lit, anchor, lastLLSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1989 seqStorePtr->lit += lastLLSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1990 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1991 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1992 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1993 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1994 static void ZSTD_compressBlock_btlazy2(ZSTD_CCtx* ctx, const void* src, size_t srcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1995 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1996 ZSTD_compressBlock_lazy_generic(ctx, src, srcSize, 1, 2); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1997 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1998 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1999 static void ZSTD_compressBlock_lazy2(ZSTD_CCtx* ctx, const void* src, size_t srcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2000 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2001 ZSTD_compressBlock_lazy_generic(ctx, src, srcSize, 0, 2); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2002 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2003 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2004 static void ZSTD_compressBlock_lazy(ZSTD_CCtx* ctx, const void* src, size_t srcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2005 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2006 ZSTD_compressBlock_lazy_generic(ctx, src, srcSize, 0, 1); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2007 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2008 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2009 static void ZSTD_compressBlock_greedy(ZSTD_CCtx* ctx, const void* src, size_t srcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2010 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2011 ZSTD_compressBlock_lazy_generic(ctx, src, srcSize, 0, 0); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2012 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2013 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2014 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2015 FORCE_INLINE |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2016 void ZSTD_compressBlock_lazy_extDict_generic(ZSTD_CCtx* ctx, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2017 const void* src, size_t srcSize, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2018 const U32 searchMethod, const U32 depth) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2019 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2020 seqStore_t* seqStorePtr = &(ctx->seqStore); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2021 const BYTE* const istart = (const BYTE*)src; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2022 const BYTE* ip = istart; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2023 const BYTE* anchor = istart; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2024 const BYTE* const iend = istart + srcSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2025 const BYTE* const ilimit = iend - 8; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2026 const BYTE* const base = ctx->base; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2027 const U32 dictLimit = ctx->dictLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2028 const U32 lowestIndex = ctx->lowLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2029 const BYTE* const prefixStart = base + dictLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2030 const BYTE* const dictBase = ctx->dictBase; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2031 const BYTE* const dictEnd = dictBase + dictLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2032 const BYTE* const dictStart = dictBase + ctx->lowLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2033 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2034 const U32 maxSearches = 1 << ctx->params.cParams.searchLog; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2035 const U32 mls = ctx->params.cParams.searchLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2036 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2037 typedef size_t (*searchMax_f)(ZSTD_CCtx* zc, const BYTE* ip, const BYTE* iLimit, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2038 size_t* offsetPtr, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2039 U32 maxNbAttempts, U32 matchLengthSearch); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2040 searchMax_f searchMax = searchMethod ? ZSTD_BtFindBestMatch_selectMLS_extDict : ZSTD_HcFindBestMatch_extDict_selectMLS; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2041 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2042 U32 offset_1 = ctx->rep[0], offset_2 = ctx->rep[1]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2043 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2044 /* init */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2045 ctx->nextToUpdate3 = ctx->nextToUpdate; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2046 ip += (ip == prefixStart); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2047 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2048 /* Match Loop */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2049 while (ip < ilimit) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2050 size_t matchLength=0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2051 size_t offset=0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2052 const BYTE* start=ip+1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2053 U32 current = (U32)(ip-base); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2054 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2055 /* check repCode */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2056 { const U32 repIndex = (U32)(current+1 - offset_1); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2057 const BYTE* const repBase = repIndex < dictLimit ? dictBase : base; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2058 const BYTE* const repMatch = repBase + repIndex; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2059 if (((U32)((dictLimit-1) - repIndex) >= 3) & (repIndex > lowestIndex)) /* intentional overflow */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2060 if (MEM_read32(ip+1) == MEM_read32(repMatch)) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2061 /* repcode detected we should take it */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2062 const BYTE* const repEnd = repIndex < dictLimit ? dictEnd : iend; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2063 matchLength = ZSTD_count_2segments(ip+1+EQUAL_READ32, repMatch+EQUAL_READ32, iend, repEnd, prefixStart) + EQUAL_READ32; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2064 if (depth==0) goto _storeSequence; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2065 } } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2066 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2067 /* first search (depth 0) */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2068 { size_t offsetFound = 99999999; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2069 size_t const ml2 = searchMax(ctx, ip, iend, &offsetFound, maxSearches, mls); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2070 if (ml2 > matchLength) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2071 matchLength = ml2, start = ip, offset=offsetFound; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2072 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2073 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2074 if (matchLength < EQUAL_READ32) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2075 ip += ((ip-anchor) >> g_searchStrength) + 1; /* jump faster over incompressible sections */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2076 continue; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2077 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2078 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2079 /* let's try to find a better solution */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2080 if (depth>=1) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2081 while (ip<ilimit) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2082 ip ++; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2083 current++; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2084 /* check repCode */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2085 if (offset) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2086 const U32 repIndex = (U32)(current - offset_1); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2087 const BYTE* const repBase = repIndex < dictLimit ? dictBase : base; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2088 const BYTE* const repMatch = repBase + repIndex; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2089 if (((U32)((dictLimit-1) - repIndex) >= 3) & (repIndex > lowestIndex)) /* intentional overflow */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2090 if (MEM_read32(ip) == MEM_read32(repMatch)) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2091 /* repcode detected */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2092 const BYTE* const repEnd = repIndex < dictLimit ? dictEnd : iend; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2093 size_t const repLength = ZSTD_count_2segments(ip+EQUAL_READ32, repMatch+EQUAL_READ32, iend, repEnd, prefixStart) + EQUAL_READ32; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2094 int const gain2 = (int)(repLength * 3); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2095 int const gain1 = (int)(matchLength*3 - ZSTD_highbit32((U32)offset+1) + 1); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2096 if ((repLength >= EQUAL_READ32) && (gain2 > gain1)) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2097 matchLength = repLength, offset = 0, start = ip; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2098 } } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2099 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2100 /* search match, depth 1 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2101 { size_t offset2=99999999; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2102 size_t const ml2 = searchMax(ctx, ip, iend, &offset2, maxSearches, mls); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2103 int const gain2 = (int)(ml2*4 - ZSTD_highbit32((U32)offset2+1)); /* raw approx */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2104 int const gain1 = (int)(matchLength*4 - ZSTD_highbit32((U32)offset+1) + 4); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2105 if ((ml2 >= EQUAL_READ32) && (gain2 > gain1)) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2106 matchLength = ml2, offset = offset2, start = ip; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2107 continue; /* search a better one */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2108 } } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2109 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2110 /* let's find an even better one */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2111 if ((depth==2) && (ip<ilimit)) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2112 ip ++; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2113 current++; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2114 /* check repCode */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2115 if (offset) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2116 const U32 repIndex = (U32)(current - offset_1); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2117 const BYTE* const repBase = repIndex < dictLimit ? dictBase : base; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2118 const BYTE* const repMatch = repBase + repIndex; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2119 if (((U32)((dictLimit-1) - repIndex) >= 3) & (repIndex > lowestIndex)) /* intentional overflow */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2120 if (MEM_read32(ip) == MEM_read32(repMatch)) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2121 /* repcode detected */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2122 const BYTE* const repEnd = repIndex < dictLimit ? dictEnd : iend; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2123 size_t repLength = ZSTD_count_2segments(ip+EQUAL_READ32, repMatch+EQUAL_READ32, iend, repEnd, prefixStart) + EQUAL_READ32; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2124 int gain2 = (int)(repLength * 4); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2125 int gain1 = (int)(matchLength*4 - ZSTD_highbit32((U32)offset+1) + 1); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2126 if ((repLength >= EQUAL_READ32) && (gain2 > gain1)) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2127 matchLength = repLength, offset = 0, start = ip; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2128 } } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2129 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2130 /* search match, depth 2 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2131 { size_t offset2=99999999; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2132 size_t const ml2 = searchMax(ctx, ip, iend, &offset2, maxSearches, mls); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2133 int const gain2 = (int)(ml2*4 - ZSTD_highbit32((U32)offset2+1)); /* raw approx */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2134 int const gain1 = (int)(matchLength*4 - ZSTD_highbit32((U32)offset+1) + 7); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2135 if ((ml2 >= EQUAL_READ32) && (gain2 > gain1)) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2136 matchLength = ml2, offset = offset2, start = ip; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2137 continue; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2138 } } } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2139 break; /* nothing found : store previous solution */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2140 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2141 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2142 /* catch up */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2143 if (offset) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2144 U32 const matchIndex = (U32)((start-base) - (offset - ZSTD_REP_MOVE)); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2145 const BYTE* match = (matchIndex < dictLimit) ? dictBase + matchIndex : base + matchIndex; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2146 const BYTE* const mStart = (matchIndex < dictLimit) ? dictStart : prefixStart; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2147 while ((start>anchor) && (match>mStart) && (start[-1] == match[-1])) { start--; match--; matchLength++; } /* catch up */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2148 offset_2 = offset_1; offset_1 = (U32)(offset - ZSTD_REP_MOVE); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2149 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2150 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2151 /* store sequence */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2152 _storeSequence: |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2153 { size_t const litLength = start - anchor; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2154 ZSTD_storeSeq(seqStorePtr, litLength, anchor, (U32)offset, matchLength-MINMATCH); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2155 anchor = ip = start + matchLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2156 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2157 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2158 /* check immediate repcode */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2159 while (ip <= ilimit) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2160 const U32 repIndex = (U32)((ip-base) - offset_2); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2161 const BYTE* const repBase = repIndex < dictLimit ? dictBase : base; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2162 const BYTE* const repMatch = repBase + repIndex; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2163 if (((U32)((dictLimit-1) - repIndex) >= 3) & (repIndex > lowestIndex)) /* intentional overflow */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2164 if (MEM_read32(ip) == MEM_read32(repMatch)) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2165 /* repcode detected we should take it */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2166 const BYTE* const repEnd = repIndex < dictLimit ? dictEnd : iend; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2167 matchLength = ZSTD_count_2segments(ip+EQUAL_READ32, repMatch+EQUAL_READ32, iend, repEnd, prefixStart) + EQUAL_READ32; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2168 offset = offset_2; offset_2 = offset_1; offset_1 = (U32)offset; /* swap offset history */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2169 ZSTD_storeSeq(seqStorePtr, 0, anchor, 0, matchLength-MINMATCH); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2170 ip += matchLength; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2171 anchor = ip; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2172 continue; /* faster when present ... (?) */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2173 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2174 break; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2175 } } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2176 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2177 /* Save reps for next block */ |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2178 ctx->repToConfirm[0] = offset_1; ctx->repToConfirm[1] = offset_2; |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2179 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2180 /* Last Literals */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2181 { size_t const lastLLSize = iend - anchor; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2182 memcpy(seqStorePtr->lit, anchor, lastLLSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2183 seqStorePtr->lit += lastLLSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2184 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2185 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2186 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2187 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2188 void ZSTD_compressBlock_greedy_extDict(ZSTD_CCtx* ctx, const void* src, size_t srcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2189 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2190 ZSTD_compressBlock_lazy_extDict_generic(ctx, src, srcSize, 0, 0); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2191 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2192 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2193 static void ZSTD_compressBlock_lazy_extDict(ZSTD_CCtx* ctx, const void* src, size_t srcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2194 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2195 ZSTD_compressBlock_lazy_extDict_generic(ctx, src, srcSize, 0, 1); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2196 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2197 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2198 static void ZSTD_compressBlock_lazy2_extDict(ZSTD_CCtx* ctx, const void* src, size_t srcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2199 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2200 ZSTD_compressBlock_lazy_extDict_generic(ctx, src, srcSize, 0, 2); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2201 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2202 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2203 static void ZSTD_compressBlock_btlazy2_extDict(ZSTD_CCtx* ctx, const void* src, size_t srcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2204 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2205 ZSTD_compressBlock_lazy_extDict_generic(ctx, src, srcSize, 1, 2); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2206 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2207 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2208 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2209 /* The optimal parser */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2210 #include "zstd_opt.h" |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2211 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2212 static void ZSTD_compressBlock_btopt(ZSTD_CCtx* ctx, const void* src, size_t srcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2213 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2214 #ifdef ZSTD_OPT_H_91842398743 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2215 ZSTD_compressBlock_opt_generic(ctx, src, srcSize, 0); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2216 #else |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2217 (void)ctx; (void)src; (void)srcSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2218 return; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2219 #endif |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2220 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2221 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2222 static void ZSTD_compressBlock_btopt2(ZSTD_CCtx* ctx, const void* src, size_t srcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2223 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2224 #ifdef ZSTD_OPT_H_91842398743 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2225 ZSTD_compressBlock_opt_generic(ctx, src, srcSize, 1); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2226 #else |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2227 (void)ctx; (void)src; (void)srcSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2228 return; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2229 #endif |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2230 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2231 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2232 static void ZSTD_compressBlock_btopt_extDict(ZSTD_CCtx* ctx, const void* src, size_t srcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2233 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2234 #ifdef ZSTD_OPT_H_91842398743 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2235 ZSTD_compressBlock_opt_extDict_generic(ctx, src, srcSize, 0); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2236 #else |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2237 (void)ctx; (void)src; (void)srcSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2238 return; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2239 #endif |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2240 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2241 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2242 static void ZSTD_compressBlock_btopt2_extDict(ZSTD_CCtx* ctx, const void* src, size_t srcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2243 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2244 #ifdef ZSTD_OPT_H_91842398743 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2245 ZSTD_compressBlock_opt_extDict_generic(ctx, src, srcSize, 1); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2246 #else |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2247 (void)ctx; (void)src; (void)srcSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2248 return; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2249 #endif |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2250 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2251 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2252 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2253 typedef void (*ZSTD_blockCompressor) (ZSTD_CCtx* ctx, const void* src, size_t srcSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2254 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2255 static ZSTD_blockCompressor ZSTD_selectBlockCompressor(ZSTD_strategy strat, int extDict) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2256 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2257 static const ZSTD_blockCompressor blockCompressor[2][8] = { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2258 { ZSTD_compressBlock_fast, ZSTD_compressBlock_doubleFast, ZSTD_compressBlock_greedy, ZSTD_compressBlock_lazy, ZSTD_compressBlock_lazy2, ZSTD_compressBlock_btlazy2, ZSTD_compressBlock_btopt, ZSTD_compressBlock_btopt2 }, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2259 { ZSTD_compressBlock_fast_extDict, ZSTD_compressBlock_doubleFast_extDict, ZSTD_compressBlock_greedy_extDict, ZSTD_compressBlock_lazy_extDict,ZSTD_compressBlock_lazy2_extDict, ZSTD_compressBlock_btlazy2_extDict, ZSTD_compressBlock_btopt_extDict, ZSTD_compressBlock_btopt2_extDict } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2260 }; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2261 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2262 return blockCompressor[extDict][(U32)strat]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2263 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2264 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2265 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2266 static size_t ZSTD_compressBlock_internal(ZSTD_CCtx* zc, void* dst, size_t dstCapacity, const void* src, size_t srcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2267 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2268 ZSTD_blockCompressor const blockCompressor = ZSTD_selectBlockCompressor(zc->params.cParams.strategy, zc->lowLimit < zc->dictLimit); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2269 const BYTE* const base = zc->base; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2270 const BYTE* const istart = (const BYTE*)src; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2271 const U32 current = (U32)(istart-base); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2272 if (srcSize < MIN_CBLOCK_SIZE+ZSTD_blockHeaderSize+1) return 0; /* don't even attempt compression below a certain srcSize */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2273 ZSTD_resetSeqStore(&(zc->seqStore)); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2274 if (current > zc->nextToUpdate + 384) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2275 zc->nextToUpdate = current - MIN(192, (U32)(current - zc->nextToUpdate - 384)); /* update tree not updated after finding very long rep matches */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2276 blockCompressor(zc, src, srcSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2277 return ZSTD_compressSequences(zc, dst, dstCapacity, srcSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2278 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2279 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2280 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2281 /*! ZSTD_compress_generic() : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2282 * Compress a chunk of data into one or multiple blocks. |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2283 * All blocks will be terminated, all input will be consumed. |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2284 * Function will issue an error if there is not enough `dstCapacity` to hold the compressed content. |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2285 * Frame is supposed already started (header already produced) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2286 * @return : compressed size, or an error code |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2287 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2288 static size_t ZSTD_compress_generic (ZSTD_CCtx* cctx, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2289 void* dst, size_t dstCapacity, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2290 const void* src, size_t srcSize, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2291 U32 lastFrameChunk) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2292 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2293 size_t blockSize = cctx->blockSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2294 size_t remaining = srcSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2295 const BYTE* ip = (const BYTE*)src; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2296 BYTE* const ostart = (BYTE*)dst; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2297 BYTE* op = ostart; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2298 U32 const maxDist = 1 << cctx->params.cParams.windowLog; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2299 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2300 if (cctx->params.fParams.checksumFlag && srcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2301 XXH64_update(&cctx->xxhState, src, srcSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2302 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2303 while (remaining) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2304 U32 const lastBlock = lastFrameChunk & (blockSize >= remaining); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2305 size_t cSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2306 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2307 if (dstCapacity < ZSTD_blockHeaderSize + MIN_CBLOCK_SIZE) return ERROR(dstSize_tooSmall); /* not enough space to store compressed block */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2308 if (remaining < blockSize) blockSize = remaining; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2309 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2310 /* preemptive overflow correction */ |
30822
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
2311 if (cctx->lowLimit > (2U<<30)) { |
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
2312 U32 const cycleMask = (1 << ZSTD_cycleLog(cctx->params.cParams.hashLog, cctx->params.cParams.strategy)) - 1; |
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
2313 U32 const current = (U32)(ip - cctx->base); |
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
2314 U32 const newCurrent = (current & cycleMask) + (1 << cctx->params.cParams.windowLog); |
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
2315 U32 const correction = current - newCurrent; |
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
2316 ZSTD_STATIC_ASSERT(ZSTD_WINDOWLOG_MAX_64 <= 30); |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2317 ZSTD_reduceIndex(cctx, correction); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2318 cctx->base += correction; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2319 cctx->dictBase += correction; |
30822
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
2320 cctx->lowLimit -= correction; |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2321 cctx->dictLimit -= correction; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2322 if (cctx->nextToUpdate < correction) cctx->nextToUpdate = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2323 else cctx->nextToUpdate -= correction; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2324 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2325 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2326 if ((U32)(ip+blockSize - cctx->base) > cctx->loadedDictEnd + maxDist) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2327 /* enforce maxDist */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2328 U32 const newLowLimit = (U32)(ip+blockSize - cctx->base) - maxDist; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2329 if (cctx->lowLimit < newLowLimit) cctx->lowLimit = newLowLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2330 if (cctx->dictLimit < cctx->lowLimit) cctx->dictLimit = cctx->lowLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2331 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2332 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2333 cSize = ZSTD_compressBlock_internal(cctx, op+ZSTD_blockHeaderSize, dstCapacity-ZSTD_blockHeaderSize, ip, blockSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2334 if (ZSTD_isError(cSize)) return cSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2335 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2336 if (cSize == 0) { /* block is not compressible */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2337 U32 const cBlockHeader24 = lastBlock + (((U32)bt_raw)<<1) + (U32)(blockSize << 3); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2338 if (blockSize + ZSTD_blockHeaderSize > dstCapacity) return ERROR(dstSize_tooSmall); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2339 MEM_writeLE32(op, cBlockHeader24); /* no pb, 4th byte will be overwritten */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2340 memcpy(op + ZSTD_blockHeaderSize, ip, blockSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2341 cSize = ZSTD_blockHeaderSize+blockSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2342 } else { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2343 U32 const cBlockHeader24 = lastBlock + (((U32)bt_compressed)<<1) + (U32)(cSize << 3); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2344 MEM_writeLE24(op, cBlockHeader24); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2345 cSize += ZSTD_blockHeaderSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2346 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2347 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2348 remaining -= blockSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2349 dstCapacity -= cSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2350 ip += blockSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2351 op += cSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2352 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2353 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2354 if (lastFrameChunk && (op>ostart)) cctx->stage = ZSTDcs_ending; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2355 return op-ostart; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2356 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2357 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2358 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2359 static size_t ZSTD_writeFrameHeader(void* dst, size_t dstCapacity, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2360 ZSTD_parameters params, U64 pledgedSrcSize, U32 dictID) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2361 { BYTE* const op = (BYTE*)dst; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2362 U32 const dictIDSizeCode = (dictID>0) + (dictID>=256) + (dictID>=65536); /* 0-3 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2363 U32 const checksumFlag = params.fParams.checksumFlag>0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2364 U32 const windowSize = 1U << params.cParams.windowLog; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2365 U32 const singleSegment = params.fParams.contentSizeFlag && (windowSize > (pledgedSrcSize-1)); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2366 BYTE const windowLogByte = (BYTE)((params.cParams.windowLog - ZSTD_WINDOWLOG_ABSOLUTEMIN) << 3); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2367 U32 const fcsCode = params.fParams.contentSizeFlag ? |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2368 (pledgedSrcSize>=256) + (pledgedSrcSize>=65536+256) + (pledgedSrcSize>=0xFFFFFFFFU) : /* 0-3 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2369 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2370 BYTE const frameHeaderDecriptionByte = (BYTE)(dictIDSizeCode + (checksumFlag<<2) + (singleSegment<<5) + (fcsCode<<6) ); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2371 size_t pos; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2372 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2373 if (dstCapacity < ZSTD_frameHeaderSize_max) return ERROR(dstSize_tooSmall); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2374 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2375 MEM_writeLE32(dst, ZSTD_MAGICNUMBER); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2376 op[4] = frameHeaderDecriptionByte; pos=5; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2377 if (!singleSegment) op[pos++] = windowLogByte; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2378 switch(dictIDSizeCode) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2379 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2380 default: /* impossible */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2381 case 0 : break; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2382 case 1 : op[pos] = (BYTE)(dictID); pos++; break; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2383 case 2 : MEM_writeLE16(op+pos, (U16)dictID); pos+=2; break; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2384 case 3 : MEM_writeLE32(op+pos, dictID); pos+=4; break; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2385 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2386 switch(fcsCode) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2387 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2388 default: /* impossible */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2389 case 0 : if (singleSegment) op[pos++] = (BYTE)(pledgedSrcSize); break; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2390 case 1 : MEM_writeLE16(op+pos, (U16)(pledgedSrcSize-256)); pos+=2; break; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2391 case 2 : MEM_writeLE32(op+pos, (U32)(pledgedSrcSize)); pos+=4; break; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2392 case 3 : MEM_writeLE64(op+pos, (U64)(pledgedSrcSize)); pos+=8; break; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2393 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2394 return pos; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2395 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2396 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2397 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2398 static size_t ZSTD_compressContinue_internal (ZSTD_CCtx* cctx, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2399 void* dst, size_t dstCapacity, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2400 const void* src, size_t srcSize, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2401 U32 frame, U32 lastFrameChunk) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2402 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2403 const BYTE* const ip = (const BYTE*) src; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2404 size_t fhSize = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2405 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2406 if (cctx->stage==ZSTDcs_created) return ERROR(stage_wrong); /* missing init (ZSTD_compressBegin) */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2407 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2408 if (frame && (cctx->stage==ZSTDcs_init)) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2409 fhSize = ZSTD_writeFrameHeader(dst, dstCapacity, cctx->params, cctx->frameContentSize, cctx->dictID); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2410 if (ZSTD_isError(fhSize)) return fhSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2411 dstCapacity -= fhSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2412 dst = (char*)dst + fhSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2413 cctx->stage = ZSTDcs_ongoing; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2414 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2415 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2416 /* Check if blocks follow each other */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2417 if (src != cctx->nextSrc) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2418 /* not contiguous */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2419 ptrdiff_t const delta = cctx->nextSrc - ip; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2420 cctx->lowLimit = cctx->dictLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2421 cctx->dictLimit = (U32)(cctx->nextSrc - cctx->base); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2422 cctx->dictBase = cctx->base; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2423 cctx->base -= delta; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2424 cctx->nextToUpdate = cctx->dictLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2425 if (cctx->dictLimit - cctx->lowLimit < HASH_READ_SIZE) cctx->lowLimit = cctx->dictLimit; /* too small extDict */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2426 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2427 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2428 /* if input and dictionary overlap : reduce dictionary (area presumed modified by input) */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2429 if ((ip+srcSize > cctx->dictBase + cctx->lowLimit) & (ip < cctx->dictBase + cctx->dictLimit)) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2430 ptrdiff_t const highInputIdx = (ip + srcSize) - cctx->dictBase; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2431 U32 const lowLimitMax = (highInputIdx > (ptrdiff_t)cctx->dictLimit) ? cctx->dictLimit : (U32)highInputIdx; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2432 cctx->lowLimit = lowLimitMax; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2433 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2434 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2435 cctx->nextSrc = ip + srcSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2436 |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2437 if (srcSize) { |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2438 size_t const cSize = frame ? |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2439 ZSTD_compress_generic (cctx, dst, dstCapacity, src, srcSize, lastFrameChunk) : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2440 ZSTD_compressBlock_internal (cctx, dst, dstCapacity, src, srcSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2441 if (ZSTD_isError(cSize)) return cSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2442 return cSize + fhSize; |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2443 } else |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2444 return fhSize; |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2445 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2446 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2447 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2448 size_t ZSTD_compressContinue (ZSTD_CCtx* cctx, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2449 void* dst, size_t dstCapacity, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2450 const void* src, size_t srcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2451 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2452 return ZSTD_compressContinue_internal(cctx, dst, dstCapacity, src, srcSize, 1, 0); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2453 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2454 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2455 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2456 size_t ZSTD_getBlockSizeMax(ZSTD_CCtx* cctx) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2457 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2458 return MIN (ZSTD_BLOCKSIZE_ABSOLUTEMAX, 1 << cctx->params.cParams.windowLog); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2459 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2460 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2461 size_t ZSTD_compressBlock(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2462 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2463 size_t const blockSizeMax = ZSTD_getBlockSizeMax(cctx); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2464 if (srcSize > blockSizeMax) return ERROR(srcSize_wrong); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2465 return ZSTD_compressContinue_internal(cctx, dst, dstCapacity, src, srcSize, 0, 0); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2466 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2467 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2468 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2469 static size_t ZSTD_loadDictionaryContent(ZSTD_CCtx* zc, const void* src, size_t srcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2470 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2471 const BYTE* const ip = (const BYTE*) src; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2472 const BYTE* const iend = ip + srcSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2473 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2474 /* input becomes current prefix */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2475 zc->lowLimit = zc->dictLimit; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2476 zc->dictLimit = (U32)(zc->nextSrc - zc->base); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2477 zc->dictBase = zc->base; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2478 zc->base += ip - zc->nextSrc; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2479 zc->nextToUpdate = zc->dictLimit; |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2480 zc->loadedDictEnd = zc->forceWindow ? 0 : (U32)(iend - zc->base); |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2481 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2482 zc->nextSrc = iend; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2483 if (srcSize <= HASH_READ_SIZE) return 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2484 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2485 switch(zc->params.cParams.strategy) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2486 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2487 case ZSTD_fast: |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2488 ZSTD_fillHashTable (zc, iend, zc->params.cParams.searchLength); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2489 break; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2490 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2491 case ZSTD_dfast: |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2492 ZSTD_fillDoubleHashTable (zc, iend, zc->params.cParams.searchLength); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2493 break; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2494 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2495 case ZSTD_greedy: |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2496 case ZSTD_lazy: |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2497 case ZSTD_lazy2: |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2498 ZSTD_insertAndFindFirstIndex (zc, iend-HASH_READ_SIZE, zc->params.cParams.searchLength); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2499 break; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2500 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2501 case ZSTD_btlazy2: |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2502 case ZSTD_btopt: |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2503 case ZSTD_btopt2: |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2504 ZSTD_updateTree(zc, iend-HASH_READ_SIZE, iend, 1 << zc->params.cParams.searchLog, zc->params.cParams.searchLength); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2505 break; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2506 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2507 default: |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2508 return ERROR(GENERIC); /* strategy doesn't exist; impossible */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2509 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2510 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2511 zc->nextToUpdate = zc->loadedDictEnd; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2512 return 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2513 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2514 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2515 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2516 /* Dictionaries that assign zero probability to symbols that show up causes problems |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2517 when FSE encoding. Refuse dictionaries that assign zero probability to symbols |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2518 that we may encounter during compression. |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2519 NOTE: This behavior is not standard and could be improved in the future. */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2520 static size_t ZSTD_checkDictNCount(short* normalizedCounter, unsigned dictMaxSymbolValue, unsigned maxSymbolValue) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2521 U32 s; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2522 if (dictMaxSymbolValue < maxSymbolValue) return ERROR(dictionary_corrupted); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2523 for (s = 0; s <= maxSymbolValue; ++s) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2524 if (normalizedCounter[s] == 0) return ERROR(dictionary_corrupted); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2525 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2526 return 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2527 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2528 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2529 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2530 /* Dictionary format : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2531 Magic == ZSTD_DICT_MAGIC (4 bytes) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2532 HUF_writeCTable(256) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2533 FSE_writeNCount(off) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2534 FSE_writeNCount(ml) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2535 FSE_writeNCount(ll) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2536 RepOffsets |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2537 Dictionary content |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2538 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2539 /*! ZSTD_loadDictEntropyStats() : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2540 @return : size read from dictionary |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2541 note : magic number supposed already checked */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2542 static size_t ZSTD_loadDictEntropyStats(ZSTD_CCtx* cctx, const void* dict, size_t dictSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2543 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2544 const BYTE* dictPtr = (const BYTE*)dict; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2545 const BYTE* const dictEnd = dictPtr + dictSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2546 short offcodeNCount[MaxOff+1]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2547 unsigned offcodeMaxValue = MaxOff; |
30822
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
2548 BYTE scratchBuffer[1<<MAX(MLFSELog,LLFSELog)]; |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2549 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2550 { size_t const hufHeaderSize = HUF_readCTable(cctx->hufTable, 255, dict, dictSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2551 if (HUF_isError(hufHeaderSize)) return ERROR(dictionary_corrupted); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2552 dictPtr += hufHeaderSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2553 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2554 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2555 { unsigned offcodeLog; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2556 size_t const offcodeHeaderSize = FSE_readNCount(offcodeNCount, &offcodeMaxValue, &offcodeLog, dictPtr, dictEnd-dictPtr); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2557 if (FSE_isError(offcodeHeaderSize)) return ERROR(dictionary_corrupted); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2558 if (offcodeLog > OffFSELog) return ERROR(dictionary_corrupted); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2559 /* Defer checking offcodeMaxValue because we need to know the size of the dictionary content */ |
30822
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
2560 CHECK_E (FSE_buildCTable_wksp(cctx->offcodeCTable, offcodeNCount, offcodeMaxValue, offcodeLog, scratchBuffer, sizeof(scratchBuffer)), dictionary_corrupted); |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2561 dictPtr += offcodeHeaderSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2562 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2563 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2564 { short matchlengthNCount[MaxML+1]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2565 unsigned matchlengthMaxValue = MaxML, matchlengthLog; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2566 size_t const matchlengthHeaderSize = FSE_readNCount(matchlengthNCount, &matchlengthMaxValue, &matchlengthLog, dictPtr, dictEnd-dictPtr); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2567 if (FSE_isError(matchlengthHeaderSize)) return ERROR(dictionary_corrupted); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2568 if (matchlengthLog > MLFSELog) return ERROR(dictionary_corrupted); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2569 /* Every match length code must have non-zero probability */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2570 CHECK_F (ZSTD_checkDictNCount(matchlengthNCount, matchlengthMaxValue, MaxML)); |
30822
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
2571 CHECK_E (FSE_buildCTable_wksp(cctx->matchlengthCTable, matchlengthNCount, matchlengthMaxValue, matchlengthLog, scratchBuffer, sizeof(scratchBuffer)), dictionary_corrupted); |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2572 dictPtr += matchlengthHeaderSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2573 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2574 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2575 { short litlengthNCount[MaxLL+1]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2576 unsigned litlengthMaxValue = MaxLL, litlengthLog; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2577 size_t const litlengthHeaderSize = FSE_readNCount(litlengthNCount, &litlengthMaxValue, &litlengthLog, dictPtr, dictEnd-dictPtr); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2578 if (FSE_isError(litlengthHeaderSize)) return ERROR(dictionary_corrupted); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2579 if (litlengthLog > LLFSELog) return ERROR(dictionary_corrupted); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2580 /* Every literal length code must have non-zero probability */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2581 CHECK_F (ZSTD_checkDictNCount(litlengthNCount, litlengthMaxValue, MaxLL)); |
30822
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
2582 CHECK_E(FSE_buildCTable_wksp(cctx->litlengthCTable, litlengthNCount, litlengthMaxValue, litlengthLog, scratchBuffer, sizeof(scratchBuffer)), dictionary_corrupted); |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2583 dictPtr += litlengthHeaderSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2584 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2585 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2586 if (dictPtr+12 > dictEnd) return ERROR(dictionary_corrupted); |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2587 cctx->rep[0] = MEM_readLE32(dictPtr+0); if (cctx->rep[0] == 0 || cctx->rep[0] >= dictSize) return ERROR(dictionary_corrupted); |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2588 cctx->rep[1] = MEM_readLE32(dictPtr+4); if (cctx->rep[1] == 0 || cctx->rep[1] >= dictSize) return ERROR(dictionary_corrupted); |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2589 cctx->rep[2] = MEM_readLE32(dictPtr+8); if (cctx->rep[2] == 0 || cctx->rep[2] >= dictSize) return ERROR(dictionary_corrupted); |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2590 dictPtr += 12; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2591 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2592 { U32 offcodeMax = MaxOff; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2593 if ((size_t)(dictEnd - dictPtr) <= ((U32)-1) - 128 KB) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2594 U32 const maxOffset = (U32)(dictEnd - dictPtr) + 128 KB; /* The maximum offset that must be supported */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2595 /* Calculate minimum offset code required to represent maxOffset */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2596 offcodeMax = ZSTD_highbit32(maxOffset); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2597 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2598 /* Every possible supported offset <= dictContentSize + 128 KB must be representable */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2599 CHECK_F (ZSTD_checkDictNCount(offcodeNCount, offcodeMaxValue, MIN(offcodeMax, MaxOff))); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2600 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2601 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2602 cctx->flagStaticTables = 1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2603 return dictPtr - (const BYTE*)dict; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2604 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2605 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2606 /** ZSTD_compress_insertDictionary() : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2607 * @return : 0, or an error code */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2608 static size_t ZSTD_compress_insertDictionary(ZSTD_CCtx* zc, const void* dict, size_t dictSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2609 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2610 if ((dict==NULL) || (dictSize<=8)) return 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2611 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2612 /* default : dict is pure content */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2613 if (MEM_readLE32(dict) != ZSTD_DICT_MAGIC) return ZSTD_loadDictionaryContent(zc, dict, dictSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2614 zc->dictID = zc->params.fParams.noDictIDFlag ? 0 : MEM_readLE32((const char*)dict+4); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2615 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2616 /* known magic number : dict is parsed for entropy stats and content */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2617 { size_t const loadError = ZSTD_loadDictEntropyStats(zc, (const char*)dict+8 /* skip dictHeader */, dictSize-8); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2618 size_t const eSize = loadError + 8; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2619 if (ZSTD_isError(loadError)) return loadError; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2620 return ZSTD_loadDictionaryContent(zc, (const char*)dict+eSize, dictSize-eSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2621 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2622 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2623 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2624 /*! ZSTD_compressBegin_internal() : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2625 * @return : 0, or an error code */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2626 static size_t ZSTD_compressBegin_internal(ZSTD_CCtx* cctx, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2627 const void* dict, size_t dictSize, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2628 ZSTD_parameters params, U64 pledgedSrcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2629 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2630 ZSTD_compResetPolicy_e const crp = dictSize ? ZSTDcrp_fullReset : ZSTDcrp_continue; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2631 CHECK_F(ZSTD_resetCCtx_advanced(cctx, params, pledgedSrcSize, crp)); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2632 return ZSTD_compress_insertDictionary(cctx, dict, dictSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2633 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2634 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2635 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2636 /*! ZSTD_compressBegin_advanced() : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2637 * @return : 0, or an error code */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2638 size_t ZSTD_compressBegin_advanced(ZSTD_CCtx* cctx, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2639 const void* dict, size_t dictSize, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2640 ZSTD_parameters params, unsigned long long pledgedSrcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2641 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2642 /* compression parameters verification and optimization */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2643 CHECK_F(ZSTD_checkCParams(params.cParams)); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2644 return ZSTD_compressBegin_internal(cctx, dict, dictSize, params, pledgedSrcSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2645 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2646 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2647 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2648 size_t ZSTD_compressBegin_usingDict(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, int compressionLevel) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2649 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2650 ZSTD_parameters const params = ZSTD_getParams(compressionLevel, 0, dictSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2651 return ZSTD_compressBegin_internal(cctx, dict, dictSize, params, 0); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2652 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2653 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2654 |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2655 size_t ZSTD_compressBegin(ZSTD_CCtx* cctx, int compressionLevel) |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2656 { |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2657 return ZSTD_compressBegin_usingDict(cctx, NULL, 0, compressionLevel); |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2658 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2659 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2660 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2661 /*! ZSTD_writeEpilogue() : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2662 * Ends a frame. |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2663 * @return : nb of bytes written into dst (or an error code) */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2664 static size_t ZSTD_writeEpilogue(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2665 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2666 BYTE* const ostart = (BYTE*)dst; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2667 BYTE* op = ostart; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2668 size_t fhSize = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2669 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2670 if (cctx->stage == ZSTDcs_created) return ERROR(stage_wrong); /* init missing */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2671 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2672 /* special case : empty frame */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2673 if (cctx->stage == ZSTDcs_init) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2674 fhSize = ZSTD_writeFrameHeader(dst, dstCapacity, cctx->params, 0, 0); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2675 if (ZSTD_isError(fhSize)) return fhSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2676 dstCapacity -= fhSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2677 op += fhSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2678 cctx->stage = ZSTDcs_ongoing; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2679 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2680 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2681 if (cctx->stage != ZSTDcs_ending) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2682 /* write one last empty block, make it the "last" block */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2683 U32 const cBlockHeader24 = 1 /* last block */ + (((U32)bt_raw)<<1) + 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2684 if (dstCapacity<4) return ERROR(dstSize_tooSmall); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2685 MEM_writeLE32(op, cBlockHeader24); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2686 op += ZSTD_blockHeaderSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2687 dstCapacity -= ZSTD_blockHeaderSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2688 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2689 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2690 if (cctx->params.fParams.checksumFlag) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2691 U32 const checksum = (U32) XXH64_digest(&cctx->xxhState); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2692 if (dstCapacity<4) return ERROR(dstSize_tooSmall); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2693 MEM_writeLE32(op, checksum); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2694 op += 4; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2695 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2696 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2697 cctx->stage = ZSTDcs_created; /* return to "created but no init" status */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2698 return op-ostart; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2699 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2700 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2701 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2702 size_t ZSTD_compressEnd (ZSTD_CCtx* cctx, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2703 void* dst, size_t dstCapacity, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2704 const void* src, size_t srcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2705 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2706 size_t endResult; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2707 size_t const cSize = ZSTD_compressContinue_internal(cctx, dst, dstCapacity, src, srcSize, 1, 1); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2708 if (ZSTD_isError(cSize)) return cSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2709 endResult = ZSTD_writeEpilogue(cctx, (char*)dst + cSize, dstCapacity-cSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2710 if (ZSTD_isError(endResult)) return endResult; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2711 return cSize + endResult; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2712 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2713 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2714 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2715 static size_t ZSTD_compress_internal (ZSTD_CCtx* cctx, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2716 void* dst, size_t dstCapacity, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2717 const void* src, size_t srcSize, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2718 const void* dict,size_t dictSize, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2719 ZSTD_parameters params) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2720 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2721 CHECK_F(ZSTD_compressBegin_internal(cctx, dict, dictSize, params, srcSize)); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2722 return ZSTD_compressEnd(cctx, dst, dstCapacity, src, srcSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2723 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2724 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2725 size_t ZSTD_compress_advanced (ZSTD_CCtx* ctx, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2726 void* dst, size_t dstCapacity, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2727 const void* src, size_t srcSize, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2728 const void* dict,size_t dictSize, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2729 ZSTD_parameters params) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2730 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2731 CHECK_F(ZSTD_checkCParams(params.cParams)); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2732 return ZSTD_compress_internal(ctx, dst, dstCapacity, src, srcSize, dict, dictSize, params); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2733 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2734 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2735 size_t ZSTD_compress_usingDict(ZSTD_CCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize, const void* dict, size_t dictSize, int compressionLevel) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2736 { |
30822
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
2737 ZSTD_parameters params = ZSTD_getParams(compressionLevel, srcSize, dict ? dictSize : 0); |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2738 params.fParams.contentSizeFlag = 1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2739 return ZSTD_compress_internal(ctx, dst, dstCapacity, src, srcSize, dict, dictSize, params); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2740 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2741 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2742 size_t ZSTD_compressCCtx (ZSTD_CCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize, int compressionLevel) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2743 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2744 return ZSTD_compress_usingDict(ctx, dst, dstCapacity, src, srcSize, NULL, 0, compressionLevel); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2745 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2746 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2747 size_t ZSTD_compress(void* dst, size_t dstCapacity, const void* src, size_t srcSize, int compressionLevel) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2748 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2749 size_t result; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2750 ZSTD_CCtx ctxBody; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2751 memset(&ctxBody, 0, sizeof(ctxBody)); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2752 memcpy(&ctxBody.customMem, &defaultCustomMem, sizeof(ZSTD_customMem)); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2753 result = ZSTD_compressCCtx(&ctxBody, dst, dstCapacity, src, srcSize, compressionLevel); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2754 ZSTD_free(ctxBody.workSpace, defaultCustomMem); /* can't free ctxBody itself, as it's on stack; free only heap content */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2755 return result; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2756 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2757 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2758 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2759 /* ===== Dictionary API ===== */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2760 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2761 struct ZSTD_CDict_s { |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2762 void* dictBuffer; |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2763 const void* dictContent; |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2764 size_t dictContentSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2765 ZSTD_CCtx* refContext; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2766 }; /* typedef'd tp ZSTD_CDict within "zstd.h" */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2767 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2768 size_t ZSTD_sizeof_CDict(const ZSTD_CDict* cdict) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2769 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2770 if (cdict==NULL) return 0; /* support sizeof on NULL */ |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2771 return ZSTD_sizeof_CCtx(cdict->refContext) + (cdict->dictBuffer ? cdict->dictContentSize : 0) + sizeof(*cdict); |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2772 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2773 |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2774 ZSTD_CDict* ZSTD_createCDict_advanced(const void* dictBuffer, size_t dictSize, unsigned byReference, |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2775 ZSTD_parameters params, ZSTD_customMem customMem) |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2776 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2777 if (!customMem.customAlloc && !customMem.customFree) customMem = defaultCustomMem; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2778 if (!customMem.customAlloc || !customMem.customFree) return NULL; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2779 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2780 { ZSTD_CDict* const cdict = (ZSTD_CDict*) ZSTD_malloc(sizeof(ZSTD_CDict), customMem); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2781 ZSTD_CCtx* const cctx = ZSTD_createCCtx_advanced(customMem); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2782 |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2783 if (!cdict || !cctx) { |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2784 ZSTD_free(cdict, customMem); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2785 ZSTD_free(cctx, customMem); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2786 return NULL; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2787 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2788 |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2789 if ((byReference) || (!dictBuffer) || (!dictSize)) { |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2790 cdict->dictBuffer = NULL; |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2791 cdict->dictContent = dictBuffer; |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2792 } else { |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2793 void* const internalBuffer = ZSTD_malloc(dictSize, customMem); |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2794 if (!internalBuffer) { ZSTD_free(cctx, customMem); ZSTD_free(cdict, customMem); return NULL; } |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2795 memcpy(internalBuffer, dictBuffer, dictSize); |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2796 cdict->dictBuffer = internalBuffer; |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2797 cdict->dictContent = internalBuffer; |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2798 } |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2799 |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2800 { size_t const errorCode = ZSTD_compressBegin_advanced(cctx, cdict->dictContent, dictSize, params, 0); |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2801 if (ZSTD_isError(errorCode)) { |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2802 ZSTD_free(cdict->dictBuffer, customMem); |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2803 ZSTD_free(cctx, customMem); |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2804 ZSTD_free(cdict, customMem); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2805 return NULL; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2806 } } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2807 |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2808 cdict->refContext = cctx; |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2809 cdict->dictContentSize = dictSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2810 return cdict; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2811 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2812 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2813 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2814 ZSTD_CDict* ZSTD_createCDict(const void* dict, size_t dictSize, int compressionLevel) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2815 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2816 ZSTD_customMem const allocator = { NULL, NULL, NULL }; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2817 ZSTD_parameters params = ZSTD_getParams(compressionLevel, 0, dictSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2818 params.fParams.contentSizeFlag = 1; |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2819 return ZSTD_createCDict_advanced(dict, dictSize, 0, params, allocator); |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2820 } |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2821 |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2822 ZSTD_CDict* ZSTD_createCDict_byReference(const void* dict, size_t dictSize, int compressionLevel) |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2823 { |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2824 ZSTD_customMem const allocator = { NULL, NULL, NULL }; |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2825 ZSTD_parameters params = ZSTD_getParams(compressionLevel, 0, dictSize); |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2826 params.fParams.contentSizeFlag = 1; |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2827 return ZSTD_createCDict_advanced(dict, dictSize, 1, params, allocator); |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2828 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2829 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2830 size_t ZSTD_freeCDict(ZSTD_CDict* cdict) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2831 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2832 if (cdict==NULL) return 0; /* support free on NULL */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2833 { ZSTD_customMem const cMem = cdict->refContext->customMem; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2834 ZSTD_freeCCtx(cdict->refContext); |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2835 ZSTD_free(cdict->dictBuffer, cMem); |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2836 ZSTD_free(cdict, cMem); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2837 return 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2838 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2839 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2840 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2841 static ZSTD_parameters ZSTD_getParamsFromCDict(const ZSTD_CDict* cdict) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2842 return ZSTD_getParamsFromCCtx(cdict->refContext); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2843 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2844 |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2845 size_t ZSTD_compressBegin_usingCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict, unsigned long long pledgedSrcSize) |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2846 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2847 if (cdict->dictContentSize) CHECK_F(ZSTD_copyCCtx(cctx, cdict->refContext, pledgedSrcSize)) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2848 else CHECK_F(ZSTD_compressBegin_advanced(cctx, NULL, 0, cdict->refContext->params, pledgedSrcSize)); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2849 return 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2850 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2851 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2852 /*! ZSTD_compress_usingCDict() : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2853 * Compression using a digested Dictionary. |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2854 * Faster startup than ZSTD_compress_usingDict(), recommended when same dictionary is used multiple times. |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2855 * Note that compression level is decided during dictionary creation */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2856 size_t ZSTD_compress_usingCDict(ZSTD_CCtx* cctx, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2857 void* dst, size_t dstCapacity, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2858 const void* src, size_t srcSize, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2859 const ZSTD_CDict* cdict) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2860 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2861 CHECK_F(ZSTD_compressBegin_usingCDict(cctx, cdict, srcSize)); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2862 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2863 if (cdict->refContext->params.fParams.contentSizeFlag==1) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2864 cctx->params.fParams.contentSizeFlag = 1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2865 cctx->frameContentSize = srcSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2866 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2867 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2868 return ZSTD_compressEnd(cctx, dst, dstCapacity, src, srcSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2869 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2870 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2871 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2872 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2873 /* ****************************************************************** |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2874 * Streaming |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2875 ********************************************************************/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2876 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2877 typedef enum { zcss_init, zcss_load, zcss_flush, zcss_final } ZSTD_cStreamStage; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2878 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2879 struct ZSTD_CStream_s { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2880 ZSTD_CCtx* cctx; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2881 ZSTD_CDict* cdictLocal; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2882 const ZSTD_CDict* cdict; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2883 char* inBuff; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2884 size_t inBuffSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2885 size_t inToCompress; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2886 size_t inBuffPos; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2887 size_t inBuffTarget; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2888 size_t blockSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2889 char* outBuff; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2890 size_t outBuffSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2891 size_t outBuffContentSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2892 size_t outBuffFlushedSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2893 ZSTD_cStreamStage stage; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2894 U32 checksum; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2895 U32 frameEnded; |
30822
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
2896 U64 pledgedSrcSize; |
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
2897 U64 inputProcessed; |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2898 ZSTD_parameters params; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2899 ZSTD_customMem customMem; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2900 }; /* typedef'd to ZSTD_CStream within "zstd.h" */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2901 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2902 ZSTD_CStream* ZSTD_createCStream(void) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2903 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2904 return ZSTD_createCStream_advanced(defaultCustomMem); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2905 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2906 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2907 ZSTD_CStream* ZSTD_createCStream_advanced(ZSTD_customMem customMem) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2908 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2909 ZSTD_CStream* zcs; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2910 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2911 if (!customMem.customAlloc && !customMem.customFree) customMem = defaultCustomMem; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2912 if (!customMem.customAlloc || !customMem.customFree) return NULL; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2913 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2914 zcs = (ZSTD_CStream*)ZSTD_malloc(sizeof(ZSTD_CStream), customMem); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2915 if (zcs==NULL) return NULL; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2916 memset(zcs, 0, sizeof(ZSTD_CStream)); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2917 memcpy(&zcs->customMem, &customMem, sizeof(ZSTD_customMem)); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2918 zcs->cctx = ZSTD_createCCtx_advanced(customMem); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2919 if (zcs->cctx == NULL) { ZSTD_freeCStream(zcs); return NULL; } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2920 return zcs; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2921 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2922 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2923 size_t ZSTD_freeCStream(ZSTD_CStream* zcs) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2924 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2925 if (zcs==NULL) return 0; /* support free on NULL */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2926 { ZSTD_customMem const cMem = zcs->customMem; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2927 ZSTD_freeCCtx(zcs->cctx); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2928 ZSTD_freeCDict(zcs->cdictLocal); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2929 ZSTD_free(zcs->inBuff, cMem); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2930 ZSTD_free(zcs->outBuff, cMem); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2931 ZSTD_free(zcs, cMem); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2932 return 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2933 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2934 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2935 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2936 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2937 /*====== Initialization ======*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2938 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2939 size_t ZSTD_CStreamInSize(void) { return ZSTD_BLOCKSIZE_ABSOLUTEMAX; } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2940 size_t ZSTD_CStreamOutSize(void) { return ZSTD_compressBound(ZSTD_BLOCKSIZE_ABSOLUTEMAX) + ZSTD_blockHeaderSize + 4 /* 32-bits hash */ ; } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2941 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2942 size_t ZSTD_resetCStream(ZSTD_CStream* zcs, unsigned long long pledgedSrcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2943 { |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2944 if (zcs->inBuffSize==0) return ERROR(stage_wrong); /* zcs has not been init at least once => can't reset */ |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2945 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2946 if (zcs->cdict) CHECK_F(ZSTD_compressBegin_usingCDict(zcs->cctx, zcs->cdict, pledgedSrcSize)) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2947 else CHECK_F(ZSTD_compressBegin_advanced(zcs->cctx, NULL, 0, zcs->params, pledgedSrcSize)); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2948 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2949 zcs->inToCompress = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2950 zcs->inBuffPos = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2951 zcs->inBuffTarget = zcs->blockSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2952 zcs->outBuffContentSize = zcs->outBuffFlushedSize = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2953 zcs->stage = zcss_load; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2954 zcs->frameEnded = 0; |
30822
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
2955 zcs->pledgedSrcSize = pledgedSrcSize; |
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
2956 zcs->inputProcessed = 0; |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2957 return 0; /* ready to go */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2958 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2959 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2960 size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2961 const void* dict, size_t dictSize, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2962 ZSTD_parameters params, unsigned long long pledgedSrcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2963 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2964 /* allocate buffers */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2965 { size_t const neededInBuffSize = (size_t)1 << params.cParams.windowLog; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2966 if (zcs->inBuffSize < neededInBuffSize) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2967 zcs->inBuffSize = neededInBuffSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2968 ZSTD_free(zcs->inBuff, zcs->customMem); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2969 zcs->inBuff = (char*) ZSTD_malloc(neededInBuffSize, zcs->customMem); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2970 if (zcs->inBuff == NULL) return ERROR(memory_allocation); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2971 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2972 zcs->blockSize = MIN(ZSTD_BLOCKSIZE_ABSOLUTEMAX, neededInBuffSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2973 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2974 if (zcs->outBuffSize < ZSTD_compressBound(zcs->blockSize)+1) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2975 zcs->outBuffSize = ZSTD_compressBound(zcs->blockSize)+1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2976 ZSTD_free(zcs->outBuff, zcs->customMem); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2977 zcs->outBuff = (char*) ZSTD_malloc(zcs->outBuffSize, zcs->customMem); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2978 if (zcs->outBuff == NULL) return ERROR(memory_allocation); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2979 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2980 |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2981 if (dict && dictSize >= 8) { |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2982 ZSTD_freeCDict(zcs->cdictLocal); |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
2983 zcs->cdictLocal = ZSTD_createCDict_advanced(dict, dictSize, 0, params, zcs->customMem); |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2984 if (zcs->cdictLocal == NULL) return ERROR(memory_allocation); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2985 zcs->cdict = zcs->cdictLocal; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2986 } else zcs->cdict = NULL; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2987 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2988 zcs->checksum = params.fParams.checksumFlag > 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2989 zcs->params = params; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2990 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2991 return ZSTD_resetCStream(zcs, pledgedSrcSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2992 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2993 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2994 /* note : cdict must outlive compression session */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2995 size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDict* cdict) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2996 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2997 ZSTD_parameters const params = ZSTD_getParamsFromCDict(cdict); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2998 size_t const initError = ZSTD_initCStream_advanced(zcs, NULL, 0, params, 0); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2999 zcs->cdict = cdict; |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
3000 zcs->cctx->dictID = params.fParams.noDictIDFlag ? 0 : cdict->refContext->dictID; |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3001 return initError; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3002 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3003 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3004 size_t ZSTD_initCStream_usingDict(ZSTD_CStream* zcs, const void* dict, size_t dictSize, int compressionLevel) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3005 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3006 ZSTD_parameters const params = ZSTD_getParams(compressionLevel, 0, dictSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3007 return ZSTD_initCStream_advanced(zcs, dict, dictSize, params, 0); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3008 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3009 |
30822
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
3010 size_t ZSTD_initCStream_srcSize(ZSTD_CStream* zcs, int compressionLevel, unsigned long long pledgedSrcSize) |
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
3011 { |
30895
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
3012 ZSTD_parameters params = ZSTD_getParams(compressionLevel, pledgedSrcSize, 0); |
c32454d69b85
zstd: vendor python-zstandard 0.7.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30822
diff
changeset
|
3013 if (pledgedSrcSize) params.fParams.contentSizeFlag = 1; |
30822
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
3014 return ZSTD_initCStream_advanced(zcs, NULL, 0, params, pledgedSrcSize); |
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
3015 } |
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
3016 |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3017 size_t ZSTD_initCStream(ZSTD_CStream* zcs, int compressionLevel) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3018 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3019 return ZSTD_initCStream_usingDict(zcs, NULL, 0, compressionLevel); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3020 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3021 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3022 size_t ZSTD_sizeof_CStream(const ZSTD_CStream* zcs) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3023 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3024 if (zcs==NULL) return 0; /* support sizeof on NULL */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3025 return sizeof(zcs) + ZSTD_sizeof_CCtx(zcs->cctx) + ZSTD_sizeof_CDict(zcs->cdictLocal) + zcs->outBuffSize + zcs->inBuffSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3026 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3027 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3028 /*====== Compression ======*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3029 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3030 typedef enum { zsf_gather, zsf_flush, zsf_end } ZSTD_flush_e; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3031 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3032 MEM_STATIC size_t ZSTD_limitCopy(void* dst, size_t dstCapacity, const void* src, size_t srcSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3033 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3034 size_t const length = MIN(dstCapacity, srcSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3035 memcpy(dst, src, length); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3036 return length; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3037 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3038 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3039 static size_t ZSTD_compressStream_generic(ZSTD_CStream* zcs, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3040 void* dst, size_t* dstCapacityPtr, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3041 const void* src, size_t* srcSizePtr, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3042 ZSTD_flush_e const flush) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3043 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3044 U32 someMoreWork = 1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3045 const char* const istart = (const char*)src; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3046 const char* const iend = istart + *srcSizePtr; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3047 const char* ip = istart; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3048 char* const ostart = (char*)dst; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3049 char* const oend = ostart + *dstCapacityPtr; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3050 char* op = ostart; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3051 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3052 while (someMoreWork) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3053 switch(zcs->stage) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3054 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3055 case zcss_init: return ERROR(init_missing); /* call ZBUFF_compressInit() first ! */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3056 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3057 case zcss_load: |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3058 /* complete inBuffer */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3059 { size_t const toLoad = zcs->inBuffTarget - zcs->inBuffPos; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3060 size_t const loaded = ZSTD_limitCopy(zcs->inBuff + zcs->inBuffPos, toLoad, ip, iend-ip); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3061 zcs->inBuffPos += loaded; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3062 ip += loaded; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3063 if ( (zcs->inBuffPos==zcs->inToCompress) || (!flush && (toLoad != loaded)) ) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3064 someMoreWork = 0; break; /* not enough input to get a full block : stop there, wait for more */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3065 } } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3066 /* compress current block (note : this stage cannot be stopped in the middle) */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3067 { void* cDst; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3068 size_t cSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3069 size_t const iSize = zcs->inBuffPos - zcs->inToCompress; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3070 size_t oSize = oend-op; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3071 if (oSize >= ZSTD_compressBound(iSize)) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3072 cDst = op; /* compress directly into output buffer (avoid flush stage) */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3073 else |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3074 cDst = zcs->outBuff, oSize = zcs->outBuffSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3075 cSize = (flush == zsf_end) ? |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3076 ZSTD_compressEnd(zcs->cctx, cDst, oSize, zcs->inBuff + zcs->inToCompress, iSize) : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3077 ZSTD_compressContinue(zcs->cctx, cDst, oSize, zcs->inBuff + zcs->inToCompress, iSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3078 if (ZSTD_isError(cSize)) return cSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3079 if (flush == zsf_end) zcs->frameEnded = 1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3080 /* prepare next block */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3081 zcs->inBuffTarget = zcs->inBuffPos + zcs->blockSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3082 if (zcs->inBuffTarget > zcs->inBuffSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3083 zcs->inBuffPos = 0, zcs->inBuffTarget = zcs->blockSize; /* note : inBuffSize >= blockSize */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3084 zcs->inToCompress = zcs->inBuffPos; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3085 if (cDst == op) { op += cSize; break; } /* no need to flush */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3086 zcs->outBuffContentSize = cSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3087 zcs->outBuffFlushedSize = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3088 zcs->stage = zcss_flush; /* pass-through to flush stage */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3089 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3090 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3091 case zcss_flush: |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3092 { size_t const toFlush = zcs->outBuffContentSize - zcs->outBuffFlushedSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3093 size_t const flushed = ZSTD_limitCopy(op, oend-op, zcs->outBuff + zcs->outBuffFlushedSize, toFlush); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3094 op += flushed; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3095 zcs->outBuffFlushedSize += flushed; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3096 if (toFlush!=flushed) { someMoreWork = 0; break; } /* dst too small to store flushed data : stop there */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3097 zcs->outBuffContentSize = zcs->outBuffFlushedSize = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3098 zcs->stage = zcss_load; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3099 break; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3100 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3101 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3102 case zcss_final: |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3103 someMoreWork = 0; /* do nothing */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3104 break; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3105 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3106 default: |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3107 return ERROR(GENERIC); /* impossible */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3108 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3109 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3110 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3111 *srcSizePtr = ip - istart; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3112 *dstCapacityPtr = op - ostart; |
30822
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
3113 zcs->inputProcessed += *srcSizePtr; |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3114 if (zcs->frameEnded) return 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3115 { size_t hintInSize = zcs->inBuffTarget - zcs->inBuffPos; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3116 if (hintInSize==0) hintInSize = zcs->blockSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3117 return hintInSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3118 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3119 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3120 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3121 size_t ZSTD_compressStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output, ZSTD_inBuffer* input) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3122 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3123 size_t sizeRead = input->size - input->pos; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3124 size_t sizeWritten = output->size - output->pos; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3125 size_t const result = ZSTD_compressStream_generic(zcs, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3126 (char*)(output->dst) + output->pos, &sizeWritten, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3127 (const char*)(input->src) + input->pos, &sizeRead, zsf_gather); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3128 input->pos += sizeRead; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3129 output->pos += sizeWritten; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3130 return result; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3131 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3132 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3133 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3134 /*====== Finalize ======*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3135 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3136 /*! ZSTD_flushStream() : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3137 * @return : amount of data remaining to flush */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3138 size_t ZSTD_flushStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3139 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3140 size_t srcSize = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3141 size_t sizeWritten = output->size - output->pos; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3142 size_t const result = ZSTD_compressStream_generic(zcs, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3143 (char*)(output->dst) + output->pos, &sizeWritten, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3144 &srcSize, &srcSize, /* use a valid src address instead of NULL */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3145 zsf_flush); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3146 output->pos += sizeWritten; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3147 if (ZSTD_isError(result)) return result; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3148 return zcs->outBuffContentSize - zcs->outBuffFlushedSize; /* remaining to flush */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3149 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3150 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3151 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3152 size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3153 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3154 BYTE* const ostart = (BYTE*)(output->dst) + output->pos; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3155 BYTE* const oend = (BYTE*)(output->dst) + output->size; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3156 BYTE* op = ostart; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3157 |
30822
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
3158 if ((zcs->pledgedSrcSize) && (zcs->inputProcessed != zcs->pledgedSrcSize)) |
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
3159 return ERROR(srcSize_wrong); /* pledgedSrcSize not respected */ |
b54a2984cdd4
zstd: vendor python-zstandard 0.6.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30434
diff
changeset
|
3160 |
30434
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3161 if (zcs->stage != zcss_final) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3162 /* flush whatever remains */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3163 size_t srcSize = 0; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3164 size_t sizeWritten = output->size - output->pos; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3165 size_t const notEnded = ZSTD_compressStream_generic(zcs, ostart, &sizeWritten, &srcSize, &srcSize, zsf_end); /* use a valid src address instead of NULL */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3166 size_t const remainingToFlush = zcs->outBuffContentSize - zcs->outBuffFlushedSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3167 op += sizeWritten; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3168 if (remainingToFlush) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3169 output->pos += sizeWritten; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3170 return remainingToFlush + ZSTD_BLOCKHEADERSIZE /* final empty block */ + (zcs->checksum * 4); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3171 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3172 /* create epilogue */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3173 zcs->stage = zcss_final; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3174 zcs->outBuffContentSize = !notEnded ? 0 : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3175 ZSTD_compressEnd(zcs->cctx, zcs->outBuff, zcs->outBuffSize, NULL, 0); /* write epilogue, including final empty block, into outBuff */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3176 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3177 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3178 /* flush epilogue */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3179 { size_t const toFlush = zcs->outBuffContentSize - zcs->outBuffFlushedSize; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3180 size_t const flushed = ZSTD_limitCopy(op, oend-op, zcs->outBuff + zcs->outBuffFlushedSize, toFlush); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3181 op += flushed; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3182 zcs->outBuffFlushedSize += flushed; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3183 output->pos += op-ostart; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3184 if (toFlush==flushed) zcs->stage = zcss_init; /* end reached */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3185 return toFlush - flushed; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3186 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3187 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3188 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3189 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3190 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3191 /*-===== Pre-defined compression levels =====-*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3192 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3193 #define ZSTD_DEFAULT_CLEVEL 1 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3194 #define ZSTD_MAX_CLEVEL 22 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3195 int ZSTD_maxCLevel(void) { return ZSTD_MAX_CLEVEL; } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3196 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3197 static const ZSTD_compressionParameters ZSTD_defaultCParameters[4][ZSTD_MAX_CLEVEL+1] = { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3198 { /* "default" */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3199 /* W, C, H, S, L, TL, strat */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3200 { 18, 12, 12, 1, 7, 16, ZSTD_fast }, /* level 0 - never used */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3201 { 19, 13, 14, 1, 7, 16, ZSTD_fast }, /* level 1 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3202 { 19, 15, 16, 1, 6, 16, ZSTD_fast }, /* level 2 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3203 { 20, 16, 17, 1, 5, 16, ZSTD_dfast }, /* level 3.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3204 { 20, 18, 18, 1, 5, 16, ZSTD_dfast }, /* level 4.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3205 { 20, 15, 18, 3, 5, 16, ZSTD_greedy }, /* level 5 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3206 { 21, 16, 19, 2, 5, 16, ZSTD_lazy }, /* level 6 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3207 { 21, 17, 20, 3, 5, 16, ZSTD_lazy }, /* level 7 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3208 { 21, 18, 20, 3, 5, 16, ZSTD_lazy2 }, /* level 8 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3209 { 21, 20, 20, 3, 5, 16, ZSTD_lazy2 }, /* level 9 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3210 { 21, 19, 21, 4, 5, 16, ZSTD_lazy2 }, /* level 10 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3211 { 22, 20, 22, 4, 5, 16, ZSTD_lazy2 }, /* level 11 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3212 { 22, 20, 22, 5, 5, 16, ZSTD_lazy2 }, /* level 12 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3213 { 22, 21, 22, 5, 5, 16, ZSTD_lazy2 }, /* level 13 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3214 { 22, 21, 22, 6, 5, 16, ZSTD_lazy2 }, /* level 14 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3215 { 22, 21, 21, 5, 5, 16, ZSTD_btlazy2 }, /* level 15 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3216 { 23, 22, 22, 5, 5, 16, ZSTD_btlazy2 }, /* level 16 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3217 { 23, 21, 22, 4, 5, 24, ZSTD_btopt }, /* level 17 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3218 { 23, 23, 22, 6, 5, 32, ZSTD_btopt }, /* level 18 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3219 { 23, 23, 22, 6, 3, 48, ZSTD_btopt }, /* level 19 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3220 { 25, 25, 23, 7, 3, 64, ZSTD_btopt2 }, /* level 20 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3221 { 26, 26, 23, 7, 3,256, ZSTD_btopt2 }, /* level 21 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3222 { 27, 27, 25, 9, 3,512, ZSTD_btopt2 }, /* level 22 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3223 }, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3224 { /* for srcSize <= 256 KB */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3225 /* W, C, H, S, L, T, strat */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3226 { 0, 0, 0, 0, 0, 0, ZSTD_fast }, /* level 0 - not used */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3227 { 18, 13, 14, 1, 6, 8, ZSTD_fast }, /* level 1 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3228 { 18, 14, 13, 1, 5, 8, ZSTD_dfast }, /* level 2 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3229 { 18, 16, 15, 1, 5, 8, ZSTD_dfast }, /* level 3 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3230 { 18, 15, 17, 1, 5, 8, ZSTD_greedy }, /* level 4.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3231 { 18, 16, 17, 4, 5, 8, ZSTD_greedy }, /* level 5.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3232 { 18, 16, 17, 3, 5, 8, ZSTD_lazy }, /* level 6.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3233 { 18, 17, 17, 4, 4, 8, ZSTD_lazy }, /* level 7 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3234 { 18, 17, 17, 4, 4, 8, ZSTD_lazy2 }, /* level 8 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3235 { 18, 17, 17, 5, 4, 8, ZSTD_lazy2 }, /* level 9 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3236 { 18, 17, 17, 6, 4, 8, ZSTD_lazy2 }, /* level 10 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3237 { 18, 18, 17, 6, 4, 8, ZSTD_lazy2 }, /* level 11.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3238 { 18, 18, 17, 7, 4, 8, ZSTD_lazy2 }, /* level 12.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3239 { 18, 19, 17, 6, 4, 8, ZSTD_btlazy2 }, /* level 13 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3240 { 18, 18, 18, 4, 4, 16, ZSTD_btopt }, /* level 14.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3241 { 18, 18, 18, 4, 3, 16, ZSTD_btopt }, /* level 15.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3242 { 18, 19, 18, 6, 3, 32, ZSTD_btopt }, /* level 16.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3243 { 18, 19, 18, 8, 3, 64, ZSTD_btopt }, /* level 17.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3244 { 18, 19, 18, 9, 3,128, ZSTD_btopt }, /* level 18.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3245 { 18, 19, 18, 10, 3,256, ZSTD_btopt }, /* level 19.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3246 { 18, 19, 18, 11, 3,512, ZSTD_btopt2 }, /* level 20.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3247 { 18, 19, 18, 12, 3,512, ZSTD_btopt2 }, /* level 21.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3248 { 18, 19, 18, 13, 3,512, ZSTD_btopt2 }, /* level 22.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3249 }, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3250 { /* for srcSize <= 128 KB */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3251 /* W, C, H, S, L, T, strat */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3252 { 17, 12, 12, 1, 7, 8, ZSTD_fast }, /* level 0 - not used */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3253 { 17, 12, 13, 1, 6, 8, ZSTD_fast }, /* level 1 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3254 { 17, 13, 16, 1, 5, 8, ZSTD_fast }, /* level 2 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3255 { 17, 16, 16, 2, 5, 8, ZSTD_dfast }, /* level 3 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3256 { 17, 13, 15, 3, 4, 8, ZSTD_greedy }, /* level 4 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3257 { 17, 15, 17, 4, 4, 8, ZSTD_greedy }, /* level 5 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3258 { 17, 16, 17, 3, 4, 8, ZSTD_lazy }, /* level 6 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3259 { 17, 15, 17, 4, 4, 8, ZSTD_lazy2 }, /* level 7 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3260 { 17, 17, 17, 4, 4, 8, ZSTD_lazy2 }, /* level 8 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3261 { 17, 17, 17, 5, 4, 8, ZSTD_lazy2 }, /* level 9 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3262 { 17, 17, 17, 6, 4, 8, ZSTD_lazy2 }, /* level 10 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3263 { 17, 17, 17, 7, 4, 8, ZSTD_lazy2 }, /* level 11 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3264 { 17, 17, 17, 8, 4, 8, ZSTD_lazy2 }, /* level 12 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3265 { 17, 18, 17, 6, 4, 8, ZSTD_btlazy2 }, /* level 13.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3266 { 17, 17, 17, 7, 3, 8, ZSTD_btopt }, /* level 14.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3267 { 17, 17, 17, 7, 3, 16, ZSTD_btopt }, /* level 15.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3268 { 17, 18, 17, 7, 3, 32, ZSTD_btopt }, /* level 16.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3269 { 17, 18, 17, 7, 3, 64, ZSTD_btopt }, /* level 17.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3270 { 17, 18, 17, 7, 3,256, ZSTD_btopt }, /* level 18.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3271 { 17, 18, 17, 8, 3,256, ZSTD_btopt }, /* level 19.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3272 { 17, 18, 17, 9, 3,256, ZSTD_btopt2 }, /* level 20.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3273 { 17, 18, 17, 10, 3,256, ZSTD_btopt2 }, /* level 21.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3274 { 17, 18, 17, 11, 3,512, ZSTD_btopt2 }, /* level 22.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3275 }, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3276 { /* for srcSize <= 16 KB */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3277 /* W, C, H, S, L, T, strat */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3278 { 14, 12, 12, 1, 7, 6, ZSTD_fast }, /* level 0 - not used */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3279 { 14, 14, 14, 1, 6, 6, ZSTD_fast }, /* level 1 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3280 { 14, 14, 14, 1, 4, 6, ZSTD_fast }, /* level 2 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3281 { 14, 14, 14, 1, 4, 6, ZSTD_dfast }, /* level 3.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3282 { 14, 14, 14, 4, 4, 6, ZSTD_greedy }, /* level 4.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3283 { 14, 14, 14, 3, 4, 6, ZSTD_lazy }, /* level 5.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3284 { 14, 14, 14, 4, 4, 6, ZSTD_lazy2 }, /* level 6 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3285 { 14, 14, 14, 5, 4, 6, ZSTD_lazy2 }, /* level 7 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3286 { 14, 14, 14, 6, 4, 6, ZSTD_lazy2 }, /* level 8.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3287 { 14, 15, 14, 6, 4, 6, ZSTD_btlazy2 }, /* level 9.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3288 { 14, 15, 14, 3, 3, 6, ZSTD_btopt }, /* level 10.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3289 { 14, 15, 14, 6, 3, 8, ZSTD_btopt }, /* level 11.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3290 { 14, 15, 14, 6, 3, 16, ZSTD_btopt }, /* level 12.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3291 { 14, 15, 14, 6, 3, 24, ZSTD_btopt }, /* level 13.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3292 { 14, 15, 15, 6, 3, 48, ZSTD_btopt }, /* level 14.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3293 { 14, 15, 15, 6, 3, 64, ZSTD_btopt }, /* level 15.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3294 { 14, 15, 15, 6, 3, 96, ZSTD_btopt }, /* level 16.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3295 { 14, 15, 15, 6, 3,128, ZSTD_btopt }, /* level 17.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3296 { 14, 15, 15, 6, 3,256, ZSTD_btopt }, /* level 18.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3297 { 14, 15, 15, 7, 3,256, ZSTD_btopt }, /* level 19.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3298 { 14, 15, 15, 8, 3,256, ZSTD_btopt2 }, /* level 20.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3299 { 14, 15, 15, 9, 3,256, ZSTD_btopt2 }, /* level 21.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3300 { 14, 15, 15, 10, 3,256, ZSTD_btopt2 }, /* level 22.*/ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3301 }, |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3302 }; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3303 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3304 /*! ZSTD_getCParams() : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3305 * @return ZSTD_compressionParameters structure for a selected compression level, `srcSize` and `dictSize`. |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3306 * Size values are optional, provide 0 if not known or unused */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3307 ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, unsigned long long srcSize, size_t dictSize) |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3308 { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3309 ZSTD_compressionParameters cp; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3310 size_t const addedSize = srcSize ? 0 : 500; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3311 U64 const rSize = srcSize+dictSize ? srcSize+dictSize+addedSize : (U64)-1; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3312 U32 const tableID = (rSize <= 256 KB) + (rSize <= 128 KB) + (rSize <= 16 KB); /* intentional underflow for srcSizeHint == 0 */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3313 if (compressionLevel <= 0) compressionLevel = ZSTD_DEFAULT_CLEVEL; /* 0 == default; no negative compressionLevel yet */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3314 if (compressionLevel > ZSTD_MAX_CLEVEL) compressionLevel = ZSTD_MAX_CLEVEL; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3315 cp = ZSTD_defaultCParameters[tableID][compressionLevel]; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3316 if (MEM_32bits()) { /* auto-correction, for 32-bits mode */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3317 if (cp.windowLog > ZSTD_WINDOWLOG_MAX) cp.windowLog = ZSTD_WINDOWLOG_MAX; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3318 if (cp.chainLog > ZSTD_CHAINLOG_MAX) cp.chainLog = ZSTD_CHAINLOG_MAX; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3319 if (cp.hashLog > ZSTD_HASHLOG_MAX) cp.hashLog = ZSTD_HASHLOG_MAX; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3320 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3321 cp = ZSTD_adjustCParams(cp, srcSize, dictSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3322 return cp; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3323 } |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3324 |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3325 /*! ZSTD_getParams() : |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3326 * same as ZSTD_getCParams(), but @return a `ZSTD_parameters` object (instead of `ZSTD_compressionParameters`). |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3327 * All fields of `ZSTD_frameParameters` are set to default (0) */ |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3328 ZSTD_parameters ZSTD_getParams(int compressionLevel, unsigned long long srcSize, size_t dictSize) { |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3329 ZSTD_parameters params; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3330 ZSTD_compressionParameters const cParams = ZSTD_getCParams(compressionLevel, srcSize, dictSize); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3331 memset(¶ms, 0, sizeof(params)); |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3332 params.cParams = cParams; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3333 return params; |
2e484bdea8c4
zstd: vendor zstd 1.1.1
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3334 } |