1 ///////////////////////////////////////////////////////////////////////////////
4 /// \brief CRC64 calculation
6 // This code has been put into the public domain.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 ///////////////////////////////////////////////////////////////////////////////
15 #include "crc_macros.h"
18 #ifdef WORDS_BIGENDIAN
19 # define A1(x) ((x) >> 56)
25 // See comments in crc32.c.
26 extern LZMA_API(uint64_t)
27 lzma_crc64(const uint8_t *buf, size_t size, uint64_t crc)
31 #ifdef WORDS_BIGENDIAN
36 while ((uintptr_t)(buf) & 3) {
37 crc = lzma_crc64_table[0][*buf++ ^ A1(crc)] ^ S8(crc);
41 const uint8_t *const limit = buf + (size & ~(size_t)(3));
44 // Calculate the CRC64 using the slice-by-four algorithm.
46 // In contrast to CRC32 code, this one seems to be fastest
47 // with -O3 -fomit-frame-pointer.
49 #ifdef WORDS_BIGENDIAN
50 const uint32_t tmp = (crc >> 32) ^ *(uint32_t *)(buf);
52 const uint32_t tmp = crc ^ *(uint32_t *)(buf);
56 // It is critical for performance, that
57 // the crc variable is XORed between the
58 // two table-lookup pairs.
59 crc = lzma_crc64_table[3][A(tmp)]
60 ^ lzma_crc64_table[2][B(tmp)]
62 ^ lzma_crc64_table[1][C(tmp)]
63 ^ lzma_crc64_table[0][D(tmp)];
68 crc = lzma_crc64_table[0][*buf++ ^ A1(crc)] ^ S8(crc);
70 #ifdef WORDS_BIGENDIAN