Ginkgo  Generated from pipelines/1680925034 branch based on develop. Ginkgo version 1.10.0
A numerical linear algebra library targeting many-core architectures
intrinsics.hpp
1 // SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
2 //
3 // SPDX-License-Identifier: BSD-3-Clause
4 
5 #ifndef GKO_PUBLIC_CORE_BASE_INTRINSICS_HPP_
6 #define GKO_PUBLIC_CORE_BASE_INTRINSICS_HPP_
7 
8 
9 #include <bitset>
10 
11 #include <ginkgo/core/base/types.hpp>
12 
13 
14 namespace gko {
15 namespace detail {
16 
17 
21 GKO_ATTRIBUTES GKO_INLINE int popcount(uint32 bitmask)
22 {
23 #if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__)
24  return __popc(static_cast<unsigned>(bitmask));
25 #else
26  std::bitset<32> bits{bitmask};
27  return bits.count();
28 #endif
29 }
30 
31 
33 GKO_ATTRIBUTES GKO_INLINE int popcount(uint64 bitmask)
34 {
35 #if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__)
36  return __popcll(static_cast<unsigned long long>(bitmask));
37 #else
38  std::bitset<64> bits{bitmask};
39  return bits.count();
40 #endif
41 }
42 
43 
44 } // namespace detail
45 } // namespace gko
46 
47 #endif // GKO_PUBLIC_CORE_BASE_INTRINSICS_HPP_
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:20
gko::uint32
std::uint32_t uint32
32-bit unsigned integral type.
Definition: types.hpp:129
gko::uint64
std::uint64_t uint64
64-bit unsigned integral type.
Definition: types.hpp:135