]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
liblzma: Tidy up crc_common.h
authorLasse Collin <lasse.collin@tukaani.org>
Sun, 23 Jun 2024 12:35:35 +0000 (15:35 +0300)
committerLasse Collin <lasse.collin@tukaani.org>
Sun, 23 Jun 2024 20:09:14 +0000 (23:09 +0300)
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.

src/liblzma/check/crc_common.h

index e55dd7c0f0493603fd424156fc5ee1059e28f851..48cd466ec5a9de338756b7edacdcefce493fe9f6 100644 (file)
@@ -3,7 +3,7 @@
 ///////////////////////////////////////////////////////////////////////////////
 //
 /// \file       crc_common.h
-/// \brief      Some functions and macros for CRC32 and CRC64
+/// \brief      Macros and declarations for CRC32 and CRC64
 //
 //  Authors:    Lasse Collin
 //              Ilya Kurdyukov
 #include "common.h"
 
 
+/////////////
+// Generic //
+/////////////
+
 #ifdef WORDS_BIGENDIAN
 #      define A(x) ((x) >> 24)
 #      define B(x) (((x) >> 16) & 0xFF)
@@ -56,26 +60,39 @@ extern const uint64_t lzma_crc64_table[4][256];
 #endif
 
 
-// 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 ARM64_RUNTIME_DETECTION 1
-#endif
+///////////////////
+// Configuration //
+///////////////////
 
+// 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 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 CRC64_ARCH_OPTIMIZED
 
 // The x86 CLMUL is used for both CRC32 and CRC64.
 #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 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
 // little endian is supported since we were unable to test on a big
@@ -87,24 +104,26 @@ extern const uint64_t lzma_crc64_table[4][256];
 #      if defined(__ARM_FEATURE_CRC32)
 #              define CRC32_ARCH_OPTIMIZED 1
 #              define CRC32_ARM64 1
-#      elif defined(ARM64_RUNTIME_DETECTION)
+#      elif defined(CRC_ARM64_RUNTIME_DETECTION)
 #              define CRC32_ARCH_OPTIMIZED 1
 #              define CRC32_ARM64 1
 #              define CRC32_GENERIC 1
 #      endif
 #endif
 
+
+// x86 and E2K
 #if defined(HAVE_USABLE_CLMUL)
-// If CLMUL is allowed unconditionally in the compiler options then the
-// generic version and the tables can be omitted. Exceptions:
-//
-//   - If 32-bit x86 assembly files are enabled then those are always
-//     built and runtime detection is used even if compiler flags
-//     were set to allow CLMUL unconditionally.
-//
-//   - This doesn't work with MSVC as I don't know how to detect
-//     the features here.
-//
+       // If CLMUL is allowed unconditionally in the compiler options then
+       // the generic version and the tables can be omitted. Exceptions:
+       //
+       //   - If 32-bit x86 assembly files are enabled then those are always
+       //     built and runtime detection is used even if compiler flags
+       //     were set to allow CLMUL unconditionally.
+       //
+       //   - This doesn't work with MSVC as I don't know how to detect
+       //     the features here.
+       //
 #      if (defined(__SSSE3__) && defined(__SSE4_1__) && defined(__PCLMUL__) \
                        && !defined(HAVE_CRC_X86_ASM)) \
                || (defined(__e2k__) && __iset__ >= 6)
@@ -120,6 +139,9 @@ extern const uint64_t lzma_crc64_table[4][256];
 #      endif
 #endif
 
+
+// Fallback configuration
+//
 // For CRC32 use the generic slice-by-eight implementation if no optimized
 // version is available.
 #if !defined(CRC32_ARCH_OPTIMIZED) && !defined(CRC32_GENERIC)