From 385d172c6f605843905f15fe8b56c080ab5c88c9 Mon Sep 17 00:00:00 2001 From: Jose Luis Rivero Date: Sat, 12 Nov 2016 18:15:56 +0100 Subject: [PATCH 1/6] Split SSE cmake option to match the semantic meaning Current FCL_HAVE_SSE is enabling march=native when compiled with gcc/clang. This flag enables much more than just SSE and it is specially dangerous when building packages. The current commit deprecate the option and change it by other two different ones: * FCL_USE_HOST_CUSTOM_CFLAGS (default off): same effect than then previous one, hopefully with a more decriptive name. * FCL_USE_X64_SSE (default on): enable the standard set of SEE flags supported in every x64 machine. --- CMakeLists.txt | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 363c78b0f..fc58bfd01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,10 +50,32 @@ else() endif() # Whether to enable SSE -option(FCL_USE_SSE "Whether FCL should SSE instructions" ON) +option(FCL_USE_X64_SSE "Whether FCL should x64 SSE instructions" ON) +if (FCL_USE_X64_SSE) + if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpmath=sse -msse -msse2 -msse3 -mssse3") + elseif(MSVC) + add_definitions(/arch:SSE2) + endif() +endif() + +option(FCL_USE_HOST_CUSTOM_CFLAGS "Whether FCL should use cflags from the host used to compile" OFF) +if (FCL_USE_HOST_CUSTOM_CFLAGS) + if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") + else() + message(WARNING "FCL_USE_HOST_CUSTOM_CFLAGS is only supported in Linux. No effect.") + endif() +endif() + +# DEPRECATED: old cmake option. Not strictly correct from the semantic point of view +# it was activating march=native, not only SSE +option(FCL_USE_SSE "(deprecated) Whether FCL should SSE instructions" OFF) if(FCL_USE_SSE) set(FCL_HAVE_SSE TRUE) if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + message(DEPRECATION "FCL_USE_SSE is deprecated please use: FCL_USE_X64_SSE or FCL_USE_HOST_CUSTOM_CFLAGS. " + "If you want to replicate the previous behaviour use FCL_USE_HOST_CUSTOM_CFLAGS") add_definitions(-march=native) elseif(MSVC) add_definitions(/arch:SSE2) From 7d02fe55e757bf87bd38d39e5580d1486501deea Mon Sep 17 00:00:00 2001 From: Jose Luis Rivero Date: Fri, 18 Nov 2016 13:14:17 +0100 Subject: [PATCH 2/6] Use SSE2 flags only in Win32 platform --- CMakeLists.txt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fc58bfd01..1c7e6fff0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,13 +50,18 @@ else() endif() # Whether to enable SSE +set (SSE_FLAGS "" LIST) option(FCL_USE_X64_SSE "Whether FCL should x64 SSE instructions" ON) if (FCL_USE_X64_SSE) if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpmath=sse -msse -msse2 -msse3 -mssse3") + set(SSE_FLAGS -mfpmath=sse -msse -msse2 -msse3 -mssse3) elseif(MSVC) - add_definitions(/arch:SSE2) + # Win64 will add the flag automatically + if("$CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32") + set(SSE_FLAGS /arch:SSE2) + endif() endif() + add_compile_options(${SSE_FLAGS}) endif() option(FCL_USE_HOST_CUSTOM_CFLAGS "Whether FCL should use cflags from the host used to compile" OFF) @@ -78,7 +83,10 @@ if(FCL_USE_SSE) "If you want to replicate the previous behaviour use FCL_USE_HOST_CUSTOM_CFLAGS") add_definitions(-march=native) elseif(MSVC) - add_definitions(/arch:SSE2) + # Win64 will add the flag automatically + if("$CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32") + add_definitions(/arch:SSE2) + endif() endif() endif() From 6c1bdd1a4439e0a5319b24c5bd374389b1879fc5 Mon Sep 17 00:00:00 2001 From: Jose Luis Rivero Date: Fri, 18 Nov 2016 13:39:18 +0100 Subject: [PATCH 3/6] Use WARNING instead of DEPRECATION --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c7e6fff0..afabaee9b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,8 +79,8 @@ option(FCL_USE_SSE "(deprecated) Whether FCL should SSE instructions" OFF) if(FCL_USE_SSE) set(FCL_HAVE_SSE TRUE) if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - message(DEPRECATION "FCL_USE_SSE is deprecated please use: FCL_USE_X64_SSE or FCL_USE_HOST_CUSTOM_CFLAGS. " - "If you want to replicate the previous behaviour use FCL_USE_HOST_CUSTOM_CFLAGS") + message(WARNING "FCL_USE_SSE is deprecated please use: FCL_USE_X64_SSE or FCL_USE_HOST_CUSTOM_CFLAGS. " + "If you want to replicate the previous behaviour use FCL_USE_HOST_CUSTOM_CFLAGS") add_definitions(-march=native) elseif(MSVC) # Win64 will add the flag automatically From 4574cd04699c2a9d9e20817afa979b815f26a225 Mon Sep 17 00:00:00 2001 From: Jose Luis Rivero Date: Fri, 18 Nov 2016 13:39:41 +0100 Subject: [PATCH 4/6] Export the SSE_FLAGS to consumers using target_compile_options --- src/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2201e214b..95c25c6dd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,6 +5,9 @@ else() add_library(${PROJECT_NAME} SHARED ${FCL_HEADERS} ${FCL_SOURCE_CODE}) endif() +# Be sure to pass to the consumer the set of SIMD used in the compilation +target_compile_options(${PROJECT_NAME} PUBLIC ${SSE_FLAGS}) + set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${FCL_VERSION} SOVERSION ${FCL_ABI_VERSION}) From cf47a21d0dc62c5b0bff6803f464db74159ceaf7 Mon Sep 17 00:00:00 2001 From: Jose Luis Rivero Date: Sun, 20 Nov 2016 00:04:03 +0100 Subject: [PATCH 5/6] Fix invalid use of LIST in set command --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index afabaee9b..3c6659a12 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,7 +50,7 @@ else() endif() # Whether to enable SSE -set (SSE_FLAGS "" LIST) +set (SSE_FLAGS "") option(FCL_USE_X64_SSE "Whether FCL should x64 SSE instructions" ON) if (FCL_USE_X64_SSE) if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") From 4a6d5f39875c9fb4de67d26744cb042322833c66 Mon Sep 17 00:00:00 2001 From: Jose Luis Rivero Date: Mon, 21 Nov 2016 12:39:16 +0100 Subject: [PATCH 6/6] Rename cmake parameter FCL_USE_HOST_CUSTOM_CFLAGS to FCL_USE_HOST_NATIVE_ARCH --- CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c6659a12..263268e7d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,12 +64,12 @@ if (FCL_USE_X64_SSE) add_compile_options(${SSE_FLAGS}) endif() -option(FCL_USE_HOST_CUSTOM_CFLAGS "Whether FCL should use cflags from the host used to compile" OFF) -if (FCL_USE_HOST_CUSTOM_CFLAGS) +option(FCL_USE_HOST_NATIVE_ARCH "Whether FCL should use cflags from the host used to compile" OFF) +if (FCL_USE_HOST_NATIVE_ARCH) if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") else() - message(WARNING "FCL_USE_HOST_CUSTOM_CFLAGS is only supported in Linux. No effect.") + message(WARNING "FCL_USE_HOST_NATIVE_ARCH is only supported in Linux. No effect.") endif() endif() @@ -79,8 +79,8 @@ option(FCL_USE_SSE "(deprecated) Whether FCL should SSE instructions" OFF) if(FCL_USE_SSE) set(FCL_HAVE_SSE TRUE) if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - message(WARNING "FCL_USE_SSE is deprecated please use: FCL_USE_X64_SSE or FCL_USE_HOST_CUSTOM_CFLAGS. " - "If you want to replicate the previous behaviour use FCL_USE_HOST_CUSTOM_CFLAGS") + message(WARNING "FCL_USE_SSE is deprecated please use: FCL_USE_X64_SSE or FCL_USE_HOST_NATIVE_ARCH. " + "If you want to replicate the previous behaviour use FCL_USE_HOST_NATIVE_ARCH") add_definitions(-march=native) elseif(MSVC) # Win64 will add the flag automatically