From 1b15e888fc1a2f5f84583b0df014c6032eb3a162 Mon Sep 17 00:00:00 2001 From: Pavel P Date: Fri, 24 Jan 2025 00:05:03 +0200 Subject: [PATCH 1/3] Move STATIC_BMI2 block as-is to portability_macros.h --- lib/common/compiler.h | 15 --------------- lib/common/portability_macros.h | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/common/compiler.h b/lib/common/compiler.h index c942b984cb0..5ad21238337 100644 --- a/lib/common/compiler.h +++ b/lib/common/compiler.h @@ -207,21 +207,6 @@ # pragma warning(disable : 4324) /* disable: C4324: padded structure */ #endif -/* Like DYNAMIC_BMI2 but for compile time determination of BMI2 support */ -#ifndef STATIC_BMI2 -# if defined(_MSC_VER) -# ifdef __AVX2__ /* MSVC does not have a BMI2 specific flag, but every CPU that supports AVX2 also supports BMI2 */ -# define STATIC_BMI2 1 -# endif -# elif defined(__BMI2__) -# define STATIC_BMI2 1 -# endif -#endif - -#ifndef STATIC_BMI2 -# define STATIC_BMI2 0 -#endif - /* compile time determination of SIMD support */ #if !defined(ZSTD_NO_INTRINSICS) # if defined(__AVX2__) diff --git a/lib/common/portability_macros.h b/lib/common/portability_macros.h index b52394382ed..b4da8a7442a 100644 --- a/lib/common/portability_macros.h +++ b/lib/common/portability_macros.h @@ -74,6 +74,21 @@ # define ZSTD_HIDE_ASM_FUNCTION(func) #endif +/* Like DYNAMIC_BMI2 but for compile time determination of BMI2 support */ +#ifndef STATIC_BMI2 +# if defined(_MSC_VER) +# ifdef __AVX2__ /* MSVC does not have a BMI2 specific flag, but every CPU that supports AVX2 also supports BMI2 */ +# define STATIC_BMI2 1 +# endif +# elif defined(__BMI2__) +# define STATIC_BMI2 1 +# endif +#endif + +#ifndef STATIC_BMI2 +# define STATIC_BMI2 0 +#endif + /* Enable runtime BMI2 dispatch based on the CPU. * Enabled for clang & gcc >=4.8 on x86 when BMI2 isn't enabled by default. */ From d486ccc9e90a9d2e0095f9a81cbf29f72bac4f37 Mon Sep 17 00:00:00 2001 From: Pavel P Date: Fri, 24 Jan 2025 00:06:13 +0200 Subject: [PATCH 2/3] Update comment for STATIC_BMI2 macro --- lib/common/portability_macros.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/common/portability_macros.h b/lib/common/portability_macros.h index b4da8a7442a..70964ba01e7 100644 --- a/lib/common/portability_macros.h +++ b/lib/common/portability_macros.h @@ -74,7 +74,7 @@ # define ZSTD_HIDE_ASM_FUNCTION(func) #endif -/* Like DYNAMIC_BMI2 but for compile time determination of BMI2 support */ +/* Compile time determination of BMI2 support */ #ifndef STATIC_BMI2 # if defined(_MSC_VER) # ifdef __AVX2__ /* MSVC does not have a BMI2 specific flag, but every CPU that supports AVX2 also supports BMI2 */ From 0a183620a3c21bce4ca3b10a12aba7d7f84c12b2 Mon Sep 17 00:00:00 2001 From: Pavel P Date: Fri, 24 Jan 2025 00:09:44 +0200 Subject: [PATCH 3/3] Reorder __BMI2__ check + if `__BMI2__` defined, then set STATIC_BMI2 for all compilers + use `defined(_MSC_VER) && defined(__AVX2__)` as fallback for ms compiler --- lib/common/portability_macros.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/common/portability_macros.h b/lib/common/portability_macros.h index 70964ba01e7..860734141df 100644 --- a/lib/common/portability_macros.h +++ b/lib/common/portability_macros.h @@ -76,12 +76,10 @@ /* Compile time determination of BMI2 support */ #ifndef STATIC_BMI2 -# if defined(_MSC_VER) -# ifdef __AVX2__ /* MSVC does not have a BMI2 specific flag, but every CPU that supports AVX2 also supports BMI2 */ -# define STATIC_BMI2 1 -# endif -# elif defined(__BMI2__) +# if defined(__BMI2__) # define STATIC_BMI2 1 +# elif defined(_MSC_VER) && defined(__AVX2__) +# define STATIC_BMI2 1 /* MSVC does not have a BMI2 specific flag, but every CPU that supports AVX2 also supports BMI2 */ # endif #endif