Commit 72f39405 authored by Orvid King's avatar Orvid King Committed by facebook-github-bot-4

MSVC 2015 constexpr in Bits.h

Summary: MSVC 2015 supports constexpr intrinsics, and, as the GCC builtins are implemented by #287, we can remove all the MSVC specific intrinsic stuff that isn't constexpr supported.
Closes https://github.com/facebook/folly/pull/288

Reviewed By: @yfeldblum

Differential Revision: D2419064

Pulled By: @JoelMarcey
parent abece752
...@@ -55,10 +55,11 @@ ...@@ -55,10 +55,11 @@
#ifndef FOLLY_BITS_H_ #ifndef FOLLY_BITS_H_
#define FOLLY_BITS_H_ #define FOLLY_BITS_H_
#if !defined(__clang__) && !defined(_MSC_VER) #if !defined(__clang__) && !(defined(_MSC_VER) && (_MSC_VER < 1900))
#define FOLLY_INTRINSIC_CONSTEXPR constexpr #define FOLLY_INTRINSIC_CONSTEXPR constexpr
#else #else
// GCC is the only compiler with intrinsics constexpr. // GCC and MSVC 2015+ are the only compilers with
// intrinsics constexpr.
#define FOLLY_INTRINSIC_CONSTEXPR const #define FOLLY_INTRINSIC_CONSTEXPR const
#endif #endif
...@@ -72,14 +73,6 @@ ...@@ -72,14 +73,6 @@
# include <byteswap.h> # include <byteswap.h>
#endif #endif
#ifdef _MSC_VER
# include <intrin.h>
# pragma intrinsic(_BitScanForward)
# pragma intrinsic(_BitScanForward64)
# pragma intrinsic(_BitScanReverse)
# pragma intrinsic(_BitScanReverse64)
#endif
#include <cassert> #include <cassert>
#include <cinttypes> #include <cinttypes>
#include <iterator> #include <iterator>
...@@ -100,12 +93,7 @@ typename std::enable_if< ...@@ -100,12 +93,7 @@ typename std::enable_if<
sizeof(T) <= sizeof(unsigned int)), sizeof(T) <= sizeof(unsigned int)),
unsigned int>::type unsigned int>::type
findFirstSet(T x) { findFirstSet(T x) {
#ifdef _MSC_VER
unsigned long index;
return _BitScanForward(&index, x) ? index : 0;
#else
return __builtin_ffs(x); return __builtin_ffs(x);
#endif
} }
template <class T> template <class T>
...@@ -117,12 +105,7 @@ typename std::enable_if< ...@@ -117,12 +105,7 @@ typename std::enable_if<
sizeof(T) <= sizeof(unsigned long)), sizeof(T) <= sizeof(unsigned long)),
unsigned int>::type unsigned int>::type
findFirstSet(T x) { findFirstSet(T x) {
#ifdef _MSC_VER
unsigned long index;
return _BitScanForward(&index, x) ? index : 0;
#else
return __builtin_ffsl(x); return __builtin_ffsl(x);
#endif
} }
template <class T> template <class T>
...@@ -134,12 +117,7 @@ typename std::enable_if< ...@@ -134,12 +117,7 @@ typename std::enable_if<
sizeof(T) <= sizeof(unsigned long long)), sizeof(T) <= sizeof(unsigned long long)),
unsigned int>::type unsigned int>::type
findFirstSet(T x) { findFirstSet(T x) {
#ifdef _MSC_VER
unsigned long index;
return _BitScanForward64(&index, x) ? index : 0;
#else
return __builtin_ffsll(x); return __builtin_ffsll(x);
#endif
} }
template <class T> template <class T>
...@@ -164,18 +142,7 @@ typename std::enable_if< ...@@ -164,18 +142,7 @@ typename std::enable_if<
sizeof(T) <= sizeof(unsigned int)), sizeof(T) <= sizeof(unsigned int)),
unsigned int>::type unsigned int>::type
findLastSet(T x) { findLastSet(T x) {
#ifdef _MSC_VER
unsigned long index;
int clz;
if (_BitScanReverse(&index, x)) {
clz = static_cast<int>(31 - index);
} else {
clz = 32;
}
return x ? 8 * sizeof(unsigned int) - clz : 0;
#else
return x ? 8 * sizeof(unsigned int) - __builtin_clz(x) : 0; return x ? 8 * sizeof(unsigned int) - __builtin_clz(x) : 0;
#endif
} }
template <class T> template <class T>
...@@ -187,18 +154,7 @@ typename std::enable_if< ...@@ -187,18 +154,7 @@ typename std::enable_if<
sizeof(T) <= sizeof(unsigned long)), sizeof(T) <= sizeof(unsigned long)),
unsigned int>::type unsigned int>::type
findLastSet(T x) { findLastSet(T x) {
#ifdef _MSC_VER
unsigned long index;
int clz;
if (_BitScanReverse(&index, x)) {
clz = static_cast<int>(31 - index);
} else {
clz = 32;
}
return x ? 8 * sizeof(unsigned int) - clz : 0;
#else
return x ? 8 * sizeof(unsigned long) - __builtin_clzl(x) : 0; return x ? 8 * sizeof(unsigned long) - __builtin_clzl(x) : 0;
#endif
} }
template <class T> template <class T>
...@@ -210,18 +166,7 @@ typename std::enable_if< ...@@ -210,18 +166,7 @@ typename std::enable_if<
sizeof(T) <= sizeof(unsigned long long)), sizeof(T) <= sizeof(unsigned long long)),
unsigned int>::type unsigned int>::type
findLastSet(T x) { findLastSet(T x) {
#ifdef _MSC_VER
unsigned long index;
unsigned long long clz;
if (_BitScanReverse(&index, x)) {
clz = static_cast<unsigned long long>(63 - index);
} else {
clz = 64;
}
return x ? 8 * sizeof(unsigned long long) - clz : 0;
#else
return x ? 8 * sizeof(unsigned long long) - __builtin_clzll(x) : 0; return x ? 8 * sizeof(unsigned long long) - __builtin_clzll(x) : 0;
#endif
} }
template <class T> template <class T>
......
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