Loading include/linux/log2.h +23 −19 Original line number Original line Diff line number Diff line Loading @@ -37,19 +37,23 @@ int __ilog2_u64(u64 n) } } #endif #endif /* /** * is_power_of_2() - check if a value is a power of two * @n: the value to check * * Determine whether some value is a power of two, where zero is * Determine whether some value is a power of two, where zero is * *not* considered a power of two. * *not* considered a power of two. * Return: true if @n is a power of 2, otherwise false. */ */ static inline __attribute__((const)) static inline __attribute__((const)) bool is_power_of_2(unsigned long n) bool is_power_of_2(unsigned long n) { { return (n != 0 && ((n & (n - 1)) == 0)); return (n != 0 && ((n & (n - 1)) == 0)); } } /* /** * round up to nearest power of two * __roundup_pow_of_two() - round up to nearest power of two * @n: value to round up */ */ static inline __attribute__((const)) static inline __attribute__((const)) unsigned long __roundup_pow_of_two(unsigned long n) unsigned long __roundup_pow_of_two(unsigned long n) Loading @@ -57,8 +61,9 @@ unsigned long __roundup_pow_of_two(unsigned long n) return 1UL << fls_long(n - 1); return 1UL << fls_long(n - 1); } } /* /** * round down to nearest power of two * __rounddown_pow_of_two() - round down to nearest power of two * @n: value to round down */ */ static inline __attribute__((const)) static inline __attribute__((const)) unsigned long __rounddown_pow_of_two(unsigned long n) unsigned long __rounddown_pow_of_two(unsigned long n) Loading @@ -67,8 +72,8 @@ unsigned long __rounddown_pow_of_two(unsigned long n) } } /** /** * ilog2 - log of base 2 of 32-bit or a 64-bit unsigned value * ilog2 - log base 2 of 32-bit or a 64-bit unsigned value * @n - parameter * @n: parameter * * * constant-capable log of base 2 calculation * constant-capable log of base 2 calculation * - this can be used to initialise global variables from constant data, hence * - this can be used to initialise global variables from constant data, hence Loading Loading @@ -150,7 +155,7 @@ unsigned long __rounddown_pow_of_two(unsigned long n) /** /** * roundup_pow_of_two - round the given value up to nearest power of two * roundup_pow_of_two - round the given value up to nearest power of two * @n - parameter * @n: parameter * * * round the given value up to the nearest power of two * round the given value up to the nearest power of two * - the result is undefined when n == 0 * - the result is undefined when n == 0 Loading @@ -167,7 +172,7 @@ unsigned long __rounddown_pow_of_two(unsigned long n) /** /** * rounddown_pow_of_two - round the given value down to nearest power of two * rounddown_pow_of_two - round the given value down to nearest power of two * @n - parameter * @n: parameter * * * round the given value down to the nearest power of two * round the given value down to the nearest power of two * - the result is undefined when n == 0 * - the result is undefined when n == 0 Loading @@ -180,6 +185,12 @@ unsigned long __rounddown_pow_of_two(unsigned long n) __rounddown_pow_of_two(n) \ __rounddown_pow_of_two(n) \ ) ) static inline __attribute_const__ int __order_base_2(unsigned long n) { return n > 1 ? ilog2(n - 1) + 1 : 0; } /** /** * order_base_2 - calculate the (rounded up) base 2 order of the argument * order_base_2 - calculate the (rounded up) base 2 order of the argument * @n: parameter * @n: parameter Loading @@ -193,13 +204,6 @@ unsigned long __rounddown_pow_of_two(unsigned long n) * ob2(5) = 3 * ob2(5) = 3 * ... and so on. * ... and so on. */ */ static inline __attribute_const__ int __order_base_2(unsigned long n) { return n > 1 ? ilog2(n - 1) + 1 : 0; } #define order_base_2(n) \ #define order_base_2(n) \ ( \ ( \ __builtin_constant_p(n) ? ( \ __builtin_constant_p(n) ? ( \ Loading Loading
include/linux/log2.h +23 −19 Original line number Original line Diff line number Diff line Loading @@ -37,19 +37,23 @@ int __ilog2_u64(u64 n) } } #endif #endif /* /** * is_power_of_2() - check if a value is a power of two * @n: the value to check * * Determine whether some value is a power of two, where zero is * Determine whether some value is a power of two, where zero is * *not* considered a power of two. * *not* considered a power of two. * Return: true if @n is a power of 2, otherwise false. */ */ static inline __attribute__((const)) static inline __attribute__((const)) bool is_power_of_2(unsigned long n) bool is_power_of_2(unsigned long n) { { return (n != 0 && ((n & (n - 1)) == 0)); return (n != 0 && ((n & (n - 1)) == 0)); } } /* /** * round up to nearest power of two * __roundup_pow_of_two() - round up to nearest power of two * @n: value to round up */ */ static inline __attribute__((const)) static inline __attribute__((const)) unsigned long __roundup_pow_of_two(unsigned long n) unsigned long __roundup_pow_of_two(unsigned long n) Loading @@ -57,8 +61,9 @@ unsigned long __roundup_pow_of_two(unsigned long n) return 1UL << fls_long(n - 1); return 1UL << fls_long(n - 1); } } /* /** * round down to nearest power of two * __rounddown_pow_of_two() - round down to nearest power of two * @n: value to round down */ */ static inline __attribute__((const)) static inline __attribute__((const)) unsigned long __rounddown_pow_of_two(unsigned long n) unsigned long __rounddown_pow_of_two(unsigned long n) Loading @@ -67,8 +72,8 @@ unsigned long __rounddown_pow_of_two(unsigned long n) } } /** /** * ilog2 - log of base 2 of 32-bit or a 64-bit unsigned value * ilog2 - log base 2 of 32-bit or a 64-bit unsigned value * @n - parameter * @n: parameter * * * constant-capable log of base 2 calculation * constant-capable log of base 2 calculation * - this can be used to initialise global variables from constant data, hence * - this can be used to initialise global variables from constant data, hence Loading Loading @@ -150,7 +155,7 @@ unsigned long __rounddown_pow_of_two(unsigned long n) /** /** * roundup_pow_of_two - round the given value up to nearest power of two * roundup_pow_of_two - round the given value up to nearest power of two * @n - parameter * @n: parameter * * * round the given value up to the nearest power of two * round the given value up to the nearest power of two * - the result is undefined when n == 0 * - the result is undefined when n == 0 Loading @@ -167,7 +172,7 @@ unsigned long __rounddown_pow_of_two(unsigned long n) /** /** * rounddown_pow_of_two - round the given value down to nearest power of two * rounddown_pow_of_two - round the given value down to nearest power of two * @n - parameter * @n: parameter * * * round the given value down to the nearest power of two * round the given value down to the nearest power of two * - the result is undefined when n == 0 * - the result is undefined when n == 0 Loading @@ -180,6 +185,12 @@ unsigned long __rounddown_pow_of_two(unsigned long n) __rounddown_pow_of_two(n) \ __rounddown_pow_of_two(n) \ ) ) static inline __attribute_const__ int __order_base_2(unsigned long n) { return n > 1 ? ilog2(n - 1) + 1 : 0; } /** /** * order_base_2 - calculate the (rounded up) base 2 order of the argument * order_base_2 - calculate the (rounded up) base 2 order of the argument * @n: parameter * @n: parameter Loading @@ -193,13 +204,6 @@ unsigned long __rounddown_pow_of_two(unsigned long n) * ob2(5) = 3 * ob2(5) = 3 * ... and so on. * ... and so on. */ */ static inline __attribute_const__ int __order_base_2(unsigned long n) { return n > 1 ? ilog2(n - 1) + 1 : 0; } #define order_base_2(n) \ #define order_base_2(n) \ ( \ ( \ __builtin_constant_p(n) ? ( \ __builtin_constant_p(n) ? ( \ Loading