Commit 3334c367 for xz

commit 3334c36726911f4df5d91c1319036fd9fd282786
Author: Lasse Collin <lasse.collin@tukaani.org>
Date:   Mon Nov 23 18:02:48 2026 +0200

    liblzma: Prefetch the next position's hash buckets

    This is for HC3, HC4, BT3, and BT4. This can reduce encoding time by
    a couple of percent.

    Co-authored-by: Yousef Mahmoud <yosefkhalil610@gmail.com>
    Closes: https://github.com/tukaani-project/xz/pull/247

diff --git a/src/liblzma/lz/lz_encoder_mf.c b/src/liblzma/lz/lz_encoder_mf.c
index 557c2612..2013e05b 100644
--- a/src/liblzma/lz/lz_encoder_mf.c
+++ b/src/liblzma/lz/lz_encoder_mf.c
@@ -314,6 +314,8 @@ lzma_mf_hc3_find(lzma_mf *mf, lzma_match *matches)
 	mf->hash[hash_2_value] = pos;
 	mf->hash[FIX_3_HASH_SIZE + hash_value] = pos;

+	hash_3_prefetch();
+
 	uint32_t len_best = 2;

 	if (delta2 < mf->cyclic_size && *(cur - delta2) == *cur) {
@@ -354,6 +356,8 @@ lzma_mf_hc3_skip(lzma_mf *mf, uint32_t amount)
 		mf->hash[hash_2_value] = pos;
 		mf->hash[FIX_3_HASH_SIZE + hash_value] = pos;

+		hash_3_prefetch();
+
 		hc_skip();

 	} while (--amount != 0);
@@ -378,6 +382,8 @@ lzma_mf_hc4_find(lzma_mf *mf, lzma_match *matches)
 	mf->hash[FIX_3_HASH_SIZE + hash_3_value] = pos;
 	mf->hash[FIX_4_HASH_SIZE + hash_value] = pos;

+	hash_4_prefetch();
+
 	uint32_t len_best = 1;

 	if (delta2 < mf->cyclic_size && *(cur - delta2) == *cur) {
@@ -434,6 +440,8 @@ lzma_mf_hc4_skip(lzma_mf *mf, uint32_t amount)
 		mf->hash[FIX_3_HASH_SIZE + hash_3_value] = pos;
 		mf->hash[FIX_4_HASH_SIZE + hash_value] = pos;

+		hash_4_prefetch();
+
 		hc_skip();

 	} while (--amount != 0);
@@ -629,6 +637,8 @@ lzma_mf_bt3_find(lzma_mf *mf, lzma_match *matches)
 	mf->hash[hash_2_value] = pos;
 	mf->hash[FIX_3_HASH_SIZE + hash_value] = pos;

+	hash_3_prefetch();
+
 	uint32_t len_best = 2;

 	if (delta2 < mf->cyclic_size && *(cur - delta2) == *cur) {
@@ -663,6 +673,8 @@ lzma_mf_bt3_skip(lzma_mf *mf, uint32_t amount)
 		mf->hash[hash_2_value] = pos;
 		mf->hash[FIX_3_HASH_SIZE + hash_value] = pos;

+		hash_3_prefetch();
+
 		bt_skip();

 	} while (--amount != 0);
@@ -687,6 +699,8 @@ lzma_mf_bt4_find(lzma_mf *mf, lzma_match *matches)
 	mf->hash[FIX_3_HASH_SIZE + hash_3_value] = pos;
 	mf->hash[FIX_4_HASH_SIZE + hash_value] = pos;

+	hash_4_prefetch();
+
 	uint32_t len_best = 1;

 	if (delta2 < mf->cyclic_size && *(cur - delta2) == *cur) {
@@ -737,6 +751,8 @@ lzma_mf_bt4_skip(lzma_mf *mf, uint32_t amount)
 		mf->hash[FIX_3_HASH_SIZE + hash_3_value] = pos;
 		mf->hash[FIX_4_HASH_SIZE + hash_value] = pos;

+		hash_4_prefetch();
+
 		bt_skip();

 	} while (--amount != 0);