4 * Fast match extension for Lempel-Ziv matchfinding.
9 * The author dedicates this file to the public domain.
10 * You can do whatever you want with this file.
13 #ifndef _WIMLIB_LZ_EXTEND_H
14 #define _WIMLIB_LZ_EXTEND_H
16 #include "wimlib/bitops.h"
17 #include "wimlib/unaligned.h"
19 /* Return the number of bytes at @matchptr that match the bytes at @strptr, up
20 * to a maximum of @max_len. Initially, @start_len bytes are matched. */
22 lz_extend(const u8 * const strptr, const u8 * const matchptr,
23 const u32 start_len, const u32 max_len)
26 machine_word_t v_word;
28 if (UNALIGNED_ACCESS_IS_FAST) {
30 if (likely(max_len - len >= 4 * WORDSIZE)) {
32 #define COMPARE_WORD_STEP \
33 v_word = load_word_unaligned(&matchptr[len]) ^ \
34 load_word_unaligned(&strptr[len]); \
43 #undef COMPARE_WORD_STEP
46 while (len + WORDSIZE <= max_len) {
47 v_word = load_word_unaligned(&matchptr[len]) ^
48 load_word_unaligned(&strptr[len]);
55 while (len < max_len && matchptr[len] == strptr[len])
60 if (CPU_IS_LITTLE_ENDIAN)
61 len += (ffsw(v_word) >> 3);
63 len += (flsw(v_word) >> 3);
67 #endif /* _WIMLIB_LZ_EXTEND_H */