| 1 | /* |
| 2 | * SPDX-License-Identifier: MIT |
| 3 | * |
| 4 | * Copyright 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 5 | */ |
| 6 | |
| 7 | #ifndef _BABELTRACE_ALIGN_H |
| 8 | #define _BABELTRACE_ALIGN_H |
| 9 | |
| 10 | #include "compat/compiler.h" |
| 11 | #include "compat/limits.h" |
| 12 | |
| 13 | #define BT_ALIGN(x, a) __BT_ALIGN_MASK(x, (__typeof__(x))(a) - 1) |
| 14 | #define __BT_ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask)) |
| 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) |
| 17 | #define __BT_ALIGN_FLOOR_MASK(x, mask) ((x) & ~(mask)) |
| 18 | #define BT_PTR_ALIGN_FLOOR(p, a) \ |
| 19 | ((__typeof__(p)) BT_ALIGN_FLOOR((unsigned long) (p), a)) |
| 20 | #define BT_IS_ALIGNED(x, a) (((x) & ((__typeof__(x)) (a) - 1)) == 0) |
| 21 | |
| 22 | #endif /* _BABELTRACE_ALIGN_H */ |