diff --git a/src/util/u_math.h b/src/util/u_math.h index c51352fcdc4..7afe136278f 100644 --- a/src/util/u_math.h +++ b/src/util/u_math.h @@ -808,6 +808,17 @@ util_clamped_uadd(unsigned a, unsigned b) return res; } +/** + * Checks the value 'n' is aligned to 'a'. + * The alignment must be a power of two. + */ +static inline bool +util_is_aligned(uintmax_t n, uintmax_t a) +{ + assert(a == (a & -a)); + return (n & (a - 1)) == 0; +} + #ifdef __cplusplus } #endif