Skip to content

Commit

Permalink
zlib: add riscv64 simd optimization
Browse files Browse the repository at this point in the history
Fixes #854.
  • Loading branch information
Chilledheart committed Mar 20, 2024
1 parent 79b91f9 commit ce70189
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 12 additions & 1 deletion third_party/zlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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()

0 comments on commit ce70189

Please sign in to comment.