]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
cmake: invoke the compiler to test arch features
authorMatthew Barr <matthew.barr@intel.com>
Mon, 23 May 2016 04:57:48 +0000 (14:57 +1000)
committerMatthew Barr <matthew.barr@intel.com>
Tue, 24 May 2016 01:26:38 +0000 (11:26 +1000)
We require SSSE3, and optionally support AVX2, and the best way of testing
the compiler and compile flags is to run the compiler.

CMakeLists.txt
cmake/arch.cmake [new file with mode: 0644]

index 7439f50b8513bb568bde9e522e960598361b108c..fe486eedd2f29ab428e3f7af522ffba731acbab5 100644 (file)
@@ -237,6 +237,9 @@ if (RELEASE_BUILD)
     endif()
 endif()
 
+# ensure we are building for the right target arch
+include (${CMAKE_MODULE_PATH}/arch.cmake)
+
 # testing a builtin takes a little more work
 CHECK_C_SOURCE_COMPILES("void *aa_test(void *x) { return __builtin_assume_aligned(x, 16);}\nint main(void) { return 0; }" HAVE_CC_BUILTIN_ASSUME_ALIGNED)
 CHECK_CXX_SOURCE_COMPILES("void *aa_test(void *x) { return __builtin_assume_aligned(x, 16);}\nint main(void) { return 0; }" HAVE_CXX_BUILTIN_ASSUME_ALIGNED)
@@ -403,7 +406,6 @@ set (hs_exec_SRCS
     src/fdr/flood_runtime.h
     src/fdr/fdr_loadval.h
     src/fdr/teddy.c
-    src/fdr/teddy_avx2.c
     src/fdr/teddy.h
     src/fdr/teddy_internal.h
     src/fdr/teddy_runtime_common.h
@@ -513,7 +515,6 @@ set (hs_exec_SRCS
     src/util/fatbit.h
     src/util/fatbit.c
     src/util/join.h
-    src/util/masked_move.c
     src/util/masked_move.h
     src/util/multibit.h
     src/util/multibit_internal.h
@@ -540,6 +541,14 @@ set (hs_exec_SRCS
     src/database.h
 )
 
+if (HAVE_AVX2)
+    set (hs_exec_SRCS
+        ${hs_exec_SRCS}
+        src/fdr/teddy_avx2.c
+        src/util/masked_move.c
+        )
+endif ()
+
 
 SET (hs_SRCS
     ${hs_HEADERS}
diff --git a/cmake/arch.cmake b/cmake/arch.cmake
new file mode 100644 (file)
index 0000000..c00401d
--- /dev/null
@@ -0,0 +1,42 @@
+# detect architecture features
+#
+# must be called after determining where compiler intrinsics are defined
+
+if (HAVE_C_X86INTRIN_H)
+    set (INTRIN_INC_H "x86intrin.h")
+elseif (HAVE_C_INTRIN_H)
+    set (INTRIN_INC_H "intrin.h")
+else ()
+    message (FATAL_ERROR "No intrinsics header found")
+endif ()
+
+
+set (CMAKE_REQUIRED_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_C_FLAGS}")
+# ensure we have the minimum of SSSE3 - call a SSSE3 intrinsic
+CHECK_C_SOURCE_COMPILES("#include <${INTRIN_INC_H}>
+int main() {
+    __m128i a = _mm_set1_epi8(1);
+    (void)_mm_shuffle_epi8(a, a);
+}" HAVE_SSSE3)
+
+if (NOT HAVE_SSSE3)
+    message(FATAL_ERROR "A minimum of SSSE3 compiler support is required")
+endif ()
+
+# now look for AVX2
+CHECK_C_SOURCE_COMPILES("#include <${INTRIN_INC_H}>
+#if !defined(__AVX2__)
+#error no avx2
+#endif
+
+int main(){
+    __m256i z = _mm256_setzero_si256();
+    (void)_mm256_xor_si256(z, z);
+}" HAVE_AVX2)
+
+if (NOT HAVE_AVX2)
+    message(STATUS "Building without AVX2 support")
+endif ()
+
+unset (CMAKE_REQUIRED_FLAGS)
+unset (INTRIN_INC_H)