xz/src/liblzma/lz/lz_encoder_hash.h

105 lines
3.6 KiB
C
Raw Normal View History

///////////////////////////////////////////////////////////////////////////////
//
/// \file lz_encoder_hash.h
/// \brief Hash macros for match finders
//
// Copyright (C) 1999-2008 Igor Pavlov
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef LZMA_LZ_ENCODER_HASH_H
#define LZMA_LZ_ENCODER_HASH_H
#define HASH_2_SIZE (UINT32_C(1) << 10)
#define HASH_3_SIZE (UINT32_C(1) << 16)
#define HASH_4_SIZE (UINT32_C(1) << 20)
#define HASH_2_MASK (HASH_2_SIZE - 1)
#define HASH_3_MASK (HASH_3_SIZE - 1)
#define HASH_4_MASK (HASH_4_SIZE - 1)
#define FIX_3_HASH_SIZE (HASH_2_SIZE)
#define FIX_4_HASH_SIZE (HASH_2_SIZE + HASH_3_SIZE)
#define FIX_5_HASH_SIZE (HASH_2_SIZE + HASH_3_SIZE + HASH_4_SIZE)
// TODO Benchmark, and probably doesn't need to be endian dependent.
#if !defined(WORDS_BIGENDIAN) && defined(HAVE_FAST_UNALIGNED_ACCESS)
# define hash_2_calc() \
const uint32_t hash_value = *(const uint16_t *)(cur);
#else
# define hash_2_calc() \
const uint32_t hash_value \
= (uint32_t)(cur[0]) | ((uint32_t)(cur[1]) << 8)
#endif
#define hash_3_calc() \
const uint32_t temp = lzma_crc32_table[0][cur[0]] ^ cur[1]; \
const uint32_t hash_2_value = temp & HASH_2_MASK; \
const uint32_t hash_value \
= (temp ^ ((uint32_t)(cur[2]) << 8)) & mf->hash_mask
#define hash_4_calc() \
const uint32_t temp = lzma_crc32_table[0][cur[0]] ^ cur[1]; \
const uint32_t hash_2_value = temp & HASH_2_MASK; \
const uint32_t hash_3_value \
= (temp ^ ((uint32_t)(cur[2]) << 8)) & HASH_3_MASK; \
const uint32_t hash_value = (temp ^ ((uint32_t)(cur[2]) << 8) \
^ (lzma_crc32_table[0][cur[3]] << 5)) & mf->hash_mask
// The following are not currently used.
#define hash_5_calc() \
const uint32_t temp = lzma_crc32_table[0][cur[0]] ^ cur[1]; \
const uint32_t hash_2_value = temp & HASH_2_MASK; \
const uint32_t hash_3_value \
= (temp ^ ((uint32_t)(cur[2]) << 8)) & HASH_3_MASK; \
uint32_t hash_4_value = (temp ^ ((uint32_t)(cur[2]) << 8) ^ \
^ lzma_crc32_table[0][cur[3]] << 5); \
const uint32_t hash_value \
= (hash_4_value ^ (lzma_crc32_table[0][cur[4]] << 3)) \
& mf->hash_mask; \
hash_4_value &= HASH_4_MASK
/*
#define hash_zip_calc() \
const uint32_t hash_value \
= (((uint32_t)(cur[0]) | ((uint32_t)(cur[1]) << 8)) \
^ lzma_crc32_table[0][cur[2]]) & 0xFFFF
*/
#define hash_zip_calc() \
const uint32_t hash_value \
= (((uint32_t)(cur[2]) | ((uint32_t)(cur[0]) << 8)) \
^ lzma_crc32_table[0][cur[1]]) & 0xFFFF
#define mt_hash_2_calc() \
const uint32_t hash_2_value \
= (lzma_crc32_table[0][cur[0]] ^ cur[1]) & HASH_2_MASK
#define mt_hash_3_calc() \
const uint32_t temp = lzma_crc32_table[0][cur[0]] ^ cur[1]; \
const uint32_t hash_2_value = temp & HASH_2_MASK; \
const uint32_t hash_3_value \
= (temp ^ ((uint32_t)(cur[2]) << 8)) & HASH_3_MASK
#define mt_hash_4_calc() \
const uint32_t temp = lzma_crc32_table[0][cur[0]] ^ cur[1]; \
const uint32_t hash_2_value = temp & HASH_2_MASK; \
const uint32_t hash_3_value \
= (temp ^ ((uint32_t)(cur[2]) << 8)) & HASH_3_MASK; \
const uint32_t hash_4_value = (temp ^ ((uint32_t)(cur[2]) << 8) ^ \
(lzma_crc32_table[0][cur[3]] << 5)) & HASH_4_MASK
#endif