Skip to content
Permalink
Browse files

include: misc: macros to perform word/pointer boundary alignment

Many things are currently aligned on 32-bit boundaries. On 64-bit
targets this should be 64-bit boundaries instead. Provide a pair of
macros, namely WB_UP() and WB_DN(),  that do the right thing in both
cases.

The naming is short on purpose as this gets will be used within other
macro definitions, sometimes multiple times per line, and having a
longer name would make for excessively long lines.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
  • Loading branch information...
Nicolas Pitre authored and nashif committed May 22, 2019
1 parent 2c4b2a1 commit d888cb54f90b4aa156ef95aa7e0f6395361faf13
Showing with 4 additions and 0 deletions.
  1. +4 −0 include/misc/util.h
@@ -75,6 +75,10 @@ constexpr size_t ARRAY_SIZE(T(&)[N]) { return N; }
#define ROUND_DOWN(x, align) \
((unsigned long)(x) & ~((unsigned long)(align) - 1))

/* round up/down to the next word boundary */
#define WB_UP(x) ROUND_UP(x, sizeof(void *))
#define WB_DN(x) ROUND_DOWN(x, sizeof(void *))

#define ceiling_fraction(numerator, divider) \
(((numerator) + ((divider) - 1)) / (divider))

0 comments on commit d888cb5

Please sign in to comment.
You can’t perform that action at this time.