extzstd 0.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +5 -5
  2. data/HISTORY.ja.md +39 -0
  3. data/README.md +38 -56
  4. data/contrib/zstd/CHANGELOG +613 -0
  5. data/contrib/zstd/CODE_OF_CONDUCT.md +5 -0
  6. data/contrib/zstd/CONTRIBUTING.md +406 -0
  7. data/contrib/zstd/COPYING +339 -0
  8. data/contrib/zstd/Makefile +420 -0
  9. data/contrib/zstd/README.md +179 -41
  10. data/contrib/zstd/TESTING.md +44 -0
  11. data/contrib/zstd/appveyor.yml +292 -0
  12. data/contrib/zstd/lib/BUCK +234 -0
  13. data/contrib/zstd/lib/Makefile +451 -0
  14. data/contrib/zstd/lib/README.md +207 -0
  15. data/contrib/zstd/{common → lib/common}/bitstream.h +187 -138
  16. data/contrib/zstd/lib/common/compiler.h +288 -0
  17. data/contrib/zstd/lib/common/cpu.h +213 -0
  18. data/contrib/zstd/lib/common/debug.c +24 -0
  19. data/contrib/zstd/lib/common/debug.h +107 -0
  20. data/contrib/zstd/lib/common/entropy_common.c +362 -0
  21. data/contrib/zstd/{common → lib/common}/error_private.c +25 -12
  22. data/contrib/zstd/{common → lib/common}/error_private.h +14 -10
  23. data/contrib/zstd/{common → lib/common}/fse.h +173 -92
  24. data/contrib/zstd/{common → lib/common}/fse_decompress.c +149 -85
  25. data/contrib/zstd/lib/common/huf.h +361 -0
  26. data/contrib/zstd/{common → lib/common}/mem.h +115 -59
  27. data/contrib/zstd/lib/common/pool.c +350 -0
  28. data/contrib/zstd/lib/common/pool.h +84 -0
  29. data/contrib/zstd/lib/common/threading.c +122 -0
  30. data/contrib/zstd/lib/common/threading.h +155 -0
  31. data/contrib/zstd/{common → lib/common}/xxhash.c +55 -96
  32. data/contrib/zstd/{common → lib/common}/xxhash.h +23 -47
  33. data/contrib/zstd/lib/common/zstd_common.c +83 -0
  34. data/contrib/zstd/lib/common/zstd_deps.h +111 -0
  35. data/contrib/zstd/lib/common/zstd_errors.h +95 -0
  36. data/contrib/zstd/lib/common/zstd_internal.h +478 -0
  37. data/contrib/zstd/{compress → lib/compress}/fse_compress.c +214 -319
  38. data/contrib/zstd/lib/compress/hist.c +181 -0
  39. data/contrib/zstd/lib/compress/hist.h +75 -0
  40. data/contrib/zstd/lib/compress/huf_compress.c +913 -0
  41. data/contrib/zstd/lib/compress/zstd_compress.c +5208 -0
  42. data/contrib/zstd/lib/compress/zstd_compress_internal.h +1203 -0
  43. data/contrib/zstd/lib/compress/zstd_compress_literals.c +158 -0
  44. data/contrib/zstd/lib/compress/zstd_compress_literals.h +29 -0
  45. data/contrib/zstd/lib/compress/zstd_compress_sequences.c +433 -0
  46. data/contrib/zstd/lib/compress/zstd_compress_sequences.h +54 -0
  47. data/contrib/zstd/lib/compress/zstd_compress_superblock.c +849 -0
  48. data/contrib/zstd/lib/compress/zstd_compress_superblock.h +32 -0
  49. data/contrib/zstd/lib/compress/zstd_cwksp.h +561 -0
  50. data/contrib/zstd/lib/compress/zstd_double_fast.c +521 -0
  51. data/contrib/zstd/lib/compress/zstd_double_fast.h +38 -0
  52. data/contrib/zstd/lib/compress/zstd_fast.c +496 -0
  53. data/contrib/zstd/lib/compress/zstd_fast.h +37 -0
  54. data/contrib/zstd/lib/compress/zstd_lazy.c +1412 -0
  55. data/contrib/zstd/lib/compress/zstd_lazy.h +87 -0
  56. data/contrib/zstd/lib/compress/zstd_ldm.c +660 -0
  57. data/contrib/zstd/lib/compress/zstd_ldm.h +116 -0
  58. data/contrib/zstd/lib/compress/zstd_opt.c +1345 -0
  59. data/contrib/zstd/lib/compress/zstd_opt.h +56 -0
  60. data/contrib/zstd/lib/compress/zstdmt_compress.c +1811 -0
  61. data/contrib/zstd/lib/compress/zstdmt_compress.h +110 -0
  62. data/contrib/zstd/lib/decompress/huf_decompress.c +1350 -0
  63. data/contrib/zstd/lib/decompress/zstd_ddict.c +244 -0
  64. data/contrib/zstd/lib/decompress/zstd_ddict.h +44 -0
  65. data/contrib/zstd/lib/decompress/zstd_decompress.c +1930 -0
  66. data/contrib/zstd/lib/decompress/zstd_decompress_block.c +1540 -0
  67. data/contrib/zstd/lib/decompress/zstd_decompress_block.h +62 -0
  68. data/contrib/zstd/lib/decompress/zstd_decompress_internal.h +190 -0
  69. data/contrib/zstd/{common → lib/deprecated}/zbuff.h +68 -45
  70. data/contrib/zstd/lib/deprecated/zbuff_common.c +26 -0
  71. data/contrib/zstd/lib/deprecated/zbuff_compress.c +147 -0
  72. data/contrib/zstd/lib/deprecated/zbuff_decompress.c +75 -0
  73. data/contrib/zstd/lib/dictBuilder/cover.c +1245 -0
  74. data/contrib/zstd/lib/dictBuilder/cover.h +157 -0
  75. data/contrib/zstd/{dictBuilder → lib/dictBuilder}/divsufsort.c +3 -3
  76. data/contrib/zstd/{dictBuilder → lib/dictBuilder}/divsufsort.h +0 -0
  77. data/contrib/zstd/lib/dictBuilder/fastcover.c +758 -0
  78. data/contrib/zstd/{dictBuilder → lib/dictBuilder}/zdict.c +318 -194
  79. data/contrib/zstd/lib/dictBuilder/zdict.h +305 -0
  80. data/contrib/zstd/{legacy → lib/legacy}/zstd_legacy.h +171 -15
  81. data/contrib/zstd/{legacy → lib/legacy}/zstd_v01.c +191 -124
  82. data/contrib/zstd/{legacy → lib/legacy}/zstd_v01.h +19 -5
  83. data/contrib/zstd/{legacy → lib/legacy}/zstd_v02.c +125 -125
  84. data/contrib/zstd/{legacy → lib/legacy}/zstd_v02.h +19 -5
  85. data/contrib/zstd/{legacy → lib/legacy}/zstd_v03.c +125 -124
  86. data/contrib/zstd/{legacy → lib/legacy}/zstd_v03.h +20 -6
  87. data/contrib/zstd/{legacy → lib/legacy}/zstd_v04.c +151 -299
  88. data/contrib/zstd/{legacy → lib/legacy}/zstd_v04.h +19 -5
  89. data/contrib/zstd/{legacy → lib/legacy}/zstd_v05.c +237 -243
  90. data/contrib/zstd/{legacy → lib/legacy}/zstd_v05.h +19 -6
  91. data/contrib/zstd/{legacy → lib/legacy}/zstd_v06.c +130 -143
  92. data/contrib/zstd/{legacy → lib/legacy}/zstd_v06.h +18 -5
  93. data/contrib/zstd/{legacy → lib/legacy}/zstd_v07.c +158 -157
  94. data/contrib/zstd/{legacy → lib/legacy}/zstd_v07.h +19 -5
  95. data/contrib/zstd/lib/libzstd.pc.in +15 -0
  96. data/contrib/zstd/lib/zstd.h +2391 -0
  97. data/ext/depend +2 -0
  98. data/ext/extconf.rb +15 -6
  99. data/ext/extzstd.c +76 -145
  100. data/ext/extzstd.h +80 -31
  101. data/ext/extzstd_stream.c +417 -142
  102. data/ext/libzstd_conf.h +8 -0
  103. data/ext/zstd_common.c +10 -7
  104. data/ext/zstd_compress.c +14 -5
  105. data/ext/zstd_decompress.c +5 -4
  106. data/ext/zstd_dictbuilder.c +9 -4
  107. data/ext/zstd_dictbuilder_fastcover.c +3 -0
  108. data/ext/zstd_legacy_v01.c +3 -1
  109. data/ext/zstd_legacy_v02.c +3 -1
  110. data/ext/zstd_legacy_v03.c +3 -1
  111. data/ext/zstd_legacy_v04.c +3 -1
  112. data/ext/zstd_legacy_v05.c +3 -1
  113. data/ext/zstd_legacy_v06.c +3 -1
  114. data/ext/zstd_legacy_v07.c +3 -1
  115. data/gemstub.rb +10 -24
  116. data/lib/extzstd.rb +64 -179
  117. data/lib/extzstd/version.rb +6 -1
  118. data/test/test_basic.rb +9 -6
  119. metadata +113 -57
  120. data/HISTORY.ja +0 -5
  121. data/contrib/zstd/common/entropy_common.c +0 -225
  122. data/contrib/zstd/common/huf.h +0 -228
  123. data/contrib/zstd/common/zstd_common.c +0 -83
  124. data/contrib/zstd/common/zstd_errors.h +0 -60
  125. data/contrib/zstd/common/zstd_internal.h +0 -267
  126. data/contrib/zstd/compress/huf_compress.c +0 -533
  127. data/contrib/zstd/compress/zbuff_compress.c +0 -319
  128. data/contrib/zstd/compress/zstd_compress.c +0 -3264
  129. data/contrib/zstd/compress/zstd_opt.h +0 -900
  130. data/contrib/zstd/decompress/huf_decompress.c +0 -883
  131. data/contrib/zstd/decompress/zbuff_decompress.c +0 -252
  132. data/contrib/zstd/decompress/zstd_decompress.c +0 -1842
  133. data/contrib/zstd/dictBuilder/zdict.h +0 -111
  134. data/contrib/zstd/zstd.h +0 -640
@@ -1,84 +1,36 @@
1
1
  /* ******************************************************************
2
- FSE : Finite State Entropy decoder
3
- Copyright (C) 2013-2015, Yann Collet.
4
-
5
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
6
-
7
- Redistribution and use in source and binary forms, with or without
8
- modification, are permitted provided that the following conditions are
9
- met:
10
-
11
- * Redistributions of source code must retain the above copyright
12
- notice, this list of conditions and the following disclaimer.
13
- * Redistributions in binary form must reproduce the above
14
- copyright notice, this list of conditions and the following disclaimer
15
- in the documentation and/or other materials provided with the
16
- distribution.
17
-
18
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
-
30
- You can contact the author at :
31
- - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy
32
- - Public forum : https://groups.google.com/forum/#!forum/lz4c
2
+ * FSE : Finite State Entropy decoder
3
+ * Copyright (c) 2013-2020, Yann Collet, Facebook, Inc.
4
+ *
5
+ * You can contact the author at :
6
+ * - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy
7
+ * - Public forum : https://groups.google.com/forum/#!forum/lz4c
8
+ *
9
+ * This source code is licensed under both the BSD-style license (found in the
10
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
11
+ * in the COPYING file in the root directory of this source tree).
12
+ * You may select, at your option, one of the above-listed licenses.
33
13
  ****************************************************************** */
34
14
 
35
15
 
36
- /* **************************************************************
37
- * Compiler specifics
38
- ****************************************************************/
39
- #ifdef _MSC_VER /* Visual Studio */
40
- # define FORCE_INLINE static __forceinline
41
- # include <intrin.h> /* For Visual 2005 */
42
- # pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
43
- # pragma warning(disable : 4214) /* disable: C4214: non-int bitfields */
44
- #else
45
- # if defined (__cplusplus) || defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
46
- # ifdef __GNUC__
47
- # define FORCE_INLINE static inline __attribute__((always_inline))
48
- # else
49
- # define FORCE_INLINE static inline
50
- # endif
51
- # else
52
- # define FORCE_INLINE static
53
- # endif /* __STDC_VERSION__ */
54
- #endif
55
-
56
-
57
16
  /* **************************************************************
58
17
  * Includes
59
18
  ****************************************************************/
60
- #include <stdlib.h> /* malloc, free, qsort */
61
- #include <string.h> /* memcpy, memset */
62
- #include <stdio.h> /* printf (debug) */
19
+ #include "debug.h" /* assert */
63
20
  #include "bitstream.h"
21
+ #include "compiler.h"
64
22
  #define FSE_STATIC_LINKING_ONLY
65
23
  #include "fse.h"
24
+ #include "error_private.h"
25
+ #define ZSTD_DEPS_NEED_MALLOC
26
+ #include "zstd_deps.h"
66
27
 
67
28
 
68
29
  /* **************************************************************
69
30
  * Error Management
70
31
  ****************************************************************/
71
32
  #define FSE_isError ERR_isError
72
- #define FSE_STATIC_ASSERT(c) { enum { FSE_static_assert = 1/(int)(!!(c)) }; } /* use only *after* variable declarations */
73
-
74
- /* check and forward error code */
75
- #define CHECK_F(f) { size_t const e = f; if (FSE_isError(e)) return e; }
76
-
77
-
78
- /* **************************************************************
79
- * Complex types
80
- ****************************************************************/
81
- typedef U32 DTable_max_t[FSE_DTABLE_SIZE_U32(FSE_MAX_TABLELOG)];
33
+ #define FSE_STATIC_ASSERT(c) DEBUG_STATIC_ASSERT(c) /* use only *after* variable declarations */
82
34
 
83
35
 
84
36
  /* **************************************************************
@@ -108,25 +60,27 @@ typedef U32 DTable_max_t[FSE_DTABLE_SIZE_U32(FSE_MAX_TABLELOG)];
108
60
  FSE_DTable* FSE_createDTable (unsigned tableLog)
109
61
  {
110
62
  if (tableLog > FSE_TABLELOG_ABSOLUTE_MAX) tableLog = FSE_TABLELOG_ABSOLUTE_MAX;
111
- return (FSE_DTable*)malloc( FSE_DTABLE_SIZE_U32(tableLog) * sizeof (U32) );
63
+ return (FSE_DTable*)ZSTD_malloc( FSE_DTABLE_SIZE_U32(tableLog) * sizeof (U32) );
112
64
  }
113
65
 
114
66
  void FSE_freeDTable (FSE_DTable* dt)
115
67
  {
116
- free(dt);
68
+ ZSTD_free(dt);
117
69
  }
118
70
 
119
- size_t FSE_buildDTable(FSE_DTable* dt, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog)
71
+ static size_t FSE_buildDTable_internal(FSE_DTable* dt, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize)
120
72
  {
121
73
  void* const tdPtr = dt+1; /* because *dt is unsigned, 32-bits aligned on 32-bits */
122
74
  FSE_DECODE_TYPE* const tableDecode = (FSE_DECODE_TYPE*) (tdPtr);
123
- U16 symbolNext[FSE_MAX_SYMBOL_VALUE+1];
75
+ U16* symbolNext = (U16*)workSpace;
76
+ BYTE* spread = (BYTE*)(symbolNext + maxSymbolValue + 1);
124
77
 
125
78
  U32 const maxSV1 = maxSymbolValue + 1;
126
79
  U32 const tableSize = 1 << tableLog;
127
80
  U32 highThreshold = tableSize-1;
128
81
 
129
82
  /* Sanity Checks */
83
+ if (FSE_BUILD_DTABLE_WKSP_SIZE(tableLog, maxSymbolValue) > wkspSize) return ERROR(maxSymbolValue_tooLarge);
130
84
  if (maxSymbolValue > FSE_MAX_SYMBOL_VALUE) return ERROR(maxSymbolValue_tooLarge);
131
85
  if (tableLog > FSE_MAX_TABLELOG) return ERROR(tableLog_tooLarge);
132
86
 
@@ -144,11 +98,57 @@ size_t FSE_buildDTable(FSE_DTable* dt, const short* normalizedCounter, unsigned
144
98
  if (normalizedCounter[s] >= largeLimit) DTableH.fastMode=0;
145
99
  symbolNext[s] = normalizedCounter[s];
146
100
  } } }
147
- memcpy(dt, &DTableH, sizeof(DTableH));
101
+ ZSTD_memcpy(dt, &DTableH, sizeof(DTableH));
148
102
  }
149
103
 
150
104
  /* Spread symbols */
151
- { U32 const tableMask = tableSize-1;
105
+ if (highThreshold == tableSize - 1) {
106
+ size_t const tableMask = tableSize-1;
107
+ size_t const step = FSE_TABLESTEP(tableSize);
108
+ /* First lay down the symbols in order.
109
+ * We use a uint64_t to lay down 8 bytes at a time. This reduces branch
110
+ * misses since small blocks generally have small table logs, so nearly
111
+ * all symbols have counts <= 8. We ensure we have 8 bytes at the end of
112
+ * our buffer to handle the over-write.
113
+ */
114
+ {
115
+ U64 const add = 0x0101010101010101ull;
116
+ size_t pos = 0;
117
+ U64 sv = 0;
118
+ U32 s;
119
+ for (s=0; s<maxSV1; ++s, sv += add) {
120
+ int i;
121
+ int const n = normalizedCounter[s];
122
+ MEM_write64(spread + pos, sv);
123
+ for (i = 8; i < n; i += 8) {
124
+ MEM_write64(spread + pos + i, sv);
125
+ }
126
+ pos += n;
127
+ }
128
+ }
129
+ /* Now we spread those positions across the table.
130
+ * The benefit of doing it in two stages is that we avoid the the
131
+ * variable size inner loop, which caused lots of branch misses.
132
+ * Now we can run through all the positions without any branch misses.
133
+ * We unroll the loop twice, since that is what emperically worked best.
134
+ */
135
+ {
136
+ size_t position = 0;
137
+ size_t s;
138
+ size_t const unroll = 2;
139
+ assert(tableSize % unroll == 0); /* FSE_MIN_TABLELOG is 5 */
140
+ for (s = 0; s < (size_t)tableSize; s += unroll) {
141
+ size_t u;
142
+ for (u = 0; u < unroll; ++u) {
143
+ size_t const uPosition = (position + (u * step)) & tableMask;
144
+ tableDecode[uPosition].symbol = spread[s + u];
145
+ }
146
+ position = (position + (unroll * step)) & tableMask;
147
+ }
148
+ assert(position == 0);
149
+ }
150
+ } else {
151
+ U32 const tableMask = tableSize-1;
152
152
  U32 const step = FSE_TABLESTEP(tableSize);
153
153
  U32 s, position = 0;
154
154
  for (s=0; s<maxSV1; s++) {
@@ -165,14 +165,19 @@ size_t FSE_buildDTable(FSE_DTable* dt, const short* normalizedCounter, unsigned
165
165
  { U32 u;
166
166
  for (u=0; u<tableSize; u++) {
167
167
  FSE_FUNCTION_TYPE const symbol = (FSE_FUNCTION_TYPE)(tableDecode[u].symbol);
168
- U16 nextState = symbolNext[symbol]++;
169
- tableDecode[u].nbBits = (BYTE) (tableLog - BIT_highbit32 ((U32)nextState) );
168
+ U32 const nextState = symbolNext[symbol]++;
169
+ tableDecode[u].nbBits = (BYTE) (tableLog - BIT_highbit32(nextState) );
170
170
  tableDecode[u].newState = (U16) ( (nextState << tableDecode[u].nbBits) - tableSize);
171
171
  } }
172
172
 
173
173
  return 0;
174
174
  }
175
175
 
176
+ size_t FSE_buildDTable_wksp(FSE_DTable* dt, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize)
177
+ {
178
+ return FSE_buildDTable_internal(dt, normalizedCounter, maxSymbolValue, tableLog, workSpace, wkspSize);
179
+ }
180
+
176
181
 
177
182
  #ifndef FSE_COMMONDEFS_ONLY
178
183
 
@@ -223,7 +228,7 @@ size_t FSE_buildDTable_raw (FSE_DTable* dt, unsigned nbBits)
223
228
  return 0;
224
229
  }
225
230
 
226
- FORCE_INLINE size_t FSE_decompress_usingDTable_generic(
231
+ FORCE_INLINE_TEMPLATE size_t FSE_decompress_usingDTable_generic(
227
232
  void* dst, size_t maxDstSize,
228
233
  const void* cSrc, size_t cSrcSize,
229
234
  const FSE_DTable* dt, const unsigned fast)
@@ -300,30 +305,89 @@ size_t FSE_decompress_usingDTable(void* dst, size_t originalSize,
300
305
  }
301
306
 
302
307
 
303
- size_t FSE_decompress(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize)
308
+ size_t FSE_decompress_wksp(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize, unsigned maxLog, void* workSpace, size_t wkspSize)
309
+ {
310
+ return FSE_decompress_wksp_bmi2(dst, dstCapacity, cSrc, cSrcSize, maxLog, workSpace, wkspSize, /* bmi2 */ 0);
311
+ }
312
+
313
+ FORCE_INLINE_TEMPLATE size_t FSE_decompress_wksp_body(
314
+ void* dst, size_t dstCapacity,
315
+ const void* cSrc, size_t cSrcSize,
316
+ unsigned maxLog, void* workSpace, size_t wkspSize,
317
+ int bmi2)
304
318
  {
305
319
  const BYTE* const istart = (const BYTE*)cSrc;
306
320
  const BYTE* ip = istart;
307
321
  short counting[FSE_MAX_SYMBOL_VALUE+1];
308
- DTable_max_t dt; /* Static analyzer seems unable to understand this table will be properly initialized later */
309
322
  unsigned tableLog;
310
323
  unsigned maxSymbolValue = FSE_MAX_SYMBOL_VALUE;
311
-
312
- if (cSrcSize<2) return ERROR(srcSize_wrong); /* too small input size */
324
+ FSE_DTable* const dtable = (FSE_DTable*)workSpace;
313
325
 
314
326
  /* normal FSE decoding mode */
315
- { size_t const NCountLength = FSE_readNCount (counting, &maxSymbolValue, &tableLog, istart, cSrcSize);
316
- if (FSE_isError(NCountLength)) return NCountLength;
317
- if (NCountLength >= cSrcSize) return ERROR(srcSize_wrong); /* too small input size */
318
- ip += NCountLength;
319
- cSrcSize -= NCountLength;
327
+ size_t const NCountLength = FSE_readNCount_bmi2(counting, &maxSymbolValue, &tableLog, istart, cSrcSize, bmi2);
328
+ if (FSE_isError(NCountLength)) return NCountLength;
329
+ if (tableLog > maxLog) return ERROR(tableLog_tooLarge);
330
+ assert(NCountLength <= cSrcSize);
331
+ ip += NCountLength;
332
+ cSrcSize -= NCountLength;
333
+
334
+ if (FSE_DECOMPRESS_WKSP_SIZE(tableLog, maxSymbolValue) > wkspSize) return ERROR(tableLog_tooLarge);
335
+ workSpace = dtable + FSE_DTABLE_SIZE_U32(tableLog);
336
+ wkspSize -= FSE_DTABLE_SIZE(tableLog);
337
+
338
+ CHECK_F( FSE_buildDTable_internal(dtable, counting, maxSymbolValue, tableLog, workSpace, wkspSize) );
339
+
340
+ {
341
+ const void* ptr = dtable;
342
+ const FSE_DTableHeader* DTableH = (const FSE_DTableHeader*)ptr;
343
+ const U32 fastMode = DTableH->fastMode;
344
+
345
+ /* select fast mode (static) */
346
+ if (fastMode) return FSE_decompress_usingDTable_generic(dst, dstCapacity, ip, cSrcSize, dtable, 1);
347
+ return FSE_decompress_usingDTable_generic(dst, dstCapacity, ip, cSrcSize, dtable, 0);
348
+ }
349
+ }
350
+
351
+ /* Avoids the FORCE_INLINE of the _body() function. */
352
+ static size_t FSE_decompress_wksp_body_default(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize, unsigned maxLog, void* workSpace, size_t wkspSize)
353
+ {
354
+ return FSE_decompress_wksp_body(dst, dstCapacity, cSrc, cSrcSize, maxLog, workSpace, wkspSize, 0);
355
+ }
356
+
357
+ #if DYNAMIC_BMI2
358
+ TARGET_ATTRIBUTE("bmi2") static size_t FSE_decompress_wksp_body_bmi2(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize, unsigned maxLog, void* workSpace, size_t wkspSize)
359
+ {
360
+ return FSE_decompress_wksp_body(dst, dstCapacity, cSrc, cSrcSize, maxLog, workSpace, wkspSize, 1);
361
+ }
362
+ #endif
363
+
364
+ size_t FSE_decompress_wksp_bmi2(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize, unsigned maxLog, void* workSpace, size_t wkspSize, int bmi2)
365
+ {
366
+ #if DYNAMIC_BMI2
367
+ if (bmi2) {
368
+ return FSE_decompress_wksp_body_bmi2(dst, dstCapacity, cSrc, cSrcSize, maxLog, workSpace, wkspSize);
320
369
  }
370
+ #endif
371
+ (void)bmi2;
372
+ return FSE_decompress_wksp_body_default(dst, dstCapacity, cSrc, cSrcSize, maxLog, workSpace, wkspSize);
373
+ }
321
374
 
322
- CHECK_F( FSE_buildDTable (dt, counting, maxSymbolValue, tableLog) );
323
375
 
324
- return FSE_decompress_usingDTable (dst, maxDstSize, ip, cSrcSize, dt); /* always return, even if it is an error code */
376
+ typedef FSE_DTable DTable_max_t[FSE_DTABLE_SIZE_U32(FSE_MAX_TABLELOG)];
377
+
378
+ #ifndef ZSTD_NO_UNUSED_FUNCTIONS
379
+ size_t FSE_buildDTable(FSE_DTable* dt, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog) {
380
+ U32 wksp[FSE_BUILD_DTABLE_WKSP_SIZE_U32(FSE_TABLELOG_ABSOLUTE_MAX, FSE_MAX_SYMBOL_VALUE)];
381
+ return FSE_buildDTable_wksp(dt, normalizedCounter, maxSymbolValue, tableLog, wksp, sizeof(wksp));
325
382
  }
326
383
 
384
+ size_t FSE_decompress(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize)
385
+ {
386
+ /* Static analyzer seems unable to understand this table will be properly initialized later */
387
+ U32 wksp[FSE_DECOMPRESS_WKSP_SIZE_U32(FSE_MAX_TABLELOG, FSE_MAX_SYMBOL_VALUE)];
388
+ return FSE_decompress_wksp(dst, dstCapacity, cSrc, cSrcSize, FSE_MAX_TABLELOG, wksp, sizeof(wksp));
389
+ }
390
+ #endif
327
391
 
328
392
 
329
393
  #endif /* FSE_COMMONDEFS_ONLY */
@@ -0,0 +1,361 @@
1
+ /* ******************************************************************
2
+ * huff0 huffman codec,
3
+ * part of Finite State Entropy library
4
+ * Copyright (c) 2013-2020, Yann Collet, Facebook, Inc.
5
+ *
6
+ * You can contact the author at :
7
+ * - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
8
+ *
9
+ * This source code is licensed under both the BSD-style license (found in the
10
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
11
+ * in the COPYING file in the root directory of this source tree).
12
+ * You may select, at your option, one of the above-listed licenses.
13
+ ****************************************************************** */
14
+
15
+ #if defined (__cplusplus)
16
+ extern "C" {
17
+ #endif
18
+
19
+ #ifndef HUF_H_298734234
20
+ #define HUF_H_298734234
21
+
22
+ /* *** Dependencies *** */
23
+ #include "zstd_deps.h" /* size_t */
24
+
25
+
26
+ /* *** library symbols visibility *** */
27
+ /* Note : when linking with -fvisibility=hidden on gcc, or by default on Visual,
28
+ * HUF symbols remain "private" (internal symbols for library only).
29
+ * Set macro FSE_DLL_EXPORT to 1 if you want HUF symbols visible on DLL interface */
30
+ #if defined(FSE_DLL_EXPORT) && (FSE_DLL_EXPORT==1) && defined(__GNUC__) && (__GNUC__ >= 4)
31
+ # define HUF_PUBLIC_API __attribute__ ((visibility ("default")))
32
+ #elif defined(FSE_DLL_EXPORT) && (FSE_DLL_EXPORT==1) /* Visual expected */
33
+ # define HUF_PUBLIC_API __declspec(dllexport)
34
+ #elif defined(FSE_DLL_IMPORT) && (FSE_DLL_IMPORT==1)
35
+ # define HUF_PUBLIC_API __declspec(dllimport) /* not required, just to generate faster code (saves a function pointer load from IAT and an indirect jump) */
36
+ #else
37
+ # define HUF_PUBLIC_API
38
+ #endif
39
+
40
+
41
+ /* ========================== */
42
+ /* *** simple functions *** */
43
+ /* ========================== */
44
+
45
+ /** HUF_compress() :
46
+ * Compress content from buffer 'src', of size 'srcSize', into buffer 'dst'.
47
+ * 'dst' buffer must be already allocated.
48
+ * Compression runs faster if `dstCapacity` >= HUF_compressBound(srcSize).
49
+ * `srcSize` must be <= `HUF_BLOCKSIZE_MAX` == 128 KB.
50
+ * @return : size of compressed data (<= `dstCapacity`).
51
+ * Special values : if return == 0, srcData is not compressible => Nothing is stored within dst !!!
52
+ * if HUF_isError(return), compression failed (more details using HUF_getErrorName())
53
+ */
54
+ HUF_PUBLIC_API size_t HUF_compress(void* dst, size_t dstCapacity,
55
+ const void* src, size_t srcSize);
56
+
57
+ /** HUF_decompress() :
58
+ * Decompress HUF data from buffer 'cSrc', of size 'cSrcSize',
59
+ * into already allocated buffer 'dst', of minimum size 'dstSize'.
60
+ * `originalSize` : **must** be the ***exact*** size of original (uncompressed) data.
61
+ * Note : in contrast with FSE, HUF_decompress can regenerate
62
+ * RLE (cSrcSize==1) and uncompressed (cSrcSize==dstSize) data,
63
+ * because it knows size to regenerate (originalSize).
64
+ * @return : size of regenerated data (== originalSize),
65
+ * or an error code, which can be tested using HUF_isError()
66
+ */
67
+ HUF_PUBLIC_API size_t HUF_decompress(void* dst, size_t originalSize,
68
+ const void* cSrc, size_t cSrcSize);
69
+
70
+
71
+ /* *** Tool functions *** */
72
+ #define HUF_BLOCKSIZE_MAX (128 * 1024) /**< maximum input size for a single block compressed with HUF_compress */
73
+ HUF_PUBLIC_API size_t HUF_compressBound(size_t size); /**< maximum compressed size (worst case) */
74
+
75
+ /* Error Management */
76
+ HUF_PUBLIC_API unsigned HUF_isError(size_t code); /**< tells if a return value is an error code */
77
+ HUF_PUBLIC_API const char* HUF_getErrorName(size_t code); /**< provides error code string (useful for debugging) */
78
+
79
+
80
+ /* *** Advanced function *** */
81
+
82
+ /** HUF_compress2() :
83
+ * Same as HUF_compress(), but offers control over `maxSymbolValue` and `tableLog`.
84
+ * `maxSymbolValue` must be <= HUF_SYMBOLVALUE_MAX .
85
+ * `tableLog` must be `<= HUF_TABLELOG_MAX` . */
86
+ HUF_PUBLIC_API size_t HUF_compress2 (void* dst, size_t dstCapacity,
87
+ const void* src, size_t srcSize,
88
+ unsigned maxSymbolValue, unsigned tableLog);
89
+
90
+ /** HUF_compress4X_wksp() :
91
+ * Same as HUF_compress2(), but uses externally allocated `workSpace`.
92
+ * `workspace` must have minimum alignment of 4, and be at least as large as HUF_WORKSPACE_SIZE */
93
+ #define HUF_WORKSPACE_SIZE ((6 << 10) + 256)
94
+ #define HUF_WORKSPACE_SIZE_U32 (HUF_WORKSPACE_SIZE / sizeof(U32))
95
+ HUF_PUBLIC_API size_t HUF_compress4X_wksp (void* dst, size_t dstCapacity,
96
+ const void* src, size_t srcSize,
97
+ unsigned maxSymbolValue, unsigned tableLog,
98
+ void* workSpace, size_t wkspSize);
99
+
100
+ #endif /* HUF_H_298734234 */
101
+
102
+ /* ******************************************************************
103
+ * WARNING !!
104
+ * The following section contains advanced and experimental definitions
105
+ * which shall never be used in the context of a dynamic library,
106
+ * because they are not guaranteed to remain stable in the future.
107
+ * Only consider them in association with static linking.
108
+ * *****************************************************************/
109
+ #if defined(HUF_STATIC_LINKING_ONLY) && !defined(HUF_H_HUF_STATIC_LINKING_ONLY)
110
+ #define HUF_H_HUF_STATIC_LINKING_ONLY
111
+
112
+ /* *** Dependencies *** */
113
+ #include "mem.h" /* U32 */
114
+ #define FSE_STATIC_LINKING_ONLY
115
+ #include "fse.h"
116
+
117
+
118
+ /* *** Constants *** */
119
+ #define HUF_TABLELOG_MAX 12 /* max runtime value of tableLog (due to static allocation); can be modified up to HUF_ABSOLUTEMAX_TABLELOG */
120
+ #define HUF_TABLELOG_DEFAULT 11 /* default tableLog value when none specified */
121
+ #define HUF_SYMBOLVALUE_MAX 255
122
+
123
+ #define HUF_TABLELOG_ABSOLUTEMAX 15 /* absolute limit of HUF_MAX_TABLELOG. Beyond that value, code does not work */
124
+ #if (HUF_TABLELOG_MAX > HUF_TABLELOG_ABSOLUTEMAX)
125
+ # error "HUF_TABLELOG_MAX is too large !"
126
+ #endif
127
+
128
+
129
+ /* ****************************************
130
+ * Static allocation
131
+ ******************************************/
132
+ /* HUF buffer bounds */
133
+ #define HUF_CTABLEBOUND 129
134
+ #define HUF_BLOCKBOUND(size) (size + (size>>8) + 8) /* only true when incompressible is pre-filtered with fast heuristic */
135
+ #define HUF_COMPRESSBOUND(size) (HUF_CTABLEBOUND + HUF_BLOCKBOUND(size)) /* Macro version, useful for static allocation */
136
+
137
+ /* static allocation of HUF's Compression Table */
138
+ /* this is a private definition, just exposed for allocation and strict aliasing purpose. never EVER access its members directly */
139
+ struct HUF_CElt_s {
140
+ U16 val;
141
+ BYTE nbBits;
142
+ }; /* typedef'd to HUF_CElt */
143
+ typedef struct HUF_CElt_s HUF_CElt; /* consider it an incomplete type */
144
+ #define HUF_CTABLE_SIZE_U32(maxSymbolValue) ((maxSymbolValue)+1) /* Use tables of U32, for proper alignment */
145
+ #define HUF_CTABLE_SIZE(maxSymbolValue) (HUF_CTABLE_SIZE_U32(maxSymbolValue) * sizeof(U32))
146
+ #define HUF_CREATE_STATIC_CTABLE(name, maxSymbolValue) \
147
+ HUF_CElt name[HUF_CTABLE_SIZE_U32(maxSymbolValue)] /* no final ; */
148
+
149
+ /* static allocation of HUF's DTable */
150
+ typedef U32 HUF_DTable;
151
+ #define HUF_DTABLE_SIZE(maxTableLog) (1 + (1<<(maxTableLog)))
152
+ #define HUF_CREATE_STATIC_DTABLEX1(DTable, maxTableLog) \
153
+ HUF_DTable DTable[HUF_DTABLE_SIZE((maxTableLog)-1)] = { ((U32)((maxTableLog)-1) * 0x01000001) }
154
+ #define HUF_CREATE_STATIC_DTABLEX2(DTable, maxTableLog) \
155
+ HUF_DTable DTable[HUF_DTABLE_SIZE(maxTableLog)] = { ((U32)(maxTableLog) * 0x01000001) }
156
+
157
+
158
+ /* ****************************************
159
+ * Advanced decompression functions
160
+ ******************************************/
161
+ size_t HUF_decompress4X1 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< single-symbol decoder */
162
+ #ifndef HUF_FORCE_DECOMPRESS_X1
163
+ size_t HUF_decompress4X2 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< double-symbols decoder */
164
+ #endif
165
+
166
+ size_t HUF_decompress4X_DCtx (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< decodes RLE and uncompressed */
167
+ size_t HUF_decompress4X_hufOnly(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< considers RLE and uncompressed as errors */
168
+ size_t HUF_decompress4X_hufOnly_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< considers RLE and uncompressed as errors */
169
+ size_t HUF_decompress4X1_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< single-symbol decoder */
170
+ size_t HUF_decompress4X1_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< single-symbol decoder */
171
+ #ifndef HUF_FORCE_DECOMPRESS_X1
172
+ size_t HUF_decompress4X2_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< double-symbols decoder */
173
+ size_t HUF_decompress4X2_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< double-symbols decoder */
174
+ #endif
175
+
176
+
177
+ /* ****************************************
178
+ * HUF detailed API
179
+ * ****************************************/
180
+
181
+ /*! HUF_compress() does the following:
182
+ * 1. count symbol occurrence from source[] into table count[] using FSE_count() (exposed within "fse.h")
183
+ * 2. (optional) refine tableLog using HUF_optimalTableLog()
184
+ * 3. build Huffman table from count using HUF_buildCTable()
185
+ * 4. save Huffman table to memory buffer using HUF_writeCTable()
186
+ * 5. encode the data stream using HUF_compress4X_usingCTable()
187
+ *
188
+ * The following API allows targeting specific sub-functions for advanced tasks.
189
+ * For example, it's possible to compress several blocks using the same 'CTable',
190
+ * or to save and regenerate 'CTable' using external methods.
191
+ */
192
+ unsigned HUF_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue);
193
+ size_t HUF_buildCTable (HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue, unsigned maxNbBits); /* @return : maxNbBits; CTable and count can overlap. In which case, CTable will overwrite count content */
194
+ size_t HUF_writeCTable (void* dst, size_t maxDstSize, const HUF_CElt* CTable, unsigned maxSymbolValue, unsigned huffLog);
195
+ size_t HUF_compress4X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable);
196
+ size_t HUF_estimateCompressedSize(const HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue);
197
+ int HUF_validateCTable(const HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue);
198
+
199
+ typedef enum {
200
+ HUF_repeat_none, /**< Cannot use the previous table */
201
+ HUF_repeat_check, /**< Can use the previous table but it must be checked. Note : The previous table must have been constructed by HUF_compress{1, 4}X_repeat */
202
+ HUF_repeat_valid /**< Can use the previous table and it is assumed to be valid */
203
+ } HUF_repeat;
204
+ /** HUF_compress4X_repeat() :
205
+ * Same as HUF_compress4X_wksp(), but considers using hufTable if *repeat != HUF_repeat_none.
206
+ * If it uses hufTable it does not modify hufTable or repeat.
207
+ * If it doesn't, it sets *repeat = HUF_repeat_none, and it sets hufTable to the table used.
208
+ * If preferRepeat then the old table will always be used if valid. */
209
+ size_t HUF_compress4X_repeat(void* dst, size_t dstSize,
210
+ const void* src, size_t srcSize,
211
+ unsigned maxSymbolValue, unsigned tableLog,
212
+ void* workSpace, size_t wkspSize, /**< `workSpace` must be aligned on 4-bytes boundaries, `wkspSize` must be >= HUF_WORKSPACE_SIZE */
213
+ HUF_CElt* hufTable, HUF_repeat* repeat, int preferRepeat, int bmi2);
214
+
215
+ /** HUF_buildCTable_wksp() :
216
+ * Same as HUF_buildCTable(), but using externally allocated scratch buffer.
217
+ * `workSpace` must be aligned on 4-bytes boundaries, and its size must be >= HUF_CTABLE_WORKSPACE_SIZE.
218
+ */
219
+ #define HUF_CTABLE_WORKSPACE_SIZE_U32 (2*HUF_SYMBOLVALUE_MAX +1 +1)
220
+ #define HUF_CTABLE_WORKSPACE_SIZE (HUF_CTABLE_WORKSPACE_SIZE_U32 * sizeof(unsigned))
221
+ size_t HUF_buildCTable_wksp (HUF_CElt* tree,
222
+ const unsigned* count, U32 maxSymbolValue, U32 maxNbBits,
223
+ void* workSpace, size_t wkspSize);
224
+
225
+ /*! HUF_readStats() :
226
+ * Read compact Huffman tree, saved by HUF_writeCTable().
227
+ * `huffWeight` is destination buffer.
228
+ * @return : size read from `src` , or an error Code .
229
+ * Note : Needed by HUF_readCTable() and HUF_readDTableXn() . */
230
+ size_t HUF_readStats(BYTE* huffWeight, size_t hwSize,
231
+ U32* rankStats, U32* nbSymbolsPtr, U32* tableLogPtr,
232
+ const void* src, size_t srcSize);
233
+
234
+ /*! HUF_readStats_wksp() :
235
+ * Same as HUF_readStats() but takes an external workspace which must be
236
+ * 4-byte aligned and its size must be >= HUF_READ_STATS_WORKSPACE_SIZE.
237
+ * If the CPU has BMI2 support, pass bmi2=1, otherwise pass bmi2=0.
238
+ */
239
+ #define HUF_READ_STATS_WORKSPACE_SIZE_U32 FSE_DECOMPRESS_WKSP_SIZE_U32(6, HUF_TABLELOG_MAX-1)
240
+ #define HUF_READ_STATS_WORKSPACE_SIZE (HUF_READ_STATS_WORKSPACE_SIZE_U32 * sizeof(unsigned))
241
+ size_t HUF_readStats_wksp(BYTE* huffWeight, size_t hwSize,
242
+ U32* rankStats, U32* nbSymbolsPtr, U32* tableLogPtr,
243
+ const void* src, size_t srcSize,
244
+ void* workspace, size_t wkspSize,
245
+ int bmi2);
246
+
247
+ /** HUF_readCTable() :
248
+ * Loading a CTable saved with HUF_writeCTable() */
249
+ size_t HUF_readCTable (HUF_CElt* CTable, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize, unsigned *hasZeroWeights);
250
+
251
+ /** HUF_getNbBits() :
252
+ * Read nbBits from CTable symbolTable, for symbol `symbolValue` presumed <= HUF_SYMBOLVALUE_MAX
253
+ * Note 1 : is not inlined, as HUF_CElt definition is private
254
+ * Note 2 : const void* used, so that it can provide a statically allocated table as argument (which uses type U32) */
255
+ U32 HUF_getNbBits(const void* symbolTable, U32 symbolValue);
256
+
257
+ /*
258
+ * HUF_decompress() does the following:
259
+ * 1. select the decompression algorithm (X1, X2) based on pre-computed heuristics
260
+ * 2. build Huffman table from save, using HUF_readDTableX?()
261
+ * 3. decode 1 or 4 segments in parallel using HUF_decompress?X?_usingDTable()
262
+ */
263
+
264
+ /** HUF_selectDecoder() :
265
+ * Tells which decoder is likely to decode faster,
266
+ * based on a set of pre-computed metrics.
267
+ * @return : 0==HUF_decompress4X1, 1==HUF_decompress4X2 .
268
+ * Assumption : 0 < dstSize <= 128 KB */
269
+ U32 HUF_selectDecoder (size_t dstSize, size_t cSrcSize);
270
+
271
+ /**
272
+ * The minimum workspace size for the `workSpace` used in
273
+ * HUF_readDTableX1_wksp() and HUF_readDTableX2_wksp().
274
+ *
275
+ * The space used depends on HUF_TABLELOG_MAX, ranging from ~1500 bytes when
276
+ * HUF_TABLE_LOG_MAX=12 to ~1850 bytes when HUF_TABLE_LOG_MAX=15.
277
+ * Buffer overflow errors may potentially occur if code modifications result in
278
+ * a required workspace size greater than that specified in the following
279
+ * macro.
280
+ */
281
+ #define HUF_DECOMPRESS_WORKSPACE_SIZE (2 << 10)
282
+ #define HUF_DECOMPRESS_WORKSPACE_SIZE_U32 (HUF_DECOMPRESS_WORKSPACE_SIZE / sizeof(U32))
283
+
284
+ #ifndef HUF_FORCE_DECOMPRESS_X2
285
+ size_t HUF_readDTableX1 (HUF_DTable* DTable, const void* src, size_t srcSize);
286
+ size_t HUF_readDTableX1_wksp (HUF_DTable* DTable, const void* src, size_t srcSize, void* workSpace, size_t wkspSize);
287
+ #endif
288
+ #ifndef HUF_FORCE_DECOMPRESS_X1
289
+ size_t HUF_readDTableX2 (HUF_DTable* DTable, const void* src, size_t srcSize);
290
+ size_t HUF_readDTableX2_wksp (HUF_DTable* DTable, const void* src, size_t srcSize, void* workSpace, size_t wkspSize);
291
+ #endif
292
+
293
+ size_t HUF_decompress4X_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable);
294
+ #ifndef HUF_FORCE_DECOMPRESS_X2
295
+ size_t HUF_decompress4X1_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable);
296
+ #endif
297
+ #ifndef HUF_FORCE_DECOMPRESS_X1
298
+ size_t HUF_decompress4X2_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable);
299
+ #endif
300
+
301
+
302
+ /* ====================== */
303
+ /* single stream variants */
304
+ /* ====================== */
305
+
306
+ size_t HUF_compress1X (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog);
307
+ size_t HUF_compress1X_wksp (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize); /**< `workSpace` must be a table of at least HUF_WORKSPACE_SIZE_U32 unsigned */
308
+ size_t HUF_compress1X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable);
309
+ /** HUF_compress1X_repeat() :
310
+ * Same as HUF_compress1X_wksp(), but considers using hufTable if *repeat != HUF_repeat_none.
311
+ * If it uses hufTable it does not modify hufTable or repeat.
312
+ * If it doesn't, it sets *repeat = HUF_repeat_none, and it sets hufTable to the table used.
313
+ * If preferRepeat then the old table will always be used if valid. */
314
+ size_t HUF_compress1X_repeat(void* dst, size_t dstSize,
315
+ const void* src, size_t srcSize,
316
+ unsigned maxSymbolValue, unsigned tableLog,
317
+ void* workSpace, size_t wkspSize, /**< `workSpace` must be aligned on 4-bytes boundaries, `wkspSize` must be >= HUF_WORKSPACE_SIZE */
318
+ HUF_CElt* hufTable, HUF_repeat* repeat, int preferRepeat, int bmi2);
319
+
320
+ size_t HUF_decompress1X1 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /* single-symbol decoder */
321
+ #ifndef HUF_FORCE_DECOMPRESS_X1
322
+ size_t HUF_decompress1X2 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /* double-symbol decoder */
323
+ #endif
324
+
325
+ size_t HUF_decompress1X_DCtx (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize);
326
+ size_t HUF_decompress1X_DCtx_wksp (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize);
327
+ #ifndef HUF_FORCE_DECOMPRESS_X2
328
+ size_t HUF_decompress1X1_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< single-symbol decoder */
329
+ size_t HUF_decompress1X1_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< single-symbol decoder */
330
+ #endif
331
+ #ifndef HUF_FORCE_DECOMPRESS_X1
332
+ size_t HUF_decompress1X2_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< double-symbols decoder */
333
+ size_t HUF_decompress1X2_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< double-symbols decoder */
334
+ #endif
335
+
336
+ size_t HUF_decompress1X_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable); /**< automatic selection of sing or double symbol decoder, based on DTable */
337
+ #ifndef HUF_FORCE_DECOMPRESS_X2
338
+ size_t HUF_decompress1X1_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable);
339
+ #endif
340
+ #ifndef HUF_FORCE_DECOMPRESS_X1
341
+ size_t HUF_decompress1X2_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable);
342
+ #endif
343
+
344
+ /* BMI2 variants.
345
+ * If the CPU has BMI2 support, pass bmi2=1, otherwise pass bmi2=0.
346
+ */
347
+ size_t HUF_decompress1X_usingDTable_bmi2(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable, int bmi2);
348
+ #ifndef HUF_FORCE_DECOMPRESS_X2
349
+ size_t HUF_decompress1X1_DCtx_wksp_bmi2(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize, int bmi2);
350
+ #endif
351
+ size_t HUF_decompress4X_usingDTable_bmi2(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable, int bmi2);
352
+ size_t HUF_decompress4X_hufOnly_wksp_bmi2(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize, int bmi2);
353
+ #ifndef HUF_FORCE_DECOMPRESS_X2
354
+ size_t HUF_readDTableX1_wksp_bmi2(HUF_DTable* DTable, const void* src, size_t srcSize, void* workSpace, size_t wkspSize, int bmi2);
355
+ #endif
356
+
357
+ #endif /* HUF_STATIC_LINKING_ONLY */
358
+
359
+ #if defined (__cplusplus)
360
+ }
361
+ #endif