Commit aca0b90f authored by steinbac's avatar steinbac

added compile time checks to test

parent 633373c7
......@@ -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