2017-10-16 17:50:09 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
namespace dxvk::bit {
|
|
|
|
|
2017-10-21 17:58:58 +02:00
|
|
|
template<typename T>
|
2017-11-07 15:10:38 +01:00
|
|
|
T extract(T value, uint32_t fst, uint32_t lst) {
|
2017-10-21 17:58:58 +02:00
|
|
|
return (value >> fst) & ~(~T(0) << (lst - fst + 1));
|
2017-10-16 17:50:09 +02:00
|
|
|
}
|
|
|
|
|
2017-11-07 15:10:38 +01:00
|
|
|
template<typename T>
|
|
|
|
T popcnt(T value) {
|
|
|
|
return value != 0
|
|
|
|
? (value & 1) + popcnt(value >> 1)
|
|
|
|
: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
T tzcnt(T value) {
|
|
|
|
uint32_t result = 0;
|
|
|
|
while ((result < sizeof(T) * 8)
|
|
|
|
&& (((value >> result) & 1) == 0))
|
|
|
|
result += 1;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-10-16 17:50:09 +02:00
|
|
|
}
|