xref: /freebsd/contrib/llvm-project/libcxx/include/__cxx03/__bit/popcount.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // TODO: __builtin_popcountg is available since Clang 19 and GCC 14. When support for older versions is dropped, we can
10 //  refactor this code to exclusively use __builtin_popcountg.
11 
12 #ifndef _LIBCPP___CXX03___BIT_POPCOUNT_H
13 #define _LIBCPP___CXX03___BIT_POPCOUNT_H
14 
15 #include <__cxx03/__bit/rotate.h>
16 #include <__cxx03/__config>
17 #include <__cxx03/limits>
18 
19 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20 #  pragma GCC system_header
21 #endif
22 
23 _LIBCPP_PUSH_MACROS
24 #include <__cxx03/__undef_macros>
25 
26 _LIBCPP_BEGIN_NAMESPACE_STD
27 
__libcpp_popcount(unsigned __x)28 inline _LIBCPP_HIDE_FROM_ABI int __libcpp_popcount(unsigned __x) _NOEXCEPT { return __builtin_popcount(__x); }
29 
__libcpp_popcount(unsigned long __x)30 inline _LIBCPP_HIDE_FROM_ABI int __libcpp_popcount(unsigned long __x) _NOEXCEPT { return __builtin_popcountl(__x); }
31 
__libcpp_popcount(unsigned long long __x)32 inline _LIBCPP_HIDE_FROM_ABI int __libcpp_popcount(unsigned long long __x) _NOEXCEPT {
33   return __builtin_popcountll(__x);
34 }
35 
36 _LIBCPP_END_NAMESPACE_STD
37 
38 _LIBCPP_POP_MACROS
39 
40 #endif // _LIBCPP___CXX03___BIT_POPCOUNT_H
41