diff options
author | mm <mm@FreeBSD.org> | 2010-05-10 06:59:50 +0000 |
---|---|---|
committer | mm <mm@FreeBSD.org> | 2010-05-10 06:59:50 +0000 |
commit | 5c358d45429b654efa9c8177ecd370a7965ec1a7 (patch) | |
tree | d2d916954c6a66a3168ee356b5f24da01c2017d6 /contrib/xz/src/liblzma/check/crc64_fast.c | |
parent | 3e09decd1986826f54af1a47be97bb87c1220783 (diff) | |
parent | 1008b7c6744a190c5b15aaf8cab1054671e4c7c3 (diff) | |
download | FreeBSD-src-5c358d45429b654efa9c8177ecd370a7965ec1a7.zip FreeBSD-src-5c358d45429b654efa9c8177ecd370a7965ec1a7.tar.gz |
Import of liblzma, xz, xzdec, lzmainfo from vendor branch
Add support for xz and lzma to lesspipe.sh (xzless, lzless)
Bump __FreeBSD_version
Approved by: delphij (mentor)
MFC after: 2 weeks
Diffstat (limited to 'contrib/xz/src/liblzma/check/crc64_fast.c')
-rw-r--r-- | contrib/xz/src/liblzma/check/crc64_fast.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/contrib/xz/src/liblzma/check/crc64_fast.c b/contrib/xz/src/liblzma/check/crc64_fast.c new file mode 100644 index 0000000..52af29e --- /dev/null +++ b/contrib/xz/src/liblzma/check/crc64_fast.c @@ -0,0 +1,72 @@ +/////////////////////////////////////////////////////////////////////////////// +// +/// \file crc64.c +/// \brief CRC64 calculation +/// +/// Calculate the CRC64 using the slice-by-four algorithm. This is the same +/// idea that is used in crc32_fast.c, but for CRC64 we use only four tables +/// instead of eight to avoid increasing CPU cache usage. +// +// Author: Lasse Collin +// +// This file has been put into the public domain. +// You can do whatever you want with this file. +// +/////////////////////////////////////////////////////////////////////////////// + +#include "check.h" +#include "crc_macros.h" + + +#ifdef WORDS_BIGENDIAN +# define A1(x) ((x) >> 56) +#else +# define A1 A +#endif + + +// See the comments in crc32_fast.c. They aren't duplicated here. +extern LZMA_API(uint64_t) +lzma_crc64(const uint8_t *buf, size_t size, uint64_t crc) +{ + crc = ~crc; + +#ifdef WORDS_BIGENDIAN + crc = bswap64(crc); +#endif + + if (size > 4) { + while ((uintptr_t)(buf) & 3) { + crc = lzma_crc64_table[0][*buf++ ^ A1(crc)] ^ S8(crc); + --size; + } + + const uint8_t *const limit = buf + (size & ~(size_t)(3)); + size &= (size_t)(3); + + while (buf < limit) { +#ifdef WORDS_BIGENDIAN + const uint32_t tmp = (crc >> 32) + ^ *(const uint32_t *)(buf); +#else + const uint32_t tmp = crc ^ *(const uint32_t *)(buf); +#endif + buf += 4; + + crc = lzma_crc64_table[3][A(tmp)] + ^ lzma_crc64_table[2][B(tmp)] + ^ S32(crc) + ^ lzma_crc64_table[1][C(tmp)] + ^ lzma_crc64_table[0][D(tmp)]; + } + } + + while (size-- != 0) + crc = lzma_crc64_table[0][*buf++ ^ A1(crc)] ^ S8(crc); + +#ifdef WORDS_BIGENDIAN + crc = bswap64(crc); +#endif + + return ~crc; +} |