]>
Commit | Line | Data |
---|---|---|
18c8241a MM |
1 | /* |
2 | * BIRD Library -- Generic Bit Operations | |
3 | * | |
4 | * (c) 1998 Martin Mares <mj@ucw.cz> | |
5 | * | |
6 | * Can be freely distributed and used under the terms of the GNU GPL. | |
7 | */ | |
8 | ||
e7d2ac44 OZ |
9 | #ifndef _BIRD_BITOPTS_H_ |
10 | #define _BIRD_BITOPTS_H_ | |
11 | ||
9b0a0ba9 OZ |
12 | #include "sysdep/config.h" |
13 | ||
18c8241a MM |
14 | /* |
15 | * Bit mask operations: | |
16 | * | |
17 | * u32_mkmask Make bit mask consisting of <n> consecutive ones | |
18 | * from the left and the rest filled with zeroes. | |
19 | * E.g., u32_mkmask(5) = 0xf8000000. | |
20 | * u32_masklen Inverse operation to u32_mkmask, -1 if not a bitmask. | |
21 | */ | |
22 | ||
ae80a2de | 23 | u32 u32_mkmask(uint n); |
fe9f1a6d | 24 | uint u32_masklen(u32 x); |
b1a597e0 OZ |
25 | |
26 | u32 u32_log2(u32 v); | |
e7d2ac44 OZ |
27 | |
28 | static inline u32 u32_hash(u32 v) { return v * 2902958171u; } | |
29 | ||
937e75d8 | 30 | static inline u8 u32_popcount(u32 v) { return __builtin_popcount(v); } |
886dd92e | 31 | static inline u8 u64_popcount(u64 v) { return __builtin_popcountll(v); } |
e7d2ac44 | 32 | |
af02b83b OZ |
33 | static inline int u32_clz(u32 v) { return __builtin_clz(v); } |
34 | static inline int u32_ctz(u32 v) { return __builtin_ctz(v); } | |
35 | ||
4fa0e472 OZ |
36 | static inline int uint_is_pow2(uint n) { return n && !(n & (n-1)); } |
37 | ||
937e75d8 | 38 | #endif |