Skip to content

Commit

Permalink
Fix msvc version of clz & clzll (#1880)
Browse files Browse the repository at this point in the history
Change msvc version of clz & clzll to match __builtin_clz & _builtin_clzll
  • Loading branch information
jk-jeon authored Sep 18, 2020
1 parent bc51a8d commit 42699bf
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ namespace detail {
# ifndef __clang__
# pragma intrinsic(_BitScanReverse)
# endif
inline uint32_t clz(uint32_t x) {
inline int clz(uint32_t x) {
unsigned long r = 0;
_BitScanReverse(&r, x);

Expand All @@ -204,15 +204,15 @@ inline uint32_t clz(uint32_t x) {
// "r", but the only way that can happen is if "x" is 0,
// which the callers guarantee to not happen.
FMT_SUPPRESS_MSC_WARNING(6102)
return 31 - r;
return 31 - static_cast<int>(r);
}
# define FMT_BUILTIN_CLZ(n) detail::clz(n)

# if defined(_WIN64) && !defined(__clang__)
# pragma intrinsic(_BitScanReverse64)
# endif

inline uint32_t clzll(uint64_t x) {
inline int clzll(uint64_t x) {
unsigned long r = 0;
# ifdef _WIN64
_BitScanReverse64(&r, x);
Expand All @@ -229,7 +229,7 @@ inline uint32_t clzll(uint64_t x) {
// "r", but the only way that can happen is if "x" is 0,
// which the callers guarantee to not happen.
FMT_SUPPRESS_MSC_WARNING(6102)
return 63 - r;
return 63 - static_cast<int>(r);
}
# define FMT_BUILTIN_CLZLL(n) detail::clzll(n)
} // namespace detail
Expand Down

0 comments on commit 42699bf

Please sign in to comment.