zlib replacement with optimizations for "next generation" systems.
Go to file
Hans Kristian Rosbach d54e3769be 2.2.1 Release
2024-07-02 15:55:49 +02:00
.github - Make codecov uploads happen even if some jobs have failed. 2024-05-23 16:30:37 +02:00
arch Fix a couple typos found by codespell 2024-06-12 14:06:37 +02:00
cmake Improved ACLE check (#1727) 2024-06-13 13:23:29 +02:00
doc Added Intel's Fast CRC Computation for Generic Polynomials Using PCLMULQDQ Instruction paper to docs folder. 2022-06-07 12:43:27 +02:00
test Enabled orphaned unit tests for compare256_rle family of functions. 2024-05-30 18:15:08 +02:00
tools Remove unused code in makecrct.c 2024-02-05 08:17:33 +01:00
win32 Rename cpu_functions.h to arch_functions.h in depcheck.cpp 2024-03-04 11:59:09 +01:00
.codecov.yaml Ignore code coverage for files in _dep directory. 2022-03-13 07:41:12 +01:00
.gitattributes Fix lint trailing whitespace error. 2024-05-30 20:03:51 +02:00
.gitignore Add temporary cmake build dirs/files to gitignore 2023-02-02 17:33:47 +01:00
.shellcheckrc Import default codecfactor.io .shellcheckrc file. 2020-03-09 14:13:36 +01:00
adler32_p.h Use size_t instead of uint64_t for len in all adler32 functions 2023-01-22 00:58:12 +01:00
adler32.c Explicitly indicate functions are conditionally dispatched 2024-03-06 23:32:15 +01:00
arch_functions.h Rename cpu_functions.h to arch_functions.h. 2024-02-22 20:11:46 +01:00
chunkset_tpl.h Inline CHUNKCOPY and CHUNKUNROLL 2024-02-22 20:20:42 +01:00
CMakeLists.txt Clean up memory allocation functions that are no longer used, and its tests. 2024-05-28 16:35:13 +02:00
compare256_rle.h Added support for unaligned/intrinsic to deflate_rle. 2023-05-16 10:27:28 +02:00
compress.c Fix definition of z_size_t to match documentation of legacy zlib API. 2023-02-23 12:17:34 +01:00
configure don't use zlib-ng's -Wl,--version-script in tests (#1750) 2024-06-28 13:21:33 +02:00
cpu_features.c Add supporting RISC-V cross compilation workflows 2023-05-12 16:57:32 +02:00
cpu_features.h Allow disabling runtime CPU features detection in tests and benchmarks 2024-04-04 13:47:02 +02:00
crc32_braid_comb_p.h Correct comment for x2nmodp. 2022-05-25 12:04:35 +02:00
crc32_braid_comb.c Move crc32 C fallbacks to arch/generic 2024-01-19 15:22:34 +01:00
crc32_braid_p.h Split CPU features checks and CPU-specific function prototypes and reduce include-dependencies. 2024-02-22 20:11:46 +01:00
crc32_braid_tbl.h Speed up software CRC-32 computation by a factor of 1.5 to 3. 2022-05-25 12:04:35 +02:00
crc32.c Explicitly indicate functions are conditionally dispatched 2024-03-06 23:32:15 +01:00
crc32.h Move crc32 C fallbacks to arch/generic 2024-01-19 15:22:34 +01:00
deflate_fast.c Explicitly indicate functions are conditionally dispatched 2024-03-06 23:32:15 +01:00
deflate_huff.c zlib 1.3.1 2024-02-07 19:15:56 +01:00
deflate_medium.c Clean up insert_match() in deflate_medium 2024-04-11 12:43:06 +02:00
deflate_p.h zlib 1.3.1 2024-02-07 19:15:56 +01:00
deflate_quick.c Explicitly indicate functions are conditionally dispatched 2024-03-06 23:32:15 +01:00
deflate_rle.c zlib 1.3.1 2024-02-07 19:15:56 +01:00
deflate_slow.c Explicitly indicate functions are conditionally dispatched 2024-03-06 23:32:15 +01:00
deflate_stored.c Fix a couple typos found by codespell 2024-06-12 14:06:37 +02:00
deflate.c Rewrite deflate memory allocation. 2024-05-28 16:35:13 +02:00
deflate.h Rewrite deflate memory allocation. 2024-05-28 16:35:13 +02:00
fallback_builtins.h Split cpu_features.h by architecture. 2024-01-30 20:50:05 +01:00
FAQ.zlib Remove mentions of an official zlib DLL distribution. 2024-02-07 19:15:56 +01:00
functable.c Fix illegal instruction usage in Xeon Phi x200 processors 2024-05-19 12:25:01 +02:00
functable.h Replace conditional call to functable.force_init with macro FUNCTABLE_INIT 2024-03-06 23:32:15 +01:00
gzguts.h zlib 1.3.1 2024-02-07 19:15:56 +01:00
gzlib.c zlib 1.3.1 2024-02-07 19:15:56 +01:00
gzread.c.in Fix bug when gzungetc() is used immediately after gzopen(). 2023-08-24 11:22:33 +02:00
gzwrite.c Fix crash when gzsetparams() attempted for transparent write. 2023-02-03 15:49:02 +01:00
INDEX.md Remove misleading manpage. 2021-03-09 16:44:07 +01:00
infback.c Rewrite inflate memory allocation. 2024-05-28 16:35:13 +02:00
inffast_tpl.h Inflate: add fast-path for literals 2023-02-24 13:24:49 +01:00
inffixed_tbl.h Fixed tab indentation for inffixed_tbl.h. 2020-09-24 15:42:02 +02:00
inflate_p.h Rewrite inflate memory allocation. 2024-05-28 16:35:13 +02:00
inflate.c Simplify inflate window management now that there is no need to 2024-05-30 13:59:40 +02:00
inflate.h Simplify inflate window management now that there is no need to 2024-05-30 13:59:40 +02:00
inftrees.c zlib 1.3.1 2024-02-07 19:15:56 +01:00
inftrees.h Discard repeated words 2023-08-07 08:28:16 +02:00
insert_string_roll.c Remove unused 's' parameter from HASH_CALC macro 2024-02-23 13:34:10 +01:00
insert_string_tpl.h Remove unused 's' parameter from HASH_CALC macro 2024-02-23 13:34:10 +01:00
insert_string.c Move update_hash(), insert_string() and quick_insert_string() out of functable 2024-02-23 13:34:10 +01:00
LICENSE.md Update copyright years in other source files. 2024-02-07 19:15:56 +01:00
Makefile.in 2.2.1 Release 2024-07-02 15:55:49 +02:00
match_tpl.h Remove deflate_state parameter from update_hash functions. 2024-02-23 13:34:10 +01:00
PORTING.md Update PORTING.md to document zlib-ng memory allocation details. 2024-05-28 16:35:13 +02:00
README.md Add option to disable runtime CPU detection 2024-03-06 23:32:15 +01:00
trees_emit.h inttypes.h includes stdint.h, so only include one of them. 2021-12-19 15:40:19 +01:00
trees_tbl.h Separate MIN_MATCH into STD_MIN_MATCH and WANT_MIN_MATCH 2021-06-13 20:55:01 +02:00
trees.c Avoid empty function by renaming bi_flush to zng_tr_flush_bits. 2024-02-12 14:37:19 +01:00
trees.h Renamed trees_p.h to trees.h. 2020-08-27 19:19:30 +02:00
uncompr.c Fix definition of z_size_t to match documentation of legacy zlib API. 2023-02-23 12:17:34 +01:00
zbuild.h Rewrite deflate memory allocation. 2024-05-28 16:35:13 +02:00
zconf-ng.h.in zlib 1.3.1 2024-02-07 19:15:56 +01:00
zconf.h.in zlib 1.3.1 2024-02-07 19:15:56 +01:00
zendian.h Handle ARM64EC as ARM64. 2023-07-16 12:42:38 +02:00
zlib_name_mangling-ng.h.in Fix various incorrect name mangling 2023-02-09 01:54:19 +01:00
zlib_name_mangling.h.empty Add support for name mangling 2021-10-09 09:19:55 +02:00
zlib_name_mangling.h.in Fix various incorrect name mangling 2023-02-09 01:54:19 +01:00
zlib-config.cmake.in Add more result variables to the cmake package configuration 2024-03-03 23:23:23 +01:00
zlib-ng-config.cmake.in Generate CMake package configuration files 2024-01-30 20:51:05 +01:00
zlib-ng.h.in 2.2.1 Release 2024-07-02 15:55:49 +02:00
zlib-ng.map Fix wrong names and invalid entries in zlib.map and zlib-ng.map 2023-02-09 01:54:19 +01:00
zlib.h.in 2.2.1 Release 2024-07-02 15:55:49 +02:00
zlib.map Add back gz_intmax for zlib compatibility when linking statically 2024-02-07 19:15:56 +01:00
zlib.pc.cmakein pkgconfig file: propagate WITH_GZFILEOP 2023-11-07 18:58:30 +01:00
zlib.pc.in [configure] Propagate -DWITH_GZFILEOP to pkgconfig. 2023-11-08 11:34:53 +01:00
zutil_p.h Memory alloc size must be a multiple of alignment for aligned_alloc. 2024-02-07 19:16:28 +01:00
zutil.c 2.2.1 Release 2024-07-02 15:55:49 +02:00
zutil.h Clean up memory allocation functions that are no longer used, and its tests. 2024-05-28 16:35:13 +02:00

CI Stable Develop
GitHub Actions Stable CMake
Stable Configure
Stable NMake
Develop CMake
Develop Configure
Develop NMake
CodeFactor CodeFactor CodeFactor
OSS-Fuzz Fuzzing Status Fuzzing Status
Codecov codecov codecov

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
  • Modern C11 syntax and a clean code layout
  • Deflate medium and quick algorithms based on Intels zlib fork
  • Support for CPU intrinsics when available
    • Adler32 implementation using SSSE3, AVX2, AVX512, AVX512-VNNI, Neon, VMX & VSX
    • CRC32-B implementation using PCLMULQDQ, VPCLMULQDQ, ACLE, & IBM Z
    • Slide hash implementations using SSE2, AVX2, ARMv6, Neon, VMX & VSX
    • Compare256 implementations using SSE2, AVX2, Neon, POWER9 & RVV
    • Inflate chunk copying using SSE2, SSSE3, AVX, Neon & VSX
    • Support for hardware-accelerated deflate using IBM Z DFLTCC
  • Unaligned memory read/writes and large bit buffer improvements
  • Includes improvements from Cloudflare and Intel forks
  • Configure, CMake, and NMake build system support
  • Comprehensive set of CMake unit tests
  • Code sanitizers, fuzzing, and coverage
  • GitHub Actions continuous integration on Windows, macOS, and Linux
    • Emulated CI for ARM, AARCH64, 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_ENABLE_TESTS Build test binaries 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_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_SANITIZER Build with sanitizer (memory, address, undefined) OFF
WITH_GTEST Build gtest_zlib ON
WITH_FUZZERS Build test/fuzz OFF
WITH_BENCHMARKS Build test/benchmarks OFF
WITH_MAINTAINER_WARNINGS Build with project maintainer warnings OFF
WITH_CODE_COVERAGE Enable code coverage reporting OFF

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
FORCE_SSE2 --force-sse2 Skip runtime check for SSE2 instructions (Always on for x86_64) OFF (x86)
WITH_AVX2 Build with AVX2 intrinsics ON
WITH_AVX512 Build with AVX512 intrinsics ON
WITH_AVX512VNNI Build with AVX512VNNI intrinsics ON
WITH_SSE2 Build with SSE2 intrinsics ON
WITH_SSSE3 Build with SSSE3 intrinsics ON
WITH_SSE42 Build with SSE42 intrinsics ON
WITH_PCLMULQDQ Build with PCLMULQDQ intrinsics ON
WITH_VPCLMULQDQ --without-vpclmulqdq Build with VPCLMULQDQ intrinsics ON
WITH_ACLE --without-acle Build with ACLE intrinsics ON
WITH_NEON --without-neon Build with NEON intrinsics ON
WITH_ARMV6 --without-armv6 Build with ARMv6 intrinsics ON
WITH_ALTIVEC --without-altivec Build with AltiVec (VMX) intrinsics ON
WITH_POWER8 --without-power8 Build with POWER8 optimisations ON
WITH_RVV Build with RVV intrinsics ON
WITH_CRC32_VX --without-crc32-vx Build with vectorized CRC32 on IBM Z ON
WITH_DFLTCC_DEFLATE --with-dfltcc-deflate Build with DFLTCC intrinsics for compression on IBM Z OFF
WITH_DFLTCC_INFLATE --with-dfltcc-inflate Build with DFLTCC intrinsics for decompression on IBM Z OFF
WITH_UNALIGNED --without-unaligned Allow optimizations that use unaligned reads if safe on current arch 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
INSTALL_UTILS Copy minigzip and minideflate during install OFF
ZLIBNG_ENABLE_TESTS Test zlib-ng specific API ON