From adaead47de2dd98ee556de911fd798371ba4c378 Mon Sep 17 00:00:00 2001 From: Lv Zheng Date: Thu, 31 Dec 2015 11:29:38 +0800 Subject: Utilities: Add ACPI_IS_POWER_OF_TWO() This patch adds a macro ACPI_IS_POWER_OF_TWO, which can be used to detect if a number is a power of two. Lv Zheng. Signed-off-by: Lv Zheng --- source/include/acmacros.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/include/acmacros.h b/source/include/acmacros.h index a805a32ce..b451cbbbd 100644 --- a/source/include/acmacros.h +++ b/source/include/acmacros.h @@ -336,6 +336,11 @@ #define ACPI_IS_MISALIGNED(value) (((ACPI_SIZE) value) & (sizeof(ACPI_SIZE)-1)) +/* Generic (power-of-two) rounding */ + +#define ACPI_IS_ALIGNED(a, s) (((a) & ((s) - 1)) == 0) +#define ACPI_IS_POWER_OF_TWO(a) ACPI_IS_ALIGNED(a, a) + /* * Bitmask creation * Bit positions start at zero. -- cgit v1.2.1