43static inline void *
align(
const size_t alignment,
const size_t size,
void **ptr_ptr,
size_t *space_ptr)
49 if (*space_ptr < size) {
70 const uintptr_t intptr = (uintptr_t)*ptr_ptr;
71 const uintptr_t aligned = (intptr - 1u + alignment) & -alignment;
72 const uintptr_t padding = aligned - intptr;
74 if (padding > (*space_ptr - size)) {
78 *space_ptr -= padding;
79 return (*ptr_ptr = (
void *)aligned);
95 const uintptr_t aligned = (ptr - 1u + alignment) & -alignment;
96 const uintptr_t padding = aligned - ptr;
105#define CALC_ALIGNMENT_PADDING(alignment, ptr) ((((ptr) - 1u + (alignment)) & -(alignment)) - (ptr))
static uintptr_t calc_alignment_padding(const size_t alignment, const uintptr_t ptr)
Calculate the alignment padding required to align a pointer.
Definition align.h:91
static void * align(const size_t alignment, const size_t size, void **ptr_ptr, size_t *space_ptr)
Align pointer to the next alignment boundary.
Definition align.h:43
Check if a number is a power of two.
static size_t is_pow2(const size_t x)
Check if a number is a power of two.
Definition is_pow2.h:34