ZXC 0.15.0
High-performance asymmetric lossless compression library
Loading...
Searching...
No Matches
zxc_deps.h File Reference

Single point of override for the C-library dependencies of libzxc. More...

#include <assert.h>
#include <limits.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Macros

Heap Allocator Abstraction

Macros around the libc allocators so non-libc targets (Linux kernel, embedded freestanding builds, custom arenas) can override them via -D flags before including any zxc header, or by vendoring this file.

Note
Aligned allocations go through ZXC_ALIGNED_MALLOC / ZXC_ALIGNED_FREE (see below), not these.
#define ZXC_MALLOC(size)   malloc(size)
 Heap allocator.
 
#define ZXC_CALLOC(nmemb, size)   calloc(nmemb, size)
 Zero-initialised heap allocator.
 
#define ZXC_REALLOC(ptr, size)   realloc(ptr, size)
 In-place / move heap reallocator.
 
#define ZXC_FREE(ptr)   free(ptr)
 Heap deallocator.
 

Aligned Allocator Abstraction

Macros around the cache-line-aligned allocator used for compression workspace and per-context scratch buffers.

The default is the pair defined below, wrapping _aligned_malloc on Windows and posix_memalign elsewhere - the core's only use of either. A host overrides both macros or neither; a vendored copy of this file defines both.

Kernel builds align by hand over the slab allocator (see contrib/linux-kernel): kmalloc guarantees only ARCH_KMALLOC_MINALIGN, 8 bytes on x86 and on arm64 since 6.5, short of the cache line the workspace layout assumes.

#define ZXC_ALIGNED_MALLOC(size, alignment)   zxc_aligned_malloc(size, alignment)
 Cache-line-aligned allocator.
 
#define ZXC_ALIGNED_FREE(ptr)   zxc_aligned_free(ptr)
 Counterpart deallocator for ZXC_ALIGNED_MALLOC.
 
static void * zxc_aligned_malloc (const size_t size, const size_t alignment)
 Default cache-line-aligned allocator; release with zxc_aligned_free.
 
static void zxc_aligned_free (void *ptr)
 Counterpart of zxc_aligned_malloc; NULL is a no-op.
 

Population Count

ZXC_POPCOUNT32 / ZXC_POPCOUNT64.

Default: the builtins, libgcc calls without a hardware count; a kernel maps them onto hweight32/64.

#define ZXC_POPCOUNT32(v)   zxc_popcount32(v)
 
#define ZXC_POPCOUNT64(v)   zxc_popcount64(v)
 
static int zxc_popcount32 (const uint32_t v)
 Portable SWAR popcount (MSVC).
 
static int zxc_popcount64 (const uint64_t v)
 

Detailed Description

Single point of override for the C-library dependencies of libzxc.

The core compression/decompression code only ever reaches the standard library through the macros and headers declared here. Freestanding consumers vendor the source tree and replace this file with an environment-specific version that maps the same macros onto their own allocator, sort, and basic header set.

Stock (hosted) build
Pulls in <assert.h>, <limits.h>, <stdint.h>, <stdlib.h>, <string.h> and expands the macros to their libc equivalents.

Per-symbol -D overrides are also accepted (each macro is guarded by an ifndef, the aligned pair as one), so vendoring is optional for ad-hoc consumers.

Definition in file zxc_deps.h.