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(uint16_t x);
28 INLINE int count_bits_in_word(uint32_t x);
29 INLINE int count_bits_in_word(uint64_t x);
30 
31 INLINE uint16_t flood_bits_down(uint16_t x);
32 INLINE uint32_t flood_bits_down(uint32_t x);
33 INLINE uint64_t flood_bits_down(uint64_t x);
34 INLINE uint16_t flood_bits_up(uint16_t x);
35 INLINE uint32_t flood_bits_up(uint32_t x);
36 INLINE uint64_t flood_bits_up(uint64_t x);
37 
38 INLINE int get_lowest_on_bit(uint16_t x);
39 INLINE int get_lowest_on_bit(uint32_t x);
40 INLINE int get_lowest_on_bit(uint64_t x);
41 INLINE int get_highest_on_bit(uint16_t x);
42 INLINE int get_highest_on_bit(uint32_t x);
43 INLINE int get_highest_on_bit(uint64_t x);
44 
45 INLINE int get_next_higher_bit(uint16_t x);
46 INLINE int get_next_higher_bit(uint32_t x);
47 INLINE int get_next_higher_bit(uint64_t x);
48 
49 // This table precomputes the number of on bits in each 16-bit word.
50 extern EXPCL_PANDA_PUTIL const unsigned char num_bits_on[65536];
51 
52 #include "pbitops.I"
53 
54 #endif
uint16_t flood_bits_up(uint16_t x)
Returns a value such that every bit at or above the highest bit in x is 1.
Definition: pbitops.I:89
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_next_higher_bit(uint16_t x)
Returns the smallest power of 2 greater than x.
Definition: pbitops.I:244
int get_lowest_on_bit(uint16_t x)
Returns the index of the lowest 1 bit in the word.
Definition: pbitops.I:129
int get_highest_on_bit(uint16_t x)
Returns the index of the highest 1 bit in the word.
Definition: pbitops.I:192
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
uint16_t flood_bits_down(uint16_t x)
Returns a value such that every bit at or below the highest bit in x is 1.
Definition: pbitops.I:50
int count_bits_in_word(uint16_t x)
Returns the number of 1 bits in the indicated word.
Definition: pbitops.I:18