From c8801996294a0418d08c5cca78989119f8763767 Mon Sep 17 00:00:00 2001 From: Nicolas Morey-Chaisemartin Date: Mon, 4 Jun 2018 10:37:32 +0200 Subject: [PATCH] buildlib: Use -msse if the compiler does not support target(sse) Some older compilers (eg gcc 4.7) support the attribute syntax, but don't allow use of the xmmintrin.h header file. Instead they require full modules to be compiled with the -msse flag. Detect this and provide the flag if required. Cc: stable@linux-rdma.org # v15 Signed-off-by: Nicolas Morey-Chaisemartin Signed-off-by: Jason Gunthorpe # Conflicts: # CMakeLists.txt # buildlib/RDMA_EnableCStd.cmake --- CMakeLists.txt | 5 ++++ buildlib/RDMA_EnableCStd.cmake | 43 ++++++++++++++++++++++++++++++++++ util/CMakeLists.txt | 1 + 3 files changed, 49 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7bf6f8fbd..7b5e5e9aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -256,6 +256,8 @@ if (NOT HAVE_SPARSE) RDMA_DoFixup("${HAVE_STDATOMIC}" "stdatomic.h") endif() +RDMA_Check_SSE(HAVE_TARGET_SSE) + # Enable development support features # Prune unneeded shared libraries during linking RDMA_AddOptLDFlag(CMAKE_EXE_LINKER_FLAGS SUPPORTS_AS_NEEDED "-Wl,--as-needed") @@ -524,3 +526,6 @@ endif() if (NOT HAVE_C_WREDUNDANT_DECLS) message(STATUS " -Wredundant-decls does NOT work") endif() +if (NOT HAVE_TARGET_SSE) + message(STATUS " attribute(target(\"sse\")) does NOT work") +endif() diff --git a/buildlib/RDMA_EnableCStd.cmake b/buildlib/RDMA_EnableCStd.cmake index c8a8c1f55..9bda71bb4 100644 --- a/buildlib/RDMA_EnableCStd.cmake +++ b/buildlib/RDMA_EnableCStd.cmake @@ -55,3 +55,46 @@ function(RDMA_EnableCStd) set(CMAKE_C_STANDARD 11 PARENT_SCOPE) endif() endfunction() + +function(RDMA_Check_SSE TO_VAR) + set(SSE_CHECK_PROGRAM " + #include + #if defined(__i386__) + #include + #endif + int __attribute__((target(\"sse\"))) main(int argc, char *argv[]) + { + int ret = 0; + + #if defined(__i386__) + __m128 tmp = {}; + tmp = _mm_loadl_pi(tmp, (__m64 *)&main); + _mm_storel_pi((__m64 *)&main, tmp); + ret = memchr(&tmp, 0, sizeof(tmp)) == &tmp; + #endif + return ret; + }") + + CHECK_C_SOURCE_COMPILES( + "${SSE_CHECK_PROGRAM}" + HAVE_TARGET_SSE + FAIL_REGEX "warning") + + if(NOT HAVE_TARGET_SSE) + # Older compiler, we can work around this by adding -msse instead of + # relying on the function attribute. + set(CMAKE_REQUIRED_FLAGS "-msse") + CHECK_C_SOURCE_COMPILES( + "${SSE_CHECK_PROGRAM}" + NEED_MSSE_FLAG + FAIL_REGEX "warning") + set(CMAKE_REQUIRED_FLAGS) + + if(NEED_MSSE_FLAG) + set(SSE_FLAGS "-msse" PARENT_SCOPE) + else() + message(FATAL_ERROR "Can not figure out how to turn on sse instructions for i386") + endif() + endif() + set(${TO_VAR} "${HAVE_TARGET_SSE}" PARENT_SCOPE) +endFunction() diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index 57d910965..4e9c4f16f 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -16,6 +16,7 @@ if (HAVE_COHERENT_DMA) set(C_FILES ${C_FILES} mmio.c ) + set_source_files_properties(mmio.c PROPERTIES COMPILE_FLAGS "${SSE_FLAGS}") endif() add_library(rdma_util STATIC ${C_FILES})