diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-04-11 02:07:14 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-04-11 23:10:40 +0200 |
commit | 9be9c7cff600018279a0c3fa5fbe719bd1c0b8ad (patch) | |
tree | 7c1e61f36680f92143e0df19a55de2f0f9a0edc3 /src/shared/macro.h | |
parent | 3fd0bd432d4875c15b9e8d586770f60f03278fe7 (diff) |
macro: make sure ALIGN() can be calculated constant by the compiler
If we pass a constant value to ALIGN() gcc should have the chance to
calculate the value during compilation rather than runtime, so let's
avoid a static inline call if we can.
Diffstat (limited to 'src/shared/macro.h')
-rw-r--r-- | src/shared/macro.h | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/shared/macro.h b/src/shared/macro.h index f884bf653f..84a453a8f2 100644 --- a/src/shared/macro.h +++ b/src/shared/macro.h @@ -53,7 +53,18 @@ #define STRINGIFY(x) XSTRINGIFY(x) /* Rounds up */ -#define ALIGN(l) ALIGN_TO((l), sizeof(void*)) + +#define ALIGN4(l) (((l) + 3) & ~3) +#define ALIGN8(l) (((l) + 7) & ~7) + +#if __SIZEOF_POINTER__ == 8 +#define ALIGN(l) ALIGN8(l) +#elif __SIZEOF_POINTER__ == 4 +#define ALIGN(l) ALIGN4(l) +#else +#error "Wut? Pointers are neither 4 nor 8 bytes long?" +#endif + static inline size_t ALIGN_TO(size_t l, size_t ali) { return ((l + ali - 1) & ~(ali - 1)); } |