1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-02 10:24:12 +01:00

[util] Optimize popcnt operation

This commit is contained in:
Philip Rebohle 2019-05-09 16:37:45 +02:00
parent a1feaa6748
commit dcd75a4f09
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99

View File

@ -14,12 +14,18 @@ namespace dxvk::bit {
T extract(T value, uint32_t fst, uint32_t lst) {
return (value >> fst) & ~(~T(0) << (lst - fst + 1));
}
inline uint32_t popcntStep(uint32_t n, uint32_t mask, uint32_t shift) {
return (n & mask) + ((n & ~mask) >> shift);
}
template<typename T>
T popcnt(T value) {
return value != 0
? (value & 1) + popcnt(value >> 1)
: 0;
inline uint32_t popcnt(uint32_t n) {
n = popcntStep(n, 0x55555555, 1);
n = popcntStep(n, 0x33333333, 2);
n = popcntStep(n, 0x0F0F0F0F, 4);
n = popcntStep(n, 0x00FF00FF, 8);
n = popcntStep(n, 0x0000FFFF, 16);
return n;
}
inline uint32_t tzcnt(uint32_t n) {