mirror of
https://github.com/doitsujin/dxvk.git
synced 2024-12-02 19:24:12 +01:00
[util] Optimize popcnt operation
This commit is contained in:
parent
a1feaa6748
commit
dcd75a4f09
@ -15,11 +15,17 @@ namespace dxvk::bit {
|
|||||||
return (value >> fst) & ~(~T(0) << (lst - fst + 1));
|
return (value >> fst) & ~(~T(0) << (lst - fst + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
inline uint32_t popcntStep(uint32_t n, uint32_t mask, uint32_t shift) {
|
||||||
T popcnt(T value) {
|
return (n & mask) + ((n & ~mask) >> shift);
|
||||||
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) {
|
inline uint32_t tzcnt(uint32_t n) {
|
||||||
|
Loading…
Reference in New Issue
Block a user