diff options
author | Samuel Pitoiset <samuel.pitoiset@gmail.com> | 2024-04-04 13:19:37 +0200 |
---|---|---|
committer | Marge Bot <emma+marge@anholt.net> | 2024-04-04 21:57:46 +0000 |
commit | 81e3c46d065c1f2a8df20159f5c70f2b883926ea (patch) | |
tree | 18ec8d4813d85d8e0b03de53760c48b00f8e8a84 | |
parent | 5cc3258533140997a61d7ddc65e50fe5b50e8acf (diff) |
util: add util_is_aligned()
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28568>
-rw-r--r-- | src/util/u_math.h | 11 |
1 files changed, 11 insertions, 0 deletions
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 |