Commit | Line | Data |
---|---|---|
de0ba614 | 1 | /* |
0235b0db | 2 | * SPDX-License-Identifier: MIT |
de0ba614 | 3 | * |
0235b0db | 4 | * Copyright 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
de0ba614 MD |
5 | */ |
6 | ||
0235b0db MJ |
7 | #ifndef _BABELTRACE_ALIGN_H |
8 | #define _BABELTRACE_ALIGN_H | |
9 | ||
578e048b MJ |
10 | #include "compat/compiler.h" |
11 | #include "compat/limits.h" | |
c4f467da | 12 | |
0ec1ae8b | 13 | #define BT_ALIGN(x, a) __BT_ALIGN_MASK(x, (__typeof__(x))(a) - 1) |
328342cd | 14 | #define __BT_ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask)) |
0ec1ae8b SM |
15 | #define BT_PTR_ALIGN(p, a) ((__typeof__(p)) BT_ALIGN((unsigned long) (p), a)) |
16 | #define BT_ALIGN_FLOOR(x, a) __BT_ALIGN_FLOOR_MASK(x, (__typeof__(x)) (a) - 1) | |
328342cd MJ |
17 | #define __BT_ALIGN_FLOOR_MASK(x, mask) ((x) & ~(mask)) |
18 | #define BT_PTR_ALIGN_FLOOR(p, a) \ | |
0ec1ae8b SM |
19 | ((__typeof__(p)) BT_ALIGN_FLOOR((unsigned long) (p), a)) |
20 | #define BT_IS_ALIGNED(x, a) (((x) & ((__typeof__(x)) (a) - 1)) == 0) | |
6dc2ca62 | 21 | |
d79865b9 | 22 | #endif /* _BABELTRACE_ALIGN_H */ |