Review of the new alignment method

This commit is contained in:
Andrea Mazzoleni 2015-03-18 08:21:28 +01:00
parent f197cfbe45
commit 7fd0beb36a
4 changed files with 31 additions and 25 deletions

View file

@ -95,8 +95,14 @@
/*
* Align a pointer at the specified size.
*/
#define __align_ptr(ptr, size) \
(void*)((uintptr_t)(((uint8_t*)ptr) + size - 1) & ~(uintptr_t)(size - 1))
static __always_inline void *__align_ptr(void *ptr, uintptr_t size)
{
uintptr_t offset = (uintptr_t)ptr;
offset = (offset + size - 1U) & ~(size - 1U);
return (void *)offset;
}
/*
* Includes the main interface header.