Commit | Line | Data |
---|---|---|
8c4127c5 | 1 | /* |
c0c0989a | 2 | * SPDX-License-Identifier: MIT |
a60d70e6 | 3 | * |
c0c0989a | 4 | * Copyright (C) 2010-2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
8c4127c5 MD |
5 | */ |
6 | ||
3d3a2bb8 MJ |
7 | #ifndef _LTTNG_UST_ALIGN_H |
8 | #define _LTTNG_UST_ALIGN_H | |
c0c0989a | 9 | |
73f94b3c | 10 | #include <lttng/ust-bug.h> |
8c4127c5 MD |
11 | |
12 | /** | |
b72687b8 MJ |
13 | * lttng_ust_offset_align - Calculate the offset needed to align an object on |
14 | * its natural alignment towards higher addresses. | |
8c4127c5 MD |
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 | */ | |
b72687b8 | 21 | #define lttng_ust_offset_align(align_drift, alignment) \ |
8c4127c5 | 22 | ({ \ |
3f12fcef | 23 | LTTNG_BUILD_RUNTIME_BUG_ON((alignment) == 0 \ |
8c4127c5 MD |
24 | || ((alignment) & ((alignment) - 1))); \ |
25 | (((alignment) - (align_drift)) & ((alignment) - 1)); \ | |
26 | }) | |
27 | ||
28 | /** | |
b72687b8 MJ |
29 | * lttng_ust_offset_align_floor - Calculate the offset needed to align an |
30 | * object on its natural alignment towards lower addresses. | |
8c4127c5 MD |
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 | */ | |
b72687b8 | 36 | #define lttng_ust_offset_align_floor(align_drift, alignment) \ |
8c4127c5 | 37 | ({ \ |
3f12fcef | 38 | LTTNG_BUILD_RUNTIME_BUG_ON((alignment) == 0 \ |
8c4127c5 | 39 | || ((alignment) & ((alignment) - 1))); \ |
bf76f1ea | 40 | (((align_drift) - (alignment)) & ((alignment) - 1)); \ |
8c4127c5 MD |
41 | }) |
42 | ||
3d3a2bb8 | 43 | #endif /* _LTTNG_UST_ALIGN_H */ |