17 #ifndef MY_BIT_INCLUDED
18 #define MY_BIT_INCLUDED
26 extern const char _my_bits_nbits[256];
27 extern const uchar _my_bits_reverse_table[256];
34 static inline uint my_bit_log2(ulong value)
37 for (bit=0 ; value > 1 ; value>>=1, bit++) ;
41 static inline uint my_count_bits(ulonglong v)
43 #if SIZEOF_LONG_LONG > 4
46 ulong v2=(ulong) (v >> 32);
47 return (uint) (uchar) (_my_bits_nbits[(uchar) v] +
48 _my_bits_nbits[(uchar) (v >> 8)] +
49 _my_bits_nbits[(uchar) (v >> 16)] +
50 _my_bits_nbits[(uchar) (v >> 24)] +
51 _my_bits_nbits[(uchar) (v2)] +
52 _my_bits_nbits[(uchar) (v2 >> 8)] +
53 _my_bits_nbits[(uchar) (v2 >> 16)] +
54 _my_bits_nbits[(uchar) (v2 >> 24)]);
56 return (uint) (uchar) (_my_bits_nbits[(uchar) v] +
57 _my_bits_nbits[(uchar) (v >> 8)] +
58 _my_bits_nbits[(uchar) (v >> 16)] +
59 _my_bits_nbits[(uchar) (v >> 24)]);
63 static inline uint my_count_bits_uint32(uint32 v)
65 return (uint) (uchar) (_my_bits_nbits[(uchar) v] +
66 _my_bits_nbits[(uchar) (v >> 8)] +
67 _my_bits_nbits[(uchar) (v >> 16)] +
68 _my_bits_nbits[(uchar) (v >> 24)]);
91 static inline uint32 my_round_up_to_next_power(uint32 v)
102 static inline uint32 my_clear_highest_bit(uint32 v)
113 static inline uint32 my_reverse_bits(uint32 key)
116 (_my_bits_reverse_table[ key & 255] << 24) |
117 (_my_bits_reverse_table[(key>> 8) & 255] << 16) |
118 (_my_bits_reverse_table[(key>>16) & 255] << 8) |
119 _my_bits_reverse_table[(key>>24) ];