From c7d2957d8f63fb16315c8cc711f6f998a677ca2d Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Wed, 9 May 2018 20:09:09 +0200 Subject: [PATCH] [util] Remove duplicate tzcnt function --- src/dxvk/dxvk_context.cpp | 2 +- src/util/util_bit.h | 30 +++++++++++++++++++++++------- src/util/util_math.h | 25 ------------------------- 3 files changed, 24 insertions(+), 33 deletions(-) diff --git a/src/dxvk/dxvk_context.cpp b/src/dxvk/dxvk_context.cpp index 56726460d..25f040f03 100644 --- a/src/dxvk/dxvk_context.cpp +++ b/src/dxvk/dxvk_context.cpp @@ -1970,7 +1970,7 @@ namespace dxvk { uint32_t bindingsSet = bindingMask; while (bindingsSet != bindingsUsed) { - uint32_t binding = tzcnt(~bindingsSet); + uint32_t binding = bit::tzcnt(~bindingsSet); buffers[binding] = m_device->dummyBufferHandle(); offsets[binding] = 0; diff --git a/src/util/util_bit.h b/src/util/util_bit.h index a946c6c95..0a1e712c6 100644 --- a/src/util/util_bit.h +++ b/src/util/util_bit.h @@ -14,13 +14,29 @@ namespace dxvk::bit { : 0; } - template - T tzcnt(T value) { - uint32_t result = 0; - while ((result < sizeof(T) * 8) - && (((value >> result) & 1) == 0)) - result += 1; - return result; + inline uint32_t tzcnt(uint32_t n) { + #if defined(__BMI__) + return __tzcnt_u32(n); + #elif defined(__GNUC__) + uint32_t res; + uint32_t tmp; + asm ( + "xor %1, %1;" + "bsf %2, %0;" + "cmovz %1, %0;" + : "=&r" (res), "=&r" (tmp) + : "r" (n)); + return res; + #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 n != 0 ? r : 32; + #endif } } \ No newline at end of file diff --git a/src/util/util_math.h b/src/util/util_math.h index 00392a611..cd0320894 100644 --- a/src/util/util_math.h +++ b/src/util/util_math.h @@ -18,29 +18,4 @@ namespace dxvk { return (what + to - 1) & ~(to - 1); } - inline uint32_t tzcnt(uint32_t n) { - #if defined(__BMI__) - return __tzcnt_u32(n); - #elif defined(__GNUC__) - uint32_t res; - uint32_t tmp; - asm ( - "xor %1, %1;" - "bsf %2, %0;" - "cmovz %1, %0;" - : "=&r" (res), "=&r" (tmp) - : "r" (n)); - return res; - #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 n != 0 ? r : 32; - #endif - } - } \ No newline at end of file