1 /* SPDX-License-Identifier: GPL-2.0-or-later */
4 * The content of this file is mainly copied/inspired from Linux kernel
5 * code in include/linux/align.h and include/uapi/linux/const.h
7 * Macro name 'ALIGN' conflicts with macOS/BSD file param.h
10 #ifndef OPENOCD_HELPER_ALIGN_H
11 #define OPENOCD_HELPER_ALIGN_H
13 #define ALIGN_MASK(x, mask) \
15 typeof(mask) _mask = (mask); \
16 ((x) + _mask) & ~_mask; \
19 /* @a is a power of 2 value */
20 #define ALIGN_UP(x, a) ALIGN_MASK(x, (typeof(x))(a) - 1)
21 #define ALIGN_DOWN(x, a) ((x) & ~((typeof(x))(a) - 1))
22 #define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0)
24 #define IS_PWR_OF_2(x) \
27 _x == 0 || (_x & (_x - 1)) == 0; \
30 #endif /* OPENOCD_HELPER_ALIGN_H */