Panda3D
pbitops.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file pbitops.h
10  * @author drose
11  * @date 2008-05-10
12  */
13 
14 #ifndef PBITOPS_H
15 #define PBITOPS_H
16 
17 #include "pandabase.h"
18 #include "numeric_types.h"
19 
20 #if defined(_MSC_VER) && !defined(CPPPARSER)
21 #include <intrin.h>
22 #endif
23 
24 // This file defines a few low-level bit-operation routines, optimized all to
25 // heck.
26 
27 INLINE int count_bits_in_word(unsigned short x);
28 INLINE int count_bits_in_word(unsigned int x);
29 INLINE int count_bits_in_word(unsigned long x);
30 INLINE int count_bits_in_word(unsigned long long x);
31 
32 INLINE unsigned short flood_bits_down(unsigned short x);
33 INLINE unsigned int flood_bits_down(unsigned int x);
34 INLINE unsigned long flood_bits_down(unsigned long x);
35 INLINE unsigned long long flood_bits_down(unsigned long long x);
36 INLINE unsigned short flood_bits_up(unsigned short x);
37 INLINE unsigned int flood_bits_up(unsigned int x);
38 INLINE unsigned long flood_bits_up(unsigned long x);
39 INLINE unsigned long long flood_bits_up(unsigned long long x);
40 
41 INLINE int get_lowest_on_bit(unsigned short x);
42 INLINE int get_lowest_on_bit(unsigned int x);
43 INLINE int get_lowest_on_bit(unsigned long x);
44 INLINE int get_lowest_on_bit(unsigned long long x);
45 INLINE int get_highest_on_bit(unsigned short x);
46 INLINE int get_highest_on_bit(unsigned int x);
47 INLINE int get_highest_on_bit(unsigned long x);
48 INLINE int get_highest_on_bit(unsigned long long x);
49 
50 INLINE int get_next_higher_bit(unsigned short x);
51 INLINE int get_next_higher_bit(unsigned int x);
52 INLINE int get_next_higher_bit(unsigned long x);
53 INLINE int get_next_higher_bit(unsigned long long x);
54 
55 // This table precomputes the number of on bits in each 16-bit word.
56 extern EXPCL_PANDA_PUTIL const unsigned char num_bits_on[65536];
57 
58 #include "pbitops.I"
59 
60 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_highest_on_bit(unsigned short x)
Returns the index of the highest 1 bit in the word.
Definition: pbitops.I:259
unsigned short flood_bits_down(unsigned short x)
Returns a value such that every bit at or below the highest bit in x is 1.
Definition: pbitops.I:64
unsigned short flood_bits_up(unsigned short x)
Returns a value such that every bit at or above the highest bit in x is 1.
Definition: pbitops.I:119
int count_bits_in_word(unsigned short x)
Returns the number of 1 bits in the indicated word.
Definition: pbitops.I:18
int get_lowest_on_bit(unsigned short x)
Returns the index of the lowest 1 bit in the word.
Definition: pbitops.I:175
int get_next_higher_bit(unsigned short x)
Returns the smallest power of 2 greater than x.
Definition: pbitops.I:328