~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/internal/my_bit.h

Merge Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#ifndef DRIZZLED_INTERNAL_MY_BIT_H
25
25
#define DRIZZLED_INTERNAL_MY_BIT_H
26
26
 
27
 
#ifdef __cplusplus
28
 
extern "C" {
29
 
#endif
 
27
namespace drizzled
 
28
{
 
29
namespace internal
 
30
{
30
31
 
31
32
extern const char _my_bits_nbits[256];
32
33
extern const unsigned char _my_bits_reverse_table[256];
64
65
}
65
66
 
66
67
 
67
 
/*
68
 
  Next highest power of two
69
 
 
70
 
  SYNOPSIS
71
 
    my_round_up_to_next_power()
72
 
    v           Value to check
73
 
 
74
 
  RETURN
75
 
    Next or equal power of 2
76
 
    Note: 0 will return 0
77
 
 
78
 
  NOTES
79
 
    Algorithm by Sean Anderson, according to:
80
 
    http://graphics.stanford.edu/~seander/bithacks.html
81
 
    (Orignal code public domain)
82
 
 
83
 
    Comments shows how this works with 01100000000000000000000000001011
84
 
*/
85
 
 
86
 
static inline uint32_t my_round_up_to_next_power(uint32_t v)
87
 
{
88
 
  v--;                  /* 01100000000000000000000000001010 */
89
 
  v|= v >> 1;           /* 01110000000000000000000000001111 */
90
 
  v|= v >> 2;           /* 01111100000000000000000000001111 */
91
 
  v|= v >> 4;           /* 01111111110000000000000000001111 */
92
 
  v|= v >> 8;           /* 01111111111111111100000000001111 */
93
 
  v|= v >> 16;          /* 01111111111111111111111111111111 */
94
 
  return v+1;           /* 10000000000000000000000000000000 */
95
 
}
96
 
 
97
68
static inline uint32_t my_clear_highest_bit(uint32_t v)
98
69
{
99
70
  uint32_t w=v >> 1;
114
85
     _my_bits_reverse_table[(key>>24)      ];
115
86
}
116
87
 
117
 
#ifdef __cplusplus
118
 
}
119
 
#endif
 
88
} /* namespace internal */
 
89
} /* namespace drizzled */
120
90
 
121
91
#endif /* DRIZZLED_INTERNAL_MY_BIT_H */