#ifndef LLVM_ADT_BIT_H
#define LLVM_ADT_BIT_H
#include "llvm/Support/Compiler.h"
#include <cstdint>
#include <limits>
#include <type_traits>
#if !__has_builtin(__builtin_bit_cast)
#include <cstring>
#endif
#if defined(_MSC_VER) && !defined(_DEBUG)
#include <cstdlib>
#endif
#if defined(__linux__) || defined(__GNU__) || defined(__HAIKU__) || \
defined(__Fuchsia__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) || \
defined(__OpenBSD__) || defined(__DragonFly__)
#include <endian.h>
#elif defined(_AIX)
#include <sys/machine.h>
#elif defined(__sun)
#include <sys/types.h>
#define BIG_ENDIAN …
#define LITTLE_ENDIAN …
#if defined(_BIG_ENDIAN)
#define BYTE_ORDER …
#else
#define BYTE_ORDER …
#endif
#elif defined(__MVS__)
#define BIG_ENDIAN …
#define LITTLE_ENDIAN …
#define BYTE_ORDER …
#else
#if !defined(BYTE_ORDER) && !defined(_WIN32)
#include <machine/endian.h>
#endif
#endif
#ifdef _MSC_VER
extern "C" {
unsigned char _BitScanForward(unsigned long *_Index, unsigned long _Mask);
unsigned char _BitScanForward64(unsigned long *_Index, unsigned __int64 _Mask);
unsigned char _BitScanReverse(unsigned long *_Index, unsigned long _Mask);
unsigned char _BitScanReverse64(unsigned long *_Index, unsigned __int64 _Mask);
}
#endif
namespace llvm {
enum class endianness { … };
template <
typename To, typename From,
typename = std::enable_if_t<sizeof(To) == sizeof(From)>,
typename = std::enable_if_t<std::is_trivially_constructible<To>::value>,
typename = std::enable_if_t<std::is_trivially_copyable<To>::value>,
typename = std::enable_if_t<std::is_trivially_copyable<From>::value>>
[[nodiscard]] inline To bit_cast(const From &from) noexcept { … }
template <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
[[nodiscard]] constexpr T byteswap(T V) noexcept { … }
template <typename T, typename = std::enable_if_t<std::is_unsigned_v<T>>>
[[nodiscard]] constexpr inline bool has_single_bit(T Value) noexcept { … }
namespace detail {
template <typename T, std::size_t SizeOfT> struct TrailingZerosCounter { … };
#if defined(__GNUC__) || defined(_MSC_VER)
TrailingZerosCounter<T, 4>;
#if !defined(_MSC_VER) || defined(_M_X64)
TrailingZerosCounter<T, 8>;
#endif
#endif
}
template <typename T> [[nodiscard]] int countr_zero(T Val) { … }
namespace detail {
template <typename T, std::size_t SizeOfT> struct LeadingZerosCounter { … };
#if defined(__GNUC__) || defined(_MSC_VER)
LeadingZerosCounter<T, 4>;
#if !defined(_MSC_VER) || defined(_M_X64)
LeadingZerosCounter<T, 8>;
#endif
#endif
}
template <typename T> [[nodiscard]] int countl_zero(T Val) { … }
template <typename T> [[nodiscard]] int countl_one(T Value) { … }
template <typename T> [[nodiscard]] int countr_one(T Value) { … }
template <typename T> [[nodiscard]] int bit_width(T Value) { … }
template <typename T> [[nodiscard]] T bit_floor(T Value) { … }
template <typename T> [[nodiscard]] T bit_ceil(T Value) { … }
namespace detail {
template <typename T, std::size_t SizeOfT> struct PopulationCounter { … };
PopulationCounter<T, 8>;
}
template <typename T, typename = std::enable_if_t<std::is_unsigned_v<T>>>
[[nodiscard]] inline int popcount(T Value) noexcept { … }
template <typename T, typename = std::enable_if_t<std::is_unsigned_v<T>>>
[[nodiscard]] constexpr T rotr(T V, int R);
template <typename T, typename = std::enable_if_t<std::is_unsigned_v<T>>>
[[nodiscard]] constexpr T rotl(T V, int R) { … }
template <typename T, typename> [[nodiscard]] constexpr T rotr(T V, int R) { … }
}
#endif