aboutsummaryrefslogtreecommitdiff
path: root/libcxx
diff options
context:
space:
mode:
authorThorsten Schütt <schuett@gmail.com>2021-01-18 13:21:00 +0100
committerThorsten Schütt <schuett@gmail.com>2021-01-22 21:20:23 +0100
commitb973e2e2f27ede7a70d470ea537f1901759d239d (patch)
tree34f066b0f06dccb7cc6b726819d9d9fdfaaf12d2 /libcxx
parentea2cfda386f1a0f0b8cab06a9400bbf4cf7bfbaa (diff)
downloadllvm-b973e2e2f27ede7a70d470ea537f1901759d239d.zip
llvm-b973e2e2f27ede7a70d470ea537f1901759d239d.tar.gz
llvm-b973e2e2f27ede7a70d470ea537f1901759d239d.tar.bz2
[libc++] Introduce __bits
It has the low-level bit fiddling operations from bit. It eliminates a cyclic dependency between __bit_reference, bits, and vector. I want to exploit this in later patches. Reviewed By: #libc, ldionne Differential Revision: https://reviews.llvm.org/D94908
Diffstat (limited to 'libcxx')
-rw-r--r--libcxx/include/CMakeLists.txt1
-rw-r--r--libcxx/include/__bit_reference2
-rw-r--r--libcxx/include/__bits146
-rw-r--r--libcxx/include/bit117
-rw-r--r--libcxx/include/module.modulemap1
5 files changed, 150 insertions, 117 deletions
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 2ffdf07..77e5e55 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -1,6 +1,7 @@
set(files
__availability
__bit_reference
+ __bits
__bsd_locale_defaults.h
__bsd_locale_fallbacks.h
__debug
diff --git a/libcxx/include/__bit_reference b/libcxx/include/__bit_reference
index 284ed0f..9cfb4b8 100644
--- a/libcxx/include/__bit_reference
+++ b/libcxx/include/__bit_reference
@@ -11,7 +11,7 @@
#define _LIBCPP___BIT_REFERENCE
#include <__config>
-#include <bit>
+#include <__bits>
#include <algorithm>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
diff --git a/libcxx/include/__bits b/libcxx/include/__bits
new file mode 100644
index 0000000..0d321da
--- /dev/null
+++ b/libcxx/include/__bits
@@ -0,0 +1,146 @@
+// -*- 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___BITS
+#define _LIBCPP___BITS
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#ifndef _LIBCPP_COMPILER_MSVC
+
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+int __libcpp_ctz(unsigned __x) _NOEXCEPT { return __builtin_ctz(__x); }
+
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+int __libcpp_ctz(unsigned long __x) _NOEXCEPT { return __builtin_ctzl(__x); }
+
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+int __libcpp_ctz(unsigned long long __x) _NOEXCEPT { return __builtin_ctzll(__x); }
+
+
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+int __libcpp_clz(unsigned __x) _NOEXCEPT { return __builtin_clz(__x); }
+
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+int __libcpp_clz(unsigned long __x) _NOEXCEPT { return __builtin_clzl(__x); }
+
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+int __libcpp_clz(unsigned long long __x) _NOEXCEPT { return __builtin_clzll(__x); }
+
+
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+int __libcpp_popcount(unsigned __x) _NOEXCEPT { return __builtin_popcount(__x); }
+
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+int __libcpp_popcount(unsigned long __x) _NOEXCEPT { return __builtin_popcountl(__x); }
+
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+int __libcpp_popcount(unsigned long long __x) _NOEXCEPT { return __builtin_popcountll(__x); }
+
+#else // _LIBCPP_COMPILER_MSVC
+
+// Precondition: __x != 0
+inline _LIBCPP_INLINE_VISIBILITY
+int __libcpp_ctz(unsigned __x) {
+ static_assert(sizeof(unsigned) == sizeof(unsigned long), "");
+ static_assert(sizeof(unsigned long) == 4, "");
+ unsigned long __where;
+ if (_BitScanForward(&__where, __x))
+ return static_cast<int>(__where);
+ return 32;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+int __libcpp_ctz(unsigned long __x) {
+ static_assert(sizeof(unsigned long) == sizeof(unsigned), "");
+ return __ctz(static_cast<unsigned>(__x));
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+int __libcpp_ctz(unsigned long long __x) {
+ unsigned long __where;
+#if defined(_LIBCPP_HAS_BITSCAN64)
+ (defined(_M_AMD64) || defined(__x86_64__))
+ if (_BitScanForward64(&__where, __x))
+ return static_cast<int>(__where);
+#else
+ // Win32 doesn't have _BitScanForward64 so emulate it with two 32 bit calls.
+ if (_BitScanForward(&__where, static_cast<unsigned long>(__x)))
+ return static_cast<int>(__where);
+ if (_BitScanForward(&__where, static_cast<unsigned long>(__x >> 32)))
+ return static_cast<int>(__where + 32);
+#endif
+ return 64;
+}
+
+// Precondition: __x != 0
+inline _LIBCPP_INLINE_VISIBILITY
+int __libcpp_clz(unsigned __x) {
+ static_assert(sizeof(unsigned) == sizeof(unsigned long), "");
+ static_assert(sizeof(unsigned long) == 4, "");
+ unsigned long __where;
+ if (_BitScanReverse(&__where, __x))
+ return static_cast<int>(31 - __where);
+ return 32; // Undefined Behavior.
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+int __libcpp_clz(unsigned long __x) {
+ static_assert(sizeof(unsigned) == sizeof(unsigned long), "");
+ return __libcpp_clz(static_cast<unsigned>(__x));
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+int __libcpp_clz(unsigned long long __x) {
+ unsigned long __where;
+#if defined(_LIBCPP_HAS_BITSCAN64)
+ if (_BitScanReverse64(&__where, __x))
+ return static_cast<int>(63 - __where);
+#else
+ // Win32 doesn't have _BitScanReverse64 so emulate it with two 32 bit calls.
+ if (_BitScanReverse(&__where, static_cast<unsigned long>(__x >> 32)))
+ return static_cast<int>(63 - (__where + 32));
+ if (_BitScanReverse(&__where, static_cast<unsigned long>(__x)))
+ return static_cast<int>(63 - __where);
+#endif
+ return 64; // Undefined Behavior.
+}
+
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_popcount(unsigned __x) {
+ static_assert(sizeof(unsigned) == 4, "");
+ return __popcnt(__x);
+}
+
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_popcount(unsigned long __x) {
+ static_assert(sizeof(unsigned long) == 4, "");
+ return __popcnt(__x);
+}
+
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_popcount(unsigned long long __x) {
+ static_assert(sizeof(unsigned long long) == 8, "");
+ return __popcnt64(__x);
+}
+
+#endif // _LIBCPP_COMPILER_MSVC
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP__BITS
diff --git a/libcxx/include/bit b/libcxx/include/bit
index a0f362d..fe36017 100644
--- a/libcxx/include/bit
+++ b/libcxx/include/bit
@@ -55,6 +55,7 @@ namespace std {
*/
#include <__config>
+#include <__bits>
#include <limits>
#include <type_traits>
#include <version>
@@ -76,122 +77,6 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD
-#ifndef _LIBCPP_COMPILER_MSVC
-
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-int __libcpp_ctz(unsigned __x) _NOEXCEPT { return __builtin_ctz(__x); }
-
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-int __libcpp_ctz(unsigned long __x) _NOEXCEPT { return __builtin_ctzl(__x); }
-
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-int __libcpp_ctz(unsigned long long __x) _NOEXCEPT { return __builtin_ctzll(__x); }
-
-
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-int __libcpp_clz(unsigned __x) _NOEXCEPT { return __builtin_clz(__x); }
-
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-int __libcpp_clz(unsigned long __x) _NOEXCEPT { return __builtin_clzl(__x); }
-
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-int __libcpp_clz(unsigned long long __x) _NOEXCEPT { return __builtin_clzll(__x); }
-
-
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-int __libcpp_popcount(unsigned __x) _NOEXCEPT { return __builtin_popcount(__x); }
-
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-int __libcpp_popcount(unsigned long __x) _NOEXCEPT { return __builtin_popcountl(__x); }
-
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-int __libcpp_popcount(unsigned long long __x) _NOEXCEPT { return __builtin_popcountll(__x); }
-
-#else // _LIBCPP_COMPILER_MSVC
-
-// Precondition: __x != 0
-inline _LIBCPP_INLINE_VISIBILITY
-int __libcpp_ctz(unsigned __x) {
- static_assert(sizeof(unsigned) == sizeof(unsigned long), "");
- static_assert(sizeof(unsigned long) == 4, "");
- unsigned long __where;
- if (_BitScanForward(&__where, __x))
- return static_cast<int>(__where);
- return 32;
-}
-
-inline _LIBCPP_INLINE_VISIBILITY
-int __libcpp_ctz(unsigned long __x) {
- static_assert(sizeof(unsigned long) == sizeof(unsigned), "");
- return __ctz(static_cast<unsigned>(__x));
-}
-
-inline _LIBCPP_INLINE_VISIBILITY
-int __libcpp_ctz(unsigned long long __x) {
- unsigned long __where;
-#if defined(_LIBCPP_HAS_BITSCAN64)
- (defined(_M_AMD64) || defined(__x86_64__))
- if (_BitScanForward64(&__where, __x))
- return static_cast<int>(__where);
-#else
- // Win32 doesn't have _BitScanForward64 so emulate it with two 32 bit calls.
- if (_BitScanForward(&__where, static_cast<unsigned long>(__x)))
- return static_cast<int>(__where);
- if (_BitScanForward(&__where, static_cast<unsigned long>(__x >> 32)))
- return static_cast<int>(__where + 32);
-#endif
- return 64;
-}
-
-// Precondition: __x != 0
-inline _LIBCPP_INLINE_VISIBILITY
-int __libcpp_clz(unsigned __x) {
- static_assert(sizeof(unsigned) == sizeof(unsigned long), "");
- static_assert(sizeof(unsigned long) == 4, "");
- unsigned long __where;
- if (_BitScanReverse(&__where, __x))
- return static_cast<int>(31 - __where);
- return 32; // Undefined Behavior.
-}
-
-inline _LIBCPP_INLINE_VISIBILITY
-int __libcpp_clz(unsigned long __x) {
- static_assert(sizeof(unsigned) == sizeof(unsigned long), "");
- return __libcpp_clz(static_cast<unsigned>(__x));
-}
-
-inline _LIBCPP_INLINE_VISIBILITY
-int __libcpp_clz(unsigned long long __x) {
- unsigned long __where;
-#if defined(_LIBCPP_HAS_BITSCAN64)
- if (_BitScanReverse64(&__where, __x))
- return static_cast<int>(63 - __where);
-#else
- // Win32 doesn't have _BitScanReverse64 so emulate it with two 32 bit calls.
- if (_BitScanReverse(&__where, static_cast<unsigned long>(__x >> 32)))
- return static_cast<int>(63 - (__where + 32));
- if (_BitScanReverse(&__where, static_cast<unsigned long>(__x)))
- return static_cast<int>(63 - __where);
-#endif
- return 64; // Undefined Behavior.
-}
-
-inline _LIBCPP_INLINE_VISIBILITY int __libcpp_popcount(unsigned __x) {
- static_assert(sizeof(unsigned) == 4, "");
- return __popcnt(__x);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY int __libcpp_popcount(unsigned long __x) {
- static_assert(sizeof(unsigned long) == 4, "");
- return __popcnt(__x);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY int __libcpp_popcount(unsigned long long __x) {
- static_assert(sizeof(unsigned long long) == 8, "");
- return __popcnt64(__x);
-}
-
-#endif // _LIBCPP_COMPILER_MSVC
template <class _Tp>
using __bitop_unsigned_integer _LIBCPP_NODEBUG_TYPE = integral_constant<bool,
diff --git a/libcxx/include/module.modulemap b/libcxx/include/module.modulemap
index b8d2a66..750cd38 100644
--- a/libcxx/include/module.modulemap
+++ b/libcxx/include/module.modulemap
@@ -522,6 +522,7 @@ module std [system] {
}
// FIXME: These should be private.
+ module __bits { header "__bits" export * }
module __bit_reference { header "__bit_reference" export * }
module __debug { header "__debug" export * }
module __errc { header "__errc" export * }