xref: /freebsd/contrib/llvm-project/libcxx/include/bit (revision 4824e7fd18a1223177218d4aec1b3c6c5c4a444e)
10b57cec5SDimitry Andric// -*- C++ -*-
2349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
30b57cec5SDimitry Andric//
40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
70b57cec5SDimitry Andric//
80b57cec5SDimitry Andric//===---------------------------------------------------------------------===//
90b57cec5SDimitry Andric
100b57cec5SDimitry Andric#ifndef _LIBCPP_BIT
110b57cec5SDimitry Andric#define _LIBCPP_BIT
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric/*
140b57cec5SDimitry Andric    bit synopsis
150b57cec5SDimitry Andric
160b57cec5SDimitry Andricnamespace std {
17349cc55cSDimitry Andric  // [bit.cast], bit_cast
18349cc55cSDimitry Andric  template<class To, class From>
19349cc55cSDimitry Andric    constexpr To bit_cast(const From& from) noexcept; // C++20
200b57cec5SDimitry Andric
21*4824e7fdSDimitry Andric  // [bit.byteswap], byteswap
22*4824e7fdSDimitry Andric  template<class T>
23*4824e7fdSDimitry Andric    constexpr T byteswap(T value) noexcept;      // C++23
24*4824e7fdSDimitry Andric
255ffd83dbSDimitry Andric  // [bit.pow.two], integral powers of 2
260b57cec5SDimitry Andric  template <class T>
27e8d8bef9SDimitry Andric    constexpr bool has_single_bit(T x) noexcept; // C++20
280b57cec5SDimitry Andric  template <class T>
29e8d8bef9SDimitry Andric    constexpr T bit_ceil(T x);                   // C++20
300b57cec5SDimitry Andric  template <class T>
31e8d8bef9SDimitry Andric    constexpr T bit_floor(T x) noexcept;         // C++20
320b57cec5SDimitry Andric  template <class T>
33e8d8bef9SDimitry Andric    constexpr T bit_width(T x) noexcept;         // C++20
340b57cec5SDimitry Andric
355ffd83dbSDimitry Andric  // [bit.rotate], rotating
360b57cec5SDimitry Andric  template<class T>
370b57cec5SDimitry Andric    constexpr T rotl(T x, unsigned int s) noexcept; // C++20
380b57cec5SDimitry Andric  template<class T>
390b57cec5SDimitry Andric    constexpr T rotr(T x, unsigned int s) noexcept; // C++20
400b57cec5SDimitry Andric
415ffd83dbSDimitry Andric  // [bit.count], counting
420b57cec5SDimitry Andric  template<class T>
430b57cec5SDimitry Andric    constexpr int countl_zero(T x) noexcept;  // C++20
440b57cec5SDimitry Andric  template<class T>
450b57cec5SDimitry Andric    constexpr int countl_one(T x) noexcept;   // C++20
460b57cec5SDimitry Andric  template<class T>
470b57cec5SDimitry Andric    constexpr int countr_zero(T x) noexcept;  // C++20
480b57cec5SDimitry Andric  template<class T>
490b57cec5SDimitry Andric    constexpr int countr_one(T x) noexcept;   // C++20
500b57cec5SDimitry Andric  template<class T>
510b57cec5SDimitry Andric    constexpr int popcount(T x) noexcept;     // C++20
520b57cec5SDimitry Andric
535ffd83dbSDimitry Andric  // [bit.endian], endian
54e40139ffSDimitry Andric  enum class endian {
55e40139ffSDimitry Andric    little = see below,        // C++20
56e40139ffSDimitry Andric    big = see below,           // C++20
57e40139ffSDimitry Andric    native = see below         // C++20
58e40139ffSDimitry Andric  };
59e40139ffSDimitry Andric
600b57cec5SDimitry Andric} // namespace std
610b57cec5SDimitry Andric
620b57cec5SDimitry Andric*/
630b57cec5SDimitry Andric
64349cc55cSDimitry Andric#include <__bit/bit_cast.h>
65*4824e7fdSDimitry Andric#include <__bit/byteswap.h>
66fe6060f1SDimitry Andric#include <__bits> // __libcpp_clz
67349cc55cSDimitry Andric#include <__config>
68fe6060f1SDimitry Andric#include <__debug>
690b57cec5SDimitry Andric#include <limits>
700b57cec5SDimitry Andric#include <type_traits>
710b57cec5SDimitry Andric#include <version>
720b57cec5SDimitry Andric
730b57cec5SDimitry Andric#if defined(__IBMCPP__)
74d409305fSDimitry Andric#include "__support/ibm/support.h"
750b57cec5SDimitry Andric#endif
760b57cec5SDimitry Andric#if defined(_LIBCPP_COMPILER_MSVC)
770b57cec5SDimitry Andric#include <intrin.h>
780b57cec5SDimitry Andric#endif
790b57cec5SDimitry Andric
800b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
810b57cec5SDimitry Andric#pragma GCC system_header
820b57cec5SDimitry Andric#endif
830b57cec5SDimitry Andric
840b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS
850b57cec5SDimitry Andric#include <__undef_macros>
860b57cec5SDimitry Andric
870b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
880b57cec5SDimitry Andric
890b57cec5SDimitry Andrictemplate<class _Tp>
900b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
910b57cec5SDimitry Andric_Tp __rotl(_Tp __t, unsigned int __cnt) _NOEXCEPT
920b57cec5SDimitry Andric{
93fe6060f1SDimitry Andric    static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__rotl requires an unsigned integer type");
940b57cec5SDimitry Andric    const unsigned int __dig = numeric_limits<_Tp>::digits;
950b57cec5SDimitry Andric    if ((__cnt % __dig) == 0)
960b57cec5SDimitry Andric        return __t;
970b57cec5SDimitry Andric    return (__t << (__cnt % __dig)) | (__t >> (__dig - (__cnt % __dig)));
980b57cec5SDimitry Andric}
990b57cec5SDimitry Andric
1000b57cec5SDimitry Andrictemplate<class _Tp>
1010b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1020b57cec5SDimitry Andric_Tp __rotr(_Tp __t, unsigned int __cnt) _NOEXCEPT
1030b57cec5SDimitry Andric{
104fe6060f1SDimitry Andric    static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__rotr requires an unsigned integer type");
1050b57cec5SDimitry Andric    const unsigned int __dig = numeric_limits<_Tp>::digits;
1060b57cec5SDimitry Andric    if ((__cnt % __dig) == 0)
1070b57cec5SDimitry Andric        return __t;
1080b57cec5SDimitry Andric    return (__t >> (__cnt % __dig)) | (__t << (__dig - (__cnt % __dig)));
1090b57cec5SDimitry Andric}
1100b57cec5SDimitry Andric
1110b57cec5SDimitry Andrictemplate<class _Tp>
1120b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1130b57cec5SDimitry Andricint __countr_zero(_Tp __t) _NOEXCEPT
1140b57cec5SDimitry Andric{
115fe6060f1SDimitry Andric    static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__countr_zero requires an unsigned integer type");
1160b57cec5SDimitry Andric    if (__t == 0)
1170b57cec5SDimitry Andric        return numeric_limits<_Tp>::digits;
1180b57cec5SDimitry Andric
1190b57cec5SDimitry Andric    if      (sizeof(_Tp) <= sizeof(unsigned int))
1200b57cec5SDimitry Andric        return __libcpp_ctz(static_cast<unsigned int>(__t));
1210b57cec5SDimitry Andric    else if (sizeof(_Tp) <= sizeof(unsigned long))
1220b57cec5SDimitry Andric        return __libcpp_ctz(static_cast<unsigned long>(__t));
1230b57cec5SDimitry Andric    else if (sizeof(_Tp) <= sizeof(unsigned long long))
1240b57cec5SDimitry Andric        return __libcpp_ctz(static_cast<unsigned long long>(__t));
1250b57cec5SDimitry Andric    else
1260b57cec5SDimitry Andric    {
1270b57cec5SDimitry Andric        int __ret = 0;
1280b57cec5SDimitry Andric        const unsigned int __ulldigits = numeric_limits<unsigned long long>::digits;
129fe6060f1SDimitry Andric        while (static_cast<unsigned long long>(__t) == 0uLL)
1300b57cec5SDimitry Andric        {
131fe6060f1SDimitry Andric            __ret += __ulldigits;
1320b57cec5SDimitry Andric            __t >>= __ulldigits;
1330b57cec5SDimitry Andric        }
134fe6060f1SDimitry Andric        return __ret + __libcpp_ctz(static_cast<unsigned long long>(__t));
1350b57cec5SDimitry Andric    }
1360b57cec5SDimitry Andric}
1370b57cec5SDimitry Andric
1380b57cec5SDimitry Andrictemplate<class _Tp>
1390b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1400b57cec5SDimitry Andricint __countl_zero(_Tp __t) _NOEXCEPT
1410b57cec5SDimitry Andric{
142fe6060f1SDimitry Andric    static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__countl_zero requires an unsigned integer type");
1430b57cec5SDimitry Andric    if (__t == 0)
1440b57cec5SDimitry Andric        return numeric_limits<_Tp>::digits;
1450b57cec5SDimitry Andric
1460b57cec5SDimitry Andric    if      (sizeof(_Tp) <= sizeof(unsigned int))
1470b57cec5SDimitry Andric        return __libcpp_clz(static_cast<unsigned int>(__t))
1480b57cec5SDimitry Andric              - (numeric_limits<unsigned int>::digits - numeric_limits<_Tp>::digits);
1490b57cec5SDimitry Andric    else if (sizeof(_Tp) <= sizeof(unsigned long))
1500b57cec5SDimitry Andric        return __libcpp_clz(static_cast<unsigned long>(__t))
1510b57cec5SDimitry Andric              - (numeric_limits<unsigned long>::digits - numeric_limits<_Tp>::digits);
1520b57cec5SDimitry Andric    else if (sizeof(_Tp) <= sizeof(unsigned long long))
1530b57cec5SDimitry Andric        return __libcpp_clz(static_cast<unsigned long long>(__t))
1540b57cec5SDimitry Andric              - (numeric_limits<unsigned long long>::digits - numeric_limits<_Tp>::digits);
1550b57cec5SDimitry Andric    else
1560b57cec5SDimitry Andric    {
1570b57cec5SDimitry Andric        int __ret = 0;
1580b57cec5SDimitry Andric        int __iter = 0;
1590b57cec5SDimitry Andric        const unsigned int __ulldigits = numeric_limits<unsigned long long>::digits;
1600b57cec5SDimitry Andric        while (true) {
1610b57cec5SDimitry Andric            __t = __rotr(__t, __ulldigits);
1620b57cec5SDimitry Andric            if ((__iter = __countl_zero(static_cast<unsigned long long>(__t))) != __ulldigits)
1630b57cec5SDimitry Andric                break;
1640b57cec5SDimitry Andric            __ret += __iter;
1650b57cec5SDimitry Andric            }
1660b57cec5SDimitry Andric        return __ret + __iter;
1670b57cec5SDimitry Andric    }
1680b57cec5SDimitry Andric}
1690b57cec5SDimitry Andric
1700b57cec5SDimitry Andrictemplate<class _Tp>
1710b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1720b57cec5SDimitry Andricint __countl_one(_Tp __t) _NOEXCEPT
1730b57cec5SDimitry Andric{
174fe6060f1SDimitry Andric    static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__countl_one requires an unsigned integer type");
1750b57cec5SDimitry Andric    return __t != numeric_limits<_Tp>::max()
1760b57cec5SDimitry Andric        ? __countl_zero(static_cast<_Tp>(~__t))
1770b57cec5SDimitry Andric        : numeric_limits<_Tp>::digits;
1780b57cec5SDimitry Andric}
1790b57cec5SDimitry Andric
1800b57cec5SDimitry Andrictemplate<class _Tp>
1810b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1820b57cec5SDimitry Andricint __countr_one(_Tp __t) _NOEXCEPT
1830b57cec5SDimitry Andric{
184fe6060f1SDimitry Andric    static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__countr_one requires an unsigned integer type");
1850b57cec5SDimitry Andric    return __t != numeric_limits<_Tp>::max()
1860b57cec5SDimitry Andric        ? __countr_zero(static_cast<_Tp>(~__t))
1870b57cec5SDimitry Andric        : numeric_limits<_Tp>::digits;
1880b57cec5SDimitry Andric}
1890b57cec5SDimitry Andric
1900b57cec5SDimitry Andrictemplate<class _Tp>
1910b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
192fe6060f1SDimitry Andricint __popcount(_Tp __t) _NOEXCEPT
1930b57cec5SDimitry Andric{
194fe6060f1SDimitry Andric    static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__popcount requires an unsigned integer type");
1950b57cec5SDimitry Andric    if      (sizeof(_Tp) <= sizeof(unsigned int))
1960b57cec5SDimitry Andric        return __libcpp_popcount(static_cast<unsigned int>(__t));
1970b57cec5SDimitry Andric    else if (sizeof(_Tp) <= sizeof(unsigned long))
1980b57cec5SDimitry Andric        return __libcpp_popcount(static_cast<unsigned long>(__t));
1990b57cec5SDimitry Andric    else if (sizeof(_Tp) <= sizeof(unsigned long long))
2000b57cec5SDimitry Andric        return __libcpp_popcount(static_cast<unsigned long long>(__t));
2010b57cec5SDimitry Andric    else
2020b57cec5SDimitry Andric    {
2030b57cec5SDimitry Andric        int __ret = 0;
2040b57cec5SDimitry Andric        while (__t != 0)
2050b57cec5SDimitry Andric        {
2060b57cec5SDimitry Andric            __ret += __libcpp_popcount(static_cast<unsigned long long>(__t));
2070b57cec5SDimitry Andric            __t >>= numeric_limits<unsigned long long>::digits;
2080b57cec5SDimitry Andric        }
2090b57cec5SDimitry Andric        return __ret;
2100b57cec5SDimitry Andric    }
2110b57cec5SDimitry Andric}
2120b57cec5SDimitry Andric
2130b57cec5SDimitry Andric// integral log base 2
2140b57cec5SDimitry Andrictemplate<class _Tp>
2150b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
2160b57cec5SDimitry Andricunsigned __bit_log2(_Tp __t) _NOEXCEPT
2170b57cec5SDimitry Andric{
218fe6060f1SDimitry Andric    static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__bit_log2 requires an unsigned integer type");
219e8d8bef9SDimitry Andric    return numeric_limits<_Tp>::digits - 1 - __countl_zero(__t);
2200b57cec5SDimitry Andric}
2210b57cec5SDimitry Andric
2220b57cec5SDimitry Andrictemplate <class _Tp>
2230b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
224e8d8bef9SDimitry Andricbool __has_single_bit(_Tp __t) _NOEXCEPT
2250b57cec5SDimitry Andric{
226fe6060f1SDimitry Andric    static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__has_single_bit requires an unsigned integer type");
2270b57cec5SDimitry Andric    return __t != 0 && (((__t & (__t - 1)) == 0));
2280b57cec5SDimitry Andric}
2290b57cec5SDimitry Andric
2300b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17
2310b57cec5SDimitry Andric
2320b57cec5SDimitry Andrictemplate<class _Tp>
2330b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY constexpr
234349cc55cSDimitry Andricenable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, _Tp>
2350b57cec5SDimitry Andricrotl(_Tp __t, unsigned int __cnt) noexcept
2360b57cec5SDimitry Andric{
2370b57cec5SDimitry Andric    return __rotl(__t, __cnt);
2380b57cec5SDimitry Andric}
2390b57cec5SDimitry Andric
2400b57cec5SDimitry Andrictemplate<class _Tp>
2410b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY constexpr
242349cc55cSDimitry Andricenable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, _Tp>
2430b57cec5SDimitry Andricrotr(_Tp __t, unsigned int __cnt) noexcept
2440b57cec5SDimitry Andric{
2450b57cec5SDimitry Andric    return __rotr(__t, __cnt);
2460b57cec5SDimitry Andric}
2470b57cec5SDimitry Andric
2480b57cec5SDimitry Andrictemplate<class _Tp>
2490b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY constexpr
250349cc55cSDimitry Andricenable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, int>
2510b57cec5SDimitry Andriccountl_zero(_Tp __t) noexcept
2520b57cec5SDimitry Andric{
2530b57cec5SDimitry Andric    return __countl_zero(__t);
2540b57cec5SDimitry Andric}
2550b57cec5SDimitry Andric
2560b57cec5SDimitry Andrictemplate<class _Tp>
2570b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY constexpr
258349cc55cSDimitry Andricenable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, int>
2590b57cec5SDimitry Andriccountl_one(_Tp __t) noexcept
2600b57cec5SDimitry Andric{
2610b57cec5SDimitry Andric    return __countl_one(__t);
2620b57cec5SDimitry Andric}
2630b57cec5SDimitry Andric
2640b57cec5SDimitry Andrictemplate<class _Tp>
2650b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY constexpr
266349cc55cSDimitry Andricenable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, int>
2670b57cec5SDimitry Andriccountr_zero(_Tp __t) noexcept
2680b57cec5SDimitry Andric{
2690b57cec5SDimitry Andric    return __countr_zero(__t);
2700b57cec5SDimitry Andric}
2710b57cec5SDimitry Andric
2720b57cec5SDimitry Andrictemplate<class _Tp>
2730b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY constexpr
274349cc55cSDimitry Andricenable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, int>
2750b57cec5SDimitry Andriccountr_one(_Tp __t) noexcept
2760b57cec5SDimitry Andric{
2770b57cec5SDimitry Andric    return __countr_one(__t);
2780b57cec5SDimitry Andric}
2790b57cec5SDimitry Andric
2800b57cec5SDimitry Andrictemplate<class _Tp>
2810b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY constexpr
282349cc55cSDimitry Andricenable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, int>
2830b57cec5SDimitry Andricpopcount(_Tp __t) noexcept
2840b57cec5SDimitry Andric{
2850b57cec5SDimitry Andric    return __popcount(__t);
2860b57cec5SDimitry Andric}
2870b57cec5SDimitry Andric
2880b57cec5SDimitry Andrictemplate <class _Tp>
2890b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY constexpr
290349cc55cSDimitry Andricenable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, bool>
291e8d8bef9SDimitry Andrichas_single_bit(_Tp __t) noexcept
2920b57cec5SDimitry Andric{
293e8d8bef9SDimitry Andric    return __has_single_bit(__t);
2940b57cec5SDimitry Andric}
2950b57cec5SDimitry Andric
2960b57cec5SDimitry Andrictemplate <class _Tp>
2970b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY constexpr
298349cc55cSDimitry Andricenable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, _Tp>
299e8d8bef9SDimitry Andricbit_floor(_Tp __t) noexcept
3000b57cec5SDimitry Andric{
3010b57cec5SDimitry Andric    return __t == 0 ? 0 : _Tp{1} << __bit_log2(__t);
3020b57cec5SDimitry Andric}
3030b57cec5SDimitry Andric
3040b57cec5SDimitry Andrictemplate <class _Tp>
3050b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY constexpr
306349cc55cSDimitry Andricenable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, _Tp>
307e8d8bef9SDimitry Andricbit_ceil(_Tp __t) noexcept
3080b57cec5SDimitry Andric{
3090b57cec5SDimitry Andric    if (__t < 2) return 1;
3100b57cec5SDimitry Andric    const unsigned __n = numeric_limits<_Tp>::digits - countl_zero((_Tp)(__t - 1u));
311e8d8bef9SDimitry Andric    _LIBCPP_DEBUG_ASSERT(__libcpp_is_constant_evaluated() || __n != numeric_limits<_Tp>::digits, "Bad input to bit_ceil");
3120b57cec5SDimitry Andric
3130b57cec5SDimitry Andric    if constexpr (sizeof(_Tp) >= sizeof(unsigned))
3140b57cec5SDimitry Andric        return _Tp{1} << __n;
3150b57cec5SDimitry Andric    else
3160b57cec5SDimitry Andric    {
3170b57cec5SDimitry Andric        const unsigned __extra = numeric_limits<unsigned>::digits  - numeric_limits<_Tp>::digits;
3180b57cec5SDimitry Andric        const unsigned __retVal = 1u << (__n + __extra);
3190b57cec5SDimitry Andric        return (_Tp) (__retVal >> __extra);
3200b57cec5SDimitry Andric    }
3210b57cec5SDimitry Andric}
3220b57cec5SDimitry Andric
3230b57cec5SDimitry Andrictemplate <class _Tp>
3240b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY constexpr
325349cc55cSDimitry Andricenable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, _Tp>
326e8d8bef9SDimitry Andricbit_width(_Tp __t) noexcept
3270b57cec5SDimitry Andric{
3280b57cec5SDimitry Andric    return __t == 0 ? 0 : __bit_log2(__t) + 1;
3290b57cec5SDimitry Andric}
3300b57cec5SDimitry Andric
331e40139ffSDimitry Andricenum class endian
332e40139ffSDimitry Andric{
333e40139ffSDimitry Andric    little = 0xDEAD,
334e40139ffSDimitry Andric    big    = 0xFACE,
335e40139ffSDimitry Andric#if defined(_LIBCPP_LITTLE_ENDIAN)
336e40139ffSDimitry Andric    native = little
337e40139ffSDimitry Andric#elif defined(_LIBCPP_BIG_ENDIAN)
338e40139ffSDimitry Andric    native = big
339e40139ffSDimitry Andric#else
340e40139ffSDimitry Andric    native = 0xCAFE
341e40139ffSDimitry Andric#endif
342e40139ffSDimitry Andric};
343e40139ffSDimitry Andric
3440b57cec5SDimitry Andric#endif // _LIBCPP_STD_VER > 17
3450b57cec5SDimitry Andric
3460b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
3470b57cec5SDimitry Andric
3480b57cec5SDimitry Andric_LIBCPP_POP_MACROS
3490b57cec5SDimitry Andric
3500b57cec5SDimitry Andric#endif // _LIBCPP_BIT
351