16#include <kernel/types.h>
21 __typeof__(_x) _max1 = (_x); \
22 __typeof__(_y) _max2 = (_y); \
23 _max1 > _max2 ? _max1 : _max2; \
29 __typeof__(_x) _max1 = (_x); \
30 __typeof__(_y) _max2 = (_y); \
31 _max1 < _max2 ? _max1 : _max2; \
37 __typeof__(_x) _tmp = (_x); \
38 _tmp < 0 ? -_tmp : _tmp; \
42#define is_power_of_2(_x) (_x != 0 && ((_x & (_x - 1)) == 0))
44#define __align_mask(_value, _power) ((__typeof__(_value))((_power)-1))
50#define align_up(_value, _power) \
51 ((((_value)-1) | __align_mask(_value, _power)) + 1)
57#define align_down(_value, _power) ((_value) & ~__align_mask(_value, _power))
60#define is_aligned(_value, _alignment) (!((_value) % (_alignment)))
62#define align_down_ptr(_ptr, _power) ((void *)align_down((vaddr_t)_ptr, _power))
63#define align_up_ptr(_ptr, _power) ((void *)align_up((vaddr_t)_ptr, _power))
64#define is_aligned_ptr(_ptr, _alignment) is_aligned((vaddr_t)_ptr, _alignment)
72static inline u32
round_up(u32 value, u32 alignment)
77 u32 offset = value % alignment;
79 value += alignment - offset;
93 return value - (value % alignment);
static u32 round_down(u32 value, u32 alignment)
Round value to the previous multiple of alignment.
Definition: math.h:88
static u32 round_up(u32 value, u32 alignment)
Round value to the next multiple of alignment.
Definition: math.h:72