From 5a463c621a223d8030976006159a5b95439181fe Mon Sep 17 00:00:00 2001 From: Mark Abraham Date: Tue, 10 Oct 2017 09:22:02 +0000 Subject: [PATCH] Fix cpuinfo on clang + non-x86 Compilers that pretend to be GCC often define such symbols, and the support for inline assembly does not compile e.g. on ARM. This broke CPU detection at cmake time, and subsequent compilation. Probably introduced by commit 863768a4dad. The latest ARM compiler is based on clang, so we should fix this. Also de-duplicated some use of compiler target defines Change-Id: Ia21363b9c0fe112762750d93b9feea267a34319f --- src/gromacs/hardware/architecture.h | 17 +++++++++++++++-- src/gromacs/hardware/cpuinfo.cpp | 7 +++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/gromacs/hardware/architecture.h b/src/gromacs/hardware/architecture.h index 2161e2530e..aeda6c3a91 100644 --- a/src/gromacs/hardware/architecture.h +++ b/src/gromacs/hardware/architecture.h @@ -53,10 +53,23 @@ enum class Architecture PowerPC //! IBM PowerPC }; +//! Whether the compilation is targeting 32-bit x86. +# if (defined __i386__ || defined __i386 || defined _X86_ || defined _M_IX86) +#define GMX_IS_X86_32 1 +#else +#define GMX_IS_X86_32 0 +#endif + +//! Whether the compilation is targeting 64-bit x86. +#if (defined __x86_64__ || defined __x86_64 || defined __amd64__ || defined __amd64 || defined _M_X64 || defined _M_AMD64) +#define GMX_IS_X86_64 1 +#else +#define GMX_IS_X86_64 0 +#endif + //! Constant that tells what the architecture is static constexpr Architecture c_architecture = -#if defined __i386__ || defined __i386 || defined _X86_ || defined _M_IX86 || \ - defined __x86_64__ || defined __amd64__ || defined _M_X64 || defined _M_AMD64 +#if GMX_IS_X86_32 || GMX_IS_X86_64 Architecture::X86; #elif defined __arm__ || defined __arm || defined _M_ARM || defined __aarch64_ Architecture::Arm; diff --git a/src/gromacs/hardware/cpuinfo.cpp b/src/gromacs/hardware/cpuinfo.cpp index 3ff092d284..273d8d8e2c 100644 --- a/src/gromacs/hardware/cpuinfo.cpp +++ b/src/gromacs/hardware/cpuinfo.cpp @@ -164,16 +164,19 @@ executeX86CpuID(unsigned int gmx_unused level, *ebx = 0; *edx = 0; -# if (defined __i386__ || defined __i386 || defined _X86_ || defined _M_IX86) && defined(__PIC__) +# if GMX_IS_X86_32 && defined(__PIC__) // Avoid clobbering the global offset table in 32-bit pic code (ebx register) __asm__ __volatile__ ("xchgl %%ebx, %1 \n\t" "cpuid \n\t" "xchgl %%ebx, %1 \n\t" : "+a" (*eax), "+r" (*ebx), "+c" (*ecx), "+d" (*edx)); -# else +# elif GMX_IS_X86_64 // i386 without PIC, or x86-64. Things are easy and we can clobber any reg we want __asm__ __volatile__ ("cpuid \n\t" : "+a" (*eax), "+b" (*ebx), "+c" (*ecx), "+d" (*edx)); +# else + // Not a normal x86, which could happen when a compiler + // targetting non-x86 pretends to be GCC. # endif return 0; -- 2.11.4.GIT