2007-12-08 22:42:33 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2023-10-12 17:07:50 +00:00
|
|
|
/// \file crc_common.h
|
2023-10-12 17:23:40 +00:00
|
|
|
/// \brief Some functions and macros for CRC32 and CRC64
|
2007-12-08 22:42:33 +00:00
|
|
|
//
|
2023-10-12 17:23:40 +00:00
|
|
|
// Authors: Lasse Collin
|
|
|
|
// Ilya Kurdyukov
|
|
|
|
// Hans Jansen
|
2023-10-14 04:17:57 +00:00
|
|
|
// Jia Tan
|
2007-12-08 22:42:33 +00:00
|
|
|
//
|
2009-04-13 08:27:40 +00:00
|
|
|
// This file has been put into the public domain.
|
|
|
|
// You can do whatever you want with this file.
|
2007-12-08 22:42:33 +00:00
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2023-10-17 17:23:26 +00:00
|
|
|
#ifndef LZMA_CRC_COMMON_H
|
|
|
|
#define LZMA_CRC_COMMON_H
|
|
|
|
|
2023-10-17 18:53:11 +00:00
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
|
2007-12-08 22:42:33 +00:00
|
|
|
#ifdef WORDS_BIGENDIAN
|
|
|
|
# define A(x) ((x) >> 24)
|
|
|
|
# define B(x) (((x) >> 16) & 0xFF)
|
|
|
|
# define C(x) (((x) >> 8) & 0xFF)
|
|
|
|
# define D(x) ((x) & 0xFF)
|
|
|
|
|
|
|
|
# define S8(x) ((x) << 8)
|
|
|
|
# define S32(x) ((x) << 32)
|
|
|
|
|
|
|
|
#else
|
|
|
|
# define A(x) ((x) & 0xFF)
|
|
|
|
# define B(x) (((x) >> 8) & 0xFF)
|
|
|
|
# define C(x) (((x) >> 16) & 0xFF)
|
|
|
|
# define D(x) ((x) >> 24)
|
|
|
|
|
|
|
|
# define S8(x) ((x) >> 8)
|
|
|
|
# define S32(x) ((x) >> 32)
|
|
|
|
#endif
|
2023-10-12 17:23:40 +00:00
|
|
|
|
|
|
|
|
2023-10-20 18:53:35 +00:00
|
|
|
// CRC CLMUL code needs this because accessing input buffers that aren't
|
|
|
|
// aligned to the vector size will inherently trip the address sanitizer.
|
|
|
|
#if lzma_has_attribute(__no_sanitize_address__)
|
|
|
|
# define crc_attr_no_sanitize_address \
|
|
|
|
__attribute__((__no_sanitize_address__))
|
|
|
|
#else
|
|
|
|
# define crc_attr_no_sanitize_address
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2023-10-18 14:48:19 +00:00
|
|
|
// The inline keyword is only a suggestion to the compiler to substitute the
|
|
|
|
// body of the function into the places where it is called. If a function
|
|
|
|
// is large and called multiple times then compiler may choose to ignore the
|
|
|
|
// inline suggestion at a sometimes high performance cost.
|
|
|
|
//
|
|
|
|
// MSVC's __forceinline is a keyword that should be used in place of inline.
|
|
|
|
// If both __forceinline and inline are used, MSVC will issue a warning.
|
|
|
|
// Since MSVC's keyword is a replacement keyword, the lzma_always_inline
|
|
|
|
// macro must also contain the inline keyword when its not used in MSVC.
|
2023-10-30 16:09:53 +00:00
|
|
|
//
|
|
|
|
// NOTE: This doesn't use lzma_always_inline for now as support for it is
|
|
|
|
// detected using preprocessor macros which might miss a compiler that
|
|
|
|
// does support it. All compilers that support the CLMUL code support
|
|
|
|
// the attribute too; if not, we will hopefully get a bug report.
|
2023-10-18 14:48:19 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
# define crc_always_inline __forceinline
|
|
|
|
#else
|
|
|
|
# define crc_always_inline __attribute__((__always_inline__)) inline
|
|
|
|
#endif
|
|
|
|
|
2023-10-12 17:23:40 +00:00
|
|
|
#undef CRC_GENERIC
|
|
|
|
#undef CRC_CLMUL
|
2023-10-14 02:23:03 +00:00
|
|
|
#undef CRC_USE_IFUNC
|
2023-10-12 17:23:40 +00:00
|
|
|
#undef CRC_USE_GENERIC_FOR_SMALL_INPUTS
|
|
|
|
|
2024-01-10 16:19:21 +00:00
|
|
|
// If CLMUL cannot be used then only the generic slice-by-eight (CRC32)
|
|
|
|
// or slice-by-four (CRC64) is built.
|
2023-10-12 17:23:40 +00:00
|
|
|
#if !defined(HAVE_USABLE_CLMUL)
|
|
|
|
# define CRC_GENERIC 1
|
|
|
|
|
|
|
|
// If CLMUL is allowed unconditionally in the compiler options then the
|
|
|
|
// generic version can be omitted. Note that this doesn't work with MSVC
|
|
|
|
// as I don't know how to detect the features here.
|
|
|
|
//
|
|
|
|
// NOTE: Keep this this in sync with crc32_table.c.
|
|
|
|
#elif (defined(__SSSE3__) && defined(__SSE4_1__) && defined(__PCLMUL__)) \
|
|
|
|
|| (defined(__e2k__) && __iset__ >= 6)
|
|
|
|
# define CRC_CLMUL 1
|
|
|
|
|
|
|
|
// Otherwise build both and detect at runtime which version to use.
|
|
|
|
#else
|
|
|
|
# define CRC_GENERIC 1
|
|
|
|
# define CRC_CLMUL 1
|
|
|
|
|
2023-10-14 02:23:03 +00:00
|
|
|
# ifdef HAVE_FUNC_ATTRIBUTE_IFUNC
|
|
|
|
# define CRC_USE_IFUNC 1
|
|
|
|
# endif
|
|
|
|
|
2023-10-12 17:23:40 +00:00
|
|
|
/*
|
|
|
|
// The generic code is much faster with 1-8-byte inputs and has
|
|
|
|
// similar performance up to 16 bytes at least in microbenchmarks
|
|
|
|
// (it depends on input buffer alignment too). If both versions are
|
|
|
|
// built, this #define will use the generic version for inputs up to
|
|
|
|
// 16 bytes and CLMUL for bigger inputs. It saves a little in code
|
|
|
|
// size since the special cases for 0-16-byte inputs will be omitted
|
|
|
|
// from the CLMUL code.
|
2023-10-18 11:30:00 +00:00
|
|
|
# ifndef CRC_USE_IFUNC
|
|
|
|
# define CRC_USE_GENERIC_FOR_SMALL_INPUTS 1
|
|
|
|
# endif
|
2023-10-12 17:23:40 +00:00
|
|
|
*/
|
|
|
|
#endif
|
|
|
|
|
2023-10-17 17:23:26 +00:00
|
|
|
#endif
|