Move compat macros in 'lttng/align.h' to a private header
[lttng-ust.git] / include / lttng / align.h
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright (C) 2010-2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 */
6
7 #ifndef _LTTNG_ALIGN_H
8 #define _LTTNG_ALIGN_H
9
10 #include <lttng/bug.h>
11
12 /**
13 * lttng_ust_offset_align - Calculate the offset needed to align an object on
14 * its natural alignment towards higher addresses.
15 * @align_drift: object offset from an "alignment"-aligned address.
16 * @alignment: natural object alignment. Must be non-zero, power of 2.
17 *
18 * Returns the offset that must be added to align towards higher
19 * addresses.
20 */
21 #define lttng_ust_offset_align(align_drift, alignment) \
22 ({ \
23 LTTNG_BUILD_RUNTIME_BUG_ON((alignment) == 0 \
24 || ((alignment) & ((alignment) - 1))); \
25 (((alignment) - (align_drift)) & ((alignment) - 1)); \
26 })
27
28 /**
29 * lttng_ust_offset_align_floor - Calculate the offset needed to align an
30 * object on its natural alignment towards lower addresses.
31 * @align_drift: object offset from an "alignment"-aligned address.
32 * @alignment: natural object alignment. Must be non-zero, power of 2.
33 *
34 * Returns the offset that must be substracted to align towards lower addresses.
35 */
36 #define lttng_ust_offset_align_floor(align_drift, alignment) \
37 ({ \
38 LTTNG_BUILD_RUNTIME_BUG_ON((alignment) == 0 \
39 || ((alignment) & ((alignment) - 1))); \
40 (((align_drift) - (alignment)) & ((alignment) - 1)); \
41 })
42
43 #endif /* _LTTNG_ALIGN_H */
This page took 0.029227 seconds and 4 git commands to generate.