mirror of
https://github.com/cuberite/libdeflate.git
synced 2025-09-10 12:58:30 -04:00
Move lz_extend() into matchfinder_common.h
This commit is contained in:
parent
bbf9eb753d
commit
0698e895a1
@ -47,7 +47,6 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "matchfinder_common.h"
|
#include "matchfinder_common.h"
|
||||||
#include "lz_extend.h"
|
|
||||||
|
|
||||||
#define BT_MATCHFINDER_HASH3_ORDER 15
|
#define BT_MATCHFINDER_HASH3_ORDER 15
|
||||||
#define BT_MATCHFINDER_HASH3_WAYS 1
|
#define BT_MATCHFINDER_HASH3_WAYS 1
|
||||||
|
@ -87,9 +87,7 @@
|
|||||||
* ----------------------------------------------------------------------------
|
* ----------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "lz_extend.h"
|
|
||||||
#include "matchfinder_common.h"
|
#include "matchfinder_common.h"
|
||||||
#include "unaligned.h"
|
|
||||||
|
|
||||||
#define HC_MATCHFINDER_HASH3_ORDER 15
|
#define HC_MATCHFINDER_HASH3_ORDER 15
|
||||||
#define HC_MATCHFINDER_HASH4_ORDER 16
|
#define HC_MATCHFINDER_HASH4_ORDER 16
|
||||||
|
@ -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;
|
|
||||||
}
|
|
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "bitops.h"
|
||||||
|
#include "unaligned.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#ifndef MATCHFINDER_WINDOW_ORDER
|
#ifndef MATCHFINDER_WINDOW_ORDER
|
||||||
@ -131,3 +133,53 @@ lz_hash(u32 seq, unsigned num_bits)
|
|||||||
{
|
{
|
||||||
return (u32)(seq * 0x1E35A7BD) >> (32 - 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;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user