7 * (C) Copyright 2010-2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * Dual LGPL v2.1/GPL v2 license.
14 #include <linux/types.h>
17 #define ALIGN_FLOOR(x, a) __ALIGN_FLOOR_MASK(x, (typeof(x)) (a) - 1)
18 #define __ALIGN_FLOOR_MASK(x, mask) ((x) & ~(mask))
19 #define PTR_ALIGN_FLOOR(p, a) \
20 ((typeof(p)) ALIGN_FLOOR((unsigned long) (p), a))
23 * Align pointer on natural object alignment.
25 #define object_align(obj) PTR_ALIGN(obj, __alignof__(*(obj)))
26 #define object_align_floor(obj) PTR_ALIGN_FLOOR(obj, __alignof__(*(obj)))
29 * offset_align - Calculate the offset needed to align an object on its natural
30 * alignment towards higher addresses.
31 * @align_drift: object offset from an "alignment"-aligned address.
32 * @alignment: natural object alignment. Must be non-zero, power of 2.
34 * Returns the offset that must be added to align towards higher
37 #define offset_align(align_drift, alignment) \
39 BUILD_RUNTIME_BUG_ON((alignment) == 0 \
40 || ((alignment) & ((alignment) - 1))); \
41 (((alignment) - (align_drift)) & ((alignment) - 1)); \
45 * offset_align_floor - Calculate the offset needed to align an object
46 * on its natural alignment towards lower addresses.
47 * @align_drift: object offset from an "alignment"-aligned address.
48 * @alignment: natural object alignment. Must be non-zero, power of 2.
50 * Returns the offset that must be substracted to align towards lower addresses.
52 #define offset_align_floor(align_drift, alignment) \
54 BUILD_RUNTIME_BUG_ON((alignment) == 0 \
55 || ((alignment) & ((alignment) - 1))); \
56 (((align_drift) - (alignment)) & ((alignment) - 1); \
59 #endif /* __KERNEL__ */
This page took 0.029965 seconds and 4 git commands to generate.