liblzma: Tidy up crc_common.h

Prefix ARM64_RUNTIME_DETECTION with CRC_ and reorder it to be with
the other ARM64-specific lines. That macro isn't used outside this
file.

ARM64 CLMUL implementation doesn't exist yet and thus CRC64_ARM64_CLMUL
isn't used anywhere yet.

It's not ideal that the single-letter CRC utility macros are here
as they pollute the namespace of the LZ encoder files. Those could
be moved their own crc_macros.h like they were in 5.2.x but in practice
this is fine enough already.
This commit is contained in:
Lasse Collin 2024-06-23 15:35:35 +03:00
parent 7484d37538
commit fe77c4e130
1 changed files with 42 additions and 20 deletions

View File

@ -3,7 +3,7 @@
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// //
/// \file crc_common.h /// \file crc_common.h
/// \brief Some functions and macros for CRC32 and CRC64 /// \brief Macros and declarations for CRC32 and CRC64
// //
// Authors: Lasse Collin // Authors: Lasse Collin
// Ilya Kurdyukov // Ilya Kurdyukov
@ -18,6 +18,10 @@
#include "common.h" #include "common.h"
/////////////
// Generic //
/////////////
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
# define A(x) ((x) >> 24) # define A(x) ((x) >> 24)
# define B(x) (((x) >> 16) & 0xFF) # define B(x) (((x) >> 16) & 0xFF)
@ -56,26 +60,39 @@ extern const uint64_t lzma_crc64_table[4][256];
#endif #endif
// Keep this in sync with changes to crc32_arm64.h ///////////////////
#if defined(_WIN32) || defined(HAVE_GETAUXVAL) \ // Configuration //
|| defined(HAVE_ELF_AUX_INFO) \ ///////////////////
|| defined(HAVE_CPU_ID_AA64ISAR0) \
|| (defined(__APPLE__) && defined(HAVE_SYSCTLBYNAME))
# define ARM64_RUNTIME_DETECTION 1
#endif
// NOTE: This config isn't used if HAVE_SMALL is defined!
// These are defined if the generic slicing-by-n implementations and their
// lookup tables are built.
#undef CRC32_GENERIC #undef CRC32_GENERIC
#undef CRC64_GENERIC #undef CRC64_GENERIC
// These are defined if an arch-specific version is built. If both this
// and matching _GENERIC is defined then runtime detection must be used.
#undef CRC32_ARCH_OPTIMIZED #undef CRC32_ARCH_OPTIMIZED
#undef CRC64_ARCH_OPTIMIZED #undef CRC64_ARCH_OPTIMIZED
// The x86 CLMUL is used for both CRC32 and CRC64. // The x86 CLMUL is used for both CRC32 and CRC64.
#undef CRC_X86_CLMUL #undef CRC_X86_CLMUL
// Many ARM64 processor have CRC32 instructions.
// CRC64 could be done with CLMUL but it's not implemented yet.
#undef CRC32_ARM64 #undef CRC32_ARM64
#undef CRC64_ARM64_CLMUL
// ARM64
//
// Keep this in sync with changes to crc32_arm64.h
#if defined(_WIN32) || defined(HAVE_GETAUXVAL) \
|| defined(HAVE_ELF_AUX_INFO) \
|| defined(HAVE_CPU_ID_AA64ISAR0) \
|| (defined(__APPLE__) && defined(HAVE_SYSCTLBYNAME))
# define CRC_ARM64_RUNTIME_DETECTION 1
#endif
// ARM64 CRC32 instruction is only useful for CRC32. Currently, only // ARM64 CRC32 instruction is only useful for CRC32. Currently, only
// little endian is supported since we were unable to test on a big // little endian is supported since we were unable to test on a big
@ -87,16 +104,18 @@ extern const uint64_t lzma_crc64_table[4][256];
# if defined(__ARM_FEATURE_CRC32) # if defined(__ARM_FEATURE_CRC32)
# define CRC32_ARCH_OPTIMIZED 1 # define CRC32_ARCH_OPTIMIZED 1
# define CRC32_ARM64 1 # define CRC32_ARM64 1
# elif defined(ARM64_RUNTIME_DETECTION) # elif defined(CRC_ARM64_RUNTIME_DETECTION)
# define CRC32_ARCH_OPTIMIZED 1 # define CRC32_ARCH_OPTIMIZED 1
# define CRC32_ARM64 1 # define CRC32_ARM64 1
# define CRC32_GENERIC 1 # define CRC32_GENERIC 1
# endif # endif
#endif #endif
// x86 and E2K
#if defined(HAVE_USABLE_CLMUL) #if defined(HAVE_USABLE_CLMUL)
// If CLMUL is allowed unconditionally in the compiler options then the // If CLMUL is allowed unconditionally in the compiler options then
// generic version and the tables can be omitted. Exceptions: // the generic version and the tables can be omitted. Exceptions:
// //
// - If 32-bit x86 assembly files are enabled then those are always // - If 32-bit x86 assembly files are enabled then those are always
// built and runtime detection is used even if compiler flags // built and runtime detection is used even if compiler flags
@ -120,6 +139,9 @@ extern const uint64_t lzma_crc64_table[4][256];
# endif # endif
#endif #endif
// Fallback configuration
//
// For CRC32 use the generic slice-by-eight implementation if no optimized // For CRC32 use the generic slice-by-eight implementation if no optimized
// version is available. // version is available.
#if !defined(CRC32_ARCH_OPTIMIZED) && !defined(CRC32_GENERIC) #if !defined(CRC32_ARCH_OPTIMIZED) && !defined(CRC32_GENERIC)