From 943ffbb778546f065b1419703b0f50f2065f8fec Mon Sep 17 00:00:00 2001 From: Egbert Eich Date: Tue, 1 Mar 2022 18:18:54 +0100 Subject: [PATCH] Do not attempt to check host CPU if TARGET is set. This wired 'autodetection' breaks DYNAMIC arch (or makes the build unreproducible) and will most likely not work with cross compiling. Presently, this is only relevant for SkylakeX, Cooperlake and Sapphire Rapids cores, that's what has been implemented. Going forward, other cores would have to be added here as well (in sync with Markfile.$(arch) as this needs to be kept in sync with changes to getarch. It would be better to remove this hack (and the counterpart in getarch) entirely. This fixes issue #3557. Signed-off-by: Egbert Eich --- Makefile.system | 14 +++++++++++--- cmake/system.cmake | 4 ++-- getarch.c | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Makefile.system b/Makefile.system index ff15b6400..0203e7c72 100644 --- a/Makefile.system +++ b/Makefile.system @@ -197,9 +197,17 @@ endif # On x86_64 build getarch with march=native unless the compiler is PGI. This is required to detect AVX512 support in getarch. ifeq ($(HOSTARCH), x86_64) -ifeq ($(findstring pgcc,$(HOSTCC))$(findstring nvc,$(HOSTCC)),) -GETARCH_FLAGS += -march=native -endif + ifeq ($(findstring pgcc,$(HOSTCC))$(findstring nvc,$(HOSTCC)),) + ifdef TARGET +GETARCH_NOPROBE=1 + endif + ifdef TARGET_CORE +GETARCH_NOPROBE=1 + endif + ifndef GETARCH_NOPROBE +GETARCH_FLAGS += -march=native -DAUTOPROBE + endif + endif endif ifdef INTERFACE64 diff --git a/cmake/system.cmake b/cmake/system.cmake index e0e92bde7..27c453906 100644 --- a/cmake/system.cmake +++ b/cmake/system.cmake @@ -55,8 +55,8 @@ if (DEFINED TARGET) endif () # On x86_64 build getarch with march=native. This is required to detect AVX512 support in getarch. -if (X86_64 AND NOT ${CMAKE_C_COMPILER_ID} STREQUAL "PGI") - set(GETARCH_FLAGS "${GETARCH_FLAGS} -march=native") +if (X86_64 AND NOT ${CMAKE_C_COMPILER_ID} STREQUAL "PGI" AND NOT DEFINED TARGET) + set(GETARCH_FLAGS "${GETARCH_FLAGS} -march=native -DAUTOPROBE") endif () # On x86 no AVX support is available diff --git a/getarch.c b/getarch.c index 00e544bc7..3adf530f5 100644 --- a/getarch.c +++ b/getarch.c @@ -94,7 +94,7 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #endif -#if defined(__x86_64__) || defined(_M_X64) +#if defined (AUTOPROBE) && (defined(__x86_64__) || defined(_M_X64)) #if (( defined(__GNUC__) && __GNUC__ > 6 && defined(__AVX2__)) || (defined(__clang__) && __clang_major__ >= 6)) #else #ifndef NO_AVX512