Panda3D
pbitops.h
1 // Filename: pbitops.h
2 // Created by: drose (10May08)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef PBITOPS_H
16 #define PBITOPS_H
17 
18 #include "pandabase.h"
19 #include "numeric_types.h"
20 
21 #ifdef _MSC_VER
22 #include <intrin.h>
23 #endif
24 
25 ////////////////////////////////////////////////////////////////////
26 // This file defines a few low-level bit-operation routines, optimized
27 // all to heck.
28 ////////////////////////////////////////////////////////////////////
29 
30 INLINE int count_bits_in_word(PN_uint16 x);
31 INLINE int count_bits_in_word(PN_uint32 x);
32 INLINE int count_bits_in_word(PN_uint64 x);
33 
34 INLINE PN_uint16 flood_bits_down(PN_uint16 x);
35 INLINE PN_uint32 flood_bits_down(PN_uint32 x);
36 INLINE PN_uint64 flood_bits_down(PN_uint64 x);
37 INLINE PN_uint16 flood_bits_up(PN_uint16 x);
38 INLINE PN_uint32 flood_bits_up(PN_uint32 x);
39 INLINE PN_uint64 flood_bits_up(PN_uint64 x);
40 
41 INLINE int get_lowest_on_bit(PN_uint16 x);
42 INLINE int get_lowest_on_bit(PN_uint32 x);
43 INLINE int get_lowest_on_bit(PN_uint64 x);
44 INLINE int get_highest_on_bit(PN_uint16 x);
45 INLINE int get_highest_on_bit(PN_uint32 x);
46 INLINE int get_highest_on_bit(PN_uint64 x);
47 
48 INLINE int get_next_higher_bit(PN_uint16 x);
49 INLINE int get_next_higher_bit(PN_uint32 x);
50 INLINE int get_next_higher_bit(PN_uint64 x);
51 
52 // This table precomputes the number of on bits in each 16-bit word.
53 extern EXPCL_PANDA_PUTIL const unsigned char num_bits_on[65536];
54 
55 #include "pbitops.I"
56 
57 #endif