/**
+ * ilog2_up - rounded up log of base 2 of 32-bit or a 64-bit unsigned value
+ * @n - parameter
+ *
+ * constant-capable log of base 2 calculation
+ * - this can be used to initialise global variables from constant data, hence
+ * the massive ternary operator construction
+ * - the result is rounded up
+ * - the result is undefined when n < 1
+ *
+ * selects the appropriately-sized optimised version depending on sizeof(n)
+ */
+#define ilog2_up(n) ((n) == 1 ? 0 : ilog2((n) - 1) + 1)
+
+/**
* roundup_pow_of_two - round the given value up to nearest power of two
* @n - parameter
*
@@ -159,8 +175,8 @@ unsigned long __roundup_pow_of_two(unsigned long n)
#define roundup_pow_of_two(n) \
( \
__builtin_constant_p(n) ? ( \
- (n == 1) ? 0 : \
- (1UL << (ilog2((n) - 1) + 1)) \
+ (n == 1) ? 1 : \
+ (1UL << ilog2_up(n)) \
) : \