16,6 → 16,12 |
#include <linux/bitops.h> |
|
/* |
* deal with unrepresentable constant logarithms |
*/ |
extern __attribute__((const, noreturn)) |
int ____ilog2_NaN(void); |
|
/* |
* non-constant log of base 2 calculators |
* - the arch may override these in asm/bitops.h if they can be implemented |
* more efficiently than using fls() and fls64() |
79,7 → 85,7 |
#define ilog2(n) \ |
( \ |
__builtin_constant_p(n) ? ( \ |
(n) < 2 ? 0 : \ |
(n) < 1 ? ____ilog2_NaN() : \ |
(n) & (1ULL << 63) ? 63 : \ |
(n) & (1ULL << 62) ? 62 : \ |
(n) & (1ULL << 61) ? 61 : \ |
142,7 → 148,10 |
(n) & (1ULL << 4) ? 4 : \ |
(n) & (1ULL << 3) ? 3 : \ |
(n) & (1ULL << 2) ? 2 : \ |
1 ) : \ |
(n) & (1ULL << 1) ? 1 : \ |
(n) & (1ULL << 0) ? 0 : \ |
____ilog2_NaN() \ |
) : \ |
(sizeof(n) <= 4) ? \ |
__ilog2_u32(n) : \ |
__ilog2_u64(n) \ |
194,17 → 203,6 |
* ... 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) ilog2(roundup_pow_of_two(n)) |
|
#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 */ |