Commit ce3f7699 authored by Victor Zverovich's avatar Victor Zverovich

Merge intrinsic blocks

parent 3b6248f6
...@@ -40,11 +40,6 @@ ...@@ -40,11 +40,6 @@
# pragma warning(disable : 4702) // unreachable code # pragma warning(disable : 4702) // unreachable code
#endif #endif
// For x64-specific MSVC intrinsics
#if defined(_MSC_VER) && defined(_M_X64)
# include <intrin.h>
#endif
// Dummy implementations of strerror_r and strerror_s called if corresponding // Dummy implementations of strerror_r and strerror_s called if corresponding
// system functions are not available. // system functions are not available.
inline fmt::detail::null<> strerror_r(int, char*, ...) { return {}; } inline fmt::detail::null<> strerror_r(int, char*, ...) { return {}; }
......
...@@ -189,12 +189,14 @@ FMT_END_NAMESPACE ...@@ -189,12 +189,14 @@ FMT_END_NAMESPACE
# define FMT_BUILTIN_CTZLL(n) __builtin_ctzll(n) # define FMT_BUILTIN_CTZLL(n) __builtin_ctzll(n)
#endif #endif
#if FMT_MSC_VER
# include <intrin.h> // _BitScanReverse[64], _BitScanForward[64], _umul128
#endif
// Some compilers masquerade as both MSVC and GCC-likes or otherwise support // Some compilers masquerade as both MSVC and GCC-likes or otherwise support
// __builtin_clz and __builtin_clzll, so only define FMT_BUILTIN_CLZ using the // __builtin_clz and __builtin_clzll, so only define FMT_BUILTIN_CLZ using the
// MSVC intrinsics if the clz and clzll builtins are not available. // MSVC intrinsics if the clz and clzll builtins are not available.
#if FMT_MSC_VER && !defined(FMT_BUILTIN_CLZLL) && !defined(_MANAGED) #if FMT_MSC_VER && !defined(FMT_BUILTIN_CLZLL) && !defined(FMT_BUILTIN_CTZLL) && !defined(_MANAGED)
# include <intrin.h> // _BitScanReverse, _BitScanReverse64
FMT_BEGIN_NAMESPACE FMT_BEGIN_NAMESPACE
namespace detail { namespace detail {
// Avoid Clang with Microsoft CodeGen's -Wunknown-pragmas warning. // Avoid Clang with Microsoft CodeGen's -Wunknown-pragmas warning.
...@@ -204,7 +206,6 @@ namespace detail { ...@@ -204,7 +206,6 @@ namespace detail {
inline int clz(uint32_t x) { inline int clz(uint32_t x) {
unsigned long r = 0; unsigned long r = 0;
_BitScanReverse(&r, x); _BitScanReverse(&r, x);
FMT_ASSERT(x != 0, ""); FMT_ASSERT(x != 0, "");
// Static analysis complains about using uninitialized data // Static analysis complains about using uninitialized data
// "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,
...@@ -225,29 +226,15 @@ inline int clzll(uint64_t x) { ...@@ -225,29 +226,15 @@ inline int clzll(uint64_t x) {
# else # else
// Scan the high 32 bits. // Scan the high 32 bits.
if (_BitScanReverse(&r, static_cast<uint32_t>(x >> 32))) return 63 - (r + 32); if (_BitScanReverse(&r, static_cast<uint32_t>(x >> 32))) return 63 - (r + 32);
// Scan the low 32 bits. // Scan the low 32 bits.
_BitScanReverse(&r, static_cast<uint32_t>(x)); _BitScanReverse(&r, static_cast<uint32_t>(x));
# endif # endif
FMT_ASSERT(x != 0, ""); FMT_ASSERT(x != 0, "");
// Static analysis complains about using uninitialized data FMT_SUPPRESS_MSC_WARNING(6102) // Suppress a bogus static analysis warning.
// "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 - static_cast<int>(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
FMT_END_NAMESPACE
#endif
// Same for __builtin_ctz and __builtin_ctzll
#if FMT_MSC_VER && !defined(FMT_BUILTIN_CTZLL) && !defined(_MANAGED)
# include <intrin.h> // _BitScanReverse, _BitScanReverse64
FMT_BEGIN_NAMESPACE
namespace detail {
// Avoid Clang with Microsoft CodeGen's -Wunknown-pragmas warning. // Avoid Clang with Microsoft CodeGen's -Wunknown-pragmas warning.
# ifndef __clang__ # ifndef __clang__
# pragma intrinsic(_BitScanForward) # pragma intrinsic(_BitScanForward)
...@@ -255,12 +242,8 @@ namespace detail { ...@@ -255,12 +242,8 @@ namespace detail {
inline int ctz(uint32_t x) { inline int ctz(uint32_t x) {
unsigned long r = 0; unsigned long r = 0;
_BitScanForward(&r, x); _BitScanForward(&r, x);
FMT_ASSERT(x != 0, ""); FMT_ASSERT(x != 0, "");
// Static analysis complains about using uninitialized data FMT_SUPPRESS_MSC_WARNING(6102) // Suppress a bogus static analysis warning.
// "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 static_cast<int>(r); return static_cast<int>(r);
} }
# define FMT_BUILTIN_CTZ(n) detail::ctz(n) # define FMT_BUILTIN_CTZ(n) detail::ctz(n)
...@@ -272,23 +255,17 @@ inline int ctz(uint32_t x) { ...@@ -272,23 +255,17 @@ inline int ctz(uint32_t x) {
inline int ctzll(uint64_t x) { inline int ctzll(uint64_t x) {
unsigned long r = 0; unsigned long r = 0;
FMT_ASSERT(x != 0, ""); FMT_ASSERT(x != 0, "");
// Static analysis complains about using uninitialized data FMT_SUPPRESS_MSC_WARNING(6102) // Suppress a bogus static analysis warning.
// "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)
# ifdef _WIN64 # ifdef _WIN64
_BitScanForward64(&r, x); _BitScanForward64(&r, x);
# else # else
// Scan the low 32 bits. // Scan the low 32 bits.
if (_BitScanForward(&r, static_cast<uint32_t>(x))) if (_BitScanForward(&r, static_cast<uint32_t>(x)))
return static_cast<int>(r); return static_cast<int>(r);
// Scan the high 32 bits. // Scan the high 32 bits.
_BitScanForward(&r, static_cast<uint32_t>(x >> 32)); _BitScanForward(&r, static_cast<uint32_t>(x >> 32));
r += 32; r += 32;
# endif # endif
return static_cast<int>(r); return static_cast<int>(r);
} }
# define FMT_BUILTIN_CTZLL(n) detail::ctzll(n) # define FMT_BUILTIN_CTZLL(n) detail::ctzll(n)
......
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