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)
24 if (UNALIGNED_ACCESS_IS_FAST && CPU_IS_LITTLE_ENDIAN) {
26 machine_word_t v_word;
28 if (likely(max_len - len >= 4 * WORDSIZE)) {
30 #define COMPARE_WORD_STEP \
31 v_word = load_word_unaligned(&matchptr[len]) ^ \
32 load_word_unaligned(&strptr[len]); \
41 #undef COMPARE_WORD_STEP
44 while (len + WORDSIZE <= max_len) {
45 v_word = load_word_unaligned(&matchptr[len]) ^
46 load_word_unaligned(&strptr[len]);
52 while (len < max_len && matchptr[len] == strptr[len])
57 return len + (ffsw(v_word) >> 3);
59 while (len < max_len && matchptr[len] == strptr[len])
65 #endif /* _WIMLIB_LZ_EXTEND_H */