summaryrefslogtreecommitdiff
path: root/third_party/libcxx/include/c++/v1/__bit
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.x@gmail.com>2026-07-11 22:48:30 +0800
committerRichard Qin <richard.qin.x@gmail.com>2026-07-11 22:48:30 +0800
commit3ad39e9878310e5317ee73c9b353c1e2c1c5c4ee (patch)
tree4bd5a49ef60ad1e371c0984cd46838368c5ef83a /third_party/libcxx/include/c++/v1/__bit
parent48ef95c24e9ac3d11200b61af617a01b10b507d1 (diff)
downloadlume-3ad39e9878310e5317ee73c9b353c1e2c1c5c4ee.tar.gz
lume-3ad39e9878310e5317ee73c9b353c1e2c1c5c4ee.tar.xz
lib: establish Zircon libc++ and KTL foundation
Diffstat (limited to 'third_party/libcxx/include/c++/v1/__bit')
-rw-r--r--third_party/libcxx/include/c++/v1/__bit/bit_cast.h44
-rw-r--r--third_party/libcxx/include/c++/v1/__bit/bit_ceil.h54
-rw-r--r--third_party/libcxx/include/c++/v1/__bit/bit_floor.h33
-rw-r--r--third_party/libcxx/include/c++/v1/__bit/bit_log2.h33
-rw-r--r--third_party/libcxx/include/c++/v1/__bit/bit_width.h33
-rw-r--r--third_party/libcxx/include/c++/v1/__bit/blsr.h34
-rw-r--r--third_party/libcxx/include/c++/v1/__bit/byteswap.h53
-rw-r--r--third_party/libcxx/include/c++/v1/__bit/countl.h48
-rw-r--r--third_party/libcxx/include/c++/v1/__bit/countr.h48
-rw-r--r--third_party/libcxx/include/c++/v1/__bit/endian.h38
-rw-r--r--third_party/libcxx/include/c++/v1/__bit/has_single_bit.h37
-rw-r--r--third_party/libcxx/include/c++/v1/__bit/invert_if.h30
-rw-r--r--third_party/libcxx/include/c++/v1/__bit/popcount.h42
-rw-r--r--third_party/libcxx/include/c++/v1/__bit/rotate.h60
14 files changed, 587 insertions, 0 deletions
diff --git a/third_party/libcxx/include/c++/v1/__bit/bit_cast.h b/third_party/libcxx/include/c++/v1/__bit/bit_cast.h
new file mode 100644
index 0000000..7350250
--- /dev/null
+++ b/third_party/libcxx/include/c++/v1/__bit/bit_cast.h
@@ -0,0 +1,44 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___BIT_BIT_CAST_H
+#define _LIBCPP___BIT_BIT_CAST_H
+
+#include <__config>
+#include <__type_traits/is_trivially_copyable.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#ifndef _LIBCPP_CXX03_LANG
+
+template <class _ToType, class _FromType>
+[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr _ToType __bit_cast(const _FromType& __from) noexcept {
+ return __builtin_bit_cast(_ToType, __from);
+}
+
+#endif // _LIBCPP_CXX03_LANG
+
+#if _LIBCPP_STD_VER >= 20
+
+template <class _ToType, class _FromType>
+ requires(sizeof(_ToType) == sizeof(_FromType) && is_trivially_copyable_v<_ToType> &&
+ is_trivially_copyable_v<_FromType>)
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _ToType bit_cast(const _FromType& __from) noexcept {
+ return __builtin_bit_cast(_ToType, __from);
+}
+
+#endif // _LIBCPP_STD_VER >= 20
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___BIT_BIT_CAST_H
diff --git a/third_party/libcxx/include/c++/v1/__bit/bit_ceil.h b/third_party/libcxx/include/c++/v1/__bit/bit_ceil.h
new file mode 100644
index 0000000..99881a8
--- /dev/null
+++ b/third_party/libcxx/include/c++/v1/__bit/bit_ceil.h
@@ -0,0 +1,54 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___BIT_BIT_CEIL_H
+#define _LIBCPP___BIT_BIT_CEIL_H
+
+#include <__assert>
+#include <__bit/countl.h>
+#include <__config>
+#include <__type_traits/integer_traits.h>
+#include <limits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 17
+
+template <class _Tp>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp __bit_ceil(_Tp __t) noexcept {
+ if (__t < 2)
+ return 1;
+ const unsigned __n = numeric_limits<_Tp>::digits - std::__countl_zero((_Tp)(__t - 1u));
+ _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(__n != numeric_limits<_Tp>::digits, "Bad input to bit_ceil");
+
+ if constexpr (sizeof(_Tp) >= sizeof(unsigned))
+ return _Tp{1} << __n;
+ else {
+ const unsigned __extra = numeric_limits<unsigned>::digits - numeric_limits<_Tp>::digits;
+ const unsigned __ret_val = 1u << (__n + __extra);
+ return (_Tp)(__ret_val >> __extra);
+ }
+}
+
+# if _LIBCPP_STD_VER >= 20
+
+template <__unsigned_integer _Tp>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp bit_ceil(_Tp __t) noexcept {
+ return std::__bit_ceil(__t);
+}
+
+# endif // _LIBCPP_STD_VER >= 20
+#endif // _LIBCPP_STD_VER >= 17
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___BIT_BIT_CEIL_H
diff --git a/third_party/libcxx/include/c++/v1/__bit/bit_floor.h b/third_party/libcxx/include/c++/v1/__bit/bit_floor.h
new file mode 100644
index 0000000..799a064
--- /dev/null
+++ b/third_party/libcxx/include/c++/v1/__bit/bit_floor.h
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___BIT_BIT_FLOOR_H
+#define _LIBCPP___BIT_BIT_FLOOR_H
+
+#include <__bit/bit_log2.h>
+#include <__config>
+#include <__type_traits/integer_traits.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 20
+
+template <__unsigned_integer _Tp>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp bit_floor(_Tp __t) noexcept {
+ return __t == 0 ? 0 : _Tp{1} << std::__bit_log2(__t);
+}
+
+#endif // _LIBCPP_STD_VER >= 20
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___BIT_BIT_FLOOR_H
diff --git a/third_party/libcxx/include/c++/v1/__bit/bit_log2.h b/third_party/libcxx/include/c++/v1/__bit/bit_log2.h
new file mode 100644
index 0000000..9ceeec1
--- /dev/null
+++ b/third_party/libcxx/include/c++/v1/__bit/bit_log2.h
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___BIT_BIT_LOG2_H
+#define _LIBCPP___BIT_BIT_LOG2_H
+
+#include <__assert>
+#include <__bit/countl.h>
+#include <__config>
+#include <__type_traits/integer_traits.h>
+#include <limits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Tp>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp __bit_log2(_Tp __t) _NOEXCEPT {
+ static_assert(__is_unsigned_integer_v<_Tp>, "__bit_log2 requires an unsigned integer type");
+ _LIBCPP_ASSERT_INTERNAL(__t != 0, "logarithm of 0 is undefined");
+ return numeric_limits<_Tp>::digits - 1 - std::__countl_zero(__t);
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___BIT_BIT_LOG2_H
diff --git a/third_party/libcxx/include/c++/v1/__bit/bit_width.h b/third_party/libcxx/include/c++/v1/__bit/bit_width.h
new file mode 100644
index 0000000..75050ac
--- /dev/null
+++ b/third_party/libcxx/include/c++/v1/__bit/bit_width.h
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___BIT_BIT_WIDTH_H
+#define _LIBCPP___BIT_BIT_WIDTH_H
+
+#include <__bit/bit_log2.h>
+#include <__config>
+#include <__type_traits/integer_traits.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER >= 20
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <__unsigned_integer _Tp>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr int bit_width(_Tp __t) noexcept {
+ return __t == 0 ? 0 : std::__bit_log2(__t) + 1;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_STD_VER >= 20
+
+#endif // _LIBCPP___BIT_BIT_WIDTH_H
diff --git a/third_party/libcxx/include/c++/v1/__bit/blsr.h b/third_party/libcxx/include/c++/v1/__bit/blsr.h
new file mode 100644
index 0000000..76bd521
--- /dev/null
+++ b/third_party/libcxx/include/c++/v1/__bit/blsr.h
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___BIT_BLSR_H
+#define _LIBCPP___BIT_BLSR_H
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unsigned __libcpp_blsr(unsigned __x) _NOEXCEPT {
+ return __x ^ (__x & -__x);
+}
+
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unsigned long __libcpp_blsr(unsigned long __x) _NOEXCEPT {
+ return __x ^ (__x & -__x);
+}
+
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unsigned long long __libcpp_blsr(unsigned long long __x) _NOEXCEPT {
+ return __x ^ (__x & -__x);
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___BIT_BLSR_H
diff --git a/third_party/libcxx/include/c++/v1/__bit/byteswap.h b/third_party/libcxx/include/c++/v1/__bit/byteswap.h
new file mode 100644
index 0000000..7ce7e06
--- /dev/null
+++ b/third_party/libcxx/include/c++/v1/__bit/byteswap.h
@@ -0,0 +1,53 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___BIT_BYTESWAP_H
+#define _LIBCPP___BIT_BYTESWAP_H
+
+#include <__concepts/arithmetic.h>
+#include <__config>
+#include <cstdint>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+template <integral _Tp>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp byteswap(_Tp __val) noexcept {
+ if constexpr (sizeof(_Tp) == 1) {
+ return __val;
+ } else if constexpr (sizeof(_Tp) == 2) {
+ return __builtin_bswap16(__val);
+ } else if constexpr (sizeof(_Tp) == 4) {
+ return __builtin_bswap32(__val);
+ } else if constexpr (sizeof(_Tp) == 8) {
+ return __builtin_bswap64(__val);
+# if _LIBCPP_HAS_INT128
+ } else if constexpr (sizeof(_Tp) == 16) {
+# if __has_builtin(__builtin_bswap128)
+ return __builtin_bswap128(__val);
+# else
+ return (static_cast<_Tp>(byteswap(static_cast<uint64_t>(__val))) << 64) |
+ static_cast<_Tp>(byteswap(static_cast<uint64_t>(__val >> 64)));
+# endif // __has_builtin(__builtin_bswap128)
+# endif // _LIBCPP_HAS_INT128
+ } else {
+ static_assert(sizeof(_Tp) == 0, "byteswap is unimplemented for integral types of this size");
+ }
+}
+
+#endif // _LIBCPP_STD_VER >= 23
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___BIT_BYTESWAP_H
diff --git a/third_party/libcxx/include/c++/v1/__bit/countl.h b/third_party/libcxx/include/c++/v1/__bit/countl.h
new file mode 100644
index 0000000..c95828f
--- /dev/null
+++ b/third_party/libcxx/include/c++/v1/__bit/countl.h
@@ -0,0 +1,48 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___BIT_COUNTL_H
+#define _LIBCPP___BIT_COUNTL_H
+
+#include <__config>
+#include <__type_traits/integer_traits.h>
+#include <limits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Tp>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int __countl_zero(_Tp __t) _NOEXCEPT {
+ return __builtin_clzg(__t, numeric_limits<_Tp>::digits);
+}
+
+#if _LIBCPP_STD_VER >= 20
+
+template <__unsigned_integer _Tp>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr int countl_zero(_Tp __t) noexcept {
+ return std::__countl_zero(__t);
+}
+
+template <__unsigned_integer _Tp>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr int countl_one(_Tp __t) noexcept {
+ return std::countl_zero(static_cast<_Tp>(~__t));
+}
+
+#endif // _LIBCPP_STD_VER >= 20
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___BIT_COUNTL_H
diff --git a/third_party/libcxx/include/c++/v1/__bit/countr.h b/third_party/libcxx/include/c++/v1/__bit/countr.h
new file mode 100644
index 0000000..16f689d
--- /dev/null
+++ b/third_party/libcxx/include/c++/v1/__bit/countr.h
@@ -0,0 +1,48 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___BIT_COUNTR_H
+#define _LIBCPP___BIT_COUNTR_H
+
+#include <__config>
+#include <__type_traits/integer_traits.h>
+#include <limits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Tp>
+[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __countr_zero(_Tp __t) _NOEXCEPT {
+ return __builtin_ctzg(__t, numeric_limits<_Tp>::digits);
+}
+
+#if _LIBCPP_STD_VER >= 20
+
+template <__unsigned_integer _Tp>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr int countr_zero(_Tp __t) noexcept {
+ return std::__countr_zero(__t);
+}
+
+template <__unsigned_integer _Tp>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr int countr_one(_Tp __t) noexcept {
+ return std::countr_zero(static_cast<_Tp>(~__t));
+}
+
+#endif // _LIBCPP_STD_VER >= 20
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___BIT_COUNTR_H
diff --git a/third_party/libcxx/include/c++/v1/__bit/endian.h b/third_party/libcxx/include/c++/v1/__bit/endian.h
new file mode 100644
index 0000000..2d31e5d
--- /dev/null
+++ b/third_party/libcxx/include/c++/v1/__bit/endian.h
@@ -0,0 +1,38 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___BIT_ENDIAN_H
+#define _LIBCPP___BIT_ENDIAN_H
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER >= 20
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+enum class endian {
+ little = 0xDEAD,
+ big = 0xFACE,
+# if defined(_LIBCPP_LITTLE_ENDIAN)
+ native = little
+# elif defined(_LIBCPP_BIG_ENDIAN)
+ native = big
+# else
+ native = 0xCAFE
+# endif
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_STD_VER >= 20
+
+#endif // _LIBCPP___BIT_ENDIAN_H
diff --git a/third_party/libcxx/include/c++/v1/__bit/has_single_bit.h b/third_party/libcxx/include/c++/v1/__bit/has_single_bit.h
new file mode 100644
index 0000000..c49c518
--- /dev/null
+++ b/third_party/libcxx/include/c++/v1/__bit/has_single_bit.h
@@ -0,0 +1,37 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___BIT_HAS_SINGLE_BIT_H
+#define _LIBCPP___BIT_HAS_SINGLE_BIT_H
+
+#include <__config>
+#include <__type_traits/integer_traits.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+#if _LIBCPP_STD_VER >= 20
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <__unsigned_integer _Tp>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool has_single_bit(_Tp __t) noexcept {
+ return __builtin_popcountg(__t) == 1;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_STD_VER >= 20
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___BIT_HAS_SINGLE_BIT_H
diff --git a/third_party/libcxx/include/c++/v1/__bit/invert_if.h b/third_party/libcxx/include/c++/v1/__bit/invert_if.h
new file mode 100644
index 0000000..f7606ed
--- /dev/null
+++ b/third_party/libcxx/include/c++/v1/__bit/invert_if.h
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___BIT_INVERT_IF_H
+#define _LIBCPP___BIT_INVERT_IF_H
+
+#include <__concepts/arithmetic.h>
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <bool _Invert, class _Tp>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp __invert_if(_Tp __v) {
+ if (_Invert)
+ return ~__v;
+ return __v;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___BIT_INVERT_IF_H
diff --git a/third_party/libcxx/include/c++/v1/__bit/popcount.h b/third_party/libcxx/include/c++/v1/__bit/popcount.h
new file mode 100644
index 0000000..d104c8e
--- /dev/null
+++ b/third_party/libcxx/include/c++/v1/__bit/popcount.h
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___BIT_POPCOUNT_H
+#define _LIBCPP___BIT_POPCOUNT_H
+
+#include <__config>
+#include <__type_traits/integer_traits.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Tp>
+[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __popcount(_Tp __t) _NOEXCEPT {
+ return __builtin_popcountg(__t);
+}
+
+#if _LIBCPP_STD_VER >= 20
+
+template <__unsigned_integer _Tp>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr int popcount(_Tp __t) noexcept {
+ return std::__popcount(__t);
+}
+
+#endif
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___BIT_POPCOUNT_H
diff --git a/third_party/libcxx/include/c++/v1/__bit/rotate.h b/third_party/libcxx/include/c++/v1/__bit/rotate.h
new file mode 100644
index 0000000..fde9058
--- /dev/null
+++ b/third_party/libcxx/include/c++/v1/__bit/rotate.h
@@ -0,0 +1,60 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___BIT_ROTATE_H
+#define _LIBCPP___BIT_ROTATE_H
+
+#include <__config>
+#include <__type_traits/integer_traits.h>
+#include <limits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// Writing two full functions for rotl and rotr makes it easier for the compiler
+// to optimize the code. On x86 this function becomes the ROL instruction and
+// the rotr function becomes the ROR instruction.
+
+#if _LIBCPP_STD_VER >= 20
+
+template <__unsigned_integer _Tp>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp rotl(_Tp __t, int __cnt) noexcept {
+ const int __n = numeric_limits<_Tp>::digits;
+ int __r = __cnt % __n;
+
+ if (__r == 0)
+ return __t;
+
+ if (__r > 0)
+ return (__t << __r) | (__t >> (__n - __r));
+
+ return (__t >> -__r) | (__t << (__n + __r));
+}
+
+template <__unsigned_integer _Tp>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp rotr(_Tp __t, int __cnt) noexcept {
+ const int __n = numeric_limits<_Tp>::digits;
+ int __r = __cnt % __n;
+
+ if (__r == 0)
+ return __t;
+
+ if (__r > 0)
+ return (__t >> __r) | (__t << (__n - __r));
+
+ return (__t << -__r) | (__t >> (__n + __r));
+}
+
+#endif // _LIBCPP_STD_VER >= 20
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___BIT_ROTATE_H