Path: blob/master/Utilities/cmliblzma/liblzma/lz/lz_encoder_hash.h
3156 views
// SPDX-License-Identifier: 0BSD12///////////////////////////////////////////////////////////////////////////////3//4/// \file lz_encoder_hash.h5/// \brief Hash macros for match finders6//7// Author: Igor Pavlov8//9///////////////////////////////////////////////////////////////////////////////1011#ifndef LZMA_LZ_ENCODER_HASH_H12#define LZMA_LZ_ENCODER_HASH_H1314#if defined(WORDS_BIGENDIAN) && !defined(HAVE_SMALL)15// This is to make liblzma produce the same output on big endian16// systems that it does on little endian systems. lz_encoder.c17// takes care of including the actual table.18lzma_attr_visibility_hidden19extern const uint32_t lzma_lz_hash_table[256];20# define hash_table lzma_lz_hash_table21#else22# include "check.h"23# define hash_table lzma_crc32_table[0]24#endif2526#define HASH_2_SIZE (UINT32_C(1) << 10)27#define HASH_3_SIZE (UINT32_C(1) << 16)28#define HASH_4_SIZE (UINT32_C(1) << 20)2930#define HASH_2_MASK (HASH_2_SIZE - 1)31#define HASH_3_MASK (HASH_3_SIZE - 1)32#define HASH_4_MASK (HASH_4_SIZE - 1)3334#define FIX_3_HASH_SIZE (HASH_2_SIZE)35#define FIX_4_HASH_SIZE (HASH_2_SIZE + HASH_3_SIZE)36#define FIX_5_HASH_SIZE (HASH_2_SIZE + HASH_3_SIZE + HASH_4_SIZE)3738// Endianness doesn't matter in hash_2_calc() (no effect on the output).39#ifdef TUKLIB_FAST_UNALIGNED_ACCESS40# define hash_2_calc() \41const uint32_t hash_value = read16ne(cur)42#else43# define hash_2_calc() \44const uint32_t hash_value \45= (uint32_t)(cur[0]) | ((uint32_t)(cur[1]) << 8)46#endif4748#define hash_3_calc() \49const uint32_t temp = hash_table[cur[0]] ^ cur[1]; \50const uint32_t hash_2_value = temp & HASH_2_MASK; \51const uint32_t hash_value \52= (temp ^ ((uint32_t)(cur[2]) << 8)) & mf->hash_mask5354#define hash_4_calc() \55const uint32_t temp = hash_table[cur[0]] ^ cur[1]; \56const uint32_t hash_2_value = temp & HASH_2_MASK; \57const uint32_t hash_3_value \58= (temp ^ ((uint32_t)(cur[2]) << 8)) & HASH_3_MASK; \59const uint32_t hash_value = (temp ^ ((uint32_t)(cur[2]) << 8) \60^ (hash_table[cur[3]] << 5)) & mf->hash_mask616263// The following are not currently used.6465#define hash_5_calc() \66const uint32_t temp = hash_table[cur[0]] ^ cur[1]; \67const uint32_t hash_2_value = temp & HASH_2_MASK; \68const uint32_t hash_3_value \69= (temp ^ ((uint32_t)(cur[2]) << 8)) & HASH_3_MASK; \70uint32_t hash_4_value = (temp ^ ((uint32_t)(cur[2]) << 8) ^ \71^ hash_table[cur[3]] << 5); \72const uint32_t hash_value \73= (hash_4_value ^ (hash_table[cur[4]] << 3)) \74& mf->hash_mask; \75hash_4_value &= HASH_4_MASK7677/*78#define hash_zip_calc() \79const uint32_t hash_value \80= (((uint32_t)(cur[0]) | ((uint32_t)(cur[1]) << 8)) \81^ hash_table[cur[2]]) & 0xFFFF82*/8384#define hash_zip_calc() \85const uint32_t hash_value \86= (((uint32_t)(cur[2]) | ((uint32_t)(cur[0]) << 8)) \87^ hash_table[cur[1]]) & 0xFFFF8889#define mt_hash_2_calc() \90const uint32_t hash_2_value \91= (hash_table[cur[0]] ^ cur[1]) & HASH_2_MASK9293#define mt_hash_3_calc() \94const uint32_t temp = hash_table[cur[0]] ^ cur[1]; \95const uint32_t hash_2_value = temp & HASH_2_MASK; \96const uint32_t hash_3_value \97= (temp ^ ((uint32_t)(cur[2]) << 8)) & HASH_3_MASK9899#define mt_hash_4_calc() \100const uint32_t temp = hash_table[cur[0]] ^ cur[1]; \101const uint32_t hash_2_value = temp & HASH_2_MASK; \102const uint32_t hash_3_value \103= (temp ^ ((uint32_t)(cur[2]) << 8)) & HASH_3_MASK; \104const uint32_t hash_4_value = (temp ^ ((uint32_t)(cur[2]) << 8) ^ \105(hash_table[cur[3]] << 5)) & HASH_4_MASK106107#endif108109110