2
2
Some useful bit functions
9
7
extern const char _my_bits_nbits[256];
10
extern const unsigned char _my_bits_reverse_table[256];
8
extern const uchar _my_bits_reverse_table[256];
13
11
Find smallest X in 2^X >= value
14
12
This can be used to divide a number with value by doing a shift instead
17
static inline uint32_t my_bit_log2(uint32_t value)
15
static inline uint my_bit_log2(ulong value)
20
18
for (bit=0 ; value > 1 ; value>>=1, bit++) ;
24
static inline uint32_t my_count_bits(uint64_t v)
22
static inline uint my_count_bits(uint64_t v)
24
#if SIZEOF_LONG_LONG > 4
26
25
/* The following code is a bit faster on 16 bit machines than if we would
28
uint32_t v2=(uint32_t) (v >> 32);
29
return (uint) (unsigned char) (_my_bits_nbits[(unsigned char) v] +
30
_my_bits_nbits[(unsigned char) (v >> 8)] +
31
_my_bits_nbits[(unsigned char) (v >> 16)] +
32
_my_bits_nbits[(unsigned char) (v >> 24)] +
33
_my_bits_nbits[(unsigned char) (v2)] +
34
_my_bits_nbits[(unsigned char) (v2 >> 8)] +
35
_my_bits_nbits[(unsigned char) (v2 >> 16)] +
36
_my_bits_nbits[(unsigned char) (v2 >> 24)]);
27
ulong v2=(ulong) (v >> 32);
28
return (uint) (uchar) (_my_bits_nbits[(uchar) v] +
29
_my_bits_nbits[(uchar) (v >> 8)] +
30
_my_bits_nbits[(uchar) (v >> 16)] +
31
_my_bits_nbits[(uchar) (v >> 24)] +
32
_my_bits_nbits[(uchar) (v2)] +
33
_my_bits_nbits[(uchar) (v2 >> 8)] +
34
_my_bits_nbits[(uchar) (v2 >> 16)] +
35
_my_bits_nbits[(uchar) (v2 >> 24)]);
37
return (uint) (uchar) (_my_bits_nbits[(uchar) v] +
38
_my_bits_nbits[(uchar) (v >> 8)] +
39
_my_bits_nbits[(uchar) (v >> 16)] +
40
_my_bits_nbits[(uchar) (v >> 24)]);
39
static inline uint32_t my_count_bits_uint16(uint16_t v)
44
static inline uint my_count_bits_ushort(ushort v)
41
46
return _my_bits_nbits[v];