Panda3D
Loading...
Searching...
No Matches
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
27INLINE int count_bits_in_word(unsigned short x);
28INLINE int count_bits_in_word(unsigned int x);
29INLINE int count_bits_in_word(unsigned long x);
30INLINE int count_bits_in_word(unsigned long long x);
31
32INLINE unsigned short flood_bits_down(unsigned short x);
33INLINE unsigned int flood_bits_down(unsigned int x);
34INLINE unsigned long flood_bits_down(unsigned long x);
35INLINE unsigned long long flood_bits_down(unsigned long long x);
36INLINE unsigned short flood_bits_up(unsigned short x);
37INLINE unsigned int flood_bits_up(unsigned int x);
38INLINE unsigned long flood_bits_up(unsigned long x);
39INLINE unsigned long long flood_bits_up(unsigned long long x);
40
41INLINE int get_lowest_on_bit(unsigned short x);
42INLINE int get_lowest_on_bit(unsigned int x);
43INLINE int get_lowest_on_bit(unsigned long x);
44INLINE int get_lowest_on_bit(unsigned long long x);
45INLINE int get_highest_on_bit(unsigned short x);
46INLINE int get_highest_on_bit(unsigned int x);
47INLINE int get_highest_on_bit(unsigned long x);
48INLINE int get_highest_on_bit(unsigned long long x);
49
50INLINE int get_next_higher_bit(unsigned short x);
51INLINE int get_next_higher_bit(unsigned int x);
52INLINE int get_next_higher_bit(unsigned long x);
53INLINE int get_next_higher_bit(unsigned long long x);
54
55// This table precomputes the number of on bits in each 16-bit word.
56extern 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