X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=include%2Fwimlib%2Flz_extend.h;h=7d7cd05bd651dc0f944e3d1017c22f00962df86a;hb=98a8f6bb9e7b3b62d87cb4b36501818b1a14df5e;hp=e9a56224ea0768104838576815c43d58179bf545;hpb=0ecb0529b5fcacc1abafa1f3f02a40c44783ada8;p=wimlib diff --git a/include/wimlib/lz_extend.h b/include/wimlib/lz_extend.h index e9a56224..7d7cd05b 100644 --- a/include/wimlib/lz_extend.h +++ b/include/wimlib/lz_extend.h @@ -3,6 +3,9 @@ * * Fast match extension for Lempel-Ziv matchfinding. * + * Author: Eric Biggers + * Year: 2014, 2015 + * * The author dedicates this file to the public domain. * You can do whatever you want with this file. */ @@ -20,11 +23,10 @@ lz_extend(const u8 * const strptr, const u8 * const matchptr, const u32 start_len, const u32 max_len) { u32 len = start_len; + machine_word_t v_word; if (UNALIGNED_ACCESS_IS_FAST) { - machine_word_t v_word; - if (likely(max_len - len >= 4 * WORDSIZE)) { #define COMPARE_WORD_STEP \ @@ -48,18 +50,18 @@ lz_extend(const u8 * const strptr, const u8 * const matchptr, goto word_differs; len += WORDSIZE; } + } - while (len < max_len && matchptr[len] == strptr[len]) - len++; - return len; + while (len < max_len && matchptr[len] == strptr[len]) + len++; + return len; - word_differs: - return len + (ffsw(v_word) >> 3); - } else { - while (len < max_len && matchptr[len] == strptr[len]) - len++; - return len; - } +word_differs: + if (CPU_IS_LITTLE_ENDIAN) + len += (ffsw(v_word) >> 3); + else + len += (8 * WORDSIZE - 1 - flsw(v_word)) >> 3; + return len; } #endif /* _WIMLIB_LZ_EXTEND_H */