From: Shawn Hoffman Date: Sun, 24 Jul 2022 04:01:04 +0000 (-0700) Subject: fix ACLE detection on msvc/arm64 X-Git-Tag: 2.1.0-beta1~176 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8098fde200388c8ef99984fbfa2cb39303ed42c8;p=thirdparty%2Fzlib-ng.git fix ACLE detection on msvc/arm64 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index c403e5b0f..8ca63a30f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -587,7 +587,7 @@ if(WITH_OPTIM) endif() list(APPEND ZLIB_ARCH_HDRS ${ARCHDIR}/arm_features.h) list(APPEND ZLIB_ARCH_SRCS ${ARCHDIR}/arm_features.c) - if(WITH_ACLE AND NOT MSVC AND NOT "${ARCH}" MATCHES "armv[2-7]") + if(WITH_ACLE AND NOT "${ARCH}" MATCHES "armv[2-7]") check_acle_compiler_flag() if(HAVE_ACLE_FLAG) add_definitions(-DARM_ACLE_CRC_HASH) diff --git a/arch/arm/arm_features.c b/arch/arm/arm_features.c index 979204b83..d41c13acb 100644 --- a/arch/arm/arm_features.c +++ b/arch/arm/arm_features.c @@ -16,7 +16,7 @@ # endif # include #elif defined(_WIN32) -# include +# include #endif static int arm_has_crc32() { @@ -34,6 +34,8 @@ static int arm_has_crc32() { size_t size = sizeof(hascrc32); return sysctlbyname("hw.optional.armv8_crc32", &hascrc32, &size, NULL, 0) == 0 && hascrc32 == 1; +#elif defined(_WIN32) + return IsProcessorFeaturePresent(PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE); #elif defined(ARM_NOCHECK_ACLE) return 1; #else diff --git a/arch/arm/crc32_acle.c b/arch/arm/crc32_acle.c index ce75c343e..ef18ae81e 100644 --- a/arch/arm/crc32_acle.c +++ b/arch/arm/crc32_acle.c @@ -6,7 +6,9 @@ */ #ifdef ARM_ACLE_CRC_HASH -#ifndef _MSC_VER +#ifdef _MSC_VER +# include +#else # include #endif #include "../../zbuild.h" @@ -31,7 +33,7 @@ uint32_t crc32_acle(uint32_t crc, const uint8_t *buf, uint64_t len) { buf4 = (const uint32_t *) buf; } -#if defined(__aarch64__) +#if defined(__aarch64__) || defined(_M_ARM64) if ((len >= sizeof(uint32_t)) && ((ptrdiff_t)buf & sizeof(uint32_t))) { c = __crc32w(c, *buf4++); len -= sizeof(uint32_t); diff --git a/cmake/detect-intrinsics.cmake b/cmake/detect-intrinsics.cmake index 1ddab2253..743af4e87 100644 --- a/cmake/detect-intrinsics.cmake +++ b/cmake/detect-intrinsics.cmake @@ -2,8 +2,12 @@ # Licensed under the Zlib license, see LICENSE.md for details macro(check_acle_compiler_flag) - if(NOT NATIVEFLAG AND NOT HAVE_ACLE_FLAG) - set(ACLEFLAG "-march=armv8-a+crc" CACHE INTERNAL "Compiler option to enable ACLE support") + if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang") + if(NOT NATIVEFLAG AND NOT HAVE_ACLE_FLAG) + set(ACLEFLAG "-march=armv8-a+crc" CACHE INTERNAL "Compiler option to enable ACLE support") + endif() + elseif(MSVC) + set(HAVE_ACLE_FLAG TRUE) endif() # Check whether compiler supports ACLE flag set(CMAKE_REQUIRED_FLAGS "${ACLEFLAG} ${NATIVEFLAG}") diff --git a/fallback_builtins.h b/fallback_builtins.h index 6ab89c20f..3e5894207 100644 --- a/fallback_builtins.h +++ b/fallback_builtins.h @@ -71,7 +71,7 @@ static inline __m512i _mm512_zextsi128_si512(__m128i a) { #endif // __AVX2__ -#if defined(ARM_NEON_ADLER32) && !defined(__aarch64__) +#if defined(ARM_NEON_ADLER32) && !defined(__aarch64__) && !defined(_M_ARM64) /* Compatibility shim for the _high family of functions */ #define vmull_high_u8(a, b) vmull_u8(vget_high_u8(a), vget_high_u8(b)) #define vmlal_high_u8(a, b, c) vmlal_u8(a, vget_high_u8(b), vget_high_u8(c))