From 367755e7f76786b934420517c2150892eceeb4a8 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Fri, 2 Sep 2016 14:38:21 +0800 Subject: [PATCH] cmake: pass -DINTEL* to gf-complete cflags * in addition to the -march=foobar, we also need to pass -DFOOBAR to gf-complete sources' cflags, so that the SIMD instructions can be generated as expected. * also extract the compiler support for instruction extensions detections into SIMDExt.cmake. * and only check the compiler support if CMAKE_SYSTEM_PROCESSOR matches with the instruction-set/arch to be checked. Signed-off-by: tone.zhang Signed-off-by: Kefu Chai --- cmake/modules/SIMDExt.cmake | 66 ++++++++++++++++++++++++++++++ src/CMakeLists.txt | 72 --------------------------------- src/erasure-code/CMakeLists.txt | 5 ++- src/test/CMakeLists.txt | 2 + 4 files changed, 71 insertions(+), 74 deletions(-) create mode 100644 cmake/modules/SIMDExt.cmake diff --git a/cmake/modules/SIMDExt.cmake b/cmake/modules/SIMDExt.cmake new file mode 100644 index 00000000000..bc08514273e --- /dev/null +++ b/cmake/modules/SIMDExt.cmake @@ -0,0 +1,66 @@ +# detect SIMD extentions +# +# ARM_NEON_FLAGS +# +# HAVE_ARMV8_CRC +# HAVE_NEON +# HAVE_SSE +# HAVE_SSE2 +# +# INTEL_SSE4_1 +# INTEL_SSE4_2 +# +# SSE3_FLAGS +# SSE4_FLAGS +# + +if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|AARCH64") + CHECK_C_COMPILER_FLAG(-march=armv8-a+crc HAVE_ARMV8_CRC) + if(HAVE_ARMV8_CRC) + set(ARM_NEON_FLAGS "-march=armv8-a+crc -DARCH_AARCH64") + endif() + CHECK_C_COMPILER_FLAG(-march=armv8-a+simd HAVE_NEON) + if(HAVE_NEON) + set(ARM_NEON_FLAGS "-march=armv8-a+simd -DARCH_AARCH64 -DARM_NEON") + endif() +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm|ARM") + CHECK_C_COMPILER_FLAG(-mfpu=neon HAVE_NEON) + if(HAVE_NEON) + set(ARM_NEON_FLAGS "-mfpu=neon -DARM_NEON") + endif() +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "i386|i686|amd64|x86_64|AMD64") + set(SSE3_FLAGS) + CHECK_C_COMPILER_FLAG(-msse HAVE_SSE) + if(HAVE_SSE) + set(SSE3_FLAGS "${SSE3_FLAGS} -msse -DINTEL_SSE") + endif() + + CHECK_C_COMPILER_FLAG(-msse2 HAVE_SSE2) + if(HAVE_SSE2) + set(SSE3_FLAGS "${SSE3_FLAGS} -msse2 -DINTEL_SSE2") + endif() + + CHECK_C_COMPILER_FLAG(-msse3 HAVE_SSE3) + if(HAVE_SSE3) + set(SSE3_FLAGS "${SSE3_FLAGS} -msse3 -DINTEL_SSE3") + endif() + + CHECK_C_COMPILER_FLAG(-mssse3 SUPPORTS_SSSE3) + if(SUPPORTS_SSSE3) + set(SSE3_FLAGS "${SSE3_FLAGS} -mssse3 -DINTEL_SSSE3") + endif() + + # pclmul is not enabled in SSE3, otherwise we need another + # flavor or an cmake option for enabling it + + set(SSE4_FLAGS ${SSE3_FLAGS}) + CHECK_C_COMPILER_FLAG(-msse4.1 INTEL_SSE4_1) + if(SUPPORTS_SSE41) + set(SSE4_FLAGS "${SSE4_FLAGS} -msse41 -DINTEL_SSE4") + endif() + + CHECK_C_COMPILER_FLAG(-msse4.2 INTEL_SSE4_2) + if(SUPPORTS_SSE42) + set(SSE4_FLAGS "${SSE4_FLAGS} -msse42 -DINTEL_SSE4") + endif() +endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 10f6b3079e4..9afe2b3ef91 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -146,78 +146,6 @@ if(COMPILER_SUPPORTS_DIAGNOSTICS_COLOR) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=${DIAGNOSTICS_COLOR}") endif() - -## detect sse support - -# create a tmp file with an empty main() -set(sse_srcs "${CMAKE_BINARY_DIR}/src/erasure-code/jerasure/tmp_sse.c") -file(WRITE ${sse_srcs} "void main() {}") - -# try each -msse flag -try_compile(INTEL_SSE ${CMAKE_BINARY_DIR} ${sse_srcs} - COMPILE_DEFINITIONS "-msse") -try_compile(INTEL_SSE2 ${CMAKE_BINARY_DIR} ${sse_srcs} - COMPILE_DEFINITIONS "-msse2") -try_compile(INTEL_SSE3 ${CMAKE_BINARY_DIR} ${sse_srcs} - COMPILE_DEFINITIONS "-msse3") -try_compile(INTEL_SSSE3 ${CMAKE_BINARY_DIR} ${sse_srcs} - COMPILE_DEFINITIONS "-mssse3") -try_compile(INTEL_SSE4_1 ${CMAKE_BINARY_DIR} ${sse_srcs} - COMPILE_DEFINITIONS "-msse4.1") -try_compile(INTEL_SSE4_2 ${CMAKE_BINARY_DIR} ${sse_srcs} - COMPILE_DEFINITIONS "-msse4.2") -try_compile(ARM_NEON ${CMAKE_BINARY_DIR} ${sse_srcs} - COMPILE_DEFINITIONS "-mfpu=neon") -try_compile(ARM_NEON2 ${CMAKE_BINARY_DIR} ${sse_srcs} - COMPILE_DEFINITIONS "-march=armv8-a+simd") -try_compile(ARM_CRC ${CMAKE_BINARY_DIR} ${sse_srcs} - COMPILE_DEFINITIONS "-march=armv8-a+crc") - -# clean up tmp file -file(REMOVE ${sse_srcs}) - -if(ARM_CRC) - set(HAVE_ARMV8_CRC 1) - set(ARM_CRC_FLAGS "-march=armv8-a+crc -DARCH_AARCH64") -endif(ARM_CRC) - -if(ARM_NEON OR ARM_NEON2) - set(HAVE_NEON 1) - if(ARM_NEON) - set(ARM_NEON_FLAGS "-mfpu=neon -DARM_NEON") - else(ARM_NEON) - set(ARM_NEON_FLAGS "-march=armv8-a+simd -DARCH_AARCH64 -DARM_NEON") - endif(ARM_NEON) -else(ARM_NEON OR ARM_NEON2) - message(STATUS "Skipping target ec_jerasure_neon & ec_shec_neon: Architecture not ARM") -endif(ARM_NEON OR ARM_NEON2) - -if(INTEL_SSE) - set(HAVE_SSE 1) - set(SSE3_FLAGS "-msse") - if (INTEL_SSE2) - set(HAVE_SSE2 1) - set(SSE3_FLAGS "${SSE3_FLAGS} -msse2") - endif (INTEL_SSE2) - if (INTEL_SSE3) - set(SSE3_FLAGS "${SSE3_FLAGS} -msse3") - endif (INTEL_SSE3) - if (INTEL_SSSE3) - set(SSE3_FLAGS "${SSE3_FLAGS} -mssse3") - endif (INTEL_SSSE3) -else(INTEL_SSE) - message(STATUS "Skipping target ec_jerasure_sse3 & ec_shec_sse3: -msse not supported") -endif(INTEL_SSE) - -if(INTEL_SSE4_1) - set(SSE4_FLAGS "${SSE3_FLAGS} -msse4.1") - if (INTEL_SSE4_2) - set(SSE4_FLAGS "${SSE4_FLAGS} -msse4.2") - endif (INTEL_SSE4_2) -else(INTEL_SSE4_1) - message(STATUS "Skipping target ec_jerasure_sse4 & ec_shec_sse4: -msse4.1 not supported") -endif(INTEL_SSE4_1) - set(EXTRALIBS rt ${CMAKE_DL_LIBS} ${ATOMIC_OPS_LIBRARIES}) if(LINUX) set(LIB_RESOLV resolv) diff --git a/src/erasure-code/CMakeLists.txt b/src/erasure-code/CMakeLists.txt index 7859a7f20d1..86ecbbc8133 100644 --- a/src/erasure-code/CMakeLists.txt +++ b/src/erasure-code/CMakeLists.txt @@ -7,16 +7,17 @@ include_directories(jerasure/jerasure/include) include_directories(jerasure/gf-complete/include) include_directories(jerasure) +include(SIMDExt) if(TRUE) list(APPEND jerasure_flavors generic) endif() -if(ARM_NEON OR ARM_NEON2) +if(HAVE_NEON) list(APPEND jerasure_flavors neon) endif() -if(INTEL_SSE) +if(HAVE_SSE) list(APPEND jerasure_flavors sse3) endif() diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 8c1c2814ad4..93283537d09 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -363,6 +363,8 @@ target_link_libraries(ceph_multi_stress_watch librados global radostest ${BLKID_LIBRARIES} ${CMAKE_DL_LIBS}) #ceph_perf_local +include(SIMDExt) + add_executable(ceph_perf_local perf_local.cc perf_helper.cc) -- 2.47.3