From 8e7505b8ce2f8705c023d5d77ac923758a9add1a Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Thu, 21 Mar 2013 18:51:21 -0700 Subject: [PATCH] Don't use CPUID call on targets that don't support it --- Sources/Plasma/CoreLib/CMakeLists.txt | 10 ++++++++++ Sources/Plasma/CoreLib/hsCpuID.cpp | 20 +++++++++++++------- cmake/check_cpuid.cpp | 11 +++++++++++ 3 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 cmake/check_cpuid.cpp diff --git a/Sources/Plasma/CoreLib/CMakeLists.txt b/Sources/Plasma/CoreLib/CMakeLists.txt index 7ff45188..3c23afba 100644 --- a/Sources/Plasma/CoreLib/CMakeLists.txt +++ b/Sources/Plasma/CoreLib/CMakeLists.txt @@ -21,6 +21,16 @@ if(NOT WCHAR_BYTES) endif(NOT WCHAR_BYTES) add_definitions(-DWCHAR_BYTES=${WCHAR_BYTES}) +try_compile(HAVE_CPUID ${PROJECT_BINARY_DIR} + ${PROJECT_SOURCE_DIR}/cmake/check_cpuid.cpp + OUTPUT_VARIABLE OUTPUT) +if(HAVE_CPUID) + add_definitions(-DHAVE_CPUID) + message("CPUID header found -- using hardware math acceleration when available") +else() + message("CPUID header not found -- using software math") +endif() + set(CoreLib_SOURCES HeadSpin.cpp hsBitVector.cpp diff --git a/Sources/Plasma/CoreLib/hsCpuID.cpp b/Sources/Plasma/CoreLib/hsCpuID.cpp index 2944c3c4..c80a81a4 100644 --- a/Sources/Plasma/CoreLib/hsCpuID.cpp +++ b/Sources/Plasma/CoreLib/hsCpuID.cpp @@ -40,12 +40,18 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com *==LICENSE==*/ -#if defined(_MSC_VER) || ((defined(_WIN32) || defined(_WIN64)) && defined(__INTEL_COMPILER)) -# include -# define MSC_COMPATIBLE -#elif defined(__GNUC__) -# include -# define GCC_COMPATIBLE +#if defined(HAVE_CPUID) +# if defined(_MSC_VER) || ((defined(_WIN32) || defined(_WIN64)) && defined(__INTEL_COMPILER)) +# include +# define MSC_COMPATIBLE +# elif defined(__GNUC__) +# include +# define GCC_COMPATIBLE +# else +# define SOFTWARE_ONLY +# endif +#else +# define SOFTWARE_ONLY #endif #include "hsCpuID.h" @@ -57,7 +63,7 @@ hsCpuId::hsCpuId() { const unsigned int ssse3_flag = 1<<9; const unsigned int sse41_flag = 1<<19; const unsigned int sse42_flag = 1<<20; - const unsigned int avx_flag = 1 << 28; + const unsigned int avx_flag = 1<<28; unsigned int ax = 0, bx = 0, cx = 0, dx = 0; diff --git a/cmake/check_cpuid.cpp b/cmake/check_cpuid.cpp new file mode 100644 index 00000000..eb3e6616 --- /dev/null +++ b/cmake/check_cpuid.cpp @@ -0,0 +1,11 @@ +#if defined(_MSC_VER) || ((defined(_WIN32) || defined(_WIN64)) && defined(__INTEL_COMPILER)) +# include +#elif defined(__GNUC__) +# include +#endif + +/* Just needed to look for the headers -- this just makes the compiler happy. */ +int main(int argc, char *argv[]) +{ + return 0; +}