[Build] Enable zlib-ng AVX2/AVX512 optimizations on all x86_64 platforms

PCLMULQDQ CRC folding is excluded for now due to a runtime hang on
Linux — needs further investigation. The library does runtime feature
detection so all other paths should be safe on CPUs without these extensions.
This commit is contained in:
Herman S.
2026-03-26 12:35:09 +09:00
parent ec5bd872d5
commit 86c7a8be79

View File

@@ -303,34 +303,36 @@ else()
target_compile_definitions(zlib-ng PRIVATE target_compile_definitions(zlib-ng PRIVATE
X86_FEATURES X86_FEATURES
X86_HAVE_XSAVE_INTRIN X86_HAVE_XSAVE_INTRIN
X86_SSE2
X86_SSSE3 X86_SSSE3
X86_SSE42 X86_SSE42
X86_AVX2
X86_AVX512
X86_AVX512VNNI
WITH_GZFILEOP WITH_GZFILEOP
) )
if(WIN32) if(NOT MSVC)
target_compile_definitions(zlib-ng PRIVATE # GCC/Clang have native __builtin_ctz/__builtin_ctzll (MSVC gets these
X86_SSE2 # from fallback_builtins.h). Defining these enables optimized compare256
X86_AVX2 # and longest_match codepaths.
X86_AVX512 target_compile_definitions(zlib-ng PRIVATE HAVE_BUILTIN_CTZ HAVE_BUILTIN_CTZLL)
X86_AVX512VNNI # GCC/Clang need per-file ISA flags; MSVC handles this via runtime dispatch
X86_PCLMULQDQ_CRC set_source_files_properties(
X86_VPCLMULQDQ_CRC zlib-ng/arch/x86/adler32_avx2.c
zlib-ng/arch/x86/chunkset_avx2.c
zlib-ng/arch/x86/compare256_avx2.c
zlib-ng/arch/x86/slide_hash_avx2.c
PROPERTIES COMPILE_OPTIONS "-mavx2;-mbmi2"
) )
else() set_source_files_properties(
# Remove AVX2/AVX512 files on non-Windows zlib-ng/arch/x86/adler32_avx512.c
set(_zlibng_exclude_patterns zlib-ng/arch/x86/chunkset_avx512.c
"adler32_avx2" "adler32_avx512" "adler32_avx512_vnni" PROPERTIES COMPILE_OPTIONS "-mavx512f;-mavx512dq;-mavx512vl;-mavx512bw;-mbmi2"
"chunkset_avx2" "compare256_avx2" )
"crc32_pclmulqdq" "crc32_vpclmulqdq" set_source_files_properties(
"slide_hash_avx2" zlib-ng/arch/x86/adler32_avx512_vnni.c
PROPERTIES COMPILE_OPTIONS "-mavx512f;-mavx512dq;-mavx512vl;-mavx512bw;-mavx512vnni;-mbmi2"
) )
foreach(_pat ${_zlibng_exclude_patterns})
list(FILTER _zlibng_x86 EXCLUDE REGEX "${_pat}")
endforeach()
# Re-set sources without excluded files
get_target_property(_zlibng_srcs zlib-ng SOURCES)
set_target_properties(zlib-ng PROPERTIES SOURCES "")
target_sources(zlib-ng PRIVATE ${_zlibng_c} ${_zlibng_x86} ${_zlibng_generic})
endif() endif()
endif() endif()
target_include_directories(zlib-ng PUBLIC zlib-ng) target_include_directories(zlib-ng PUBLIC zlib-ng)