1 /* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1)
5 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
13 #include <linux/types.h>
16 #define ALIGN_FLOOR(x, a) __ALIGN_FLOOR_MASK(x, (typeof(x)) (a) - 1)
17 #define __ALIGN_FLOOR_MASK(x, mask) ((x) & ~(mask))
18 #define PTR_ALIGN_FLOOR(p, a) \
19 ((typeof(p)) ALIGN_FLOOR((unsigned long) (p), a))
22 * Align pointer on natural object alignment.
24 #define object_align(obj) PTR_ALIGN(obj, __alignof__(*(obj)))
25 #define object_align_floor(obj) PTR_ALIGN_FLOOR(obj, __alignof__(*(obj)))
28 * offset_align - Calculate the offset needed to align an object on its natural
29 * alignment towards higher addresses.
30 * @align_drift: object offset from an "alignment"-aligned address.
31 * @alignment: natural object alignment. Must be non-zero, power of 2.
33 * Returns the offset that must be added to align towards higher
36 #define offset_align(align_drift, alignment) \
38 BUILD_RUNTIME_BUG_ON((alignment) == 0 \
39 || ((alignment) & ((alignment) - 1))); \
40 (((alignment) - (align_drift)) & ((alignment) - 1)); \
44 * offset_align_floor - Calculate the offset needed to align an object
45 * on its natural alignment towards lower addresses.
46 * @align_drift: object offset from an "alignment"-aligned address.
47 * @alignment: natural object alignment. Must be non-zero, power of 2.
49 * Returns the offset that must be substracted to align towards lower addresses.
51 #define offset_align_floor(align_drift, alignment) \
53 BUILD_RUNTIME_BUG_ON((alignment) == 0 \
54 || ((alignment) & ((alignment) - 1))); \
55 (((align_drift) - (alignment)) & ((alignment) - 1)); \
58 #endif /* __KERNEL__ */
This page took 0.030853 seconds and 4 git commands to generate.