Skip to content

Commit

Permalink
buildlib: Use -msse if the compiler does not support target(sse)
Browse files Browse the repository at this point in the history
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: [email protected] # v15
Signed-off-by: Nicolas Morey-Chaisemartin <[email protected]>
Signed-off-by: Jason Gunthorpe <[email protected]>

# Conflicts:
#	CMakeLists.txt
#	buildlib/RDMA_EnableCStd.cmake
  • Loading branch information
nmorey committed Jun 11, 2018
1 parent 7bdca36 commit c880199
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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()
43 changes: 43 additions & 0 deletions buildlib/RDMA_EnableCStd.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 <string.h>
#if defined(__i386__)
#include <xmmintrin.h>
#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()
1 change: 1 addition & 0 deletions util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down

0 comments on commit c880199

Please sign in to comment.