util: add IS_POT macro
This macro kinda complements util_is_power_of_two_*, but is implemented as a macro. This means that it can expand to a constant integral expression, and thus be used in static_assert. Because we don't really need the added complexity, this doesn't handle zero correctly. But that's OK, because the call-sites will. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Jesse Natalie <jenatali@microsoft.com> Reviewed-by: Yonggang Luo <luoyonggang@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16670>
This commit is contained in:

committed by
Marge Bot

parent
cf52d79d24
commit
9ecb6f8820
@@ -371,6 +371,9 @@ do { \
|
||||
/** Align a value to a power of two */
|
||||
#define ALIGN_POT(x, pot_align) (((x) + (pot_align) - 1) & ~((pot_align) - 1))
|
||||
|
||||
/** Checks is a value is a power of two. Does not handle zero. */
|
||||
#define IS_POT(v) (((v) & ((v) - 1)) == 0)
|
||||
|
||||
/**
|
||||
* Macro for declaring an explicit conversion operator. Defaults to an
|
||||
* implicit conversion if C++11 is not supported.
|
||||
|
Reference in New Issue
Block a user