lz_encoder_mf.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. /// \file lz_encoder_mf.c
  4. /// \brief Match finders
  5. ///
  6. // Authors: Igor Pavlov
  7. // Lasse Collin
  8. //
  9. // This file has been put into the public domain.
  10. // You can do whatever you want with this file.
  11. //
  12. ///////////////////////////////////////////////////////////////////////////////
  13. #include "lz_encoder.h"
  14. #include "lz_encoder_hash.h"
  15. #include "memcmplen.h"
  16. /// \brief Find matches starting from the current byte
  17. ///
  18. /// \return The length of the longest match found
  19. extern uint32_t
  20. lzma_mf_find(lzma_mf *mf, uint32_t *count_ptr, lzma_match *matches)
  21. {
  22. // Call the match finder. It returns the number of length-distance
  23. // pairs found.
  24. // FIXME: Minimum count is zero, what _exactly_ is the maximum?
  25. const uint32_t count = mf->find(mf, matches);
  26. // Length of the longest match; assume that no matches were found
  27. // and thus the maximum length is zero.
  28. uint32_t len_best = 0;
  29. if (count > 0) {
  30. #ifndef NDEBUG
  31. // Validate the matches.
  32. for (uint32_t i = 0; i < count; ++i) {
  33. assert(matches[i].len <= mf->nice_len);
  34. assert(matches[i].dist < mf->read_pos);
  35. assert(memcmp(mf_ptr(mf) - 1,
  36. mf_ptr(mf) - matches[i].dist - 2,
  37. matches[i].len) == 0);
  38. }
  39. #endif
  40. // The last used element in the array contains
  41. // the longest match.
  42. len_best = matches[count - 1].len;
  43. // If a match of maximum search length was found, try to
  44. // extend the match to maximum possible length.
  45. if (len_best == mf->nice_len) {
  46. // The limit for the match length is either the
  47. // maximum match length supported by the LZ-based
  48. // encoder or the number of bytes left in the
  49. // dictionary, whichever is smaller.
  50. uint32_t limit = mf_avail(mf) + 1;
  51. if (limit > mf->match_len_max)
  52. limit = mf->match_len_max;
  53. // Pointer to the byte we just ran through
  54. // the match finder.
  55. const uint8_t *p1 = mf_ptr(mf) - 1;
  56. // Pointer to the beginning of the match. We need -1
  57. // here because the match distances are zero based.
  58. const uint8_t *p2 = p1 - matches[count - 1].dist - 1;
  59. len_best = lzma_memcmplen(p1, p2, len_best, limit);
  60. }
  61. }
  62. *count_ptr = count;
  63. // Finally update the read position to indicate that match finder was
  64. // run for this dictionary offset.
  65. ++mf->read_ahead;
  66. return len_best;
  67. }
  68. /// Hash value to indicate unused element in the hash. Since we start the
  69. /// positions from dict_size + 1, zero is always too far to qualify
  70. /// as usable match position.
  71. #define EMPTY_HASH_VALUE 0
  72. /// Normalization must be done when lzma_mf.offset + lzma_mf.read_pos
  73. /// reaches MUST_NORMALIZE_POS.
  74. #define MUST_NORMALIZE_POS UINT32_MAX
  75. /// \brief Normalizes hash values
  76. ///
  77. /// The hash arrays store positions of match candidates. The positions are
  78. /// relative to an arbitrary offset that is not the same as the absolute
  79. /// offset in the input stream. The relative position of the current byte
  80. /// is lzma_mf.offset + lzma_mf.read_pos. The distances of the matches are
  81. /// the differences of the current read position and the position found from
  82. /// the hash.
  83. ///
  84. /// To prevent integer overflows of the offsets stored in the hash arrays,
  85. /// we need to "normalize" the stored values now and then. During the
  86. /// normalization, we drop values that indicate distance greater than the
  87. /// dictionary size, thus making space for new values.
  88. static void
  89. normalize(lzma_mf *mf)
  90. {
  91. assert(mf->read_pos + mf->offset == MUST_NORMALIZE_POS);
  92. // In future we may not want to touch the lowest bits, because there
  93. // may be match finders that use larger resolution than one byte.
  94. const uint32_t subvalue
  95. = (MUST_NORMALIZE_POS - mf->cyclic_size);
  96. // & ~((UINT32_C(1) << 10) - 1);
  97. for (uint32_t i = 0; i < mf->hash_count; ++i) {
  98. // If the distance is greater than the dictionary size,
  99. // we can simply mark the hash element as empty.
  100. if (mf->hash[i] <= subvalue)
  101. mf->hash[i] = EMPTY_HASH_VALUE;
  102. else
  103. mf->hash[i] -= subvalue;
  104. }
  105. for (uint32_t i = 0; i < mf->sons_count; ++i) {
  106. // Do the same for mf->son.
  107. //
  108. // NOTE: There may be uninitialized elements in mf->son.
  109. // Valgrind may complain that the "if" below depends on
  110. // an uninitialized value. In this case it is safe to ignore
  111. // the warning. See also the comments in lz_encoder_init()
  112. // in lz_encoder.c.
  113. if (mf->son[i] <= subvalue)
  114. mf->son[i] = EMPTY_HASH_VALUE;
  115. else
  116. mf->son[i] -= subvalue;
  117. }
  118. // Update offset to match the new locations.
  119. mf->offset -= subvalue;
  120. return;
  121. }
  122. /// Mark the current byte as processed from point of view of the match finder.
  123. static void
  124. move_pos(lzma_mf *mf)
  125. {
  126. if (++mf->cyclic_pos == mf->cyclic_size)
  127. mf->cyclic_pos = 0;
  128. ++mf->read_pos;
  129. assert(mf->read_pos <= mf->write_pos);
  130. if (unlikely(mf->read_pos + mf->offset == UINT32_MAX))
  131. normalize(mf);
  132. }
  133. /// When flushing, we cannot run the match finder unless there is nice_len
  134. /// bytes available in the dictionary. Instead, we skip running the match
  135. /// finder (indicating that no match was found), and count how many bytes we
  136. /// have ignored this way.
  137. ///
  138. /// When new data is given after the flushing was completed, the match finder
  139. /// is restarted by rewinding mf->read_pos backwards by mf->pending. Then
  140. /// the missed bytes are added to the hash using the match finder's skip
  141. /// function (with small amount of input, it may start using mf->pending
  142. /// again if flushing).
  143. ///
  144. /// Due to this rewinding, we don't touch cyclic_pos or test for
  145. /// normalization. It will be done when the match finder's skip function
  146. /// catches up after a flush.
  147. static void
  148. move_pending(lzma_mf *mf)
  149. {
  150. ++mf->read_pos;
  151. assert(mf->read_pos <= mf->write_pos);
  152. ++mf->pending;
  153. }
  154. /// Calculate len_limit and determine if there is enough input to run
  155. /// the actual match finder code. Sets up "cur" and "pos". This macro
  156. /// is used by all find functions and binary tree skip functions. Hash
  157. /// chain skip function doesn't need len_limit so a simpler code is used
  158. /// in them.
  159. #define header(is_bt, len_min, ret_op) \
  160. uint32_t len_limit = mf_avail(mf); \
  161. if (mf->nice_len <= len_limit) { \
  162. len_limit = mf->nice_len; \
  163. } else if (len_limit < (len_min) \
  164. || (is_bt && mf->action == LZMA_SYNC_FLUSH)) { \
  165. assert(mf->action != LZMA_RUN); \
  166. move_pending(mf); \
  167. ret_op; \
  168. } \
  169. const uint8_t *cur = mf_ptr(mf); \
  170. const uint32_t pos = mf->read_pos + mf->offset
  171. /// Header for find functions. "return 0" indicates that zero matches
  172. /// were found.
  173. #define header_find(is_bt, len_min) \
  174. header(is_bt, len_min, return 0); \
  175. uint32_t matches_count = 0
  176. /// Header for a loop in a skip function. "continue" tells to skip the rest
  177. /// of the code in the loop.
  178. #define header_skip(is_bt, len_min) \
  179. header(is_bt, len_min, continue)
  180. /// Calls hc_find_func() or bt_find_func() and calculates the total number
  181. /// of matches found. Updates the dictionary position and returns the number
  182. /// of matches found.
  183. #define call_find(func, len_best) \
  184. do { \
  185. matches_count = func(len_limit, pos, cur, cur_match, mf->depth, \
  186. mf->son, mf->cyclic_pos, mf->cyclic_size, \
  187. matches + matches_count, len_best) \
  188. - matches; \
  189. move_pos(mf); \
  190. return matches_count; \
  191. } while (0)
  192. ////////////////
  193. // Hash Chain //
  194. ////////////////
  195. #if defined(HAVE_MF_HC3) || defined(HAVE_MF_HC4)
  196. ///
  197. ///
  198. /// \param len_limit Don't look for matches longer than len_limit.
  199. /// \param pos lzma_mf.read_pos + lzma_mf.offset
  200. /// \param cur Pointer to current byte (mf_ptr(mf))
  201. /// \param cur_match Start position of the current match candidate
  202. /// \param depth Maximum length of the hash chain
  203. /// \param son lzma_mf.son (contains the hash chain)
  204. /// \param cyclic_pos
  205. /// \param cyclic_size
  206. /// \param matches Array to hold the matches.
  207. /// \param len_best The length of the longest match found so far.
  208. static lzma_match *
  209. hc_find_func(
  210. const uint32_t len_limit,
  211. const uint32_t pos,
  212. const uint8_t *const cur,
  213. uint32_t cur_match,
  214. uint32_t depth,
  215. uint32_t *const son,
  216. const uint32_t cyclic_pos,
  217. const uint32_t cyclic_size,
  218. lzma_match *matches,
  219. uint32_t len_best)
  220. {
  221. son[cyclic_pos] = cur_match;
  222. while (true) {
  223. const uint32_t delta = pos - cur_match;
  224. if (depth-- == 0 || delta >= cyclic_size)
  225. return matches;
  226. const uint8_t *const pb = cur - delta;
  227. cur_match = son[cyclic_pos - delta
  228. + (delta > cyclic_pos ? cyclic_size : 0)];
  229. if (pb[len_best] == cur[len_best] && pb[0] == cur[0]) {
  230. uint32_t len = lzma_memcmplen(pb, cur, 1, len_limit);
  231. if (len_best < len) {
  232. len_best = len;
  233. matches->len = len;
  234. matches->dist = delta - 1;
  235. ++matches;
  236. if (len == len_limit)
  237. return matches;
  238. }
  239. }
  240. }
  241. }
  242. #define hc_find(len_best) \
  243. call_find(hc_find_func, len_best)
  244. #define hc_skip() \
  245. do { \
  246. mf->son[mf->cyclic_pos] = cur_match; \
  247. move_pos(mf); \
  248. } while (0)
  249. #endif
  250. #ifdef HAVE_MF_HC3
  251. extern uint32_t
  252. lzma_mf_hc3_find(lzma_mf *mf, lzma_match *matches)
  253. {
  254. header_find(false, 3);
  255. hash_3_calc();
  256. const uint32_t delta2 = pos - mf->hash[hash_2_value];
  257. const uint32_t cur_match = mf->hash[FIX_3_HASH_SIZE + hash_value];
  258. mf->hash[hash_2_value] = pos;
  259. mf->hash[FIX_3_HASH_SIZE + hash_value] = pos;
  260. uint32_t len_best = 2;
  261. if (delta2 < mf->cyclic_size && *(cur - delta2) == *cur) {
  262. len_best = lzma_memcmplen(cur - delta2, cur,
  263. len_best, len_limit);
  264. matches[0].len = len_best;
  265. matches[0].dist = delta2 - 1;
  266. matches_count = 1;
  267. if (len_best == len_limit) {
  268. hc_skip();
  269. return 1; // matches_count
  270. }
  271. }
  272. hc_find(len_best);
  273. }
  274. extern void
  275. lzma_mf_hc3_skip(lzma_mf *mf, uint32_t amount)
  276. {
  277. do {
  278. if (mf_avail(mf) < 3) {
  279. move_pending(mf);
  280. continue;
  281. }
  282. const uint8_t *cur = mf_ptr(mf);
  283. const uint32_t pos = mf->read_pos + mf->offset;
  284. hash_3_calc();
  285. const uint32_t cur_match
  286. = mf->hash[FIX_3_HASH_SIZE + hash_value];
  287. mf->hash[hash_2_value] = pos;
  288. mf->hash[FIX_3_HASH_SIZE + hash_value] = pos;
  289. hc_skip();
  290. } while (--amount != 0);
  291. }
  292. #endif
  293. #ifdef HAVE_MF_HC4
  294. extern uint32_t
  295. lzma_mf_hc4_find(lzma_mf *mf, lzma_match *matches)
  296. {
  297. header_find(false, 4);
  298. hash_4_calc();
  299. uint32_t delta2 = pos - mf->hash[hash_2_value];
  300. const uint32_t delta3
  301. = pos - mf->hash[FIX_3_HASH_SIZE + hash_3_value];
  302. const uint32_t cur_match = mf->hash[FIX_4_HASH_SIZE + hash_value];
  303. mf->hash[hash_2_value ] = pos;
  304. mf->hash[FIX_3_HASH_SIZE + hash_3_value] = pos;
  305. mf->hash[FIX_4_HASH_SIZE + hash_value] = pos;
  306. uint32_t len_best = 1;
  307. if (delta2 < mf->cyclic_size && *(cur - delta2) == *cur) {
  308. len_best = 2;
  309. matches[0].len = 2;
  310. matches[0].dist = delta2 - 1;
  311. matches_count = 1;
  312. }
  313. if (delta2 != delta3 && delta3 < mf->cyclic_size
  314. && *(cur - delta3) == *cur) {
  315. len_best = 3;
  316. matches[matches_count++].dist = delta3 - 1;
  317. delta2 = delta3;
  318. }
  319. if (matches_count != 0) {
  320. len_best = lzma_memcmplen(cur - delta2, cur,
  321. len_best, len_limit);
  322. matches[matches_count - 1].len = len_best;
  323. if (len_best == len_limit) {
  324. hc_skip();
  325. return matches_count;
  326. }
  327. }
  328. if (len_best < 3)
  329. len_best = 3;
  330. hc_find(len_best);
  331. }
  332. extern void
  333. lzma_mf_hc4_skip(lzma_mf *mf, uint32_t amount)
  334. {
  335. do {
  336. if (mf_avail(mf) < 4) {
  337. move_pending(mf);
  338. continue;
  339. }
  340. const uint8_t *cur = mf_ptr(mf);
  341. const uint32_t pos = mf->read_pos + mf->offset;
  342. hash_4_calc();
  343. const uint32_t cur_match
  344. = mf->hash[FIX_4_HASH_SIZE + hash_value];
  345. mf->hash[hash_2_value] = pos;
  346. mf->hash[FIX_3_HASH_SIZE + hash_3_value] = pos;
  347. mf->hash[FIX_4_HASH_SIZE + hash_value] = pos;
  348. hc_skip();
  349. } while (--amount != 0);
  350. }
  351. #endif
  352. /////////////////
  353. // Binary Tree //
  354. /////////////////
  355. #if defined(HAVE_MF_BT2) || defined(HAVE_MF_BT3) || defined(HAVE_MF_BT4)
  356. static lzma_match *
  357. bt_find_func(
  358. const uint32_t len_limit,
  359. const uint32_t pos,
  360. const uint8_t *const cur,
  361. uint32_t cur_match,
  362. uint32_t depth,
  363. uint32_t *const son,
  364. const uint32_t cyclic_pos,
  365. const uint32_t cyclic_size,
  366. lzma_match *matches,
  367. uint32_t len_best)
  368. {
  369. uint32_t *ptr0 = son + (cyclic_pos << 1) + 1;
  370. uint32_t *ptr1 = son + (cyclic_pos << 1);
  371. uint32_t len0 = 0;
  372. uint32_t len1 = 0;
  373. while (true) {
  374. const uint32_t delta = pos - cur_match;
  375. if (depth-- == 0 || delta >= cyclic_size) {
  376. *ptr0 = EMPTY_HASH_VALUE;
  377. *ptr1 = EMPTY_HASH_VALUE;
  378. return matches;
  379. }
  380. uint32_t *const pair = son + ((cyclic_pos - delta
  381. + (delta > cyclic_pos ? cyclic_size : 0))
  382. << 1);
  383. const uint8_t *const pb = cur - delta;
  384. uint32_t len = my_min(len0, len1);
  385. if (pb[len] == cur[len]) {
  386. len = lzma_memcmplen(pb, cur, len + 1, len_limit);
  387. if (len_best < len) {
  388. len_best = len;
  389. matches->len = len;
  390. matches->dist = delta - 1;
  391. ++matches;
  392. if (len == len_limit) {
  393. *ptr1 = pair[0];
  394. *ptr0 = pair[1];
  395. return matches;
  396. }
  397. }
  398. }
  399. if (pb[len] < cur[len]) {
  400. *ptr1 = cur_match;
  401. ptr1 = pair + 1;
  402. cur_match = *ptr1;
  403. len1 = len;
  404. } else {
  405. *ptr0 = cur_match;
  406. ptr0 = pair;
  407. cur_match = *ptr0;
  408. len0 = len;
  409. }
  410. }
  411. }
  412. static void
  413. bt_skip_func(
  414. const uint32_t len_limit,
  415. const uint32_t pos,
  416. const uint8_t *const cur,
  417. uint32_t cur_match,
  418. uint32_t depth,
  419. uint32_t *const son,
  420. const uint32_t cyclic_pos,
  421. const uint32_t cyclic_size)
  422. {
  423. uint32_t *ptr0 = son + (cyclic_pos << 1) + 1;
  424. uint32_t *ptr1 = son + (cyclic_pos << 1);
  425. uint32_t len0 = 0;
  426. uint32_t len1 = 0;
  427. while (true) {
  428. const uint32_t delta = pos - cur_match;
  429. if (depth-- == 0 || delta >= cyclic_size) {
  430. *ptr0 = EMPTY_HASH_VALUE;
  431. *ptr1 = EMPTY_HASH_VALUE;
  432. return;
  433. }
  434. uint32_t *pair = son + ((cyclic_pos - delta
  435. + (delta > cyclic_pos ? cyclic_size : 0))
  436. << 1);
  437. const uint8_t *pb = cur - delta;
  438. uint32_t len = my_min(len0, len1);
  439. if (pb[len] == cur[len]) {
  440. len = lzma_memcmplen(pb, cur, len + 1, len_limit);
  441. if (len == len_limit) {
  442. *ptr1 = pair[0];
  443. *ptr0 = pair[1];
  444. return;
  445. }
  446. }
  447. if (pb[len] < cur[len]) {
  448. *ptr1 = cur_match;
  449. ptr1 = pair + 1;
  450. cur_match = *ptr1;
  451. len1 = len;
  452. } else {
  453. *ptr0 = cur_match;
  454. ptr0 = pair;
  455. cur_match = *ptr0;
  456. len0 = len;
  457. }
  458. }
  459. }
  460. #define bt_find(len_best) \
  461. call_find(bt_find_func, len_best)
  462. #define bt_skip() \
  463. do { \
  464. bt_skip_func(len_limit, pos, cur, cur_match, mf->depth, \
  465. mf->son, mf->cyclic_pos, \
  466. mf->cyclic_size); \
  467. move_pos(mf); \
  468. } while (0)
  469. #endif
  470. #ifdef HAVE_MF_BT2
  471. extern uint32_t
  472. lzma_mf_bt2_find(lzma_mf *mf, lzma_match *matches)
  473. {
  474. header_find(true, 2);
  475. hash_2_calc();
  476. const uint32_t cur_match = mf->hash[hash_value];
  477. mf->hash[hash_value] = pos;
  478. bt_find(1);
  479. }
  480. extern void
  481. lzma_mf_bt2_skip(lzma_mf *mf, uint32_t amount)
  482. {
  483. do {
  484. header_skip(true, 2);
  485. hash_2_calc();
  486. const uint32_t cur_match = mf->hash[hash_value];
  487. mf->hash[hash_value] = pos;
  488. bt_skip();
  489. } while (--amount != 0);
  490. }
  491. #endif
  492. #ifdef HAVE_MF_BT3
  493. extern uint32_t
  494. lzma_mf_bt3_find(lzma_mf *mf, lzma_match *matches)
  495. {
  496. header_find(true, 3);
  497. hash_3_calc();
  498. const uint32_t delta2 = pos - mf->hash[hash_2_value];
  499. const uint32_t cur_match = mf->hash[FIX_3_HASH_SIZE + hash_value];
  500. mf->hash[hash_2_value] = pos;
  501. mf->hash[FIX_3_HASH_SIZE + hash_value] = pos;
  502. uint32_t len_best = 2;
  503. if (delta2 < mf->cyclic_size && *(cur - delta2) == *cur) {
  504. len_best = lzma_memcmplen(
  505. cur, cur - delta2, len_best, len_limit);
  506. matches[0].len = len_best;
  507. matches[0].dist = delta2 - 1;
  508. matches_count = 1;
  509. if (len_best == len_limit) {
  510. bt_skip();
  511. return 1; // matches_count
  512. }
  513. }
  514. bt_find(len_best);
  515. }
  516. extern void
  517. lzma_mf_bt3_skip(lzma_mf *mf, uint32_t amount)
  518. {
  519. do {
  520. header_skip(true, 3);
  521. hash_3_calc();
  522. const uint32_t cur_match
  523. = mf->hash[FIX_3_HASH_SIZE + hash_value];
  524. mf->hash[hash_2_value] = pos;
  525. mf->hash[FIX_3_HASH_SIZE + hash_value] = pos;
  526. bt_skip();
  527. } while (--amount != 0);
  528. }
  529. #endif
  530. #ifdef HAVE_MF_BT4
  531. extern uint32_t
  532. lzma_mf_bt4_find(lzma_mf *mf, lzma_match *matches)
  533. {
  534. header_find(true, 4);
  535. hash_4_calc();
  536. uint32_t delta2 = pos - mf->hash[hash_2_value];
  537. const uint32_t delta3
  538. = pos - mf->hash[FIX_3_HASH_SIZE + hash_3_value];
  539. const uint32_t cur_match = mf->hash[FIX_4_HASH_SIZE + hash_value];
  540. mf->hash[hash_2_value] = pos;
  541. mf->hash[FIX_3_HASH_SIZE + hash_3_value] = pos;
  542. mf->hash[FIX_4_HASH_SIZE + hash_value] = pos;
  543. uint32_t len_best = 1;
  544. if (delta2 < mf->cyclic_size && *(cur - delta2) == *cur) {
  545. len_best = 2;
  546. matches[0].len = 2;
  547. matches[0].dist = delta2 - 1;
  548. matches_count = 1;
  549. }
  550. if (delta2 != delta3 && delta3 < mf->cyclic_size
  551. && *(cur - delta3) == *cur) {
  552. len_best = 3;
  553. matches[matches_count++].dist = delta3 - 1;
  554. delta2 = delta3;
  555. }
  556. if (matches_count != 0) {
  557. len_best = lzma_memcmplen(
  558. cur, cur - delta2, len_best, len_limit);
  559. matches[matches_count - 1].len = len_best;
  560. if (len_best == len_limit) {
  561. bt_skip();
  562. return matches_count;
  563. }
  564. }
  565. if (len_best < 3)
  566. len_best = 3;
  567. bt_find(len_best);
  568. }
  569. extern void
  570. lzma_mf_bt4_skip(lzma_mf *mf, uint32_t amount)
  571. {
  572. do {
  573. header_skip(true, 4);
  574. hash_4_calc();
  575. const uint32_t cur_match
  576. = mf->hash[FIX_4_HASH_SIZE + hash_value];
  577. mf->hash[hash_2_value] = pos;
  578. mf->hash[FIX_3_HASH_SIZE + hash_3_value] = pos;
  579. mf->hash[FIX_4_HASH_SIZE + hash_value] = pos;
  580. bt_skip();
  581. } while (--amount != 0);
  582. }
  583. #endif