multi_compress 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -3
  3. data/GET_STARTED.md +3 -3
  4. data/README.md +75 -66
  5. data/THIRD_PARTY_NOTICES.md +24 -0
  6. data/ext/multi_compress/brotli_dec_static_init.c +3 -0
  7. data/ext/multi_compress/brotli_enc_static_init.c +3 -0
  8. data/ext/multi_compress/extconf.rb +22 -1
  9. data/ext/multi_compress/multi_compress.c +152 -72
  10. data/ext/multi_compress/vendor/.vendored +2 -2
  11. data/ext/multi_compress/vendor/brotli/LICENSE +19 -0
  12. data/ext/multi_compress/vendor/brotli/c/common/constants.c +7 -7
  13. data/ext/multi_compress/vendor/brotli/c/common/constants.h +2 -5
  14. data/ext/multi_compress/vendor/brotli/c/common/context.c +2 -2
  15. data/ext/multi_compress/vendor/brotli/c/common/context.h +1 -2
  16. data/ext/multi_compress/vendor/brotli/c/common/dictionary.c +4 -5856
  17. data/ext/multi_compress/vendor/brotli/c/common/dictionary.h +1 -2
  18. data/ext/multi_compress/vendor/brotli/c/common/dictionary_inc.h +5847 -0
  19. data/ext/multi_compress/vendor/brotli/c/common/platform.c +0 -4
  20. data/ext/multi_compress/vendor/brotli/c/common/platform.h +182 -43
  21. data/ext/multi_compress/vendor/brotli/c/common/shared_dictionary.c +3 -7
  22. data/ext/multi_compress/vendor/brotli/c/common/shared_dictionary_internal.h +1 -1
  23. data/ext/multi_compress/vendor/brotli/c/common/static_init.h +56 -0
  24. data/ext/multi_compress/vendor/brotli/c/common/transform.c +6 -4
  25. data/ext/multi_compress/vendor/brotli/c/common/transform.h +1 -2
  26. data/ext/multi_compress/vendor/brotli/c/common/version.h +3 -3
  27. data/ext/multi_compress/vendor/brotli/c/dec/bit_reader.c +2 -3
  28. data/ext/multi_compress/vendor/brotli/c/dec/bit_reader.h +0 -4
  29. data/ext/multi_compress/vendor/brotli/c/dec/decode.c +128 -39
  30. data/ext/multi_compress/vendor/brotli/c/dec/huffman.c +2 -5
  31. data/ext/multi_compress/vendor/brotli/c/dec/huffman.h +0 -2
  32. data/ext/multi_compress/vendor/brotli/c/dec/prefix.c +67 -0
  33. data/ext/multi_compress/vendor/brotli/c/dec/prefix.h +18 -708
  34. data/ext/multi_compress/vendor/brotli/c/dec/prefix_inc.h +707 -0
  35. data/ext/multi_compress/vendor/brotli/c/dec/state.c +18 -15
  36. data/ext/multi_compress/vendor/brotli/c/dec/state.h +2 -6
  37. data/ext/multi_compress/vendor/brotli/c/dec/static_init.c +53 -0
  38. data/ext/multi_compress/vendor/brotli/c/dec/static_init.h +30 -0
  39. data/ext/multi_compress/vendor/brotli/c/enc/backward_references.c +32 -8
  40. data/ext/multi_compress/vendor/brotli/c/enc/backward_references.h +1 -5
  41. data/ext/multi_compress/vendor/brotli/c/enc/backward_references_hq.c +15 -15
  42. data/ext/multi_compress/vendor/brotli/c/enc/backward_references_hq.h +1 -5
  43. data/ext/multi_compress/vendor/brotli/c/enc/bit_cost.c +28 -4
  44. data/ext/multi_compress/vendor/brotli/c/enc/bit_cost.h +8 -40
  45. data/ext/multi_compress/vendor/brotli/c/enc/bit_cost_inc.h +1 -1
  46. data/ext/multi_compress/vendor/brotli/c/enc/block_splitter.c +9 -12
  47. data/ext/multi_compress/vendor/brotli/c/enc/block_splitter.h +0 -3
  48. data/ext/multi_compress/vendor/brotli/c/enc/block_splitter_inc.h +14 -8
  49. data/ext/multi_compress/vendor/brotli/c/enc/brotli_bit_stream.c +10 -9
  50. data/ext/multi_compress/vendor/brotli/c/enc/brotli_bit_stream.h +0 -6
  51. data/ext/multi_compress/vendor/brotli/c/enc/cluster.c +0 -2
  52. data/ext/multi_compress/vendor/brotli/c/enc/cluster.h +0 -2
  53. data/ext/multi_compress/vendor/brotli/c/enc/command.c +1 -1
  54. data/ext/multi_compress/vendor/brotli/c/enc/command.h +8 -10
  55. data/ext/multi_compress/vendor/brotli/c/enc/compound_dictionary.c +3 -5
  56. data/ext/multi_compress/vendor/brotli/c/enc/compound_dictionary.h +1 -4
  57. data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment.c +3 -13
  58. data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment.h +0 -2
  59. data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment_two_pass.c +5 -15
  60. data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment_two_pass.h +0 -2
  61. data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash.c +127 -1830
  62. data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash.h +23 -3
  63. data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash_inc.h +1829 -0
  64. data/ext/multi_compress/vendor/brotli/c/enc/encode.c +77 -52
  65. data/ext/multi_compress/vendor/brotli/c/enc/encoder_dict.c +9 -7
  66. data/ext/multi_compress/vendor/brotli/c/enc/encoder_dict.h +2 -4
  67. data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode.c +3 -6
  68. data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode.h +2 -4
  69. data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode_static.h +18 -12
  70. data/ext/multi_compress/vendor/brotli/c/enc/fast_log.c +1 -1
  71. data/ext/multi_compress/vendor/brotli/c/enc/fast_log.h +2 -3
  72. data/ext/multi_compress/vendor/brotli/c/enc/find_match_length.h +0 -2
  73. data/ext/multi_compress/vendor/brotli/c/enc/hash.h +38 -31
  74. data/ext/multi_compress/vendor/brotli/c/enc/hash_base.h +38 -0
  75. data/ext/multi_compress/vendor/brotli/c/enc/hash_forgetful_chain_inc.h +11 -1
  76. data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match64_inc.h +24 -7
  77. data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match64_simd_inc.h +304 -0
  78. data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_inc.h +30 -11
  79. data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_quickly_inc.h +4 -0
  80. data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_simd_inc.h +278 -0
  81. data/ext/multi_compress/vendor/brotli/c/enc/histogram.c +1 -0
  82. data/ext/multi_compress/vendor/brotli/c/enc/histogram.h +0 -4
  83. data/ext/multi_compress/vendor/brotli/c/enc/literal_cost.c +4 -6
  84. data/ext/multi_compress/vendor/brotli/c/enc/literal_cost.h +0 -2
  85. data/ext/multi_compress/vendor/brotli/c/enc/matching_tag_mask.h +69 -0
  86. data/ext/multi_compress/vendor/brotli/c/enc/memory.c +0 -5
  87. data/ext/multi_compress/vendor/brotli/c/enc/memory.h +0 -4
  88. data/ext/multi_compress/vendor/brotli/c/enc/metablock.c +7 -9
  89. data/ext/multi_compress/vendor/brotli/c/enc/metablock.h +3 -3
  90. data/ext/multi_compress/vendor/brotli/c/enc/metablock_inc.h +4 -4
  91. data/ext/multi_compress/vendor/brotli/c/enc/params.h +0 -1
  92. data/ext/multi_compress/vendor/brotli/c/enc/prefix.h +0 -2
  93. data/ext/multi_compress/vendor/brotli/c/enc/quality.h +17 -10
  94. data/ext/multi_compress/vendor/brotli/c/enc/ringbuffer.h +1 -4
  95. data/ext/multi_compress/vendor/brotli/c/enc/state.h +2 -2
  96. data/ext/multi_compress/vendor/brotli/c/enc/static_dict.c +5 -11
  97. data/ext/multi_compress/vendor/brotli/c/enc/static_dict.h +1 -3
  98. data/ext/multi_compress/vendor/brotli/c/enc/static_dict_lut.c +224 -0
  99. data/ext/multi_compress/vendor/brotli/c/enc/static_dict_lut.h +20 -5837
  100. data/ext/multi_compress/vendor/brotli/c/enc/static_dict_lut_inc.h +5830 -0
  101. data/ext/multi_compress/vendor/brotli/c/enc/static_init.c +59 -0
  102. data/ext/multi_compress/vendor/brotli/c/enc/static_init.h +30 -0
  103. data/ext/multi_compress/vendor/brotli/c/enc/static_init_lazy.cc +26 -0
  104. data/ext/multi_compress/vendor/brotli/c/enc/utf8_util.c +1 -1
  105. data/ext/multi_compress/vendor/brotli/c/enc/utf8_util.h +0 -2
  106. data/ext/multi_compress/vendor/brotli/c/enc/write_bits.h +0 -2
  107. data/ext/multi_compress/vendor/brotli/c/include/brotli/decode.h +1 -1
  108. data/ext/multi_compress/vendor/brotli/c/include/brotli/encode.h +5 -1
  109. data/ext/multi_compress/vendor/brotli/c/include/brotli/port.h +4 -7
  110. data/ext/multi_compress/vendor/brotli/c/include/brotli/types.h +2 -2
  111. data/ext/multi_compress/vendor/lz4/LICENSE +12 -0
  112. data/ext/multi_compress/vendor/zstd/COPYING +339 -0
  113. data/ext/multi_compress/vendor/zstd/LICENSE +30 -0
  114. data/ext/multi_compress/vendor/zstd/lib/Makefile +67 -35
  115. data/ext/multi_compress/vendor/zstd/lib/README.md +33 -2
  116. data/ext/multi_compress/vendor/zstd/lib/common/allocations.h +55 -0
  117. data/ext/multi_compress/vendor/zstd/lib/common/bits.h +205 -0
  118. data/ext/multi_compress/vendor/zstd/lib/common/bitstream.h +84 -108
  119. data/ext/multi_compress/vendor/zstd/lib/common/compiler.h +170 -41
  120. data/ext/multi_compress/vendor/zstd/lib/common/cpu.h +37 -1
  121. data/ext/multi_compress/vendor/zstd/lib/common/debug.c +7 -1
  122. data/ext/multi_compress/vendor/zstd/lib/common/debug.h +21 -21
  123. data/ext/multi_compress/vendor/zstd/lib/common/entropy_common.c +12 -40
  124. data/ext/multi_compress/vendor/zstd/lib/common/error_private.c +10 -2
  125. data/ext/multi_compress/vendor/zstd/lib/common/error_private.h +46 -47
  126. data/ext/multi_compress/vendor/zstd/lib/common/fse.h +8 -100
  127. data/ext/multi_compress/vendor/zstd/lib/common/fse_decompress.c +28 -116
  128. data/ext/multi_compress/vendor/zstd/lib/common/huf.h +79 -166
  129. data/ext/multi_compress/vendor/zstd/lib/common/mem.h +46 -66
  130. data/ext/multi_compress/vendor/zstd/lib/common/pool.c +27 -11
  131. data/ext/multi_compress/vendor/zstd/lib/common/pool.h +8 -11
  132. data/ext/multi_compress/vendor/zstd/lib/common/portability_macros.h +45 -11
  133. data/ext/multi_compress/vendor/zstd/lib/common/threading.c +74 -14
  134. data/ext/multi_compress/vendor/zstd/lib/common/threading.h +5 -18
  135. data/ext/multi_compress/vendor/zstd/lib/common/xxhash.c +5 -11
  136. data/ext/multi_compress/vendor/zstd/lib/common/xxhash.h +2411 -1003
  137. data/ext/multi_compress/vendor/zstd/lib/common/zstd_common.c +1 -36
  138. data/ext/multi_compress/vendor/zstd/lib/common/zstd_deps.h +13 -1
  139. data/ext/multi_compress/vendor/zstd/lib/common/zstd_internal.h +13 -182
  140. data/ext/multi_compress/vendor/zstd/lib/common/zstd_trace.h +6 -13
  141. data/ext/multi_compress/vendor/zstd/lib/compress/clevels.h +1 -1
  142. data/ext/multi_compress/vendor/zstd/lib/compress/fse_compress.c +15 -131
  143. data/ext/multi_compress/vendor/zstd/lib/compress/hist.c +11 -1
  144. data/ext/multi_compress/vendor/zstd/lib/compress/hist.h +8 -1
  145. data/ext/multi_compress/vendor/zstd/lib/compress/huf_compress.c +283 -189
  146. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress.c +2419 -903
  147. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_internal.h +423 -245
  148. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_literals.c +116 -40
  149. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_literals.h +16 -8
  150. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_sequences.c +10 -10
  151. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_sequences.h +8 -7
  152. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_superblock.c +254 -139
  153. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_superblock.h +1 -1
  154. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_cwksp.h +184 -95
  155. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_double_fast.c +163 -81
  156. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_double_fast.h +18 -14
  157. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_fast.c +507 -197
  158. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_fast.h +7 -14
  159. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_lazy.c +579 -484
  160. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_lazy.h +133 -65
  161. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.c +61 -40
  162. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.h +7 -15
  163. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm_geartab.h +1 -1
  164. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_opt.c +352 -218
  165. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_opt.h +37 -21
  166. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_preSplit.c +238 -0
  167. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_preSplit.h +33 -0
  168. data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.c +239 -175
  169. data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.h +5 -16
  170. data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress.c +543 -488
  171. data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress_amd64.S +78 -61
  172. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.c +4 -4
  173. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.h +1 -1
  174. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress.c +295 -115
  175. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_block.c +430 -293
  176. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_block.h +7 -2
  177. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_internal.h +11 -7
  178. data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff.h +1 -1
  179. data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_common.c +1 -1
  180. data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_compress.c +1 -1
  181. data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_decompress.c +3 -1
  182. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/cover.c +95 -46
  183. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/cover.h +3 -9
  184. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/divsufsort.h +0 -10
  185. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/fastcover.c +4 -4
  186. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/zdict.c +25 -97
  187. data/ext/multi_compress/vendor/zstd/lib/dll/example/Makefile +1 -1
  188. data/ext/multi_compress/vendor/zstd/lib/dll/example/README.md +1 -1
  189. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_legacy.h +38 -1
  190. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v01.c +19 -50
  191. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v01.h +1 -1
  192. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v02.c +27 -80
  193. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v02.h +1 -1
  194. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v03.c +28 -83
  195. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v03.h +1 -1
  196. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v04.c +25 -74
  197. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v04.h +1 -1
  198. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v05.c +31 -76
  199. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v05.h +1 -1
  200. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v06.c +44 -88
  201. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v06.h +1 -1
  202. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v07.c +33 -84
  203. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v07.h +1 -1
  204. data/ext/multi_compress/vendor/zstd/lib/libzstd.mk +65 -33
  205. data/ext/multi_compress/vendor/zstd/lib/libzstd.pc.in +5 -5
  206. data/ext/multi_compress/vendor/zstd/lib/module.modulemap +13 -3
  207. data/ext/multi_compress/vendor/zstd/lib/zdict.h +65 -36
  208. data/ext/multi_compress/vendor/zstd/lib/zstd.h +890 -267
  209. data/ext/multi_compress/vendor/zstd/lib/zstd_errors.h +28 -16
  210. data/lib/multi_compress/version.rb +1 -1
  211. metadata +29 -2
@@ -1,7 +1,7 @@
1
1
  /* ******************************************************************
2
2
  * huff0 huffman codec,
3
3
  * part of Finite State Entropy library
4
- * Copyright (c) Yann Collet, Facebook, Inc.
4
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
5
5
  *
6
6
  * You can contact the author at :
7
7
  * - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
@@ -12,108 +12,26 @@
12
12
  * You may select, at your option, one of the above-listed licenses.
13
13
  ****************************************************************** */
14
14
 
15
- #if defined (__cplusplus)
16
- extern "C" {
17
- #endif
18
-
19
15
  #ifndef HUF_H_298734234
20
16
  #define HUF_H_298734234
21
17
 
22
18
  /* *** Dependencies *** */
23
19
  #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
-
20
+ #include "mem.h" /* U32 */
21
+ #define FSE_STATIC_LINKING_ONLY
22
+ #include "fse.h"
70
23
 
71
24
  /* *** 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) */
25
+ #define HUF_BLOCKSIZE_MAX (128 * 1024) /**< maximum input size for a single block compressed with HUF_compress */
26
+ size_t HUF_compressBound(size_t size); /**< maximum compressed size (worst case) */
74
27
 
75
28
  /* 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 *** */
29
+ unsigned HUF_isError(size_t code); /**< tells if a return value is an error code */
30
+ const char* HUF_getErrorName(size_t code); /**< provides error code string (useful for debugging) */
81
31
 
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
32
 
90
- /** HUF_compress4X_wksp() :
91
- * Same as HUF_compress2(), but uses externally allocated `workSpace`.
92
- * `workspace` must be at least as large as HUF_WORKSPACE_SIZE */
93
33
  #define HUF_WORKSPACE_SIZE ((8 << 10) + 512 /* sorting scratch space */)
94
34
  #define HUF_WORKSPACE_SIZE_U64 (HUF_WORKSPACE_SIZE / sizeof(U64))
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
35
 
118
36
  /* *** Constants *** */
119
37
  #define HUF_TABLELOG_MAX 12 /* max runtime value of tableLog (due to static allocation); can be modified up to HUF_TABLELOG_ABSOLUTEMAX */
@@ -154,25 +72,49 @@ typedef U32 HUF_DTable;
154
72
  /* ****************************************
155
73
  * Advanced decompression functions
156
74
  ******************************************/
157
- size_t HUF_decompress4X1 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< single-symbol decoder */
158
- #ifndef HUF_FORCE_DECOMPRESS_X1
159
- size_t HUF_decompress4X2 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< double-symbols decoder */
160
- #endif
161
75
 
162
- size_t HUF_decompress4X_DCtx (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< decodes RLE and uncompressed */
163
- 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 */
164
- 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 */
165
- size_t HUF_decompress4X1_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< single-symbol decoder */
166
- 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 */
167
- #ifndef HUF_FORCE_DECOMPRESS_X1
168
- size_t HUF_decompress4X2_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< double-symbols decoder */
169
- 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 */
170
- #endif
76
+ /**
77
+ * Huffman flags bitset.
78
+ * For all flags, 0 is the default value.
79
+ */
80
+ typedef enum {
81
+ /**
82
+ * If compiled with DYNAMIC_BMI2: Set flag only if the CPU supports BMI2 at runtime.
83
+ * Otherwise: Ignored.
84
+ */
85
+ HUF_flags_bmi2 = (1 << 0),
86
+ /**
87
+ * If set: Test possible table depths to find the one that produces the smallest header + encoded size.
88
+ * If unset: Use heuristic to find the table depth.
89
+ */
90
+ HUF_flags_optimalDepth = (1 << 1),
91
+ /**
92
+ * If set: If the previous table can encode the input, always reuse the previous table.
93
+ * If unset: If the previous table can encode the input, reuse the previous table if it results in a smaller output.
94
+ */
95
+ HUF_flags_preferRepeat = (1 << 2),
96
+ /**
97
+ * If set: Sample the input and check if the sample is uncompressible, if it is then don't attempt to compress.
98
+ * If unset: Always histogram the entire input.
99
+ */
100
+ HUF_flags_suspectUncompressible = (1 << 3),
101
+ /**
102
+ * If set: Don't use assembly implementations
103
+ * If unset: Allow using assembly implementations
104
+ */
105
+ HUF_flags_disableAsm = (1 << 4),
106
+ /**
107
+ * If set: Don't use the fast decoding loop, always use the fallback decoding loop.
108
+ * If unset: Use the fast decoding loop when possible.
109
+ */
110
+ HUF_flags_disableFast = (1 << 5)
111
+ } HUF_flags_e;
171
112
 
172
113
 
173
114
  /* ****************************************
174
115
  * HUF detailed API
175
116
  * ****************************************/
117
+ #define HUF_OPTIMAL_DEPTH_THRESHOLD ZSTD_btultra
176
118
 
177
119
  /*! HUF_compress() does the following:
178
120
  * 1. count symbol occurrence from source[] into table count[] using FSE_count() (exposed within "fse.h")
@@ -185,12 +127,12 @@ size_t HUF_decompress4X2_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize,
185
127
  * For example, it's possible to compress several blocks using the same 'CTable',
186
128
  * or to save and regenerate 'CTable' using external methods.
187
129
  */
188
- unsigned HUF_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue);
189
- 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 */
190
- size_t HUF_writeCTable (void* dst, size_t maxDstSize, const HUF_CElt* CTable, unsigned maxSymbolValue, unsigned huffLog);
130
+ unsigned HUF_minTableLog(unsigned symbolCardinality);
131
+ unsigned HUF_cardinality(const unsigned* count, unsigned maxSymbolValue);
132
+ unsigned HUF_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue, void* workSpace,
133
+ size_t wkspSize, HUF_CElt* table, const unsigned* count, int flags); /* table is used as scratch space for building and testing tables, not a return value */
191
134
  size_t HUF_writeCTable_wksp(void* dst, size_t maxDstSize, const HUF_CElt* CTable, unsigned maxSymbolValue, unsigned huffLog, void* workspace, size_t workspaceSize);
192
- size_t HUF_compress4X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable);
193
- size_t HUF_compress4X_usingCTable_bmi2(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable, int bmi2);
135
+ size_t HUF_compress4X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable, int flags);
194
136
  size_t HUF_estimateCompressedSize(const HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue);
195
137
  int HUF_validateCTable(const HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue);
196
138
 
@@ -199,6 +141,7 @@ typedef enum {
199
141
  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 */
200
142
  HUF_repeat_valid /**< Can use the previous table and it is assumed to be valid */
201
143
  } HUF_repeat;
144
+
202
145
  /** HUF_compress4X_repeat() :
203
146
  * Same as HUF_compress4X_wksp(), but considers using hufTable if *repeat != HUF_repeat_none.
204
147
  * If it uses hufTable it does not modify hufTable or repeat.
@@ -209,13 +152,13 @@ size_t HUF_compress4X_repeat(void* dst, size_t dstSize,
209
152
  const void* src, size_t srcSize,
210
153
  unsigned maxSymbolValue, unsigned tableLog,
211
154
  void* workSpace, size_t wkspSize, /**< `workSpace` must be aligned on 4-bytes boundaries, `wkspSize` must be >= HUF_WORKSPACE_SIZE */
212
- HUF_CElt* hufTable, HUF_repeat* repeat, int preferRepeat, int bmi2, unsigned suspectUncompressible);
155
+ HUF_CElt* hufTable, HUF_repeat* repeat, int flags);
213
156
 
214
157
  /** HUF_buildCTable_wksp() :
215
158
  * Same as HUF_buildCTable(), but using externally allocated scratch buffer.
216
159
  * `workSpace` must be aligned on 4-bytes boundaries, and its size must be >= HUF_CTABLE_WORKSPACE_SIZE.
217
160
  */
218
- #define HUF_CTABLE_WORKSPACE_SIZE_U32 (2*HUF_SYMBOLVALUE_MAX +1 +1)
161
+ #define HUF_CTABLE_WORKSPACE_SIZE_U32 ((4 * (HUF_SYMBOLVALUE_MAX + 1)) + 192)
219
162
  #define HUF_CTABLE_WORKSPACE_SIZE (HUF_CTABLE_WORKSPACE_SIZE_U32 * sizeof(unsigned))
220
163
  size_t HUF_buildCTable_wksp (HUF_CElt* tree,
221
164
  const unsigned* count, U32 maxSymbolValue, U32 maxNbBits,
@@ -241,7 +184,7 @@ size_t HUF_readStats_wksp(BYTE* huffWeight, size_t hwSize,
241
184
  U32* rankStats, U32* nbSymbolsPtr, U32* tableLogPtr,
242
185
  const void* src, size_t srcSize,
243
186
  void* workspace, size_t wkspSize,
244
- int bmi2);
187
+ int flags);
245
188
 
246
189
  /** HUF_readCTable() :
247
190
  * Loading a CTable saved with HUF_writeCTable() */
@@ -249,9 +192,22 @@ size_t HUF_readCTable (HUF_CElt* CTable, unsigned* maxSymbolValuePtr, const void
249
192
 
250
193
  /** HUF_getNbBitsFromCTable() :
251
194
  * Read nbBits from CTable symbolTable, for symbol `symbolValue` presumed <= HUF_SYMBOLVALUE_MAX
252
- * Note 1 : is not inlined, as HUF_CElt definition is private */
195
+ * Note 1 : If symbolValue > HUF_readCTableHeader(symbolTable).maxSymbolValue, returns 0
196
+ * Note 2 : is not inlined, as HUF_CElt definition is private
197
+ */
253
198
  U32 HUF_getNbBitsFromCTable(const HUF_CElt* symbolTable, U32 symbolValue);
254
199
 
200
+ typedef struct {
201
+ BYTE tableLog;
202
+ BYTE maxSymbolValue;
203
+ BYTE unused[sizeof(size_t) - 2];
204
+ } HUF_CTableHeader;
205
+
206
+ /** HUF_readCTableHeader() :
207
+ * @returns The header from the CTable specifying the tableLog and the maxSymbolValue.
208
+ */
209
+ HUF_CTableHeader HUF_readCTableHeader(HUF_CElt const* ctable);
210
+
255
211
  /*
256
212
  * HUF_decompress() does the following:
257
213
  * 1. select the decompression algorithm (X1, X2) based on pre-computed heuristics
@@ -279,32 +235,12 @@ U32 HUF_selectDecoder (size_t dstSize, size_t cSrcSize);
279
235
  #define HUF_DECOMPRESS_WORKSPACE_SIZE ((2 << 10) + (1 << 9))
280
236
  #define HUF_DECOMPRESS_WORKSPACE_SIZE_U32 (HUF_DECOMPRESS_WORKSPACE_SIZE / sizeof(U32))
281
237
 
282
- #ifndef HUF_FORCE_DECOMPRESS_X2
283
- size_t HUF_readDTableX1 (HUF_DTable* DTable, const void* src, size_t srcSize);
284
- size_t HUF_readDTableX1_wksp (HUF_DTable* DTable, const void* src, size_t srcSize, void* workSpace, size_t wkspSize);
285
- #endif
286
- #ifndef HUF_FORCE_DECOMPRESS_X1
287
- size_t HUF_readDTableX2 (HUF_DTable* DTable, const void* src, size_t srcSize);
288
- size_t HUF_readDTableX2_wksp (HUF_DTable* DTable, const void* src, size_t srcSize, void* workSpace, size_t wkspSize);
289
- #endif
290
-
291
- size_t HUF_decompress4X_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable);
292
- #ifndef HUF_FORCE_DECOMPRESS_X2
293
- size_t HUF_decompress4X1_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable);
294
- #endif
295
- #ifndef HUF_FORCE_DECOMPRESS_X1
296
- size_t HUF_decompress4X2_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable);
297
- #endif
298
-
299
238
 
300
239
  /* ====================== */
301
240
  /* single stream variants */
302
241
  /* ====================== */
303
242
 
304
- size_t HUF_compress1X (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog);
305
- 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_U64 U64 */
306
- size_t HUF_compress1X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable);
307
- size_t HUF_compress1X_usingCTable_bmi2(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable, int bmi2);
243
+ size_t HUF_compress1X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable, int flags);
308
244
  /** HUF_compress1X_repeat() :
309
245
  * Same as HUF_compress1X_wksp(), but considers using hufTable if *repeat != HUF_repeat_none.
310
246
  * If it uses hufTable it does not modify hufTable or repeat.
@@ -315,50 +251,27 @@ size_t HUF_compress1X_repeat(void* dst, size_t dstSize,
315
251
  const void* src, size_t srcSize,
316
252
  unsigned maxSymbolValue, unsigned tableLog,
317
253
  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, unsigned suspectUncompressible);
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
254
+ HUF_CElt* hufTable, HUF_repeat* repeat, int flags);
335
255
 
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
256
+ 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, int flags);
340
257
  #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);
258
+ 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, int flags); /**< double-symbols decoder */
342
259
  #endif
343
260
 
344
261
  /* BMI2 variants.
345
262
  * If the CPU has BMI2 support, pass bmi2=1, otherwise pass bmi2=0.
346
263
  */
347
- size_t HUF_decompress1X_usingDTable_bmi2(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable, int bmi2);
264
+ size_t HUF_decompress1X_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable, int flags);
348
265
  #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);
266
+ 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, int flags);
350
267
  #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);
268
+ size_t HUF_decompress4X_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable, int flags);
269
+ 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, int flags);
353
270
  #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);
271
+ size_t HUF_readDTableX1_wksp(HUF_DTable* DTable, const void* src, size_t srcSize, void* workSpace, size_t wkspSize, int flags);
355
272
  #endif
356
273
  #ifndef HUF_FORCE_DECOMPRESS_X1
357
- size_t HUF_readDTableX2_wksp_bmi2(HUF_DTable* DTable, const void* src, size_t srcSize, void* workSpace, size_t wkspSize, int bmi2);
274
+ size_t HUF_readDTableX2_wksp(HUF_DTable* DTable, const void* src, size_t srcSize, void* workSpace, size_t wkspSize, int flags);
358
275
  #endif
359
276
 
360
- #endif /* HUF_STATIC_LINKING_ONLY */
361
-
362
- #if defined (__cplusplus)
363
- }
364
- #endif
277
+ #endif /* HUF_H_298734234 */
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) Yann Collet, Facebook, Inc.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under both the BSD-style license (found in the
@@ -11,10 +11,6 @@
11
11
  #ifndef MEM_H_MODULE
12
12
  #define MEM_H_MODULE
13
13
 
14
- #if defined (__cplusplus)
15
- extern "C" {
16
- #endif
17
-
18
14
  /*-****************************************
19
15
  * Dependencies
20
16
  ******************************************/
@@ -30,15 +26,8 @@ extern "C" {
30
26
  #if defined(_MSC_VER) /* Visual Studio */
31
27
  # include <stdlib.h> /* _byteswap_ulong */
32
28
  # include <intrin.h> /* _byteswap_* */
33
- #endif
34
- #if defined(__GNUC__)
35
- # define MEM_STATIC static __inline __attribute__((unused))
36
- #elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
37
- # define MEM_STATIC static inline
38
- #elif defined(_MSC_VER)
39
- # define MEM_STATIC static __inline
40
- #else
41
- # define MEM_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */
29
+ #elif defined(__ICCARM__)
30
+ # include <intrinsics.h>
42
31
  #endif
43
32
 
44
33
  /*-**************************************************************
@@ -83,7 +72,6 @@ extern "C" {
83
72
  typedef signed long long S64;
84
73
  #endif
85
74
 
86
-
87
75
  /*-**************************************************************
88
76
  * Memory I/O API
89
77
  *****************************************************************/
@@ -133,21 +121,15 @@ MEM_STATIC size_t MEM_swapST(size_t in);
133
121
  /*-**************************************************************
134
122
  * Memory I/O Implementation
135
123
  *****************************************************************/
136
- /* MEM_FORCE_MEMORY_ACCESS :
137
- * By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable.
138
- * Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal.
139
- * The below switch allow to select different access method for improved performance.
140
- * Method 0 (default) : use `memcpy()`. Safe and portable.
141
- * Method 1 : `__packed` statement. It depends on compiler extension (i.e., not portable).
142
- * This method is safe if your compiler supports it, and *generally* as fast or faster than `memcpy`.
124
+ /* MEM_FORCE_MEMORY_ACCESS : For accessing unaligned memory:
125
+ * Method 0 : always use `memcpy()`. Safe and portable.
126
+ * Method 1 : Use compiler extension to set unaligned access.
143
127
  * Method 2 : direct access. This method is portable but violate C standard.
144
128
  * It can generate buggy code on targets depending on alignment.
145
- * In some circumstances, it's the only known way to get the most performance (i.e. GCC + ARMv6)
146
- * See http://fastcompression.blogspot.fr/2015/08/accessing-unaligned-memory.html for details.
147
- * Prefer these methods in priority order (0 > 1 > 2)
129
+ * Default : method 1 if supported, else method 0
148
130
  */
149
131
  #ifndef MEM_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
150
- # if defined(__INTEL_COMPILER) || defined(__GNUC__) || defined(__ICCARM__)
132
+ # ifdef __GNUC__
151
133
  # define MEM_FORCE_MEMORY_ACCESS 1
152
134
  # endif
153
135
  #endif
@@ -165,10 +147,12 @@ MEM_STATIC unsigned MEM_isLittleEndian(void)
165
147
  return 1;
166
148
  #elif defined(__clang__) && __BIG_ENDIAN__
167
149
  return 0;
168
- #elif defined(_MSC_VER) && (_M_AMD64 || _M_IX86)
150
+ #elif defined(_MSC_VER) && (_M_X64 || _M_IX86)
169
151
  return 1;
170
152
  #elif defined(__DMC__) && defined(_M_IX86)
171
153
  return 1;
154
+ #elif defined(__IAR_SYSTEMS_ICC__) && __LITTLE_ENDIAN__
155
+ return 1;
172
156
  #else
173
157
  const union { U32 u; BYTE c[4]; } one = { 1 }; /* don't use static : performance detrimental */
174
158
  return one.c[0];
@@ -190,30 +174,19 @@ MEM_STATIC void MEM_write64(void* memPtr, U64 value) { *(U64*)memPtr = value; }
190
174
 
191
175
  #elif defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==1)
192
176
 
193
- /* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */
194
- /* currently only defined for gcc and icc */
195
- #if defined(_MSC_VER) || (defined(__INTEL_COMPILER) && defined(WIN32))
196
- __pragma( pack(push, 1) )
197
- typedef struct { U16 v; } unalign16;
198
- typedef struct { U32 v; } unalign32;
199
- typedef struct { U64 v; } unalign64;
200
- typedef struct { size_t v; } unalignArch;
201
- __pragma( pack(pop) )
202
- #else
203
- typedef struct { U16 v; } __attribute__((packed)) unalign16;
204
- typedef struct { U32 v; } __attribute__((packed)) unalign32;
205
- typedef struct { U64 v; } __attribute__((packed)) unalign64;
206
- typedef struct { size_t v; } __attribute__((packed)) unalignArch;
207
- #endif
177
+ typedef __attribute__((aligned(1))) U16 unalign16;
178
+ typedef __attribute__((aligned(1))) U32 unalign32;
179
+ typedef __attribute__((aligned(1))) U64 unalign64;
180
+ typedef __attribute__((aligned(1))) size_t unalignArch;
208
181
 
209
- MEM_STATIC U16 MEM_read16(const void* ptr) { return ((const unalign16*)ptr)->v; }
210
- MEM_STATIC U32 MEM_read32(const void* ptr) { return ((const unalign32*)ptr)->v; }
211
- MEM_STATIC U64 MEM_read64(const void* ptr) { return ((const unalign64*)ptr)->v; }
212
- MEM_STATIC size_t MEM_readST(const void* ptr) { return ((const unalignArch*)ptr)->v; }
182
+ MEM_STATIC U16 MEM_read16(const void* ptr) { return *(const unalign16*)ptr; }
183
+ MEM_STATIC U32 MEM_read32(const void* ptr) { return *(const unalign32*)ptr; }
184
+ MEM_STATIC U64 MEM_read64(const void* ptr) { return *(const unalign64*)ptr; }
185
+ MEM_STATIC size_t MEM_readST(const void* ptr) { return *(const unalignArch*)ptr; }
213
186
 
214
- MEM_STATIC void MEM_write16(void* memPtr, U16 value) { ((unalign16*)memPtr)->v = value; }
215
- MEM_STATIC void MEM_write32(void* memPtr, U32 value) { ((unalign32*)memPtr)->v = value; }
216
- MEM_STATIC void MEM_write64(void* memPtr, U64 value) { ((unalign64*)memPtr)->v = value; }
187
+ MEM_STATIC void MEM_write16(void* memPtr, U16 value) { *(unalign16*)memPtr = value; }
188
+ MEM_STATIC void MEM_write32(void* memPtr, U32 value) { *(unalign32*)memPtr = value; }
189
+ MEM_STATIC void MEM_write64(void* memPtr, U64 value) { *(unalign64*)memPtr = value; }
217
190
 
218
191
  #else
219
192
 
@@ -257,6 +230,14 @@ MEM_STATIC void MEM_write64(void* memPtr, U64 value)
257
230
 
258
231
  #endif /* MEM_FORCE_MEMORY_ACCESS */
259
232
 
233
+ MEM_STATIC U32 MEM_swap32_fallback(U32 in)
234
+ {
235
+ return ((in << 24) & 0xff000000 ) |
236
+ ((in << 8) & 0x00ff0000 ) |
237
+ ((in >> 8) & 0x0000ff00 ) |
238
+ ((in >> 24) & 0x000000ff );
239
+ }
240
+
260
241
  MEM_STATIC U32 MEM_swap32(U32 in)
261
242
  {
262
243
  #if defined(_MSC_VER) /* Visual Studio */
@@ -264,23 +245,16 @@ MEM_STATIC U32 MEM_swap32(U32 in)
264
245
  #elif (defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403)) \
265
246
  || (defined(__clang__) && __has_builtin(__builtin_bswap32))
266
247
  return __builtin_bswap32(in);
248
+ #elif defined(__ICCARM__)
249
+ return __REV(in);
267
250
  #else
268
- return ((in << 24) & 0xff000000 ) |
269
- ((in << 8) & 0x00ff0000 ) |
270
- ((in >> 8) & 0x0000ff00 ) |
271
- ((in >> 24) & 0x000000ff );
251
+ return MEM_swap32_fallback(in);
272
252
  #endif
273
253
  }
274
254
 
275
- MEM_STATIC U64 MEM_swap64(U64 in)
255
+ MEM_STATIC U64 MEM_swap64_fallback(U64 in)
276
256
  {
277
- #if defined(_MSC_VER) /* Visual Studio */
278
- return _byteswap_uint64(in);
279
- #elif (defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403)) \
280
- || (defined(__clang__) && __has_builtin(__builtin_bswap64))
281
- return __builtin_bswap64(in);
282
- #else
283
- return ((in << 56) & 0xff00000000000000ULL) |
257
+ return ((in << 56) & 0xff00000000000000ULL) |
284
258
  ((in << 40) & 0x00ff000000000000ULL) |
285
259
  ((in << 24) & 0x0000ff0000000000ULL) |
286
260
  ((in << 8) & 0x000000ff00000000ULL) |
@@ -288,6 +262,17 @@ MEM_STATIC U64 MEM_swap64(U64 in)
288
262
  ((in >> 24) & 0x0000000000ff0000ULL) |
289
263
  ((in >> 40) & 0x000000000000ff00ULL) |
290
264
  ((in >> 56) & 0x00000000000000ffULL);
265
+ }
266
+
267
+ MEM_STATIC U64 MEM_swap64(U64 in)
268
+ {
269
+ #if defined(_MSC_VER) /* Visual Studio */
270
+ return _byteswap_uint64(in);
271
+ #elif (defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403)) \
272
+ || (defined(__clang__) && __has_builtin(__builtin_bswap64))
273
+ return __builtin_bswap64(in);
274
+ #else
275
+ return MEM_swap64_fallback(in);
291
276
  #endif
292
277
  }
293
278
 
@@ -434,9 +419,4 @@ MEM_STATIC void MEM_writeBEST(void* memPtr, size_t val)
434
419
  /* code only tested on 32 and 64 bits systems */
435
420
  MEM_STATIC void MEM_check(void) { DEBUG_STATIC_ASSERT((sizeof(size_t)==4) || (sizeof(size_t)==8)); }
436
421
 
437
-
438
- #if defined (__cplusplus)
439
- }
440
- #endif
441
-
442
422
  #endif /* MEM_H_MODULE */
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) Yann Collet, Facebook, Inc.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under both the BSD-style license (found in the
@@ -10,9 +10,9 @@
10
10
 
11
11
 
12
12
  /* ====== Dependencies ======= */
13
+ #include "../common/allocations.h" /* ZSTD_customCalloc, ZSTD_customFree */
13
14
  #include "zstd_deps.h" /* size_t */
14
15
  #include "debug.h" /* assert */
15
- #include "zstd_internal.h" /* ZSTD_customMalloc, ZSTD_customFree */
16
16
  #include "pool.h"
17
17
 
18
18
  /* ====== Compiler specifics ====== */
@@ -96,9 +96,7 @@ static void* POOL_thread(void* opaque) {
96
96
  /* If the intended queue size was 0, signal after finishing job */
97
97
  ZSTD_pthread_mutex_lock(&ctx->queueMutex);
98
98
  ctx->numThreadsBusy--;
99
- if (ctx->queueSize == 1) {
100
- ZSTD_pthread_cond_signal(&ctx->queuePushCond);
101
- }
99
+ ZSTD_pthread_cond_signal(&ctx->queuePushCond);
102
100
  ZSTD_pthread_mutex_unlock(&ctx->queueMutex);
103
101
  }
104
102
  } /* for (;;) */
@@ -128,7 +126,7 @@ POOL_ctx* POOL_create_advanced(size_t numThreads, size_t queueSize,
128
126
  * empty and full queues.
129
127
  */
130
128
  ctx->queueSize = queueSize + 1;
131
- ctx->queue = (POOL_job*)ZSTD_customMalloc(ctx->queueSize * sizeof(POOL_job), customMem);
129
+ ctx->queue = (POOL_job*)ZSTD_customCalloc(ctx->queueSize * sizeof(POOL_job), customMem);
132
130
  ctx->queueHead = 0;
133
131
  ctx->queueTail = 0;
134
132
  ctx->numThreadsBusy = 0;
@@ -142,7 +140,7 @@ POOL_ctx* POOL_create_advanced(size_t numThreads, size_t queueSize,
142
140
  }
143
141
  ctx->shutdown = 0;
144
142
  /* Allocate space for the thread handles */
145
- ctx->threads = (ZSTD_pthread_t*)ZSTD_customMalloc(numThreads * sizeof(ZSTD_pthread_t), customMem);
143
+ ctx->threads = (ZSTD_pthread_t*)ZSTD_customCalloc(numThreads * sizeof(ZSTD_pthread_t), customMem);
146
144
  ctx->threadCapacity = 0;
147
145
  ctx->customMem = customMem;
148
146
  /* Check for errors */
@@ -175,7 +173,7 @@ static void POOL_join(POOL_ctx* ctx) {
175
173
  /* Join all of the threads */
176
174
  { size_t i;
177
175
  for (i = 0; i < ctx->threadCapacity; ++i) {
178
- ZSTD_pthread_join(ctx->threads[i], NULL); /* note : could fail */
176
+ ZSTD_pthread_join(ctx->threads[i]); /* note : could fail */
179
177
  } }
180
178
  }
181
179
 
@@ -190,6 +188,17 @@ void POOL_free(POOL_ctx *ctx) {
190
188
  ZSTD_customFree(ctx, ctx->customMem);
191
189
  }
192
190
 
191
+ /*! POOL_joinJobs() :
192
+ * Waits for all queued jobs to finish executing.
193
+ */
194
+ void POOL_joinJobs(POOL_ctx* ctx) {
195
+ ZSTD_pthread_mutex_lock(&ctx->queueMutex);
196
+ while(!ctx->queueEmpty || ctx->numThreadsBusy > 0) {
197
+ ZSTD_pthread_cond_wait(&ctx->queuePushCond, &ctx->queueMutex);
198
+ }
199
+ ZSTD_pthread_mutex_unlock(&ctx->queueMutex);
200
+ }
201
+
193
202
  void ZSTD_freeThreadPool (ZSTD_threadPool* pool) {
194
203
  POOL_free (pool);
195
204
  }
@@ -211,10 +220,10 @@ static int POOL_resize_internal(POOL_ctx* ctx, size_t numThreads)
211
220
  return 0;
212
221
  }
213
222
  /* numThreads > threadCapacity */
214
- { ZSTD_pthread_t* const threadPool = (ZSTD_pthread_t*)ZSTD_customMalloc(numThreads * sizeof(ZSTD_pthread_t), ctx->customMem);
223
+ { ZSTD_pthread_t* const threadPool = (ZSTD_pthread_t*)ZSTD_customCalloc(numThreads * sizeof(ZSTD_pthread_t), ctx->customMem);
215
224
  if (!threadPool) return 1;
216
225
  /* replace existing thread pool */
217
- ZSTD_memcpy(threadPool, ctx->threads, ctx->threadCapacity * sizeof(*threadPool));
226
+ ZSTD_memcpy(threadPool, ctx->threads, ctx->threadCapacity * sizeof(ZSTD_pthread_t));
218
227
  ZSTD_customFree(ctx->threads, ctx->customMem);
219
228
  ctx->threads = threadPool;
220
229
  /* Initialize additional threads */
@@ -262,7 +271,9 @@ static int isQueueFull(POOL_ctx const* ctx) {
262
271
  static void
263
272
  POOL_add_internal(POOL_ctx* ctx, POOL_function function, void *opaque)
264
273
  {
265
- POOL_job const job = {function, opaque};
274
+ POOL_job job;
275
+ job.function = function;
276
+ job.opaque = opaque;
266
277
  assert(ctx != NULL);
267
278
  if (ctx->shutdown) return;
268
279
 
@@ -330,6 +341,11 @@ void POOL_free(POOL_ctx* ctx) {
330
341
  (void)ctx;
331
342
  }
332
343
 
344
+ void POOL_joinJobs(POOL_ctx* ctx){
345
+ assert(!ctx || ctx == &g_poolCtx);
346
+ (void)ctx;
347
+ }
348
+
333
349
  int POOL_resize(POOL_ctx* ctx, size_t numThreads) {
334
350
  (void)ctx; (void)numThreads;
335
351
  return 0;