From 88dd97e17461948c5924217b5000c69d8b39ee62 Mon Sep 17 00:00:00 2001 From: Can Xia Date: Fri, 14 Jun 2024 18:32:37 +0800 Subject: [PATCH] enable simd in zlib Signed-off-by: Can Xia Change-Id: Ieb96ccf9f840114a619daafa680267518e2f640b Signed-off-by: Can Xia --- third_party/externals/zlib/cpu_features.c | 8 ++++---- third_party/zlib/BUILD.gn | 12 +++++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/third_party/externals/zlib/cpu_features.c b/third_party/externals/zlib/cpu_features.c index 70f01beebe..5be4144cab 100644 --- a/third_party/externals/zlib/cpu_features.c +++ b/third_party/externals/zlib/cpu_features.c @@ -31,13 +31,13 @@ int ZLIB_INTERNAL x86_cpu_enable_simd = 0; #ifndef CPU_NO_SIMD -#if defined(ARMV8_OS_ANDROID) || defined(ARMV8_OS_LINUX) || defined(ARMV8_OS_FUCHSIA) +#if defined(ARMV8_OS_ANDROID) || defined(ARMV8_OS_LINUX) || defined(ARMV8_OS_FUCHSIA) || defined(ARMV8_OS_OHOS) #include #endif #if defined(ARMV8_OS_ANDROID) #include -#elif defined(ARMV8_OS_LINUX) +#elif (defined(ARMV8_OS_LINUX) || defined(ARMV8_OS_OHOS)) && __has_include() && __has_include() #include #include #elif defined(ARMV8_OS_FUCHSIA) @@ -56,7 +56,7 @@ int ZLIB_INTERNAL x86_cpu_enable_simd = 0; static void _cpu_check_features(void); #endif -#if defined(ARMV8_OS_ANDROID) || defined(ARMV8_OS_LINUX) || defined(ARMV8_OS_MACOS) || defined(ARMV8_OS_FUCHSIA) || defined(X86_NOT_WINDOWS) +#if defined(ARMV8_OS_ANDROID) || defined(ARMV8_OS_LINUX) || defined(ARMV8_OS_MACOS) || defined(ARMV8_OS_FUCHSIA) || defined(X86_NOT_WINDOWS) || defined(ARMV8_OS_OHOS) #if !defined(ARMV8_OS_MACOS) // _cpu_check_features() doesn't need to do anything on mac/arm since all // features are known at build time, so don't call it. @@ -104,7 +104,7 @@ static void _cpu_check_features(void) uint64_t features = android_getCpuFeatures(); arm_cpu_enable_crc32 = !!(features & ANDROID_CPU_ARM_FEATURE_CRC32); arm_cpu_enable_pmull = !!(features & ANDROID_CPU_ARM_FEATURE_PMULL); -#elif defined(ARMV8_OS_LINUX) && defined(__aarch64__) +#elif (defined(ARMV8_OS_LINUX) || defined(ARMV8_OS_OHOS)) && defined(__aarch64__) && __has_include() && __has_include() unsigned long features = getauxval(AT_HWCAP); arm_cpu_enable_crc32 = !!(features & HWCAP_CRC32); arm_cpu_enable_pmull = !!(features & HWCAP_PMULL); diff --git a/third_party/zlib/BUILD.gn b/third_party/zlib/BUILD.gn index abe74d025d..a5a0fc079b 100644 --- a/third_party/zlib/BUILD.gn +++ b/third_party/zlib/BUILD.gn @@ -44,8 +44,10 @@ if (skia_use_system_zlib) { # iOS@ARM is a special case where we always have NEON but don't check # for crypto extensions. defines += [ "ARM_OS_IOS" ] - } # else { - # assert(false, "Unsupported ARM OS") + } else if (is_ohos) { + defines += [ "ARMV8_OS_OHOS" ] + } # else { + # assert(false, "Unsupported ARM OS") # } } @@ -57,6 +59,10 @@ if (skia_use_system_zlib) { } } + config("zlib_crc32_config") { + defines = [ "CRC32_ARMV8_CRC32" ] + } + source_set("zlib_adler32_simd") { visibility = [ ":*" ] configs += [ ":zlib_simd_config" ] @@ -80,7 +86,7 @@ if (skia_use_system_zlib) { # "All implementations of the ARMv8.1 architecture are required to # implement the CRC32* instructions. These are optional in ARMv8.0." if (!is_ios && use_arm_neon_optimizations) { - defines = [ "CRC32_ARMV8_CRC32" ] + public_configs = [ ":zlib_crc32_config" ] # An ARMv7 GCC build will fail to compile without building this target # for ARMv8-a+crc and letting runtime cpu detection select the correct -- Gitee