mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-01-18 02:52:10 +01:00
[util] Add bsf helper
For when we know we aren't going to put in a mask of 0, we can use this and get better codegen.
This commit is contained in:
parent
b09b912797
commit
64f417d6e6
@ -76,6 +76,25 @@ namespace dxvk::bit {
|
||||
#endif
|
||||
}
|
||||
|
||||
inline uint32_t bsf(uint32_t n) {
|
||||
#if defined(_MSC_VER) && !defined(__clang__)
|
||||
DWORD index;
|
||||
_BitScanForward(&index, n);
|
||||
return uint32_t(index);
|
||||
#elif defined(__GNUC__) || defined(__clang__)
|
||||
return __builtin_ctz(n);
|
||||
#else
|
||||
uint32_t r = 31;
|
||||
n &= -n;
|
||||
r -= (n & 0x0000FFFF) ? 16 : 0;
|
||||
r -= (n & 0x00FF00FF) ? 8 : 0;
|
||||
r -= (n & 0x0F0F0F0F) ? 4 : 0;
|
||||
r -= (n & 0x33333333) ? 2 : 0;
|
||||
r -= (n & 0x55555555) ? 1 : 0;
|
||||
return r;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline uint32_t lzcnt(uint32_t n) {
|
||||
#if (defined(_MSC_VER) && !defined(__clang__)) || defined(__LZCNT__)
|
||||
return _lzcnt_u32(n);
|
||||
|
Loading…
x
Reference in New Issue
Block a user