diff --git a/CMakeLists.txt b/CMakeLists.txt index 243ba12..b4530e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,18 @@ if (WIN32) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/lib/") endif() +# Check CPU requirements +include(cmake/ZREDetectSSE42.cmake) +message(STATUS "SUPPORTS_SSE4.2 = ${SUPPORTS_SSE42}") +include(cmake/ZREDetectNEON.cmake) +message(STATUS "SUPPORTS_NEON = ${SUPPORTS_NEON}") + +if(CMAKE_SIZEOF_VOID_P EQUAL 8 AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64" AND NOT SUPPORTS_AVX) + message(FATAL_ERROR "FATAL: A CPU supporting SSE4.2 is required.") +elseif(NOT SUPPORTS_NEON) + message(FATAL_ERROR "FATAL: A CPU supporting NEON is required.") +endif() + set(RT64_STATIC TRUE) add_subdirectory(${CMAKE_SOURCE_DIR}/lib/rt64 ${CMAKE_BINARY_DIR}/rt64) diff --git a/cmake/ZREDetectNEON.cmake b/cmake/ZREDetectNEON.cmake new file mode 100644 index 0000000..56a1c1a --- /dev/null +++ b/cmake/ZREDetectNEON.cmake @@ -0,0 +1,4 @@ +try_compile(SUPPORTS_NEON + "${CMAKE_BINARY_DIR}" + "${CMAKE_SOURCE_DIR}/cmake/checks/cpu_neon.cpp" +) \ No newline at end of file diff --git a/cmake/ZREDetectSSE42.cmake b/cmake/ZREDetectSSE42.cmake new file mode 100644 index 0000000..ab96e95 --- /dev/null +++ b/cmake/ZREDetectSSE42.cmake @@ -0,0 +1,4 @@ +try_compile(SUPPORTS_SSE42 + "${CMAKE_BINARY_DIR}" + "${CMAKE_SOURCE_DIR}/cmake/checks/cpu_sse42.cpp" +) \ No newline at end of file diff --git a/cmake/checks/cpu_neon.cpp b/cmake/checks/cpu_neon.cpp new file mode 100644 index 0000000..b7a8145 --- /dev/null +++ b/cmake/checks/cpu_neon.cpp @@ -0,0 +1,29 @@ +#include + +#if defined _WIN32 && (defined(_M_ARM) || defined(_M_ARM64)) +#include +#include +#define CV_NEON 1 +#elif defined(__ARM_NEON) +#include +#define CV_NEON 1 +#endif + +void test_aliased_type(const uint8x16_t &a) {} +void test_aliased_type(const int8x16_t &a) {} + +#if defined CV_NEON +int test() { + const float src[] = {0.0f, 0.0f, 0.0f, 0.0f}; + float32x4_t val = vld1q_f32((const float32_t *)(src)); + return (int)vgetq_lane_f32(val, 0); +} +#else +#error "NEON is not supported" +#endif + +int main() { + auto result = test(); + printf("NEON supported and test function executed. Result: %d\n", result); + return 0; +} diff --git a/cmake/checks/cpu_sse42.cpp b/cmake/checks/cpu_sse42.cpp new file mode 100644 index 0000000..b133ae1 --- /dev/null +++ b/cmake/checks/cpu_sse42.cpp @@ -0,0 +1,12 @@ +#include +#include + +int test() { + unsigned int res = _mm_crc32_u8(1, 2); +} + +int main() { + auto result = test(); + printf("SSE4.2 supported and test function executed. Result: %d\n", result); + return 0; +}