zlib replacement with optimizations for "next generation" systems.
Go to file
2022-03-13 07:41:12 +01:00
.github/workflows Compile MSAN instrumented C++ libraries for MSAN build with googletest. 2022-03-13 07:41:12 +01:00
arch Use pclmulqdq accelerated CRC for exported function 2022-03-08 11:09:20 +01:00
cmake Prefer posix versions of MinGW for compiling against googletest. 2022-03-13 07:41:12 +01:00
doc upgrade links to HTTPS 2021-05-08 18:10:56 +02:00
test Compile MSAN instrumented C++ libraries for MSAN build with googletest. 2022-03-13 07:41:12 +01:00
tools Switch to using Codecov GitHub Action. 2022-02-23 21:03:18 +01:00
win32 Axe the SSE4 compare256 functions 2022-02-11 09:56:19 +01:00
.codecov.yaml Ignore code coverage for files in _dep directory. 2022-03-13 07:41:12 +01:00
.gitattributes Fix minor formatting issues 2021-10-13 15:43:53 +02:00
.gitignore Move CVE-2003-0107 test to Google Tests. 2022-03-13 07:41:12 +01:00
.shellcheckrc Import default codecfactor.io .shellcheckrc file. 2020-03-09 14:13:36 +01:00
adler32_p.h Reuse adler32_len_64 in adler32_c. 2021-12-02 09:27:21 +01:00
adler32.c Remove zutil.h includes from many files to prevent zlib.h being included. 2022-01-29 17:03:22 +01:00
chunkset_tpl.h Introduce zmemcpy to use unaligned access for architectures we know support unaligned access, otherwise use memcpy. 2022-02-10 16:10:48 +01:00
chunkset.c Introduce zmemcpy to use unaligned access for architectures we know support unaligned access, otherwise use memcpy. 2022-02-10 16:10:48 +01:00
CMakeLists.txt Move CVE-2003-0107 test to Google Tests. 2022-03-13 07:41:12 +01:00
compare256.c Introduce zmemcpy to use unaligned access for architectures we know support unaligned access, otherwise use memcpy. 2022-02-10 16:10:48 +01:00
compress.c Fix deflateBound and compressBound returning very small size estimates. 2021-12-20 14:49:27 +01:00
configure Move CVE-2003-0107 test to Google Tests. 2022-03-13 07:41:12 +01:00
cpu_features.c Move cpu_feature includes out of zutil.h. 2022-01-23 16:39:48 +01:00
cpu_features.h Use pclmulqdq accelerated CRC for exported function 2022-03-08 11:09:20 +01:00
crc32_comb_tbl.h Separate crc32 and crc32_combine tables so the crc32_combine tables are not included when not used if statically linking. Reduces code size by 4k. 2020-11-22 20:33:54 +01:00
crc32_comb.c Remove duplicate header includes. 2022-02-06 16:52:24 +01:00
crc32_fold.c Remove zutil.h includes from many files to prevent zlib.h being included. 2022-01-29 17:03:22 +01:00
crc32_fold.h Clean up crc32_fold structure and clearly define the size of the fold buffer. 2022-01-17 09:11:53 +01:00
crc32_p.h Remove zutil.h includes from many files to prevent zlib.h being included. 2022-01-29 17:03:22 +01:00
crc32_tbl.h Separate crc32 and crc32_combine tables so the crc32_combine tables are not included when not used if statically linking. Reduces code size by 4k. 2020-11-22 20:33:54 +01:00
crc32.c Remove duplicate header includes. 2022-02-06 16:52:24 +01:00
deflate_fast.c Fixed trailing whitespaces and missing new lines. 2021-09-22 16:00:46 +02:00
deflate_huff.c Separate huff, rle, and stored deflate strategies into their own source files. 2021-06-12 19:34:42 +02:00
deflate_medium.c Remove duplicate header includes. 2022-02-06 16:52:24 +01:00
deflate_p.h Switch longest_match in deflate_slow based on whether or not rolling hash is being used. 2021-06-25 20:09:14 +02:00
deflate_quick.c Introduce zmemcmp to use unaligned access for architectures we know support unaligned access, otherwise use memcmp. 2022-02-10 16:10:48 +01:00
deflate_rle.c Separate MIN_MATCH into STD_MIN_MATCH and WANT_MIN_MATCH 2021-06-13 20:55:01 +02:00
deflate_slow.c Prevent stale stub functions from being called in deflate_slow 2022-02-23 14:47:49 +01:00
deflate_stored.c Use MIN and MAX macros. 2021-06-13 20:56:06 +02:00
deflate.c Use cpu_check_features in inflate and deflate. 2022-01-23 16:39:48 +01:00
deflate.h Introduce zmemcpy to use unaligned access for architectures we know support unaligned access, otherwise use memcpy. 2022-02-10 16:10:48 +01:00
fallback_builtins.h Improved adler32 NEON performance by 30-47% 2022-02-24 16:00:51 +01:00
FAQ.zlib Spelling fixes 2021-05-16 13:20:15 +02:00
functable.c Use pclmulqdq accelerated CRC for exported function 2022-03-08 11:09:20 +01:00
functable.h Group together functable definitions that use deflate_state. 2022-01-23 16:39:48 +01:00
gzguts.h Remove gz_intmax implementation, since INT_MAX is always available in modern C implementations. 2021-12-19 15:40:52 +01:00
gzlib.c Remove gz_intmax implementation, since INT_MAX is always available in modern C implementations. 2021-12-19 15:40:52 +01:00
gzread.c.in Add support for name mangling 2021-10-09 09:19:55 +02:00
gzwrite.c Fixed part of conditional expression is always true since size is always greater than 0. 2022-01-08 00:08:02 +01:00
INDEX.md Remove misleading manpage. 2021-03-09 16:44:07 +01:00
infback.c Add back original version of inflate_fast for use with inflateBack. 2021-12-02 09:26:32 +01:00
inffast.c Introduce zmemcpy to use unaligned access for architectures we know support unaligned access, otherwise use memcpy. 2022-02-10 16:10:48 +01:00
inffast.h Add back original version of inflate_fast for use with inflateBack. 2021-12-02 09:26:32 +01:00
inffixed_tbl.h Fixed tab indentation for inffixed_tbl.h. 2020-09-24 15:42:02 +02:00
inflate_p.h Added checks and comments to ensure that when using raw mode no checksumming takes place. 2021-12-09 14:28:34 +01:00
inflate.c Use cpu_check_features in inflate and deflate. 2022-01-23 16:39:48 +01:00
inflate.h Clean up crc32_fold structure and clearly define the size of the fold buffer. 2022-01-17 09:11:53 +01:00
inftrees.c Minor optimization of inftrees.c based on profiling 2021-06-21 13:23:34 +02:00
inftrees.h Spelling fixes 2021-05-16 13:20:15 +02:00
insert_string_roll.c Added rolling hash functions for hash table. 2021-06-25 20:09:14 +02:00
insert_string_tpl.h Introduce zmemcpy to use unaligned access for architectures we know support unaligned access, otherwise use memcpy. 2022-02-10 16:10:48 +01:00
insert_string.c Added rolling hash functions for hash table. 2021-06-25 20:09:14 +02:00
LICENSE.md Update readme and create LICENSE.md file 2015-04-10 12:26:51 +02:00
Makefile.in Implement unit testing using Google Test framework. 2022-03-13 07:41:12 +01:00
match_tpl.h Introduce zmemcmp to use unaligned access for architectures we know support unaligned access, otherwise use memcmp. 2022-02-10 16:10:48 +01:00
PORTING.md Spelling fixes 2021-05-16 13:20:15 +02:00
README.md Axe the SSE4 compare256 functions 2022-02-11 09:56:19 +01:00
slide_hash.c Separate slide_hash_c in the same way that insert_string_c is separated from deflate.c. 2021-07-08 09:33:41 +02: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 Fixed undefined behavior of isgraph when character is not in the range 0 through 0xFF inclusive. 2021-09-03 11:21:09 +02:00
trees.h Renamed trees_p.h to trees.h. 2020-08-27 19:19:30 +02:00
uncompr.c Remove zutil.h includes from many files to prevent zlib.h being included. 2022-01-29 17:03:22 +01:00
zbuild.h Introduce zmemcmp to use unaligned access for architectures we know support unaligned access, otherwise use memcmp. 2022-02-10 16:10:48 +01:00
zconf-ng.h.in Add support for name mangling 2021-10-09 09:19:55 +02:00
zconf.h.in Add support for name mangling 2021-10-09 09:19:55 +02:00
zendian.h Clean up windows defines, use _WIN32 2020-06-08 15:09:17 +02:00
zlib_name_mangling-ng.h.in Remove gz_intmax implementation, since INT_MAX is always available in modern C implementations. 2021-12-19 15:40:52 +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 Remove gz_intmax implementation, since INT_MAX is always available in modern C implementations. 2021-12-19 15:40:52 +01:00
zlib-ng.h.in Fix compilation with clang-cl on windows 2022-02-09 22:03:03 +01:00
zlib-ng.map Remove gz_intmax implementation, since INT_MAX is always available in modern C implementations. 2021-12-19 15:40:52 +01:00
zlib.h.in Fix compilation with clang-cl on windows 2022-02-09 22:03:03 +01:00
zlib.map Remove gz_intmax implementation, since INT_MAX is always available in modern C implementations. 2021-12-19 15:40:52 +01:00
zlib.pc.cmakein Add support for name mangling 2021-10-09 09:19:55 +02:00
zlib.pc.in Add support for name mangling 2021-10-09 09:19:55 +02:00
zutil_p.h Move _POSIX_C_SOURCE define before first stdlib.h include in zbuild.h for posix_memalign. 2022-01-29 17:03:22 +01:00
zutil.c Added build system check for posix_memalign support. 2021-07-07 19:55:08 +02:00
zutil.h Move build basics to zbuild.h. 2022-01-29 17:03:22 +01:00

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)

CI Status
GitHub Actions Master Branch Status Master Branch Status Master Branch Status
Buildkite Build status
CodeFactor CodeFactor
OSS-Fuzz Fuzzing Status
Codecov codecov.io

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
    • Hash table implementation using CRC32-C intrinsics on x86 and ARM
    • Slide hash implementations using SSE2, AVX2, Neon, VMX & VSX
    • Compare256 implementations using SSE2 & AVX2
    • Inflate chunk copying using SSE2, 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, SPARC64, S390x using qemu

History

The motivation for this fork came after seeing several 3rd party contributions containing 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 lots of systems that predate the Internet. This is great, but it does complicate further development and maintainability. The zlib code has numerous workarounds for old compilers that do not understand ANSI-C 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. For example, the [v]s[n]printf workaround code has a whopping 8 different implementations just to cater to various old compilers. With this many workarounds cluttered throughout the code, new programmers with an idea/interest for zlib will need to take some time to figure out why all of these seemingly strange things are used, and how to work within those confines.

So I decided to make a fork, merge all the Intel optimizations, merge the Cloudflare optimizations that did not conflict, plus a couple of other smaller patches. Then I started cleaning out workarounds, various dead code, all contrib and example code as there is little point in having those in this fork for various reasons.

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.

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

Build

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 --native Compiles with full instruction set supported on this host (gcc/clang -march=native) OFF
WITH_SANITIZER --with-sanitizer Build with sanitizer (memory, address, undefined) OFF
WITH_FUZZERS --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 zlib-ng will temporarily be used instead by the program, without risking system-wide instability.

LD_PRELOAD=/opt/zlib-ng/libz.so.1.2.11.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

Contributing

Zlib-ng is a aiming to be open to contributions, and we would be delighted to receive pull requests on github. Just remember that any code you submit must be your own and it must be zlib licensed. Help with testing and reviewing of pull requests etc is also very much appreciated.

If you are interested in contributing, please consider joining our IRC channel #zlib-ng on the Freenode IRC network.

Acknowledgments

Thanks to Servebolt.com for sponsoring my maintainership of zlib-ng.

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
ZLIB_DUAL_LINK Dual link tests with system zlib OFF
UNALIGNED_OK Allow unaligned reads ON (x86, arm)
--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_SSE41 Build with SSE41 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_ALTIVEC --without-altivec Build with AltiVec (VMX) intrinsics ON
WITH_POWER8 --without-power8 Build with POWER8 optimisations 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 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