From 0ed3a722a8e32b358c6cb30f86e8bea714714098 Mon Sep 17 00:00:00 2001 From: Lasse Collin Date: Tue, 11 Jun 2024 12:47:59 +0300 Subject: [PATCH] liblzma: Use a single macro to select CLMUL CRC to build This way it's clearer that two things cannot be selected at the same time. --- src/liblzma/check/crc32_fast.c | 4 ++-- src/liblzma/check/crc64_fast.c | 4 ++-- src/liblzma/check/crc_e2k_clmul.h | 14 ++++++++------ src/liblzma/check/crc_x86_clmul.h | 18 ++++++++++-------- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/liblzma/check/crc32_fast.c b/src/liblzma/check/crc32_fast.c index acdddd30e..2e8770e63 100644 --- a/src/liblzma/check/crc32_fast.c +++ b/src/liblzma/check/crc32_fast.c @@ -15,10 +15,10 @@ #include "crc_common.h" #if defined(CRC_X86_CLMUL) -# define BUILDING_CRC32_CLMUL +# define BUILDING_CRC_CLMUL 32 # include "crc_x86_clmul.h" #elif defined(CRC_E2K_CLMUL) -# define BUILDING_CRC32_CLMUL +# define BUILDING_CRC_CLMUL 32 # include "crc_e2k_clmul.h" #elif defined(CRC32_ARM64) # include "crc32_arm64.h" diff --git a/src/liblzma/check/crc64_fast.c b/src/liblzma/check/crc64_fast.c index e3662c5da..9e43edc23 100644 --- a/src/liblzma/check/crc64_fast.c +++ b/src/liblzma/check/crc64_fast.c @@ -14,10 +14,10 @@ #include "crc_common.h" #if defined(CRC_X86_CLMUL) -# define BUILDING_CRC64_CLMUL +# define BUILDING_CRC_CLMUL 64 # include "crc_x86_clmul.h" #elif defined(CRC_E2K_CLMUL) -# define BUILDING_CRC64_CLMUL +# define BUILDING_CRC_CLMUL 64 # include "crc_e2k_clmul.h" #endif diff --git a/src/liblzma/check/crc_e2k_clmul.h b/src/liblzma/check/crc_e2k_clmul.h index 643e0b7e8..f2276a912 100644 --- a/src/liblzma/check/crc_e2k_clmul.h +++ b/src/liblzma/check/crc_e2k_clmul.h @@ -14,10 +14,8 @@ /// (URLs were checked on 2023-10-14). /// /// While this file has both CRC32 and CRC64 implementations, only one -/// should be built at a time to ensure that crc_simd_body() is inlined -/// even with compilers with which lzma_always_inline expands to plain inline. -/// The version to build is selected by defining BUILDING_CRC32_CLMUL or -/// BUILDING_CRC64_CLMUL before including this file. +/// can be built at a time. The version to build is selected by defining +/// BUILDING_CRC_CLMUL to 32 or 64 before including this file. // // Authors: Ilya Kurdyukov // Hans Jansen @@ -32,6 +30,10 @@ #endif #define LZMA_CRC_E2K_CLMUL_H +#if BUILDING_CRC_CLMUL != 32 && BUILDING_CRC_CLMUL != 64 +# error BUILDING_CRC_CLMUL is undefined or has an invalid value +#endif + #include @@ -182,7 +184,7 @@ crc_simd_body(const uint8_t *buf, const size_t size, __m128i *v0, __m128i *v1, } -#ifdef BUILDING_CRC32_CLMUL +#if BUILDING_CRC_CLMUL == 32 static uint32_t crc32_arch_optimized(const uint8_t *buf, size_t size, uint32_t crc) { @@ -211,7 +213,7 @@ crc32_arch_optimized(const uint8_t *buf, size_t size, uint32_t crc) #endif -#ifdef BUILDING_CRC64_CLMUL +#if BUILDING_CRC_CLMUL == 64 static uint64_t crc64_arch_optimized(const uint8_t *buf, size_t size, uint64_t crc) { diff --git a/src/liblzma/check/crc_x86_clmul.h b/src/liblzma/check/crc_x86_clmul.h index 6ff104f34..8a1e3903e 100644 --- a/src/liblzma/check/crc_x86_clmul.h +++ b/src/liblzma/check/crc_x86_clmul.h @@ -14,10 +14,8 @@ /// (URLs were checked on 2023-10-14). /// /// While this file has both CRC32 and CRC64 implementations, only one -/// should be built at a time to ensure that crc_simd_body() is inlined -/// even with compilers with which lzma_always_inline expands to plain inline. -/// The version to build is selected by defining BUILDING_CRC32_CLMUL or -/// BUILDING_CRC64_CLMUL before including this file. +/// can be built at a time. The version to build is selected by defining +/// BUILDING_CRC_CLMUL to 32 or 64 before including this file. /// /// FIXME: Builds for 32-bit x86 use the assembly .S files by default /// unless configured with --disable-assembler. Even then the lookup table @@ -37,6 +35,10 @@ #endif #define LZMA_CRC_X86_CLMUL_H +#if BUILDING_CRC_CLMUL != 32 && BUILDING_CRC_CLMUL != 64 +# error BUILDING_CRC_CLMUL is undefined or has an invalid value +#endif + #include #if defined(_MSC_VER) @@ -211,7 +213,7 @@ crc_simd_body(const uint8_t *buf, const size_t size, __m128i *v0, __m128i *v1, // x86 CLMUL CRC32 // ///////////////////// -#ifdef BUILDING_CRC32_CLMUL +#if BUILDING_CRC_CLMUL == 32 crc_attr_target static uint32_t @@ -239,14 +241,14 @@ crc32_arch_optimized(const uint8_t *buf, size_t size, uint32_t crc) v0 = _mm_xor_si128(v0, v1); return ~(uint32_t)_mm_extract_epi32(v0, 2); } -#endif // BUILDING_CRC32_CLMUL +#endif // BUILDING_CRC_CLMUL == 32 ///////////////////// // x86 CLMUL CRC64 // ///////////////////// -#ifdef BUILDING_CRC64_CLMUL +#if BUILDING_CRC_CLMUL == 64 // MSVC (VS2015 - VS2022) produces bad 32-bit x86 code from the CLMUL CRC // code when optimizations are enabled (release build). According to the bug @@ -309,7 +311,7 @@ crc64_arch_optimized(const uint8_t *buf, size_t size, uint64_t crc) # pragma optimize("", on) #endif -#endif // BUILDING_CRC64_CLMUL +#endif // BUILDING_CRC_CLMUL == 64 // Inlining this function duplicates the function body in crc32_resolve() and