From 90d79158eebbb2dc9bc0d8f1041e555a7b9e287b Mon Sep 17 00:00:00 2001 From: Tobias Frost Date: Fri, 19 Jun 2015 15:50:17 +0200 Subject: [PATCH 1/3] Make the CPUSTRING and additional from default optimizations configureable --- neo/CMakeLists.txt | 11 ++++++++++- neo/idlib/sys/sys_defines.h | 4 ++++ neo/idlib/sys/sys_intrinsics.h | 3 +++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/neo/CMakeLists.txt b/neo/CMakeLists.txt index 625fbf15..c5e11188 100644 --- a/neo/CMakeLists.txt +++ b/neo/CMakeLists.txt @@ -36,6 +36,10 @@ option(USE_SYSTEM_LIBJPEG option(USE_SYSTEM_LIBGLEW "Use the system libglew instead of the bundled one" OFF) +set(CPU_TYPE "" CACHE STRING "When set, passes this string as CPU-ID and disables CPU specific optimizatin which are not default for the compiler") + +set(CPU_OPTIMIZATION "-mmmx -msse -msse2" CACHE STRING "Which CPU specific optimitations should be used beside the compiler's default?") + if(UNIX) set(OPENAL TRUE) endif() @@ -61,7 +65,12 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang") #add_definitions(-Wall) add_definitions(-Werror=format-security) add_definitions(-Werror=format) - add_definitions(-mmmx -msse -msse2) + if(CPU_TYPE) + add_definitions(-DCPUSTRING="${CPU_TYPE}") + endif() + if (CPU_OPTIMIZATION) + add_definitions(${CPU_OPTIMIZATION}) + endif() if(WIN32) # require msvcr70.dll or newer for _aligned_malloc etc # I think it is from Visual C++ .NET 2002, so it should be available on any remotely modern system. diff --git a/neo/idlib/sys/sys_defines.h b/neo/idlib/sys/sys_defines.h index 3daa5e59..c8edb8a1 100644 --- a/neo/idlib/sys/sys_defines.h +++ b/neo/idlib/sys/sys_defines.h @@ -104,10 +104,14 @@ If you have questions concerning this license or the applicable additional terms #elif defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) +#ifndef CPUSTRING #if defined(__i386__) #define CPUSTRING "x86" #elif defined(__x86_64__) #define CPUSTRING "x86_86" +#else +#error unknown CPU +#endif #endif #if defined(__FreeBSD__) diff --git a/neo/idlib/sys/sys_intrinsics.h b/neo/idlib/sys/sys_intrinsics.h index 6cf1beca..64a387a3 100644 --- a/neo/idlib/sys/sys_intrinsics.h +++ b/neo/idlib/sys/sys_intrinsics.h @@ -29,7 +29,10 @@ If you have questions concerning this license or the applicable additional terms #ifndef __SYS_INTRIINSICS_H__ #define __SYS_INTRIINSICS_H__ +#if defined(__x86_64__) +// Enable this only on amd64 #define USE_INTRINSICS +#endif #if defined(USE_INTRINSICS) #include From 332fc8d0e75ac424b65de9f11907f3a078aafcf3 Mon Sep 17 00:00:00 2001 From: Tobias Frost Date: Fri, 19 Jun 2015 15:56:24 +0200 Subject: [PATCH 2/3] Update description of CPU_TYPE -- it does not disable anything anymore --- neo/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo/CMakeLists.txt b/neo/CMakeLists.txt index c5e11188..b6662492 100644 --- a/neo/CMakeLists.txt +++ b/neo/CMakeLists.txt @@ -36,7 +36,7 @@ option(USE_SYSTEM_LIBJPEG option(USE_SYSTEM_LIBGLEW "Use the system libglew instead of the bundled one" OFF) -set(CPU_TYPE "" CACHE STRING "When set, passes this string as CPU-ID and disables CPU specific optimizatin which are not default for the compiler") +set(CPU_TYPE "" CACHE STRING "When set, passes this string as CPU-ID which will be embedded into the binary.") set(CPU_OPTIMIZATION "-mmmx -msse -msse2" CACHE STRING "Which CPU specific optimitations should be used beside the compiler's default?") From 9212ed4263e2e147a39cde37d4fd372bf146ef01 Mon Sep 17 00:00:00 2001 From: Tobias Frost Date: Fri, 19 Jun 2015 16:09:30 +0200 Subject: [PATCH 3/3] Propagate USE_INTRINSICS through CMake --- neo/CMakeLists.txt | 5 +++++ neo/idlib/sys/sys_intrinsics.h | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/neo/CMakeLists.txt b/neo/CMakeLists.txt index b6662492..92ca88e8 100644 --- a/neo/CMakeLists.txt +++ b/neo/CMakeLists.txt @@ -40,6 +40,8 @@ set(CPU_TYPE "" CACHE STRING "When set, passes this string as CPU-ID which will set(CPU_OPTIMIZATION "-mmmx -msse -msse2" CACHE STRING "Which CPU specific optimitations should be used beside the compiler's default?") +option(USE_INTRINSICS "Compile using intrinsics (e.g mmx, sse, msse2)" ON) + if(UNIX) set(OPENAL TRUE) endif() @@ -71,6 +73,9 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang") if (CPU_OPTIMIZATION) add_definitions(${CPU_OPTIMIZATION}) endif() + if (USE_INTRINSICS) + add_definitions(-DUSE_INTRINSICS) + endif() if(WIN32) # require msvcr70.dll or newer for _aligned_malloc etc # I think it is from Visual C++ .NET 2002, so it should be available on any remotely modern system. diff --git a/neo/idlib/sys/sys_intrinsics.h b/neo/idlib/sys/sys_intrinsics.h index 64a387a3..eab03980 100644 --- a/neo/idlib/sys/sys_intrinsics.h +++ b/neo/idlib/sys/sys_intrinsics.h @@ -29,11 +29,6 @@ If you have questions concerning this license or the applicable additional terms #ifndef __SYS_INTRIINSICS_H__ #define __SYS_INTRIINSICS_H__ -#if defined(__x86_64__) -// Enable this only on amd64 -#define USE_INTRINSICS -#endif - #if defined(USE_INTRINSICS) #include #endif