Line | Count | Source |
1 | | /* zutil_p.h -- Private inline functions used internally in zlib-ng |
2 | | * For conditions of distribution and use, see copyright notice in zlib.h |
3 | | */ |
4 | | |
5 | | #ifndef ZUTIL_P_H |
6 | | #define ZUTIL_P_H |
7 | | |
8 | | #if defined(HAVE_POSIX_MEMALIGN) || defined(HAVE_ALIGNED_ALLOC) |
9 | | # include <stdlib.h> |
10 | | #elif defined(__FreeBSD__) |
11 | | # include <stdlib.h> |
12 | | # include <malloc_np.h> |
13 | | #elif defined(HAVE_MEMALIGN) || defined(HAVE__ALIGNED_MALLOC) |
14 | | # include <malloc.h> |
15 | | #else |
16 | | /* Fallback, when no other aligned allocation function was found */ |
17 | | # include <stdlib.h> |
18 | | #endif |
19 | | |
20 | | /* Function to allocate 16 or 64-byte aligned memory */ |
21 | 121k | static inline void *zng_alloc(size_t size) { |
22 | 121k | #ifdef HAVE_ALIGNED_ALLOC |
23 | | /* Size must be a multiple of alignment */ |
24 | 121k | size = (size + (64 - 1)) & ~(64 - 1); |
25 | 121k | return (void *)aligned_alloc(64, size); /* Defined in C11 */ |
26 | | #elif defined(HAVE_POSIX_MEMALIGN) |
27 | | void *ptr; |
28 | | return posix_memalign(&ptr, 64, size) ? NULL : ptr; |
29 | | #elif defined(HAVE__ALIGNED_MALLOC) |
30 | | /* Fallback: Use MSVC extensions: _aligned_malloc() / _aligned_free() */ |
31 | | return (void *)_aligned_malloc(size, 64); |
32 | | #elif defined(HAVE_MEMALIGN) |
33 | | /* Fallback: Use deprecated GNU extension: memalign() */ |
34 | | return (void *)memalign(64, size); |
35 | | #else |
36 | | /* Fallback: Use a normal allocation (On macOS, alignment is 16 bytes) */ |
37 | | /* zlib-ng adjust allocations for [de]compression to be properly aligned */ |
38 | | return (void *)malloc(size); |
39 | | #endif |
40 | 121k | } Line | Count | Source | 21 | 83.9k | static inline void *zng_alloc(size_t size) { | 22 | 83.9k | #ifdef HAVE_ALIGNED_ALLOC | 23 | | /* Size must be a multiple of alignment */ | 24 | 83.9k | size = (size + (64 - 1)) & ~(64 - 1); | 25 | 83.9k | return (void *)aligned_alloc(64, size); /* Defined in C11 */ | 26 | | #elif defined(HAVE_POSIX_MEMALIGN) | 27 | | void *ptr; | 28 | | return posix_memalign(&ptr, 64, size) ? NULL : ptr; | 29 | | #elif defined(HAVE__ALIGNED_MALLOC) | 30 | | /* Fallback: Use MSVC extensions: _aligned_malloc() / _aligned_free() */ | 31 | | return (void *)_aligned_malloc(size, 64); | 32 | | #elif defined(HAVE_MEMALIGN) | 33 | | /* Fallback: Use deprecated GNU extension: memalign() */ | 34 | | return (void *)memalign(64, size); | 35 | | #else | 36 | | /* Fallback: Use a normal allocation (On macOS, alignment is 16 bytes) */ | 37 | | /* zlib-ng adjust allocations for [de]compression to be properly aligned */ | 38 | | return (void *)malloc(size); | 39 | | #endif | 40 | 83.9k | } |
Line | Count | Source | 21 | 12.5k | static inline void *zng_alloc(size_t size) { | 22 | 12.5k | #ifdef HAVE_ALIGNED_ALLOC | 23 | | /* Size must be a multiple of alignment */ | 24 | 12.5k | size = (size + (64 - 1)) & ~(64 - 1); | 25 | 12.5k | return (void *)aligned_alloc(64, size); /* Defined in C11 */ | 26 | | #elif defined(HAVE_POSIX_MEMALIGN) | 27 | | void *ptr; | 28 | | return posix_memalign(&ptr, 64, size) ? NULL : ptr; | 29 | | #elif defined(HAVE__ALIGNED_MALLOC) | 30 | | /* Fallback: Use MSVC extensions: _aligned_malloc() / _aligned_free() */ | 31 | | return (void *)_aligned_malloc(size, 64); | 32 | | #elif defined(HAVE_MEMALIGN) | 33 | | /* Fallback: Use deprecated GNU extension: memalign() */ | 34 | | return (void *)memalign(64, size); | 35 | | #else | 36 | | /* Fallback: Use a normal allocation (On macOS, alignment is 16 bytes) */ | 37 | | /* zlib-ng adjust allocations for [de]compression to be properly aligned */ | 38 | | return (void *)malloc(size); | 39 | | #endif | 40 | 12.5k | } |
Line | Count | Source | 21 | 12.5k | static inline void *zng_alloc(size_t size) { | 22 | 12.5k | #ifdef HAVE_ALIGNED_ALLOC | 23 | | /* Size must be a multiple of alignment */ | 24 | 12.5k | size = (size + (64 - 1)) & ~(64 - 1); | 25 | 12.5k | return (void *)aligned_alloc(64, size); /* Defined in C11 */ | 26 | | #elif defined(HAVE_POSIX_MEMALIGN) | 27 | | void *ptr; | 28 | | return posix_memalign(&ptr, 64, size) ? NULL : ptr; | 29 | | #elif defined(HAVE__ALIGNED_MALLOC) | 30 | | /* Fallback: Use MSVC extensions: _aligned_malloc() / _aligned_free() */ | 31 | | return (void *)_aligned_malloc(size, 64); | 32 | | #elif defined(HAVE_MEMALIGN) | 33 | | /* Fallback: Use deprecated GNU extension: memalign() */ | 34 | | return (void *)memalign(64, size); | 35 | | #else | 36 | | /* Fallback: Use a normal allocation (On macOS, alignment is 16 bytes) */ | 37 | | /* zlib-ng adjust allocations for [de]compression to be properly aligned */ | 38 | | return (void *)malloc(size); | 39 | | #endif | 40 | 12.5k | } |
Line | Count | Source | 21 | 12.5k | static inline void *zng_alloc(size_t size) { | 22 | 12.5k | #ifdef HAVE_ALIGNED_ALLOC | 23 | | /* Size must be a multiple of alignment */ | 24 | 12.5k | size = (size + (64 - 1)) & ~(64 - 1); | 25 | 12.5k | return (void *)aligned_alloc(64, size); /* Defined in C11 */ | 26 | | #elif defined(HAVE_POSIX_MEMALIGN) | 27 | | void *ptr; | 28 | | return posix_memalign(&ptr, 64, size) ? NULL : ptr; | 29 | | #elif defined(HAVE__ALIGNED_MALLOC) | 30 | | /* Fallback: Use MSVC extensions: _aligned_malloc() / _aligned_free() */ | 31 | | return (void *)_aligned_malloc(size, 64); | 32 | | #elif defined(HAVE_MEMALIGN) | 33 | | /* Fallback: Use deprecated GNU extension: memalign() */ | 34 | | return (void *)memalign(64, size); | 35 | | #else | 36 | | /* Fallback: Use a normal allocation (On macOS, alignment is 16 bytes) */ | 37 | | /* zlib-ng adjust allocations for [de]compression to be properly aligned */ | 38 | | return (void *)malloc(size); | 39 | | #endif | 40 | 12.5k | } |
|
41 | | |
42 | | /* Function that can free aligned memory */ |
43 | 121k | static inline void zng_free(void *ptr) { |
44 | | #if defined(HAVE__ALIGNED_MALLOC) && !defined(HAVE_POSIX_MEMALIGN) && !defined(HAVE_ALIGNED_ALLOC) |
45 | | _aligned_free(ptr); |
46 | | #else |
47 | 121k | free(ptr); |
48 | 121k | #endif |
49 | 121k | } Line | Count | Source | 43 | 83.9k | static inline void zng_free(void *ptr) { | 44 | | #if defined(HAVE__ALIGNED_MALLOC) && !defined(HAVE_POSIX_MEMALIGN) && !defined(HAVE_ALIGNED_ALLOC) | 45 | | _aligned_free(ptr); | 46 | | #else | 47 | 83.9k | free(ptr); | 48 | 83.9k | #endif | 49 | 83.9k | } |
Unexecuted instantiation: gzlib.c:zng_free Line | Count | Source | 43 | 18.7k | static inline void zng_free(void *ptr) { | 44 | | #if defined(HAVE__ALIGNED_MALLOC) && !defined(HAVE_POSIX_MEMALIGN) && !defined(HAVE_ALIGNED_ALLOC) | 45 | | _aligned_free(ptr); | 46 | | #else | 47 | 18.7k | free(ptr); | 48 | 18.7k | #endif | 49 | 18.7k | } |
Line | Count | Source | 43 | 18.8k | static inline void zng_free(void *ptr) { | 44 | | #if defined(HAVE__ALIGNED_MALLOC) && !defined(HAVE_POSIX_MEMALIGN) && !defined(HAVE_ALIGNED_ALLOC) | 45 | | _aligned_free(ptr); | 46 | | #else | 47 | 18.8k | free(ptr); | 48 | 18.8k | #endif | 49 | 18.8k | } |
|
50 | | |
51 | | #endif |