From ce7018914965868e97e3a8e5f28d572399d7b249 Mon Sep 17 00:00:00 2001 From: Keeyou Date: Wed, 20 Mar 2024 14:59:21 +0800 Subject: [PATCH] zlib: add riscv64 simd optimization Fixes #854. --- CMakeLists.txt | 3 +++ third_party/zlib/CMakeLists.txt | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e3845d4ec..6a548c24b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -307,6 +307,9 @@ else() CMAKE_C_COMPILER_TARGET MATCHES "^aarch64-.*")) set(OS_AARCH64 TRUE) endif() + if (CMAKE_C_COMPILER_TARGET MATCHES "^riscv64-.*") + set(OS_RISCV64 TRUE) + endif() # Fix MINGW (native mingw)'s CMAKE_SYSTEM_PROCESSOR if (MINGW) if (OS_X86) diff --git a/third_party/zlib/CMakeLists.txt b/third_party/zlib/CMakeLists.txt index 2b69fa517..324177376 100644 --- a/third_party/zlib/CMakeLists.txt +++ b/third_party/zlib/CMakeLists.txt @@ -68,6 +68,11 @@ if ((OS_ARM AND ANDROID) OR OS_AARCH64) set(ZLIB_USE_ARM_NEON TRUE) endif() +if (OS_RISCV64) + message(STATUS "zlib: use riscv64 rvv optimization") + set(ZLIB_USE_RISCV64_OPTIMIZATIONS TRUE) +endif() + if (ZLIB_USE_X86_X64_OPTIMIZATIONS) # zlib_adler32_simd target_compile_definitions(zlib PUBLIC "ADLER32_SIMD_SSSE3") @@ -151,7 +156,13 @@ elseif(ZLIB_USE_ARM_NEON) crc32_simd.c crc32_simd.h ) +elseif (ZLIB_USE_RISCV64_OPTIMIZATIONS) + target_compile_definitions(zlib PUBLIC "RISCV_RVV") + target_compile_definitions(zlib PUBLIC "DEFLATE_SLIDE_HASH_RVV") + target_compile_definitions(zlib PUBLIC "ADLER32_SIMD_RVV") + target_compile_options(zlib PRIVATE "-march=rv64gcv") + target_sources(zlib PRIVATE inflate.c) else() - target_compile_definitions(zlib PUBLIC "-DCPU_NO_SIMD") + target_compile_definitions(zlib PUBLIC "CPU_NO_SIMD") target_sources(zlib PRIVATE inflate.c) endif()