diff options
Diffstat (limited to 'include/linux/log2.h')
-rw-r--r-- | include/linux/log2.h | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/include/linux/log2.h b/include/linux/log2.h index fd7ff3d91e6a..ef3d4f67118c 100644 --- a/include/linux/log2.h +++ b/include/linux/log2.h | |||
@@ -203,6 +203,17 @@ unsigned long __rounddown_pow_of_two(unsigned long n) | |||
203 | * ... and so on. | 203 | * ... and so on. |
204 | */ | 204 | */ |
205 | 205 | ||
206 | #define order_base_2(n) ilog2(roundup_pow_of_two(n)) | 206 | static inline __attribute_const__ |
207 | int __order_base_2(unsigned long n) | ||
208 | { | ||
209 | return n > 1 ? ilog2(n - 1) + 1 : 0; | ||
210 | } | ||
207 | 211 | ||
212 | #define order_base_2(n) \ | ||
213 | ( \ | ||
214 | __builtin_constant_p(n) ? ( \ | ||
215 | ((n) == 0 || (n) == 1) ? 0 : \ | ||
216 | ilog2((n) - 1) + 1) : \ | ||
217 | __order_base_2(n) \ | ||
218 | ) | ||
208 | #endif /* _LINUX_LOG2_H */ | 219 | #endif /* _LINUX_LOG2_H */ |