Last active
August 29, 2015 14:05
-
-
Save awreece/c9dc6b3036deb71e4b48 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Align p to a multiple of w bytes | |
static inline void* align(const void const* p, unsigned char w) { | |
return (void*)(((uintptr_t)(p) + (w-1)) & ~(w-1)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static inline uintptr_t | |
round_up(uintptr_t val, uintptr_t alignment) { | |
// Alignment must be a power of two. | |
ASSERT3(__builtin_popcount(alignment), ==, 1); | |
return ((val + (alignment-1)) & ~(alignment-1)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment