Move lz_extend() into matchfinder_common.h

This commit is contained in:
Eric Biggers 2015-11-22 11:03:29 -06:00
parent bbf9eb753d
commit 0698e895a1
4 changed files with 52 additions and 61 deletions

View File

@ -47,7 +47,6 @@
#include "matchfinder_common.h"
#include "lz_extend.h"
#define BT_MATCHFINDER_HASH3_ORDER 15
#define BT_MATCHFINDER_HASH3_WAYS 1

View File

@ -87,9 +87,7 @@
* ----------------------------------------------------------------------------
*/
#include "lz_extend.h"
#include "matchfinder_common.h"
#include "unaligned.h"
#define HC_MATCHFINDER_HASH3_ORDER 15
#define HC_MATCHFINDER_HASH4_ORDER 16

View File

@ -1,58 +0,0 @@
/*
* lz_extend.h - fast match extension for Lempel-Ziv matchfinding
*/
#pragma once
#include "bitops.h"
#include "unaligned.h"
/*
* Return the number of bytes at @matchptr that match the bytes at @strptr, up
* to a maximum of @max_len. Initially, @start_len bytes are matched.
*/
static forceinline unsigned
lz_extend(const u8 * const strptr, const u8 * const matchptr,
const unsigned start_len, const unsigned max_len)
{
unsigned len = start_len;
machine_word_t v_word;
if (UNALIGNED_ACCESS_IS_FAST) {
if (likely(max_len - len >= 4 * WORDSIZE)) {
#define COMPARE_WORD_STEP \
v_word = load_word_unaligned(&matchptr[len]) ^ \
load_word_unaligned(&strptr[len]); \
if (v_word != 0) \
goto word_differs; \
len += WORDSIZE; \
COMPARE_WORD_STEP
COMPARE_WORD_STEP
COMPARE_WORD_STEP
COMPARE_WORD_STEP
#undef COMPARE_WORD_STEP
}
while (len + WORDSIZE <= max_len) {
v_word = load_word_unaligned(&matchptr[len]) ^
load_word_unaligned(&strptr[len]);
if (v_word != 0)
goto word_differs;
len += WORDSIZE;
}
}
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 += (flsw(v_word) >> 3);
return len;
}

View File

@ -4,6 +4,8 @@
#pragma once
#include "bitops.h"
#include "unaligned.h"
#include "util.h"
#ifndef MATCHFINDER_WINDOW_ORDER
@ -131,3 +133,53 @@ lz_hash(u32 seq, unsigned num_bits)
{
return (u32)(seq * 0x1E35A7BD) >> (32 - num_bits);
}
/*
* Return the number of bytes at @matchptr that match the bytes at @strptr, up
* to a maximum of @max_len. Initially, @start_len bytes are matched.
*/
static forceinline unsigned
lz_extend(const u8 * const strptr, const u8 * const matchptr,
const unsigned start_len, const unsigned max_len)
{
unsigned len = start_len;
machine_word_t v_word;
if (UNALIGNED_ACCESS_IS_FAST) {
if (likely(max_len - len >= 4 * WORDSIZE)) {
#define COMPARE_WORD_STEP \
v_word = load_word_unaligned(&matchptr[len]) ^ \
load_word_unaligned(&strptr[len]); \
if (v_word != 0) \
goto word_differs; \
len += WORDSIZE; \
COMPARE_WORD_STEP
COMPARE_WORD_STEP
COMPARE_WORD_STEP
COMPARE_WORD_STEP
#undef COMPARE_WORD_STEP
}
while (len + WORDSIZE <= max_len) {
v_word = load_word_unaligned(&matchptr[len]) ^
load_word_unaligned(&strptr[len]);
if (v_word != 0)
goto word_differs;
len += WORDSIZE;
}
}
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 += (flsw(v_word) >> 3);
return len;
}