1 ///////////////////////////////////////////////////////////////////////////////
3 /// \file lz_encoder_hash.h
4 /// \brief Hash macros for match finders
8 // This file has been put into the public domain.
9 // You can do whatever you want with this file.
11 ///////////////////////////////////////////////////////////////////////////////
13 #ifndef LZMA_LZ_ENCODER_HASH_H
14 #define LZMA_LZ_ENCODER_HASH_H
16 #define HASH_2_SIZE (UINT32_C(1) << 10)
17 #define HASH_3_SIZE (UINT32_C(1) << 16)
18 #define HASH_4_SIZE (UINT32_C(1) << 20)
20 #define HASH_2_MASK (HASH_2_SIZE - 1)
21 #define HASH_3_MASK (HASH_3_SIZE - 1)
22 #define HASH_4_MASK (HASH_4_SIZE - 1)
24 #define FIX_3_HASH_SIZE (HASH_2_SIZE)
25 #define FIX_4_HASH_SIZE (HASH_2_SIZE + HASH_3_SIZE)
26 #define FIX_5_HASH_SIZE (HASH_2_SIZE + HASH_3_SIZE + HASH_4_SIZE)
28 // TODO Benchmark, and probably doesn't need to be endian dependent.
29 #if !defined(WORDS_BIGENDIAN) && defined(HAVE_FAST_UNALIGNED_ACCESS)
30 # define hash_2_calc() \
31 const uint32_t hash_value = *(const uint16_t *)(cur);
33 # define hash_2_calc() \
34 const uint32_t hash_value \
35 = (uint32_t)(cur[0]) | ((uint32_t)(cur[1]) << 8)
38 #define hash_3_calc() \
39 const uint32_t temp = lzma_crc32_table[0][cur[0]] ^ cur[1]; \
40 const uint32_t hash_2_value = temp & HASH_2_MASK; \
41 const uint32_t hash_value \
42 = (temp ^ ((uint32_t)(cur[2]) << 8)) & mf->hash_mask
44 #define hash_4_calc() \
45 const uint32_t temp = lzma_crc32_table[0][cur[0]] ^ cur[1]; \
46 const uint32_t hash_2_value = temp & HASH_2_MASK; \
47 const uint32_t hash_3_value \
48 = (temp ^ ((uint32_t)(cur[2]) << 8)) & HASH_3_MASK; \
49 const uint32_t hash_value = (temp ^ ((uint32_t)(cur[2]) << 8) \
50 ^ (lzma_crc32_table[0][cur[3]] << 5)) & mf->hash_mask
53 // The following are not currently used.
55 #define hash_5_calc() \
56 const uint32_t temp = lzma_crc32_table[0][cur[0]] ^ cur[1]; \
57 const uint32_t hash_2_value = temp & HASH_2_MASK; \
58 const uint32_t hash_3_value \
59 = (temp ^ ((uint32_t)(cur[2]) << 8)) & HASH_3_MASK; \
60 uint32_t hash_4_value = (temp ^ ((uint32_t)(cur[2]) << 8) ^ \
61 ^ lzma_crc32_table[0][cur[3]] << 5); \
62 const uint32_t hash_value \
63 = (hash_4_value ^ (lzma_crc32_table[0][cur[4]] << 3)) \
65 hash_4_value &= HASH_4_MASK
68 #define hash_zip_calc() \
69 const uint32_t hash_value \
70 = (((uint32_t)(cur[0]) | ((uint32_t)(cur[1]) << 8)) \
71 ^ lzma_crc32_table[0][cur[2]]) & 0xFFFF
74 #define hash_zip_calc() \
75 const uint32_t hash_value \
76 = (((uint32_t)(cur[2]) | ((uint32_t)(cur[0]) << 8)) \
77 ^ lzma_crc32_table[0][cur[1]]) & 0xFFFF
79 #define mt_hash_2_calc() \
80 const uint32_t hash_2_value \
81 = (lzma_crc32_table[0][cur[0]] ^ cur[1]) & HASH_2_MASK
83 #define mt_hash_3_calc() \
84 const uint32_t temp = lzma_crc32_table[0][cur[0]] ^ cur[1]; \
85 const uint32_t hash_2_value = temp & HASH_2_MASK; \
86 const uint32_t hash_3_value \
87 = (temp ^ ((uint32_t)(cur[2]) << 8)) & HASH_3_MASK
89 #define mt_hash_4_calc() \
90 const uint32_t temp = lzma_crc32_table[0][cur[0]] ^ cur[1]; \
91 const uint32_t hash_2_value = temp & HASH_2_MASK; \
92 const uint32_t hash_3_value \
93 = (temp ^ ((uint32_t)(cur[2]) << 8)) & HASH_3_MASK; \
94 const uint32_t hash_4_value = (temp ^ ((uint32_t)(cur[2]) << 8) ^ \
95 (lzma_crc32_table[0][cur[3]] << 5)) & HASH_4_MASK