7 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; only
12 * version 2.1 of the License.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #include <linux/types.h>
29 #define ALIGN_FLOOR(x, a) __ALIGN_FLOOR_MASK(x, (typeof(x)) (a) - 1)
30 #define __ALIGN_FLOOR_MASK(x, mask) ((x) & ~(mask))
31 #define PTR_ALIGN_FLOOR(p, a) \
32 ((typeof(p)) ALIGN_FLOOR((unsigned long) (p), a))
35 * Align pointer on natural object alignment.
37 #define object_align(obj) PTR_ALIGN(obj, __alignof__(*(obj)))
38 #define object_align_floor(obj) PTR_ALIGN_FLOOR(obj, __alignof__(*(obj)))
41 * offset_align - Calculate the offset needed to align an object on its natural
42 * alignment towards higher addresses.
43 * @align_drift: object offset from an "alignment"-aligned address.
44 * @alignment: natural object alignment. Must be non-zero, power of 2.
46 * Returns the offset that must be added to align towards higher
49 #define offset_align(align_drift, alignment) \
51 BUILD_RUNTIME_BUG_ON((alignment) == 0 \
52 || ((alignment) & ((alignment) - 1))); \
53 (((alignment) - (align_drift)) & ((alignment) - 1)); \
57 * offset_align_floor - Calculate the offset needed to align an object
58 * on its natural alignment towards lower addresses.
59 * @align_drift: object offset from an "alignment"-aligned address.
60 * @alignment: natural object alignment. Must be non-zero, power of 2.
62 * Returns the offset that must be substracted to align towards lower addresses.
64 #define offset_align_floor(align_drift, alignment) \
66 BUILD_RUNTIME_BUG_ON((alignment) == 0 \
67 || ((alignment) & ((alignment) - 1))); \
68 (((align_drift) - (alignment)) & ((alignment) - 1)); \
71 #endif /* __KERNEL__ */
This page took 0.029874 seconds and 4 git commands to generate.