Add CPU instruction set requirements

This commit is contained in:
dcvz 2024-05-21 23:43:40 +02:00
parent 0a0699f272
commit e43e9ebb6a
5 changed files with 61 additions and 0 deletions

View File

@ -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)

View File

@ -0,0 +1,4 @@
try_compile(SUPPORTS_NEON
"${CMAKE_BINARY_DIR}"
"${CMAKE_SOURCE_DIR}/cmake/checks/cpu_neon.cpp"
)

View File

@ -0,0 +1,4 @@
try_compile(SUPPORTS_SSE42
"${CMAKE_BINARY_DIR}"
"${CMAKE_SOURCE_DIR}/cmake/checks/cpu_sse42.cpp"
)

29
cmake/checks/cpu_neon.cpp Normal file
View File

@ -0,0 +1,29 @@
#include <stdio.h>
#if defined _WIN32 && (defined(_M_ARM) || defined(_M_ARM64))
#include <Intrin.h>
#include <arm_neon.h>
#define CV_NEON 1
#elif defined(__ARM_NEON)
#include <arm_neon.h>
#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;
}

View File

@ -0,0 +1,12 @@
#include <stdio.h>
#include <nmmintrin.h>
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;
}