Commit Graph

52 Commits

Author SHA1 Message Date
Adam Stylinski
50e9ca06e2 Fold a copy into the adler32 function for UPDATEWINDOW for neon
So a lot of alterations had to be done to make this not worse and
so far, it's not really better, either. I had to force inlining for
the adler routine, I had to remove the x4 load instruction otherwise
pipelining stalled, and I had to use restrict pointers with a copy
idiom for GCC to inline a copy routine for the tail.

Still, we see a small benefit in benchmarks, particularly when done
with size of our window or larger. There's also an added benefit that
this will fix #1824.
2025-03-05 22:17:55 +01:00
Hans Kristian Rosbach
bf05e882b8 Continued cleanup of old UNALIGNED_OK checks
- Remove obsolete checks
- Fix checks that are inconsistent
- Stop compiling compare256/longest_match variants that never gets called
- Improve how the generic compare256 functions are handled.
- Allow overriding OPTIMAL_CMP

This simplifies the code and avoids having a lot of code in the compiled library than can never get executed.
2024-12-26 22:14:46 +01:00
Cameron Cawley
fc90e7b3fc Improved setting of OPTIMAL_CMP on ARM 2024-12-23 14:07:06 +01:00
Cameron Cawley
005c2d38c5 Set OPTIMAL_CMP for 32-bit PowerPC 2024-12-22 13:00:14 +01:00
Adam Stylinski
04d1b75819 Make big endians first class citizens again
No longer do the big iron on yore which lack SIMD optimized loads need
to search strings a byte at a time like primitive machines of the vax
era. This guard here was mostly due to the fact that the string
comparison was searched with "count trailing zero", which assumes an
endianness.  We can just conditionally use leading zeros when on big
endian and stop using the extremely naive C implementation. This makes
things a tad bit faster.
2024-12-21 13:16:08 +01:00
Hans Kristian Rosbach
509f6b5818 Since we long ago make unaligned reads safe (by using memcpy or intrinsics),
it is time to replace the UNALIGNED_OK checks that have since really only been
used to select the optimal comparison sizes for the arch instead.
2024-12-21 00:46:48 +01:00
Hans Kristian Rosbach
037ab0fd35 Revert "Since we long ago make unaligned reads safe (by using memcpy or intrinsics),"
This reverts commit 80fffd72f3.
It was mistakenly pushed to develop instead of going through a PR and the appropriate reviews.
2024-12-17 23:09:31 +01:00
Hans Kristian Rosbach
80fffd72f3 Since we long ago make unaligned reads safe (by using memcpy or intrinsics),
it is time to replace the UNALIGNED_OK checks that have since really only been
used to select the optimal comparison sizes for the arch instead.
2024-12-17 23:02:32 +01:00
Detlef Riekenberg
a4e7c34a4a zbuild: Provide a fallback for "ALIGNED_(x)" for other compiler 2024-12-08 12:51:06 +01:00
FantasqueX
a689e107c3 Replace non-ascii characters to fix MSVC warning 2024-09-20 13:21:27 +02:00
Mika Lindqvist
5b04d9ce04 Enable warning C4242 and treat warnings as errors for Visual C++. 2024-08-22 16:47:59 +02:00
Hans Kristian Rosbach
130055e8d1 Rewrite deflate memory allocation.
Deflate used to call allocate 5 times during init.

- 5 calls to external alloc function now becomes 1
- Handling alignment of allocated buffers is simplified
  - Efforts to align the allocated buffer now needs to happen only once.
  - Individual buffers are ordered so that they have natural sequential alignment.
- Due to reduced losses to alignment, we allocate less memory in total.
- While doing alloc(), we now store pointer to corresponding free(), avoiding crashes
  with applications that incorrectly set alloc/free pointers after running init function.
- Removed need for extra padding after window, chunked reads can now go beyond the window
  buffer without causing a segfault.

Co-authored-by: Ilya Leoshkevich <iii@linux.ibm.com>
2024-05-28 16:35:13 +02:00
Ilya Leoshkevich
1007e7a9c7 IBM zSystems DFLTCC: Extend sanitizer checks
Currently the DFLTCC sanitizer instrumentation is limited to
MSAN-unpoisoning the parameter block. Add ASAN and MSAN checks;
also MSAN-unpoison the window.

Introduce the generic instrument_read(), instrument_write() and
instrument_read_write() macros, that are modeled after the repsective
functions in the Linux kernel.
2024-05-06 22:51:54 +02:00
Vladislav Shchapov
dfced56c57 Remove unused Z_TLS and HAVE_THREAD_LOCAL
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
2023-12-25 20:47:24 +01:00
Mika Lindqvist
4ece1a480c Add support for __attribute__((__target__(...))) to overcome limitations of -march=native. 2023-12-25 20:43:31 +01:00
Hans Kristian Rosbach
828dde716b Expand support for symbol versioning to also allow multiple functions
with the same name to exist with bindings to different versions.
2023-07-24 18:33:23 +02:00
David Korth
8976caa3f0 Handle ARM64EC as ARM64.
ARM64EC is a new ARM64 variant introduced in Windows 11 that uses an
ABI similar to AMD64, which allows for better interoperability with
emulated AMD64 applications. When enabled in MSVC, it defines _M_AMD64
and _M_ARM64EC, but not _M_ARM64, so we need to check for _M_ARM64EC.
2023-07-16 12:42:38 +02:00
Ilya Leoshkevich
e23130bdea Define an empty __msan_unpoison() without Z_MEMORY_SANITIZER
Currently all the usages of __msan_unpoison() have to be guarded by
"#ifdef Z_MEMORY_SANITIZER". Simplify things by defining an empty
__msan_unpoison() when the code is compiled without MSan.
2023-07-16 12:41:50 +02:00
Hans Kristian Rosbach
1382b88a14 Fix z_size_t definition:
- Zlib Compat: Move definition of z_size_t to zconf.h, so it is exported to applications.
               Always defined as size_t to follow zlib 1.2.13 behavior with STDC compilers.
- Zlib-NG: Keeps internal definition of z_size_t in zbuild.h
2023-05-16 10:28:28 +02:00
Benjamin Stürz
e24334f369 Fix compilation on OpenBSD
Non-POSIX functions (like vasprintf() and swap16()) require
_BSD_SOURCE to be defined.

Signed-off-by: Benjamin Stürz <benni@stuerz.xyz>
2023-04-15 15:23:16 +02:00
lawadr
7a60d93829 Check for attribute aligned compiler support
Check for compiler support in CMake and the configure script. This
allows ALIGNED_ to be defined for more compilers so that more than
just Clang, GCC and MSVC can build the project.
2023-04-13 14:34:29 +02:00
Cameron Cawley
bfde4b91ee Remove unused PREFETCH macros 2023-03-27 20:06:25 +02:00
Vladislav Shchapov
c5b4aa34fe Replace __WIN__ with X86_FEATURES
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
2023-02-25 13:32:35 +01:00
Mika T. Lindqvist
c970422caa Fix definition of z_size_t to match documentation of legacy zlib API. 2023-02-23 12:17:34 +01: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
Pavel P
359e572966 Use const char* for z_error argument 2023-01-20 00:29:21 +01:00
Cameron Cawley
b3dcf11b42 Support using aligned_alloc() for memory allocation 2022-11-01 13:26:36 +01:00
Cameron Cawley
0c118a14dd Detect the availability of _Thread_local using a configure check 2022-10-23 15:01:26 +02:00
Cameron Cawley
baf0fd1234 Enable and fix -Wimplicit-fallthrough warnings 2022-10-23 15:00:46 +02:00
Mika Lindqvist
65c45b064a Fix memcpy() overflow in adler32_fold.c and crc32_fold.c
* On 32-bit platforms, last parameter of memcpy() is limited to SSIZE_MAX, but is likely to overlap if used
2022-10-11 12:22:59 +02:00
Nathan Moinvaziri
e22195e5bc Don't use unaligned access for memcpy instructions due to GCC 11 assuming it is aligned in certain instances. 2022-08-17 14:41:18 +02:00
Ilya Leoshkevich
bdcae54e5a Bump _POSIX_C_SOURCE to 200809 for strdup()
Google Test uses strdup(), which makes building tests fail on a fresh
MSYS2 setup:

In file included from zlib-ng/_deps/googletest-src/googletest/include/gtest/internal/gtest-internal.h:40,
                 from zlib-ng/_deps/googletest-src/googletest/include/gtest/gtest.h:62,
                 from zlib-ng/test/test_compress.cc:17:
zlib-ng/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h: In function ‘char* testing::internal::posix::StrDup(const char*)’:
zlib-ng/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:2046:47: error: ‘strdup’ was not declared in this scope; did you mean ‘StrDup’?
 2046 | inline char* StrDup(const char* src) { return strdup(src); }
      |                                               ^~~~~~
      |                                               StrDup

Bump _POSIX_C_SOURCE to enable this function. An alternative solution
would be to define _POSIX_C_SOURCE in test/CMakeLists.txt, but having a
bigger value for zlib-ng itself should not hurt.

Include zbuild.h earlier in minideflate.c in order to make the new
setting take effect for this file.
2022-06-30 12:23:11 +02:00
Nathan Moinvaziri
41d6739692 Fixed incorrect case for __clang__ preprocessor macro in zbuild.h. 2022-05-12 12:06:17 +02:00
Nathan Moinvaziri
c882034d48 Use _msan_unposion to unposion end of window for when it needs to read the past < chunksize bytes in the window. See #1245.
Co-authored-by: Adam Stylinski <kungfujesus06@gmail.com>
2022-04-14 00:00:27 +02:00
Nathan Moinvaziri
7a6d5ace97 Added check for UNALIGNED64_OK when defining zmemcpy_8 and zmemcmp_8. 2022-03-17 11:03:26 +01:00
Nathan Moinvaziri
c78c835a49 Make unaligned access being disabled configurable via build scripts. 2022-03-17 11:03:26 +01:00
Nathan Moinvaziri
e38c493337 Move UNALIGNED_OK detection to compile time instead of configure time. 2022-03-17 11:03:26 +01: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
363a95fb9b Introduce zmemcpy to use unaligned access for architectures we know support unaligned access, otherwise use memcpy. 2022-02-10 16:10:48 +01:00
Nathan Moinvaziri
b7192b694c Move _POSIX_C_SOURCE define before first stdlib.h include in zbuild.h for posix_memalign. 2022-01-29 17:03:22 +01:00
Nathan Moinvaziri
6d01d437fd Move build basics to zbuild.h. 2022-01-29 17:03:22 +01:00
Nathan Moinvaziri
3aa7b0bb5f Use STDC11 defined earlier in zbuild.h for Z_TLS check. 2021-07-07 19:55:08 +02:00
Hans Kristian Rosbach
101653c020 Add support for Thread Local Storage to ensure consistency in functable. 2021-06-18 09:24:35 +02:00
Hans Kristian Rosbach
40a12fe994 Change requested compiler standard to C11 2021-06-18 09:24:35 +02:00
Nathan Moinvaziri
857e4f1e04 Added Z_UNUSED define for ignore unused variables. 2021-06-18 09:16:44 +02:00
Nathan Moinvaziri
3f5801f151 Use MIN and MAX macros. 2021-06-13 20:56:06 +02:00
Mika Lindqvist
4747276ffe Move MIN() macro to zbuild.h 2021-06-04 20:54:28 +02:00
Nathan Moinvaziri
a540c3f963
Add optional support for thread local storage. (#733) 2020-08-23 09:59:38 +02:00
Nathan Moinvaziri
6dcc7bf815 For gzseek, gzoffset, gzopen, adler32_combine, crc32_combine and crc32_combine_gen, export 32-bit and 64-bit versions for zlib-compatible api and only 64-bit version (without 64 suffix) for zlib-ng native api. 2020-06-08 21:14:07 +02:00
Pavel P
ee1c9bc0be Avoid unnecessary include of windows.h from zbuild.h
zbuild.h is included from every .c file of zlib-ng, which forces every translation unit to parse all windows system includes only to be able to typedef ssize_t. This change removes windows.h include from zbuild.h and ssize_t is instead defined in-line with equivalent defines from windows.h
2020-03-27 12:37:27 +01:00