4 * Fast match extension for Lempel-Ziv matchfinding.
6 * The author dedicates this file to the public domain.
7 * You can do whatever you want with this file.
10 #ifndef _WIMLIB_LZ_EXTEND_H
11 #define _WIMLIB_LZ_EXTEND_H
13 #include "wimlib/bitops.h"
14 #include "wimlib/unaligned.h"
16 /* Return the number of bytes at @matchptr that match the bytes at @strptr, up
17 * to a maximum of @max_len. Initially, @start_len bytes are matched. */
19 lz_extend(const u8 * const strptr, const u8 * const matchptr,
20 const u32 start_len, const u32 max_len)
23 machine_word_t v_word;
25 if (UNALIGNED_ACCESS_IS_FAST) {
27 if (likely(max_len - len >= 4 * WORDSIZE)) {
29 #define COMPARE_WORD_STEP \
30 v_word = load_word_unaligned(&matchptr[len]) ^ \
31 load_word_unaligned(&strptr[len]); \
40 #undef COMPARE_WORD_STEP
43 while (len + WORDSIZE <= max_len) {
44 v_word = load_word_unaligned(&matchptr[len]) ^
45 load_word_unaligned(&strptr[len]);
52 while (len < max_len && matchptr[len] == strptr[len])
57 if (CPU_IS_LITTLE_ENDIAN)
58 len += (ffsw(v_word) >> 3);
60 len += (flsw(v_word) >> 3);
64 #endif /* _WIMLIB_LZ_EXTEND_H */