Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/native/external/zlib-ng-version.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
v2.2.4
860e4cff7917d93f54f5d7f0bc1d0e8b1a3cb988
v2.2.5
425439062b114a0f6cf625022c41d929c7e879f9

https://github.com/zlib-ng/zlib-ng/releases/tag/2.2.4
https://github.com/zlib-ng/zlib-ng/releases/tag/2.2.5

We have removed the following folders from our local copy as these files are not needed for our compilation:

Expand Down
4 changes: 4 additions & 0 deletions src/native/external/zlib-ng/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,7 @@ gzread.c
MinSizeRel
RelWithDebInfo
/_deps/googletest*

# Test datasets
test/data/corpora/
test/data/local/
62 changes: 50 additions & 12 deletions src/native/external/zlib-ng/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ include(CMakeDependentOption)
include(CMakePackageConfigHelpers)
include(FeatureSummary)

# We need to enable C++ before trying to check for coverage
option(WITH_GTEST "Build gtest_zlib" ON)
option(WITH_FUZZERS "Build test/fuzz" OFF)
option(WITH_BENCHMARKS "Build test/benchmarks" OFF)

if(WITH_GTEST OR WITH_FUZZERS OR WITH_BENCHMARKS)
enable_language(CXX)
endif()

include(cmake/detect-arch.cmake)
include(cmake/detect-install-dirs.cmake)
include(cmake/detect-coverage.cmake)
Expand Down Expand Up @@ -79,9 +88,6 @@ option(WITH_GZFILEOP "Compile with support for gzFile related functions" ON)
option(ZLIB_COMPAT "Compile with zlib compatible API" OFF)
option(ZLIB_ENABLE_TESTS "Build test binaries" ON)
option(ZLIBNG_ENABLE_TESTS "Test zlib-ng specific API" ON)
option(WITH_GTEST "Build gtest_zlib" ON)
option(WITH_FUZZERS "Build test/fuzz" OFF)
option(WITH_BENCHMARKS "Build test/benchmarks" OFF)
option(WITH_BENCHMARK_APPS "Build application benchmarks" OFF)
option(WITH_OPTIM "Build with optimisation" ON)
option(WITH_REDUCED_MEM "Reduced memory usage for special cases (reduces performance)" OFF)
Expand Down Expand Up @@ -362,6 +368,21 @@ if(MSVC)
endif()
endif()

#
# Additional flags for features checking
#
set(ADDITIONAL_CHECK_FLAGS )
if(APPLE)
check_c_compiler_flag(-Werror=unguarded-availability HAVE_W_ERROR_UNGUARDED_AVAILABILITY)
if(HAVE_W_ERROR_UNGUARDED_AVAILABILITY)
set(ADDITIONAL_CHECK_FLAGS "${ADDITIONAL_CHECK_FLAGS} -Werror=unguarded-availability")
endif()
check_c_compiler_flag(-Werror=unguarded-availability-new HAVE_W_ERROR_UNGUARDED_AVAILABILITY_NEW)
if(HAVE_W_ERROR_UNGUARDED_AVAILABILITY_NEW)
set(ADDITIONAL_CHECK_FLAGS "${ADDITIONAL_CHECK_FLAGS} -Werror=unguarded-availability-new")
endif()
endif()

#
# Check for standard/system includes
#
Expand Down Expand Up @@ -407,28 +428,42 @@ set(CMAKE_REQUIRED_DEFINITIONS) # clear variable
#
# Check for fseeko and other optional functions
#
set(CMAKE_REQUIRED_FLAGS "${ADDITIONAL_CHECK_FLAGS}")
check_function_exists(fseeko HAVE_FSEEKO)
if(NOT HAVE_FSEEKO)
add_definitions(-DNO_FSEEKO)
endif()
set(CMAKE_REQUIRED_FLAGS)

set(CMAKE_REQUIRED_FLAGS "${ADDITIONAL_CHECK_FLAGS}")
check_function_exists(strerror HAVE_STRERROR)
if(NOT HAVE_STRERROR)
add_definitions(-DNO_STRERROR)
endif()
set(CMAKE_REQUIRED_FLAGS)

set(CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=200112L)
#
# Check for aligned memory allocation support: POSIX
#
set(CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=200112L -D_ISOC11_SOURCE=1)
set(CMAKE_REQUIRED_FLAGS "${ADDITIONAL_CHECK_FLAGS}")
check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN)
if(HAVE_POSIX_MEMALIGN)
add_definitions(-DHAVE_POSIX_MEMALIGN)
endif()
set(CMAKE_REQUIRED_FLAGS)
set(CMAKE_REQUIRED_DEFINITIONS)

set(CMAKE_REQUIRED_DEFINITIONS -D_ISOC11_SOURCE=1)
#
# Check for aligned memory allocation support: C11
#
set(CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=200112L -D_ISOC11_SOURCE=1)
set(CMAKE_REQUIRED_FLAGS "${ADDITIONAL_CHECK_FLAGS}")
check_symbol_exists(aligned_alloc stdlib.h HAVE_ALIGNED_ALLOC)
if(HAVE_ALIGNED_ALLOC)
add_definitions(-DHAVE_ALIGNED_ALLOC)
endif()
set(CMAKE_REQUIRED_FLAGS)
set(CMAKE_REQUIRED_DEFINITIONS)

if(WITH_SANITIZER STREQUAL "Address")
Expand Down Expand Up @@ -577,13 +612,6 @@ if(MSVC)
add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
endif()

if(BASEARCH_X86_FOUND)
# FORCE_SSE2 option will only be shown if HAVE_SSE2_INTRIN is true
if("${ARCH}" MATCHES "i[3-6]86")
cmake_dependent_option(FORCE_SSE2 "Always assume CPU is SSE2 capable" OFF "HAVE_SSE2_INTRIN" OFF)
endif()
endif()

#
# Enable deflate_quick at level 1
#
Expand Down Expand Up @@ -902,6 +930,10 @@ if(WITH_OPTIM)
endif()
if(WITH_SSE2)
check_sse2_intrinsics()
# FORCE_SSE2 option will only be shown if HAVE_SSE2_INTRIN is true
if("${ARCH}" MATCHES "i[3-6]86")
cmake_dependent_option(FORCE_SSE2 "Always assume CPU is SSE2 capable" OFF "HAVE_SSE2_INTRIN" OFF)
endif()
if(HAVE_SSE2_INTRIN)
add_definitions(-DX86_SSE2)
set(SSE2_SRCS ${ARCHDIR}/chunkset_sse2.c ${ARCHDIR}/compare256_sse2.c ${ARCHDIR}/slide_hash_sse2.c)
Expand Down Expand Up @@ -1064,6 +1096,12 @@ else()
set(PC_INC_INSTALL_DIR "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
endif()

if(IS_ABSOLUTE "${CMAKE_INSTALL_BINDIR}")
set(PC_BIN_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}")
else()
set(PC_BIN_INSTALL_DIR "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
endif()

if(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}")
set(PC_LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}")
else()
Expand Down
2 changes: 1 addition & 1 deletion src/native/external/zlib-ng/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ LDSHARED=$(CC)
LDSHAREDFLAGS=-shared
LDVERSIONSCRIPT=

VER=2.2.4
VER=2.2.5
VER1=2

STATICLIB=$(LIBNAME1).a
Expand Down
63 changes: 63 additions & 0 deletions src/native/external/zlib-ng/arch/riscv/Makefile.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Makefile for zlib-ng
# Copyright (C) 1995-2013 Jean-loup Gailly, Mark Adler
# Copyright (C) 2024 Hans Kristian Rosbach
# Copyright (C) 2025 Yin Tong <yintong.ustc@bytedance.com>, ByteDance
# For conditions of distribution and use, see copyright notice in zlib.h

CC=
CFLAGS=
SFLAGS=
INCLUDES=
SUFFIX=

SRCDIR=.
SRCTOP=../..
TOPDIR=$(SRCTOP)

RVVFLAG=

all: \
riscv_features.o riscv_features.lo \
adler32_rvv.o adler32_rvv.lo \
chunkset_rvv.o chunkset_rvv.lo \
compare256_rvv.o compare256_rvv.lo \
slide_hash_rvv.o slide_hash_rvv.lo

riscv_features.o: $(SRCDIR)/riscv_features.c
$(CC) $(CFLAGS) $(RVVFLAG) $(INCLUDES) -c -o $@ $(SRCDIR)/riscv_features.c

riscv_features.lo: $(SRCDIR)/riscv_features.c
$(CC) $(SFLAGS) $(RVVFLAG) -DPIC $(INCLUDES) -c -o $@ $(SRCDIR)/riscv_features.c

adler32_rvv.o: $(SRCDIR)/adler32_rvv.c
$(CC) $(CFLAGS) $(RVVFLAG) $(INCLUDES) -c -o $@ $(SRCDIR)/adler32_rvv.c

adler32_rvv.lo: $(SRCDIR)/adler32_rvv.c
$(CC) $(SFLAGS) $(RVVFLAG) -DPIC $(INCLUDES) -c -o $@ $(SRCDIR)/adler32_rvv.c

chunkset_rvv.o: $(SRCDIR)/chunkset_rvv.c
$(CC) $(CFLAGS) $(RVVFLAG) $(INCLUDES) -c -o $@ $(SRCDIR)/chunkset_rvv.c

chunkset_rvv.lo: $(SRCDIR)/chunkset_rvv.c
$(CC) $(SFLAGS) $(RVVFLAG) -DPIC $(INCLUDES) -c -o $@ $(SRCDIR)/chunkset_rvv.c

compare256_rvv.o: $(SRCDIR)/compare256_rvv.c
$(CC) $(CFLAGS) $(RVVFLAG) $(INCLUDES) -c -o $@ $(SRCDIR)/compare256_rvv.c

compare256_rvv.lo: $(SRCDIR)/compare256_rvv.c
$(CC) $(SFLAGS) $(RVVFLAG) -DPIC $(INCLUDES) -c -o $@ $(SRCDIR)/compare256_rvv.c

slide_hash_rvv.o: $(SRCDIR)/slide_hash_rvv.c
$(CC) $(CFLAGS) $(RVVFLAG) $(INCLUDES) -c -o $@ $(SRCDIR)/slide_hash_rvv.c

slide_hash_rvv.lo: $(SRCDIR)/slide_hash_rvv.c
$(CC) $(SFLAGS) $(RVVFLAG) -DPIC $(INCLUDES) -c -o $@ $(SRCDIR)/slide_hash_rvv.c

mostlyclean: clean
clean:
rm -f *.o *.lo *~
rm -rf objs
rm -f *.gcda *.gcno *.gcov

distclean: clean
rm -f Makefile
2 changes: 1 addition & 1 deletion src/native/external/zlib-ng/arch/riscv/chunkset_rvv.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static inline uint8_t* CHUNKCOPY(uint8_t *out, uint8_t const *from, unsigned len
from += align;
len -= align;
ptrdiff_t dist = out - from;
if (dist >= len) {
if (dist < 0 || dist >= len) {
memcpy(out, from, len);
out += len;
from += len;
Expand Down
2 changes: 1 addition & 1 deletion src/native/external/zlib-ng/arch/s390/s390_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ uint32_t crc32_s390_vx(uint32_t crc, const uint8_t *buf, size_t len);
#ifdef DISABLE_RUNTIME_CPU_DETECTION
# if defined(S390_CRC32_VX) && defined(__zarch__) && __ARCH__ >= 11 && defined(__VX__)
# undef native_crc32
# define native_crc32 = crc32_s390_vx
# define native_crc32 crc32_s390_vx
# endif
#endif

Expand Down
7 changes: 7 additions & 0 deletions src/native/external/zlib-ng/arch/x86/chunkset_avx512.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ static inline uint8_t* CHUNKCOPY(uint8_t *out, uint8_t const *from, unsigned len
return out;
}

/* MSVC compiler decompression bug when optimizing for size */
#if defined(_MSC_VER) && _MSC_VER < 1943
# pragma optimize("", off)
#endif
static inline chunk_t GET_CHUNK_MAG(uint8_t *buf, uint32_t *chunk_rem, uint32_t dist) {
lut_rem_pair lut_rem = perm_idx_lut[dist - 3];
__m256i ret_vec;
Expand Down Expand Up @@ -128,6 +132,9 @@ static inline chunk_t GET_CHUNK_MAG(uint8_t *buf, uint32_t *chunk_rem, uint32_t

return ret_vec;
}
#if defined(_MSC_VER) && _MSC_VER < 1943
# pragma optimize("", on)
#endif

static inline void storehalfchunk(uint8_t *out, halfchunk_t *chunk) {
_mm_storeu_si128((__m128i *)out, *chunk);
Expand Down
9 changes: 4 additions & 5 deletions src/native/external/zlib-ng/arch/x86/x86_features.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,17 @@ void Z_INTERNAL x86_check_features(struct x86_cpu_features *features) {
}

if (maxbasic >= 7) {
// Reference: https://software.intel.com/sites/default/files/article/405250/how-to-detect-new-instruction-support-in-the-4th-generation-intel-core-processor-family.pdf
cpuidex(7, 0, &eax, &ebx, &ecx, &edx);

// check BMI1 bit
// Reference: https://software.intel.com/sites/default/files/article/405250/how-to-detect-new-instruction-support-in-the-4th-generation-intel-core-processor-family.pdf
features->has_vpclmulqdq = ecx & 0x400;
// check BMI2 bit
features->has_bmi2 = ebx & 0x8;

// check AVX2 bit if the OS supports saving YMM registers
if (features->has_os_save_ymm) {
features->has_avx2 = ebx & 0x20;
}

features->has_bmi2 = ebx & 0x8;

// check AVX512 bits if the OS supports saving ZMM registers
if (features->has_os_save_zmm) {
features->has_avx512f = ebx & 0x00010000;
Expand All @@ -112,6 +110,7 @@ void Z_INTERNAL x86_check_features(struct x86_cpu_features *features) {
features->has_avx512_common = features->has_avx512f && features->has_avx512dq && features->has_avx512bw \
&& features->has_avx512vl && features->has_bmi2;
features->has_avx512vnni = ecx & 0x800;
features->has_vpclmulqdq = ecx & 0x400;
}
}
}
30 changes: 14 additions & 16 deletions src/native/external/zlib-ng/arch/x86/x86_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ uint32_t crc32_vpclmulqdq(uint32_t crc32, const uint8_t *buf, size_t len);
# undef native_longest_match_slow
# define native_longest_match_slow longest_match_slow_sse2
# endif
#endif
# endif
// X86 - SSSE3
# if defined(X86_SSSE3) && defined(__SSSE3__)
# undef native_adler32
Expand All @@ -105,21 +105,20 @@ uint32_t crc32_vpclmulqdq(uint32_t crc32, const uint8_t *buf, size_t len);
# undef native_adler32_fold_copy
# define native_adler32_fold_copy adler32_fold_copy_sse42
# endif

// X86 - PCLMUL
#if defined(X86_PCLMULQDQ_CRC) && defined(__PCLMUL__)
# undef native_crc32
# define native_crc32 crc32_pclmulqdq
# undef native_crc32_fold
# define native_crc32_fold crc32_fold_pclmulqdq
# undef native_crc32_fold_copy
# define native_crc32_fold_copy crc32_fold_pclmulqdq_copy
# undef native_crc32_fold_final
# define native_crc32_fold_final crc32_fold_pclmulqdq_final
# undef native_crc32_fold_reset
# define native_crc32_fold_reset crc32_fold_pclmulqdq_reset
#endif
// X86 - AVX
# if defined(X86_PCLMULQDQ_CRC) && defined(__PCLMUL__)
# undef native_crc32
# define native_crc32 crc32_pclmulqdq
# undef native_crc32_fold
# define native_crc32_fold crc32_fold_pclmulqdq
# undef native_crc32_fold_copy
# define native_crc32_fold_copy crc32_fold_pclmulqdq_copy
# undef native_crc32_fold_final
# define native_crc32_fold_final crc32_fold_pclmulqdq_final
# undef native_crc32_fold_reset
# define native_crc32_fold_reset crc32_fold_pclmulqdq_reset
# endif
// X86 - AVX2
# if defined(X86_AVX2) && defined(__AVX2__)
# undef native_adler32
# define native_adler32 adler32_avx2
Expand All @@ -142,7 +141,6 @@ uint32_t crc32_vpclmulqdq(uint32_t crc32, const uint8_t *buf, size_t len);
# define native_longest_match_slow longest_match_slow_avx2
# endif
# endif

// X86 - AVX512 (F,DQ,BW,Vl)
# if defined(X86_AVX512) && defined(__AVX512F__) && defined(__AVX512DQ__) && defined(__AVX512BW__) && defined(__AVX512VL__)
# undef native_adler32
Expand Down
1 change: 0 additions & 1 deletion src/native/external/zlib-ng/cmake/detect-arch.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ elseif(CMAKE_CROSSCOMPILING)
set(ARCH ${CMAKE_C_COMPILER_TARGET})
else()
# Let preprocessor parse archdetect.c and raise an error containing the arch identifier
enable_language(C)
try_run(
run_result_unused
compile_result_unused
Expand Down
14 changes: 9 additions & 5 deletions src/native/external/zlib-ng/cmake/detect-intrinsics.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,15 @@ macro(check_avx512vnni_intrinsics)
set(CMAKE_REQUIRED_FLAGS "${AVX512VNNIFLAG} ${NATIVEFLAG} ${ZNOLTOFLAG}")
check_c_source_compiles(
"#include <immintrin.h>
__m512i f(__m512i x, __m512i y) {
__m512i z = _mm512_setzero_epi32();
return _mm512_dpbusd_epi32(z, x, y);
}
int main(void) { return 0; }"
int main(void) {
const __m512i z512 = _mm512_setzero_si512();
const __m256i z256 = _mm256_setzero_si256();
volatile __m512i r512 = _mm512_dpbusd_epi32(z512, z512, z512);
volatile __m256i r256 = _mm256_dpbusd_epi32(z256, z256, z256);
(void)r512;
(void)r256;
return 0;
}"
HAVE_AVX512VNNI_INTRIN
)
set(CMAKE_REQUIRED_FLAGS)
Expand Down
16 changes: 16 additions & 0 deletions src/native/external/zlib-ng/cmake/toolchain-riscv-clang.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR riscv64)
set(CMAKE_SYSTEM_VERSION 1)

set(CMAKE_C_COMPILER clang)
set(CMAKE_C_COMPILER_TARGET riscv64-linux-gnu)
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_CXX_COMPILER_TARGET riscv64-linux-gnu)

set(CMAKE_CROSSCOMPILING TRUE)
set(CMAKE_CROSSCOMPILING_EMULATOR qemu-riscv64 -cpu rv64,zba=true,zbb=true,zbc=true,zbs=true,v=true,vlen=512,elen=64,vext_spec=v1.0 -L /usr/${CMAKE_C_COMPILER_TARGET}/)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
Loading
Loading