Move folly/Hash.h to folly/hash/, leaving a shim
[folly.git] / folly / Bits.h
index 6c3c30ece1d027a5fd6018dedfbe270ca260b1f5..4b71c18963600ebdd74b4eadc076d98cbf5fbb96 100644 (file)
 
 #pragma once
 
-#if !defined(__clang__) && !(defined(_MSC_VER) && (_MSC_VER < 1900))
-#define FOLLY_INTRINSIC_CONSTEXPR constexpr
-#else
-// GCC and MSVC 2015+ are the only compilers with
-// intrinsics constexpr.
+// MSVC does not support intrinsics constexpr
+#if defined(_MSC_VER)
 #define FOLLY_INTRINSIC_CONSTEXPR const
+#else
+#define FOLLY_INTRINSIC_CONSTEXPR constexpr
 #endif
 
-#include <folly/Portability.h>
-#include <folly/portability/Builtins.h>
-
-#include <folly/Assume.h>
-#include <folly/detail/BitsDetail.h>
-#include <folly/detail/BitIteratorDetail.h>
-#include <folly/Likely.h>
-
 #include <cassert>
-#include <cstring>
 #include <cinttypes>
+#include <cstdint>
+#include <cstring>
 #include <iterator>
 #include <limits>
 #include <type_traits>
+
 #include <boost/iterator/iterator_adaptor.hpp>
-#include <stdint.h>
+
+#include <folly/Assume.h>
+#include <folly/Likely.h>
+#include <folly/Portability.h>
+#include <folly/detail/BitIteratorDetail.h>
+#include <folly/portability/Builtins.h>
 
 namespace folly {
 
@@ -214,7 +212,7 @@ inline typename std::enable_if<
    sizeof(T) <= sizeof(unsigned int)),
   size_t>::type
   popcount(T x) {
-  return size_t(detail::popcount(x));
+  return size_t(__builtin_popcount(x));
 }
 
 template <class T>
@@ -225,7 +223,7 @@ inline typename std::enable_if<
    sizeof(T) <= sizeof(unsigned long long)),
   size_t>::type
   popcount(T x) {
-  return size_t(detail::popcountll(x));
+  return size_t(__builtin_popcountll(x));
 }
 
 /**
@@ -241,7 +239,7 @@ struct uint_types_by_size;
     return fn(v);                                           \
   }                                                         \
   template <>                                               \
-  struct uint_types_by_size<sz> {                           \
+  struct uint_types_by_size<sz / 8> {                       \
     using type = uint##sz##_t;                              \
   };
 
@@ -268,7 +266,7 @@ struct EndianInt {
     // we implement this with memcpy because that is defined behavior in C++
     // we rely on compilers to optimize away the memcpy calls
     constexpr auto s = sizeof(T);
-    using B = typename uint_types_by_size<8 * s>::type;
+    using B = typename uint_types_by_size<s>::type;
     B b;
     std::memcpy(&b, &x, s);
     b = byteswap_gen(b);
@@ -283,7 +281,7 @@ struct EndianInt {
   }
 };
 
-}  // namespace detail
+} // namespace detail
 
 // big* convert between native and big-endian representations
 // little* convert between native and little-endian representations
@@ -551,4 +549,4 @@ inline void storeUnaligned(void* p, T value) {
   }
 }
 
-}  // namespace folly
+} // namespace folly