Commit 4afa162b authored by Peter Steinbach's avatar Peter Steinbach Committed by GitHub

Merge pull request #12 from psteinb/cmake-detect-feature

Cmake detect feature
parents be79a839 aca0b90f
......@@ -35,6 +35,8 @@ endif()
check_cxx_compiler_flag(-Wl,-Bsymbolic HAS_BSYMBOLIC_COMPILERFLAG)
check_cxx_compiler_flag("-Xclang -march=native" HAS_XCLANG_COMPILERFLAG)
check_cxx_compiler_flag("-march=native" HAS_MARCH_COMPILERFLAG)
check_cxx_compiler_flag("-xHost" HAS_XHOST_COMPILERFLAG)
check_cxx_compiler_flag(-Wall HAS_WALL_COMPILERFLAG)
check_cxx_compiler_flag(-ggdb HAS_GGDB_COMPILERFLAG)
......
#ifndef COMPASS_CT_PREPROCESSOR_IMPL_H_
#define COMPASS_CT_PREPROCESSOR_IMPL_H_
#ifndef WIN32
#if defined __SSE2__ && defined __SSE2_MATH__
#define COMPASS_HAS_SSE2
#endif
#else
#if _M_IX86_FP >= 2
#define COMPASS_HAS_SSE2
#if defined(__SSE2__) || defined(__SSE2_MATH__) // && __SSE2__ != 0 && __SSE2_MATH__ != 0
#define COMPASS_CT_HAS_SSE2 1
#endif
#endif
#ifndef WIN32
#if defined __SSE3__ && defined __SSSE3__
#define COMPASS_HAS_SSE3
#if defined(__SSE3__) && defined(__SSSE3__)
#define COMPASS_CT_HAS_SSE3 1
#endif
#if defined __SSE4_2__ && defined __SSE4_1__
#define COMPASS_HAS_SSE4
#if defined(__SSE4_2__) && defined(__SSE4_1__)
#define COMPASS_CT_HAS_SSE4 1
#endif
#else
//TODO: try to warn users on Windows that we are enabling SSE3 + SSE4 upon assumption here
#define COMPASS_HAS_SSE3
#define COMPASS_HAS_SSE4
#if _M_IX86_FP >= 2
#define COMPASS_CT_HAS_SSE2 1
#define COMPASS_CT_HAS_SSE3 1
#define COMPASS_CT_HAS_SSE4 1
#endif
#endif
#include "detail/tags.hpp"
namespace compass {
......
......@@ -24,6 +24,4 @@ namespace compass {
};
//#include "ct/preprocessor_impl.hpp"
#endif /* DEFINITIONS_H */
......@@ -8,6 +8,7 @@
#include "detail/definitions.hpp"
#ifdef COMPASS_CT_ARCH_X86
#include "ct/preprocessor_impl.hpp"
#include "rt/x86_impl.hpp"
#include "rt/x86_sizes.hpp"
#endif
......
......@@ -47,8 +47,6 @@ namespace compass {
};
#endif
namespace compass {
......@@ -252,6 +250,106 @@ namespace compass {
#endif
#ifdef COMPASS_CT_ARCH_X86
#ifndef COMPASS_CT_PREPROCESSOR_IMPL_H_
#define COMPASS_CT_PREPROCESSOR_IMPL_H_
#ifndef WIN32
#if defined(__SSE2__) || defined(__SSE2_MATH__)
#define COMPASS_CT_HAS_SSE2 1
#endif
#if defined(__SSE3__) && defined(__SSSE3__)
#define COMPASS_CT_HAS_SSE3 1
#endif
#if defined(__SSE4_2__) && defined(__SSE4_1__)
#define COMPASS_CT_HAS_SSE4 1
#endif
#else
#if _M_IX86_FP >= 2
#define COMPASS_CT_HAS_SSE2 1
#define COMPASS_CT_HAS_SSE3 1
#define COMPASS_CT_HAS_SSE4 1
#endif
#endif
#ifndef COMPASS_TAGS_H_
#define COMPASS_TAGS_H_
namespace compass {
namespace feature {
struct sse {};
struct sse2 {};
struct sse3 {};
struct sse4 {};
struct avx {};
struct avx2 {};
};
};
#endif
namespace compass {
namespace compiletime {
template<typename feature_t>
struct has{
static const bool enabled = false;
};
template<>
struct has<feature::sse2>{
static const bool enabled=
#ifdef COMPASS_CT_HAS_SSE2
true;
#else
false;
#endif
};
template<>
struct has<feature::sse3>{
static const bool enabled=
#ifdef COMPASS_CT_HAS_SSE3
true;
#else
false;
#endif
};
template<>
struct has<feature::sse4>{
static const bool enabled=
#ifdef COMPASS_CT_HAS_SSE4
true;
#else
false;
#endif
};
};
};
#endif
#ifndef COMPASS_RT_X86_IMPL_H_
#define COMPASS_RT_X86_IMPL_H_
#ifndef COMPASS_RT_X86_CPUID_H
......@@ -515,33 +613,6 @@ namespace compass {
#endif
#endif
#endif
#ifndef COMPASS_TAGS_H_
#define COMPASS_TAGS_H_
namespace compass {
namespace feature {
struct sse {};
struct sse2 {};
struct sse3 {};
struct sse4 {};
struct avx {};
struct avx2 {};
};
};
#endif
#ifndef COMPASS_BIT_VIEW_H
#define COMPASS_BIT_VIEW_H
......
......@@ -86,3 +86,20 @@ configure_file(${PROJECT_SOURCE_DIR}/tests/build_machine.hpp.in ${CMAKE_CURRENT_
add_executable(test_build_machine test_build_machine.cpp $<TARGET_OBJECTS:catcho>)
target_include_directories(test_build_machine PRIVATE ${CATCH2_HEADER_PATH} ${COMPASS_INCLUDE_BUILD_DIR} ${CMAKE_CURRENT_BINARY_DIR})
if(HAS_MARCH_COMPILERFLAG)
target_compile_options(test_build_machine PRIVATE "-march=native")
endif()
if(HAS_XHOST_COMPILERFLAG)
target_compile_options(test_build_machine PRIVATE "-xHost")
endif()
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")
if(SSE2_FOUND)
target_compile_options(test_build_machine PRIVATE "/arch:SSE2")
elseif(AVX_FOUND)
target_compile_options(test_build_machine PRIVATE "/arch:AVX")
elseif(AVX2_FOUND)
target_compile_options(test_build_machine PRIVATE "/arch:AVX2")
endif()
endif()
......@@ -66,6 +66,7 @@ TEST_CASE_METHOD( host_reference, "machine_specific" ){
REQUIRE(value==expected_has_sse);
}
SECTION( "has_sse2_right" ){
......@@ -73,6 +74,9 @@ TEST_CASE_METHOD( host_reference, "machine_specific" ){
auto value = compass::runtime::has(compass::feature::sse2());
REQUIRE(value==expected_has_sse2);
if(expected_has_sse2){
REQUIRE(compass::compiletime::has<compass::feature::sse2>::enabled==expected_has_sse2);
}
}
......@@ -81,6 +85,8 @@ TEST_CASE_METHOD( host_reference, "machine_specific" ){
auto value = compass::runtime::has(compass::feature::sse3());
REQUIRE(value==expected_has_sse3);
if(expected_has_sse3)
REQUIRE(compass::compiletime::has<compass::feature::sse3>::enabled==expected_has_sse3);
}
......@@ -89,6 +95,8 @@ TEST_CASE_METHOD( host_reference, "machine_specific" ){
auto value = compass::runtime::has(compass::feature::sse4());
REQUIRE(value==expected_has_sse4);
if(expected_has_sse4)
REQUIRE(compass::compiletime::has<compass::feature::sse4>::enabled==expected_has_sse4);
}
......
......@@ -38,6 +38,6 @@ TEST_CASE( "compass_fundamentals" ){
REQUIRE(value>0u);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment