Commit Graph

30 Commits

Author SHA1 Message Date
Cameron Cawley
d7e121e56b Use GCC's may_alias attribute for unaligned memory access 2024-12-24 12:55:44 +01:00
Carlos Sánchez López
3da40c259e Fixes build issues C4242, C4244 and C4334 caused by loss of data bugs due to data type mismatch in various files. 2024-08-16 11:52:50 +02:00
Vladislav Shchapov
fe0a6407da Explicitly indicate functions are conditionally dispatched
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
2024-03-06 23:32:15 +01:00
Hans Kristian Rosbach
9953f12e21 Move update_hash(), insert_string() and quick_insert_string() out of functable
and remove SSE4.2 and ACLE optimizations. The functable overhead is higher
than the benefit from using optimized functions.
2024-02-23 13:34:10 +01:00
Mika Lindqvist
f346148df0 Fix out-of-bound access of zng_length_codes. 2023-05-07 20:36:34 +02:00
Nathan Moinvaziri
596f6c2f37 Use memcpy instead of memcmp for unaligned memory comparisons.
Use memcpy because it is better supported for compilers that support unaligned
access than memcmp.
2023-02-08 22:12:37 +01:00
Nathan Moinvaziri
b047c7247f Prefix shared functions to prevent symbol conflict when linking native api against compat api. 2023-01-09 15:10:11 +01:00
Ilya Leoshkevich
9be98893aa Use PREFIX() for some of the Z_INTERNAL symbols
https://github.com/powturbo/TurboBench links zlib and zlib-ng into the
same binary, causing non-static symbol conflicts. Fix by using PREFIX()
for flush_pending(), bi_reverse(), inflate_ensure_window() and all of
the IBM Z symbols.

Note: do not use an explicit zng_, since one of the long-term goals is
to be able to link two versions of zlib-ng into the same binary for
benchmarking [1].

[1] https://github.com/zlib-ng/zlib-ng/pull/1248#issuecomment-1096648932
2022-04-27 10:37:43 +02:00
Nathan Moinvaziri
ab6665b1be Introduce zmemcmp to use unaligned access for architectures we know support unaligned access, otherwise use memcmp. 2022-02-10 16:10:48 +01:00
Nathan Moinvaziri
66506ace8d Convert compare258 to compare256 and moved 2 byte check into deflate_quick. Prevents having multiple compare258 functions with 2 byte checks. 2022-01-16 17:30:15 +01:00
Hans Kristian Rosbach
6bea850887 Minor formatting changes related to MIN_MATCH/MAX_MATCH 2021-06-13 20:55:01 +02:00
Hans Kristian Rosbach
cf9127a231 Separate MIN_MATCH into STD_MIN_MATCH and WANT_MIN_MATCH
Rename MAX_MATCH to STD_MAX_MATCH
2021-06-13 20:55:01 +02:00
Ilya Leoshkevich
ff0ab283f0 Fix block_open handling in deflate_quick()
The attached test fails with "inflate() failed", because the deflate
stream that it produces ends up being corrupted. Bisect points to the
commit e7bb6db09a ("Replace hash_bits, hash_size and hash_mask with
defines."), but it's most likely a coincidence.

In any case, the reason is that if we happen to simultaneously exhaust
all the buffers (in, out and bi), we return finish_started without
writing the end of block symbol, which will never happen afterwards.

Fix by adding another check to the tricky condition: if we are in the
middle of a block, return need_more instead of finish_started.
2021-03-17 10:08:32 +01:00
Ilya Leoshkevich iii@linux.ibm.com
04ae6d8b19 Fix bi_valid handling in deflate_quick()
The attached test started failing after commit ad89d5131b ("Don't
write end of last block when returning finish_started."): either with
"bi_buf not flushed" message in debug builds, or by producing corrupted
output in release builds.

The problem is that we must not return finish_started when bi_buf is
not empty, because the bits there will be lost. Fix by checking that
bi_valid is not 0.
2021-03-16 12:21:30 +01:00
Nathan Moinvaziri
bc5915e2de Fixed unsigned integer overflow ASAN error when hash_head > s->strstart.
zlib-ng/deflate_medium.c:244:47: runtime error: unsigned integer overflow: 58442 - 58452 cannot be represented in type 'unsigned int'

Co-authored-by: Mika Lindqvist <postmaster@raasu.org>
Co-authored-by: Hans Kristian Rosbach <hk-git@circlestorm.org>
2020-10-18 14:35:55 +02:00
Nathan Moinvaziri
7cffba4dd6 Rename ZLIB_INTERNAL to Z_INTERNAL for consistency. 2020-08-31 12:33:16 +02:00
Hans Kristian Rosbach
3a26093baf Fix some of the old and new conversion warnings in deflate* 2020-08-27 19:20:38 +02:00
Nathan Moinvaziri
072f0bd93d Return proper exit code after flushing end block in deflate_quick when no available output. 2020-07-14 06:15:43 +02:00
Hans Kristian Rosbach
47b1208c44 Add likely/unlikely hinting to all deflate algorithms. 2020-07-03 15:33:43 +02:00
Nathan Moinvaziri
ad89d5131b Don't write end of last block when returning finish_started. 2020-06-28 11:17:44 +02:00
Nathan Moinvaziri
3f6e40d8fc Fixed avail_out == 0 conditional not returning need_more in deflate_quick.
Fixed ending block when returning need_more caused problems with inflate.

So instead of ending the block each time the function returns to finish the last block, we check upon start to see if it is the last block and if the last block has been started, and if not it will close the previous block and start the last block.
2020-06-28 11:17:44 +02:00
Nathan Moinvaziri
203ddfc745 Fixed whitespace in deflate_quick. 2020-06-27 16:24:14 +02:00
Nathan Moinvaziri
e617236ab3 Move check to start block out of main loop for performance reasons. 2020-06-18 22:12:10 +02:00
Nathan Moinvaziri
1631b5cf3a Fixed deflate_quick to not emit a block when there is no available input. Pigz requires no blocks to be emitted in certain instances when calling deflate with Z_BLOCK.
Fixed end block not being emitted between calls to deflate_quick causing invalid stored block lengths in certain instances.
2020-06-18 22:12:10 +02:00
Nathan Moinvaziri
bf01f6b9ea Move check for match length in deflate_quick to check_match. 2020-06-08 21:16:31 +02:00
Nathan Moinvaziri
b6b8ad6c0f Make deflate_quick algorithm available to all architectures. #205 2020-06-08 15:01:50 +02:00
hansr
f24d42f977 Separate arch-specific code into separate folders 2014-10-14 12:08:05 +02:00
hansr
3f8e26e0b7 Remove workarounds for non-ANSI-C compatible compilers (Part 2)
-Removing usage of OF() definition
2014-10-12 22:57:27 +02:00
Martin O. Pollard
ed145f4cf0 Add forward declarations for fill_window_sse and flush_pending to deflate_quick.c. 2014-07-26 15:53:17 -07:00
Jim Kukunas
d948170e11 deflate: add new deflate_quick strategy for level 1
The deflate_quick strategy is designed to provide maximum
deflate performance.

deflate_quick achieves this through:
    - only checking the first hash match
    - using a small inline SSE4.2-optimized longest_match
    - forcing a window size of 8K, and using a precomputed dist/len
      table
    - forcing the static Huffman tree and emitting codes immediately
      instead of tallying

This patch changes the scope of flush_pending, bi_windup, and
static_ltree to ZLIB_INTERNAL and moves END_BLOCK, send_code,
put_short, and send_bits to deflate.h.

Updates the configure script to enable by default for x86. On systems
without SSE4.2, fallback is to deflate_fast strategy.

Fixes #6
Fixes #8
2014-07-26 15:53:17 -07:00