summaryrefslogtreecommitdiff
path: root/inffast.c
AgeCommit message (Collapse)Author
2021-12-24Fix UB in inffast.c when not using windowOri Livneh
When not using window, `window + wsize` applies a zero offset to a null pointer, which is undefined behavior.
2021-12-24Fixed trailing whitespaces and missing new lines.Nathan Moinvaziri
2021-06-21Cast calculation of safe length to unsigned int to avoid compiler warnings.Mika Lindqvist
2021-06-13Must use safe chunk copies due to inflateBack using the same allocation for ↵Nathan Moinvaziri
output and window. In this instance if too many bytes are written it will not correctly write matches with distances close to the window size.
2021-06-11[inflate_fast] Always use safe versions of chunkcopy and chunkmemset to ↵Nathan Moinvaziri
avoid errors with optimizations enabled.
2020-10-24Small formatting changes in inflate.c, inflate.h and inffast.cHans Kristian Rosbach
2020-10-24inflate: add SET_BAD macro, to make inflate.c a little cleaner.Hans Kristian Rosbach
2020-08-31Rename ZLIB_INTERNAL to Z_INTERNAL for consistency.Nathan Moinvaziri
2020-08-23Reintroduce support for ZLIB_CONST in compat mode. (#704)Mika Lindqvist
* Reintroduce support for ZLIB_CONST in compat mode.
2020-08-16Optimize inflate_fast for a 0.8% speedupJosh Triplett
When inflate_fast checks for extra length bits, it first checks if the number of extra length bits (in op) is non-zero. However, if the number of extra length bits is 0, the `bits < op` check will be false, BITS(op) will be 0, and DROPBITS(op) will do nothing. So, drop the conditional, for a speedup of about 0.8%. This makes the handling of extra length bits match the handling of extra dist bits, which already lacks the extra conditional.
2020-06-28Only calculate inflate chunk size once and store it for future use for ↵Nathan Moinvaziri
performance.
2020-06-28Split memcopy by architecture.Nathan Moinvaziri
Use uint8_t[8] struct on big-endian machines for speed.
2020-02-07Fixed formatting, 4 spaces for code intent, 2 spaces for preprocessor ↵Nathan Moinvaziri
indent, initial function brace on the same line as definition, removed extraneous spaces and new lines.
2019-10-25Comment assert in chunkmemset when len < sizeof(uint64_t) since the function ↵Nathan Moinvaziri
handles that condition properly.
2019-10-25Fixed assert during inflate fast when len < sizeof(uint64_t).Nathan Moinvaziri
2019-08-06Deduplicate common inflate/inflatefast/inflateBack macros into inflate_p.hHans Kristian Rosbach
2019-07-18Add zng_ prefix to internal functions to avoid linking conflicts with zlib. ↵Nathan Moinvaziri
(#363)
2019-03-27fix oss-fuzz/13863Sebastian Pop
The oss fuzzers started failing with the following assert ``` ASSERT: 0 == memcmp(data + offset, buf, len) ``` after the following patch has been pulled in the tree: ``` commit 20ca64fa5d2d8a7421ed86b68709ef971dcfbddf Author: Sebastian Pop <s.pop@samsung.com> Date: Wed Mar 6 14:16:20 2019 -0600 define and use chunkmemset instead of byte_memset for INFFAST_CHUNKSIZE ``` The function chunkcopysafe is assuming that the input `len` is less than 16 bytes: ``` if ((safe - out) < (ptrdiff_t)INFFAST_CHUNKSIZE) { ``` but we were called with `len = 22` because `safe` was defined too small: ``` - safe = out + (strm->avail_out - INFFAST_CHUNKSIZE); ``` and the difference `safe - out` was 16 bytes smaller than the actual `len`. The patch fixes the initialization of `safe` to: ``` + safe = out + strm->avail_out; ```
2019-03-21define and use chunkmemset instead of byte_memset for INFFAST_CHUNKSIZESebastian Pop
2019-03-21move INFFAST_CHUCKSIZE code to memcopy.hSebastian Pop
2019-03-08remove MEMCPY, replace with memcpySebastian Pop
2019-03-01Fixed arithmetic overflow warnings on Windows (#302)Nathan Moinvaziri
Fixed arithmetic overflow warnings in MSVC. Fixed uint64_t to uint32_t casting warning. Added assert to check if bits is greater than 32 before cast.
2019-01-15Small speedup to inflate [psumbera].Mark Adler
Seeing a few percent speedup by using a pointer instead of an assigned structure. This seems to help the compiler to optimize better.
2018-12-18bug #117: speed up inflate_fastSebastian Pop
Based on a patch by Nigel Tao: https://github.com/madler/zlib/pull/292/commits/e0ff1f330cc03ee04843f857869b4036593ab39d This patch makes unzipping of files up to 1.2x faster on x86_64. The other part (1.3x speedup) of the patch by Nigel Tao is unsafe as discussed in the review of that pull request. zlib-ng already has a different way to optimize the memcpy for that missing part. The original patch was enabled only on little-endian machines. This patch adapts the loading of 64 bits at a time to big endian machines. Benchmarking notes from Hans Kristian Rosbach: https://github.com/zlib-ng/zlib-ng/pull/224#issuecomment-444837182 Benchmark runs: 7, tested levels: 0-7, testfile 100M develop at 796ad10 with -O3: Level Comp Comptime min/avg/max Decomptime min/avg/max 0 100.02% 0.01/0.01/0.02 0.08/0.09/0.11 1 47.08% 0.49/0.50/0.51 0.37/0.39/0.40 2 36.02% 1.10/1.12/1.13 0.39/0.39/0.40 3 34.77% 1.32/1.34/1.37 0.38/0.38/0.38 4 33.41% 1.50/1.53/1.56 0.37/0.37/0.38 5 33.07% 1.85/1.87/1.90 0.36/0.37/0.38 6 32.83% 2.54/2.57/2.61 0.36/0.37/0.38 avg 45.31% 1.28 0.34 tot 62.60 16.58 PR224 with -O3: Level Comp Comptime min/avg/max Decomptime min/avg/max 0 100.02% 0.01/0.01/0.02 0.09/0.09/0.10 1 47.08% 0.49/0.50/0.51 0.37/0.37/0.38 2 36.02% 1.09/1.11/1.13 0.38/0.38/0.39 3 34.77% 1.32/1.34/1.38 0.35/0.36/0.38 4 33.41% 1.49/1.52/1.54 0.36/0.36/0.37 5 33.07% 1.85/1.88/1.93 0.35/0.36/0.37 6 32.83% 2.55/2.58/2.65 0.35/0.35/0.36 avg 45.31% 1.28 0.33 tot 62.48 16.02 So I see about a 5.4% speedup on my x86_64 machine, not quite the 1.2x speedup but a nice speedup nevertheless. This benchmark measures the total execution time of minigzip, so that might have caused some inefficiencies. At -O2, I only see a 2.7% speedup.
2018-03-22Move private defines from zconf.h and zconf-ng.h to zbuild.hMika Lindqvist
* move definition of z_size_t to zbuild.h
2018-01-31Adapt code to support PREFIX macros and update build scriptsMika Lindqvist
2017-03-29inflate: improve performance of memory copy operationsSebastian Pop
When memory copy operations happen byte by byte, the processors are unable to fuse the loads and stores together because of aliasing issues. This patch clusters some of the memory copy operations in chunks of 16 and 8 bytes. For byte memset, the compiler knows how to prepare the chunk to be stored. When the memset pattern is larger than a byte, this patch builds the pattern for chunk memset using the same technique as in Simon Hosie's patch https://codereview.chromium.org/2722063002 This patch improves by 50% the performance of zlib decompression of a 50K PNG on aarch64-linux and x86_64-linux when compiled with gcc-7 or llvm-5. The number of executed instructions reported by valgrind --tool=cachegrind on the decompression of a 50K PNG file on aarch64-linux: - before the patch: I refs: 3,783,757,451 D refs: 1,574,572,882 (869,116,630 rd + 705,456,252 wr) - with the patch: I refs: 2,391,899,214 D refs: 899,359,836 (516,666,051 rd + 382,693,785 wr) The compression of a 260MB directory containing the code of llvm into a tar.gz of 35MB and decompressing that with minigzip -d on i7-4790K x86_64-linux, it takes 0.533s before the patch and 0.493s with the patch, on Juno-r0 aarch64-linux A57, it takes 2.796s before the patch and 2.467s with the patch, on Juno-r0 aarch64-linux A53, it takes 4.055s before the patch and 3.604s with the patch.
2017-03-24Inflate using wider loads and stores and a minimum of branches. (#95)Simon Hosie
* Inflate using wider loads and stores. In inflate_fast() the output pointer always has plenty of room to write. This means that so long as the target is capable, wide un-aligned loads and stores can be used to transfer several bytes at once. When the reference distance is too short simply unroll the data a little to increase the distance. Change-Id: I59854eb25d2b1e43561c8a2afaf9175bf10cf674
2017-03-24call memset for read after write dependences at distance 1Sebastian Pop
On a benchmark using zlib to decompress a PNG image this change shows a 20% speedup. It makes sense to special case distance = 1 of read after write dependences because it is possible to replace the loop kernel with a memset which is usually implemented in assembly in the libc, and because of the frequency at which distance = 1 appears during the PNG decompression: Distance Frequency 1 1009001 6 64500 9 29000 3 25500 144 14500 12 10000 15 3500 7 2000 24 1000 21 1000 18 1000 87 500 22 500 192 500
2017-02-13zlib 1.2.11Mark Adler
2017-02-09zlib 1.2.9Mark Adler
2017-01-31Use post-increment only in inffast.c.Mark Adler
An old inffast.c optimization turns out to not be optimal anymore with modern compilers, and furthermore was not compliant with the C standard, for which decrementing a pointer before its allocated memory is undefined. Per the recommendation of a security audit of the zlib code by Trail of Bits and TrustInSoft, in support of the Mozilla Foundation, this "optimization" was removed, in order to avoid the possibility of undefined behavior.
2015-12-14Type cleanup.Mika Lindqvist
2015-06-05Revert "Replace 'unsigned long' with most suitable fixed-size type."Hans Kristian Rosbach
This commit was cherry-picked and was not done, resulting in a few problems with gcc on 64bit windows. This reverts commit edd7a72e056b994458ff040d4740b16b35336b60. Conflicts: arch/x86/crc_folding.c arch/x86/fill_window_sse.c deflate.c deflate.h match.c trees.c
2015-05-25Style cleanup for inflate codeHans Kristian Rosbach
2015-05-23Replace 'unsigned long' with most suitable fixed-size type.Mika Lindqvist
2015-05-13z_const -> constDaniel Axtens
Signed-off-by: Daniel Axtens <dja@axtens.net> Conflicts: arch/x86/crc_folding.c crc32.c
2015-04-26Cleanup: Replace 'z_streamp' with 'z_stream *'Hans Kristian Rosbach
2014-11-05Remove support for ASMV and ASMINF defines and clean up match.c handling.hansr
This makes it easier to implement support for ASM replacements using configure parameters if needed later. Also since zlib-ng uses compiler intrinsics, this needed a cleanup in any case.
2014-10-18Rewrite K&R-style function prototypes to ANSI-C-style.hansr
Only internal functions, no exported functions in this commit.
2014-10-13inffast.c: add BITS and DROPBITS macros like inflate.cZhaoxiu Zeng
2014-10-09Remove FAR definitionhansr
Remove a few leftovers from the legacy OS support removal
2013-03-24zlib 1.2.7.1Mark Adler
2013-03-24Line length cleanup.Mark Adler
2012-08-13Clean up the usage of z_const and respect const usage within zlib.Mark Adler
This patch allows zlib to compile cleanly with the -Wcast-qual gcc warning enabled, but only if ZLIB_CONST is defined, which adds const to next_in and msg in z_stream and in the in_func prototype. A --const option is added to ./configure which adds -DZLIB_CONST to the compile flags, and adds -Wcast-qual to the compile flags when ZLIBGCCWARN is set in the environment.
2011-09-09zlib 1.2.5Mark Adler
2011-09-09zlib 1.2.4.5Mark Adler
2011-09-09zlib 1.2.3.5Mark Adler
2011-09-09zlib 1.2.3.4Mark Adler
2011-09-09zlib 1.2.3.3Mark Adler