aboutsummaryrefslogtreecommitdiff
path: root/src/liblzma/lz/lz_encoder_hash.h
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2009-10-02 11:03:26 +0300
committerLasse Collin <lasse.collin@tukaani.org>2009-10-02 11:03:26 +0300
commitc5f68b5cc79085a87f950fea53843e27f328068e (patch)
tree3de2840a1ac485bdb6b440a4f6236659f7962d8b /src/liblzma/lz/lz_encoder_hash.h
parentadd lzmainfo to gitignore (diff)
downloadxz-c5f68b5cc79085a87f950fea53843e27f328068e.tar.xz
Make liblzma produce the same output on both endiannesses.
Seems that it is a problem in some cases if the same version of XZ Utils produces different output on different endiannesses, so this commit fixes that problem. The output will still vary between different XZ Utils versions, but I cannot avoid that for now. This commit bloatens the code on big endian systems by 1 KiB, which should be OK since liblzma is bloated already. ;-)
Diffstat (limited to 'src/liblzma/lz/lz_encoder_hash.h')
-rw-r--r--src/liblzma/lz/lz_encoder_hash.h35
1 files changed, 23 insertions, 12 deletions
diff --git a/src/liblzma/lz/lz_encoder_hash.h b/src/liblzma/lz/lz_encoder_hash.h
index dd4b1f19..e92251d2 100644
--- a/src/liblzma/lz/lz_encoder_hash.h
+++ b/src/liblzma/lz/lz_encoder_hash.h
@@ -13,6 +13,17 @@
#ifndef LZMA_LZ_ENCODER_HASH_H
#define LZMA_LZ_ENCODER_HASH_H
+#if defined(WORDS_BIGENDIAN) && !defined(HAVE_SMALL)
+ // This is to make liblzma produce the same output on big endian
+ // systems that it does on little endian systems. lz_encoder.c
+ // takes care of including the actual table.
+ extern const uint32_t lzma_lz_hash_table[256];
+# define hash_table lzma_lz_hash_table
+#else
+# include "check.h"
+# define hash_table lzma_crc32_table[0]
+#endif
+
#define HASH_2_SIZE (UINT32_C(1) << 10)
#define HASH_3_SIZE (UINT32_C(1) << 16)
#define HASH_4_SIZE (UINT32_C(1) << 20)
@@ -36,31 +47,31 @@
#endif
#define hash_3_calc() \
- const uint32_t temp = lzma_crc32_table[0][cur[0]] ^ cur[1]; \
+ const uint32_t temp = hash_table[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 temp = hash_table[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
+ ^ (hash_table[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 temp = hash_table[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); \
+ ^ hash_table[cur[3]] << 5); \
const uint32_t hash_value \
- = (hash_4_value ^ (lzma_crc32_table[0][cur[4]] << 3)) \
+ = (hash_4_value ^ (hash_table[cur[4]] << 3)) \
& mf->hash_mask; \
hash_4_value &= HASH_4_MASK
@@ -68,30 +79,30 @@
#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
+ ^ hash_table[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
+ ^ hash_table[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
+ = (hash_table[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 temp = hash_table[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 temp = hash_table[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
+ (hash_table[cur[3]] << 5)) & HASH_4_MASK
#endif