Unverified Commit 42699bf4 authored by jk-jeon's avatar jk-jeon Committed by GitHub

Fix msvc version of clz & clzll (#1880)

Change msvc version of clz & clzll to match __builtin_clz & _builtin_clzll
parent bc51a8df
...@@ -195,7 +195,7 @@ namespace detail { ...@@ -195,7 +195,7 @@ namespace detail {
# ifndef __clang__ # ifndef __clang__
# pragma intrinsic(_BitScanReverse) # pragma intrinsic(_BitScanReverse)
# endif # endif
inline uint32_t clz(uint32_t x) { inline int clz(uint32_t x) {
unsigned long r = 0; unsigned long r = 0;
_BitScanReverse(&r, x); _BitScanReverse(&r, x);
...@@ -204,7 +204,7 @@ inline uint32_t clz(uint32_t x) { ...@@ -204,7 +204,7 @@ inline uint32_t clz(uint32_t x) {
// "r", but the only way that can happen is if "x" is 0, // "r", but the only way that can happen is if "x" is 0,
// which the callers guarantee to not happen. // which the callers guarantee to not happen.
FMT_SUPPRESS_MSC_WARNING(6102) FMT_SUPPRESS_MSC_WARNING(6102)
return 31 - r; return 31 - static_cast<int>(r);
} }
# define FMT_BUILTIN_CLZ(n) detail::clz(n) # define FMT_BUILTIN_CLZ(n) detail::clz(n)
...@@ -212,7 +212,7 @@ inline uint32_t clz(uint32_t x) { ...@@ -212,7 +212,7 @@ inline uint32_t clz(uint32_t x) {
# pragma intrinsic(_BitScanReverse64) # pragma intrinsic(_BitScanReverse64)
# endif # endif
inline uint32_t clzll(uint64_t x) { inline int clzll(uint64_t x) {
unsigned long r = 0; unsigned long r = 0;
# ifdef _WIN64 # ifdef _WIN64
_BitScanReverse64(&r, x); _BitScanReverse64(&r, x);
...@@ -229,7 +229,7 @@ inline uint32_t clzll(uint64_t x) { ...@@ -229,7 +229,7 @@ inline uint32_t clzll(uint64_t x) {
// "r", but the only way that can happen is if "x" is 0, // "r", but the only way that can happen is if "x" is 0,
// which the callers guarantee to not happen. // which the callers guarantee to not happen.
FMT_SUPPRESS_MSC_WARNING(6102) FMT_SUPPRESS_MSC_WARNING(6102)
return 63 - r; return 63 - static_cast<int>(r);
} }
# define FMT_BUILTIN_CLZLL(n) detail::clzll(n) # define FMT_BUILTIN_CLZLL(n) detail::clzll(n)
} // namespace detail } // namespace detail
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment