12940b44dSPeter Avalos /////////////////////////////////////////////////////////////////////////////// 22940b44dSPeter Avalos // 32940b44dSPeter Avalos /// \file lz_encoder_hash.h 42940b44dSPeter Avalos /// \brief Hash macros for match finders 52940b44dSPeter Avalos // 62940b44dSPeter Avalos // Author: Igor Pavlov 72940b44dSPeter Avalos // 82940b44dSPeter Avalos // This file has been put into the public domain. 92940b44dSPeter Avalos // You can do whatever you want with this file. 102940b44dSPeter Avalos // 112940b44dSPeter Avalos /////////////////////////////////////////////////////////////////////////////// 122940b44dSPeter Avalos 132940b44dSPeter Avalos #ifndef LZMA_LZ_ENCODER_HASH_H 142940b44dSPeter Avalos #define LZMA_LZ_ENCODER_HASH_H 152940b44dSPeter Avalos 162940b44dSPeter Avalos #if defined(WORDS_BIGENDIAN) && !defined(HAVE_SMALL) 172940b44dSPeter Avalos // This is to make liblzma produce the same output on big endian 182940b44dSPeter Avalos // systems that it does on little endian systems. lz_encoder.c 192940b44dSPeter Avalos // takes care of including the actual table. 202940b44dSPeter Avalos extern const uint32_t lzma_lz_hash_table[256]; 212940b44dSPeter Avalos # define hash_table lzma_lz_hash_table 222940b44dSPeter Avalos #else 232940b44dSPeter Avalos # include "check.h" 242940b44dSPeter Avalos # define hash_table lzma_crc32_table[0] 252940b44dSPeter Avalos #endif 262940b44dSPeter Avalos 272940b44dSPeter Avalos #define HASH_2_SIZE (UINT32_C(1) << 10) 282940b44dSPeter Avalos #define HASH_3_SIZE (UINT32_C(1) << 16) 292940b44dSPeter Avalos #define HASH_4_SIZE (UINT32_C(1) << 20) 302940b44dSPeter Avalos 312940b44dSPeter Avalos #define HASH_2_MASK (HASH_2_SIZE - 1) 322940b44dSPeter Avalos #define HASH_3_MASK (HASH_3_SIZE - 1) 332940b44dSPeter Avalos #define HASH_4_MASK (HASH_4_SIZE - 1) 342940b44dSPeter Avalos 352940b44dSPeter Avalos #define FIX_3_HASH_SIZE (HASH_2_SIZE) 362940b44dSPeter Avalos #define FIX_4_HASH_SIZE (HASH_2_SIZE + HASH_3_SIZE) 372940b44dSPeter Avalos #define FIX_5_HASH_SIZE (HASH_2_SIZE + HASH_3_SIZE + HASH_4_SIZE) 382940b44dSPeter Avalos 392940b44dSPeter Avalos // Endianness doesn't matter in hash_2_calc() (no effect on the output). 402940b44dSPeter Avalos #ifdef TUKLIB_FAST_UNALIGNED_ACCESS 412940b44dSPeter Avalos # define hash_2_calc() \ 42*e151908bSDaniel Fojt const uint32_t hash_value = read16ne(cur) 432940b44dSPeter Avalos #else 442940b44dSPeter Avalos # define hash_2_calc() \ 452940b44dSPeter Avalos const uint32_t hash_value \ 462940b44dSPeter Avalos = (uint32_t)(cur[0]) | ((uint32_t)(cur[1]) << 8) 472940b44dSPeter Avalos #endif 482940b44dSPeter Avalos 492940b44dSPeter Avalos #define hash_3_calc() \ 502940b44dSPeter Avalos const uint32_t temp = hash_table[cur[0]] ^ cur[1]; \ 512940b44dSPeter Avalos const uint32_t hash_2_value = temp & HASH_2_MASK; \ 522940b44dSPeter Avalos const uint32_t hash_value \ 532940b44dSPeter Avalos = (temp ^ ((uint32_t)(cur[2]) << 8)) & mf->hash_mask 542940b44dSPeter Avalos 552940b44dSPeter Avalos #define hash_4_calc() \ 562940b44dSPeter Avalos const uint32_t temp = hash_table[cur[0]] ^ cur[1]; \ 572940b44dSPeter Avalos const uint32_t hash_2_value = temp & HASH_2_MASK; \ 582940b44dSPeter Avalos const uint32_t hash_3_value \ 592940b44dSPeter Avalos = (temp ^ ((uint32_t)(cur[2]) << 8)) & HASH_3_MASK; \ 602940b44dSPeter Avalos const uint32_t hash_value = (temp ^ ((uint32_t)(cur[2]) << 8) \ 612940b44dSPeter Avalos ^ (hash_table[cur[3]] << 5)) & mf->hash_mask 622940b44dSPeter Avalos 632940b44dSPeter Avalos 642940b44dSPeter Avalos // The following are not currently used. 652940b44dSPeter Avalos 662940b44dSPeter Avalos #define hash_5_calc() \ 672940b44dSPeter Avalos const uint32_t temp = hash_table[cur[0]] ^ cur[1]; \ 682940b44dSPeter Avalos const uint32_t hash_2_value = temp & HASH_2_MASK; \ 692940b44dSPeter Avalos const uint32_t hash_3_value \ 702940b44dSPeter Avalos = (temp ^ ((uint32_t)(cur[2]) << 8)) & HASH_3_MASK; \ 712940b44dSPeter Avalos uint32_t hash_4_value = (temp ^ ((uint32_t)(cur[2]) << 8) ^ \ 722940b44dSPeter Avalos ^ hash_table[cur[3]] << 5); \ 732940b44dSPeter Avalos const uint32_t hash_value \ 742940b44dSPeter Avalos = (hash_4_value ^ (hash_table[cur[4]] << 3)) \ 752940b44dSPeter Avalos & mf->hash_mask; \ 762940b44dSPeter Avalos hash_4_value &= HASH_4_MASK 772940b44dSPeter Avalos 782940b44dSPeter Avalos /* 792940b44dSPeter Avalos #define hash_zip_calc() \ 802940b44dSPeter Avalos const uint32_t hash_value \ 812940b44dSPeter Avalos = (((uint32_t)(cur[0]) | ((uint32_t)(cur[1]) << 8)) \ 822940b44dSPeter Avalos ^ hash_table[cur[2]]) & 0xFFFF 832940b44dSPeter Avalos */ 842940b44dSPeter Avalos 852940b44dSPeter Avalos #define hash_zip_calc() \ 862940b44dSPeter Avalos const uint32_t hash_value \ 872940b44dSPeter Avalos = (((uint32_t)(cur[2]) | ((uint32_t)(cur[0]) << 8)) \ 882940b44dSPeter Avalos ^ hash_table[cur[1]]) & 0xFFFF 892940b44dSPeter Avalos 902940b44dSPeter Avalos #define mt_hash_2_calc() \ 912940b44dSPeter Avalos const uint32_t hash_2_value \ 922940b44dSPeter Avalos = (hash_table[cur[0]] ^ cur[1]) & HASH_2_MASK 932940b44dSPeter Avalos 942940b44dSPeter Avalos #define mt_hash_3_calc() \ 952940b44dSPeter Avalos const uint32_t temp = hash_table[cur[0]] ^ cur[1]; \ 962940b44dSPeter Avalos const uint32_t hash_2_value = temp & HASH_2_MASK; \ 972940b44dSPeter Avalos const uint32_t hash_3_value \ 982940b44dSPeter Avalos = (temp ^ ((uint32_t)(cur[2]) << 8)) & HASH_3_MASK 992940b44dSPeter Avalos 1002940b44dSPeter Avalos #define mt_hash_4_calc() \ 1012940b44dSPeter Avalos const uint32_t temp = hash_table[cur[0]] ^ cur[1]; \ 1022940b44dSPeter Avalos const uint32_t hash_2_value = temp & HASH_2_MASK; \ 1032940b44dSPeter Avalos const uint32_t hash_3_value \ 1042940b44dSPeter Avalos = (temp ^ ((uint32_t)(cur[2]) << 8)) & HASH_3_MASK; \ 1052940b44dSPeter Avalos const uint32_t hash_4_value = (temp ^ ((uint32_t)(cur[2]) << 8) ^ \ 1062940b44dSPeter Avalos (hash_table[cur[3]] << 5)) & HASH_4_MASK 1072940b44dSPeter Avalos 1082940b44dSPeter Avalos #endif 109