mirror of
https://github.com/opencv/opencv.git
synced 2024-12-14 00:39:13 +08:00
85923c8f30
Update zlib-ng to 2.2.1 #26113 Release: https://github.com/zlib-ng/zlib-ng/releases/tag/2.2.1 ARM diagnostics patch: https://github.com/zlib-ng/zlib-ng/pull/1774 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake
76 lines
2.1 KiB
C
76 lines
2.1 KiB
C
/* zutil_p.h -- Private inline functions used internally in zlib-ng
|
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
|
*/
|
|
|
|
#ifndef ZUTIL_P_H
|
|
#define ZUTIL_P_H
|
|
|
|
#if defined(__APPLE__) || defined(HAVE_POSIX_MEMALIGN) || defined(HAVE_ALIGNED_ALLOC)
|
|
# include <stdlib.h>
|
|
#elif defined(__FreeBSD__)
|
|
# include <stdlib.h>
|
|
# include <malloc_np.h>
|
|
#else
|
|
# include <malloc.h>
|
|
#endif
|
|
|
|
/* Function to allocate 16 or 64-byte aligned memory */
|
|
static inline void *zng_alloc(size_t size) {
|
|
#ifdef HAVE_ALIGNED_ALLOC
|
|
/* Size must be a multiple of alignment */
|
|
size = (size + (64 - 1)) & ~(64 - 1);
|
|
return (void *)aligned_alloc(64, size); /* Defined in C11 */
|
|
#elif defined(HAVE_POSIX_MEMALIGN)
|
|
void *ptr;
|
|
return posix_memalign(&ptr, 64, size) ? NULL : ptr;
|
|
#elif defined(_WIN32)
|
|
return (void *)_aligned_malloc(size, 64);
|
|
#elif defined(__APPLE__)
|
|
/* Fallback for when posix_memalign and aligned_alloc are not available.
|
|
* On macOS, it always aligns to 16 bytes. */
|
|
return (void *)malloc(size);
|
|
#else
|
|
return (void *)memalign(64, size);
|
|
#endif
|
|
}
|
|
|
|
/* Function that can free aligned memory */
|
|
static inline void zng_free(void *ptr) {
|
|
#if defined(_WIN32)
|
|
_aligned_free(ptr);
|
|
#else
|
|
free(ptr);
|
|
#endif
|
|
}
|
|
|
|
/* Use memcpy instead of memcmp to avoid older compilers not converting memcmp calls to
|
|
unaligned comparisons when unaligned access is supported. */
|
|
static inline int32_t zng_memcmp_2(const void *src0, const void *src1) {
|
|
uint16_t src0_cmp, src1_cmp;
|
|
|
|
memcpy(&src0_cmp, src0, sizeof(src0_cmp));
|
|
memcpy(&src1_cmp, src1, sizeof(src1_cmp));
|
|
|
|
return src0_cmp != src1_cmp;
|
|
}
|
|
|
|
static inline int32_t zng_memcmp_4(const void *src0, const void *src1) {
|
|
uint32_t src0_cmp, src1_cmp;
|
|
|
|
memcpy(&src0_cmp, src0, sizeof(src0_cmp));
|
|
memcpy(&src1_cmp, src1, sizeof(src1_cmp));
|
|
|
|
return src0_cmp != src1_cmp;
|
|
}
|
|
|
|
static inline int32_t zng_memcmp_8(const void *src0, const void *src1) {
|
|
uint64_t src0_cmp, src1_cmp;
|
|
|
|
memcpy(&src0_cmp, src0, sizeof(src0_cmp));
|
|
memcpy(&src1_cmp, src1, sizeof(src1_cmp));
|
|
|
|
return src0_cmp != src1_cmp;
|
|
}
|
|
|
|
#endif
|