~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_bit.h

  • Committer: Padraig O'Sullivan
  • Date: 2009-09-13 01:03:01 UTC
  • mto: (1126.9.2 captain-20090915-01)
  • mto: This revision was merged to the branch mainline in revision 1133.
  • Revision ID: osullivan.padraig@gmail.com-20090913010301-tcvvezipx1124acy
Added calls to the dtrace delete begin/end probes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008, 2009 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
19
 
 
20
1
/*
21
2
  Some useful bit functions
22
3
*/
23
4
 
24
 
#ifndef DRIZZLED_INTERNAL_MY_BIT_H
25
 
#define DRIZZLED_INTERNAL_MY_BIT_H
26
 
 
27
 
namespace drizzled
28
 
{
29
 
namespace internal
30
 
{
 
5
#ifdef __cplusplus
 
6
extern "C" {
 
7
#endif
31
8
 
32
9
extern const char _my_bits_nbits[256];
33
10
extern const unsigned char _my_bits_reverse_table[256];
65
42
}
66
43
 
67
44
 
 
45
/*
 
46
  Next highest power of two
 
47
 
 
48
  SYNOPSIS
 
49
    my_round_up_to_next_power()
 
50
    v           Value to check
 
51
 
 
52
  RETURN
 
53
    Next or equal power of 2
 
54
    Note: 0 will return 0
 
55
 
 
56
  NOTES
 
57
    Algorithm by Sean Anderson, according to:
 
58
    http://graphics.stanford.edu/~seander/bithacks.html
 
59
    (Orignal code public domain)
 
60
 
 
61
    Comments shows how this works with 01100000000000000000000000001011
 
62
*/
 
63
 
 
64
static inline uint32_t my_round_up_to_next_power(uint32_t v)
 
65
{
 
66
  v--;                  /* 01100000000000000000000000001010 */
 
67
  v|= v >> 1;           /* 01110000000000000000000000001111 */
 
68
  v|= v >> 2;           /* 01111100000000000000000000001111 */
 
69
  v|= v >> 4;           /* 01111111110000000000000000001111 */
 
70
  v|= v >> 8;           /* 01111111111111111100000000001111 */
 
71
  v|= v >> 16;          /* 01111111111111111111111111111111 */
 
72
  return v+1;           /* 10000000000000000000000000000000 */
 
73
}
 
74
 
68
75
static inline uint32_t my_clear_highest_bit(uint32_t v)
69
76
{
70
77
  uint32_t w=v >> 1;
85
92
     _my_bits_reverse_table[(key>>24)      ];
86
93
}
87
94
 
88
 
} /* namespace internal */
89
 
} /* namespace drizzled */
 
95
#ifdef __cplusplus
 
96
}
 
97
#endif
90
98
 
91
 
#endif /* DRIZZLED_INTERNAL_MY_BIT_H */