diff options
| author | Ingo Molnar <mingo@kernel.org> | 2017-02-14 07:29:14 +0100 |
|---|---|---|
| committer | Ingo Molnar <mingo@kernel.org> | 2017-02-14 07:29:14 +0100 |
| commit | 210f400d68a14bc89e2e61dc2e06cdd67cfeb5f6 (patch) | |
| tree | 2098a7db539f0e92676d8d953002db3cc8eb03b8 /include/linux/log2.h | |
| parent | f2029b1e47b607619d1dd2cb0bbb77f64ec6b7c2 (diff) | |
| parent | 7089db84e356562f8ba737c29e472cc42d530dbc (diff) | |
Merge tag 'v4.10-rc8' into perf/core, to pick up fixes
Signed-off-by: Ingo Molnar <mingo@kernel.org>
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) * ... and so on. */ -#define order_base_2(n) ilog2(roundup_pow_of_two(n)) +static inline __attribute_const__ +int __order_base_2(unsigned long n) +{ + return n > 1 ? ilog2(n - 1) + 1 : 0; +} +#define order_base_2(n) \ +( \ + __builtin_constant_p(n) ? ( \ + ((n) == 0 || (n) == 1) ? 0 : \ + ilog2((n) - 1) + 1) : \ + __order_base_2(n) \ +) #endif /* _LINUX_LOG2_H */ |
