multi_compress 0.3.2 → 0.3.4

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 (212) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +17 -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 +79 -3
  9. data/ext/multi_compress/multi_compress.c +199 -120
  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. data/lib/multi_compress.rb +80 -41
  212. metadata +29 -2
@@ -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,8 +11,49 @@
11
11
  #include "zstd_compress_internal.h"
12
12
  #include "zstd_double_fast.h"
13
13
 
14
+ #ifndef ZSTD_EXCLUDE_DFAST_BLOCK_COMPRESSOR
14
15
 
15
- void ZSTD_fillDoubleHashTable(ZSTD_matchState_t* ms,
16
+ static
17
+ ZSTD_ALLOW_POINTER_OVERFLOW_ATTR
18
+ void ZSTD_fillDoubleHashTableForCDict(ZSTD_MatchState_t* ms,
19
+ void const* end, ZSTD_dictTableLoadMethod_e dtlm)
20
+ {
21
+ const ZSTD_compressionParameters* const cParams = &ms->cParams;
22
+ U32* const hashLarge = ms->hashTable;
23
+ U32 const hBitsL = cParams->hashLog + ZSTD_SHORT_CACHE_TAG_BITS;
24
+ U32 const mls = cParams->minMatch;
25
+ U32* const hashSmall = ms->chainTable;
26
+ U32 const hBitsS = cParams->chainLog + ZSTD_SHORT_CACHE_TAG_BITS;
27
+ const BYTE* const base = ms->window.base;
28
+ const BYTE* ip = base + ms->nextToUpdate;
29
+ const BYTE* const iend = ((const BYTE*)end) - HASH_READ_SIZE;
30
+ const U32 fastHashFillStep = 3;
31
+
32
+ /* Always insert every fastHashFillStep position into the hash tables.
33
+ * Insert the other positions into the large hash table if their entry
34
+ * is empty.
35
+ */
36
+ for (; ip + fastHashFillStep - 1 <= iend; ip += fastHashFillStep) {
37
+ U32 const curr = (U32)(ip - base);
38
+ U32 i;
39
+ for (i = 0; i < fastHashFillStep; ++i) {
40
+ size_t const smHashAndTag = ZSTD_hashPtr(ip + i, hBitsS, mls);
41
+ size_t const lgHashAndTag = ZSTD_hashPtr(ip + i, hBitsL, 8);
42
+ if (i == 0) {
43
+ ZSTD_writeTaggedIndex(hashSmall, smHashAndTag, curr + i);
44
+ }
45
+ if (i == 0 || hashLarge[lgHashAndTag >> ZSTD_SHORT_CACHE_TAG_BITS] == 0) {
46
+ ZSTD_writeTaggedIndex(hashLarge, lgHashAndTag, curr + i);
47
+ }
48
+ /* Only load extra positions for ZSTD_dtlm_full */
49
+ if (dtlm == ZSTD_dtlm_fast)
50
+ break;
51
+ } }
52
+ }
53
+
54
+ static
55
+ ZSTD_ALLOW_POINTER_OVERFLOW_ATTR
56
+ void ZSTD_fillDoubleHashTableForCCtx(ZSTD_MatchState_t* ms,
16
57
  void const* end, ZSTD_dictTableLoadMethod_e dtlm)
17
58
  {
18
59
  const ZSTD_compressionParameters* const cParams = &ms->cParams;
@@ -43,13 +84,26 @@ void ZSTD_fillDoubleHashTable(ZSTD_matchState_t* ms,
43
84
  /* Only load extra positions for ZSTD_dtlm_full */
44
85
  if (dtlm == ZSTD_dtlm_fast)
45
86
  break;
46
- } }
87
+ } }
88
+ }
89
+
90
+ void ZSTD_fillDoubleHashTable(ZSTD_MatchState_t* ms,
91
+ const void* const end,
92
+ ZSTD_dictTableLoadMethod_e dtlm,
93
+ ZSTD_tableFillPurpose_e tfp)
94
+ {
95
+ if (tfp == ZSTD_tfp_forCDict) {
96
+ ZSTD_fillDoubleHashTableForCDict(ms, end, dtlm);
97
+ } else {
98
+ ZSTD_fillDoubleHashTableForCCtx(ms, end, dtlm);
99
+ }
47
100
  }
48
101
 
49
102
 
50
103
  FORCE_INLINE_TEMPLATE
104
+ ZSTD_ALLOW_POINTER_OVERFLOW_ATTR
51
105
  size_t ZSTD_compressBlock_doubleFast_noDict_generic(
52
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
106
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
53
107
  void const* src, size_t srcSize, U32 const mls /* template */)
54
108
  {
55
109
  ZSTD_compressionParameters const* cParams = &ms->cParams;
@@ -67,7 +121,7 @@ size_t ZSTD_compressBlock_doubleFast_noDict_generic(
67
121
  const BYTE* const iend = istart + srcSize;
68
122
  const BYTE* const ilimit = iend - HASH_READ_SIZE;
69
123
  U32 offset_1=rep[0], offset_2=rep[1];
70
- U32 offsetSaved = 0;
124
+ U32 offsetSaved1 = 0, offsetSaved2 = 0;
71
125
 
72
126
  size_t mLength;
73
127
  U32 offset;
@@ -88,9 +142,14 @@ size_t ZSTD_compressBlock_doubleFast_noDict_generic(
88
142
  const BYTE* matchl0; /* the long match for ip */
89
143
  const BYTE* matchs0; /* the short match for ip */
90
144
  const BYTE* matchl1; /* the long match for ip1 */
145
+ const BYTE* matchs0_safe; /* matchs0 or safe address */
91
146
 
92
147
  const BYTE* ip = istart; /* the current position */
93
148
  const BYTE* ip1; /* the next position */
149
+ /* Array of ~random data, should have low probability of matching data
150
+ * we load from here instead of from tables, if matchl0/matchl1 are
151
+ * invalid indices. Used to avoid unpredictable branches. */
152
+ const BYTE dummy[] = {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0xe2,0xb4};
94
153
 
95
154
  DEBUGLOG(5, "ZSTD_compressBlock_doubleFast_noDict_generic");
96
155
 
@@ -100,8 +159,8 @@ size_t ZSTD_compressBlock_doubleFast_noDict_generic(
100
159
  U32 const current = (U32)(ip - base);
101
160
  U32 const windowLow = ZSTD_getLowestPrefixIndex(ms, current, cParams->windowLog);
102
161
  U32 const maxRep = current - windowLow;
103
- if (offset_2 > maxRep) offsetSaved = offset_2, offset_2 = 0;
104
- if (offset_1 > maxRep) offsetSaved = offset_1, offset_1 = 0;
162
+ if (offset_2 > maxRep) offsetSaved2 = offset_2, offset_2 = 0;
163
+ if (offset_1 > maxRep) offsetSaved1 = offset_1, offset_1 = 0;
105
164
  }
106
165
 
107
166
  /* Outer Loop: one iteration per match found and stored */
@@ -131,30 +190,35 @@ size_t ZSTD_compressBlock_doubleFast_noDict_generic(
131
190
  if ((offset_1 > 0) & (MEM_read32(ip+1-offset_1) == MEM_read32(ip+1))) {
132
191
  mLength = ZSTD_count(ip+1+4, ip+1+4-offset_1, iend) + 4;
133
192
  ip++;
134
- ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, STORE_REPCODE_1, mLength);
193
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, REPCODE1_TO_OFFBASE, mLength);
135
194
  goto _match_stored;
136
195
  }
137
196
 
138
197
  hl1 = ZSTD_hashPtr(ip1, hBitsL, 8);
139
198
 
140
- if (idxl0 > prefixLowestIndex) {
199
+ /* idxl0 > prefixLowestIndex is a (somewhat) unpredictable branch.
200
+ * However expression below complies into conditional move. Since
201
+ * match is unlikely and we only *branch* on idxl0 > prefixLowestIndex
202
+ * if there is a match, all branches become predictable. */
203
+ { const BYTE* const matchl0_safe = ZSTD_selectAddr(idxl0, prefixLowestIndex, matchl0, &dummy[0]);
204
+
141
205
  /* check prefix long match */
142
- if (MEM_read64(matchl0) == MEM_read64(ip)) {
206
+ if (MEM_read64(matchl0_safe) == MEM_read64(ip) && matchl0_safe == matchl0) {
143
207
  mLength = ZSTD_count(ip+8, matchl0+8, iend) + 8;
144
208
  offset = (U32)(ip-matchl0);
145
209
  while (((ip>anchor) & (matchl0>prefixLowest)) && (ip[-1] == matchl0[-1])) { ip--; matchl0--; mLength++; } /* catch up */
146
210
  goto _match_found;
147
- }
148
- }
211
+ } }
149
212
 
150
213
  idxl1 = hashLong[hl1];
151
214
  matchl1 = base + idxl1;
152
215
 
153
- if (idxs0 > prefixLowestIndex) {
154
- /* check prefix short match */
155
- if (MEM_read32(matchs0) == MEM_read32(ip)) {
156
- goto _search_next_long;
157
- }
216
+ /* Same optimization as matchl0 above */
217
+ matchs0_safe = ZSTD_selectAddr(idxs0, prefixLowestIndex, matchs0, &dummy[0]);
218
+
219
+ /* check prefix short match */
220
+ if(MEM_read32(matchs0_safe) == MEM_read32(ip) && matchs0_safe == matchs0) {
221
+ goto _search_next_long;
158
222
  }
159
223
 
160
224
  if (ip1 >= nextStep) {
@@ -175,30 +239,36 @@ size_t ZSTD_compressBlock_doubleFast_noDict_generic(
175
239
  } while (ip1 <= ilimit);
176
240
 
177
241
  _cleanup:
242
+ /* If offset_1 started invalid (offsetSaved1 != 0) and became valid (offset_1 != 0),
243
+ * rotate saved offsets. See comment in ZSTD_compressBlock_fast_noDict for more context. */
244
+ offsetSaved2 = ((offsetSaved1 != 0) && (offset_1 != 0)) ? offsetSaved1 : offsetSaved2;
245
+
178
246
  /* save reps for next block */
179
- rep[0] = offset_1 ? offset_1 : offsetSaved;
180
- rep[1] = offset_2 ? offset_2 : offsetSaved;
247
+ rep[0] = offset_1 ? offset_1 : offsetSaved1;
248
+ rep[1] = offset_2 ? offset_2 : offsetSaved2;
181
249
 
182
250
  /* Return the last literals size */
183
251
  return (size_t)(iend - anchor);
184
252
 
185
253
  _search_next_long:
186
254
 
187
- /* check prefix long +1 match */
188
- if (idxl1 > prefixLowestIndex) {
189
- if (MEM_read64(matchl1) == MEM_read64(ip1)) {
255
+ /* short match found: let's check for a longer one */
256
+ mLength = ZSTD_count(ip+4, matchs0+4, iend) + 4;
257
+ offset = (U32)(ip - matchs0);
258
+
259
+ /* check long match at +1 position */
260
+ if ((idxl1 > prefixLowestIndex) && (MEM_read64(matchl1) == MEM_read64(ip1))) {
261
+ size_t const l1len = ZSTD_count(ip1+8, matchl1+8, iend) + 8;
262
+ if (l1len > mLength) {
263
+ /* use the long match instead */
190
264
  ip = ip1;
191
- mLength = ZSTD_count(ip+8, matchl1+8, iend) + 8;
265
+ mLength = l1len;
192
266
  offset = (U32)(ip-matchl1);
193
- while (((ip>anchor) & (matchl1>prefixLowest)) && (ip[-1] == matchl1[-1])) { ip--; matchl1--; mLength++; } /* catch up */
194
- goto _match_found;
267
+ matchs0 = matchl1;
195
268
  }
196
269
  }
197
270
 
198
- /* if no long +1 match, explore the short match we found */
199
- mLength = ZSTD_count(ip+4, matchs0+4, iend) + 4;
200
- offset = (U32)(ip - matchs0);
201
- while (((ip>anchor) & (matchs0>prefixLowest)) && (ip[-1] == matchs0[-1])) { ip--; matchs0--; mLength++; } /* catch up */
271
+ while (((ip>anchor) & (matchs0>prefixLowest)) && (ip[-1] == matchs0[-1])) { ip--; matchs0--; mLength++; } /* complete backward */
202
272
 
203
273
  /* fall-through */
204
274
 
@@ -217,7 +287,7 @@ _match_found: /* requires ip, offset, mLength */
217
287
  hashLong[hl1] = (U32)(ip1 - base);
218
288
  }
219
289
 
220
- ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, STORE_OFFSET(offset), mLength);
290
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, OFFSET_TO_OFFBASE(offset), mLength);
221
291
 
222
292
  _match_stored:
223
293
  /* match found */
@@ -243,7 +313,7 @@ _match_stored:
243
313
  U32 const tmpOff = offset_2; offset_2 = offset_1; offset_1 = tmpOff; /* swap offset_2 <=> offset_1 */
244
314
  hashSmall[ZSTD_hashPtr(ip, hBitsS, mls)] = (U32)(ip-base);
245
315
  hashLong[ZSTD_hashPtr(ip, hBitsL, 8)] = (U32)(ip-base);
246
- ZSTD_storeSeq(seqStore, 0, anchor, iend, STORE_REPCODE_1, rLength);
316
+ ZSTD_storeSeq(seqStore, 0, anchor, iend, REPCODE1_TO_OFFBASE, rLength);
247
317
  ip += rLength;
248
318
  anchor = ip;
249
319
  continue; /* faster when present ... (?) */
@@ -254,8 +324,9 @@ _match_stored:
254
324
 
255
325
 
256
326
  FORCE_INLINE_TEMPLATE
327
+ ZSTD_ALLOW_POINTER_OVERFLOW_ATTR
257
328
  size_t ZSTD_compressBlock_doubleFast_dictMatchState_generic(
258
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
329
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
259
330
  void const* src, size_t srcSize,
260
331
  U32 const mls /* template */)
261
332
  {
@@ -275,9 +346,8 @@ size_t ZSTD_compressBlock_doubleFast_dictMatchState_generic(
275
346
  const BYTE* const iend = istart + srcSize;
276
347
  const BYTE* const ilimit = iend - HASH_READ_SIZE;
277
348
  U32 offset_1=rep[0], offset_2=rep[1];
278
- U32 offsetSaved = 0;
279
349
 
280
- const ZSTD_matchState_t* const dms = ms->dictMatchState;
350
+ const ZSTD_MatchState_t* const dms = ms->dictMatchState;
281
351
  const ZSTD_compressionParameters* const dictCParams = &dms->cParams;
282
352
  const U32* const dictHashLong = dms->hashTable;
283
353
  const U32* const dictHashSmall = dms->chainTable;
@@ -286,8 +356,8 @@ size_t ZSTD_compressBlock_doubleFast_dictMatchState_generic(
286
356
  const BYTE* const dictStart = dictBase + dictStartIndex;
287
357
  const BYTE* const dictEnd = dms->window.nextSrc;
288
358
  const U32 dictIndexDelta = prefixLowestIndex - (U32)(dictEnd - dictBase);
289
- const U32 dictHBitsL = dictCParams->hashLog;
290
- const U32 dictHBitsS = dictCParams->chainLog;
359
+ const U32 dictHBitsL = dictCParams->hashLog + ZSTD_SHORT_CACHE_TAG_BITS;
360
+ const U32 dictHBitsS = dictCParams->chainLog + ZSTD_SHORT_CACHE_TAG_BITS;
291
361
  const U32 dictAndPrefixLength = (U32)((ip - prefixLowest) + (dictEnd - dictStart));
292
362
 
293
363
  DEBUGLOG(5, "ZSTD_compressBlock_doubleFast_dictMatchState_generic");
@@ -295,6 +365,13 @@ size_t ZSTD_compressBlock_doubleFast_dictMatchState_generic(
295
365
  /* if a dictionary is attached, it must be within window range */
296
366
  assert(ms->window.dictLimit + (1U << cParams->windowLog) >= endIndex);
297
367
 
368
+ if (ms->prefetchCDictTables) {
369
+ size_t const hashTableBytes = (((size_t)1) << dictCParams->hashLog) * sizeof(U32);
370
+ size_t const chainTableBytes = (((size_t)1) << dictCParams->chainLog) * sizeof(U32);
371
+ PREFETCH_AREA(dictHashLong, hashTableBytes);
372
+ PREFETCH_AREA(dictHashSmall, chainTableBytes);
373
+ }
374
+
298
375
  /* init */
299
376
  ip += (dictAndPrefixLength == 0);
300
377
 
@@ -309,8 +386,12 @@ size_t ZSTD_compressBlock_doubleFast_dictMatchState_generic(
309
386
  U32 offset;
310
387
  size_t const h2 = ZSTD_hashPtr(ip, hBitsL, 8);
311
388
  size_t const h = ZSTD_hashPtr(ip, hBitsS, mls);
312
- size_t const dictHL = ZSTD_hashPtr(ip, dictHBitsL, 8);
313
- size_t const dictHS = ZSTD_hashPtr(ip, dictHBitsS, mls);
389
+ size_t const dictHashAndTagL = ZSTD_hashPtr(ip, dictHBitsL, 8);
390
+ size_t const dictHashAndTagS = ZSTD_hashPtr(ip, dictHBitsS, mls);
391
+ U32 const dictMatchIndexAndTagL = dictHashLong[dictHashAndTagL >> ZSTD_SHORT_CACHE_TAG_BITS];
392
+ U32 const dictMatchIndexAndTagS = dictHashSmall[dictHashAndTagS >> ZSTD_SHORT_CACHE_TAG_BITS];
393
+ int const dictTagsMatchL = ZSTD_comparePackedTags(dictMatchIndexAndTagL, dictHashAndTagL);
394
+ int const dictTagsMatchS = ZSTD_comparePackedTags(dictMatchIndexAndTagS, dictHashAndTagS);
314
395
  U32 const curr = (U32)(ip-base);
315
396
  U32 const matchIndexL = hashLong[h2];
316
397
  U32 matchIndexS = hashSmall[h];
@@ -323,26 +404,24 @@ size_t ZSTD_compressBlock_doubleFast_dictMatchState_generic(
323
404
  hashLong[h2] = hashSmall[h] = curr; /* update hash tables */
324
405
 
325
406
  /* check repcode */
326
- if (((U32)((prefixLowestIndex-1) - repIndex) >= 3 /* intentional underflow */)
407
+ if ((ZSTD_index_overlap_check(prefixLowestIndex, repIndex))
327
408
  && (MEM_read32(repMatch) == MEM_read32(ip+1)) ) {
328
409
  const BYTE* repMatchEnd = repIndex < prefixLowestIndex ? dictEnd : iend;
329
410
  mLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, prefixLowest) + 4;
330
411
  ip++;
331
- ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, STORE_REPCODE_1, mLength);
412
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, REPCODE1_TO_OFFBASE, mLength);
332
413
  goto _match_stored;
333
414
  }
334
415
 
335
- if (matchIndexL > prefixLowestIndex) {
416
+ if ((matchIndexL >= prefixLowestIndex) && (MEM_read64(matchLong) == MEM_read64(ip))) {
336
417
  /* check prefix long match */
337
- if (MEM_read64(matchLong) == MEM_read64(ip)) {
338
- mLength = ZSTD_count(ip+8, matchLong+8, iend) + 8;
339
- offset = (U32)(ip-matchLong);
340
- while (((ip>anchor) & (matchLong>prefixLowest)) && (ip[-1] == matchLong[-1])) { ip--; matchLong--; mLength++; } /* catch up */
341
- goto _match_found;
342
- }
343
- } else {
418
+ mLength = ZSTD_count(ip+8, matchLong+8, iend) + 8;
419
+ offset = (U32)(ip-matchLong);
420
+ while (((ip>anchor) & (matchLong>prefixLowest)) && (ip[-1] == matchLong[-1])) { ip--; matchLong--; mLength++; } /* catch up */
421
+ goto _match_found;
422
+ } else if (dictTagsMatchL) {
344
423
  /* check dictMatchState long match */
345
- U32 const dictMatchIndexL = dictHashLong[dictHL];
424
+ U32 const dictMatchIndexL = dictMatchIndexAndTagL >> ZSTD_SHORT_CACHE_TAG_BITS;
346
425
  const BYTE* dictMatchL = dictBase + dictMatchIndexL;
347
426
  assert(dictMatchL < dictEnd);
348
427
 
@@ -354,13 +433,13 @@ size_t ZSTD_compressBlock_doubleFast_dictMatchState_generic(
354
433
  } }
355
434
 
356
435
  if (matchIndexS > prefixLowestIndex) {
357
- /* check prefix short match */
436
+ /* short match candidate */
358
437
  if (MEM_read32(match) == MEM_read32(ip)) {
359
438
  goto _search_next_long;
360
439
  }
361
- } else {
440
+ } else if (dictTagsMatchS) {
362
441
  /* check dictMatchState short match */
363
- U32 const dictMatchIndexS = dictHashSmall[dictHS];
442
+ U32 const dictMatchIndexS = dictMatchIndexAndTagS >> ZSTD_SHORT_CACHE_TAG_BITS;
364
443
  match = dictBase + dictMatchIndexS;
365
444
  matchIndexS = dictMatchIndexS + dictIndexDelta;
366
445
 
@@ -375,25 +454,24 @@ size_t ZSTD_compressBlock_doubleFast_dictMatchState_generic(
375
454
  continue;
376
455
 
377
456
  _search_next_long:
378
-
379
457
  { size_t const hl3 = ZSTD_hashPtr(ip+1, hBitsL, 8);
380
- size_t const dictHLNext = ZSTD_hashPtr(ip+1, dictHBitsL, 8);
458
+ size_t const dictHashAndTagL3 = ZSTD_hashPtr(ip+1, dictHBitsL, 8);
381
459
  U32 const matchIndexL3 = hashLong[hl3];
460
+ U32 const dictMatchIndexAndTagL3 = dictHashLong[dictHashAndTagL3 >> ZSTD_SHORT_CACHE_TAG_BITS];
461
+ int const dictTagsMatchL3 = ZSTD_comparePackedTags(dictMatchIndexAndTagL3, dictHashAndTagL3);
382
462
  const BYTE* matchL3 = base + matchIndexL3;
383
463
  hashLong[hl3] = curr + 1;
384
464
 
385
465
  /* check prefix long +1 match */
386
- if (matchIndexL3 > prefixLowestIndex) {
387
- if (MEM_read64(matchL3) == MEM_read64(ip+1)) {
388
- mLength = ZSTD_count(ip+9, matchL3+8, iend) + 8;
389
- ip++;
390
- offset = (U32)(ip-matchL3);
391
- while (((ip>anchor) & (matchL3>prefixLowest)) && (ip[-1] == matchL3[-1])) { ip--; matchL3--; mLength++; } /* catch up */
392
- goto _match_found;
393
- }
394
- } else {
466
+ if ((matchIndexL3 >= prefixLowestIndex) && (MEM_read64(matchL3) == MEM_read64(ip+1))) {
467
+ mLength = ZSTD_count(ip+9, matchL3+8, iend) + 8;
468
+ ip++;
469
+ offset = (U32)(ip-matchL3);
470
+ while (((ip>anchor) & (matchL3>prefixLowest)) && (ip[-1] == matchL3[-1])) { ip--; matchL3--; mLength++; } /* catch up */
471
+ goto _match_found;
472
+ } else if (dictTagsMatchL3) {
395
473
  /* check dict long +1 match */
396
- U32 const dictMatchIndexL3 = dictHashLong[dictHLNext];
474
+ U32 const dictMatchIndexL3 = dictMatchIndexAndTagL3 >> ZSTD_SHORT_CACHE_TAG_BITS;
397
475
  const BYTE* dictMatchL3 = dictBase + dictMatchIndexL3;
398
476
  assert(dictMatchL3 < dictEnd);
399
477
  if (dictMatchL3 > dictStart && MEM_read64(dictMatchL3) == MEM_read64(ip+1)) {
@@ -419,7 +497,7 @@ _match_found:
419
497
  offset_2 = offset_1;
420
498
  offset_1 = offset;
421
499
 
422
- ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, STORE_OFFSET(offset), mLength);
500
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, OFFSET_TO_OFFBASE(offset), mLength);
423
501
 
424
502
  _match_stored:
425
503
  /* match found */
@@ -443,12 +521,12 @@ _match_stored:
443
521
  const BYTE* repMatch2 = repIndex2 < prefixLowestIndex ?
444
522
  dictBase + repIndex2 - dictIndexDelta :
445
523
  base + repIndex2;
446
- if ( ((U32)((prefixLowestIndex-1) - (U32)repIndex2) >= 3 /* intentional overflow */)
524
+ if ( (ZSTD_index_overlap_check(prefixLowestIndex, repIndex2))
447
525
  && (MEM_read32(repMatch2) == MEM_read32(ip)) ) {
448
526
  const BYTE* const repEnd2 = repIndex2 < prefixLowestIndex ? dictEnd : iend;
449
527
  size_t const repLength2 = ZSTD_count_2segments(ip+4, repMatch2+4, iend, repEnd2, prefixLowest) + 4;
450
528
  U32 tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset; /* swap offset_2 <=> offset_1 */
451
- ZSTD_storeSeq(seqStore, 0, anchor, iend, STORE_REPCODE_1, repLength2);
529
+ ZSTD_storeSeq(seqStore, 0, anchor, iend, REPCODE1_TO_OFFBASE, repLength2);
452
530
  hashSmall[ZSTD_hashPtr(ip, hBitsS, mls)] = current2;
453
531
  hashLong[ZSTD_hashPtr(ip, hBitsL, 8)] = current2;
454
532
  ip += repLength2;
@@ -461,8 +539,8 @@ _match_stored:
461
539
  } /* while (ip < ilimit) */
462
540
 
463
541
  /* save reps for next block */
464
- rep[0] = offset_1 ? offset_1 : offsetSaved;
465
- rep[1] = offset_2 ? offset_2 : offsetSaved;
542
+ rep[0] = offset_1;
543
+ rep[1] = offset_2;
466
544
 
467
545
  /* Return the last literals size */
468
546
  return (size_t)(iend - anchor);
@@ -470,7 +548,7 @@ _match_stored:
470
548
 
471
549
  #define ZSTD_GEN_DFAST_FN(dictMode, mls) \
472
550
  static size_t ZSTD_compressBlock_doubleFast_##dictMode##_##mls( \
473
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM], \
551
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM], \
474
552
  void const* src, size_t srcSize) \
475
553
  { \
476
554
  return ZSTD_compressBlock_doubleFast_##dictMode##_generic(ms, seqStore, rep, src, srcSize, mls); \
@@ -488,7 +566,7 @@ ZSTD_GEN_DFAST_FN(dictMatchState, 7)
488
566
 
489
567
 
490
568
  size_t ZSTD_compressBlock_doubleFast(
491
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
569
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
492
570
  void const* src, size_t srcSize)
493
571
  {
494
572
  const U32 mls = ms->cParams.minMatch;
@@ -508,7 +586,7 @@ size_t ZSTD_compressBlock_doubleFast(
508
586
 
509
587
 
510
588
  size_t ZSTD_compressBlock_doubleFast_dictMatchState(
511
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
589
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
512
590
  void const* src, size_t srcSize)
513
591
  {
514
592
  const U32 mls = ms->cParams.minMatch;
@@ -527,8 +605,10 @@ size_t ZSTD_compressBlock_doubleFast_dictMatchState(
527
605
  }
528
606
 
529
607
 
530
- static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
531
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
608
+ static
609
+ ZSTD_ALLOW_POINTER_OVERFLOW_ATTR
610
+ size_t ZSTD_compressBlock_doubleFast_extDict_generic(
611
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
532
612
  void const* src, size_t srcSize,
533
613
  U32 const mls /* template */)
534
614
  {
@@ -579,13 +659,13 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
579
659
  size_t mLength;
580
660
  hashSmall[hSmall] = hashLong[hLong] = curr; /* update hash table */
581
661
 
582
- if ((((U32)((prefixStartIndex-1) - repIndex) >= 3) /* intentional underflow : ensure repIndex doesn't overlap dict + prefix */
662
+ if (((ZSTD_index_overlap_check(prefixStartIndex, repIndex))
583
663
  & (offset_1 <= curr+1 - dictStartIndex)) /* note: we are searching at curr+1 */
584
664
  && (MEM_read32(repMatch) == MEM_read32(ip+1)) ) {
585
665
  const BYTE* repMatchEnd = repIndex < prefixStartIndex ? dictEnd : iend;
586
666
  mLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, prefixStart) + 4;
587
667
  ip++;
588
- ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, STORE_REPCODE_1, mLength);
668
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, REPCODE1_TO_OFFBASE, mLength);
589
669
  } else {
590
670
  if ((matchLongIndex > dictStartIndex) && (MEM_read64(matchLong) == MEM_read64(ip))) {
591
671
  const BYTE* const matchEnd = matchLongIndex < prefixStartIndex ? dictEnd : iend;
@@ -596,7 +676,7 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
596
676
  while (((ip>anchor) & (matchLong>lowMatchPtr)) && (ip[-1] == matchLong[-1])) { ip--; matchLong--; mLength++; } /* catch up */
597
677
  offset_2 = offset_1;
598
678
  offset_1 = offset;
599
- ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, STORE_OFFSET(offset), mLength);
679
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, OFFSET_TO_OFFBASE(offset), mLength);
600
680
 
601
681
  } else if ((matchIndex > dictStartIndex) && (MEM_read32(match) == MEM_read32(ip))) {
602
682
  size_t const h3 = ZSTD_hashPtr(ip+1, hBitsL, 8);
@@ -621,7 +701,7 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
621
701
  }
622
702
  offset_2 = offset_1;
623
703
  offset_1 = offset;
624
- ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, STORE_OFFSET(offset), mLength);
704
+ ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, OFFSET_TO_OFFBASE(offset), mLength);
625
705
 
626
706
  } else {
627
707
  ip += ((ip-anchor) >> kSearchStrength) + 1;
@@ -647,13 +727,13 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
647
727
  U32 const current2 = (U32)(ip-base);
648
728
  U32 const repIndex2 = current2 - offset_2;
649
729
  const BYTE* repMatch2 = repIndex2 < prefixStartIndex ? dictBase + repIndex2 : base + repIndex2;
650
- if ( (((U32)((prefixStartIndex-1) - repIndex2) >= 3) /* intentional overflow : ensure repIndex2 doesn't overlap dict + prefix */
730
+ if ( ((ZSTD_index_overlap_check(prefixStartIndex, repIndex2))
651
731
  & (offset_2 <= current2 - dictStartIndex))
652
732
  && (MEM_read32(repMatch2) == MEM_read32(ip)) ) {
653
733
  const BYTE* const repEnd2 = repIndex2 < prefixStartIndex ? dictEnd : iend;
654
734
  size_t const repLength2 = ZSTD_count_2segments(ip+4, repMatch2+4, iend, repEnd2, prefixStart) + 4;
655
735
  U32 const tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset; /* swap offset_2 <=> offset_1 */
656
- ZSTD_storeSeq(seqStore, 0, anchor, iend, STORE_REPCODE_1, repLength2);
736
+ ZSTD_storeSeq(seqStore, 0, anchor, iend, REPCODE1_TO_OFFBASE, repLength2);
657
737
  hashSmall[ZSTD_hashPtr(ip, hBitsS, mls)] = current2;
658
738
  hashLong[ZSTD_hashPtr(ip, hBitsL, 8)] = current2;
659
739
  ip += repLength2;
@@ -677,7 +757,7 @@ ZSTD_GEN_DFAST_FN(extDict, 6)
677
757
  ZSTD_GEN_DFAST_FN(extDict, 7)
678
758
 
679
759
  size_t ZSTD_compressBlock_doubleFast_extDict(
680
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
760
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
681
761
  void const* src, size_t srcSize)
682
762
  {
683
763
  U32 const mls = ms->cParams.minMatch;
@@ -694,3 +774,5 @@ size_t ZSTD_compressBlock_doubleFast_extDict(
694
774
  return ZSTD_compressBlock_doubleFast_extDict_7(ms, seqStore, rep, src, srcSize);
695
775
  }
696
776
  }
777
+
778
+ #endif /* ZSTD_EXCLUDE_DFAST_BLOCK_COMPRESSOR */
@@ -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,28 +11,32 @@
11
11
  #ifndef ZSTD_DOUBLE_FAST_H
12
12
  #define ZSTD_DOUBLE_FAST_H
13
13
 
14
- #if defined (__cplusplus)
15
- extern "C" {
16
- #endif
17
-
18
14
  #include "../common/mem.h" /* U32 */
19
15
  #include "zstd_compress_internal.h" /* ZSTD_CCtx, size_t */
20
16
 
21
- void ZSTD_fillDoubleHashTable(ZSTD_matchState_t* ms,
22
- void const* end, ZSTD_dictTableLoadMethod_e dtlm);
17
+ #ifndef ZSTD_EXCLUDE_DFAST_BLOCK_COMPRESSOR
18
+
19
+ void ZSTD_fillDoubleHashTable(ZSTD_MatchState_t* ms,
20
+ void const* end, ZSTD_dictTableLoadMethod_e dtlm,
21
+ ZSTD_tableFillPurpose_e tfp);
22
+
23
23
  size_t ZSTD_compressBlock_doubleFast(
24
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
24
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
25
25
  void const* src, size_t srcSize);
26
26
  size_t ZSTD_compressBlock_doubleFast_dictMatchState(
27
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
27
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
28
28
  void const* src, size_t srcSize);
29
29
  size_t ZSTD_compressBlock_doubleFast_extDict(
30
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
30
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
31
31
  void const* src, size_t srcSize);
32
32
 
33
-
34
- #if defined (__cplusplus)
35
- }
36
- #endif
33
+ #define ZSTD_COMPRESSBLOCK_DOUBLEFAST ZSTD_compressBlock_doubleFast
34
+ #define ZSTD_COMPRESSBLOCK_DOUBLEFAST_DICTMATCHSTATE ZSTD_compressBlock_doubleFast_dictMatchState
35
+ #define ZSTD_COMPRESSBLOCK_DOUBLEFAST_EXTDICT ZSTD_compressBlock_doubleFast_extDict
36
+ #else
37
+ #define ZSTD_COMPRESSBLOCK_DOUBLEFAST NULL
38
+ #define ZSTD_COMPRESSBLOCK_DOUBLEFAST_DICTMATCHSTATE NULL
39
+ #define ZSTD_COMPRESSBLOCK_DOUBLEFAST_EXTDICT NULL
40
+ #endif /* ZSTD_EXCLUDE_DFAST_BLOCK_COMPRESSOR */
37
41
 
38
42
  #endif /* ZSTD_DOUBLE_FAST_H */