xref: /llvm-project/libcxx/include/bit (revision b9a2658a3e8bd13b0f9e7a8a440832a95b377216)
1e02ee4f0SMarshall Clow// -*- C++ -*-
2eb8650a7SLouis Dionne//===----------------------------------------------------------------------===//
3e02ee4f0SMarshall Clow//
457b08b09SChandler Carruth// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
557b08b09SChandler Carruth// See https://llvm.org/LICENSE.txt for license information.
657b08b09SChandler Carruth// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7e02ee4f0SMarshall Clow//
8e02ee4f0SMarshall Clow//===---------------------------------------------------------------------===//
9e02ee4f0SMarshall Clow
10e02ee4f0SMarshall Clow#ifndef _LIBCPP_BIT
11e02ee4f0SMarshall Clow#define _LIBCPP_BIT
12e02ee4f0SMarshall Clow
13e02ee4f0SMarshall Clow/*
14e02ee4f0SMarshall Clow    bit synopsis
15e02ee4f0SMarshall Clow
16e02ee4f0SMarshall Clownamespace std {
17b1fb3d75SLouis Dionne  // [bit.cast], bit_cast
18b1fb3d75SLouis Dionne  template<class To, class From>
19b1fb3d75SLouis Dionne    constexpr To bit_cast(const From& from) noexcept; // C++20
20e02ee4f0SMarshall Clow
211dc62f26SNikolas Klauser  // [bit.byteswap], byteswap
221dc62f26SNikolas Klauser  template<class T>
231dc62f26SNikolas Klauser    constexpr T byteswap(T value) noexcept;      // C++23
241dc62f26SNikolas Klauser
25ebddf90aSLouis Dionne  // [bit.pow.two], integral powers of 2
26a5c3485aSMarshall Clow  template <class T>
271a036e9cSMark de Wever    constexpr bool has_single_bit(T x) noexcept; // C++20
28a5c3485aSMarshall Clow  template <class T>
291a036e9cSMark de Wever    constexpr T bit_ceil(T x);                   // C++20
30a5c3485aSMarshall Clow  template <class T>
311a036e9cSMark de Wever    constexpr T bit_floor(T x) noexcept;         // C++20
32a5c3485aSMarshall Clow  template <class T>
333347e7d4SArthur O'Dwyer    constexpr int bit_width(T x) noexcept;       // C++20
34a5c3485aSMarshall Clow
35ebddf90aSLouis Dionne  // [bit.rotate], rotating
36a5c3485aSMarshall Clow  template<class T>
3745500fa0SDaniil Kalinin    constexpr T rotl(T x, int s) noexcept; // C++20
38a5c3485aSMarshall Clow  template<class T>
3945500fa0SDaniil Kalinin    constexpr T rotr(T x, int s) noexcept; // C++20
40a5c3485aSMarshall Clow
41ebddf90aSLouis Dionne  // [bit.count], counting
42a5c3485aSMarshall Clow  template<class T>
43a5c3485aSMarshall Clow    constexpr int countl_zero(T x) noexcept;  // C++20
44a5c3485aSMarshall Clow  template<class T>
45a5c3485aSMarshall Clow    constexpr int countl_one(T x) noexcept;   // C++20
46a5c3485aSMarshall Clow  template<class T>
47a5c3485aSMarshall Clow    constexpr int countr_zero(T x) noexcept;  // C++20
48a5c3485aSMarshall Clow  template<class T>
49a5c3485aSMarshall Clow    constexpr int countr_one(T x) noexcept;   // C++20
50a5c3485aSMarshall Clow  template<class T>
51a5c3485aSMarshall Clow    constexpr int popcount(T x) noexcept;     // C++20
52a5c3485aSMarshall Clow
53ebddf90aSLouis Dionne  // [bit.endian], endian
5430f12a42SMarshall Clow  enum class endian {
5530f12a42SMarshall Clow    little = see below,        // C++20
5630f12a42SMarshall Clow    big = see below,           // C++20
5730f12a42SMarshall Clow    native = see below         // C++20
5830f12a42SMarshall Clow  };
5930f12a42SMarshall Clow
60e02ee4f0SMarshall Clow} // namespace std
61e02ee4f0SMarshall Clow
62e02ee4f0SMarshall Clow*/
63e02ee4f0SMarshall Clow
64*b9a2658aSNikolas Klauser#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
65*b9a2658aSNikolas Klauser#  include <__cxx03/bit>
66*b9a2658aSNikolas Klauser#else
67d5c654b5SNikolas Klauser#  include <__config>
68d5c654b5SNikolas Klauser
69d5c654b5SNikolas Klauser#  if _LIBCPP_STD_VER >= 20
70b1fb3d75SLouis Dionne#    include <__bit/bit_cast.h>
7186aac87fSNikolas Klauser#    include <__bit/bit_ceil.h>
7286aac87fSNikolas Klauser#    include <__bit/bit_floor.h>
7386aac87fSNikolas Klauser#    include <__bit/bit_log2.h>
7486aac87fSNikolas Klauser#    include <__bit/bit_width.h>
7586aac87fSNikolas Klauser#    include <__bit/countl.h>
7686aac87fSNikolas Klauser#    include <__bit/countr.h>
7786aac87fSNikolas Klauser#    include <__bit/endian.h>
7886aac87fSNikolas Klauser#    include <__bit/has_single_bit.h>
7986aac87fSNikolas Klauser#    include <__bit/popcount.h>
8086aac87fSNikolas Klauser#    include <__bit/rotate.h>
81d5c654b5SNikolas Klauser#  endif
82d5c654b5SNikolas Klauser
83d5c654b5SNikolas Klauser#  if _LIBCPP_STD_VER >= 23
84d5c654b5SNikolas Klauser#    include <__bit/byteswap.h>
85d5c654b5SNikolas Klauser#  endif
86d5c654b5SNikolas Klauser
87f56972e2SMarshall Clow#  include <version>
88e02ee4f0SMarshall Clow
89e02ee4f0SMarshall Clow#  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
90e02ee4f0SMarshall Clow#    pragma GCC system_header
91e02ee4f0SMarshall Clow#  endif
92e02ee4f0SMarshall Clow
93e31c2a1bSMark de Wever#  if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
9475196f8eSNikolas Klauser#    include <cstdlib>
95e31c2a1bSMark de Wever#    include <iosfwd>
9686aac87fSNikolas Klauser#    include <limits>
9786aac87fSNikolas Klauser#    include <type_traits>
98e31c2a1bSMark de Wever#  endif
99*b9a2658aSNikolas Klauser#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
100e31c2a1bSMark de Wever
101e02ee4f0SMarshall Clow#endif // _LIBCPP_BIT
102