4 #include <ctf/compiler.h>
6 #define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a) - 1)
7 #define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
8 #define PTR_ALIGN(p, a) ((typeof(p)) ALIGN((unsigned long) (p), a))
9 #define ALIGN_FLOOR(x, a) __ALIGN_FLOOR_MASK(x, (typeof(x)) (a) - 1)
10 #define __ALIGN_FLOOR_MASK(x, mask) ((x) & ~(mask))
11 #define PTR_ALIGN_FLOOR(p, a) \
12 ((typeof(p)) ALIGN_FLOOR((unsigned long) (p), a))
13 #define IS_ALIGNED(x, a) (((x) & ((typeof(x)) (a) - 1)) == 0)
16 * Align pointer on natural object alignment.
18 #define object_align(obj) PTR_ALIGN(obj, __alignof__(*(obj)))
19 #define object_align_floor(obj) PTR_ALIGN_FLOOR(obj, __alignof__(*(obj)))
22 * offset_align - Calculate the offset needed to align an object on its natural
23 * alignment towards higher addresses.
24 * @align_drift: object offset from an "alignment"-aligned address.
25 * @alignment: natural object alignment. Must be non-zero, power of 2.
27 * Returns the offset that must be added to align towards higher
30 #define offset_align(align_drift, alignment) \
32 MAYBE_BUILD_BUG_ON((alignment) == 0 \
33 || ((alignment) & ((alignment) - 1))); \
34 (((alignment) - (align_drift)) & ((alignment) - 1)); \
38 * offset_align_floor - Calculate the offset needed to align an object
39 * on its natural alignment towards lower addresses.
40 * @align_drift: object offset from an "alignment"-aligned address.
41 * @alignment: natural object alignment. Must be non-zero, power of 2.
43 * Returns the offset that must be substracted to align towards lower addresses.
45 #define offset_align_floor(align_drift, alignment) \
47 MAYBE_BUILD_BUG_ON((alignment) == 0 \
48 || ((alignment) & ((alignment) - 1))); \
49 (((align_drift) - (alignment)) & ((alignment) - 1); \
52 #endif /* _CTF_ALIGN_H */
This page took 0.031983 seconds and 5 git commands to generate.