zlib replacement with optimizations for "next generation" systems.
  • C 74%
  • C++ 16.5%
  • CMake 7.3%
  • Makefile 1.3%
  • Shell 0.8%
Find a file
Mark Adler c1d540edb6 Note that deflateBound() cannot precede deflateSetDictionary().
Keep the three-space comment indent used by the rest of the header.

Upstream: e3cd2b12
2026-12-03 10:47:49 +01:00
.github CI: Let APT retry 3 times due to microsoft CDN failures (#2547) 2026-12-03 00:45:22 +01:00
arch Optimize generic slide_hash_c with 64-bit SWAR (#2500) 2026-11-27 13:19:16 +01:00
cmake Extend support for -fprofile-update=atomic 2026-11-08 10:26:23 +01:00
doc Update links to the RFCs. 2026-07-29 11:50:45 +02:00
test Add a regression test for the crc32_combine_op() zero operator. 2026-12-02 11:36:50 +01:00
tools Move makecrct, makefixed and maketrees to utils/ folder. 2026-06-10 15:35:32 +02:00
utils [maketrees] base_length and base_dist are never referenced after initializing. (#2541) 2026-11-24 23:54:09 +01:00
win32 Rename dll filename for MinGW builds 2026-10-07 15:20:49 +02:00
.gitattributes Fix lint trailing whitespace error. 2024-05-30 20:03:51 +02:00
.gitignore Add AGENTS.md with guidance for coding agents (#2535) 2026-11-29 16:49:21 +01:00
.shellcheckrc Import default codecfactor.io .shellcheckrc file. 2020-03-09 14:13:36 +01:00
adler32.c Remove unnecessary (unsigned long) cast on BASE in adler32_combine 2026-02-17 17:29:13 +01:00
adler32_p.h Fix sum overflow in adler32_c on unaligned buffers 2026-10-20 18:58:51 +02:00
AGENTS.md Add AGENTS.md with guidance for coding agents (#2535) 2026-11-29 16:49:21 +01:00
arch_functions.h Initial support for MIPS MSA optimizations for I6400. 2026-09-14 12:24:58 +02:00
arch_natives.h Add compile-time native feature detection macros 2026-03-08 23:33:57 +01:00
chunkset_tpl.h Copy two chunks per iteration in the non-safe inflate fast path (#2432) 2026-11-20 13:38:09 +01:00
CMakeLists.txt Fix compilation on Solaris 11.3 (#2520) 2026-11-18 13:31:36 +01:00
compare256_rle.h Add include guard to compare256_rle.h 2026-10-22 12:22:44 +02:00
compress.c zlib 1.3.2. 2026-10-04 12:14:05 +02:00
configure [configure] Generate dependencies for files in utils subdirectory (#2521) 2026-11-23 12:36:15 +01:00
cpu_features.c Initial support for MIPS MSA optimizations for I6400. 2026-09-14 12:24:58 +02:00
cpu_features.h Initial support for MIPS MSA optimizations for I6400. 2026-09-14 12:24:58 +02:00
crc32.c zlib 1.3.2. 2026-10-04 12:14:05 +02:00
crc32_braid_comb.c Return zero from crc32_combine_op() for a zero operator. 2026-12-02 11:36:50 +01:00
crc32_braid_comb_p.h Correct comment for x2nmodp. 2022-05-25 12:04:35 +02:00
crc32_braid_p.h Split CRC32 Braid and Chorba word types 2026-02-17 23:23:12 +01:00
crc32_braid_tbl.h Fix warnings about BRAID_W/BRAID_N being undefined. 2026-06-10 12:57:42 +02:00
crc32_chorba_p.h Cleanup pointer style and parameter names in crc32 chorba functions 2026-02-18 20:15:09 +01:00
crc32_p.h Make CRC32 checking of headers use crc32_small directly, instead of taking 2026-05-17 01:36:02 +02:00
create-abi-files.sh zlib 1.3.2. 2026-10-04 12:14:05 +02:00
deflate.c Let small deflate windows reach the whole window (#2477) 2026-11-27 21:56:25 +01:00
deflate.h Make d_code distance lookup branchless (#2545) 2026-11-28 00:53:14 +01:00
deflate_fast.c Ensure max_inserts is at least 2 in deflate_fast and deflate_medium. (#2509) 2026-11-11 13:23:13 +01:00
deflate_huff.c Hoist strstart and lookahead to locals in deflate strategies 2026-06-17 11:40:48 +02:00
deflate_medium.c deflate_medium: Change matches to use uin32_t instead of uint16_t. 2026-09-01 11:44:00 +02:00
deflate_medium_tpl.h Ensure max_inserts is at least 2 in deflate_fast and deflate_medium. (#2509) 2026-11-11 13:23:13 +01:00
deflate_p.h Remove LIT_MEM. (#2501) 2026-11-10 00:35:23 +01:00
deflate_quick.c Use dynamic trees for the default deflate_quick strategy 2026-11-01 23:48:05 +01:00
deflate_rle.c Hoist strstart and lookahead to locals in deflate strategies 2026-06-17 11:40:48 +02:00
deflate_slow.c Move deflate_slow tail insert into insert_string helpers 2026-11-04 11:37:31 +01:00
deflate_stored.c Slide small deflate windows across a 32K input buffer 2026-11-05 21:24:55 +01:00
fallback_builtins.h Reject short-match candidates with a masked test instead of ctz 2026-07-14 12:47:34 +02:00
FAQ.zlib Remove mentions of an official zlib DLL distribution. 2024-02-07 19:15:56 +01:00
functable.c Split inflate_fast into safe and non-safe specializations 2026-09-25 17:22:15 +02:00
functable.h Split inflate_fast into safe and non-safe specializations 2026-09-25 17:22:15 +02:00
gzguts.h zlib 1.3.2. 2026-10-04 12:14:05 +02:00
gzlib.c zlib 1.3.2. 2026-10-04 12:14:05 +02:00
gzread.c Add gzfile api missing NULL checks (#2517) 2026-11-21 12:27:24 +01:00
gzread_mangle.h.in Simplify the gzread.c name mangling workaround by splitting out just 2026-01-12 00:58:42 +01:00
gzwrite.c Add gzfile api missing NULL checks (#2517) 2026-11-21 12:27:24 +01:00
INDEX.md Remove misleading manpage. 2021-03-09 16:44:07 +01:00
infback.c Test inflate api errors (#2516) 2026-11-23 12:43:18 +01:00
inffast_tpl.h Inflate: Increase lenbits from 10 to 11 (#2247) 2026-11-21 09:48:47 +01:00
inffixed_tbl.h zlib 1.3.2. 2026-10-04 12:14:05 +02:00
inflate.c Test inflate api errors (#2516) 2026-11-23 12:43:18 +01:00
inflate.h Copy two chunks per iteration in the non-safe inflate fast path (#2432) 2026-11-20 13:38:09 +01:00
inflate_p.h Inline chunkcopy_safe into the safe inflate_fast variant on ARM clang 2026-09-25 17:22:15 +02:00
inftrees.c Inflate: Increase lenbits from 10 to 11 (#2247) 2026-11-21 09:48:47 +01:00
inftrees.h Inflate: Increase lenbits from 10 to 11 (#2247) 2026-11-21 09:48:47 +01:00
insert_string.c Introduce insert_knuth_stepped(), allowing inserting only N number of 2026-10-22 12:10:10 +02:00
insert_string_p.h Move deflate_slow tail insert into insert_string helpers 2026-11-04 11:37:31 +01:00
LICENSE.md Update copyright years in other source files. 2024-02-07 19:15:56 +01:00
Makefile.in Make sure input and output filenames are not the same in minideflate. (#2512) 2026-11-23 12:35:18 +01:00
match_tpl.h Refill the window at the 2 * w_size cadence 2026-11-05 21:24:55 +01:00
PORTING.md Add zlib-ng-compat.h (#2283) 2026-11-12 12:03:36 +01:00
README.md Add zlib-ng-compat.h (#2283) 2026-11-12 12:03:36 +01:00
trees.c Hoist pending_buf across compress_block loop (#2548) 2026-12-03 10:44:14 +01:00
trees.h Renamed trees_p.h to trees.h. 2020-08-27 19:19:30 +02:00
trees_emit.h Hoist pending_buf across compress_block loop (#2548) 2026-12-03 10:44:14 +01:00
trees_tbl.h Minor style cleanup of zng_length_code and zng_dist_code 2026-07-20 22:06:31 +02:00
uncompr.c zlib 1.3.2. 2026-10-04 12:14:05 +02:00
zarch.h Add support for more architectures. 2026-10-18 00:16:01 +02:00
zbuild.h Optimize generic slide_hash_c with 64-bit SWAR (#2500) 2026-11-27 13:19:16 +01:00
zconf-ng.h.in zlib 1.3.2. 2026-10-04 12:14:05 +02:00
zconf.h.in zlib 1.3.2. 2026-10-04 12:14:05 +02:00
zendian.h Fix warnings about BIG_ENDIAN/LITTLE_ENDIAN being undefined 2026-06-10 12:57:42 +02:00
zlib-config.cmake.in rename cmake config target files to avoid illegal overwrite of PACKAGE_VERSION 2025-10-28 23:35:53 +01:00
zlib-ng-compat.h Add zlib-ng-compat.h (#2283) 2026-11-12 12:03:36 +01:00
zlib-ng-config.cmake.in rename cmake config target files to avoid illegal overwrite of PACKAGE_VERSION 2025-10-28 23:35:53 +01:00
zlib-ng.h.in Note that deflateBound() cannot precede deflateSetDictionary(). 2026-12-03 10:47:49 +01:00
zlib-ng.map.in Add gzopen_w to zlib-ng.map as it is exported symbol 2026-09-23 15:14:40 +02:00
zlib.h.in Note that deflateBound() cannot precede deflateSetDictionary(). 2026-12-03 10:47:49 +01:00
zlib.map.in zlib 1.3.2. 2026-10-04 12:14:05 +02:00
zlib.pc.cmakein Add bindir into zlib.pc.in for compatibility with Cygwin and Msys2 2025-06-16 19:50:19 +02:00
zlib.pc.in Add bindir into zlib.pc.in for compatibility with Cygwin and Msys2 2025-06-16 19:50:19 +02:00
zlib_name_mangling-ng.h.in Prefix in_func and out_func typedefs in the zlib-ng native API 2026-09-25 17:21:17 +02:00
zlib_name_mangling.h.empty Add support for name mangling 2021-10-09 09:19:55 +02:00
zlib_name_mangling.h.in Add compressBound_z, deflateBound_z, xompress_z and uncompress_z functions for large values. 2026-09-03 20:38:13 +02:00
zmemory.h [CI] Re-enable coverage for GCC debug build. 2026-11-06 13:41:35 +01:00
zsanitizer.h Use uintptr_t for ASan function signatures and macro variables 2026-03-11 00:56:35 +01:00
zutil.c zlib 1.3.2. 2026-10-04 12:14:05 +02:00
zutil.h Inflate: Increase lenbits from 10 to 11 (#2247) 2026-11-21 09:48:47 +01:00
zutil_p.h Remove unnecessary casts on malloc return values 2026-02-17 17:29:13 +01:00

CI Stable Develop
GitHub Actions Stable CMake
Stable Configure
Develop CMake
Develop Configure
CodeFactor CodeFactor CodeFactor
OSS-Fuzz Fuzzing Status Fuzzing Status
Coveralls Coverage Status Coverage Status

zlib-ng

zlib data compression library for the next generation systems

Maintained by Hans Kristian Rosbach aka Dead2 (zlib-ng àt circlestorm dót org)

Features

  • Zlib compatible API with support for dual-linking
  • Modernized native API based on zlib API for ease of porting
  • Major speed improvements, x86-64 can be about 4x faster than stock zlib for example.
  • Modern C11 syntax and a clean code layout
  • Deflate medium and quick algorithms based on Intel’s zlib fork
  • Support for CPU intrinsics when available
    • Adler32 implementation using SSSE3, SSE4.2, AVX2, AVX512, AVX512-VNNI, Neon, Neon(DotProd), MSA, VMX & VSX, LSX, LASX, RVV
    • CRC32-B implementation using SSE2, SSE4.1, (V)PCLMULQDQ, ARMv8, ARMv8.2 PMULL+EOR3, Power8, IBM Z, LoongArch, ZBC
    • Slide hash implementations using SSE2, AVX2, ARMv6, Neon, MSA, Power8, VMX & VSX, LSX, LASX
    • Compare256 implementations using SSE2, AVX2, AVX512, Neon, Power9, LSX, LASX, RVV
    • Inflate chunk copying using SSE2, SSSE3, AVX2, AVX512, Neon, Power8, VSX, LSX, LASX, RVV
    • Support for hardware-accelerated deflate using IBM Z DFLTCC
  • Safe unaligned memory read/writes and large bit buffer improvements
  • Includes improvements from Cloudflare and Intel forks
  • Configure and CMake build system support
  • Comprehensive set of CMake unit tests
  • Code sanitizers, fuzzing, and coverage
  • GitHub Actions continuous integration on Windows, macOS, and Linux
    • Native CI for Aarch64, S390x, x86, x86-64
    • Emulated CI for ARM, LoongArch, PPC, PPC64, RISCV, SPARC64, S390x using qemu

History

The motivation for this fork was seeing several 3rd party contributions with new optimizations not getting implemented into the official zlib repository.

Mark Adler has been maintaining zlib for a very long time, and he has done a great job and hopefully he will continue for a long time yet. The idea of zlib-ng is not to replace zlib, but to co-exist as a drop-in replacement with a lower threshold for code change.

zlib has a long history and is incredibly portable, even supporting many systems that predate the Internet.
That is great, but it can complicate further development and maintainability. The zlib code contains many workarounds for really old compilers or to accommodate systems with limitations such as operating in a 16-bit environment.

Many of these workarounds are only maintenance burdens, some of them are pretty huge code-wise. With many workarounds cluttered throughout the code, it makes it harder for new programmers with an idea/interest for zlib to contribute.

I decided to make a fork, merge all the Intel optimizations, some of the Cloudflare optimizations, plus a couple other smaller patches. Then started cleaning out workarounds, various dead code, all contrib and example code.
The result is a better performing and easier to maintain zlib-ng.

A lot of improvements have gone into zlib-ng since its start, and numerous people and companies have contributed both small and big improvements, or valuable testing.

Build

Please read LICENSE.md, it is very simple and very liberal.

There are two ways to build zlib-ng:

Cmake

To build zlib-ng using the cross-platform makefile generator cmake.

cmake .
cmake --build . --config Release
ctest --verbose -C Release

Alternatively, you can use the cmake configuration GUI tool ccmake:

ccmake .

Configure

To build zlib-ng using the bash configure script:

./configure
make
make test

Build Options

CMake configure Description Default
ZLIB_COMPAT --zlib-compat Compile with zlib compatible API OFF
ZLIB_ALIASES Provide zlib compatible CMake targets ON
WITH_COMPAT_HEADER Install zlib-ng-compat.h that aliases the zlib API onto zlib-ng, native mode only ON
WITH_GZFILEOP --without-gzfileops Compile with support for gzFile related functions ON
WITH_OPTIM --without-optimizations Build with optimisations ON
WITH_NEW_STRATEGIES --without-new-strategies Use new strategies ON
WITH_CRC32_CHORBA Build with Chorba optimized CRC32 ON
WITH_REDUCED_MEM --with-reduced-mem Reduce zlib-ng memory usage, affects performance and compression ratio OFF
WITH_GTEST Build tests using GTest framework ON
WITH_BENCHMARKS Build benchmarks using Google Benchmark framework OFF
INSTALL_UTILS Copy minigzip, minideflate and zran during install OFF
BUILD_TESTING Build test binaries ON

Install

WARNING: We do not recommend manually installing unless you really know what you are doing, because this can potentially override the system default zlib library, and any incompatibility or wrong configuration of zlib-ng can make the whole system unusable, requiring recovery or reinstall. If you still want a manual install, we recommend using the /opt/ path prefix.

For Linux distros, an alternative way to use zlib-ng (if compiled in zlib-compat mode) instead of zlib, is through the use of the LD_PRELOAD environment variable. If the program is dynamically linked with zlib, then the program will temporarily attempt to use zlib-ng instead, without risking system-wide instability.

LD_PRELOAD=/opt/zlib-ng/libz.so.1.2.13.zlib-ng /usr/bin/program

Cmake

To install zlib-ng system-wide using cmake:

cmake --build . --target install

Configure

To install zlib-ng system-wide using the configure script:

make install

CPack

After building with cmake, an installation package can be created using cpack. By default a tgz package is created, but you can append -G <format> to each command to generate alternative packages types (TGZ, ZIP, RPM, DEB). To easily create a rpm or deb package, you would use -G RPM or -G DEB respectively.

cd build
cpack --config CPackConfig.cmake
cpack --config CPackSourceConfig.cmake

Vcpkg

Alternatively, you can build and install zlib-ng using the vcpkg dependency manager:

git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh # "./bootstrap-vcpkg.bat" for powershell
./vcpkg integrate install
./vcpkg install zlib-ng

The zlib-ng port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please create an issue or pull request on the vcpkg repository.

Contributing

Zlib-ng is aiming to be open to contributions, and we would be delighted to receive pull requests on github. Help with testing and reviewing pull requests etc is also very much appreciated.

Please check the Wiki for more info: Contributing

Acknowledgments

Thanks go out to all the people and companies who have taken the time to contribute code reviews, testing and/or patches. Zlib-ng would not have been nearly as good without you.

The deflate format used by zlib was defined by Phil Katz.
The deflate and zlib specifications were written by L. Peter Deutsch.

zlib was originally created by Jean-loup Gailly (compression) and Mark Adler (decompression).

Advanced Build Options

CMake configure Description Default
WITH_NATIVE_INSTRUCTIONS Compiles with full instruction set supported on this host (gcc/clang -march=native) OFF
WITH_RUNTIME_CPU_DETECTION Compiles with runtime CPU detection ON
WITH_SSE2 x86: Build with SSE2 intrinsics ON
WITH_SSSE3 x86: Build with SSSE3 intrinsics ON
WITH_SSE41 x86: Build with SSE41 intrinsics ON
WITH_SSE42 x86: Build with SSE42 intrinsics ON
WITH_PCLMULQDQ x86: Build with PCLMULQDQ intrinsics ON
WITH_AVX2 x86: Build with AVX2 intrinsics ON
WITH_AVX512 x86: Build with AVX512 intrinsics ON
WITH_AVX512VNNI x86: Build with AVX512VNNI intrinsics ON
WITH_VPCLMULQDQ x86: Build with VPCLMULQDQ intrinsics ON
WITH_ARMV6 --without-armv6 arm: Build with ARMv6 intrinsics ON
WITH_ARMV8 --without-armv8 arm: Build with ARMv8 intrinsics ON
WITH_NEON --without-neon arm: Build with NEON intrinsics ON
WITH_MSA --without-msa mips: Build with MSA intrinsics ON
WITH_ALTIVEC --without-altivec ppc: Build with AltiVec (VMX) intrinsics ON
WITH_POWER8 --without-power8 ppc: Build with POWER8 intrinsics ON
WITH_POWER9 --without-power9 ppc: Build with POWER9 intrinsics ON
WITH_RVV --without-rvv riscv: Build with RVV intrinsics ON
WITH_RISCV_ZBC --without-zbc riscv: Build with RiscV ZBC intrinsics ON
WITH_S390_VX --without-s390-vx s390x: Build with S390 VX intrinsics on IBM Z ON
WITH_DFLTCC_DEFLATE --with-dfltcc-deflate s390x: Build with DFLTCC intrinsics for compression on IBM Z OFF
WITH_DFLTCC_INFLATE --with-dfltcc-inflate s390x: Build with DFLTCC intrinsics for decompression on IBM Z OFF
WITH_LSX loongarch: Build with LSX intrinsics ON
WITH_CRC32_LA --without-crc32-la loongarch: Build with vectorized CRC32 ON
WITH_INFLATE_STRICT Build with strict inflate distance checking OFF
WITH_INFLATE_ALLOW_INVALID_DIST Build with zero fill for inflate invalid distances OFF
WITH_BENCHMARK_APPS Build benchmark apps (currently libpng) OFF
WITH_ALL_FALLBACKS Build with all c-fallbacks (useful for Gbench comparisons) OFF
WITH_MAINTAINER_WARNINGS Build with project maintainer warnings OFF
WITH_SANITIZER Build with sanitizer (memory, address, undefined) OFF
WITH_FUZZERS Build test/fuzz OFF
WITH_CODE_COVERAGE Enable code coverage reporting OFF