~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/internal/my_bit.h

  • Committer: Brian Aker
  • Date: 2010-01-22 00:53:13 UTC
  • Revision ID: brian@gaz-20100122005313-jmizcbcdi1lt4tcx
Revert db patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008, 2009 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008, 2009 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
24
24
#ifndef DRIZZLED_INTERNAL_MY_BIT_H
25
25
#define DRIZZLED_INTERNAL_MY_BIT_H
26
26
 
27
 
namespace drizzled
28
 
{
29
 
namespace internal
30
 
{
 
27
#ifdef __cplusplus
 
28
extern "C" {
 
29
#endif
31
30
 
32
31
extern const char _my_bits_nbits[256];
33
32
extern const unsigned char _my_bits_reverse_table[256];
65
64
}
66
65
 
67
66
 
 
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
 
68
97
static inline uint32_t my_clear_highest_bit(uint32_t v)
69
98
{
70
99
  uint32_t w=v >> 1;
85
114
     _my_bits_reverse_table[(key>>24)      ];
86
115
}
87
116
 
88
 
} /* namespace internal */
89
 
} /* namespace drizzled */
 
117
#ifdef __cplusplus
 
118
}
 
119
#endif
90
120
 
91
121
#endif /* DRIZZLED_INTERNAL_MY_BIT_H */