mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
Improve pbitops performance by enabling GCC intrinsics when available
This commit is contained in:
parent
747e1fe381
commit
10a72e595b
@ -218,13 +218,4 @@ init_libputil() {
|
|||||||
|
|
||||||
BamCacheIndex::register_with_read_factory();
|
BamCacheIndex::register_with_read_factory();
|
||||||
BamCacheRecord::register_with_read_factory();
|
BamCacheRecord::register_with_read_factory();
|
||||||
|
|
||||||
// Initialize the num_bits_on table, for BitMask::get_num_on_bits().
|
|
||||||
for (int bit = 0; bit < 16; ++bit) {
|
|
||||||
int w = (1 << bit);
|
|
||||||
for (int i = 0; i < w; ++i) {
|
|
||||||
num_bits_on[i + w] = num_bits_on[i] + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,11 @@ count_bits_in_word(PN_uint16 x) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE int
|
INLINE int
|
||||||
count_bits_in_word(PN_uint32 x) {
|
count_bits_in_word(PN_uint32 x) {
|
||||||
|
#if defined(__GNUC__) && defined(__POPCNT__)
|
||||||
|
return __builtin_popcount((unsigned int) x);
|
||||||
|
#else
|
||||||
return (int)num_bits_on[x & 0xffff] + (int)num_bits_on[(x >> 16) & 0xffff];
|
return (int)num_bits_on[x & 0xffff] + (int)num_bits_on[(x >> 16) & 0xffff];
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -37,7 +41,11 @@ count_bits_in_word(PN_uint32 x) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE int
|
INLINE int
|
||||||
count_bits_in_word(PN_uint64 x) {
|
count_bits_in_word(PN_uint64 x) {
|
||||||
|
#if defined(__GNUC__) && defined(__POPCNT__)
|
||||||
|
return __builtin_popcountll((unsigned long long) x);
|
||||||
|
#else
|
||||||
return count_bits_in_word((PN_uint32)x) + count_bits_in_word((PN_uint32)(x >> 32));
|
return count_bits_in_word((PN_uint32)x) + count_bits_in_word((PN_uint32)(x >> 32));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -137,12 +145,16 @@ flood_bits_up(PN_uint64 x) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE int
|
INLINE int
|
||||||
get_lowest_on_bit(PN_uint16 x) {
|
get_lowest_on_bit(PN_uint16 x) {
|
||||||
|
#ifdef __GNUC__
|
||||||
|
return __builtin_ffs((unsigned int) x) - 1;
|
||||||
|
#else
|
||||||
if (x == 0) {
|
if (x == 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
PN_uint16 w = (x & (~x + 1));
|
PN_uint16 w = (x & (~x + 1));
|
||||||
return (int)num_bits_on[w - 1];
|
return (int)num_bits_on[w - 1];
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -152,12 +164,16 @@ get_lowest_on_bit(PN_uint16 x) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE int
|
INLINE int
|
||||||
get_lowest_on_bit(PN_uint32 x) {
|
get_lowest_on_bit(PN_uint32 x) {
|
||||||
|
#ifdef __GNUC__
|
||||||
|
return __builtin_ffs((unsigned int) x) - 1;
|
||||||
|
#else
|
||||||
if (x == 0) {
|
if (x == 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
PN_uint32 w = (x & (~x + 1));
|
PN_uint32 w = (x & (~x + 1));
|
||||||
return count_bits_in_word(w - 1);
|
return count_bits_in_word(w - 1);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -167,12 +183,16 @@ get_lowest_on_bit(PN_uint32 x) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE int
|
INLINE int
|
||||||
get_lowest_on_bit(PN_uint64 x) {
|
get_lowest_on_bit(PN_uint64 x) {
|
||||||
|
#ifdef __GNUC__
|
||||||
|
return __builtin_ffsll((unsigned long long) x) - 1;
|
||||||
|
#else
|
||||||
if (x == 0) {
|
if (x == 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
PN_uint64 w = (x & (~x + 1));
|
PN_uint64 w = (x & (~x + 1));
|
||||||
return count_bits_in_word(w - 1);
|
return count_bits_in_word(w - 1);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -182,8 +202,12 @@ get_lowest_on_bit(PN_uint64 x) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE int
|
INLINE int
|
||||||
get_highest_on_bit(PN_uint16 x) {
|
get_highest_on_bit(PN_uint16 x) {
|
||||||
|
#ifdef __GNUC__
|
||||||
|
return (x == 0) ? -1 : 31 - __builtin_clz((unsigned int) x);
|
||||||
|
#else
|
||||||
PN_uint16 w = flood_bits_down(x);
|
PN_uint16 w = flood_bits_down(x);
|
||||||
return count_bits_in_word(w) - 1;
|
return count_bits_in_word(w) - 1;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -193,8 +217,12 @@ get_highest_on_bit(PN_uint16 x) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE int
|
INLINE int
|
||||||
get_highest_on_bit(PN_uint32 x) {
|
get_highest_on_bit(PN_uint32 x) {
|
||||||
|
#ifdef __GNUC__
|
||||||
|
return (x == 0) ? -1 : 31 - __builtin_clz((unsigned int) x);
|
||||||
|
#else
|
||||||
PN_uint32 w = flood_bits_down(x);
|
PN_uint32 w = flood_bits_down(x);
|
||||||
return count_bits_in_word(w) - 1;
|
return count_bits_in_word(w) - 1;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -204,8 +232,12 @@ get_highest_on_bit(PN_uint32 x) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE int
|
INLINE int
|
||||||
get_highest_on_bit(PN_uint64 x) {
|
get_highest_on_bit(PN_uint64 x) {
|
||||||
|
#ifdef __GNUC__
|
||||||
|
return (x == 0) ? -1 : 63 - __builtin_clzll((unsigned long long) x);
|
||||||
|
#else
|
||||||
PN_uint64 w = flood_bits_down(x);
|
PN_uint64 w = flood_bits_down(x);
|
||||||
return count_bits_in_word(w) - 1;
|
return count_bits_in_word(w) - 1;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -46,7 +46,7 @@ INLINE int get_next_higher_bit(PN_uint32 x);
|
|||||||
INLINE int get_next_higher_bit(PN_uint64 x);
|
INLINE int get_next_higher_bit(PN_uint64 x);
|
||||||
|
|
||||||
// This table precomputes the number of on bits in each 16-bit word.
|
// This table precomputes the number of on bits in each 16-bit word.
|
||||||
extern EXPCL_PANDA_PUTIL unsigned char num_bits_on[65536];
|
extern EXPCL_PANDA_PUTIL const unsigned char num_bits_on[65536];
|
||||||
|
|
||||||
#include "pbitops.I"
|
#include "pbitops.I"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user