68#define ZXC_MALLOC(size) malloc(size)
74#define ZXC_CALLOC(nmemb, size) calloc(nmemb, size)
80#define ZXC_REALLOC(ptr, size) realloc(ptr, size)
86#define ZXC_FREE(ptr) free(ptr)
106#if defined(ZXC_ALIGNED_MALLOC) != defined(ZXC_ALIGNED_FREE)
107#error "ZXC_ALIGNED_MALLOC and ZXC_ALIGNED_FREE are overridden together"
110#ifndef ZXC_ALIGNED_MALLOC
115 return _aligned_malloc(size, alignment);
118 if (posix_memalign(&ptr, alignment, size) != 0)
return NULL;
134#define ZXC_ALIGNED_MALLOC(size, alignment) zxc_aligned_malloc(size, alignment)
137#define ZXC_ALIGNED_FREE(ptr) zxc_aligned_free(ptr)
150#if defined(ZXC_POPCOUNT32) != defined(ZXC_POPCOUNT64)
151#error "ZXC_POPCOUNT32 and ZXC_POPCOUNT64 are overridden together"
154#ifndef ZXC_POPCOUNT32
155#if defined(__GNUC__) || defined(__clang__)
156#define ZXC_POPCOUNT32(v) __builtin_popcount(v)
157#define ZXC_POPCOUNT64(v) __builtin_popcountll(v)
161 uint32_t x = v - ((v >> 1) & 0x55555555U);
162 x = (x & 0x33333333U) + ((x >> 2) & 0x33333333U);
163 x = (x + (x >> 4)) & 0x0F0F0F0FU;
164 return (
int)((x * 0x01010101U) >> 24);
166static inline int zxc_popcount64(
const uint64_t v) {
169#define ZXC_POPCOUNT32(v) zxc_popcount32(v)
170#define ZXC_POPCOUNT64(v) zxc_popcount64(v)
static void * zxc_aligned_malloc(const size_t size, const size_t alignment)
Default cache-line-aligned allocator; release with zxc_aligned_free.
static int zxc_popcount32(const uint32_t v)
Portable SWAR popcount (MSVC).
static void zxc_aligned_free(void *ptr)
Counterpart of zxc_aligned_malloc; NULL is a no-op.