mirror of https://github.com/inolen/redream.git
avoid using popcnt intrinsics to support older processors such as the
core 2 duo which are plenty fast enough to support
This commit is contained in:
parent
1e412dac1d
commit
29c86bb03a
|
@ -17,14 +17,21 @@ static inline uint32_t bswap24(uint32_t v) {
|
||||||
return ((v & 0xff) << 16) | (v & 0x00ff00) | ((v & 0xff0000) >> 16);
|
return ((v & 0xff) << 16) | (v & 0x00ff00) | ((v & 0xff0000) >> 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int popcnt32(uint32_t v) {
|
||||||
|
/* avoid using popcnt intrinsics to support older processors such as the
|
||||||
|
core 2 duo which are plenty fast enough to support */
|
||||||
|
v = (v & 0x55555555) + ((v >> 1) & 0x55555555);
|
||||||
|
v = (v & 0x33333333) + ((v >> 2) & 0x33333333);
|
||||||
|
v = (v & 0x0f0f0f0f) + ((v >> 4) & 0x0f0f0f0f);
|
||||||
|
v = (v & 0x00ff00ff) + ((v >> 8) & 0x00ff00ff);
|
||||||
|
v = (v & 0x0000ffff) + ((v >> 16) & 0x0000ffff);
|
||||||
|
return (int)v;
|
||||||
|
}
|
||||||
|
|
||||||
#if COMPILER_MSVC
|
#if COMPILER_MSVC
|
||||||
|
|
||||||
#include <intrin.h>
|
#include <intrin.h>
|
||||||
|
|
||||||
static inline int popcnt32(uint32_t v) {
|
|
||||||
return __popcnt(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int clz32(uint32_t v) {
|
static inline int clz32(uint32_t v) {
|
||||||
unsigned long r = 0;
|
unsigned long r = 0;
|
||||||
_BitScanReverse(&r, v);
|
_BitScanReverse(&r, v);
|
||||||
|
@ -55,10 +62,6 @@ static inline uint32_t bswap32(uint32_t v) {
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
static inline int popcnt32(uint32_t v) {
|
|
||||||
return __builtin_popcount(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int clz32(uint32_t v) {
|
static inline int clz32(uint32_t v) {
|
||||||
return __builtin_clz(v);
|
return __builtin_clz(v);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue