From: Un1q32 Date: Thu, 13 Jun 2024 11:23:29 +0000 (-0400) Subject: Improved ACLE check (#1727) X-Git-Tag: 2.2.0~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c5b4b351060be435e194f45dd7d279b8faf61dfc;p=thirdparty%2Fzlib-ng.git Improved ACLE check (#1727) Co-authored-by: Cameron Cawley --- diff --git a/cmake/detect-intrinsics.cmake b/cmake/detect-intrinsics.cmake index 94ec789f..14f82fcb 100644 --- a/cmake/detect-intrinsics.cmake +++ b/cmake/detect-intrinsics.cmake @@ -2,35 +2,34 @@ # Licensed under the Zlib license, see LICENSE.md for details macro(check_acle_compiler_flag) - if(MSVC) - # Both ARM and ARM64-targeting msvc support intrinsics, but - # ARM msvc is missing some intrinsics introduced with ARMv8, e.g. crc32 - if(MSVC_C_ARCHITECTURE_ID STREQUAL "ARM64") - set(HAVE_ACLE_FLAG TRUE) - endif() - else() - if(NOT NATIVEFLAG) - if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang") + if(NOT NATIVEFLAG) + if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang") + check_c_compiler_flag("-march=armv8-a+crc" HAVE_MARCH_ARMV8_CRC) + if(HAVE_MARCH_ARMV8_CRC) set(ACLEFLAG "-march=armv8-a+crc" CACHE INTERNAL "Compiler option to enable ACLE support") + else() + check_c_compiler_flag("-march=armv8-a+crc+simd" HAVE_MARCH_ARMV8_CRC_SIMD) + if(HAVE_MARCH_ARMV8_CRC_SIMD) + set(ACLEFLAG "-march=armv8-a+crc+simd" CACHE INTERNAL "Compiler option to enable ACLE support") + endif() endif() endif() - # Check whether compiler supports ACLE flag - set(CMAKE_REQUIRED_FLAGS "${ACLEFLAG} ${NATIVEFLAG} ${ZNOLTOFLAG}") - check_c_source_compiles( - "int main() { return 0; }" - HAVE_ACLE_FLAG FAIL_REGEX "not supported") - if(NOT NATIVEFLAG AND NOT HAVE_ACLE_FLAG) - set(ACLEFLAG "-march=armv8-a+crc+simd" CACHE INTERNAL "Compiler option to enable ACLE support" FORCE) - # Check whether compiler supports ACLE flag - set(CMAKE_REQUIRED_FLAGS "${ACLEFLAG}") - check_c_source_compiles( - "int main() { return 0; }" - HAVE_ACLE_FLAG2 FAIL_REGEX "not supported") - set(HAVE_ACLE_FLAG ${HAVE_ACLE_FLAG2} CACHE INTERNAL "Have compiler option to enable ACLE intrinsics" FORCE) - unset(HAVE_ACLE_FLAG2 CACHE) # Don't cache this internal variable - endif() - set(CMAKE_REQUIRED_FLAGS) endif() + # Check whether compiler supports ARMv8 CRC intrinsics + set(CMAKE_REQUIRED_FLAGS "${ACLEFLAG} ${NATIVEFLAG} ${ZNOLTOFLAG}") + check_c_source_compiles( + "#if defined(_MSC_VER) + #include + #else + #include + #endif + unsigned int f(unsigned int a, unsigned int b) { + return __crc32w(a, b); + } + int main(void) { return 0; }" + HAVE_ACLE_FLAG + ) + set(CMAKE_REQUIRED_FLAGS) endmacro() macro(check_armv6_compiler_flag) diff --git a/configure b/configure index 6cf61da2..f60530fd 100755 --- a/configure +++ b/configure @@ -1113,20 +1113,33 @@ check_acle_compiler_flag() { int main() { return 0; } EOF if try $CC -c $CFLAGS -march=armv8-a+crc $test.c; then - ACLE_AVAILABLE=1 echo "Check whether -march=armv8-a+crc works ... Yes." | tee -a configure.log acleflag="-march=armv8-a+crc" else echo "Check whether -march=armv8-a+crc works ... No." | tee -a configure.log if try $CC -c $CFLAGS -march=armv8-a+crc+simd $test.c; then - ACLE_AVAILABLE=1 echo "Check whether -march=armv8-a+crc+simd works ... Yes." | tee -a configure.log acleflag="-march=armv8-a+crc+simd" else - ACLE_AVAILABLE=0 echo "Check whether -march=armv8-a+crc+simd works ... No." | tee -a configure.log fi fi + + # Check whether compiler supports ARMv8 CRC intrinsics + cat > $test.c << EOF +#include +unsigned int f(unsigned int a, unsigned int b) { + return __crc32w(a, b); +} +int main(void) { return 0; } +EOF + if try ${CC} ${CFLAGS} ${acleflag} $test.c; then + echo "Checking for ARMv8 CRC intrinsics ... Yes." | tee -a configure.log + ACLE_AVAILABLE=1 + else + echo "Checking for ARMv8 CRC intrinsics ... No." | tee -a configure.log + ACLE_AVAILABLE=0 + fi } check_neon_compiler_flag() {