aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/log2.h')
-rw-r--r--include/linux/log2.h26
1 files changed, 14 insertions, 12 deletions
diff --git a/include/linux/log2.h b/include/linux/log2.h
index fd7ff3d91e6a..c373295f359f 100644
--- a/include/linux/log2.h
+++ b/include/linux/log2.h
@@ -16,12 +16,6 @@
16#include <linux/bitops.h> 16#include <linux/bitops.h>
17 17
18/* 18/*
19 * deal with unrepresentable constant logarithms
20 */
21extern __attribute__((const, noreturn))
22int ____ilog2_NaN(void);
23
24/*
25 * non-constant log of base 2 calculators 19 * non-constant log of base 2 calculators
26 * - the arch may override these in asm/bitops.h if they can be implemented 20 * - the arch may override these in asm/bitops.h if they can be implemented
27 * more efficiently than using fls() and fls64() 21 * more efficiently than using fls() and fls64()
@@ -85,7 +79,7 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
85#define ilog2(n) \ 79#define ilog2(n) \
86( \ 80( \
87 __builtin_constant_p(n) ? ( \ 81 __builtin_constant_p(n) ? ( \
88 (n) < 1 ? ____ilog2_NaN() : \ 82 (n) < 2 ? 0 : \
89 (n) & (1ULL << 63) ? 63 : \ 83 (n) & (1ULL << 63) ? 63 : \
90 (n) & (1ULL << 62) ? 62 : \ 84 (n) & (1ULL << 62) ? 62 : \
91 (n) & (1ULL << 61) ? 61 : \ 85 (n) & (1ULL << 61) ? 61 : \
@@ -148,10 +142,7 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
148 (n) & (1ULL << 4) ? 4 : \ 142 (n) & (1ULL << 4) ? 4 : \
149 (n) & (1ULL << 3) ? 3 : \ 143 (n) & (1ULL << 3) ? 3 : \
150 (n) & (1ULL << 2) ? 2 : \ 144 (n) & (1ULL << 2) ? 2 : \
151 (n) & (1ULL << 1) ? 1 : \ 145 1 ) : \
152 (n) & (1ULL << 0) ? 0 : \
153 ____ilog2_NaN() \
154 ) : \
155 (sizeof(n) <= 4) ? \ 146 (sizeof(n) <= 4) ? \
156 __ilog2_u32(n) : \ 147 __ilog2_u32(n) : \
157 __ilog2_u64(n) \ 148 __ilog2_u64(n) \
@@ -203,6 +194,17 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
203 * ... and so on. 194 * ... and so on.
204 */ 195 */
205 196
206#define order_base_2(n) ilog2(roundup_pow_of_two(n)) 197static inline __attribute_const__
198int __order_base_2(unsigned long n)
199{
200 return n > 1 ? ilog2(n - 1) + 1 : 0;
201}
207 202
203#define order_base_2(n) \
204( \
205 __builtin_constant_p(n) ? ( \
206 ((n) == 0 || (n) == 1) ? 0 : \
207 ilog2((n) - 1) + 1) : \
208 __order_base_2(n) \
209)
208#endif /* _LINUX_LOG2_H */ 210#endif /* _LINUX_LOG2_H */