Path: blob/master/Utilities/cmliblzma/liblzma/check/crc_common.h
3153 views
// SPDX-License-Identifier: 0BSD12///////////////////////////////////////////////////////////////////////////////3//4/// \file crc_common.h5/// \brief Some functions and macros for CRC32 and CRC646//7// Authors: Lasse Collin8// Ilya Kurdyukov9// Hans Jansen10// Jia Tan11//12///////////////////////////////////////////////////////////////////////////////1314#ifndef LZMA_CRC_COMMON_H15#define LZMA_CRC_COMMON_H1617#include "common.h"181920#ifdef WORDS_BIGENDIAN21# define A(x) ((x) >> 24)22# define B(x) (((x) >> 16) & 0xFF)23# define C(x) (((x) >> 8) & 0xFF)24# define D(x) ((x) & 0xFF)2526# define S8(x) ((x) << 8)27# define S32(x) ((x) << 32)2829#else30# define A(x) ((x) & 0xFF)31# define B(x) (((x) >> 8) & 0xFF)32# define C(x) (((x) >> 16) & 0xFF)33# define D(x) ((x) >> 24)3435# define S8(x) ((x) >> 8)36# define S32(x) ((x) >> 32)37#endif383940// CRC CLMUL code needs this because accessing input buffers that aren't41// aligned to the vector size will inherently trip the address sanitizer.42#if lzma_has_attribute(__no_sanitize_address__)43# define crc_attr_no_sanitize_address \44__attribute__((__no_sanitize_address__))45#else46# define crc_attr_no_sanitize_address47#endif4849// Keep this in sync with changes to crc32_arm64.h50#if defined(_WIN32) || defined(HAVE_GETAUXVAL) \51|| defined(HAVE_ELF_AUX_INFO) \52|| (defined(__APPLE__) && defined(HAVE_SYSCTLBYNAME))53# define ARM64_RUNTIME_DETECTION 154#endif555657#undef CRC32_GENERIC58#undef CRC64_GENERIC5960#undef CRC32_ARCH_OPTIMIZED61#undef CRC64_ARCH_OPTIMIZED6263// The x86 CLMUL is used for both CRC32 and CRC64.64#undef CRC_X86_CLMUL6566#undef CRC32_ARM6467#undef CRC64_ARM64_CLMUL6869#undef CRC_USE_GENERIC_FOR_SMALL_INPUTS7071// ARM64 CRC32 instruction is only useful for CRC32. Currently, only72// little endian is supported since we were unable to test on a big73// endian machine.74//75// NOTE: Keep this and the next check in sync with the macro76// NO_CRC32_TABLE in crc32_table.c77#if defined(HAVE_ARM64_CRC32) && !defined(WORDS_BIGENDIAN)78// Allow ARM64 CRC32 instruction without a runtime check if79// __ARM_FEATURE_CRC32 is defined. GCC and Clang only define80// this if the proper compiler options are used.81# if defined(__ARM_FEATURE_CRC32)82# define CRC32_ARCH_OPTIMIZED 183# define CRC32_ARM64 184# elif defined(ARM64_RUNTIME_DETECTION)85# define CRC32_ARCH_OPTIMIZED 186# define CRC32_ARM64 187# define CRC32_GENERIC 188# endif89#endif9091#if defined(HAVE_USABLE_CLMUL)92// If CLMUL is allowed unconditionally in the compiler options then the93// generic version can be omitted. Note that this doesn't work with MSVC94// as I don't know how to detect the features here.95//96// NOTE: Keep this in sync with the NO_CRC32_TABLE macro in crc32_table.c97// and NO_CRC64_TABLE in crc64_table.c.98# if (defined(__SSSE3__) && defined(__SSE4_1__) && defined(__PCLMUL__)) \99|| (defined(__e2k__) && __iset__ >= 6)100# define CRC32_ARCH_OPTIMIZED 1101# define CRC64_ARCH_OPTIMIZED 1102# define CRC_X86_CLMUL 1103# else104# define CRC32_GENERIC 1105# define CRC64_GENERIC 1106# define CRC32_ARCH_OPTIMIZED 1107# define CRC64_ARCH_OPTIMIZED 1108# define CRC_X86_CLMUL 1109110/*111// The generic code is much faster with 1-8-byte inputs and112// has similar performance up to 16 bytes at least in113// microbenchmarks (it depends on input buffer alignment114// too). If both versions are built, this #define will use115// the generic version for inputs up to 16 bytes and CLMUL116// for bigger inputs. It saves a little in code size since117// the special cases for 0-16-byte inputs will be omitted118// from the CLMUL code.119# define CRC_USE_GENERIC_FOR_SMALL_INPUTS 1120*/121# endif122#endif123124// For CRC32 use the generic slice-by-eight implementation if no optimized125// version is available.126#if !defined(CRC32_ARCH_OPTIMIZED) && !defined(CRC32_GENERIC)127# define CRC32_GENERIC 1128#endif129130// For CRC64 use the generic slice-by-four implementation if no optimized131// version is available.132#if !defined(CRC64_ARCH_OPTIMIZED) && !defined(CRC64_GENERIC)133# define CRC64_GENERIC 1134#endif135136#endif137138139